Skip to content
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 38 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4766de4
Add update schema script
Feb 6, 2025
09b4c0b
feat: adds scan trigger
Feb 6, 2025
a1ef871
fix: return err to terminate process with exit code on failure
Feb 7, 2025
b28a2d0
feat: add dockerfile & releaser
Feb 7, 2025
d789875
rework shell scripts
Feb 7, 2025
035ec7c
v0.1.0
Feb 7, 2025
79d9895
Fix Dockerfile for goreleaser
Feb 7, 2025
c4f910b
v0.1.1
Feb 7, 2025
7ae2331
add docker login
Feb 7, 2025
1409bc1
v0.1.2
Feb 7, 2025
1837560
fix: docker hub image repo
Feb 7, 2025
b266f6c
v0.1.3
Feb 7, 2025
9989aa8
fix: build cross platform docker images
Feb 7, 2025
a0caba4
v0.1.4
Feb 7, 2025
9d9770c
fix2: build cross platform docker images
Feb 7, 2025
4345284
v0.1.5
Feb 7, 2025
e9dc73b
fix3: build cross platform docker images
Feb 7, 2025
4cb5d5d
v0.1.6
Feb 7, 2025
0c9b7ee
fix4: build cross platform docker images
Feb 7, 2025
ce477ef
v0.1.7
Feb 7, 2025
7d0e3a4
Add platform to base image
Feb 7, 2025
742603c
v0.1.8
Feb 7, 2025
f44ee43
fix copy cmd
Feb 7, 2025
0f7b8e8
v0.1.9
Feb 7, 2025
60a8bf8
fix: publish tag
Feb 7, 2025
a0f02a5
v0.1.10
Feb 7, 2025
a52b88e
fix2: publish tag
Feb 7, 2025
ddc1ac3
v0.1.11
Feb 7, 2025
e12b161
add docker manifests to handle both images as the same docker tag on Hub
Feb 7, 2025
374ff8d
v0.1.12
Feb 7, 2025
e449094
fix: go releaser
Feb 7, 2025
c73de38
v0.1.13
Feb 7, 2025
606f4dd
fix tags
Feb 7, 2025
389f95d
v0.1.14
Feb 7, 2025
d240d44
fix order
Feb 7, 2025
bb25105
v0.1.15
Feb 7, 2025
c7864df
fix: minor version
Feb 7, 2025
df7db5f
Delete .github/workflows/docker-publish.yaml
ValentinR01 Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/public-api.json

Large diffs are not rendered by default.

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: "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
},
}
42 changes: 42 additions & 0 deletions scripts/new-version.sh
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add SCRIPT_DIR and PROJECT_ROOT


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 !"
12 changes: 12 additions & 0 deletions scripts/update-schema.sh
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/...