Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for secretGroupID #7

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Concourse resource for secrets stored in IBM Cloud Secrets Manager instances.
- **endpointURL**: _Required_ Endpoint URL of the Secrets Manager instance to connect to, see [secrets manager docs](https://cloud.ibm.com/apidocs/secrets-manager/secrets-manager-v2?code=go#endpoints) for more details.
- **apikey**: _Required_ API key that allows access to read from the respective secrets manager instance.
- **secretName**: _Required_ Name of the secret in the secrets manager instance. This is the name, not the ID of the secret. The secret will be searched for by name through the API.
- **secretGroupID**: _Optional_ ID of the secret group to narrow down the search for the secret.

### Example

Expand Down
7 changes: 4 additions & 3 deletions internal/smr/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ type InConfig struct {
}

type Source struct {
EndpointURL string `json:"endpointURL"`
ApiKey string `json:"apikey"`
SecretName string `json:"secretName"`
EndpointURL string `json:"endpointURL"`
ApiKey string `json:"apikey"`
SecretName string `json:"secretName"`
SecretGroupID string `json:"secretGroupID"`
}

type CheckResult []Version
Expand Down
4 changes: 2 additions & 2 deletions internal/smr/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Check(r io.Reader) error {
return err
}

metadata, err := GetSecretMetaDataBySecretName(*secretsManagerService, config.Source.SecretName)
metadata, err := GetSecretMetaDataBySecretName(*secretsManagerService, config.Source)
if err != nil {
return err
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func In(r io.Reader, target string) error {
return err
}

metadata, err := GetSecretMetaDataBySecretName(*secretsManagerService, config.Source.SecretName)
metadata, err := GetSecretMetaDataBySecretName(*secretsManagerService, config.Source)
if err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions internal/smr/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ func (s *SecretMetadata) Id() (string, error) {
return *s.ID, nil
}

func GetSecretMetaDataBySecretName(service sm.SecretsManagerV2, name string) (*SecretMetadata, error) {
listSecretsOptions := &sm.ListSecretsOptions{
Search: &name,
func GetSecretMetaDataBySecretName(service sm.SecretsManagerV2, source Source) (*SecretMetadata, error) {
listSecretsOptions := &sm.ListSecretsOptions{Search: &source.SecretName}

if source.SecretGroupID != "" {
listSecretsOptions.Groups = append(listSecretsOptions.Groups, source.SecretGroupID)
}

pager, err := service.NewSecretsPager(listSecretsOptions)
Expand All @@ -77,11 +79,11 @@ func GetSecretMetaDataBySecretName(service sm.SecretsManagerV2, name string) (*S
}

if len(results) == 0 {
return nil, fmt.Errorf("cannot find secret with name %q", name)
return nil, fmt.Errorf("cannot find secret with name %q", source.SecretName)
}

if len(results) != 1 {
return nil, fmt.Errorf("more than one secret was found searching for %q", name)
return nil, fmt.Errorf("more than one secret was found searching for %q", source.SecretName)
}

data, err := json.Marshal(results[0])
Expand Down
Loading