in provider/secrets_manager_provider.go [115:152]
func (p *SecretsManagerProvider) isCurrent(
ctx context.Context,
descriptor *SecretDescriptor,
curMap map[string]*v1alpha1.ObjectVersion,
) (cur bool, ver string, e error) {
// If we don't have this version, it is not current.
curVer := curMap[descriptor.GetFileName()]
if curVer == nil {
return false, "", nil
}
// If the secret is pinned to a version see if that is what we have.
if len(descriptor.ObjectVersion) > 0 {
return curVer.Version == descriptor.ObjectVersion, curVer.Version, nil
}
// Lookup the current version information.
rsp, err := p.client.DescribeSecretWithContext(ctx, &secretsmanager.DescribeSecretInput{SecretId: aws.String(descriptor.ObjectName)})
if err != nil {
return false, curVer.Version, fmt.Errorf("Failed to describe secret %s: %s", descriptor.ObjectName, err.Error())
}
// If no label is specified use current, otherwise use the specified label.
label := "AWSCURRENT"
if len(descriptor.ObjectVersionLabel) > 0 {
label = descriptor.ObjectVersionLabel
}
// Linear search for desired label in the list of labels on current version.
stages := rsp.VersionIdsToStages[curVer.Version]
hasLabel := false
for i := 0; i < len(stages) && !hasLabel; i++ {
hasLabel = *(stages[i]) == label
}
return hasLabel, curVer.Version, nil // If the current version has the desired label, it is current.
}