Skip to content

Commit

Permalink
vmware - regen embedded sdk (#14133)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored Nov 12, 2021
1 parent 6964085 commit 65b6749
Show file tree
Hide file tree
Showing 47 changed files with 3,546 additions and 1,073 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
package authorizations

import "strings"

type ExpressRouteAuthorizationProvisioningState string

const (
ExpressRouteAuthorizationProvisioningStateFailed ExpressRouteAuthorizationProvisioningState = "Failed"
ExpressRouteAuthorizationProvisioningStateSucceeded ExpressRouteAuthorizationProvisioningState = "Succeeded"
ExpressRouteAuthorizationProvisioningStateUpdating ExpressRouteAuthorizationProvisioningState = "Updating"
)

func PossibleValuesForExpressRouteAuthorizationProvisioningState() []string {
return []string{
string(ExpressRouteAuthorizationProvisioningStateFailed),
string(ExpressRouteAuthorizationProvisioningStateSucceeded),
string(ExpressRouteAuthorizationProvisioningStateUpdating),
}
}

func parseExpressRouteAuthorizationProvisioningState(input string) (*ExpressRouteAuthorizationProvisioningState, error) {
vals := map[string]ExpressRouteAuthorizationProvisioningState{
"failed": ExpressRouteAuthorizationProvisioningStateFailed,
"succeeded": ExpressRouteAuthorizationProvisioningStateSucceeded,
"updating": ExpressRouteAuthorizationProvisioningStateUpdating,
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// otherwise presume it's an undefined value and best-effort it
out := ExpressRouteAuthorizationProvisioningState(input)
return &out, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,120 +7,131 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.ResourceId = AuthorizationId{}

// AuthorizationId is a struct representing the Resource ID for a Authorization
type AuthorizationId struct {
SubscriptionId string
ResourceGroup string
PrivateCloudName string
Name string
SubscriptionId string
ResourceGroupName string
PrivateCloudName string
AuthorizationName string
}

func NewAuthorizationID(subscriptionId, resourceGroup, privateCloudName, name string) AuthorizationId {
// NewAuthorizationID returns a new AuthorizationId struct
func NewAuthorizationID(subscriptionId string, resourceGroupName string, privateCloudName string, authorizationName string) AuthorizationId {
return AuthorizationId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
PrivateCloudName: privateCloudName,
Name: name,
SubscriptionId: subscriptionId,
ResourceGroupName: resourceGroupName,
PrivateCloudName: privateCloudName,
AuthorizationName: authorizationName,
}
}

func (id AuthorizationId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Private Cloud Name %q", id.PrivateCloudName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Authorization", segmentsStr)
}

func (id AuthorizationId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AVS/privateClouds/%s/authorizations/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.PrivateCloudName, id.Name)
}

// ParseAuthorizationID parses a Authorization ID into an AuthorizationId struct
// ParseAuthorizationID parses 'input' into a AuthorizationId
func ParseAuthorizationID(input string) (*AuthorizationId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(AuthorizationId{})
parsed, err := parser.Parse(input, false)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

resourceId := AuthorizationId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}
var ok bool
id := AuthorizationId{}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok {
return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input)
}

if resourceId.PrivateCloudName, err = id.PopSegment("privateClouds"); err != nil {
return nil, err
}
if resourceId.Name, err = id.PopSegment("authorizations"); err != nil {
return nil, err
if id.PrivateCloudName, ok = parsed.Parsed["privateCloudName"]; !ok {
return nil, fmt.Errorf("the segment 'privateCloudName' was not found in the resource id %q", input)
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
if id.AuthorizationName, ok = parsed.Parsed["authorizationName"]; !ok {
return nil, fmt.Errorf("the segment 'authorizationName' was not found in the resource id %q", input)
}

return &resourceId, nil
return &id, nil
}

// ParseAuthorizationIDInsensitively parses an Authorization ID into an AuthorizationId struct, insensitively
// This should only be used to parse an ID for rewriting to a consistent casing,
// the ParseAuthorizationID method should be used instead for validation etc.
// ParseAuthorizationIDInsensitively parses 'input' case-insensitively into a AuthorizationId
// note: this method should only be used for API response data and not user input
func ParseAuthorizationIDInsensitively(input string) (*AuthorizationId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(AuthorizationId{})
parsed, err := parser.Parse(input, true)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

resourceId := AuthorizationId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}
var ok bool
id := AuthorizationId{}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok {
return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input)
}

// find the correct casing for the 'privateClouds' segment
privateCloudsKey := "privateClouds"
for key := range id.Path {
if strings.EqualFold(key, privateCloudsKey) {
privateCloudsKey = key
break
}
if id.PrivateCloudName, ok = parsed.Parsed["privateCloudName"]; !ok {
return nil, fmt.Errorf("the segment 'privateCloudName' was not found in the resource id %q", input)
}
if resourceId.PrivateCloudName, err = id.PopSegment(privateCloudsKey); err != nil {
return nil, err

if id.AuthorizationName, ok = parsed.Parsed["authorizationName"]; !ok {
return nil, fmt.Errorf("the segment 'authorizationName' was not found in the resource id %q", input)
}

// find the correct casing for the 'authorizations' segment
authorizationsKey := "authorizations"
for key := range id.Path {
if strings.EqualFold(key, authorizationsKey) {
authorizationsKey = key
break
}
return &id, nil
}

// ValidateAuthorizationID checks that 'input' can be parsed as a Authorization ID
func ValidateAuthorizationID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}
if resourceId.Name, err = id.PopSegment(authorizationsKey); err != nil {
return nil, err

if _, err := ParseAuthorizationID(v); err != nil {
errors = append(errors, err)
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
return
}

// ID returns the formatted Authorization ID
func (id AuthorizationId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.AVS/privateClouds/%s/authorizations/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.PrivateCloudName, id.AuthorizationName)
}

// Segments returns a slice of Resource ID Segments which comprise this Authorization ID
func (id AuthorizationId) Segments() []resourceids.Segment {
return []resourceids.Segment{
resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"),
resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"),
resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"),
resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"),
resourceids.StaticSegment("staticProviders", "providers", "providers"),
resourceids.ResourceProviderSegment("staticMicrosoftAVS", "Microsoft.AVS", "Microsoft.AVS"),
resourceids.StaticSegment("staticPrivateClouds", "privateClouds", "privateClouds"),
resourceids.UserSpecifiedSegment("privateCloudName", "privateCloudValue"),
resourceids.StaticSegment("staticAuthorizations", "authorizations", "authorizations"),
resourceids.UserSpecifiedSegment("authorizationName", "authorizationValue"),
}
}

return &resourceId, nil
// String returns a human-readable description of this Authorization ID
func (id AuthorizationId) String() string {
components := []string{
fmt.Sprintf("Subscription: %q", id.SubscriptionId),
fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName),
fmt.Sprintf("Private Cloud Name: %q", id.PrivateCloudName),
fmt.Sprintf("Authorization Name: %q", id.AuthorizationName),
}
return fmt.Sprintf("Authorization (%s)", strings.Join(components, "\n"))
}
Loading

0 comments on commit 65b6749

Please sign in to comment.