Skip to content

Commit 6d90182

Browse files
authored
Merge pull request #1 from Escape-Technologies/feat/add-start-scan
Feat: add start-scan command
2 parents a70600f + df7db5f commit 6d90182

File tree

11 files changed

+155
-7
lines changed

11 files changed

+155
-7
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
./scripts
2+
./assets

.github/workflows/release-binary.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ jobs:
1919
with:
2020
go-version: 1.21.x
2121

22+
- uses: docker/login-action@v2
23+
with:
24+
username: ${{ secrets.DOCKERHUB_USERNAME }}
25+
password: ${{ secrets.DOCKERHUB_TOKEN }}
26+
2227
- uses: goreleaser/goreleaser-action@v4
2328
with:
2429
args: "release --clean"

.goreleaser.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@ builds:
1616
main: ./cmd/main.go
1717
ldflags:
1818
- -s -w -X github.com/Escape-Technologies/cli/pkg/cli.version={{.Version}} -X github.com/Escape-Technologies/cli/pkg/cli.commit={{.ShortCommit}}
19+
dockers:
20+
- image_templates:
21+
- "escapetech/app-cli:{{ .Version }}-amd64"
22+
dockerfile: Dockerfile
23+
goarch: amd64
24+
build_flag_templates:
25+
- "--pull"
26+
- "--platform=linux/amd64"
27+
- "--label=org.opencontainers.image.created={{.Date}}"
28+
- "--label=org.opencontainers.image.title=app-cli"
29+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
30+
- "--label=org.opencontainers.image.version={{.Version}}"
31+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
32+
- image_templates:
33+
- "escapetech/app-cli:{{ .Version }}-arm64"
34+
dockerfile: Dockerfile
35+
goarch: arm64
36+
build_flag_templates:
37+
- "--pull"
38+
- "--platform=linux/arm64"
39+
- "--label=org.opencontainers.image.created={{.Date}}"
40+
- "--label=org.opencontainers.image.title=app-cli"
41+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
42+
- "--label=org.opencontainers.image.version={{.Version}}"
43+
- "--label=org.opencontainers.image.licenses=Apache-2.0"
44+
45+
docker_manifests:
46+
- name_template: "escapetech/app-cli:{{ .Version }}"
47+
skip_push: false
48+
image_templates:
49+
- escapetech/app-cli:{{ .Version }}-amd64
50+
- escapetech/app-cli:{{ .Version }}-arm64
51+
- name_template: "escapetech/app-cli:latest"
52+
skip_push: false
53+
image_templates:
54+
- escapetech/app-cli:{{ .Version }}-amd64
55+
- escapetech/app-cli:{{ .Version }}-arm64
1956

2057
checksum:
2158
algorithm: sha256

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Runtime
2+
FROM --platform=$BUILDPLATFORM alpine:3.20
3+
4+
RUN adduser -D escape
5+
USER escape
6+
7+
COPY --chown=escape:escape ./escape-cli /usr/local/bin/escape-cli
8+
9+
ENTRYPOINT ["/bin/sh"]

assets/public-api.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.22.5
55
toolchain go1.23.4
66

77
require (
8+
github.com/gofrs/uuid/v5 v5.0.0
89
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
910
github.com/oapi-codegen/runtime v1.1.1
1011
github.com/sirupsen/logrus v1.9.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
1717
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
1818
github.com/getkin/kin-openapi v0.127.0 h1:Mghqi3Dhryf3F8vR370nN67pAERW+3a95vomb3MAREY=
1919
github.com/getkin/kin-openapi v0.127.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
20-
github.com/getkin/kin-openapi v0.129.0 h1:QGYTNcmyP5X0AtFQ2Dkou9DGBJsUETeLH9rFrJXZh30=
21-
github.com/getkin/kin-openapi v0.129.0/go.mod h1:gmWI+b/J45xqpyK5wJmRRZse5wefA5H0RDMK46kLUtI=
2220
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
2321
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
2422
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
2523
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
2624
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
2725
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
2826
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
27+
github.com/gofrs/uuid/v5 v5.3.0 h1:m0mUMr+oVYUdxpMLgSYCZiXe7PuVPnI94+OMeVBNedk=
28+
github.com/gofrs/uuid/v5 v5.3.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
2929
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3030
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
3131
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=

pkg/cli/root.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,28 @@ func Run() error {
6363
log.Trace("Main cli done, exiting")
6464
},
6565
}
66-
66+
// Flags
6767
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output")
6868
rootCmd.PersistentFlags().StringVarP(&outputStr, "output", "o", "pretty", "Output format (pretty|json|yaml)")
6969

70+
// Version
7071
rootCmd.AddCommand(versionCmd)
7172

73+
// Locations
7274
rootCmd.AddCommand(locationsCmd)
7375
locationsCmd.AddCommand(locationsListCmd)
7476
locationsCmd.AddCommand(locationsDeleteCmd)
7577

78+
// Integrations
7679
rootCmd.AddCommand(integrationsCmd)
7780
integrationsCmd.AddCommand(integrationsAkamaiCmd)
7881
integrationsAkamaiCmd.AddCommand(integrationsAkamaiList)
7982
integrationsCmd.AddCommand(integrationsKubernetesCmd)
8083
integrationsKubernetesCmd.AddCommand(integrationsKubernetesList)
8184
integrationsKubernetesCmd.AddCommand(integrationsKubernetesDelete)
8285

86+
// Scan
87+
rootCmd.AddCommand(startScanCmd)
88+
8389
return rootCmd.Execute()
8490
}

pkg/cli/scan.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package cli
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"os"
8+
9+
"github.com/Escape-Technologies/cli/pkg/api"
10+
"github.com/google/uuid"
11+
"github.com/oapi-codegen/runtime/types"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var startScanCmd = &cobra.Command{
16+
Use: "start-scan [applicationId]",
17+
Short: "Trigger a scan on an application",
18+
Args: cobra.ExactArgs(1),
19+
Example: "escape-cli start-scan 123e4567-e89b-12d3-a456-426614174001",
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
applicationID := args[0]
22+
fmt.Printf("Triggering scan for application %s\n\n", applicationID)
23+
24+
client, err := api.NewAPIClient()
25+
if err != nil {
26+
return fmt.Errorf("failed to create API client: %w", err)
27+
}
28+
29+
parsedUUID, err := uuid.Parse(applicationID)
30+
if err != nil {
31+
return fmt.Errorf("invalid UUID format: %w", err)
32+
}
33+
applicationId := types.UUID(parsedUUID)
34+
params := &api.PostApplicationsIdStartScanParams{
35+
ContentType: api.PostApplicationsIdStartScanParamsContentTypeApplicationjson,
36+
}
37+
38+
body := api.PostApplicationsIdStartScanJSONRequestBody{}
39+
scan, err := client.PostApplicationsIdStartScanWithResponse(context.Background(), applicationId, params, body)
40+
if err != nil {
41+
return err
42+
}
43+
// Handle response
44+
var data interface{}
45+
if scan.JSON200 != nil {
46+
print(
47+
scan.JSON200,
48+
func() {
49+
fmt.Printf("-> Scan successfully launched\n")
50+
fmt.Printf("Scan ID: %s\n", scan.JSON200.Id)
51+
},
52+
)
53+
return nil
54+
} else if scan.JSON400 != nil {
55+
data = scan.JSON400
56+
} else {
57+
data = scan.JSON500
58+
}
59+
print(
60+
data,
61+
func() {
62+
var responseMessage map[string]interface{}
63+
json.Unmarshal(scan.Body, &responseMessage)
64+
65+
// Print status code and error message
66+
fmt.Println(scan.HTTPResponse.Status)
67+
fmt.Printf("%s\n\n", responseMessage["message"])
68+
},
69+
)
70+
os.Exit(1)
71+
return err
72+
},
73+
}

new-version.sh renamed to scripts/new-version.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22

3-
old_version=$(cat version.txt)
3+
# Retrieve project root directory
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
6+
7+
old_version=$(cat $PROJECT_ROOT/version.txt)
48
SEMVER_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$"
59

610
if [[ "$old_version" =~ $SEMVER_REGEX ]]; then
@@ -29,9 +33,9 @@ esac
2933
new_version="${_major}.${_minor}.${_patch}"
3034
echo "Bump done: $old_version -> $new_version"
3135

32-
echo "${new_version}" > version.txt
36+
echo "${new_version}" > $PROJECT_ROOT/version.txt
3337

34-
git add version.txt
38+
git add $PROJECT_ROOT/version.txt
3539
git commit -m "v${new_version}"
3640
git tag -a "v${new_version}" -m "v${new_version}"
3741
git push

0 commit comments

Comments
 (0)