Use different creds than the default ones

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2024-04-27 18:22:21 +00:00
parent 349ba1f9e8
commit 402c8b70e2
3 changed files with 15 additions and 12 deletions

View file

@ -15,6 +15,8 @@
package cmd package cmd
import ( import (
"crypto/x509"
"encoding/pem"
"fmt" "fmt"
"os" "os"
"strconv" "strconv"
@ -41,7 +43,7 @@ var (
var credentialsCmd = &cobra.Command{ var credentialsCmd = &cobra.Command{
Use: "credentials", Use: "credentials",
Aliases: []string{"creds"}, 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. Long: `List all available github credentials.
This command is an alias for the garm-cli github credentials command.`, This command is an alias for the garm-cli github credentials command.`,
@ -258,20 +260,20 @@ func init() {
} }
func parsePrivateKeyFromPath(path string) ([]byte, error) { func parsePrivateKeyFromPath(path string) ([]byte, error) {
// if _, err := os.Stat(path); err != nil { if _, err := os.Stat(path); err != nil {
// return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath) return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath)
// } }
keyContents, err := os.ReadFile(path) keyContents, err := os.ReadFile(path)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to read private key file: %w", err) return nil, fmt.Errorf("failed to read private key file: %w", err)
} }
// pemBlock, _ := pem.Decode(keyContents) pemBlock, _ := pem.Decode(keyContents)
// if pemBlock == nil { if pemBlock == nil {
// return nil, fmt.Errorf("failed to decode PEM block") return nil, fmt.Errorf("failed to decode PEM block")
// } }
// if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil { if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil {
// return nil, fmt.Errorf("failed to parse private key: %w", err) return nil, fmt.Errorf("failed to parse private key: %w", err)
// } }
return keyContents, nil return keyContents, nil
} }

View file

@ -585,6 +585,7 @@ type GithubCredentials struct {
Enterprises []Enterprise `json:"enterprises,omitempty"` Enterprises []Enterprise `json:"enterprises,omitempty"`
Endpoint GithubEndpoint `json:"endpoint"` Endpoint GithubEndpoint `json:"endpoint"`
// Do not serialize sensitive info.
CredentialsPayload []byte `json:"-"` CredentialsPayload []byte `json:"-"`
} }

View file

@ -170,7 +170,7 @@ func TestGithubCredentialsFailWhenEndpointDoesntExist() {
slog.Info("Testing error when endpoint doesn't exist") slog.Info("Testing error when endpoint doesn't exist")
createCredsParams := params.CreateGithubCredentialsParams{ createCredsParams := params.CreateGithubCredentialsParams{
Name: dummyCredentialsName, Name: dummyCredentialsName,
Endpoint: defaultEndpointName, Endpoint: "iDontExist.example.com",
Description: "GARM test credentials", Description: "GARM test credentials",
AuthType: params.GithubAuthTypePAT, AuthType: params.GithubAuthTypePAT,
PAT: params.GithubPAT{ PAT: params.GithubPAT{