-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Escape-Technologies/feat/add-start-scan
Feat: add start-scan command
- Loading branch information
Showing
11 changed files
with
155 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
./scripts | ||
./assets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/... |