#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 > 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 ```bash
vet scan -D /path/to/repository vet scan -D /path/to/repository

View File

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

View File

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

View File

@ -11,6 +11,11 @@ func PrintBanner(s string) {
fmt.Fprintf(os.Stderr, s) 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) { func PrintError(s string, args ...any) {
msg := fmt.Sprintf(s, args...) msg := fmt.Sprintf(s, args...)
fmt.Fprint(os.Stderr, text.FgRed.Sprint(msg), "\n") fmt.Fprint(os.Stderr, text.FgRed.Sprint(msg), "\n")