Skip to content

Commit

Permalink
include missing error logs before exiting (#26)
Browse files Browse the repository at this point in the history
* include missing error logs before exiting

* add some debug logging for auth
  • Loading branch information
tim-thacker-nullify authored Nov 22, 2023
1 parent 43261f2 commit db78fbe
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ func main() {
switch {
case args.DAST != nil && args.DAST.Path != "":
logger.Info(
"running fuzz test",
"running dast scan",
logger.String("path", args.DAST.Path),
logger.String("targetHost", args.DAST.TargetHost),
)

openAPISpec, err := lib.CreateOpenAPIFile(args.DAST.Path)
if err != nil {
logger.Error("failed to create openapi file", logger.Err(err))
os.Exit(1)
}

authHeaders, err := lib.ParseAuthHeaders(args.DAST.AuthHeaders)
if err != nil {
logger.Error("failed to parse auth headers", logger.Err(err))
os.Exit(1)
}

Expand Down
26 changes: 23 additions & 3 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/nullify-platform/cli/internal/models"
"github.com/nullify-platform/logger/pkg/logger"
)

type authTransport struct {
Expand All @@ -22,11 +23,16 @@ func (t *authTransport) RoundTrip(req *http.Request) (*http.Response, error) {
}

func NewHTTPClient(nullifyHost string, authSources *models.AuthSources) (*http.Client, error) {
token, error := getToken(nullifyHost, authSources)
if error != nil {
return nil, error
token, err := getToken(nullifyHost, authSources)
if err != nil {
return nil, err
}

logger.Debug(
"using token",
logger.String("token", token),
)

return &http.Client{
Transport: &authTransport{
token: token,
Expand All @@ -39,11 +45,13 @@ var ErrNoToken = errors.New("no token detected")

func getToken(nullifyHost string, authSources *models.AuthSources) (string, error) {
if authSources.NullifyToken != "" {
logger.Debug("using token from config")
return authSources.NullifyToken, nil
}

token := os.Getenv("NULLIFY_TOKEN")
if token != "" {
logger.Debug("using token from env")
return token, nil
}

Expand All @@ -52,6 +60,12 @@ func getToken(nullifyHost string, authSources *models.AuthSources) (string, erro
os.Getenv("GITHUB_ACTION_REPOSITORY") != "" {
repo := os.Getenv("GITHUB_ACTION_REPOSITORY")

logger.Debug(
"exchanging github actions token for a nullify token",
logger.String("repository", repo),
logger.String("githubToken", authSources.GitHubToken),
)

parts := strings.Split(repo, "/")

if len(parts) != 2 {
Expand All @@ -77,6 +91,12 @@ func getToken(nullifyHost string, authSources *models.AuthSources) (string, erro
return "", err
}

logger.Debug(
"exchanged github actions token for a nullify token",
logger.String("repository", repo),
logger.String("token", token.Token),
)

return token.Token, nil
}

Expand Down
6 changes: 6 additions & 0 deletions internal/dast/dast_local_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ type DASTLocalScanOutput struct {
const ImageName = "dast-local"

func DASTLocalScan(httpClient *http.Client, nullifyHost string, input *DASTLocalScanInput) error {
logger.Info(
"starting local scan",
logger.String("appName", input.AppName),
logger.String("host", input.TargetHost),
)

requestBody, err := json.Marshal(input)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions internal/dast/start_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ type StartScanOutput struct {
}

func StartScan(httpClient *http.Client, nullifyHost string, input *StartScanInput) (*StartScanOutput, error) {
logger.Info(
"starting server side scan",
logger.String("appName", input.AppName),
logger.String("host", input.Host),
)

requestBody, err := json.Marshal(input)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions internal/lib/auth_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ func ParseAuthHeaders(authHeaders []string) (map[string]string, error) {
headerValue := strings.TrimSpace(headerParts[1])
result[headerName] = headerValue
}

return result, nil
}

0 comments on commit db78fbe

Please sign in to comment.