Skip to content

Commit

Permalink
regen embedded sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry committed Nov 10, 2021
1 parent dc716ed commit 12a8c2b
Show file tree
Hide file tree
Showing 26 changed files with 1,903 additions and 401 deletions.
4 changes: 2 additions & 2 deletions internal/services/maps/maps_account_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func dataSourceMapsAccountRead(d *pluginsdk.ResourceData, meta interface{}) erro

d.SetId(id.ID())

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.AccountName)
d.Set("resource_group_name", id.ResourceGroupName)

if model := resp.Model; model != nil {
d.Set("sku_name", model.Sku.Name)
Expand Down
4 changes: 2 additions & 2 deletions internal/services/maps/maps_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func resourceMapsAccountRead(d *pluginsdk.ResourceData, meta interface{}) error
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.AccountName)
d.Set("resource_group_name", id.ResourceGroupName)

if model := resp.Model; model != nil {
d.Set("sku_name", model.Sku.Name)
Expand Down
100 changes: 100 additions & 0 deletions internal/services/maps/sdk/2021-02-01/accounts/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package accounts

import "strings"

type CreatedByType string

const (
Expand All @@ -9,24 +11,122 @@ const (
CreatedByTypeUser CreatedByType = "User"
)

func PossibleValuesForCreatedByType() []string {
return []string{
"Application",
"Key",
"ManagedIdentity",
"User",
}
}

func parseCreatedByType(input string) (*CreatedByType, error) {
vals := map[string]CreatedByType{
"application": "Application",
"key": "Key",
"managedidentity": "ManagedIdentity",
"user": "User",
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// it could be a new value - best effort convert this
v := input

out := CreatedByType(v)
return &out, nil
}

type KeyType string

const (
KeyTypePrimary KeyType = "primary"
KeyTypeSecondary KeyType = "secondary"
)

func PossibleValuesForKeyType() []string {
return []string{
"primary",
"secondary",
}
}

func parseKeyType(input string) (*KeyType, error) {
vals := map[string]KeyType{
"primary": "primary",
"secondary": "secondary",
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// it could be a new value - best effort convert this
v := input

out := KeyType(v)
return &out, nil
}

type Kind string

const (
KindGenOne Kind = "Gen1"
KindGenTwo Kind = "Gen2"
)

func PossibleValuesForKind() []string {
return []string{
"Gen1",
"Gen2",
}
}

func parseKind(input string) (*Kind, error) {
vals := map[string]Kind{
"genone": "Gen1",
"gentwo": "Gen2",
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// it could be a new value - best effort convert this
v := input

out := Kind(v)
return &out, nil
}

type Name string

const (
NameGTwo Name = "G2"
NameSOne Name = "S1"
NameSZero Name = "S0"
)

func PossibleValuesForName() []string {
return []string{
"G2",
"S1",
"S0",
}
}

func parseName(input string) (*Name, error) {
vals := map[string]Name{
"gtwo": "G2",
"sone": "S1",
"szero": "S0",
}
if v, ok := vals[strings.ToLower(input)]; ok {
return &v, nil
}

// it could be a new value - best effort convert this
v := input

out := Name(v)
return &out, nil
}
142 changes: 79 additions & 63 deletions internal/services/maps/sdk/2021-02-01/accounts/id_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,118 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.ResourceId = AccountId{}

// AccountId is a struct representing the Resource ID for a Account
type AccountId struct {
SubscriptionId string
ResourceGroup string
Name string
SubscriptionId string
ResourceGroupName string
AccountName string
}

func NewAccountID(subscriptionId, resourceGroup, name string) AccountId {
// NewAccountID returns a new AccountId struct
func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId {
return AccountId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
Name: name,
SubscriptionId: subscriptionId,
ResourceGroupName: resourceGroupName,
AccountName: accountName,
}
}

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

func (id AccountId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Maps/accounts/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.Name)
}

// ParseAccountID parses a Account ID into an AccountId struct
// ParseAccountID parses 'input' into a AccountId
func ParseAccountID(input string) (*AccountId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(AccountId{})
parsed, err := parser.Parse(input, false)
if err != nil {
return nil, err
}

resourceId := AccountId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}
var ok bool
id := AccountId{}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' 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.Name, err = id.PopSegment("accounts"); err != nil {
return nil, err
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 err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
if id.AccountName, ok = parsed.Parsed["accountName"]; !ok {
return nil, fmt.Errorf("the segment 'accountName' was not found in the resource id %q", input)
}

return &resourceId, nil
return &id, nil
}

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

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

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.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' 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.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.AccountName, ok = parsed.Parsed["accountName"]; !ok {
return nil, fmt.Errorf("the segment 'accountName' was not found in the resource id %q", input)
}

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

// ValidateAccountID checks that 'input' can be parsed as a Account ID
func ValidateAccountID(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(accountsKey); err != nil {
return nil, err

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

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

// ID returns the formatted Account ID
func (id AccountId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Maps/accounts/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName)
}

// Segments returns a slice of Resource ID Segments which comprise this Account ID
func (id AccountId) Segments() []resourceids.Segment {
return []resourceids.Segment{
resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"),
resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"),
resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"),
resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"),
resourceids.StaticSegment("providers", "providers", "providers"),
resourceids.ResourceProviderSegment("microsoftMaps", "Microsoft.Maps", "Microsoft.Maps"),
resourceids.StaticSegment("accounts", "accounts", "accounts"),
resourceids.UserSpecifiedSegment("accountName", "accountValue"),
}
}

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

0 comments on commit 12a8c2b

Please sign in to comment.