Skip to content

Commit 8ec4798

Browse files
Use different creds than the default ones
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 349ba1f commit 8ec4798

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

cmd/garm-cli/cmd/github_credentials.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package cmd
1616

1717
import (
18+
"crypto/x509"
19+
"encoding/pem"
1820
"fmt"
1921
"os"
2022
"strconv"
@@ -41,7 +43,7 @@ var (
4143
var credentialsCmd = &cobra.Command{
4244
Use: "credentials",
4345
Aliases: []string{"creds"},
44-
Short: "List configured credentials",
46+
Short: "List configured credentials. This is an alias for the github credentials command.",
4547
Long: `List all available github credentials.
4648
4749
This command is an alias for the garm-cli github credentials command.`,
@@ -258,20 +260,20 @@ func init() {
258260
}
259261

260262
func parsePrivateKeyFromPath(path string) ([]byte, error) {
261-
// if _, err := os.Stat(path); err != nil {
262-
// return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath)
263-
// }
263+
if _, err := os.Stat(path); err != nil {
264+
return nil, fmt.Errorf("private key file not found: %s", credentialsPrivateKeyPath)
265+
}
264266
keyContents, err := os.ReadFile(path)
265267
if err != nil {
266268
return nil, fmt.Errorf("failed to read private key file: %w", err)
267269
}
268-
// pemBlock, _ := pem.Decode(keyContents)
269-
// if pemBlock == nil {
270-
// return nil, fmt.Errorf("failed to decode PEM block")
271-
// }
272-
// if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil {
273-
// return nil, fmt.Errorf("failed to parse private key: %w", err)
274-
// }
270+
pemBlock, _ := pem.Decode(keyContents)
271+
if pemBlock == nil {
272+
return nil, fmt.Errorf("failed to decode PEM block")
273+
}
274+
if _, err := x509.ParsePKCS1PrivateKey(pemBlock.Bytes); err != nil {
275+
return nil, fmt.Errorf("failed to parse private key: %w", err)
276+
}
275277
return keyContents, nil
276278
}
277279

params/params.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ type GithubCredentials struct {
585585
Enterprises []Enterprise `json:"enterprises,omitempty"`
586586
Endpoint GithubEndpoint `json:"endpoint"`
587587

588+
// Do not serialize sensitive info.
588589
CredentialsPayload []byte `json:"-"`
589590
}
590591

test/integration/e2e/credentials.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ func TestGithubCredentialsFailsToDeleteWhenInUse() {
6262

6363
repo := CreateRepo("dummy-owner", "dummy-repo", creds.Name, "superSecret@123BlaBla")
6464
defer func() {
65-
deleteRepo(cli, authToken, repo.ID)
6665
deleteGithubCredentials(cli, authToken, int64(creds.ID))
66+
deleteRepo(cli, authToken, repo.ID)
6767
}()
6868

6969
if err := deleteGithubCredentials(cli, authToken, int64(creds.ID)); err == nil {
@@ -170,7 +170,7 @@ func TestGithubCredentialsFailWhenEndpointDoesntExist() {
170170
slog.Info("Testing error when endpoint doesn't exist")
171171
createCredsParams := params.CreateGithubCredentialsParams{
172172
Name: dummyCredentialsName,
173-
Endpoint: defaultEndpointName,
173+
Endpoint: "iDontExist.example.com",
174174
Description: "GARM test credentials",
175175
AuthType: params.GithubAuthTypePAT,
176176
PAT: params.GithubPAT{

0 commit comments

Comments
 (0)