github.com/adevinta/maiao@v0.0.0-20240318133227-b6f9656b5e07/pkg/github/credentials.go (about) 1 package gh 2 3 import ( 4 "os" 5 6 "github.com/99designs/keyring" 7 "github.com/adevinta/maiao/pkg/credentials" 8 ) 9 10 // DefaultCredentialGetter implements retrieving credentials from a netrc formatted 11 // file, with a location of ~/.netrc 12 var DefaultCredentialGetter credentials.CredentialGetter = defaultCredentials() 13 14 func defaultCredentials() credentials.CredentialGetter { 15 getters := []credentials.CredentialGetter{ 16 &credentials.EnvToken{PasswordKey: "GITHUB_TOKEN"}, 17 &credentials.Netrc{}, 18 &credentials.GitCredentials{GitPath: "git"}, 19 } 20 if os.Getenv("MAIAO_EXPERIMENTAL_CREDENTIALS") == "true" { 21 getters = append(getters, 22 credentials.MustNewKeyring(keyring.Config{ 23 ServiceName: "maiao", 24 PassPrefix: "maiao/", 25 KeychainTrustApplication: true, 26 KeychainSynchronizable: true, 27 }), 28 ) 29 } 30 return credentials.ChainCredentialGetter(getters) 31 }