func()

in provider/secret_descriptor.go [323:363]


func (p *SecretDescriptor) validateObjectName(objectName string, objectType string, region string) (err error) {
	var objARN arn.ARN

	// Validate if ARNs
	hasARN := strings.HasPrefix(objectName, "arn:")
	if hasARN {
		objARN, err = arn.Parse(objectName)
		if err != nil {
			return fmt.Errorf("Invalid ARN format in object name: %s", objectName)
		}
	}

	// If has an ARN, validate that it matches the primary region
	if hasARN && objARN.Region != region {
		return fmt.Errorf("ARN region must match region %s: %s", region, objectName)
	}

	// Make sure either objectType is used or a full ARN is specified
	if len(objectType) == 0 && !hasARN {
		return fmt.Errorf("Must use objectType when a full ARN is not specified: %s", objectName)
	}

	// Make sure the ARN is for a supported service
	_, ok := typeMap[objARN.Service]
	if len(objectType) == 0 && !ok {
		return fmt.Errorf("Invalid service in ARN: %s", objARN.Service)
	}

	// Make sure objectType is one we understand
	_, ok = typeMap[objectType]
	if len(objectType) != 0 && (!ok || objectType == "ssm") {
		return fmt.Errorf("Invalid objectType: %s", objectType)
	}

	// If both ARN and objectType are used make sure they agree
	if len(objectType) != 0 && hasARN && typeMap[objectType] != typeMap[objARN.Service] {
		return fmt.Errorf("objectType does not match ARN: %s", objectName)
	}

	return nil
}