|
| 1 | +package nginxapikey |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strings" |
| 6 | + |
| 7 | + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" |
| 8 | + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" |
| 9 | +) |
| 10 | + |
| 11 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 12 | +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. |
| 13 | + |
| 14 | +func init() { |
| 15 | + recaser.RegisterResourceId(&ApiKeyId{}) |
| 16 | +} |
| 17 | + |
| 18 | +var _ resourceids.ResourceId = &ApiKeyId{} |
| 19 | + |
| 20 | +// ApiKeyId is a struct representing the Resource ID for a Api Key |
| 21 | +type ApiKeyId struct { |
| 22 | + SubscriptionId string |
| 23 | + ResourceGroupName string |
| 24 | + NginxDeploymentName string |
| 25 | + ApiKeyName string |
| 26 | +} |
| 27 | + |
| 28 | +// NewApiKeyID returns a new ApiKeyId struct |
| 29 | +func NewApiKeyID(subscriptionId string, resourceGroupName string, nginxDeploymentName string, apiKeyName string) ApiKeyId { |
| 30 | + return ApiKeyId{ |
| 31 | + SubscriptionId: subscriptionId, |
| 32 | + ResourceGroupName: resourceGroupName, |
| 33 | + NginxDeploymentName: nginxDeploymentName, |
| 34 | + ApiKeyName: apiKeyName, |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// ParseApiKeyID parses 'input' into a ApiKeyId |
| 39 | +func ParseApiKeyID(input string) (*ApiKeyId, error) { |
| 40 | + parser := resourceids.NewParserFromResourceIdType(&ApiKeyId{}) |
| 41 | + parsed, err := parser.Parse(input, false) |
| 42 | + if err != nil { |
| 43 | + return nil, fmt.Errorf("parsing %q: %+v", input, err) |
| 44 | + } |
| 45 | + |
| 46 | + id := ApiKeyId{} |
| 47 | + if err = id.FromParseResult(*parsed); err != nil { |
| 48 | + return nil, err |
| 49 | + } |
| 50 | + |
| 51 | + return &id, nil |
| 52 | +} |
| 53 | + |
| 54 | +// ParseApiKeyIDInsensitively parses 'input' case-insensitively into a ApiKeyId |
| 55 | +// note: this method should only be used for API response data and not user input |
| 56 | +func ParseApiKeyIDInsensitively(input string) (*ApiKeyId, error) { |
| 57 | + parser := resourceids.NewParserFromResourceIdType(&ApiKeyId{}) |
| 58 | + parsed, err := parser.Parse(input, true) |
| 59 | + if err != nil { |
| 60 | + return nil, fmt.Errorf("parsing %q: %+v", input, err) |
| 61 | + } |
| 62 | + |
| 63 | + id := ApiKeyId{} |
| 64 | + if err = id.FromParseResult(*parsed); err != nil { |
| 65 | + return nil, err |
| 66 | + } |
| 67 | + |
| 68 | + return &id, nil |
| 69 | +} |
| 70 | + |
| 71 | +func (id *ApiKeyId) FromParseResult(input resourceids.ParseResult) error { |
| 72 | + var ok bool |
| 73 | + |
| 74 | + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { |
| 75 | + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) |
| 76 | + } |
| 77 | + |
| 78 | + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { |
| 79 | + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) |
| 80 | + } |
| 81 | + |
| 82 | + if id.NginxDeploymentName, ok = input.Parsed["nginxDeploymentName"]; !ok { |
| 83 | + return resourceids.NewSegmentNotSpecifiedError(id, "nginxDeploymentName", input) |
| 84 | + } |
| 85 | + |
| 86 | + if id.ApiKeyName, ok = input.Parsed["apiKeyName"]; !ok { |
| 87 | + return resourceids.NewSegmentNotSpecifiedError(id, "apiKeyName", input) |
| 88 | + } |
| 89 | + |
| 90 | + return nil |
| 91 | +} |
| 92 | + |
| 93 | +// ValidateApiKeyID checks that 'input' can be parsed as a Api Key ID |
| 94 | +func ValidateApiKeyID(input interface{}, key string) (warnings []string, errors []error) { |
| 95 | + v, ok := input.(string) |
| 96 | + if !ok { |
| 97 | + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) |
| 98 | + return |
| 99 | + } |
| 100 | + |
| 101 | + if _, err := ParseApiKeyID(v); err != nil { |
| 102 | + errors = append(errors, err) |
| 103 | + } |
| 104 | + |
| 105 | + return |
| 106 | +} |
| 107 | + |
| 108 | +// ID returns the formatted Api Key ID |
| 109 | +func (id ApiKeyId) ID() string { |
| 110 | + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Nginx.NginxPlus/nginxDeployments/%s/apiKeys/%s" |
| 111 | + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.NginxDeploymentName, id.ApiKeyName) |
| 112 | +} |
| 113 | + |
| 114 | +// Segments returns a slice of Resource ID Segments which comprise this Api Key ID |
| 115 | +func (id ApiKeyId) Segments() []resourceids.Segment { |
| 116 | + return []resourceids.Segment{ |
| 117 | + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), |
| 118 | + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), |
| 119 | + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), |
| 120 | + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), |
| 121 | + resourceids.StaticSegment("staticProviders", "providers", "providers"), |
| 122 | + resourceids.ResourceProviderSegment("staticNginxNginxPlus", "Nginx.NginxPlus", "Nginx.NginxPlus"), |
| 123 | + resourceids.StaticSegment("staticNginxDeployments", "nginxDeployments", "nginxDeployments"), |
| 124 | + resourceids.UserSpecifiedSegment("nginxDeploymentName", "nginxDeploymentName"), |
| 125 | + resourceids.StaticSegment("staticApiKeys", "apiKeys", "apiKeys"), |
| 126 | + resourceids.UserSpecifiedSegment("apiKeyName", "apiKeyName"), |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +// String returns a human-readable description of this Api Key ID |
| 131 | +func (id ApiKeyId) String() string { |
| 132 | + components := []string{ |
| 133 | + fmt.Sprintf("Subscription: %q", id.SubscriptionId), |
| 134 | + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), |
| 135 | + fmt.Sprintf("Nginx Deployment Name: %q", id.NginxDeploymentName), |
| 136 | + fmt.Sprintf("Api Key Name: %q", id.ApiKeyName), |
| 137 | + } |
| 138 | + return fmt.Sprintf("Api Key (%s)", strings.Join(components, "\n")) |
| 139 | +} |
0 commit comments