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(auth): auto detect API Url during OAuth authentication #5601

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 6 additions & 10 deletions cliv2/cmd/cliv2/logheader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"regexp"
"strings"

"github.com/snyk/go-application-framework/pkg/local_workflows/config_utils"

"github.com/snyk/go-application-framework/pkg/auth"
"github.com/snyk/go-application-framework/pkg/configuration"
localworkflows "github.com/snyk/go-application-framework/pkg/local_workflows"
Expand Down Expand Up @@ -81,8 +83,6 @@ func getFipsStatus(config configuration.Configuration) string {
}

func writeLogHeader(config configuration.Configuration, networkAccess networking.NetworkAccess) {
keys := []string{configuration.API_URL, configuration.AUTHENTICATION_TOKEN, configuration.AUTHENTICATION_BEARER_TOKEN, configuration.ORGANIZATION}

authorization, _, userAgent := logHeaderAuthorizationInfo(config, networkAccess)

org := config.GetString(configuration.ORGANIZATION)
Expand Down Expand Up @@ -127,16 +127,12 @@ func writeLogHeader(config configuration.Configuration, networkAccess networking
tablePrint(" fips", fipsEnabled)
tablePrint("Checks", "")

checkCount := 0
for _, key := range keys {
keysSpecified := config.GetAllKeysThatContainValues(key)
if len(keysSpecified) > 1 {
checkCount++
tablePrint(" Configuration", fmt.Sprintf("Possible unexpected behavior, the following configuration values might override each other %s", strings.ToUpper(strings.Join(keysSpecified, ", "))))
}
sanityCheckResults := config_utils.CheckSanity(config)
for _, result := range sanityCheckResults {
tablePrint(" Configuration", result.Description)
}

if checkCount == 0 {
if len(sanityCheckResults) == 0 {
tablePrint(" Configuration", "all good")
}
}
15 changes: 15 additions & 0 deletions cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func getErrorFromWorkFlowData(engine workflow.Engine, data []workflow.Data) erro
func sendAnalytics(analytics analytics.Analytics, debugLogger *zerolog.Logger) {
debugLogger.Print("Sending Analytics")

analytics.SetApiUrl(globalConfiguration.GetString(configuration.API_URL))

res, err := analytics.Send()
if err != nil {
debugLogger.Err(err).Msg("Failed to send Analytics")
Expand Down Expand Up @@ -312,6 +314,17 @@ func runCodeTestCommand(cmd *cobra.Command, args []string) error {
return runCommand(cmd, args)
}

func runAuthCommand(cmd *cobra.Command, args []string) error {
err := runCommand(cmd, args)

reloadError := globalConfiguration.ReloadConfig()
if reloadError != nil {
globalLogger.Err(reloadError).Msg("Failed to reload the configuration after authentication.")
}

return err
}

func getGlobalFLags() *pflag.FlagSet {
globalConfigurationOptions := workflow.GetGlobalConfiguration()
globalFLags := workflow.FlagsetFromConfigurationOptions(globalConfigurationOptions)
Expand Down Expand Up @@ -374,6 +387,8 @@ func createCommandsForWorkflows(rootCommand *cobra.Command, engine workflow.Engi

// use the special run command to ensure that the non-standard behavior of the command can be kept
parentCommand.RunE = runCodeTestCommand
} else if currentCommandString == "auth" {
parentCommand.RunE = runAuthCommand
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cliv2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/snyk/cli-extension-sbom v0.0.0-20241016065306-0df2be5b3b8f
github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069
github.com/snyk/go-application-framework v0.0.0-20241128111948-07c460117921
github.com/snyk/go-application-framework v0.0.0-20241202122446-a1ff367a586f
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65
github.com/snyk/snyk-iac-capture v0.6.5
github.com/snyk/snyk-ls v0.0.0-20241128161444-157e462bd309
Expand Down
4 changes: 2 additions & 2 deletions cliv2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,8 @@ github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7 h1:Zn5BcV76oFAb
github.com/snyk/container-cli v0.0.0-20240821111304-7ca1c415a5d7/go.mod h1:38w+dcAQp9eG3P5t2eNS9eG0reut10AeJjLv5lJ5lpM=
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069 h1:Oj/BJAEMEuBjTAQ72UYB4tR0IZKOB2ZtdDnAnJDL1BM=
github.com/snyk/error-catalog-golang-public v0.0.0-20241030160523-0aa643bb7069/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20241128111948-07c460117921 h1:9rBEB8Zfcgr3n8/1owhcrS+K3Ry+1XOcj7xlGojvr2s=
github.com/snyk/go-application-framework v0.0.0-20241128111948-07c460117921/go.mod h1:GekIT38VeZQiDw/Ot9Qn0s2kxVR1TXMw6gcaaAiKsVg=
github.com/snyk/go-application-framework v0.0.0-20241202122446-a1ff367a586f h1:eNu5W0dQaRuD4epXxEtwE+CZvY/fgX62RkPfQsv2V/c=
github.com/snyk/go-application-framework v0.0.0-20241202122446-a1ff367a586f/go.mod h1:GekIT38VeZQiDw/Ot9Qn0s2kxVR1TXMw6gcaaAiKsVg=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65 h1:CEQuYv0Go6MEyRCD3YjLYM2u3Oxkx8GpCpFBd4rUTUk=
github.com/snyk/go-httpauth v0.0.0-20240307114523-1f5ea3f55c65/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/snyk/policy-engine v0.31.3 h1:FepCg6QN/X8uvxYjF+WwB2aiBPJB+NENDgKQeI/FwLg=
Expand Down
Loading