-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: add start-scan command #1
Merged
Merged
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
4766de4
Add update schema script
09b4c0b
feat: adds scan trigger
a1ef871
fix: return err to terminate process with exit code on failure
b28a2d0
feat: add dockerfile & releaser
d789875
rework shell scripts
035ec7c
v0.1.0
79d9895
Fix Dockerfile for goreleaser
c4f910b
v0.1.1
7ae2331
add docker login
1409bc1
v0.1.2
1837560
fix: docker hub image repo
b266f6c
v0.1.3
9989aa8
fix: build cross platform docker images
a0caba4
v0.1.4
9d9770c
fix2: build cross platform docker images
4345284
v0.1.5
e9dc73b
fix3: build cross platform docker images
4cb5d5d
v0.1.6
0c9b7ee
fix4: build cross platform docker images
ce477ef
v0.1.7
7d0e3a4
Add platform to base image
742603c
v0.1.8
f44ee43
fix copy cmd
0f7b8e8
v0.1.9
60a8bf8
fix: publish tag
a0f02a5
v0.1.10
a52b88e
fix2: publish tag
ddc1ac3
v0.1.11
e12b161
add docker manifests to handle both images as the same docker tag on Hub
374ff8d
v0.1.12
e449094
fix: go releaser
c73de38
v0.1.13
606f4dd
fix tags
389f95d
v0.1.14
d240d44
fix order
bb25105
v0.1.15
c7864df
fix: minor version
df7db5f
Delete .github/workflows/docker-publish.yaml
ValentinR01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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: "scan [applicationId]", | ||
Short: "Trigger a scan on an application", | ||
Args: cobra.ExactArgs(1), | ||
Example: "escape-cli 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
old_version=$(cat version.txt) | ||
SEMVER_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$" | ||
|
||
if [[ "$old_version" =~ $SEMVER_REGEX ]]; then | ||
_major=${BASH_REMATCH[1]} | ||
_minor=${BASH_REMATCH[2]} | ||
_patch=${BASH_REMATCH[3]} | ||
else | ||
echo "Invalid version in version.txt: $old_version" | ||
exit 1 | ||
fi | ||
|
||
case $1 in | ||
patch) | ||
_patch=$(($_patch + 1)) | ||
;; | ||
minor) | ||
_minor=$(($_minor + 1)) | ||
_patch=0 | ||
;; | ||
*) | ||
echo "Usage: $0 <minor|patch>" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
new_version="${_major}.${_minor}.${_patch}" | ||
echo "Bump done: $old_version -> $new_version" | ||
|
||
echo "${new_version}" > version.txt | ||
|
||
git add version.txt | ||
git commit -m "v${new_version}" | ||
git tag -a "v${new_version}" -m "v${new_version}" | ||
git push | ||
git push --tags | ||
|
||
GOPROXY=proxy.golang.org go list -m "github.com/Escape-Technologies/cli@v${new_version}" | ||
|
||
echo "Done !" |
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,12 @@ | ||
#!/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/... | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add
SCRIPT_DIR
andPROJECT_ROOT