Skip to content

Commit

Permalink
Use different creds than the default ones
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
  • Loading branch information
gabriel-samfira committed Apr 27, 2024
1 parent 349ba1f commit 402c8b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions cmd/garm-cli/cmd/github_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package cmd

import (
"crypto/x509"
"encoding/pem"
"fmt"
"os"
"strconv"
Expand All @@ -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.`,
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ type GithubCredentials struct {
Enterprises []Enterprise `json:"enterprises,omitempty"`
Endpoint GithubEndpoint `json:"endpoint"`

// Do not serialize sensitive info.
CredentialsPayload []byte `json:"-"`
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/e2e/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 402c8b7

Please sign in to comment.