From 402c8b70e22ccba3b0f6f98da910a88abaf2afc6 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Sat, 27 Apr 2024 18:22:21 +0000 Subject: [PATCH] Use different creds than the default ones Signed-off-by: Gabriel Adrian Samfira --- cmd/garm-cli/cmd/github_credentials.go | 24 +++++++++++++----------- params/params.go | 1 + test/integration/e2e/credentials.go | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/cmd/garm-cli/cmd/github_credentials.go b/cmd/garm-cli/cmd/github_credentials.go index ca345332..5f09a8e4 100644 --- a/cmd/garm-cli/cmd/github_credentials.go +++ b/cmd/garm-cli/cmd/github_credentials.go @@ -15,6 +15,8 @@ package cmd import ( + "crypto/x509" + "encoding/pem" "fmt" "os" "strconv" @@ -41,7 +43,7 @@ var ( var credentialsCmd = &cobra.Command{ Use: "credentials", Aliases: []string{"creds"}, - Short: "List configured credentials", + Short: "List configured credentials. This is an alias for the github credentials command.", Long: `List all available github credentials. This command is an alias for the garm-cli github credentials command.`, @@ -258,20 +260,20 @@ func init() { } func parsePrivateKeyFromPath(path string) ([]byte, error) { - // if _, err := os.Stat(path); err != nil { - // return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath) - // } + if _, err := os.Stat(path); err != nil { + return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath) + } keyContents, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read private key file: %w", err) } - // pemBlock, _ := pem.Decode(keyContents) - // if pemBlock == nil { - // return nil, fmt.Errorf("failed to decode PEM block") - // } - // if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil { - // return nil, fmt.Errorf("failed to parse private key: %w", err) - // } + pemBlock, _ := pem.Decode(keyContents) + if pemBlock == nil { + return nil, fmt.Errorf("failed to decode PEM block") + } + if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil { + return nil, fmt.Errorf("failed to parse private key: %w", err) + } return keyContents, nil } diff --git a/params/params.go b/params/params.go index f9629fc7..b17a2d14 100644 --- a/params/params.go +++ b/params/params.go @@ -585,6 +585,7 @@ type GithubCredentials struct { Enterprises []Enterprise `json:"enterprises,omitempty"` Endpoint GithubEndpoint `json:"endpoint"` + // Do not serialize sensitive info. CredentialsPayload []byte `json:"-"` } diff --git a/test/integration/e2e/credentials.go b/test/integration/e2e/credentials.go index 2ca027c5..67e1d35c 100644 --- a/test/integration/e2e/credentials.go +++ b/test/integration/e2e/credentials.go @@ -170,7 +170,7 @@ func TestGithubCredentialsFailWhenEndpointDoesntExist() { slog.Info("Testing error when endpoint doesn't exist") createCredsParams := params.CreateGithubCredentialsParams{ Name: dummyCredentialsName, - Endpoint: defaultEndpointName, + Endpoint: "iDontExist.example.com", Description: "GARM test credentials", AuthType: params.GithubAuthTypePAT, PAT: params.GithubPAT{