Skip to content

Commit

Permalink
Merge pull request #1 from Escape-Technologies/feat/add-start-scan
Browse files Browse the repository at this point in the history
Feat: add start-scan command
  • Loading branch information
ValentinR01 authored Feb 7, 2025
2 parents a70600f + df7db5f commit 6d90182
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./scripts
./assets
5 changes: 5 additions & 0 deletions .github/workflows/release-binary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
with:
go-version: 1.21.x

- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- uses: goreleaser/goreleaser-action@v4
with:
args: "release --clean"
Expand Down
37 changes: 37 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ builds:
main: ./cmd/main.go
ldflags:
- -s -w -X github.com/Escape-Technologies/cli/pkg/cli.version={{.Version}} -X github.com/Escape-Technologies/cli/pkg/cli.commit={{.ShortCommit}}
dockers:
- image_templates:
- "escapetech/app-cli:{{ .Version }}-amd64"
dockerfile: Dockerfile
goarch: amd64
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=app-cli"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.licenses=Apache-2.0"
- image_templates:
- "escapetech/app-cli:{{ .Version }}-arm64"
dockerfile: Dockerfile
goarch: arm64
build_flag_templates:
- "--pull"
- "--platform=linux/arm64"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title=app-cli"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.licenses=Apache-2.0"

docker_manifests:
- name_template: "escapetech/app-cli:{{ .Version }}"
skip_push: false
image_templates:
- escapetech/app-cli:{{ .Version }}-amd64
- escapetech/app-cli:{{ .Version }}-arm64
- name_template: "escapetech/app-cli:latest"
skip_push: false
image_templates:
- escapetech/app-cli:{{ .Version }}-amd64
- escapetech/app-cli:{{ .Version }}-arm64

checksum:
algorithm: sha256
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Runtime
FROM --platform=$BUILDPLATFORM alpine:3.20

RUN adduser -D escape
USER escape

COPY --chown=escape:escape ./escape-cli /usr/local/bin/escape-cli

ENTRYPOINT ["/bin/sh"]
2 changes: 1 addition & 1 deletion assets/public-api.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.5
toolchain go1.23.4

require (
github.com/gofrs/uuid/v5 v5.0.0
github.com/oapi-codegen/oapi-codegen/v2 v2.4.1
github.com/oapi-codegen/runtime v1.1.1
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/getkin/kin-openapi v0.127.0 h1:Mghqi3Dhryf3F8vR370nN67pAERW+3a95vomb3MAREY=
github.com/getkin/kin-openapi v0.127.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/getkin/kin-openapi v0.129.0 h1:QGYTNcmyP5X0AtFQ2Dkou9DGBJsUETeLH9rFrJXZh30=
github.com/getkin/kin-openapi v0.129.0/go.mod h1:gmWI+b/J45xqpyK5wJmRRZse5wefA5H0RDMK46kLUtI=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gofrs/uuid/v5 v5.3.0 h1:m0mUMr+oVYUdxpMLgSYCZiXe7PuVPnI94+OMeVBNedk=
github.com/gofrs/uuid/v5 v5.3.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
Expand Down
8 changes: 7 additions & 1 deletion pkg/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,28 @@ func Run() error {
log.Trace("Main cli done, exiting")
},
}

// Flags
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose output")
rootCmd.PersistentFlags().StringVarP(&outputStr, "output", "o", "pretty", "Output format (pretty|json|yaml)")

// Version
rootCmd.AddCommand(versionCmd)

// Locations
rootCmd.AddCommand(locationsCmd)
locationsCmd.AddCommand(locationsListCmd)
locationsCmd.AddCommand(locationsDeleteCmd)

// Integrations
rootCmd.AddCommand(integrationsCmd)
integrationsCmd.AddCommand(integrationsAkamaiCmd)
integrationsAkamaiCmd.AddCommand(integrationsAkamaiList)
integrationsCmd.AddCommand(integrationsKubernetesCmd)
integrationsKubernetesCmd.AddCommand(integrationsKubernetesList)
integrationsKubernetesCmd.AddCommand(integrationsKubernetesDelete)

// Scan
rootCmd.AddCommand(startScanCmd)

return rootCmd.Execute()
}
73 changes: 73 additions & 0 deletions pkg/cli/scan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package cli

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/Escape-Technologies/cli/pkg/api"
"github.com/google/uuid"
"github.com/oapi-codegen/runtime/types"
"github.com/spf13/cobra"
)

var startScanCmd = &cobra.Command{
Use: "start-scan [applicationId]",
Short: "Trigger a scan on an application",
Args: cobra.ExactArgs(1),
Example: "escape-cli start-scan 123e4567-e89b-12d3-a456-426614174001",
RunE: func(cmd *cobra.Command, args []string) error {
applicationID := args[0]
fmt.Printf("Triggering scan for application %s\n\n", applicationID)

client, err := api.NewAPIClient()
if err != nil {
return fmt.Errorf("failed to create API client: %w", err)
}

parsedUUID, err := uuid.Parse(applicationID)
if err != nil {
return fmt.Errorf("invalid UUID format: %w", err)
}
applicationId := types.UUID(parsedUUID)
params := &api.PostApplicationsIdStartScanParams{
ContentType: api.PostApplicationsIdStartScanParamsContentTypeApplicationjson,
}

body := api.PostApplicationsIdStartScanJSONRequestBody{}
scan, err := client.PostApplicationsIdStartScanWithResponse(context.Background(), applicationId, params, body)
if err != nil {
return err
}
// Handle response
var data interface{}
if scan.JSON200 != nil {
print(
scan.JSON200,
func() {
fmt.Printf("-> Scan successfully launched\n")
fmt.Printf("Scan ID: %s\n", scan.JSON200.Id)
},
)
return nil
} else if scan.JSON400 != nil {
data = scan.JSON400
} else {
data = scan.JSON500
}
print(
data,
func() {
var responseMessage map[string]interface{}
json.Unmarshal(scan.Body, &responseMessage)

// Print status code and error message
fmt.Println(scan.HTTPResponse.Status)
fmt.Printf("%s\n\n", responseMessage["message"])
},
)
os.Exit(1)
return err
},
}
10 changes: 7 additions & 3 deletions new-version.sh → scripts/new-version.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash

old_version=$(cat version.txt)
# Retrieve project root directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

old_version=$(cat $PROJECT_ROOT/version.txt)
SEMVER_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$"

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

echo "${new_version}" > version.txt
echo "${new_version}" > $PROJECT_ROOT/version.txt

git add version.txt
git add $PROJECT_ROOT/version.txt
git commit -m "v${new_version}"
git tag -a "v${new_version}" -m "v${new_version}"
git push
Expand Down
11 changes: 11 additions & 0 deletions scripts/update-schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Retrieve project root directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

# Retrieve the schema from the public API
curl -s https://public.escape.tech/v1/openapi.json > $PROJECT_ROOT/assets/public-api.json

# Generate the code binding on openAPI schema
go generate $PROJECT_ROOT/pkg/api/...

0 comments on commit 6d90182

Please sign in to comment.