#7: Show success msg for auth verification

This commit is contained in:
abhisek 2023-03-09 23:00:49 +05:30
parent b9530c0fbe
commit 8097829f54
No known key found for this signature in database
GPG Key ID: CB92A4990C02A88F
4 changed files with 23 additions and 4 deletions

View File

@ -55,9 +55,16 @@ vet auth configure
```
> Insights API is used to enrich OSS packages with meta-data for rich query and policy
> decisions
> decisions. Alternatively, the API key can be passed through environment
> variable `VET_API_KEY`
Run `vet` to identify risks
Verify authentication token is valid
```bash
vet auth verify
```
Run `vet` to identify risks in a source repository
```bash
vet scan -D /path/to/repository

View File

@ -10,6 +10,7 @@ import (
"golang.org/x/term"
"github.com/safedep/vet/internal/auth"
"github.com/safedep/vet/internal/ui"
)
var (
@ -76,6 +77,7 @@ func verifyAuthCommand() *cobra.Command {
ControlPlaneApiUrl: authControlPlaneApiBaseUrl,
}))
ui.PrintSuccess("Authentication key is valid!")
return nil
},
}

View File

@ -10,8 +10,9 @@ import (
)
const (
apiUrlEnvKey = "VET_INSIGHTS_API_URL"
apiKeyEnvKey = "VET_INSIGHTS_API_KEY"
apiUrlEnvKey = "VET_INSIGHTS_API_URL"
apiKeyEnvKey = "VET_INSIGHTS_API_KEY"
apiKeyAlternateEnvKey = "VET_API_KEY"
defaultApiUrl = "https://api.safedep.io/insights/v1"
defaultControlPlaneApiUrl = "https://api.safedep.io/control-plane/v1"
@ -61,6 +62,10 @@ func ApiKey() string {
return key
}
if key, ok := os.LookupEnv(apiKeyAlternateEnvKey); ok {
return key
}
if globalConfig != nil {
return globalConfig.ApiKey
}

View File

@ -11,6 +11,11 @@ func PrintBanner(s string) {
fmt.Fprintf(os.Stderr, s)
}
func PrintSuccess(s string, args ...any) {
msg := fmt.Sprintf(s, args...)
fmt.Fprint(os.Stderr, text.FgGreen.Sprint(msg), "\n")
}
func PrintError(s string, args ...any) {
msg := fmt.Sprintf(s, args...)
fmt.Fprint(os.Stderr, text.FgRed.Sprint(msg), "\n")