github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runners/secrets/common.go (about) 1 package secrets 2 3 import ( 4 "strings" 5 6 "github.com/ActiveState/cli/internal/keypairs" 7 "github.com/ActiveState/cli/internal/locale" 8 "github.com/ActiveState/cli/pkg/platform/authentication" 9 "github.com/ActiveState/cli/pkg/project" 10 ) 11 12 func getSecret(proj *project.Project, namespace string, cfg keypairs.Configurable, auth *authentication.Auth) (*project.Secret, error) { 13 n := strings.Split(namespace, ".") 14 if len(n) != 2 { 15 return nil, locale.NewInputError("secrets_err_invalid_namespace", "", namespace) 16 } 17 18 secretScope, err := project.NewSecretScope(n[0]) 19 if err != nil { 20 return nil, err 21 } 22 secretName := n[1] 23 24 return proj.InitSecret(secretName, secretScope, cfg, auth), nil 25 } 26 27 func getSecretWithValue(proj *project.Project, name string, cfg keypairs.Configurable, auth *authentication.Auth) (*project.Secret, *string, error) { 28 secret, err := getSecret(proj, name, cfg, auth) 29 if err != nil { 30 return nil, nil, err 31 } 32 33 val, err := secret.ValueOrNil() 34 if err != nil { 35 return nil, nil, err 36 } 37 38 return secret, val, nil 39 }