in provider/secrets_manager_provider.go [166:204]
func (p *SecretsManagerProvider) isCurrent(
ctx context.Context,
client SecretsManagerClient,
descriptor *SecretDescriptor,
curMap map[string]*v1alpha1.ObjectVersion,
) (cur bool, ver string, err 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.GetObjectVersion(client.IsFailover)) > 0 {
return curVer.Version == descriptor.GetObjectVersion(client.IsFailover), curVer.Version, nil
}
// Lookup the current version information.
rsp, err := client.Client.DescribeSecretWithContext(ctx, &secretsmanager.DescribeSecretInput{SecretId: aws.String(descriptor.GetSecretName(client.IsFailover))})
if err != nil {
return false, curVer.Version, fmt.Errorf("%s: Failed to describe secret %s: %w", client.Region, descriptor.ObjectName, err)
}
// If no label is specified use current, otherwise use the specified label.
label := "AWSCURRENT"
if len(descriptor.GetObjectVersionLabel(client.IsFailover)) > 0 {
label = descriptor.GetObjectVersionLabel(client.IsFailover)
}
// 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.
}