diff --git a/resource-manager/datadog/2023-01-01/createresource/README.md b/resource-manager/datadog/2023-01-01/createresource/README.md index 2ff09463f2a..028e663bbe4 100644 --- a/resource-manager/datadog/2023-01-01/createresource/README.md +++ b/resource-manager/datadog/2023-01-01/createresource/README.md @@ -43,11 +43,12 @@ if model := read.Model; model != nil { ctx := context.TODO() id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") -read, err := client.CreationSupportedList(ctx, id, createresource.DefaultCreationSupportedListOperationOptions()) +// alternatively `client.CreationSupportedList(ctx, id, createresource.DefaultCreationSupportedListOperationOptions())` can be used to do batched pagination +items, err := client.CreationSupportedListComplete(ctx, id, createresource.DefaultCreationSupportedListOperationOptions()) if err != nil { // handle the error } -if model := read.Model; model != nil { - // do something with the model/response object +for _, item := range items { + // do something } ``` diff --git a/resource-manager/datadog/2023-01-01/createresource/method_creationsupportedlist.go b/resource-manager/datadog/2023-01-01/createresource/method_creationsupportedlist.go index 41b7075e70f..5d480a660e4 100644 --- a/resource-manager/datadog/2023-01-01/createresource/method_creationsupportedlist.go +++ b/resource-manager/datadog/2023-01-01/createresource/method_creationsupportedlist.go @@ -16,7 +16,12 @@ import ( type CreationSupportedListOperationResponse struct { HttpResponse *http.Response OData *odata.OData - Model *CreateResourceSupportedResponseList + Model *[]CreateResourceSupportedResponse +} + +type CreationSupportedListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CreateResourceSupportedResponse } type CreationSupportedListOperationOptions struct { @@ -47,6 +52,18 @@ func (o CreationSupportedListOperationOptions) ToQuery() *client.QueryParams { return &out } +type CreationSupportedListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *CreationSupportedListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + // CreationSupportedList ... func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions) (result CreationSupportedListOperationResponse, err error) { opts := client.RequestOptions{ @@ -56,6 +73,7 @@ func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id comm }, HttpMethod: http.MethodGet, OptionsObject: options, + Pager: &CreationSupportedListCustomPager{}, Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/subscriptionStatuses", id.ID()), } @@ -65,7 +83,7 @@ func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id comm } var resp *client.Response - resp, err = req.Execute(ctx) + resp, err = req.ExecutePaged(ctx) if resp != nil { result.OData = resp.OData result.HttpResponse = resp.Response @@ -74,11 +92,44 @@ func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id comm return } - var model CreateResourceSupportedResponseList - result.Model = &model - if err = resp.Unmarshal(result.Model); err != nil { + var values struct { + Values *[]CreateResourceSupportedResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { return } + result.Model = values.Values + + return +} + +// CreationSupportedListComplete retrieves all the results into a single object +func (c CreateResourceClient) CreationSupportedListComplete(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions) (CreationSupportedListCompleteResult, error) { + return c.CreationSupportedListCompleteMatchingPredicate(ctx, id, options, CreateResourceSupportedResponseOperationPredicate{}) +} + +// CreationSupportedListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CreateResourceClient) CreationSupportedListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions, predicate CreateResourceSupportedResponseOperationPredicate) (result CreationSupportedListCompleteResult, err error) { + items := make([]CreateResourceSupportedResponse, 0) + + resp, err := c.CreationSupportedList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = CreationSupportedListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } return } diff --git a/resource-manager/datadog/2023-01-01/createresource/predicates.go b/resource-manager/datadog/2023-01-01/createresource/predicates.go new file mode 100644 index 00000000000..6d0aee3581f --- /dev/null +++ b/resource-manager/datadog/2023-01-01/createresource/predicates.go @@ -0,0 +1,12 @@ +package createresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateResourceSupportedResponseOperationPredicate struct { +} + +func (p CreateResourceSupportedResponseOperationPredicate) Matches(input CreateResourceSupportedResponse) bool { + + return true +} diff --git a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/README.md b/resource-manager/datadog/2023-01-01/monitoredsubscriptions/README.md index 33a20049004..0ca437ecc75 100644 --- a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/README.md +++ b/resource-manager/datadog/2023-01-01/monitoredsubscriptions/README.md @@ -71,12 +71,13 @@ if model := read.Model; model != nil { ctx := context.TODO() id := monitoredsubscriptions.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") -read, err := client.List(ctx, id) +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) if err != nil { // handle the error } -if model := read.Model; model != nil { - // do something with the model/response object +for _, item := range items { + // do something } ``` diff --git a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/method_list.go b/resource-manager/datadog/2023-01-01/monitoredsubscriptions/method_list.go index dc41d74e5d3..0b2feef2399 100644 --- a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/method_list.go +++ b/resource-manager/datadog/2023-01-01/monitoredsubscriptions/method_list.go @@ -15,7 +15,24 @@ import ( type ListOperationResponse struct { HttpResponse *http.Response OData *odata.OData - Model *MonitoredSubscriptionPropertiesList + Model *[]MonitoredSubscriptionProperties +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MonitoredSubscriptionProperties +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink } // List ... @@ -26,6 +43,7 @@ func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (r http.StatusOK, }, HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, Path: fmt.Sprintf("%s/monitoredSubscriptions", id.ID()), } @@ -35,7 +53,7 @@ func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (r } var resp *client.Response - resp, err = req.Execute(ctx) + resp, err = req.ExecutePaged(ctx) if resp != nil { result.OData = resp.OData result.HttpResponse = resp.Response @@ -44,11 +62,44 @@ func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (r return } - var model MonitoredSubscriptionPropertiesList - result.Model = &model - if err = resp.Unmarshal(result.Model); err != nil { + var values struct { + Values *[]MonitoredSubscriptionProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { return } + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MonitoredSubscriptionsClient) ListComplete(ctx context.Context, id MonitorId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, MonitoredSubscriptionPropertiesOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MonitoredSubscriptionsClient) ListCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate MonitoredSubscriptionPropertiesOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MonitoredSubscriptionProperties, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } return } diff --git a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/predicates.go b/resource-manager/datadog/2023-01-01/monitoredsubscriptions/predicates.go new file mode 100644 index 00000000000..e2d724249cb --- /dev/null +++ b/resource-manager/datadog/2023-01-01/monitoredsubscriptions/predicates.go @@ -0,0 +1,27 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredSubscriptionPropertiesOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p MonitoredSubscriptionPropertiesOperationPredicate) Matches(input MonitoredSubscriptionProperties) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/agreements/README.md b/resource-manager/datadog/2023-10-20/agreements/README.md new file mode 100644 index 00000000000..a597dd53b9e --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/README.md @@ -0,0 +1,59 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/agreements` Documentation + +The `agreements` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/agreements" +``` + + +### Client Initialization + +```go +client := agreements.NewAgreementsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AgreementsClient.MarketplaceAgreementsCreateOrUpdate` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := agreements.DatadogAgreementResource{ + // ... +} + + +read, err := client.MarketplaceAgreementsCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AgreementsClient.MarketplaceAgreementsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.MarketplaceAgreementsList(ctx, id)` can be used to do batched pagination +items, err := client.MarketplaceAgreementsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/agreements/client.go b/resource-manager/datadog/2023-10-20/agreements/client.go new file mode 100644 index 00000000000..8093cc0b5c0 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/client.go @@ -0,0 +1,26 @@ +package agreements + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AgreementsClient struct { + Client *resourcemanager.Client +} + +func NewAgreementsClientWithBaseURI(sdkApi sdkEnv.Api) (*AgreementsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "agreements", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AgreementsClient: %+v", err) + } + + return &AgreementsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/agreements/method_marketplaceagreementscreateorupdate.go b/resource-manager/datadog/2023-10-20/agreements/method_marketplaceagreementscreateorupdate.go new file mode 100644 index 00000000000..6deef30408d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/method_marketplaceagreementscreateorupdate.go @@ -0,0 +1,59 @@ +package agreements + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MarketplaceAgreementsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatadogAgreementResource +} + +// MarketplaceAgreementsCreateOrUpdate ... +func (c AgreementsClient) MarketplaceAgreementsCreateOrUpdate(ctx context.Context, id commonids.SubscriptionId, input DatadogAgreementResource) (result MarketplaceAgreementsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/agreements/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DatadogAgreementResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/agreements/method_marketplaceagreementslist.go b/resource-manager/datadog/2023-10-20/agreements/method_marketplaceagreementslist.go new file mode 100644 index 00000000000..be05666d6c2 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/method_marketplaceagreementslist.go @@ -0,0 +1,106 @@ +package agreements + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MarketplaceAgreementsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatadogAgreementResource +} + +type MarketplaceAgreementsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatadogAgreementResource +} + +type MarketplaceAgreementsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MarketplaceAgreementsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MarketplaceAgreementsList ... +func (c AgreementsClient) MarketplaceAgreementsList(ctx context.Context, id commonids.SubscriptionId) (result MarketplaceAgreementsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &MarketplaceAgreementsListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/agreements", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatadogAgreementResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MarketplaceAgreementsListComplete retrieves all the results into a single object +func (c AgreementsClient) MarketplaceAgreementsListComplete(ctx context.Context, id commonids.SubscriptionId) (MarketplaceAgreementsListCompleteResult, error) { + return c.MarketplaceAgreementsListCompleteMatchingPredicate(ctx, id, DatadogAgreementResourceOperationPredicate{}) +} + +// MarketplaceAgreementsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AgreementsClient) MarketplaceAgreementsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DatadogAgreementResourceOperationPredicate) (result MarketplaceAgreementsListCompleteResult, err error) { + items := make([]DatadogAgreementResource, 0) + + resp, err := c.MarketplaceAgreementsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MarketplaceAgreementsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/agreements/model_datadogagreementproperties.go b/resource-manager/datadog/2023-10-20/agreements/model_datadogagreementproperties.go new file mode 100644 index 00000000000..d4a9321c3a2 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/model_datadogagreementproperties.go @@ -0,0 +1,33 @@ +package agreements + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogAgreementProperties struct { + Accepted *bool `json:"accepted,omitempty"` + LicenseTextLink *string `json:"licenseTextLink,omitempty"` + Plan *string `json:"plan,omitempty"` + PrivacyPolicyLink *string `json:"privacyPolicyLink,omitempty"` + Product *string `json:"product,omitempty"` + Publisher *string `json:"publisher,omitempty"` + RetrieveDatetime *string `json:"retrieveDatetime,omitempty"` + Signature *string `json:"signature,omitempty"` +} + +func (o *DatadogAgreementProperties) GetRetrieveDatetimeAsTime() (*time.Time, error) { + if o.RetrieveDatetime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.RetrieveDatetime, "2006-01-02T15:04:05Z07:00") +} + +func (o *DatadogAgreementProperties) SetRetrieveDatetimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.RetrieveDatetime = &formatted +} diff --git a/resource-manager/datadog/2023-10-20/agreements/model_datadogagreementresource.go b/resource-manager/datadog/2023-10-20/agreements/model_datadogagreementresource.go new file mode 100644 index 00000000000..955594e4a90 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/model_datadogagreementresource.go @@ -0,0 +1,16 @@ +package agreements + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogAgreementResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatadogAgreementProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/agreements/predicates.go b/resource-manager/datadog/2023-10-20/agreements/predicates.go new file mode 100644 index 00000000000..de8de760948 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/predicates.go @@ -0,0 +1,27 @@ +package agreements + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogAgreementResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatadogAgreementResourceOperationPredicate) Matches(input DatadogAgreementResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/agreements/version.go b/resource-manager/datadog/2023-10-20/agreements/version.go new file mode 100644 index 00000000000..3a03e436776 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/agreements/version.go @@ -0,0 +1,10 @@ +package agreements + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/agreements/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/apikey/README.md b/resource-manager/datadog/2023-10-20/apikey/README.md new file mode 100644 index 00000000000..1f1ed0048c4 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/apikey` Documentation + +The `apikey` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/apikey" +``` + + +### Client Initialization + +```go +client := apikey.NewApiKeyClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ApiKeyClient.MonitorsGetDefaultKey` + +```go +ctx := context.TODO() +id := apikey.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +read, err := client.MonitorsGetDefaultKey(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ApiKeyClient.MonitorsListApiKeys` + +```go +ctx := context.TODO() +id := apikey.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.MonitorsListApiKeys(ctx, id)` can be used to do batched pagination +items, err := client.MonitorsListApiKeysComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ApiKeyClient.MonitorsSetDefaultKey` + +```go +ctx := context.TODO() +id := apikey.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +payload := apikey.DatadogApiKey{ + // ... +} + + +read, err := client.MonitorsSetDefaultKey(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/datadog/2023-10-20/apikey/client.go b/resource-manager/datadog/2023-10-20/apikey/client.go new file mode 100644 index 00000000000..94ca415d9d6 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/client.go @@ -0,0 +1,26 @@ +package apikey + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ApiKeyClient struct { + Client *resourcemanager.Client +} + +func NewApiKeyClientWithBaseURI(sdkApi sdkEnv.Api) (*ApiKeyClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "apikey", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ApiKeyClient: %+v", err) + } + + return &ApiKeyClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/apikey/id_monitor.go b/resource-manager/datadog/2023-10-20/apikey/id_monitor.go new file mode 100644 index 00000000000..765e0fab63c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/id_monitor.go @@ -0,0 +1,130 @@ +package apikey + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/apikey/id_monitor_test.go b/resource-manager/datadog/2023-10-20/apikey/id_monitor_test.go new file mode 100644 index 00000000000..4b85e448759 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/id_monitor_test.go @@ -0,0 +1,282 @@ +package apikey + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/apikey/method_monitorsgetdefaultkey.go b/resource-manager/datadog/2023-10-20/apikey/method_monitorsgetdefaultkey.go new file mode 100644 index 00000000000..d17df22f1b4 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/method_monitorsgetdefaultkey.go @@ -0,0 +1,54 @@ +package apikey + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsGetDefaultKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatadogApiKey +} + +// MonitorsGetDefaultKey ... +func (c ApiKeyClient) MonitorsGetDefaultKey(ctx context.Context, id MonitorId) (result MonitorsGetDefaultKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getDefaultKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DatadogApiKey + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/apikey/method_monitorslistapikeys.go b/resource-manager/datadog/2023-10-20/apikey/method_monitorslistapikeys.go new file mode 100644 index 00000000000..4b3c2aae3af --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/method_monitorslistapikeys.go @@ -0,0 +1,105 @@ +package apikey + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsListApiKeysOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatadogApiKey +} + +type MonitorsListApiKeysCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatadogApiKey +} + +type MonitorsListApiKeysCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MonitorsListApiKeysCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MonitorsListApiKeys ... +func (c ApiKeyClient) MonitorsListApiKeys(ctx context.Context, id MonitorId) (result MonitorsListApiKeysOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &MonitorsListApiKeysCustomPager{}, + Path: fmt.Sprintf("%s/listApiKeys", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatadogApiKey `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MonitorsListApiKeysComplete retrieves all the results into a single object +func (c ApiKeyClient) MonitorsListApiKeysComplete(ctx context.Context, id MonitorId) (MonitorsListApiKeysCompleteResult, error) { + return c.MonitorsListApiKeysCompleteMatchingPredicate(ctx, id, DatadogApiKeyOperationPredicate{}) +} + +// MonitorsListApiKeysCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ApiKeyClient) MonitorsListApiKeysCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate DatadogApiKeyOperationPredicate) (result MonitorsListApiKeysCompleteResult, err error) { + items := make([]DatadogApiKey, 0) + + resp, err := c.MonitorsListApiKeys(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MonitorsListApiKeysCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/apikey/method_monitorssetdefaultkey.go b/resource-manager/datadog/2023-10-20/apikey/method_monitorssetdefaultkey.go new file mode 100644 index 00000000000..c7f9ce56069 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/method_monitorssetdefaultkey.go @@ -0,0 +1,51 @@ +package apikey + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsSetDefaultKeyOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// MonitorsSetDefaultKey ... +func (c ApiKeyClient) MonitorsSetDefaultKey(ctx context.Context, id MonitorId, input DatadogApiKey) (result MonitorsSetDefaultKeyOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/setDefaultKey", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/apikey/model_datadogapikey.go b/resource-manager/datadog/2023-10-20/apikey/model_datadogapikey.go new file mode 100644 index 00000000000..5ce9113e22c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/model_datadogapikey.go @@ -0,0 +1,11 @@ +package apikey + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogApiKey struct { + Created *string `json:"created,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + Key string `json:"key"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/apikey/predicates.go b/resource-manager/datadog/2023-10-20/apikey/predicates.go new file mode 100644 index 00000000000..87f7ab5d1a2 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/predicates.go @@ -0,0 +1,32 @@ +package apikey + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogApiKeyOperationPredicate struct { + Created *string + CreatedBy *string + Key *string + Name *string +} + +func (p DatadogApiKeyOperationPredicate) Matches(input DatadogApiKey) bool { + + if p.Created != nil && (input.Created == nil || *p.Created != *input.Created) { + return false + } + + if p.CreatedBy != nil && (input.CreatedBy == nil || *p.CreatedBy != *input.CreatedBy) { + return false + } + + if p.Key != nil && *p.Key != input.Key { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/apikey/version.go b/resource-manager/datadog/2023-10-20/apikey/version.go new file mode 100644 index 00000000000..780d3ba016c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/apikey/version.go @@ -0,0 +1,10 @@ +package apikey + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/apikey/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/client.go b/resource-manager/datadog/2023-10-20/client.go new file mode 100644 index 00000000000..68f0faeb084 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/client.go @@ -0,0 +1,127 @@ +package v2023_10_20 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/agreements" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/apikey" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/connectedresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/createresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/hosts" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/linkedresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitoredresources" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitoredsubscriptions" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitorsresource" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/refreshsetpasswordlink" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/rules" + "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/singlesignon" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + Agreements *agreements.AgreementsClient + ApiKey *apikey.ApiKeyClient + ConnectedResources *connectedresources.ConnectedResourcesClient + CreateResource *createresource.CreateResourceClient + Hosts *hosts.HostsClient + LinkedResources *linkedresources.LinkedResourcesClient + MonitoredResources *monitoredresources.MonitoredResourcesClient + MonitoredSubscriptions *monitoredsubscriptions.MonitoredSubscriptionsClient + MonitorsResource *monitorsresource.MonitorsResourceClient + RefreshSetPasswordLink *refreshsetpasswordlink.RefreshSetPasswordLinkClient + Rules *rules.RulesClient + SingleSignOn *singlesignon.SingleSignOnClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + agreementsClient, err := agreements.NewAgreementsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Agreements client: %+v", err) + } + configureFunc(agreementsClient.Client) + + apiKeyClient, err := apikey.NewApiKeyClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ApiKey client: %+v", err) + } + configureFunc(apiKeyClient.Client) + + connectedResourcesClient, err := connectedresources.NewConnectedResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building ConnectedResources client: %+v", err) + } + configureFunc(connectedResourcesClient.Client) + + createResourceClient, err := createresource.NewCreateResourceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building CreateResource client: %+v", err) + } + configureFunc(createResourceClient.Client) + + hostsClient, err := hosts.NewHostsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Hosts client: %+v", err) + } + configureFunc(hostsClient.Client) + + linkedResourcesClient, err := linkedresources.NewLinkedResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building LinkedResources client: %+v", err) + } + configureFunc(linkedResourcesClient.Client) + + monitoredResourcesClient, err := monitoredresources.NewMonitoredResourcesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MonitoredResources client: %+v", err) + } + configureFunc(monitoredResourcesClient.Client) + + monitoredSubscriptionsClient, err := monitoredsubscriptions.NewMonitoredSubscriptionsClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MonitoredSubscriptions client: %+v", err) + } + configureFunc(monitoredSubscriptionsClient.Client) + + monitorsResourceClient, err := monitorsresource.NewMonitorsResourceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building MonitorsResource client: %+v", err) + } + configureFunc(monitorsResourceClient.Client) + + refreshSetPasswordLinkClient, err := refreshsetpasswordlink.NewRefreshSetPasswordLinkClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building RefreshSetPasswordLink client: %+v", err) + } + configureFunc(refreshSetPasswordLinkClient.Client) + + rulesClient, err := rules.NewRulesClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building Rules client: %+v", err) + } + configureFunc(rulesClient.Client) + + singleSignOnClient, err := singlesignon.NewSingleSignOnClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SingleSignOn client: %+v", err) + } + configureFunc(singleSignOnClient.Client) + + return &Client{ + Agreements: agreementsClient, + ApiKey: apiKeyClient, + ConnectedResources: connectedResourcesClient, + CreateResource: createResourceClient, + Hosts: hostsClient, + LinkedResources: linkedResourcesClient, + MonitoredResources: monitoredResourcesClient, + MonitoredSubscriptions: monitoredSubscriptionsClient, + MonitorsResource: monitorsResourceClient, + RefreshSetPasswordLink: refreshSetPasswordLinkClient, + Rules: rulesClient, + SingleSignOn: singleSignOnClient, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/README.md b/resource-manager/datadog/2023-10-20/connectedresources/README.md new file mode 100644 index 00000000000..4442a00ff7b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/connectedresources` Documentation + +The `connectedresources` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/connectedresources" +``` + + +### Client Initialization + +```go +client := connectedresources.NewConnectedResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConnectedResourcesClient.BillingInfoGet` + +```go +ctx := context.TODO() +id := connectedresources.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +read, err := client.BillingInfoGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/datadog/2023-10-20/connectedresources/client.go b/resource-manager/datadog/2023-10-20/connectedresources/client.go new file mode 100644 index 00000000000..14585172530 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/client.go @@ -0,0 +1,26 @@ +package connectedresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedResourcesClient struct { + Client *resourcemanager.Client +} + +func NewConnectedResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*ConnectedResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "connectedresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ConnectedResourcesClient: %+v", err) + } + + return &ConnectedResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/id_monitor.go b/resource-manager/datadog/2023-10-20/connectedresources/id_monitor.go new file mode 100644 index 00000000000..66b5e0a15e7 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/id_monitor.go @@ -0,0 +1,130 @@ +package connectedresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/id_monitor_test.go b/resource-manager/datadog/2023-10-20/connectedresources/id_monitor_test.go new file mode 100644 index 00000000000..88b5b2b7448 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/id_monitor_test.go @@ -0,0 +1,282 @@ +package connectedresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/method_billinginfoget.go b/resource-manager/datadog/2023-10-20/connectedresources/method_billinginfoget.go new file mode 100644 index 00000000000..80f3b222b1d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/method_billinginfoget.go @@ -0,0 +1,54 @@ +package connectedresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingInfoGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *BillingInfoResponse +} + +// BillingInfoGet ... +func (c ConnectedResourcesClient) BillingInfoGet(ctx context.Context, id MonitorId) (result BillingInfoGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getBillingInfo", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model BillingInfoResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/model_billinginforesponse.go b/resource-manager/datadog/2023-10-20/connectedresources/model_billinginforesponse.go new file mode 100644 index 00000000000..513c01b2fdb --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/model_billinginforesponse.go @@ -0,0 +1,9 @@ +package connectedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type BillingInfoResponse struct { + MarketplaceSaasInfo *MarketplaceSaaSInfo `json:"marketplaceSaasInfo,omitempty"` + PartnerBillingEntity *PartnerBillingEntity `json:"partnerBillingEntity,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/model_marketplacesaasinfo.go b/resource-manager/datadog/2023-10-20/connectedresources/model_marketplacesaasinfo.go new file mode 100644 index 00000000000..26401891977 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/model_marketplacesaasinfo.go @@ -0,0 +1,12 @@ +package connectedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MarketplaceSaaSInfo struct { + BilledAzureSubscriptionId *string `json:"billedAzureSubscriptionId,omitempty"` + MarketplaceName *string `json:"marketplaceName,omitempty"` + MarketplaceStatus *string `json:"marketplaceStatus,omitempty"` + MarketplaceSubscriptionId *string `json:"marketplaceSubscriptionId,omitempty"` + Subscribed *bool `json:"subscribed,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/model_partnerbillingentity.go b/resource-manager/datadog/2023-10-20/connectedresources/model_partnerbillingentity.go new file mode 100644 index 00000000000..7dca44d7c73 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/model_partnerbillingentity.go @@ -0,0 +1,10 @@ +package connectedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PartnerBillingEntity struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + PartnerEntityUri *string `json:"partnerEntityUri,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/connectedresources/version.go b/resource-manager/datadog/2023-10-20/connectedresources/version.go new file mode 100644 index 00000000000..845a0300ae6 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/connectedresources/version.go @@ -0,0 +1,10 @@ +package connectedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/connectedresources/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/createresource/README.md b/resource-manager/datadog/2023-10-20/createresource/README.md new file mode 100644 index 00000000000..60bc0ac2ad0 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/README.md @@ -0,0 +1,54 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/createresource` Documentation + +The `createresource` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/createresource" +``` + + +### Client Initialization + +```go +client := createresource.NewCreateResourceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CreateResourceClient.CreationSupportedGet` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +read, err := client.CreationSupportedGet(ctx, id, createresource.DefaultCreationSupportedGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CreateResourceClient.CreationSupportedList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.CreationSupportedList(ctx, id, createresource.DefaultCreationSupportedListOperationOptions())` can be used to do batched pagination +items, err := client.CreationSupportedListComplete(ctx, id, createresource.DefaultCreationSupportedListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/createresource/client.go b/resource-manager/datadog/2023-10-20/createresource/client.go new file mode 100644 index 00000000000..9647d67895d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/client.go @@ -0,0 +1,26 @@ +package createresource + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateResourceClient struct { + Client *resourcemanager.Client +} + +func NewCreateResourceClientWithBaseURI(sdkApi sdkEnv.Api) (*CreateResourceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "createresource", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CreateResourceClient: %+v", err) + } + + return &CreateResourceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/createresource/method_creationsupportedget.go b/resource-manager/datadog/2023-10-20/createresource/method_creationsupportedget.go new file mode 100644 index 00000000000..35efe4e9461 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/method_creationsupportedget.go @@ -0,0 +1,84 @@ +package createresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreationSupportedGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CreateResourceSupportedResponse +} + +type CreationSupportedGetOperationOptions struct { + DatadogOrganizationId *string +} + +func DefaultCreationSupportedGetOperationOptions() CreationSupportedGetOperationOptions { + return CreationSupportedGetOperationOptions{} +} + +func (o CreationSupportedGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreationSupportedGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreationSupportedGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatadogOrganizationId != nil { + out.Append("datadogOrganizationId", fmt.Sprintf("%v", *o.DatadogOrganizationId)) + } + return &out +} + +// CreationSupportedGet ... +func (c CreateResourceClient) CreationSupportedGet(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedGetOperationOptions) (result CreationSupportedGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/subscriptionStatuses/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CreateResourceSupportedResponse + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/createresource/method_creationsupportedlist.go b/resource-manager/datadog/2023-10-20/createresource/method_creationsupportedlist.go new file mode 100644 index 00000000000..5d480a660e4 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/method_creationsupportedlist.go @@ -0,0 +1,135 @@ +package createresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreationSupportedListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]CreateResourceSupportedResponse +} + +type CreationSupportedListCompleteResult struct { + LatestHttpResponse *http.Response + Items []CreateResourceSupportedResponse +} + +type CreationSupportedListOperationOptions struct { + DatadogOrganizationId *string +} + +func DefaultCreationSupportedListOperationOptions() CreationSupportedListOperationOptions { + return CreationSupportedListOperationOptions{} +} + +func (o CreationSupportedListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o CreationSupportedListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreationSupportedListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.DatadogOrganizationId != nil { + out.Append("datadogOrganizationId", fmt.Sprintf("%v", *o.DatadogOrganizationId)) + } + return &out +} + +type CreationSupportedListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *CreationSupportedListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// CreationSupportedList ... +func (c CreateResourceClient) CreationSupportedList(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions) (result CreationSupportedListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &CreationSupportedListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/subscriptionStatuses", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]CreateResourceSupportedResponse `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CreationSupportedListComplete retrieves all the results into a single object +func (c CreateResourceClient) CreationSupportedListComplete(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions) (CreationSupportedListCompleteResult, error) { + return c.CreationSupportedListCompleteMatchingPredicate(ctx, id, options, CreateResourceSupportedResponseOperationPredicate{}) +} + +// CreationSupportedListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CreateResourceClient) CreationSupportedListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, options CreationSupportedListOperationOptions, predicate CreateResourceSupportedResponseOperationPredicate) (result CreationSupportedListCompleteResult, err error) { + items := make([]CreateResourceSupportedResponse, 0) + + resp, err := c.CreationSupportedList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = CreationSupportedListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/createresource/model_createresourcesupportedproperties.go b/resource-manager/datadog/2023-10-20/createresource/model_createresourcesupportedproperties.go new file mode 100644 index 00000000000..68ac091a43d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/model_createresourcesupportedproperties.go @@ -0,0 +1,9 @@ +package createresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateResourceSupportedProperties struct { + CreationSupported *bool `json:"creationSupported,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/datadog/2023-01-01/createresource/model_createresourcesupportedresponselist.go b/resource-manager/datadog/2023-10-20/createresource/model_createresourcesupportedresponse.go similarity index 59% rename from resource-manager/datadog/2023-01-01/createresource/model_createresourcesupportedresponselist.go rename to resource-manager/datadog/2023-10-20/createresource/model_createresourcesupportedresponse.go index 43d16feef8d..b12015663fb 100644 --- a/resource-manager/datadog/2023-01-01/createresource/model_createresourcesupportedresponselist.go +++ b/resource-manager/datadog/2023-10-20/createresource/model_createresourcesupportedresponse.go @@ -3,6 +3,6 @@ package createresource // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. -type CreateResourceSupportedResponseList struct { - Value *[]CreateResourceSupportedResponse `json:"value,omitempty"` +type CreateResourceSupportedResponse struct { + Properties *CreateResourceSupportedProperties `json:"properties,omitempty"` } diff --git a/resource-manager/datadog/2023-10-20/createresource/predicates.go b/resource-manager/datadog/2023-10-20/createresource/predicates.go new file mode 100644 index 00000000000..6d0aee3581f --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/predicates.go @@ -0,0 +1,12 @@ +package createresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateResourceSupportedResponseOperationPredicate struct { +} + +func (p CreateResourceSupportedResponseOperationPredicate) Matches(input CreateResourceSupportedResponse) bool { + + return true +} diff --git a/resource-manager/datadog/2023-10-20/createresource/version.go b/resource-manager/datadog/2023-10-20/createresource/version.go new file mode 100644 index 00000000000..d0ffb69ef57 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/createresource/version.go @@ -0,0 +1,10 @@ +package createresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/createresource/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/hosts/README.md b/resource-manager/datadog/2023-10-20/hosts/README.md new file mode 100644 index 00000000000..6ebf2bd5472 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/hosts` Documentation + +The `hosts` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/hosts" +``` + + +### Client Initialization + +```go +client := hosts.NewHostsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `HostsClient.MonitorsListHosts` + +```go +ctx := context.TODO() +id := hosts.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.MonitorsListHosts(ctx, id)` can be used to do batched pagination +items, err := client.MonitorsListHostsComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/hosts/client.go b/resource-manager/datadog/2023-10-20/hosts/client.go new file mode 100644 index 00000000000..b8da7c2f8fd --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/client.go @@ -0,0 +1,26 @@ +package hosts + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HostsClient struct { + Client *resourcemanager.Client +} + +func NewHostsClientWithBaseURI(sdkApi sdkEnv.Api) (*HostsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "hosts", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating HostsClient: %+v", err) + } + + return &HostsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/hosts/id_monitor.go b/resource-manager/datadog/2023-10-20/hosts/id_monitor.go new file mode 100644 index 00000000000..710e26024b5 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/id_monitor.go @@ -0,0 +1,130 @@ +package hosts + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/hosts/id_monitor_test.go b/resource-manager/datadog/2023-10-20/hosts/id_monitor_test.go new file mode 100644 index 00000000000..07a9cda3b71 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/id_monitor_test.go @@ -0,0 +1,282 @@ +package hosts + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/hosts/method_monitorslisthosts.go b/resource-manager/datadog/2023-10-20/hosts/method_monitorslisthosts.go new file mode 100644 index 00000000000..68d1cc65246 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/method_monitorslisthosts.go @@ -0,0 +1,105 @@ +package hosts + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsListHostsOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatadogHost +} + +type MonitorsListHostsCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatadogHost +} + +type MonitorsListHostsCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MonitorsListHostsCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MonitorsListHosts ... +func (c HostsClient) MonitorsListHosts(ctx context.Context, id MonitorId) (result MonitorsListHostsOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &MonitorsListHostsCustomPager{}, + Path: fmt.Sprintf("%s/listHosts", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatadogHost `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MonitorsListHostsComplete retrieves all the results into a single object +func (c HostsClient) MonitorsListHostsComplete(ctx context.Context, id MonitorId) (MonitorsListHostsCompleteResult, error) { + return c.MonitorsListHostsCompleteMatchingPredicate(ctx, id, DatadogHostOperationPredicate{}) +} + +// MonitorsListHostsCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c HostsClient) MonitorsListHostsCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate DatadogHostOperationPredicate) (result MonitorsListHostsCompleteResult, err error) { + items := make([]DatadogHost, 0) + + resp, err := c.MonitorsListHosts(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MonitorsListHostsCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/hosts/model_datadoghost.go b/resource-manager/datadog/2023-10-20/hosts/model_datadoghost.go new file mode 100644 index 00000000000..7cec2bbdda3 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/model_datadoghost.go @@ -0,0 +1,11 @@ +package hosts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogHost struct { + Aliases *[]string `json:"aliases,omitempty"` + Apps *[]string `json:"apps,omitempty"` + Meta *DatadogHostMetadata `json:"meta,omitempty"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/hosts/model_datadoghostmetadata.go b/resource-manager/datadog/2023-10-20/hosts/model_datadoghostmetadata.go new file mode 100644 index 00000000000..8c1d9694e18 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/model_datadoghostmetadata.go @@ -0,0 +1,10 @@ +package hosts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogHostMetadata struct { + AgentVersion *string `json:"agentVersion,omitempty"` + InstallMethod *DatadogInstallMethod `json:"installMethod,omitempty"` + LogsAgent *DatadogLogsAgent `json:"logsAgent,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/hosts/model_datadoginstallmethod.go b/resource-manager/datadog/2023-10-20/hosts/model_datadoginstallmethod.go new file mode 100644 index 00000000000..3e7aa3a8549 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/model_datadoginstallmethod.go @@ -0,0 +1,10 @@ +package hosts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogInstallMethod struct { + InstallerVersion *string `json:"installerVersion,omitempty"` + Tool *string `json:"tool,omitempty"` + ToolVersion *string `json:"toolVersion,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/hosts/model_datadoglogsagent.go b/resource-manager/datadog/2023-10-20/hosts/model_datadoglogsagent.go new file mode 100644 index 00000000000..6da8fd76eeb --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/model_datadoglogsagent.go @@ -0,0 +1,8 @@ +package hosts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogLogsAgent struct { + Transport *string `json:"transport,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/hosts/predicates.go b/resource-manager/datadog/2023-10-20/hosts/predicates.go new file mode 100644 index 00000000000..35bb78eed8b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/predicates.go @@ -0,0 +1,17 @@ +package hosts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogHostOperationPredicate struct { + Name *string +} + +func (p DatadogHostOperationPredicate) Matches(input DatadogHost) bool { + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/hosts/version.go b/resource-manager/datadog/2023-10-20/hosts/version.go new file mode 100644 index 00000000000..56c381de042 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/hosts/version.go @@ -0,0 +1,10 @@ +package hosts + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/hosts/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/README.md b/resource-manager/datadog/2023-10-20/linkedresources/README.md new file mode 100644 index 00000000000..79c52dcdbf7 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/linkedresources` Documentation + +The `linkedresources` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/linkedresources" +``` + + +### Client Initialization + +```go +client := linkedresources.NewLinkedResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `LinkedResourcesClient.MonitorsListLinkedResources` + +```go +ctx := context.TODO() +id := linkedresources.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.MonitorsListLinkedResources(ctx, id)` can be used to do batched pagination +items, err := client.MonitorsListLinkedResourcesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/linkedresources/client.go b/resource-manager/datadog/2023-10-20/linkedresources/client.go new file mode 100644 index 00000000000..3def6afad30 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/client.go @@ -0,0 +1,26 @@ +package linkedresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedResourcesClient struct { + Client *resourcemanager.Client +} + +func NewLinkedResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*LinkedResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "linkedresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating LinkedResourcesClient: %+v", err) + } + + return &LinkedResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/id_monitor.go b/resource-manager/datadog/2023-10-20/linkedresources/id_monitor.go new file mode 100644 index 00000000000..75fe445b83c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/id_monitor.go @@ -0,0 +1,130 @@ +package linkedresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/id_monitor_test.go b/resource-manager/datadog/2023-10-20/linkedresources/id_monitor_test.go new file mode 100644 index 00000000000..890f0a93c15 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/id_monitor_test.go @@ -0,0 +1,282 @@ +package linkedresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/method_monitorslistlinkedresources.go b/resource-manager/datadog/2023-10-20/linkedresources/method_monitorslistlinkedresources.go new file mode 100644 index 00000000000..ddc72b2816a --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/method_monitorslistlinkedresources.go @@ -0,0 +1,105 @@ +package linkedresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsListLinkedResourcesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]LinkedResource +} + +type MonitorsListLinkedResourcesCompleteResult struct { + LatestHttpResponse *http.Response + Items []LinkedResource +} + +type MonitorsListLinkedResourcesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MonitorsListLinkedResourcesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MonitorsListLinkedResources ... +func (c LinkedResourcesClient) MonitorsListLinkedResources(ctx context.Context, id MonitorId) (result MonitorsListLinkedResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &MonitorsListLinkedResourcesCustomPager{}, + Path: fmt.Sprintf("%s/listLinkedResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]LinkedResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MonitorsListLinkedResourcesComplete retrieves all the results into a single object +func (c LinkedResourcesClient) MonitorsListLinkedResourcesComplete(ctx context.Context, id MonitorId) (MonitorsListLinkedResourcesCompleteResult, error) { + return c.MonitorsListLinkedResourcesCompleteMatchingPredicate(ctx, id, LinkedResourceOperationPredicate{}) +} + +// MonitorsListLinkedResourcesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c LinkedResourcesClient) MonitorsListLinkedResourcesCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate LinkedResourceOperationPredicate) (result MonitorsListLinkedResourcesCompleteResult, err error) { + items := make([]LinkedResource, 0) + + resp, err := c.MonitorsListLinkedResources(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MonitorsListLinkedResourcesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/model_linkedresource.go b/resource-manager/datadog/2023-10-20/linkedresources/model_linkedresource.go new file mode 100644 index 00000000000..b424b340d03 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/model_linkedresource.go @@ -0,0 +1,9 @@ +package linkedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedResource struct { + Id *string `json:"id,omitempty"` + Location *string `json:"location,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/predicates.go b/resource-manager/datadog/2023-10-20/linkedresources/predicates.go new file mode 100644 index 00000000000..0948a9eb828 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/predicates.go @@ -0,0 +1,22 @@ +package linkedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LinkedResourceOperationPredicate struct { + Id *string + Location *string +} + +func (p LinkedResourceOperationPredicate) Matches(input LinkedResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && (input.Location == nil || *p.Location != *input.Location) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/linkedresources/version.go b/resource-manager/datadog/2023-10-20/linkedresources/version.go new file mode 100644 index 00000000000..36f32086523 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/linkedresources/version.go @@ -0,0 +1,10 @@ +package linkedresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/linkedresources/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/README.md b/resource-manager/datadog/2023-10-20/monitoredresources/README.md new file mode 100644 index 00000000000..fffff86c925 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitoredresources` Documentation + +The `monitoredresources` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitoredresources" +``` + + +### Client Initialization + +```go +client := monitoredresources.NewMonitoredResourcesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MonitoredResourcesClient.MonitorsListMonitoredResources` + +```go +ctx := context.TODO() +id := monitoredresources.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.MonitorsListMonitoredResources(ctx, id)` can be used to do batched pagination +items, err := client.MonitorsListMonitoredResourcesComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/client.go b/resource-manager/datadog/2023-10-20/monitoredresources/client.go new file mode 100644 index 00000000000..8548ed2734d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/client.go @@ -0,0 +1,26 @@ +package monitoredresources + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredResourcesClient struct { + Client *resourcemanager.Client +} + +func NewMonitoredResourcesClientWithBaseURI(sdkApi sdkEnv.Api) (*MonitoredResourcesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "monitoredresources", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MonitoredResourcesClient: %+v", err) + } + + return &MonitoredResourcesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/id_monitor.go b/resource-manager/datadog/2023-10-20/monitoredresources/id_monitor.go new file mode 100644 index 00000000000..01fa1ed375b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/id_monitor.go @@ -0,0 +1,130 @@ +package monitoredresources + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/id_monitor_test.go b/resource-manager/datadog/2023-10-20/monitoredresources/id_monitor_test.go new file mode 100644 index 00000000000..78d2b0efe08 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/id_monitor_test.go @@ -0,0 +1,282 @@ +package monitoredresources + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/method_monitorslistmonitoredresources.go b/resource-manager/datadog/2023-10-20/monitoredresources/method_monitorslistmonitoredresources.go new file mode 100644 index 00000000000..1f1f519ddb8 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/method_monitorslistmonitoredresources.go @@ -0,0 +1,105 @@ +package monitoredresources + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsListMonitoredResourcesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MonitoredResource +} + +type MonitorsListMonitoredResourcesCompleteResult struct { + LatestHttpResponse *http.Response + Items []MonitoredResource +} + +type MonitorsListMonitoredResourcesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MonitorsListMonitoredResourcesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MonitorsListMonitoredResources ... +func (c MonitoredResourcesClient) MonitorsListMonitoredResources(ctx context.Context, id MonitorId) (result MonitorsListMonitoredResourcesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &MonitorsListMonitoredResourcesCustomPager{}, + Path: fmt.Sprintf("%s/listMonitoredResources", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MonitoredResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MonitorsListMonitoredResourcesComplete retrieves all the results into a single object +func (c MonitoredResourcesClient) MonitorsListMonitoredResourcesComplete(ctx context.Context, id MonitorId) (MonitorsListMonitoredResourcesCompleteResult, error) { + return c.MonitorsListMonitoredResourcesCompleteMatchingPredicate(ctx, id, MonitoredResourceOperationPredicate{}) +} + +// MonitorsListMonitoredResourcesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MonitoredResourcesClient) MonitorsListMonitoredResourcesCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate MonitoredResourceOperationPredicate) (result MonitorsListMonitoredResourcesCompleteResult, err error) { + items := make([]MonitoredResource, 0) + + resp, err := c.MonitorsListMonitoredResources(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MonitorsListMonitoredResourcesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/model_monitoredresource.go b/resource-manager/datadog/2023-10-20/monitoredresources/model_monitoredresource.go new file mode 100644 index 00000000000..b6f7df3c210 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/model_monitoredresource.go @@ -0,0 +1,12 @@ +package monitoredresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredResource struct { + Id *string `json:"id,omitempty"` + ReasonForLogsStatus *string `json:"reasonForLogsStatus,omitempty"` + ReasonForMetricsStatus *string `json:"reasonForMetricsStatus,omitempty"` + SendingLogs *bool `json:"sendingLogs,omitempty"` + SendingMetrics *bool `json:"sendingMetrics,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/predicates.go b/resource-manager/datadog/2023-10-20/monitoredresources/predicates.go new file mode 100644 index 00000000000..0797c7a22d6 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/predicates.go @@ -0,0 +1,37 @@ +package monitoredresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredResourceOperationPredicate struct { + Id *string + ReasonForLogsStatus *string + ReasonForMetricsStatus *string + SendingLogs *bool + SendingMetrics *bool +} + +func (p MonitoredResourceOperationPredicate) Matches(input MonitoredResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.ReasonForLogsStatus != nil && (input.ReasonForLogsStatus == nil || *p.ReasonForLogsStatus != *input.ReasonForLogsStatus) { + return false + } + + if p.ReasonForMetricsStatus != nil && (input.ReasonForMetricsStatus == nil || *p.ReasonForMetricsStatus != *input.ReasonForMetricsStatus) { + return false + } + + if p.SendingLogs != nil && (input.SendingLogs == nil || *p.SendingLogs != *input.SendingLogs) { + return false + } + + if p.SendingMetrics != nil && (input.SendingMetrics == nil || *p.SendingMetrics != *input.SendingMetrics) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/monitoredresources/version.go b/resource-manager/datadog/2023-10-20/monitoredresources/version.go new file mode 100644 index 00000000000..d9a4231bf66 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredresources/version.go @@ -0,0 +1,10 @@ +package monitoredresources + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/monitoredresources/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/README.md b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/README.md new file mode 100644 index 00000000000..c4cdabda619 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitoredsubscriptions` Documentation + +The `monitoredsubscriptions` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitoredsubscriptions" +``` + + +### Client Initialization + +```go +client := monitoredsubscriptions.NewMonitoredSubscriptionsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MonitoredSubscriptionsClient.CreateorUpdate` + +```go +ctx := context.TODO() +id := monitoredsubscriptions.NewMonitoredSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "monitoredSubscriptionName") + +payload := monitoredsubscriptions.MonitoredSubscriptionProperties{ + // ... +} + + +if err := client.CreateorUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MonitoredSubscriptionsClient.Delete` + +```go +ctx := context.TODO() +id := monitoredsubscriptions.NewMonitoredSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "monitoredSubscriptionName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MonitoredSubscriptionsClient.Get` + +```go +ctx := context.TODO() +id := monitoredsubscriptions.NewMonitoredSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "monitoredSubscriptionName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MonitoredSubscriptionsClient.List` + +```go +ctx := context.TODO() +id := monitoredsubscriptions.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MonitoredSubscriptionsClient.Update` + +```go +ctx := context.TODO() +id := monitoredsubscriptions.NewMonitoredSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "monitoredSubscriptionName") + +payload := monitoredsubscriptions.MonitoredSubscriptionProperties{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/client.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/client.go new file mode 100644 index 00000000000..3e047b7e997 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/client.go @@ -0,0 +1,26 @@ +package monitoredsubscriptions + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredSubscriptionsClient struct { + Client *resourcemanager.Client +} + +func NewMonitoredSubscriptionsClientWithBaseURI(sdkApi sdkEnv.Api) (*MonitoredSubscriptionsClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "monitoredsubscriptions", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MonitoredSubscriptionsClient: %+v", err) + } + + return &MonitoredSubscriptionsClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/constants.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/constants.go new file mode 100644 index 00000000000..d70d942905a --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/constants.go @@ -0,0 +1,210 @@ +package monitoredsubscriptions + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Operation string + +const ( + OperationActive Operation = "Active" + OperationAddBegin Operation = "AddBegin" + OperationAddComplete Operation = "AddComplete" + OperationDeleteBegin Operation = "DeleteBegin" + OperationDeleteComplete Operation = "DeleteComplete" +) + +func PossibleValuesForOperation() []string { + return []string{ + string(OperationActive), + string(OperationAddBegin), + string(OperationAddComplete), + string(OperationDeleteBegin), + string(OperationDeleteComplete), + } +} + +func (s *Operation) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOperation(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOperation(input string) (*Operation, error) { + vals := map[string]Operation{ + "active": OperationActive, + "addbegin": OperationAddBegin, + "addcomplete": OperationAddComplete, + "deletebegin": OperationDeleteBegin, + "deletecomplete": OperationDeleteComplete, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Operation(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type Status string + +const ( + StatusActive Status = "Active" + StatusDeleting Status = "Deleting" + StatusFailed Status = "Failed" + StatusInProgress Status = "InProgress" +) + +func PossibleValuesForStatus() []string { + return []string{ + string(StatusActive), + string(StatusDeleting), + string(StatusFailed), + string(StatusInProgress), + } +} + +func (s *Status) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseStatus(input string) (*Status, error) { + vals := map[string]Status{ + "active": StatusActive, + "deleting": StatusDeleting, + "failed": StatusFailed, + "inprogress": StatusInProgress, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := Status(input) + return &out, nil +} + +type TagAction string + +const ( + TagActionExclude TagAction = "Exclude" + TagActionInclude TagAction = "Include" +) + +func PossibleValuesForTagAction() []string { + return []string{ + string(TagActionExclude), + string(TagActionInclude), + } +} + +func (s *TagAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTagAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTagAction(input string) (*TagAction, error) { + vals := map[string]TagAction{ + "exclude": TagActionExclude, + "include": TagActionInclude, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TagAction(input) + return &out, nil +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitor.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitor.go new file mode 100644 index 00000000000..0b16339c3f0 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitor.go @@ -0,0 +1,130 @@ +package monitoredsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitor_test.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitor_test.go new file mode 100644 index 00000000000..31cea3579da --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitor_test.go @@ -0,0 +1,282 @@ +package monitoredsubscriptions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitoredsubscription.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitoredsubscription.go new file mode 100644 index 00000000000..3ffec73bd3b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitoredsubscription.go @@ -0,0 +1,139 @@ +package monitoredsubscriptions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitoredSubscriptionId{}) +} + +var _ resourceids.ResourceId = &MonitoredSubscriptionId{} + +// MonitoredSubscriptionId is a struct representing the Resource ID for a Monitored Subscription +type MonitoredSubscriptionId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string + MonitoredSubscriptionName string +} + +// NewMonitoredSubscriptionID returns a new MonitoredSubscriptionId struct +func NewMonitoredSubscriptionID(subscriptionId string, resourceGroupName string, monitorName string, monitoredSubscriptionName string) MonitoredSubscriptionId { + return MonitoredSubscriptionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + MonitoredSubscriptionName: monitoredSubscriptionName, + } +} + +// ParseMonitoredSubscriptionID parses 'input' into a MonitoredSubscriptionId +func ParseMonitoredSubscriptionID(input string) (*MonitoredSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitoredSubscriptionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitoredSubscriptionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitoredSubscriptionIDInsensitively parses 'input' case-insensitively into a MonitoredSubscriptionId +// note: this method should only be used for API response data and not user input +func ParseMonitoredSubscriptionIDInsensitively(input string) (*MonitoredSubscriptionId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitoredSubscriptionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitoredSubscriptionId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitoredSubscriptionId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + if id.MonitoredSubscriptionName, ok = input.Parsed["monitoredSubscriptionName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitoredSubscriptionName", input) + } + + return nil +} + +// ValidateMonitoredSubscriptionID checks that 'input' can be parsed as a Monitored Subscription ID +func ValidateMonitoredSubscriptionID(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 _, err := ParseMonitoredSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitored Subscription ID +func (id MonitoredSubscriptionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s/monitoredSubscriptions/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName, id.MonitoredSubscriptionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitored Subscription ID +func (id MonitoredSubscriptionId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + resourceids.StaticSegment("staticMonitoredSubscriptions", "monitoredSubscriptions", "monitoredSubscriptions"), + resourceids.UserSpecifiedSegment("monitoredSubscriptionName", "monitoredSubscriptionName"), + } +} + +// String returns a human-readable description of this Monitored Subscription ID +func (id MonitoredSubscriptionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + fmt.Sprintf("Monitored Subscription Name: %q", id.MonitoredSubscriptionName), + } + return fmt.Sprintf("Monitored Subscription (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitoredsubscription_test.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitoredsubscription_test.go new file mode 100644 index 00000000000..616c38c517f --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/id_monitoredsubscription_test.go @@ -0,0 +1,327 @@ +package monitoredsubscriptions + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitoredSubscriptionId{} + +func TestNewMonitoredSubscriptionID(t *testing.T) { + id := NewMonitoredSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "monitoredSubscriptionName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } + + if id.MonitoredSubscriptionName != "monitoredSubscriptionName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitoredSubscriptionName'", id.MonitoredSubscriptionName, "monitoredSubscriptionName") + } +} + +func TestFormatMonitoredSubscriptionID(t *testing.T) { + actual := NewMonitoredSubscriptionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "monitoredSubscriptionName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions/monitoredSubscriptionName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitoredSubscriptionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitoredSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions/monitoredSubscriptionName", + Expected: &MonitoredSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + MonitoredSubscriptionName: "monitoredSubscriptionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions/monitoredSubscriptionName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitoredSubscriptionID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + if actual.MonitoredSubscriptionName != v.Expected.MonitoredSubscriptionName { + t.Fatalf("Expected %q but got %q for MonitoredSubscriptionName", v.Expected.MonitoredSubscriptionName, actual.MonitoredSubscriptionName) + } + + } +} + +func TestParseMonitoredSubscriptionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitoredSubscriptionId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/mOnItOrEdSuBsCrIpTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions/monitoredSubscriptionName", + Expected: &MonitoredSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + MonitoredSubscriptionName: "monitoredSubscriptionName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/monitoredSubscriptions/monitoredSubscriptionName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/mOnItOrEdSuBsCrIpTiOnS/mOnItOrEdSuBsCrIpTiOnNaMe", + Expected: &MonitoredSubscriptionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + MonitoredSubscriptionName: "mOnItOrEdSuBsCrIpTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/mOnItOrEdSuBsCrIpTiOnS/mOnItOrEdSuBsCrIpTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitoredSubscriptionIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + if actual.MonitoredSubscriptionName != v.Expected.MonitoredSubscriptionName { + t.Fatalf("Expected %q but got %q for MonitoredSubscriptionName", v.Expected.MonitoredSubscriptionName, actual.MonitoredSubscriptionName) + } + + } +} + +func TestSegmentsForMonitoredSubscriptionId(t *testing.T) { + segments := MonitoredSubscriptionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitoredSubscriptionId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_createorupdate.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_createorupdate.go new file mode 100644 index 00000000000..1b8d5abc1d3 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_createorupdate.go @@ -0,0 +1,76 @@ +package monitoredsubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateorUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MonitoredSubscriptionProperties +} + +// CreateorUpdate ... +func (c MonitoredSubscriptionsClient) CreateorUpdate(ctx context.Context, id MonitoredSubscriptionId, input MonitoredSubscriptionProperties) (result CreateorUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateorUpdateThenPoll performs CreateorUpdate then polls until it's completed +func (c MonitoredSubscriptionsClient) CreateorUpdateThenPoll(ctx context.Context, id MonitoredSubscriptionId, input MonitoredSubscriptionProperties) error { + result, err := c.CreateorUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateorUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateorUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_delete.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_delete.go new file mode 100644 index 00000000000..449514ade60 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_delete.go @@ -0,0 +1,71 @@ +package monitoredsubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c MonitoredSubscriptionsClient) Delete(ctx context.Context, id MonitoredSubscriptionId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c MonitoredSubscriptionsClient) DeleteThenPoll(ctx context.Context, id MonitoredSubscriptionId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_get.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_get.go new file mode 100644 index 00000000000..92e066e378c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_get.go @@ -0,0 +1,53 @@ +package monitoredsubscriptions + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MonitoredSubscriptionProperties +} + +// Get ... +func (c MonitoredSubscriptionsClient) Get(ctx context.Context, id MonitoredSubscriptionId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MonitoredSubscriptionProperties + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_list.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_list.go new file mode 100644 index 00000000000..0b2feef2399 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_list.go @@ -0,0 +1,105 @@ +package monitoredsubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MonitoredSubscriptionProperties +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MonitoredSubscriptionProperties +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c MonitoredSubscriptionsClient) List(ctx context.Context, id MonitorId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/monitoredSubscriptions", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MonitoredSubscriptionProperties `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c MonitoredSubscriptionsClient) ListComplete(ctx context.Context, id MonitorId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, MonitoredSubscriptionPropertiesOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MonitoredSubscriptionsClient) ListCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate MonitoredSubscriptionPropertiesOperationPredicate) (result ListCompleteResult, err error) { + items := make([]MonitoredSubscriptionProperties, 0) + + resp, err := c.List(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_update.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_update.go new file mode 100644 index 00000000000..7cda2292a5c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/method_update.go @@ -0,0 +1,75 @@ +package monitoredsubscriptions + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MonitoredSubscriptionProperties +} + +// Update ... +func (c MonitoredSubscriptionsClient) Update(ctx context.Context, id MonitoredSubscriptionId, input MonitoredSubscriptionProperties) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c MonitoredSubscriptionsClient) UpdateThenPoll(ctx context.Context, id MonitoredSubscriptionId, input MonitoredSubscriptionProperties) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_filteringtag.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_filteringtag.go new file mode 100644 index 00000000000..c1021ca10e4 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_filteringtag.go @@ -0,0 +1,10 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FilteringTag struct { + Action *TagAction `json:"action,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_logrules.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_logrules.go new file mode 100644 index 00000000000..87d29bd16ab --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_logrules.go @@ -0,0 +1,11 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogRules struct { + FilteringTags *[]FilteringTag `json:"filteringTags,omitempty"` + SendAadLogs *bool `json:"sendAadLogs,omitempty"` + SendResourceLogs *bool `json:"sendResourceLogs,omitempty"` + SendSubscriptionLogs *bool `json:"sendSubscriptionLogs,omitempty"` +} diff --git a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/model_monitoredsubscriptionpropertieslist.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_metricrules.go similarity index 62% rename from resource-manager/datadog/2023-01-01/monitoredsubscriptions/model_monitoredsubscriptionpropertieslist.go rename to resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_metricrules.go index 7ca8845fac2..77dfe58601d 100644 --- a/resource-manager/datadog/2023-01-01/monitoredsubscriptions/model_monitoredsubscriptionpropertieslist.go +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_metricrules.go @@ -3,6 +3,6 @@ package monitoredsubscriptions // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. -type MonitoredSubscriptionPropertiesList struct { - Value *[]MonitoredSubscriptionProperties `json:"value,omitempty"` +type MetricRules struct { + FilteringTags *[]FilteringTag `json:"filteringTags,omitempty"` } diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoredsubscription.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoredsubscription.go new file mode 100644 index 00000000000..fa0d9d7e951 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoredsubscription.go @@ -0,0 +1,11 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredSubscription struct { + Error *string `json:"error,omitempty"` + Status *Status `json:"status,omitempty"` + SubscriptionId *string `json:"subscriptionId,omitempty"` + TagRules *MonitoringTagRulesProperties `json:"tagRules,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoredsubscriptionproperties.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoredsubscriptionproperties.go new file mode 100644 index 00000000000..5b22442513c --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoredsubscriptionproperties.go @@ -0,0 +1,11 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredSubscriptionProperties struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SubscriptionList `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoringtagrulesproperties.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoringtagrulesproperties.go new file mode 100644 index 00000000000..79c44861371 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_monitoringtagrulesproperties.go @@ -0,0 +1,12 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringTagRulesProperties struct { + Automuting *bool `json:"automuting,omitempty"` + CustomMetrics *bool `json:"customMetrics,omitempty"` + LogRules *LogRules `json:"logRules,omitempty"` + MetricRules *MetricRules `json:"metricRules,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_subscriptionlist.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_subscriptionlist.go new file mode 100644 index 00000000000..1e257864219 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/model_subscriptionlist.go @@ -0,0 +1,9 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SubscriptionList struct { + MonitoredSubscriptionList *[]MonitoredSubscription `json:"monitoredSubscriptionList,omitempty"` + Operation *Operation `json:"operation,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/predicates.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/predicates.go new file mode 100644 index 00000000000..e2d724249cb --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/predicates.go @@ -0,0 +1,27 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoredSubscriptionPropertiesOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p MonitoredSubscriptionPropertiesOperationPredicate) Matches(input MonitoredSubscriptionProperties) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/monitoredsubscriptions/version.go b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/version.go new file mode 100644 index 00000000000..34f0134c520 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitoredsubscriptions/version.go @@ -0,0 +1,10 @@ +package monitoredsubscriptions + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/monitoredsubscriptions/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/README.md b/resource-manager/datadog/2023-10-20/monitorsresource/README.md new file mode 100644 index 00000000000..63eddf0b8e9 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/README.md @@ -0,0 +1,117 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitorsresource` Documentation + +The `monitorsresource` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/monitorsresource" +``` + + +### Client Initialization + +```go +client := monitorsresource.NewMonitorsResourceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `MonitorsResourceClient.MonitorsCreate` + +```go +ctx := context.TODO() +id := monitorsresource.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +payload := monitorsresource.DatadogMonitorResource{ + // ... +} + + +if err := client.MonitorsCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `MonitorsResourceClient.MonitorsDelete` + +```go +ctx := context.TODO() +id := monitorsresource.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +if err := client.MonitorsDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `MonitorsResourceClient.MonitorsGet` + +```go +ctx := context.TODO() +id := monitorsresource.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +read, err := client.MonitorsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `MonitorsResourceClient.MonitorsList` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.MonitorsList(ctx, id)` can be used to do batched pagination +items, err := client.MonitorsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MonitorsResourceClient.MonitorsListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.MonitorsListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.MonitorsListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `MonitorsResourceClient.MonitorsUpdate` + +```go +ctx := context.TODO() +id := monitorsresource.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +payload := monitorsresource.DatadogMonitorResourceUpdateParameters{ + // ... +} + + +if err := client.MonitorsUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/client.go b/resource-manager/datadog/2023-10-20/monitorsresource/client.go new file mode 100644 index 00000000000..5e8ae38cada --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/client.go @@ -0,0 +1,26 @@ +package monitorsresource + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsResourceClient struct { + Client *resourcemanager.Client +} + +func NewMonitorsResourceClientWithBaseURI(sdkApi sdkEnv.Api) (*MonitorsResourceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "monitorsresource", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating MonitorsResourceClient: %+v", err) + } + + return &MonitorsResourceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/constants.go b/resource-manager/datadog/2023-10-20/monitorsresource/constants.go new file mode 100644 index 00000000000..49f5f1f8513 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/constants.go @@ -0,0 +1,242 @@ +package monitorsresource + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LiftrResourceCategories string + +const ( + LiftrResourceCategoriesMonitorLogs LiftrResourceCategories = "MonitorLogs" + LiftrResourceCategoriesUnknown LiftrResourceCategories = "Unknown" +) + +func PossibleValuesForLiftrResourceCategories() []string { + return []string{ + string(LiftrResourceCategoriesMonitorLogs), + string(LiftrResourceCategoriesUnknown), + } +} + +func (s *LiftrResourceCategories) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseLiftrResourceCategories(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseLiftrResourceCategories(input string) (*LiftrResourceCategories, error) { + vals := map[string]LiftrResourceCategories{ + "monitorlogs": LiftrResourceCategoriesMonitorLogs, + "unknown": LiftrResourceCategoriesUnknown, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LiftrResourceCategories(input) + return &out, nil +} + +type ManagedIdentityTypes string + +const ( + ManagedIdentityTypesSystemAssigned ManagedIdentityTypes = "SystemAssigned" + ManagedIdentityTypesUserAssigned ManagedIdentityTypes = "UserAssigned" +) + +func PossibleValuesForManagedIdentityTypes() []string { + return []string{ + string(ManagedIdentityTypesSystemAssigned), + string(ManagedIdentityTypesUserAssigned), + } +} + +func (s *ManagedIdentityTypes) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseManagedIdentityTypes(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseManagedIdentityTypes(input string) (*ManagedIdentityTypes, error) { + vals := map[string]ManagedIdentityTypes{ + "systemassigned": ManagedIdentityTypesSystemAssigned, + "userassigned": ManagedIdentityTypesUserAssigned, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ManagedIdentityTypes(input) + return &out, nil +} + +type MarketplaceSubscriptionStatus string + +const ( + MarketplaceSubscriptionStatusActive MarketplaceSubscriptionStatus = "Active" + MarketplaceSubscriptionStatusProvisioning MarketplaceSubscriptionStatus = "Provisioning" + MarketplaceSubscriptionStatusSuspended MarketplaceSubscriptionStatus = "Suspended" + MarketplaceSubscriptionStatusUnsubscribed MarketplaceSubscriptionStatus = "Unsubscribed" +) + +func PossibleValuesForMarketplaceSubscriptionStatus() []string { + return []string{ + string(MarketplaceSubscriptionStatusActive), + string(MarketplaceSubscriptionStatusProvisioning), + string(MarketplaceSubscriptionStatusSuspended), + string(MarketplaceSubscriptionStatusUnsubscribed), + } +} + +func (s *MarketplaceSubscriptionStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMarketplaceSubscriptionStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMarketplaceSubscriptionStatus(input string) (*MarketplaceSubscriptionStatus, error) { + vals := map[string]MarketplaceSubscriptionStatus{ + "active": MarketplaceSubscriptionStatusActive, + "provisioning": MarketplaceSubscriptionStatusProvisioning, + "suspended": MarketplaceSubscriptionStatusSuspended, + "unsubscribed": MarketplaceSubscriptionStatusUnsubscribed, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MarketplaceSubscriptionStatus(input) + return &out, nil +} + +type MonitoringStatus string + +const ( + MonitoringStatusDisabled MonitoringStatus = "Disabled" + MonitoringStatusEnabled MonitoringStatus = "Enabled" +) + +func PossibleValuesForMonitoringStatus() []string { + return []string{ + string(MonitoringStatusDisabled), + string(MonitoringStatusEnabled), + } +} + +func (s *MonitoringStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseMonitoringStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseMonitoringStatus(input string) (*MonitoringStatus, error) { + vals := map[string]MonitoringStatus{ + "disabled": MonitoringStatusDisabled, + "enabled": MonitoringStatusEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := MonitoringStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/id_monitor.go b/resource-manager/datadog/2023-10-20/monitorsresource/id_monitor.go new file mode 100644 index 00000000000..ce00a854e6b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/id_monitor.go @@ -0,0 +1,130 @@ +package monitorsresource + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/id_monitor_test.go b/resource-manager/datadog/2023-10-20/monitorsresource/id_monitor_test.go new file mode 100644 index 00000000000..1c02872f24b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/id_monitor_test.go @@ -0,0 +1,282 @@ +package monitorsresource + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorscreate.go b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorscreate.go new file mode 100644 index 00000000000..1f36c301dee --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorscreate.go @@ -0,0 +1,75 @@ +package monitorsresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsCreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DatadogMonitorResource +} + +// MonitorsCreate ... +func (c MonitorsResourceClient) MonitorsCreate(ctx context.Context, id MonitorId, input DatadogMonitorResource) (result MonitorsCreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// MonitorsCreateThenPoll performs MonitorsCreate then polls until it's completed +func (c MonitorsResourceClient) MonitorsCreateThenPoll(ctx context.Context, id MonitorId, input DatadogMonitorResource) error { + result, err := c.MonitorsCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing MonitorsCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MonitorsCreate: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsdelete.go b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsdelete.go new file mode 100644 index 00000000000..bd3e718e8a8 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsdelete.go @@ -0,0 +1,71 @@ +package monitorsresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsDeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// MonitorsDelete ... +func (c MonitorsResourceClient) MonitorsDelete(ctx context.Context, id MonitorId) (result MonitorsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// MonitorsDeleteThenPoll performs MonitorsDelete then polls until it's completed +func (c MonitorsResourceClient) MonitorsDeleteThenPoll(ctx context.Context, id MonitorId) error { + result, err := c.MonitorsDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing MonitorsDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MonitorsDelete: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsget.go b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsget.go new file mode 100644 index 00000000000..221cbce6132 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsget.go @@ -0,0 +1,53 @@ +package monitorsresource + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatadogMonitorResource +} + +// MonitorsGet ... +func (c MonitorsResourceClient) MonitorsGet(ctx context.Context, id MonitorId) (result MonitorsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DatadogMonitorResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorslist.go b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorslist.go new file mode 100644 index 00000000000..cf82fe7deb7 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorslist.go @@ -0,0 +1,106 @@ +package monitorsresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatadogMonitorResource +} + +type MonitorsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatadogMonitorResource +} + +type MonitorsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MonitorsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MonitorsList ... +func (c MonitorsResourceClient) MonitorsList(ctx context.Context, id commonids.SubscriptionId) (result MonitorsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &MonitorsListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/monitors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatadogMonitorResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MonitorsListComplete retrieves all the results into a single object +func (c MonitorsResourceClient) MonitorsListComplete(ctx context.Context, id commonids.SubscriptionId) (MonitorsListCompleteResult, error) { + return c.MonitorsListCompleteMatchingPredicate(ctx, id, DatadogMonitorResourceOperationPredicate{}) +} + +// MonitorsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MonitorsResourceClient) MonitorsListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate DatadogMonitorResourceOperationPredicate) (result MonitorsListCompleteResult, err error) { + items := make([]DatadogMonitorResource, 0) + + resp, err := c.MonitorsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MonitorsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorslistbyresourcegroup.go b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorslistbyresourcegroup.go new file mode 100644 index 00000000000..d8a82668200 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorslistbyresourcegroup.go @@ -0,0 +1,106 @@ +package monitorsresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatadogMonitorResource +} + +type MonitorsListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatadogMonitorResource +} + +type MonitorsListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *MonitorsListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// MonitorsListByResourceGroup ... +func (c MonitorsResourceClient) MonitorsListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result MonitorsListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &MonitorsListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.Datadog/monitors", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatadogMonitorResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// MonitorsListByResourceGroupComplete retrieves all the results into a single object +func (c MonitorsResourceClient) MonitorsListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (MonitorsListByResourceGroupCompleteResult, error) { + return c.MonitorsListByResourceGroupCompleteMatchingPredicate(ctx, id, DatadogMonitorResourceOperationPredicate{}) +} + +// MonitorsListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c MonitorsResourceClient) MonitorsListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate DatadogMonitorResourceOperationPredicate) (result MonitorsListByResourceGroupCompleteResult, err error) { + items := make([]DatadogMonitorResource, 0) + + resp, err := c.MonitorsListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = MonitorsListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsupdate.go b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsupdate.go new file mode 100644 index 00000000000..d1d58e0a81a --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/method_monitorsupdate.go @@ -0,0 +1,75 @@ +package monitorsresource + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DatadogMonitorResource +} + +// MonitorsUpdate ... +func (c MonitorsResourceClient) MonitorsUpdate(ctx context.Context, id MonitorId, input DatadogMonitorResourceUpdateParameters) (result MonitorsUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// MonitorsUpdateThenPoll performs MonitorsUpdate then polls until it's completed +func (c MonitorsResourceClient) MonitorsUpdateThenPoll(ctx context.Context, id MonitorId, input DatadogMonitorResourceUpdateParameters) error { + result, err := c.MonitorsUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing MonitorsUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MonitorsUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogmonitorresource.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogmonitorresource.go new file mode 100644 index 00000000000..b70ac52c8fd --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogmonitorresource.go @@ -0,0 +1,20 @@ +package monitorsresource + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogMonitorResource struct { + Id *string `json:"id,omitempty"` + Identity *IdentityProperties `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *MonitorProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogmonitorresourceupdateparameters.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogmonitorresourceupdateparameters.go new file mode 100644 index 00000000000..f775abd0f2d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogmonitorresourceupdateparameters.go @@ -0,0 +1,10 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogMonitorResourceUpdateParameters struct { + Properties *MonitorUpdateProperties `json:"properties,omitempty"` + Sku *ResourceSku `json:"sku,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogorganizationproperties.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogorganizationproperties.go new file mode 100644 index 00000000000..e07cfbd0599 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_datadogorganizationproperties.go @@ -0,0 +1,16 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogOrganizationProperties struct { + ApiKey *string `json:"apiKey,omitempty"` + ApplicationKey *string `json:"applicationKey,omitempty"` + Cspm *bool `json:"cspm,omitempty"` + EnterpriseAppId *string `json:"enterpriseAppId,omitempty"` + Id *string `json:"id,omitempty"` + LinkingAuthCode *string `json:"linkingAuthCode,omitempty"` + LinkingClientId *string `json:"linkingClientId,omitempty"` + Name *string `json:"name,omitempty"` + RedirectUri *string `json:"redirectUri,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_identityproperties.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_identityproperties.go new file mode 100644 index 00000000000..dacb58bfc75 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_identityproperties.go @@ -0,0 +1,10 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IdentityProperties struct { + PrincipalId *string `json:"principalId,omitempty"` + TenantId *string `json:"tenantId,omitempty"` + Type *ManagedIdentityTypes `json:"type,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_monitorproperties.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_monitorproperties.go new file mode 100644 index 00000000000..81899cc5ed4 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_monitorproperties.go @@ -0,0 +1,14 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorProperties struct { + DatadogOrganizationProperties *DatadogOrganizationProperties `json:"datadogOrganizationProperties,omitempty"` + LiftrResourceCategory *LiftrResourceCategories `json:"liftrResourceCategory,omitempty"` + LiftrResourcePreference *int64 `json:"liftrResourcePreference,omitempty"` + MarketplaceSubscriptionStatus *MarketplaceSubscriptionStatus `json:"marketplaceSubscriptionStatus,omitempty"` + MonitoringStatus *MonitoringStatus `json:"monitoringStatus,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + UserInfo *UserInfo `json:"userInfo,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_monitorupdateproperties.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_monitorupdateproperties.go new file mode 100644 index 00000000000..84412f47ae6 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_monitorupdateproperties.go @@ -0,0 +1,9 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorUpdateProperties struct { + Cspm *bool `json:"cspm,omitempty"` + MonitoringStatus *MonitoringStatus `json:"monitoringStatus,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_resourcesku.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_resourcesku.go new file mode 100644 index 00000000000..9344eedf068 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_resourcesku.go @@ -0,0 +1,8 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceSku struct { + Name string `json:"name"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/model_userinfo.go b/resource-manager/datadog/2023-10-20/monitorsresource/model_userinfo.go new file mode 100644 index 00000000000..b61d14dac6d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/model_userinfo.go @@ -0,0 +1,10 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UserInfo struct { + EmailAddress *string `json:"emailAddress,omitempty"` + Name *string `json:"name,omitempty"` + PhoneNumber *string `json:"phoneNumber,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/predicates.go b/resource-manager/datadog/2023-10-20/monitorsresource/predicates.go new file mode 100644 index 00000000000..a2ee22984f1 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/predicates.go @@ -0,0 +1,32 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogMonitorResourceOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p DatadogMonitorResourceOperationPredicate) Matches(input DatadogMonitorResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/monitorsresource/version.go b/resource-manager/datadog/2023-10-20/monitorsresource/version.go new file mode 100644 index 00000000000..c848c62b455 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/monitorsresource/version.go @@ -0,0 +1,10 @@ +package monitorsresource + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/monitorsresource/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/README.md b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/README.md new file mode 100644 index 00000000000..a2b7e9a5093 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/README.md @@ -0,0 +1,36 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/refreshsetpasswordlink` Documentation + +The `refreshsetpasswordlink` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/refreshsetpasswordlink" +``` + + +### Client Initialization + +```go +client := refreshsetpasswordlink.NewRefreshSetPasswordLinkClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RefreshSetPasswordLinkClient.MonitorsRefreshSetPasswordLink` + +```go +ctx := context.TODO() +id := refreshsetpasswordlink.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +read, err := client.MonitorsRefreshSetPasswordLink(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/client.go b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/client.go new file mode 100644 index 00000000000..c765560ae22 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/client.go @@ -0,0 +1,26 @@ +package refreshsetpasswordlink + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RefreshSetPasswordLinkClient struct { + Client *resourcemanager.Client +} + +func NewRefreshSetPasswordLinkClientWithBaseURI(sdkApi sdkEnv.Api) (*RefreshSetPasswordLinkClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "refreshsetpasswordlink", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RefreshSetPasswordLinkClient: %+v", err) + } + + return &RefreshSetPasswordLinkClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/id_monitor.go b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/id_monitor.go new file mode 100644 index 00000000000..ab47aec2a9a --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/id_monitor.go @@ -0,0 +1,130 @@ +package refreshsetpasswordlink + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/id_monitor_test.go b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/id_monitor_test.go new file mode 100644 index 00000000000..081466dbf9a --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/id_monitor_test.go @@ -0,0 +1,282 @@ +package refreshsetpasswordlink + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/method_monitorsrefreshsetpasswordlink.go b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/method_monitorsrefreshsetpasswordlink.go new file mode 100644 index 00000000000..bc543edfd95 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/method_monitorsrefreshsetpasswordlink.go @@ -0,0 +1,54 @@ +package refreshsetpasswordlink + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitorsRefreshSetPasswordLinkOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatadogSetPasswordLink +} + +// MonitorsRefreshSetPasswordLink ... +func (c RefreshSetPasswordLinkClient) MonitorsRefreshSetPasswordLink(ctx context.Context, id MonitorId) (result MonitorsRefreshSetPasswordLinkOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/refreshSetPasswordLink", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DatadogSetPasswordLink + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/model_datadogsetpasswordlink.go b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/model_datadogsetpasswordlink.go new file mode 100644 index 00000000000..c1fa0c22482 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/model_datadogsetpasswordlink.go @@ -0,0 +1,8 @@ +package refreshsetpasswordlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogSetPasswordLink struct { + SetPasswordLink *string `json:"setPasswordLink,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/version.go b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/version.go new file mode 100644 index 00000000000..65865637db8 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/refreshsetpasswordlink/version.go @@ -0,0 +1,10 @@ +package refreshsetpasswordlink + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/refreshsetpasswordlink/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/rules/README.md b/resource-manager/datadog/2023-10-20/rules/README.md new file mode 100644 index 00000000000..40271a8fead --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/README.md @@ -0,0 +1,74 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/rules` Documentation + +The `rules` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/rules" +``` + + +### Client Initialization + +```go +client := rules.NewRulesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RulesClient.TagRulesCreateOrUpdate` + +```go +ctx := context.TODO() +id := rules.NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName") + +payload := rules.MonitoringTagRules{ + // ... +} + + +read, err := client.TagRulesCreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RulesClient.TagRulesGet` + +```go +ctx := context.TODO() +id := rules.NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName") + +read, err := client.TagRulesGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RulesClient.TagRulesList` + +```go +ctx := context.TODO() +id := rules.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.TagRulesList(ctx, id)` can be used to do batched pagination +items, err := client.TagRulesListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/rules/client.go b/resource-manager/datadog/2023-10-20/rules/client.go new file mode 100644 index 00000000000..ee5a5154cef --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/client.go @@ -0,0 +1,26 @@ +package rules + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RulesClient struct { + Client *resourcemanager.Client +} + +func NewRulesClientWithBaseURI(sdkApi sdkEnv.Api) (*RulesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "rules", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RulesClient: %+v", err) + } + + return &RulesClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/rules/constants.go b/resource-manager/datadog/2023-10-20/rules/constants.go new file mode 100644 index 00000000000..e755600d6ea --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/constants.go @@ -0,0 +1,113 @@ +package rules + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type TagAction string + +const ( + TagActionExclude TagAction = "Exclude" + TagActionInclude TagAction = "Include" +) + +func PossibleValuesForTagAction() []string { + return []string{ + string(TagActionExclude), + string(TagActionInclude), + } +} + +func (s *TagAction) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseTagAction(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseTagAction(input string) (*TagAction, error) { + vals := map[string]TagAction{ + "exclude": TagActionExclude, + "include": TagActionInclude, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := TagAction(input) + return &out, nil +} diff --git a/resource-manager/datadog/2023-10-20/rules/id_monitor.go b/resource-manager/datadog/2023-10-20/rules/id_monitor.go new file mode 100644 index 00000000000..644db5507c3 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/id_monitor.go @@ -0,0 +1,130 @@ +package rules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/rules/id_monitor_test.go b/resource-manager/datadog/2023-10-20/rules/id_monitor_test.go new file mode 100644 index 00000000000..3a9306c3ea8 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/id_monitor_test.go @@ -0,0 +1,282 @@ +package rules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/rules/id_tagrule.go b/resource-manager/datadog/2023-10-20/rules/id_tagrule.go new file mode 100644 index 00000000000..e08c204523b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/id_tagrule.go @@ -0,0 +1,139 @@ +package rules + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TagRuleId{}) +} + +var _ resourceids.ResourceId = &TagRuleId{} + +// TagRuleId is a struct representing the Resource ID for a Tag Rule +type TagRuleId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string + TagRuleName string +} + +// NewTagRuleID returns a new TagRuleId struct +func NewTagRuleID(subscriptionId string, resourceGroupName string, monitorName string, tagRuleName string) TagRuleId { + return TagRuleId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + TagRuleName: tagRuleName, + } +} + +// ParseTagRuleID parses 'input' into a TagRuleId +func ParseTagRuleID(input string) (*TagRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagRuleId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTagRuleIDInsensitively parses 'input' case-insensitively into a TagRuleId +// note: this method should only be used for API response data and not user input +func ParseTagRuleIDInsensitively(input string) (*TagRuleId, error) { + parser := resourceids.NewParserFromResourceIdType(&TagRuleId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TagRuleId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TagRuleId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + if id.TagRuleName, ok = input.Parsed["tagRuleName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "tagRuleName", input) + } + + return nil +} + +// ValidateTagRuleID checks that 'input' can be parsed as a Tag Rule ID +func ValidateTagRuleID(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 _, err := ParseTagRuleID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Tag Rule ID +func (id TagRuleId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s/tagRules/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName, id.TagRuleName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Tag Rule ID +func (id TagRuleId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + resourceids.StaticSegment("staticTagRules", "tagRules", "tagRules"), + resourceids.UserSpecifiedSegment("tagRuleName", "tagRuleName"), + } +} + +// String returns a human-readable description of this Tag Rule ID +func (id TagRuleId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + fmt.Sprintf("Tag Rule Name: %q", id.TagRuleName), + } + return fmt.Sprintf("Tag Rule (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/rules/id_tagrule_test.go b/resource-manager/datadog/2023-10-20/rules/id_tagrule_test.go new file mode 100644 index 00000000000..96eea9c53a4 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/id_tagrule_test.go @@ -0,0 +1,327 @@ +package rules + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TagRuleId{} + +func TestNewTagRuleID(t *testing.T) { + id := NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } + + if id.TagRuleName != "tagRuleName" { + t.Fatalf("Expected %q but got %q for Segment 'TagRuleName'", id.TagRuleName, "tagRuleName") + } +} + +func TestFormatTagRuleID(t *testing.T) { + actual := NewTagRuleID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "tagRuleName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules/tagRuleName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTagRuleID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules/tagRuleName", + Expected: &TagRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + TagRuleName: "tagRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules/tagRuleName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagRuleID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + if actual.TagRuleName != v.Expected.TagRuleName { + t.Fatalf("Expected %q but got %q for TagRuleName", v.Expected.TagRuleName, actual.TagRuleName) + } + + } +} + +func TestParseTagRuleIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TagRuleId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/tAgRuLeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules/tagRuleName", + Expected: &TagRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + TagRuleName: "tagRuleName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/tagRules/tagRuleName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/tAgRuLeS/tAgRuLeNaMe", + Expected: &TagRuleId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + TagRuleName: "tAgRuLeNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/tAgRuLeS/tAgRuLeNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTagRuleIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + if actual.TagRuleName != v.Expected.TagRuleName { + t.Fatalf("Expected %q but got %q for TagRuleName", v.Expected.TagRuleName, actual.TagRuleName) + } + + } +} + +func TestSegmentsForTagRuleId(t *testing.T) { + segments := TagRuleId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TagRuleId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/rules/method_tagrulescreateorupdate.go b/resource-manager/datadog/2023-10-20/rules/method_tagrulescreateorupdate.go new file mode 100644 index 00000000000..5ddded602ce --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/method_tagrulescreateorupdate.go @@ -0,0 +1,57 @@ +package rules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagRulesCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MonitoringTagRules +} + +// TagRulesCreateOrUpdate ... +func (c RulesClient) TagRulesCreateOrUpdate(ctx context.Context, id TagRuleId, input MonitoringTagRules) (result TagRulesCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MonitoringTagRules + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/rules/method_tagrulesget.go b/resource-manager/datadog/2023-10-20/rules/method_tagrulesget.go new file mode 100644 index 00000000000..86d73a88c56 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/method_tagrulesget.go @@ -0,0 +1,53 @@ +package rules + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagRulesGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *MonitoringTagRules +} + +// TagRulesGet ... +func (c RulesClient) TagRulesGet(ctx context.Context, id TagRuleId) (result TagRulesGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model MonitoringTagRules + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/rules/method_tagruleslist.go b/resource-manager/datadog/2023-10-20/rules/method_tagruleslist.go new file mode 100644 index 00000000000..07a4cb77f27 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/method_tagruleslist.go @@ -0,0 +1,105 @@ +package rules + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagRulesListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]MonitoringTagRules +} + +type TagRulesListCompleteResult struct { + LatestHttpResponse *http.Response + Items []MonitoringTagRules +} + +type TagRulesListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *TagRulesListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// TagRulesList ... +func (c RulesClient) TagRulesList(ctx context.Context, id MonitorId) (result TagRulesListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &TagRulesListCustomPager{}, + Path: fmt.Sprintf("%s/tagRules", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]MonitoringTagRules `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// TagRulesListComplete retrieves all the results into a single object +func (c RulesClient) TagRulesListComplete(ctx context.Context, id MonitorId) (TagRulesListCompleteResult, error) { + return c.TagRulesListCompleteMatchingPredicate(ctx, id, MonitoringTagRulesOperationPredicate{}) +} + +// TagRulesListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RulesClient) TagRulesListCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate MonitoringTagRulesOperationPredicate) (result TagRulesListCompleteResult, err error) { + items := make([]MonitoringTagRules, 0) + + resp, err := c.TagRulesList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = TagRulesListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/rules/model_filteringtag.go b/resource-manager/datadog/2023-10-20/rules/model_filteringtag.go new file mode 100644 index 00000000000..e3a860d7a44 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/model_filteringtag.go @@ -0,0 +1,10 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FilteringTag struct { + Action *TagAction `json:"action,omitempty"` + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/rules/model_logrules.go b/resource-manager/datadog/2023-10-20/rules/model_logrules.go new file mode 100644 index 00000000000..092bd8ff183 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/model_logrules.go @@ -0,0 +1,11 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type LogRules struct { + FilteringTags *[]FilteringTag `json:"filteringTags,omitempty"` + SendAadLogs *bool `json:"sendAadLogs,omitempty"` + SendResourceLogs *bool `json:"sendResourceLogs,omitempty"` + SendSubscriptionLogs *bool `json:"sendSubscriptionLogs,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/rules/model_metricrules.go b/resource-manager/datadog/2023-10-20/rules/model_metricrules.go new file mode 100644 index 00000000000..76e4a907e22 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/model_metricrules.go @@ -0,0 +1,8 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MetricRules struct { + FilteringTags *[]FilteringTag `json:"filteringTags,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/rules/model_monitoringtagrules.go b/resource-manager/datadog/2023-10-20/rules/model_monitoringtagrules.go new file mode 100644 index 00000000000..fa5d3787584 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/model_monitoringtagrules.go @@ -0,0 +1,16 @@ +package rules + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringTagRules struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *MonitoringTagRulesProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/rules/model_monitoringtagrulesproperties.go b/resource-manager/datadog/2023-10-20/rules/model_monitoringtagrulesproperties.go new file mode 100644 index 00000000000..93e2a58e71e --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/model_monitoringtagrulesproperties.go @@ -0,0 +1,12 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringTagRulesProperties struct { + Automuting *bool `json:"automuting,omitempty"` + CustomMetrics *bool `json:"customMetrics,omitempty"` + LogRules *LogRules `json:"logRules,omitempty"` + MetricRules *MetricRules `json:"metricRules,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/rules/predicates.go b/resource-manager/datadog/2023-10-20/rules/predicates.go new file mode 100644 index 00000000000..8052394d262 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/predicates.go @@ -0,0 +1,27 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MonitoringTagRulesOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p MonitoringTagRulesOperationPredicate) Matches(input MonitoringTagRules) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/rules/version.go b/resource-manager/datadog/2023-10-20/rules/version.go new file mode 100644 index 00000000000..73b04936e42 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/rules/version.go @@ -0,0 +1,10 @@ +package rules + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/rules/2023-10-20" +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/README.md b/resource-manager/datadog/2023-10-20/singlesignon/README.md new file mode 100644 index 00000000000..0acc40bddae --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/README.md @@ -0,0 +1,70 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/singlesignon` Documentation + +The `singlesignon` SDK allows for interaction with Azure Resource Manager `datadog` (API Version `2023-10-20`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2023-10-20/singlesignon" +``` + + +### Client Initialization + +```go +client := singlesignon.NewSingleSignOnClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SingleSignOnClient.ConfigurationsCreateOrUpdate` + +```go +ctx := context.TODO() +id := singlesignon.NewSingleSignOnConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "singleSignOnConfigurationName") + +payload := singlesignon.DatadogSingleSignOnResource{ + // ... +} + + +if err := client.ConfigurationsCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SingleSignOnClient.ConfigurationsGet` + +```go +ctx := context.TODO() +id := singlesignon.NewSingleSignOnConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "singleSignOnConfigurationName") + +read, err := client.ConfigurationsGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SingleSignOnClient.ConfigurationsList` + +```go +ctx := context.TODO() +id := singlesignon.NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + +// alternatively `client.ConfigurationsList(ctx, id)` can be used to do batched pagination +items, err := client.ConfigurationsListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/datadog/2023-10-20/singlesignon/client.go b/resource-manager/datadog/2023-10-20/singlesignon/client.go new file mode 100644 index 00000000000..7e124666990 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/client.go @@ -0,0 +1,26 @@ +package singlesignon + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SingleSignOnClient struct { + Client *resourcemanager.Client +} + +func NewSingleSignOnClientWithBaseURI(sdkApi sdkEnv.Api) (*SingleSignOnClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "singlesignon", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SingleSignOnClient: %+v", err) + } + + return &SingleSignOnClient{ + Client: client, + }, nil +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/constants.go b/resource-manager/datadog/2023-10-20/singlesignon/constants.go new file mode 100644 index 00000000000..c9cdd7eb362 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/constants.go @@ -0,0 +1,119 @@ +package singlesignon + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" + ProvisioningStateDeleted ProvisioningState = "Deleted" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateNotSpecified ProvisioningState = "NotSpecified" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), + string(ProvisioningStateDeleted), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateNotSpecified), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, + "deleted": ProvisioningStateDeleted, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "notspecified": ProvisioningStateNotSpecified, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} + +type SingleSignOnStates string + +const ( + SingleSignOnStatesDisable SingleSignOnStates = "Disable" + SingleSignOnStatesEnable SingleSignOnStates = "Enable" + SingleSignOnStatesExisting SingleSignOnStates = "Existing" + SingleSignOnStatesInitial SingleSignOnStates = "Initial" +) + +func PossibleValuesForSingleSignOnStates() []string { + return []string{ + string(SingleSignOnStatesDisable), + string(SingleSignOnStatesEnable), + string(SingleSignOnStatesExisting), + string(SingleSignOnStatesInitial), + } +} + +func (s *SingleSignOnStates) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSingleSignOnStates(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSingleSignOnStates(input string) (*SingleSignOnStates, error) { + vals := map[string]SingleSignOnStates{ + "disable": SingleSignOnStatesDisable, + "enable": SingleSignOnStatesEnable, + "existing": SingleSignOnStatesExisting, + "initial": SingleSignOnStatesInitial, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SingleSignOnStates(input) + return &out, nil +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/id_monitor.go b/resource-manager/datadog/2023-10-20/singlesignon/id_monitor.go new file mode 100644 index 00000000000..f45a315b1b7 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/id_monitor.go @@ -0,0 +1,130 @@ +package singlesignon + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&MonitorId{}) +} + +var _ resourceids.ResourceId = &MonitorId{} + +// MonitorId is a struct representing the Resource ID for a Monitor +type MonitorId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string +} + +// NewMonitorID returns a new MonitorId struct +func NewMonitorID(subscriptionId string, resourceGroupName string, monitorName string) MonitorId { + return MonitorId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + } +} + +// ParseMonitorID parses 'input' into a MonitorId +func ParseMonitorID(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseMonitorIDInsensitively parses 'input' case-insensitively into a MonitorId +// note: this method should only be used for API response data and not user input +func ParseMonitorIDInsensitively(input string) (*MonitorId, error) { + parser := resourceids.NewParserFromResourceIdType(&MonitorId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := MonitorId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *MonitorId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + return nil +} + +// ValidateMonitorID checks that 'input' can be parsed as a Monitor ID +func ValidateMonitorID(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 _, err := ParseMonitorID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Monitor ID +func (id MonitorId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Monitor ID +func (id MonitorId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + } +} + +// String returns a human-readable description of this Monitor ID +func (id MonitorId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + } + return fmt.Sprintf("Monitor (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/id_monitor_test.go b/resource-manager/datadog/2023-10-20/singlesignon/id_monitor_test.go new file mode 100644 index 00000000000..e21e11cfd06 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/id_monitor_test.go @@ -0,0 +1,282 @@ +package singlesignon + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &MonitorId{} + +func TestNewMonitorID(t *testing.T) { + id := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } +} + +func TestFormatMonitorID(t *testing.T) { + actual := NewMonitorID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseMonitorID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestParseMonitorIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *MonitorId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Expected: &MonitorId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseMonitorIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + } +} + +func TestSegmentsForMonitorId(t *testing.T) { + segments := MonitorId{}.Segments() + if len(segments) == 0 { + t.Fatalf("MonitorId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/id_singlesignonconfiguration.go b/resource-manager/datadog/2023-10-20/singlesignon/id_singlesignonconfiguration.go new file mode 100644 index 00000000000..623f7daf3f5 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/id_singlesignonconfiguration.go @@ -0,0 +1,139 @@ +package singlesignon + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SingleSignOnConfigurationId{}) +} + +var _ resourceids.ResourceId = &SingleSignOnConfigurationId{} + +// SingleSignOnConfigurationId is a struct representing the Resource ID for a Single Sign On Configuration +type SingleSignOnConfigurationId struct { + SubscriptionId string + ResourceGroupName string + MonitorName string + SingleSignOnConfigurationName string +} + +// NewSingleSignOnConfigurationID returns a new SingleSignOnConfigurationId struct +func NewSingleSignOnConfigurationID(subscriptionId string, resourceGroupName string, monitorName string, singleSignOnConfigurationName string) SingleSignOnConfigurationId { + return SingleSignOnConfigurationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + MonitorName: monitorName, + SingleSignOnConfigurationName: singleSignOnConfigurationName, + } +} + +// ParseSingleSignOnConfigurationID parses 'input' into a SingleSignOnConfigurationId +func ParseSingleSignOnConfigurationID(input string) (*SingleSignOnConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&SingleSignOnConfigurationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SingleSignOnConfigurationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSingleSignOnConfigurationIDInsensitively parses 'input' case-insensitively into a SingleSignOnConfigurationId +// note: this method should only be used for API response data and not user input +func ParseSingleSignOnConfigurationIDInsensitively(input string) (*SingleSignOnConfigurationId, error) { + parser := resourceids.NewParserFromResourceIdType(&SingleSignOnConfigurationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SingleSignOnConfigurationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SingleSignOnConfigurationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.MonitorName, ok = input.Parsed["monitorName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "monitorName", input) + } + + if id.SingleSignOnConfigurationName, ok = input.Parsed["singleSignOnConfigurationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "singleSignOnConfigurationName", input) + } + + return nil +} + +// ValidateSingleSignOnConfigurationID checks that 'input' can be parsed as a Single Sign On Configuration ID +func ValidateSingleSignOnConfigurationID(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 _, err := ParseSingleSignOnConfigurationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Single Sign On Configuration ID +func (id SingleSignOnConfigurationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Datadog/monitors/%s/singleSignOnConfigurations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.MonitorName, id.SingleSignOnConfigurationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Single Sign On Configuration ID +func (id SingleSignOnConfigurationId) 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("staticMicrosoftDatadog", "Microsoft.Datadog", "Microsoft.Datadog"), + resourceids.StaticSegment("staticMonitors", "monitors", "monitors"), + resourceids.UserSpecifiedSegment("monitorName", "monitorName"), + resourceids.StaticSegment("staticSingleSignOnConfigurations", "singleSignOnConfigurations", "singleSignOnConfigurations"), + resourceids.UserSpecifiedSegment("singleSignOnConfigurationName", "singleSignOnConfigurationName"), + } +} + +// String returns a human-readable description of this Single Sign On Configuration ID +func (id SingleSignOnConfigurationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Monitor Name: %q", id.MonitorName), + fmt.Sprintf("Single Sign On Configuration Name: %q", id.SingleSignOnConfigurationName), + } + return fmt.Sprintf("Single Sign On Configuration (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/id_singlesignonconfiguration_test.go b/resource-manager/datadog/2023-10-20/singlesignon/id_singlesignonconfiguration_test.go new file mode 100644 index 00000000000..36b9754415d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/id_singlesignonconfiguration_test.go @@ -0,0 +1,327 @@ +package singlesignon + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SingleSignOnConfigurationId{} + +func TestNewSingleSignOnConfigurationID(t *testing.T) { + id := NewSingleSignOnConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "singleSignOnConfigurationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.MonitorName != "monitorName" { + t.Fatalf("Expected %q but got %q for Segment 'MonitorName'", id.MonitorName, "monitorName") + } + + if id.SingleSignOnConfigurationName != "singleSignOnConfigurationName" { + t.Fatalf("Expected %q but got %q for Segment 'SingleSignOnConfigurationName'", id.SingleSignOnConfigurationName, "singleSignOnConfigurationName") + } +} + +func TestFormatSingleSignOnConfigurationID(t *testing.T) { + actual := NewSingleSignOnConfigurationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "monitorName", "singleSignOnConfigurationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations/singleSignOnConfigurationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSingleSignOnConfigurationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SingleSignOnConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations/singleSignOnConfigurationName", + Expected: &SingleSignOnConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + SingleSignOnConfigurationName: "singleSignOnConfigurationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations/singleSignOnConfigurationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSingleSignOnConfigurationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + if actual.SingleSignOnConfigurationName != v.Expected.SingleSignOnConfigurationName { + t.Fatalf("Expected %q but got %q for SingleSignOnConfigurationName", v.Expected.SingleSignOnConfigurationName, actual.SingleSignOnConfigurationName) + } + + } +} + +func TestParseSingleSignOnConfigurationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SingleSignOnConfigurationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/sInGlEsIgNoNcOnFiGuRaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations/singleSignOnConfigurationName", + Expected: &SingleSignOnConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + MonitorName: "monitorName", + SingleSignOnConfigurationName: "singleSignOnConfigurationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Datadog/monitors/monitorName/singleSignOnConfigurations/singleSignOnConfigurationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/sInGlEsIgNoNcOnFiGuRaTiOnS/sInGlEsIgNoNcOnFiGuRaTiOnNaMe", + Expected: &SingleSignOnConfigurationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + MonitorName: "mOnItOrNaMe", + SingleSignOnConfigurationName: "sInGlEsIgNoNcOnFiGuRaTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dAtAdOg/mOnItOrS/mOnItOrNaMe/sInGlEsIgNoNcOnFiGuRaTiOnS/sInGlEsIgNoNcOnFiGuRaTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSingleSignOnConfigurationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.MonitorName != v.Expected.MonitorName { + t.Fatalf("Expected %q but got %q for MonitorName", v.Expected.MonitorName, actual.MonitorName) + } + + if actual.SingleSignOnConfigurationName != v.Expected.SingleSignOnConfigurationName { + t.Fatalf("Expected %q but got %q for SingleSignOnConfigurationName", v.Expected.SingleSignOnConfigurationName, actual.SingleSignOnConfigurationName) + } + + } +} + +func TestSegmentsForSingleSignOnConfigurationId(t *testing.T) { + segments := SingleSignOnConfigurationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SingleSignOnConfigurationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/method_configurationscreateorupdate.go b/resource-manager/datadog/2023-10-20/singlesignon/method_configurationscreateorupdate.go new file mode 100644 index 00000000000..f7eaa63e44a --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/method_configurationscreateorupdate.go @@ -0,0 +1,75 @@ +package singlesignon + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *DatadogSingleSignOnResource +} + +// ConfigurationsCreateOrUpdate ... +func (c SingleSignOnClient) ConfigurationsCreateOrUpdate(ctx context.Context, id SingleSignOnConfigurationId, input DatadogSingleSignOnResource) (result ConfigurationsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// ConfigurationsCreateOrUpdateThenPoll performs ConfigurationsCreateOrUpdate then polls until it's completed +func (c SingleSignOnClient) ConfigurationsCreateOrUpdateThenPoll(ctx context.Context, id SingleSignOnConfigurationId, input DatadogSingleSignOnResource) error { + result, err := c.ConfigurationsCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ConfigurationsCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after ConfigurationsCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/method_configurationsget.go b/resource-manager/datadog/2023-10-20/singlesignon/method_configurationsget.go new file mode 100644 index 00000000000..73ab9b27853 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/method_configurationsget.go @@ -0,0 +1,53 @@ +package singlesignon + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *DatadogSingleSignOnResource +} + +// ConfigurationsGet ... +func (c SingleSignOnClient) ConfigurationsGet(ctx context.Context, id SingleSignOnConfigurationId) (result ConfigurationsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model DatadogSingleSignOnResource + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/method_configurationslist.go b/resource-manager/datadog/2023-10-20/singlesignon/method_configurationslist.go new file mode 100644 index 00000000000..381b447564b --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/method_configurationslist.go @@ -0,0 +1,105 @@ +package singlesignon + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConfigurationsListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]DatadogSingleSignOnResource +} + +type ConfigurationsListCompleteResult struct { + LatestHttpResponse *http.Response + Items []DatadogSingleSignOnResource +} + +type ConfigurationsListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ConfigurationsListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ConfigurationsList ... +func (c SingleSignOnClient) ConfigurationsList(ctx context.Context, id MonitorId) (result ConfigurationsListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ConfigurationsListCustomPager{}, + Path: fmt.Sprintf("%s/singleSignOnConfigurations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]DatadogSingleSignOnResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ConfigurationsListComplete retrieves all the results into a single object +func (c SingleSignOnClient) ConfigurationsListComplete(ctx context.Context, id MonitorId) (ConfigurationsListCompleteResult, error) { + return c.ConfigurationsListCompleteMatchingPredicate(ctx, id, DatadogSingleSignOnResourceOperationPredicate{}) +} + +// ConfigurationsListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SingleSignOnClient) ConfigurationsListCompleteMatchingPredicate(ctx context.Context, id MonitorId, predicate DatadogSingleSignOnResourceOperationPredicate) (result ConfigurationsListCompleteResult, err error) { + items := make([]DatadogSingleSignOnResource, 0) + + resp, err := c.ConfigurationsList(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ConfigurationsListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/model_datadogsinglesignonproperties.go b/resource-manager/datadog/2023-10-20/singlesignon/model_datadogsinglesignonproperties.go new file mode 100644 index 00000000000..6ee23f09143 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/model_datadogsinglesignonproperties.go @@ -0,0 +1,11 @@ +package singlesignon + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogSingleSignOnProperties struct { + EnterpriseAppId *string `json:"enterpriseAppId,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SingleSignOnState *SingleSignOnStates `json:"singleSignOnState,omitempty"` + SingleSignOnURL *string `json:"singleSignOnUrl,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/model_datadogsinglesignonresource.go b/resource-manager/datadog/2023-10-20/singlesignon/model_datadogsinglesignonresource.go new file mode 100644 index 00000000000..8285ab57895 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/model_datadogsinglesignonresource.go @@ -0,0 +1,16 @@ +package singlesignon + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogSingleSignOnResource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *DatadogSingleSignOnProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/predicates.go b/resource-manager/datadog/2023-10-20/singlesignon/predicates.go new file mode 100644 index 00000000000..bc73bd31dd3 --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/predicates.go @@ -0,0 +1,27 @@ +package singlesignon + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DatadogSingleSignOnResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p DatadogSingleSignOnResourceOperationPredicate) Matches(input DatadogSingleSignOnResource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/datadog/2023-10-20/singlesignon/version.go b/resource-manager/datadog/2023-10-20/singlesignon/version.go new file mode 100644 index 00000000000..b9d802f101d --- /dev/null +++ b/resource-manager/datadog/2023-10-20/singlesignon/version.go @@ -0,0 +1,10 @@ +package singlesignon + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-10-20" + +func userAgent() string { + return "hashicorp/go-azure-sdk/singlesignon/2023-10-20" +} diff --git a/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_sapodplinkedservicetypeproperties.go b/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_sapodplinkedservicetypeproperties.go index 5be9d837145..f376a5e51d7 100644 --- a/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_sapodplinkedservicetypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_sapodplinkedservicetypeproperties.go @@ -18,7 +18,7 @@ type SapOdpLinkedServiceTypeProperties struct { Password SecretBase `json:"password"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` @@ -41,7 +41,7 @@ func (s *SapOdpLinkedServiceTypeProperties) UnmarshalJSON(bytes []byte) error { MessageServerService *string `json:"messageServerService,omitempty"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` diff --git a/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_saptablelinkedservicetypeproperties.go b/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_saptablelinkedservicetypeproperties.go index 15c5eb9d256..49b9c8c2e41 100644 --- a/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_saptablelinkedservicetypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/dataflowdebugsession/model_saptablelinkedservicetypeproperties.go @@ -18,7 +18,7 @@ type SapTableLinkedServiceTypeProperties struct { Password SecretBase `json:"password"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` @@ -39,7 +39,7 @@ func (s *SapTableLinkedServiceTypeProperties) UnmarshalJSON(bytes []byte) error MessageServerService *string `json:"messageServerService,omitempty"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` diff --git a/resource-manager/datafactory/2018-06-01/linkedservices/model_sapodplinkedservicetypeproperties.go b/resource-manager/datafactory/2018-06-01/linkedservices/model_sapodplinkedservicetypeproperties.go index 83462caba38..bac4a98b216 100644 --- a/resource-manager/datafactory/2018-06-01/linkedservices/model_sapodplinkedservicetypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/linkedservices/model_sapodplinkedservicetypeproperties.go @@ -18,7 +18,7 @@ type SapOdpLinkedServiceTypeProperties struct { Password SecretBase `json:"password"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` @@ -41,7 +41,7 @@ func (s *SapOdpLinkedServiceTypeProperties) UnmarshalJSON(bytes []byte) error { MessageServerService *string `json:"messageServerService,omitempty"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` diff --git a/resource-manager/datafactory/2018-06-01/linkedservices/model_saptablelinkedservicetypeproperties.go b/resource-manager/datafactory/2018-06-01/linkedservices/model_saptablelinkedservicetypeproperties.go index 6884fde51ea..6f795a2dbe3 100644 --- a/resource-manager/datafactory/2018-06-01/linkedservices/model_saptablelinkedservicetypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/linkedservices/model_saptablelinkedservicetypeproperties.go @@ -18,7 +18,7 @@ type SapTableLinkedServiceTypeProperties struct { Password SecretBase `json:"password"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` @@ -39,7 +39,7 @@ func (s *SapTableLinkedServiceTypeProperties) UnmarshalJSON(bytes []byte) error MessageServerService *string `json:"messageServerService,omitempty"` Server *string `json:"server,omitempty"` SncLibraryPath *string `json:"sncLibraryPath,omitempty"` - SncMode *string `json:"sncMode,omitempty"` + SncMode *bool `json:"sncMode,omitempty"` SncMyName *string `json:"sncMyName,omitempty"` SncPartnerName *string `json:"sncPartnerName,omitempty"` SncQop *string `json:"sncQop,omitempty"` diff --git a/resource-manager/datafactory/2018-06-01/pipelines/model_scriptactivitytypeproperties.go b/resource-manager/datafactory/2018-06-01/pipelines/model_scriptactivitytypeproperties.go index 0bd14c302c7..a21fc8076ce 100644 --- a/resource-manager/datafactory/2018-06-01/pipelines/model_scriptactivitytypeproperties.go +++ b/resource-manager/datafactory/2018-06-01/pipelines/model_scriptactivitytypeproperties.go @@ -5,6 +5,7 @@ package pipelines type ScriptActivityTypeProperties struct { LogSettings *ScriptActivityTypePropertiesLogSettings `json:"logSettings,omitempty"` + ReturnMultistatementResult *bool `json:"returnMultistatementResult,omitempty"` ScriptBlockExecutionTimeout *string `json:"scriptBlockExecutionTimeout,omitempty"` Scripts *[]ScriptActivityScriptBlock `json:"scripts,omitempty"` } diff --git a/resource-manager/devopsinfrastructure/2024-10-19/pools/README.md b/resource-manager/devopsinfrastructure/2024-10-19/pools/README.md index 3fd1ec923aa..b2967c942d1 100644 --- a/resource-manager/devopsinfrastructure/2024-10-19/pools/README.md +++ b/resource-manager/devopsinfrastructure/2024-10-19/pools/README.md @@ -21,6 +21,27 @@ client.Client.Authorizer = authorizer ``` +### Example Usage: `PoolsClient.CheckNameAvailability` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := pools.CheckNameAvailability{ + // ... +} + + +read, err := client.CheckNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + ### Example Usage: `PoolsClient.CreateOrUpdate` ```go diff --git a/resource-manager/devopsinfrastructure/2024-10-19/pools/constants.go b/resource-manager/devopsinfrastructure/2024-10-19/pools/constants.go index e311ee19900..7c01c280dbb 100644 --- a/resource-manager/devopsinfrastructure/2024-10-19/pools/constants.go +++ b/resource-manager/devopsinfrastructure/2024-10-19/pools/constants.go @@ -9,6 +9,47 @@ import ( // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. +type AvailabilityStatus string + +const ( + AvailabilityStatusAvailable AvailabilityStatus = "Available" + AvailabilityStatusUnavailable AvailabilityStatus = "Unavailable" +) + +func PossibleValuesForAvailabilityStatus() []string { + return []string{ + string(AvailabilityStatusAvailable), + string(AvailabilityStatusUnavailable), + } +} + +func (s *AvailabilityStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAvailabilityStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAvailabilityStatus(input string) (*AvailabilityStatus, error) { + vals := map[string]AvailabilityStatus{ + "available": AvailabilityStatusAvailable, + "unavailable": AvailabilityStatusUnavailable, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AvailabilityStatus(input) + return &out, nil +} + type AzureDevOpsPermissionType string const ( @@ -97,6 +138,85 @@ func parseCachingType(input string) (*CachingType, error) { return &out, nil } +type CheckNameAvailabilityReason string + +const ( + CheckNameAvailabilityReasonAlreadyExists CheckNameAvailabilityReason = "AlreadyExists" + CheckNameAvailabilityReasonInvalid CheckNameAvailabilityReason = "Invalid" +) + +func PossibleValuesForCheckNameAvailabilityReason() []string { + return []string{ + string(CheckNameAvailabilityReasonAlreadyExists), + string(CheckNameAvailabilityReasonInvalid), + } +} + +func (s *CheckNameAvailabilityReason) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCheckNameAvailabilityReason(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCheckNameAvailabilityReason(input string) (*CheckNameAvailabilityReason, error) { + vals := map[string]CheckNameAvailabilityReason{ + "alreadyexists": CheckNameAvailabilityReasonAlreadyExists, + "invalid": CheckNameAvailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CheckNameAvailabilityReason(input) + return &out, nil +} + +type DevOpsInfrastructureResourceType string + +const ( + DevOpsInfrastructureResourceTypeMicrosoftPointDevOpsInfrastructurePools DevOpsInfrastructureResourceType = "Microsoft.DevOpsInfrastructure/pools" +) + +func PossibleValuesForDevOpsInfrastructureResourceType() []string { + return []string{ + string(DevOpsInfrastructureResourceTypeMicrosoftPointDevOpsInfrastructurePools), + } +} + +func (s *DevOpsInfrastructureResourceType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDevOpsInfrastructureResourceType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDevOpsInfrastructureResourceType(input string) (*DevOpsInfrastructureResourceType, error) { + vals := map[string]DevOpsInfrastructureResourceType{ + "microsoft.devopsinfrastructure/pools": DevOpsInfrastructureResourceTypeMicrosoftPointDevOpsInfrastructurePools, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DevOpsInfrastructureResourceType(input) + return &out, nil +} + type LogonType string const ( diff --git a/resource-manager/devopsinfrastructure/2024-10-19/pools/method_checknameavailability.go b/resource-manager/devopsinfrastructure/2024-10-19/pools/method_checknameavailability.go new file mode 100644 index 00000000000..ac113c41a89 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-10-19/pools/method_checknameavailability.go @@ -0,0 +1,59 @@ +package pools + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *CheckNameAvailabilityResult +} + +// CheckNameAvailability ... +func (c PoolsClient) CheckNameAvailability(ctx context.Context, id commonids.SubscriptionId, input CheckNameAvailability) (result CheckNameAvailabilityOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.DevOpsInfrastructure/checkNameAvailability", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model CheckNameAvailabilityResult + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/devopsinfrastructure/2024-10-19/pools/model_checknameavailability.go b/resource-manager/devopsinfrastructure/2024-10-19/pools/model_checknameavailability.go new file mode 100644 index 00000000000..443cbd49032 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-10-19/pools/model_checknameavailability.go @@ -0,0 +1,9 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailability struct { + Name string `json:"name"` + Type DevOpsInfrastructureResourceType `json:"type"` +} diff --git a/resource-manager/devopsinfrastructure/2024-10-19/pools/model_checknameavailabilityresult.go b/resource-manager/devopsinfrastructure/2024-10-19/pools/model_checknameavailabilityresult.go new file mode 100644 index 00000000000..7506c4e2270 --- /dev/null +++ b/resource-manager/devopsinfrastructure/2024-10-19/pools/model_checknameavailabilityresult.go @@ -0,0 +1,11 @@ +package pools + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CheckNameAvailabilityResult struct { + Available AvailabilityStatus `json:"available"` + Message string `json:"message"` + Name string `json:"name"` + Reason CheckNameAvailabilityReason `json:"reason"` +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/README.md b/resource-manager/machinelearningservices/2024-10-01-preview/quota/README.md index 904acc9c9ef..d1f8a7ea650 100644 --- a/resource-manager/machinelearningservices/2024-10-01-preview/quota/README.md +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/README.md @@ -37,6 +37,56 @@ for _, item := range items { ``` +### Example Usage: `QuotaClient.PTUQuotaGetAvailable` + +```go +ctx := context.TODO() +id := quota.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +read, err := client.PTUQuotaGetAvailable(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `QuotaClient.PTUQuotaList` + +```go +ctx := context.TODO() +id := quota.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.PTUQuotaList(ctx, id, quota.DefaultPTUQuotaListOperationOptions())` can be used to do batched pagination +items, err := client.PTUQuotaListComplete(ctx, id, quota.DefaultPTUQuotaListOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `QuotaClient.PTUQuotaListAvailable` + +```go +ctx := context.TODO() +id := quota.NewLocationID("12345678-1234-9876-4563-123456789012", "locationName") + +// alternatively `client.PTUQuotaListAvailable(ctx, id, quota.DefaultPTUQuotaListAvailableOperationOptions())` can be used to do batched pagination +items, err := client.PTUQuotaListAvailableComplete(ctx, id, quota.DefaultPTUQuotaListAvailableOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + ### Example Usage: `QuotaClient.Update` ```go diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotagetavailable.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotagetavailable.go new file mode 100644 index 00000000000..3bd7abdb5ba --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotagetavailable.go @@ -0,0 +1,54 @@ +package quota + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PTUQuotaGetAvailableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *AvailableQuota +} + +// PTUQuotaGetAvailable ... +func (c QuotaClient) PTUQuotaGetAvailable(ctx context.Context, id LocationId) (result PTUQuotaGetAvailableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/availableQuota/default", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model AvailableQuota + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotalist.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotalist.go new file mode 100644 index 00000000000..9cfc0d52ff0 --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotalist.go @@ -0,0 +1,134 @@ +package quota + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PTUQuotaListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]UsageAndQuotaDetails +} + +type PTUQuotaListCompleteResult struct { + LatestHttpResponse *http.Response + Items []UsageAndQuotaDetails +} + +type PTUQuotaListOperationOptions struct { + Skip *string +} + +func DefaultPTUQuotaListOperationOptions() PTUQuotaListOperationOptions { + return PTUQuotaListOperationOptions{} +} + +func (o PTUQuotaListOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o PTUQuotaListOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o PTUQuotaListOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + return &out +} + +type PTUQuotaListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *PTUQuotaListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// PTUQuotaList ... +func (c QuotaClient) PTUQuotaList(ctx context.Context, id LocationId, options PTUQuotaListOperationOptions) (result PTUQuotaListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &PTUQuotaListCustomPager{}, + Path: fmt.Sprintf("%s/quotaAndUsage", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]UsageAndQuotaDetails `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PTUQuotaListComplete retrieves all the results into a single object +func (c QuotaClient) PTUQuotaListComplete(ctx context.Context, id LocationId, options PTUQuotaListOperationOptions) (PTUQuotaListCompleteResult, error) { + return c.PTUQuotaListCompleteMatchingPredicate(ctx, id, options, UsageAndQuotaDetailsOperationPredicate{}) +} + +// PTUQuotaListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QuotaClient) PTUQuotaListCompleteMatchingPredicate(ctx context.Context, id LocationId, options PTUQuotaListOperationOptions, predicate UsageAndQuotaDetailsOperationPredicate) (result PTUQuotaListCompleteResult, err error) { + items := make([]UsageAndQuotaDetails, 0) + + resp, err := c.PTUQuotaList(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PTUQuotaListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotalistavailable.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotalistavailable.go new file mode 100644 index 00000000000..3d960fbe944 --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/method_ptuquotalistavailable.go @@ -0,0 +1,134 @@ +package quota + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PTUQuotaListAvailableOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]AvailableQuota +} + +type PTUQuotaListAvailableCompleteResult struct { + LatestHttpResponse *http.Response + Items []AvailableQuota +} + +type PTUQuotaListAvailableOperationOptions struct { + Skip *string +} + +func DefaultPTUQuotaListAvailableOperationOptions() PTUQuotaListAvailableOperationOptions { + return PTUQuotaListAvailableOperationOptions{} +} + +func (o PTUQuotaListAvailableOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o PTUQuotaListAvailableOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o PTUQuotaListAvailableOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + return &out +} + +type PTUQuotaListAvailableCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *PTUQuotaListAvailableCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// PTUQuotaListAvailable ... +func (c QuotaClient) PTUQuotaListAvailable(ctx context.Context, id LocationId, options PTUQuotaListAvailableOperationOptions) (result PTUQuotaListAvailableOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &PTUQuotaListAvailableCustomPager{}, + Path: fmt.Sprintf("%s/availableQuota", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]AvailableQuota `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// PTUQuotaListAvailableComplete retrieves all the results into a single object +func (c QuotaClient) PTUQuotaListAvailableComplete(ctx context.Context, id LocationId, options PTUQuotaListAvailableOperationOptions) (PTUQuotaListAvailableCompleteResult, error) { + return c.PTUQuotaListAvailableCompleteMatchingPredicate(ctx, id, options, AvailableQuotaOperationPredicate{}) +} + +// PTUQuotaListAvailableCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c QuotaClient) PTUQuotaListAvailableCompleteMatchingPredicate(ctx context.Context, id LocationId, options PTUQuotaListAvailableOperationOptions, predicate AvailableQuotaOperationPredicate) (result PTUQuotaListAvailableCompleteResult, err error) { + items := make([]AvailableQuota, 0) + + resp, err := c.PTUQuotaListAvailable(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = PTUQuotaListAvailableCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_availablequota.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_availablequota.go new file mode 100644 index 00000000000..da2ea18ab0b --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_availablequota.go @@ -0,0 +1,8 @@ +package quota + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableQuota struct { + Properties *AvailableQuotaProperties `json:"properties,omitempty"` +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_availablequotaproperties.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_availablequotaproperties.go new file mode 100644 index 00000000000..f75679ec4c0 --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_availablequotaproperties.go @@ -0,0 +1,8 @@ +package quota + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AvailableQuotaProperties struct { + Total *int64 `json:"total,omitempty"` +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_ptudeploymentusage.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_ptudeploymentusage.go new file mode 100644 index 00000000000..52d6e5d4168 --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_ptudeploymentusage.go @@ -0,0 +1,12 @@ +package quota + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PTUDeploymentUsage struct { + CollectionQuotaUsage *int64 `json:"collectionQuotaUsage,omitempty"` + DeploymentName *string `json:"deploymentName,omitempty"` + ResourceGroup *string `json:"resourceGroup,omitempty"` + Usage *int64 `json:"usage,omitempty"` + WorkspaceName *string `json:"workspaceName,omitempty"` +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_usageandquotadetails.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_usageandquotadetails.go new file mode 100644 index 00000000000..306801dbefc --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/model_usageandquotadetails.go @@ -0,0 +1,10 @@ +package quota + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UsageAndQuotaDetails struct { + ModelCollection *string `json:"modelCollection,omitempty"` + Quota *int64 `json:"quota,omitempty"` + UsageDetails *[]PTUDeploymentUsage `json:"usageDetails,omitempty"` +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/quota/predicates.go b/resource-manager/machinelearningservices/2024-10-01-preview/quota/predicates.go index db56a8407ce..a06e9862db5 100644 --- a/resource-manager/machinelearningservices/2024-10-01-preview/quota/predicates.go +++ b/resource-manager/machinelearningservices/2024-10-01-preview/quota/predicates.go @@ -3,6 +3,14 @@ package quota // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See NOTICE.txt in the project root for license information. +type AvailableQuotaOperationPredicate struct { +} + +func (p AvailableQuotaOperationPredicate) Matches(input AvailableQuota) bool { + + return true +} + type ResourceQuotaOperationPredicate struct { AmlWorkspaceLocation *string Id *string @@ -53,3 +61,21 @@ func (p UpdateWorkspaceQuotasOperationPredicate) Matches(input UpdateWorkspaceQu return true } + +type UsageAndQuotaDetailsOperationPredicate struct { + ModelCollection *string + Quota *int64 +} + +func (p UsageAndQuotaDetailsOperationPredicate) Matches(input UsageAndQuotaDetails) bool { + + if p.ModelCollection != nil && (input.ModelCollection == nil || *p.ModelCollection != *input.ModelCollection) { + return false + } + + if p.Quota != nil && (input.Quota == nil || *p.Quota != *input.Quota) { + return false + } + + return true +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registry.go b/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registry.go index ff07ae4f321..60b07afa517 100644 --- a/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registry.go +++ b/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registry.go @@ -4,12 +4,13 @@ package registrymanagement // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type Registry struct { - DiscoveryURL *string `json:"discoveryUrl,omitempty"` - IntellectualPropertyPublisher *string `json:"intellectualPropertyPublisher,omitempty"` - ManagedResourceGroup *ArmResourceId `json:"managedResourceGroup,omitempty"` - ManagedResourceGroupSettings *ManagedResourceGroupSettings `json:"managedResourceGroupSettings,omitempty"` - MlFlowRegistryUri *string `json:"mlFlowRegistryUri,omitempty"` - PublicNetworkAccess *string `json:"publicNetworkAccess,omitempty"` - RegionDetails *[]RegistryRegionArmDetails `json:"regionDetails,omitempty"` - RegistryPrivateEndpointConnections *[]RegistryPrivateEndpointConnection `json:"registryPrivateEndpointConnections,omitempty"` + DiscoveryURL *string `json:"discoveryUrl,omitempty"` + IntellectualPropertyPublisher *string `json:"intellectualPropertyPublisher,omitempty"` + ManagedResourceGroup *ArmResourceId `json:"managedResourceGroup,omitempty"` + ManagedResourceGroupSettings *ManagedResourceGroupSettings `json:"managedResourceGroupSettings,omitempty"` + MlFlowRegistryUri *string `json:"mlFlowRegistryUri,omitempty"` + PublicNetworkAccess *string `json:"publicNetworkAccess,omitempty"` + RegionDetails *[]RegistryRegionArmDetails `json:"regionDetails,omitempty"` + RegistryPrivateEndpointConnections *[]RegistryPrivateEndpointConnection `json:"registryPrivateEndpointConnections,omitempty"` + SyndicatedRegistries *[]RegistrySyndicatedRegistriesInlined `json:"syndicatedRegistries,omitempty"` } diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registrysyndicatedregistriesinlined.go b/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registrysyndicatedregistriesinlined.go new file mode 100644 index 00000000000..3fb9d268fec --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_registrysyndicatedregistriesinlined.go @@ -0,0 +1,9 @@ +package registrymanagement + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RegistrySyndicatedRegistriesInlined struct { + SyndicatedRegistry *SyndicatedRegistry `json:"syndicatedRegistry,omitempty"` + SyndicatedRegistryGuid *string `json:"syndicatedRegistryGuid,omitempty"` +} diff --git a/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_syndicatedregistry.go b/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_syndicatedregistry.go new file mode 100644 index 00000000000..d947b380e1a --- /dev/null +++ b/resource-manager/machinelearningservices/2024-10-01-preview/registrymanagement/model_syndicatedregistry.go @@ -0,0 +1,8 @@ +package registrymanagement + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SyndicatedRegistry struct { + RegistryId *string `json:"registryId,omitempty"` +} diff --git a/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go b/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go index c9291fb2fab..793caeabedc 100644 --- a/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go +++ b/resource-manager/network/2024-05-01/networkmanageractiveconfigurations/constants.go @@ -138,6 +138,8 @@ func parseGroupMemberType(input string) (*GroupMemberType, error) { type ProvisioningState string const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -146,6 +148,8 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -168,6 +172,8 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go b/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go index 642ecd4a0bd..6f3a6c4f554 100644 --- a/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go +++ b/resource-manager/network/2024-05-01/networkmanageractiveconnectivityconfigurations/constants.go @@ -217,6 +217,8 @@ func parseIsGlobal(input string) (*IsGlobal, error) { type ProvisioningState string const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -225,6 +227,8 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ + string(ProvisioningStateCanceled), + string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -247,6 +251,8 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ + "canceled": ProvisioningStateCanceled, + "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go b/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go index 9007e4a33df..caa8b3c8747 100644 --- a/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go +++ b/resource-manager/network/2024-05-01/networkmanagereffectiveconnectivityconfiguration/constants.go @@ -217,8 +217,6 @@ func parseIsGlobal(input string) (*IsGlobal, error) { type ProvisioningState string const ( - ProvisioningStateCanceled ProvisioningState = "Canceled" - ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -227,8 +225,6 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ - string(ProvisioningStateCanceled), - string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -251,8 +247,6 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ - "canceled": ProvisioningStateCanceled, - "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go b/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go index 6dbd1e6db74..67086d778e3 100644 --- a/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go +++ b/resource-manager/network/2024-05-01/networkmanagereffectivesecurityadminrules/constants.go @@ -138,8 +138,6 @@ func parseGroupMemberType(input string) (*GroupMemberType, error) { type ProvisioningState string const ( - ProvisioningStateCanceled ProvisioningState = "Canceled" - ProvisioningStateCreating ProvisioningState = "Creating" ProvisioningStateDeleting ProvisioningState = "Deleting" ProvisioningStateFailed ProvisioningState = "Failed" ProvisioningStateSucceeded ProvisioningState = "Succeeded" @@ -148,8 +146,6 @@ const ( func PossibleValuesForProvisioningState() []string { return []string{ - string(ProvisioningStateCanceled), - string(ProvisioningStateCreating), string(ProvisioningStateDeleting), string(ProvisioningStateFailed), string(ProvisioningStateSucceeded), @@ -172,8 +168,6 @@ func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { func parseProvisioningState(input string) (*ProvisioningState, error) { vals := map[string]ProvisioningState{ - "canceled": ProvisioningStateCanceled, - "creating": ProvisioningStateCreating, "deleting": ProvisioningStateDeleting, "failed": ProvisioningStateFailed, "succeeded": ProvisioningStateSucceeded, diff --git a/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparameters.go b/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparameters.go index 7c8c1ecd012..8d9d8518ad1 100644 --- a/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparameters.go +++ b/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparameters.go @@ -4,6 +4,5 @@ package databases // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ForceLinkParameters struct { - GroupNickname string `json:"groupNickname"` - LinkedDatabases []LinkedDatabase `json:"linkedDatabases"` + GeoReplication ForceLinkParametersGeoReplication `json:"geoReplication"` } diff --git a/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparametersgeoreplication.go b/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparametersgeoreplication.go new file mode 100644 index 00000000000..89772649f89 --- /dev/null +++ b/resource-manager/redisenterprise/2024-06-01-preview/databases/model_forcelinkparametersgeoreplication.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParametersGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparameters.go b/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparameters.go index 32ca00618d3..b80b6aaf76b 100644 --- a/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparameters.go +++ b/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparameters.go @@ -4,6 +4,5 @@ package redisenterprise // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ForceLinkParameters struct { - GroupNickname string `json:"groupNickname"` - LinkedDatabases []LinkedDatabase `json:"linkedDatabases"` + GeoReplication ForceLinkParametersGeoReplication `json:"geoReplication"` } diff --git a/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparametersgeoreplication.go b/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparametersgeoreplication.go new file mode 100644 index 00000000000..53242cf971b --- /dev/null +++ b/resource-manager/redisenterprise/2024-06-01-preview/redisenterprise/model_forcelinkparametersgeoreplication.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParametersGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go b/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go index 7c8c1ecd012..8d9d8518ad1 100644 --- a/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparameters.go @@ -4,6 +4,5 @@ package databases // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ForceLinkParameters struct { - GroupNickname string `json:"groupNickname"` - LinkedDatabases []LinkedDatabase `json:"linkedDatabases"` + GeoReplication ForceLinkParametersGeoReplication `json:"geoReplication"` } diff --git a/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparametersgeoreplication.go b/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparametersgeoreplication.go new file mode 100644 index 00000000000..89772649f89 --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/databases/model_forcelinkparametersgeoreplication.go @@ -0,0 +1,9 @@ +package databases + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParametersGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go index 32ca00618d3..b80b6aaf76b 100644 --- a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparameters.go @@ -4,6 +4,5 @@ package redisenterprise // Licensed under the MIT License. See NOTICE.txt in the project root for license information. type ForceLinkParameters struct { - GroupNickname string `json:"groupNickname"` - LinkedDatabases []LinkedDatabase `json:"linkedDatabases"` + GeoReplication ForceLinkParametersGeoReplication `json:"geoReplication"` } diff --git a/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparametersgeoreplication.go b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparametersgeoreplication.go new file mode 100644 index 00000000000..53242cf971b --- /dev/null +++ b/resource-manager/redisenterprise/2024-10-01/redisenterprise/model_forcelinkparametersgeoreplication.go @@ -0,0 +1,9 @@ +package redisenterprise + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ForceLinkParametersGeoReplication struct { + GroupNickname *string `json:"groupNickname,omitempty"` + LinkedDatabases *[]LinkedDatabase `json:"linkedDatabases,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/README.md b/resource-manager/servicenetworking/2025-01-01/associationsinterface/README.md new file mode 100644 index 00000000000..3911595217c --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/associationsinterface` Documentation + +The `associationsinterface` SDK allows for interaction with Azure Resource Manager `servicenetworking` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/associationsinterface" +``` + + +### Client Initialization + +```go +client := associationsinterface.NewAssociationsInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `AssociationsInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "associationName") + +payload := associationsinterface.Association{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `AssociationsInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "associationName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `AssociationsInterfaceClient.Get` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "associationName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `AssociationsInterfaceClient.ListByTrafficController` + +```go +ctx := context.TODO() +id := associationsinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +// alternatively `client.ListByTrafficController(ctx, id)` can be used to do batched pagination +items, err := client.ListByTrafficControllerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `AssociationsInterfaceClient.Update` + +```go +ctx := context.TODO() +id := associationsinterface.NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "associationName") + +payload := associationsinterface.AssociationUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/client.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/client.go new file mode 100644 index 00000000000..56041630036 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/client.go @@ -0,0 +1,26 @@ +package associationsinterface + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationsInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewAssociationsInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*AssociationsInterfaceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "associationsinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating AssociationsInterfaceClient: %+v", err) + } + + return &AssociationsInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/constants.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/constants.go new file mode 100644 index 00000000000..b11441f4b9a --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/constants.go @@ -0,0 +1,104 @@ +package associationsinterface + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationType string + +const ( + AssociationTypeSubnets AssociationType = "subnets" +) + +func PossibleValuesForAssociationType() []string { + return []string{ + string(AssociationTypeSubnets), + } +} + +func (s *AssociationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAssociationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAssociationType(input string) (*AssociationType, error) { + vals := map[string]AssociationType{ + "subnets": AssociationTypeSubnets, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AssociationType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_association.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_association.go new file mode 100644 index 00000000000..f9dc7107c00 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_association.go @@ -0,0 +1,139 @@ +package associationsinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&AssociationId{}) +} + +var _ resourceids.ResourceId = &AssociationId{} + +// AssociationId is a struct representing the Resource ID for a Association +type AssociationId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string + AssociationName string +} + +// NewAssociationID returns a new AssociationId struct +func NewAssociationID(subscriptionId string, resourceGroupName string, trafficControllerName string, associationName string) AssociationId { + return AssociationId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + AssociationName: associationName, + } +} + +// ParseAssociationID parses 'input' into a AssociationId +func ParseAssociationID(input string) (*AssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AssociationId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AssociationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAssociationIDInsensitively parses 'input' case-insensitively into a AssociationId +// note: this method should only be used for API response data and not user input +func ParseAssociationIDInsensitively(input string) (*AssociationId, error) { + parser := resourceids.NewParserFromResourceIdType(&AssociationId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AssociationId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AssociationId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + if id.AssociationName, ok = input.Parsed["associationName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "associationName", input) + } + + return nil +} + +// ValidateAssociationID checks that 'input' can be parsed as a Association ID +func ValidateAssociationID(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 _, err := ParseAssociationID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Association ID +func (id AssociationId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s/associations/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName, id.AssociationName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Association ID +func (id AssociationId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + resourceids.StaticSegment("staticAssociations", "associations", "associations"), + resourceids.UserSpecifiedSegment("associationName", "associationName"), + } +} + +// String returns a human-readable description of this Association ID +func (id AssociationId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + fmt.Sprintf("Association Name: %q", id.AssociationName), + } + return fmt.Sprintf("Association (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_association_test.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_association_test.go new file mode 100644 index 00000000000..8dd9fcca214 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_association_test.go @@ -0,0 +1,327 @@ +package associationsinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &AssociationId{} + +func TestNewAssociationID(t *testing.T) { + id := NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "associationName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } + + if id.AssociationName != "associationName" { + t.Fatalf("Expected %q but got %q for Segment 'AssociationName'", id.AssociationName, "associationName") + } +} + +func TestFormatAssociationID(t *testing.T) { + actual := NewAssociationID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "associationName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations/associationName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseAssociationID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AssociationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations/associationName", + Expected: &AssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + AssociationName: "associationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations/associationName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAssociationID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.AssociationName != v.Expected.AssociationName { + t.Fatalf("Expected %q but got %q for AssociationName", v.Expected.AssociationName, actual.AssociationName) + } + + } +} + +func TestParseAssociationIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *AssociationId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/aSsOcIaTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations/associationName", + Expected: &AssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + AssociationName: "associationName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/associations/associationName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/aSsOcIaTiOnS/aSsOcIaTiOnNaMe", + Expected: &AssociationId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + AssociationName: "aSsOcIaTiOnNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/aSsOcIaTiOnS/aSsOcIaTiOnNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseAssociationIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.AssociationName != v.Expected.AssociationName { + t.Fatalf("Expected %q but got %q for AssociationName", v.Expected.AssociationName, actual.AssociationName) + } + + } +} + +func TestSegmentsForAssociationId(t *testing.T) { + segments := AssociationId{}.Segments() + if len(segments) == 0 { + t.Fatalf("AssociationId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..ce9c4da0d6c --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_trafficcontroller.go @@ -0,0 +1,130 @@ +package associationsinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TrafficControllerId{}) +} + +var _ resourceids.ResourceId = &TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TrafficControllerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + return nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 _, err := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..a822ef1cece --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package associationsinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_createorupdate.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_createorupdate.go new file mode 100644 index 00000000000..9c84e3a3260 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_createorupdate.go @@ -0,0 +1,75 @@ +package associationsinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Association +} + +// CreateOrUpdate ... +func (c AssociationsInterfaceClient) CreateOrUpdate(ctx context.Context, id AssociationId, input Association) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c AssociationsInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id AssociationId, input Association) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_delete.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_delete.go new file mode 100644 index 00000000000..3a1ec07b70e --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_delete.go @@ -0,0 +1,70 @@ +package associationsinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c AssociationsInterfaceClient) Delete(ctx context.Context, id AssociationId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c AssociationsInterfaceClient) DeleteThenPoll(ctx context.Context, id AssociationId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_get.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_get.go new file mode 100644 index 00000000000..4ba57d2c856 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_get.go @@ -0,0 +1,53 @@ +package associationsinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Association +} + +// Get ... +func (c AssociationsInterfaceClient) Get(ctx context.Context, id AssociationId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Association + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_listbytrafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_listbytrafficcontroller.go new file mode 100644 index 00000000000..b2f29ec61c7 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_listbytrafficcontroller.go @@ -0,0 +1,105 @@ +package associationsinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByTrafficControllerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Association +} + +type ListByTrafficControllerCompleteResult struct { + LatestHttpResponse *http.Response + Items []Association +} + +type ListByTrafficControllerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTrafficControllerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByTrafficController ... +func (c AssociationsInterfaceClient) ListByTrafficController(ctx context.Context, id TrafficControllerId) (result ListByTrafficControllerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByTrafficControllerCustomPager{}, + Path: fmt.Sprintf("%s/associations", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Association `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTrafficControllerComplete retrieves all the results into a single object +func (c AssociationsInterfaceClient) ListByTrafficControllerComplete(ctx context.Context, id TrafficControllerId) (ListByTrafficControllerCompleteResult, error) { + return c.ListByTrafficControllerCompleteMatchingPredicate(ctx, id, AssociationOperationPredicate{}) +} + +// ListByTrafficControllerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c AssociationsInterfaceClient) ListByTrafficControllerCompleteMatchingPredicate(ctx context.Context, id TrafficControllerId, predicate AssociationOperationPredicate) (result ListByTrafficControllerCompleteResult, err error) { + items := make([]Association, 0) + + resp, err := c.ListByTrafficController(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTrafficControllerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_update.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_update.go new file mode 100644 index 00000000000..dab57f9779f --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/method_update.go @@ -0,0 +1,57 @@ +package associationsinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Association +} + +// Update ... +func (c AssociationsInterfaceClient) Update(ctx context.Context, id AssociationId, input AssociationUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Association + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_association.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_association.go new file mode 100644 index 00000000000..51e5fc503be --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_association.go @@ -0,0 +1,18 @@ +package associationsinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Association struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *AssociationProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationproperties.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationproperties.go new file mode 100644 index 00000000000..cb4915b6591 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationproperties.go @@ -0,0 +1,10 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationProperties struct { + AssociationType AssociationType `json:"associationType"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + Subnet *AssociationSubnet `json:"subnet,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationsubnet.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationsubnet.go new file mode 100644 index 00000000000..0ca18bb5ea3 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationsubnet.go @@ -0,0 +1,8 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationSubnet struct { + Id string `json:"id"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationsubnetupdate.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationsubnetupdate.go new file mode 100644 index 00000000000..c24d87e1a7b --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationsubnetupdate.go @@ -0,0 +1,8 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationSubnetUpdate struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationupdate.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationupdate.go new file mode 100644 index 00000000000..86f5d0c0bb2 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationupdate.go @@ -0,0 +1,9 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationUpdate struct { + Properties *AssociationUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationupdateproperties.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationupdateproperties.go new file mode 100644 index 00000000000..84beffe2c44 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/model_associationupdateproperties.go @@ -0,0 +1,9 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationUpdateProperties struct { + AssociationType *AssociationType `json:"associationType,omitempty"` + Subnet *AssociationSubnetUpdate `json:"subnet,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/predicates.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/predicates.go new file mode 100644 index 00000000000..52d86740212 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/predicates.go @@ -0,0 +1,32 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AssociationOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p AssociationOperationPredicate) Matches(input Association) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/servicenetworking/2025-01-01/associationsinterface/version.go b/resource-manager/servicenetworking/2025-01-01/associationsinterface/version.go new file mode 100644 index 00000000000..41bd3da888f --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/associationsinterface/version.go @@ -0,0 +1,10 @@ +package associationsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/associationsinterface/2025-01-01" +} diff --git a/resource-manager/servicenetworking/2025-01-01/client.go b/resource-manager/servicenetworking/2025-01-01/client.go new file mode 100644 index 00000000000..4837ec89c37 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/client.go @@ -0,0 +1,55 @@ +package v2025_01_01 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/associationsinterface" + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/frontendsinterface" + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface" + "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +type Client struct { + AssociationsInterface *associationsinterface.AssociationsInterfaceClient + FrontendsInterface *frontendsinterface.FrontendsInterfaceClient + SecurityPoliciesInterface *securitypoliciesinterface.SecurityPoliciesInterfaceClient + TrafficControllerInterface *trafficcontrollerinterface.TrafficControllerInterfaceClient +} + +func NewClientWithBaseURI(sdkApi sdkEnv.Api, configureFunc func(c *resourcemanager.Client)) (*Client, error) { + associationsInterfaceClient, err := associationsinterface.NewAssociationsInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building AssociationsInterface client: %+v", err) + } + configureFunc(associationsInterfaceClient.Client) + + frontendsInterfaceClient, err := frontendsinterface.NewFrontendsInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building FrontendsInterface client: %+v", err) + } + configureFunc(frontendsInterfaceClient.Client) + + securityPoliciesInterfaceClient, err := securitypoliciesinterface.NewSecurityPoliciesInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building SecurityPoliciesInterface client: %+v", err) + } + configureFunc(securityPoliciesInterfaceClient.Client) + + trafficControllerInterfaceClient, err := trafficcontrollerinterface.NewTrafficControllerInterfaceClientWithBaseURI(sdkApi) + if err != nil { + return nil, fmt.Errorf("building TrafficControllerInterface client: %+v", err) + } + configureFunc(trafficControllerInterfaceClient.Client) + + return &Client{ + AssociationsInterface: associationsInterfaceClient, + FrontendsInterface: frontendsInterfaceClient, + SecurityPoliciesInterface: securityPoliciesInterfaceClient, + TrafficControllerInterface: trafficControllerInterfaceClient, + }, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/README.md b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/README.md new file mode 100644 index 00000000000..a6076c2ad07 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/frontendsinterface` Documentation + +The `frontendsinterface` SDK allows for interaction with Azure Resource Manager `servicenetworking` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/frontendsinterface" +``` + + +### Client Initialization + +```go +client := frontendsinterface.NewFrontendsInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `FrontendsInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "frontendName") + +payload := frontendsinterface.Frontend{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `FrontendsInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "frontendName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `FrontendsInterfaceClient.Get` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "frontendName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `FrontendsInterfaceClient.ListByTrafficController` + +```go +ctx := context.TODO() +id := frontendsinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +// alternatively `client.ListByTrafficController(ctx, id)` can be used to do batched pagination +items, err := client.ListByTrafficControllerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `FrontendsInterfaceClient.Update` + +```go +ctx := context.TODO() +id := frontendsinterface.NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "frontendName") + +payload := frontendsinterface.FrontendUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/client.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/client.go new file mode 100644 index 00000000000..77cd97766d3 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/client.go @@ -0,0 +1,26 @@ +package frontendsinterface + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendsInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewFrontendsInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*FrontendsInterfaceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "frontendsinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating FrontendsInterfaceClient: %+v", err) + } + + return &FrontendsInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/constants.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/constants.go new file mode 100644 index 00000000000..ce65291eaa3 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/constants.go @@ -0,0 +1,66 @@ +package frontendsinterface + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_frontend.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_frontend.go new file mode 100644 index 00000000000..8432266caae --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_frontend.go @@ -0,0 +1,139 @@ +package frontendsinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&FrontendId{}) +} + +var _ resourceids.ResourceId = &FrontendId{} + +// FrontendId is a struct representing the Resource ID for a Frontend +type FrontendId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string + FrontendName string +} + +// NewFrontendID returns a new FrontendId struct +func NewFrontendID(subscriptionId string, resourceGroupName string, trafficControllerName string, frontendName string) FrontendId { + return FrontendId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + FrontendName: frontendName, + } +} + +// ParseFrontendID parses 'input' into a FrontendId +func ParseFrontendID(input string) (*FrontendId, error) { + parser := resourceids.NewParserFromResourceIdType(&FrontendId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FrontendId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFrontendIDInsensitively parses 'input' case-insensitively into a FrontendId +// note: this method should only be used for API response data and not user input +func ParseFrontendIDInsensitively(input string) (*FrontendId, error) { + parser := resourceids.NewParserFromResourceIdType(&FrontendId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FrontendId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FrontendId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + if id.FrontendName, ok = input.Parsed["frontendName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "frontendName", input) + } + + return nil +} + +// ValidateFrontendID checks that 'input' can be parsed as a Frontend ID +func ValidateFrontendID(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 _, err := ParseFrontendID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Frontend ID +func (id FrontendId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s/frontends/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName, id.FrontendName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Frontend ID +func (id FrontendId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + resourceids.StaticSegment("staticFrontends", "frontends", "frontends"), + resourceids.UserSpecifiedSegment("frontendName", "frontendName"), + } +} + +// String returns a human-readable description of this Frontend ID +func (id FrontendId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + fmt.Sprintf("Frontend Name: %q", id.FrontendName), + } + return fmt.Sprintf("Frontend (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_frontend_test.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_frontend_test.go new file mode 100644 index 00000000000..f21b8553a80 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_frontend_test.go @@ -0,0 +1,327 @@ +package frontendsinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &FrontendId{} + +func TestNewFrontendID(t *testing.T) { + id := NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "frontendName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } + + if id.FrontendName != "frontendName" { + t.Fatalf("Expected %q but got %q for Segment 'FrontendName'", id.FrontendName, "frontendName") + } +} + +func TestFormatFrontendID(t *testing.T) { + actual := NewFrontendID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "frontendName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends/frontendName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseFrontendID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FrontendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends/frontendName", + Expected: &FrontendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + FrontendName: "frontendName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends/frontendName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFrontendID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.FrontendName != v.Expected.FrontendName { + t.Fatalf("Expected %q but got %q for FrontendName", v.Expected.FrontendName, actual.FrontendName) + } + + } +} + +func TestParseFrontendIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *FrontendId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/fRoNtEnDs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends/frontendName", + Expected: &FrontendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + FrontendName: "frontendName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/frontends/frontendName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/fRoNtEnDs/fRoNtEnDnAmE", + Expected: &FrontendId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + FrontendName: "fRoNtEnDnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/fRoNtEnDs/fRoNtEnDnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseFrontendIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.FrontendName != v.Expected.FrontendName { + t.Fatalf("Expected %q but got %q for FrontendName", v.Expected.FrontendName, actual.FrontendName) + } + + } +} + +func TestSegmentsForFrontendId(t *testing.T) { + segments := FrontendId{}.Segments() + if len(segments) == 0 { + t.Fatalf("FrontendId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..be465042d57 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_trafficcontroller.go @@ -0,0 +1,130 @@ +package frontendsinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TrafficControllerId{}) +} + +var _ resourceids.ResourceId = &TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TrafficControllerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + return nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 _, err := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..135a6a0af48 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package frontendsinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_createorupdate.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_createorupdate.go new file mode 100644 index 00000000000..3ff52741e99 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_createorupdate.go @@ -0,0 +1,75 @@ +package frontendsinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Frontend +} + +// CreateOrUpdate ... +func (c FrontendsInterfaceClient) CreateOrUpdate(ctx context.Context, id FrontendId, input Frontend) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c FrontendsInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id FrontendId, input Frontend) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_delete.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_delete.go new file mode 100644 index 00000000000..25ad0defd2a --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_delete.go @@ -0,0 +1,70 @@ +package frontendsinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c FrontendsInterfaceClient) Delete(ctx context.Context, id FrontendId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c FrontendsInterfaceClient) DeleteThenPoll(ctx context.Context, id FrontendId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_get.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_get.go new file mode 100644 index 00000000000..983aac9a874 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_get.go @@ -0,0 +1,53 @@ +package frontendsinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Frontend +} + +// Get ... +func (c FrontendsInterfaceClient) Get(ctx context.Context, id FrontendId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Frontend + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_listbytrafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_listbytrafficcontroller.go new file mode 100644 index 00000000000..39972b7f9c5 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_listbytrafficcontroller.go @@ -0,0 +1,105 @@ +package frontendsinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByTrafficControllerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Frontend +} + +type ListByTrafficControllerCompleteResult struct { + LatestHttpResponse *http.Response + Items []Frontend +} + +type ListByTrafficControllerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTrafficControllerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByTrafficController ... +func (c FrontendsInterfaceClient) ListByTrafficController(ctx context.Context, id TrafficControllerId) (result ListByTrafficControllerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByTrafficControllerCustomPager{}, + Path: fmt.Sprintf("%s/frontends", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Frontend `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTrafficControllerComplete retrieves all the results into a single object +func (c FrontendsInterfaceClient) ListByTrafficControllerComplete(ctx context.Context, id TrafficControllerId) (ListByTrafficControllerCompleteResult, error) { + return c.ListByTrafficControllerCompleteMatchingPredicate(ctx, id, FrontendOperationPredicate{}) +} + +// ListByTrafficControllerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c FrontendsInterfaceClient) ListByTrafficControllerCompleteMatchingPredicate(ctx context.Context, id TrafficControllerId, predicate FrontendOperationPredicate) (result ListByTrafficControllerCompleteResult, err error) { + items := make([]Frontend, 0) + + resp, err := c.ListByTrafficController(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTrafficControllerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_update.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_update.go new file mode 100644 index 00000000000..a4c8148292c --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/method_update.go @@ -0,0 +1,57 @@ +package frontendsinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *Frontend +} + +// Update ... +func (c FrontendsInterfaceClient) Update(ctx context.Context, id FrontendId, input FrontendUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model Frontend + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontend.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontend.go new file mode 100644 index 00000000000..d60b842d9ca --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontend.go @@ -0,0 +1,18 @@ +package frontendsinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Frontend struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *FrontendProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontendproperties.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontendproperties.go new file mode 100644 index 00000000000..666719495f9 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontendproperties.go @@ -0,0 +1,9 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendProperties struct { + Fqdn *string `json:"fqdn,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontendupdate.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontendupdate.go new file mode 100644 index 00000000000..ac589ede9df --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/model_frontendupdate.go @@ -0,0 +1,8 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendUpdate struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/predicates.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/predicates.go new file mode 100644 index 00000000000..15b28850961 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/predicates.go @@ -0,0 +1,32 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type FrontendOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p FrontendOperationPredicate) Matches(input Frontend) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/servicenetworking/2025-01-01/frontendsinterface/version.go b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/version.go new file mode 100644 index 00000000000..b08c8904a3c --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/frontendsinterface/version.go @@ -0,0 +1,10 @@ +package frontendsinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/frontendsinterface/2025-01-01" +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/README.md b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/README.md new file mode 100644 index 00000000000..e5052ff56b9 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/README.md @@ -0,0 +1,103 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface` Documentation + +The `securitypoliciesinterface` SDK allows for interaction with Azure Resource Manager `servicenetworking` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface" +``` + + +### Client Initialization + +```go +client := securitypoliciesinterface.NewSecurityPoliciesInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecurityPoliciesInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := securitypoliciesinterface.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "securityPolicyName") + +payload := securitypoliciesinterface.SecurityPolicy{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecurityPoliciesInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := securitypoliciesinterface.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "securityPolicyName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecurityPoliciesInterfaceClient.Get` + +```go +ctx := context.TODO() +id := securitypoliciesinterface.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "securityPolicyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SecurityPoliciesInterfaceClient.ListByTrafficController` + +```go +ctx := context.TODO() +id := securitypoliciesinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +// alternatively `client.ListByTrafficController(ctx, id)` can be used to do batched pagination +items, err := client.ListByTrafficControllerComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SecurityPoliciesInterfaceClient.Update` + +```go +ctx := context.TODO() +id := securitypoliciesinterface.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "securityPolicyName") + +payload := securitypoliciesinterface.SecurityPolicyUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/client.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/client.go new file mode 100644 index 00000000000..769a48d7e2b --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/client.go @@ -0,0 +1,26 @@ +package securitypoliciesinterface + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPoliciesInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewSecurityPoliciesInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityPoliciesInterfaceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "securitypoliciesinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityPoliciesInterfaceClient: %+v", err) + } + + return &SecurityPoliciesInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/constants.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/constants.go new file mode 100644 index 00000000000..0218d5c44eb --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/constants.go @@ -0,0 +1,104 @@ +package securitypoliciesinterface + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyType string + +const ( + PolicyTypeWaf PolicyType = "waf" +) + +func PossibleValuesForPolicyType() []string { + return []string{ + string(PolicyTypeWaf), + } +} + +func (s *PolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyType(input string) (*PolicyType, error) { + vals := map[string]PolicyType{ + "waf": PolicyTypeWaf, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_securitypolicy.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_securitypolicy.go new file mode 100644 index 00000000000..3bd2a722a67 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_securitypolicy.go @@ -0,0 +1,139 @@ +package securitypoliciesinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SecurityPolicyId{}) +} + +var _ resourceids.ResourceId = &SecurityPolicyId{} + +// SecurityPolicyId is a struct representing the Resource ID for a Security Policy +type SecurityPolicyId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string + SecurityPolicyName string +} + +// NewSecurityPolicyID returns a new SecurityPolicyId struct +func NewSecurityPolicyID(subscriptionId string, resourceGroupName string, trafficControllerName string, securityPolicyName string) SecurityPolicyId { + return SecurityPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + SecurityPolicyName: securityPolicyName, + } +} + +// ParseSecurityPolicyID parses 'input' into a SecurityPolicyId +func ParseSecurityPolicyID(input string) (*SecurityPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecurityPolicyIDInsensitively parses 'input' case-insensitively into a SecurityPolicyId +// note: this method should only be used for API response data and not user input +func ParseSecurityPolicyIDInsensitively(input string) (*SecurityPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecurityPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + if id.SecurityPolicyName, ok = input.Parsed["securityPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityPolicyName", input) + } + + return nil +} + +// ValidateSecurityPolicyID checks that 'input' can be parsed as a Security Policy ID +func ValidateSecurityPolicyID(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 _, err := ParseSecurityPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Security Policy ID +func (id SecurityPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s/securityPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName, id.SecurityPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Security Policy ID +func (id SecurityPolicyId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + resourceids.StaticSegment("staticSecurityPolicies", "securityPolicies", "securityPolicies"), + resourceids.UserSpecifiedSegment("securityPolicyName", "securityPolicyName"), + } +} + +// String returns a human-readable description of this Security Policy ID +func (id SecurityPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + fmt.Sprintf("Security Policy Name: %q", id.SecurityPolicyName), + } + return fmt.Sprintf("Security Policy (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_securitypolicy_test.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_securitypolicy_test.go new file mode 100644 index 00000000000..696713aff2e --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_securitypolicy_test.go @@ -0,0 +1,327 @@ +package securitypoliciesinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &SecurityPolicyId{} + +func TestNewSecurityPolicyID(t *testing.T) { + id := NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "securityPolicyName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } + + if id.SecurityPolicyName != "securityPolicyName" { + t.Fatalf("Expected %q but got %q for Segment 'SecurityPolicyName'", id.SecurityPolicyName, "securityPolicyName") + } +} + +func TestFormatSecurityPolicyID(t *testing.T) { + actual := NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName", "securityPolicyName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies/securityPolicyName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseSecurityPolicyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies/securityPolicyName", + Expected: &SecurityPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + SecurityPolicyName: "securityPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies/securityPolicyName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityPolicyID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.SecurityPolicyName != v.Expected.SecurityPolicyName { + t.Fatalf("Expected %q but got %q for SecurityPolicyName", v.Expected.SecurityPolicyName, actual.SecurityPolicyName) + } + + } +} + +func TestParseSecurityPolicyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SecurityPolicyId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/sEcUrItYpOlIcIeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies/securityPolicyName", + Expected: &SecurityPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + SecurityPolicyName: "securityPolicyName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/securityPolicies/securityPolicyName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/sEcUrItYpOlIcIeS/sEcUrItYpOlIcYnAmE", + Expected: &SecurityPolicyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + SecurityPolicyName: "sEcUrItYpOlIcYnAmE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/sEcUrItYpOlIcIeS/sEcUrItYpOlIcYnAmE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseSecurityPolicyIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + if actual.SecurityPolicyName != v.Expected.SecurityPolicyName { + t.Fatalf("Expected %q but got %q for SecurityPolicyName", v.Expected.SecurityPolicyName, actual.SecurityPolicyName) + } + + } +} + +func TestSegmentsForSecurityPolicyId(t *testing.T) { + segments := SecurityPolicyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("SecurityPolicyId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..9de0e0553d9 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_trafficcontroller.go @@ -0,0 +1,130 @@ +package securitypoliciesinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TrafficControllerId{}) +} + +var _ resourceids.ResourceId = &TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TrafficControllerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + return nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 _, err := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..f5a37ed100f --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package securitypoliciesinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_createorupdate.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_createorupdate.go new file mode 100644 index 00000000000..667fb80b7cc --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_createorupdate.go @@ -0,0 +1,75 @@ +package securitypoliciesinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// CreateOrUpdate ... +func (c SecurityPoliciesInterfaceClient) CreateOrUpdate(ctx context.Context, id SecurityPolicyId, input SecurityPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c SecurityPoliciesInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id SecurityPolicyId, input SecurityPolicy) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_delete.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_delete.go new file mode 100644 index 00000000000..e54c28e108c --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_delete.go @@ -0,0 +1,70 @@ +package securitypoliciesinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityPoliciesInterfaceClient) Delete(ctx context.Context, id SecurityPolicyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SecurityPoliciesInterfaceClient) DeleteThenPoll(ctx context.Context, id SecurityPolicyId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_get.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_get.go new file mode 100644 index 00000000000..1fe00ca8587 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_get.go @@ -0,0 +1,53 @@ +package securitypoliciesinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Get ... +func (c SecurityPoliciesInterfaceClient) Get(ctx context.Context, id SecurityPolicyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SecurityPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_listbytrafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_listbytrafficcontroller.go new file mode 100644 index 00000000000..43b86528c43 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_listbytrafficcontroller.go @@ -0,0 +1,105 @@ +package securitypoliciesinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByTrafficControllerOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityPolicy +} + +type ListByTrafficControllerCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityPolicy +} + +type ListByTrafficControllerCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByTrafficControllerCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByTrafficController ... +func (c SecurityPoliciesInterfaceClient) ListByTrafficController(ctx context.Context, id TrafficControllerId) (result ListByTrafficControllerOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByTrafficControllerCustomPager{}, + Path: fmt.Sprintf("%s/securityPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SecurityPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByTrafficControllerComplete retrieves all the results into a single object +func (c SecurityPoliciesInterfaceClient) ListByTrafficControllerComplete(ctx context.Context, id TrafficControllerId) (ListByTrafficControllerCompleteResult, error) { + return c.ListByTrafficControllerCompleteMatchingPredicate(ctx, id, SecurityPolicyOperationPredicate{}) +} + +// ListByTrafficControllerCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityPoliciesInterfaceClient) ListByTrafficControllerCompleteMatchingPredicate(ctx context.Context, id TrafficControllerId, predicate SecurityPolicyOperationPredicate) (result ListByTrafficControllerCompleteResult, err error) { + items := make([]SecurityPolicy, 0) + + resp, err := c.ListByTrafficController(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByTrafficControllerCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_update.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_update.go new file mode 100644 index 00000000000..849703155ff --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/method_update.go @@ -0,0 +1,57 @@ +package securitypoliciesinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Update ... +func (c SecurityPoliciesInterfaceClient) Update(ctx context.Context, id SecurityPolicyId, input SecurityPolicyUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SecurityPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicy.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicy.go new file mode 100644 index 00000000000..8cb6d97686a --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicy.go @@ -0,0 +1,18 @@ +package securitypoliciesinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicy struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *SecurityPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyproperties.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyproperties.go new file mode 100644 index 00000000000..b3506421a55 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyproperties.go @@ -0,0 +1,10 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyProperties struct { + PolicyType *PolicyType `json:"policyType,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + WafPolicy *WafPolicy `json:"wafPolicy,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyupdate.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyupdate.go new file mode 100644 index 00000000000..952db519351 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyupdate.go @@ -0,0 +1,9 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyUpdate struct { + Properties *SecurityPolicyUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyupdateproperties.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyupdateproperties.go new file mode 100644 index 00000000000..5627e8f6be6 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_securitypolicyupdateproperties.go @@ -0,0 +1,8 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyUpdateProperties struct { + WafPolicy *WafPolicyUpdate `json:"wafPolicy,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_wafpolicy.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_wafpolicy.go new file mode 100644 index 00000000000..40e7b8a0072 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_wafpolicy.go @@ -0,0 +1,8 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafPolicy struct { + Id string `json:"id"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_wafpolicyupdate.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_wafpolicyupdate.go new file mode 100644 index 00000000000..f6ce0cfb060 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/model_wafpolicyupdate.go @@ -0,0 +1,8 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafPolicyUpdate struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/predicates.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/predicates.go new file mode 100644 index 00000000000..ff70b635723 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/predicates.go @@ -0,0 +1,32 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p SecurityPolicyOperationPredicate) Matches(input SecurityPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/version.go b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/version.go new file mode 100644 index 00000000000..78eb46ad38d --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/securitypoliciesinterface/version.go @@ -0,0 +1,10 @@ +package securitypoliciesinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/securitypoliciesinterface/2025-01-01" +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/README.md b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/README.md new file mode 100644 index 00000000000..b87921fe9fb --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/README.md @@ -0,0 +1,121 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface` Documentation + +The `trafficcontrollerinterface` SDK allows for interaction with Azure Resource Manager `servicenetworking` (API Version `2025-01-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface" +``` + + +### Client Initialization + +```go +client := trafficcontrollerinterface.NewTrafficControllerInterfaceClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `TrafficControllerInterfaceClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +payload := trafficcontrollerinterface.TrafficController{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.Delete` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.Get` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.ListBySubscription` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `TrafficControllerInterfaceClient.Update` + +```go +ctx := context.TODO() +id := trafficcontrollerinterface.NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + +payload := trafficcontrollerinterface.TrafficControllerUpdate{ + // ... +} + + +read, err := client.Update(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/client.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/client.go new file mode 100644 index 00000000000..2cf5ce13358 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/client.go @@ -0,0 +1,26 @@ +package trafficcontrollerinterface + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerInterfaceClient struct { + Client *resourcemanager.Client +} + +func NewTrafficControllerInterfaceClientWithBaseURI(sdkApi sdkEnv.Api) (*TrafficControllerInterfaceClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "trafficcontrollerinterface", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating TrafficControllerInterfaceClient: %+v", err) + } + + return &TrafficControllerInterfaceClient{ + Client: client, + }, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/constants.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/constants.go new file mode 100644 index 00000000000..3eaf31f91f0 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/constants.go @@ -0,0 +1,66 @@ +package trafficcontrollerinterface + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func (s *ProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/id_trafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/id_trafficcontroller.go new file mode 100644 index 00000000000..6bd9619a01c --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/id_trafficcontroller.go @@ -0,0 +1,130 @@ +package trafficcontrollerinterface + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&TrafficControllerId{}) +} + +var _ resourceids.ResourceId = &TrafficControllerId{} + +// TrafficControllerId is a struct representing the Resource ID for a Traffic Controller +type TrafficControllerId struct { + SubscriptionId string + ResourceGroupName string + TrafficControllerName string +} + +// NewTrafficControllerID returns a new TrafficControllerId struct +func NewTrafficControllerID(subscriptionId string, resourceGroupName string, trafficControllerName string) TrafficControllerId { + return TrafficControllerId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + TrafficControllerName: trafficControllerName, + } +} + +// ParseTrafficControllerID parses 'input' into a TrafficControllerId +func ParseTrafficControllerID(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseTrafficControllerIDInsensitively parses 'input' case-insensitively into a TrafficControllerId +// note: this method should only be used for API response data and not user input +func ParseTrafficControllerIDInsensitively(input string) (*TrafficControllerId, error) { + parser := resourceids.NewParserFromResourceIdType(&TrafficControllerId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := TrafficControllerId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *TrafficControllerId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.TrafficControllerName, ok = input.Parsed["trafficControllerName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "trafficControllerName", input) + } + + return nil +} + +// ValidateTrafficControllerID checks that 'input' can be parsed as a Traffic Controller ID +func ValidateTrafficControllerID(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 _, err := ParseTrafficControllerID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Traffic Controller ID +func (id TrafficControllerId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ServiceNetworking/trafficControllers/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.TrafficControllerName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Traffic Controller ID +func (id TrafficControllerId) 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("staticMicrosoftServiceNetworking", "Microsoft.ServiceNetworking", "Microsoft.ServiceNetworking"), + resourceids.StaticSegment("staticTrafficControllers", "trafficControllers", "trafficControllers"), + resourceids.UserSpecifiedSegment("trafficControllerName", "trafficControllerName"), + } +} + +// String returns a human-readable description of this Traffic Controller ID +func (id TrafficControllerId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Traffic Controller Name: %q", id.TrafficControllerName), + } + return fmt.Sprintf("Traffic Controller (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/id_trafficcontroller_test.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/id_trafficcontroller_test.go new file mode 100644 index 00000000000..36d9603bf4e --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/id_trafficcontroller_test.go @@ -0,0 +1,282 @@ +package trafficcontrollerinterface + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = &TrafficControllerId{} + +func TestNewTrafficControllerID(t *testing.T) { + id := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.TrafficControllerName != "trafficControllerName" { + t.Fatalf("Expected %q but got %q for Segment 'TrafficControllerName'", id.TrafficControllerName, "trafficControllerName") + } +} + +func TestFormatTrafficControllerID(t *testing.T) { + actual := NewTrafficControllerID("12345678-1234-9876-4563-123456789012", "example-resource-group", "trafficControllerName").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseTrafficControllerID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestParseTrafficControllerIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *TrafficControllerId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + TrafficControllerName: "trafficControllerName", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.ServiceNetworking/trafficControllers/trafficControllerName/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe", + Expected: &TrafficControllerId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + TrafficControllerName: "tRaFfIcCoNtRoLlErNaMe", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.sErViCeNeTwOrKiNg/tRaFfIcCoNtRoLlErS/tRaFfIcCoNtRoLlErNaMe/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseTrafficControllerIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.TrafficControllerName != v.Expected.TrafficControllerName { + t.Fatalf("Expected %q but got %q for TrafficControllerName", v.Expected.TrafficControllerName, actual.TrafficControllerName) + } + + } +} + +func TestSegmentsForTrafficControllerId(t *testing.T) { + segments := TrafficControllerId{}.Segments() + if len(segments) == 0 { + t.Fatalf("TrafficControllerId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_createorupdate.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_createorupdate.go new file mode 100644 index 00000000000..b80c4ffd4f9 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_createorupdate.go @@ -0,0 +1,75 @@ +package trafficcontrollerinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *TrafficController +} + +// CreateOrUpdate ... +func (c TrafficControllerInterfaceClient) CreateOrUpdate(ctx context.Context, id TrafficControllerId, input TrafficController) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c TrafficControllerInterfaceClient) CreateOrUpdateThenPoll(ctx context.Context, id TrafficControllerId, input TrafficController) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_delete.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_delete.go new file mode 100644 index 00000000000..c433146cef9 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_delete.go @@ -0,0 +1,70 @@ +package trafficcontrollerinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c TrafficControllerInterfaceClient) Delete(ctx context.Context, id TrafficControllerId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c TrafficControllerInterfaceClient) DeleteThenPoll(ctx context.Context, id TrafficControllerId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_get.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_get.go new file mode 100644 index 00000000000..076825ace84 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_get.go @@ -0,0 +1,53 @@ +package trafficcontrollerinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TrafficController +} + +// Get ... +func (c TrafficControllerInterfaceClient) Get(ctx context.Context, id TrafficControllerId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TrafficController + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_listbyresourcegroup.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_listbyresourcegroup.go new file mode 100644 index 00000000000..adc21a74865 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package trafficcontrollerinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TrafficController +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []TrafficController +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c TrafficControllerInterfaceClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ServiceNetworking/trafficControllers", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TrafficController `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c TrafficControllerInterfaceClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, TrafficControllerOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TrafficControllerInterfaceClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate TrafficControllerOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]TrafficController, 0) + + resp, err := c.ListByResourceGroup(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_listbysubscription.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_listbysubscription.go new file mode 100644 index 00000000000..c85c83eec57 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_listbysubscription.go @@ -0,0 +1,106 @@ +package trafficcontrollerinterface + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]TrafficController +} + +type ListBySubscriptionCompleteResult struct { + LatestHttpResponse *http.Response + Items []TrafficController +} + +type ListBySubscriptionCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListBySubscriptionCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListBySubscription ... +func (c TrafficControllerInterfaceClient) ListBySubscription(ctx context.Context, id commonids.SubscriptionId) (result ListBySubscriptionOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListBySubscriptionCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.ServiceNetworking/trafficControllers", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]TrafficController `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListBySubscriptionComplete retrieves all the results into a single object +func (c TrafficControllerInterfaceClient) ListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ListBySubscriptionCompleteResult, error) { + return c.ListBySubscriptionCompleteMatchingPredicate(ctx, id, TrafficControllerOperationPredicate{}) +} + +// ListBySubscriptionCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c TrafficControllerInterfaceClient) ListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate TrafficControllerOperationPredicate) (result ListBySubscriptionCompleteResult, err error) { + items := make([]TrafficController, 0) + + resp, err := c.ListBySubscription(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListBySubscriptionCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_update.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_update.go new file mode 100644 index 00000000000..45a38d199f6 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/method_update.go @@ -0,0 +1,57 @@ +package trafficcontrollerinterface + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type UpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *TrafficController +} + +// Update ... +func (c TrafficControllerInterfaceClient) Update(ctx context.Context, id TrafficControllerId, input TrafficControllerUpdate) (result UpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model TrafficController + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_resourceid.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_resourceid.go new file mode 100644 index 00000000000..bb565db648e --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_resourceid.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceId struct { + Id string `json:"id"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_securitypolicyconfigurations.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_securitypolicyconfigurations.go new file mode 100644 index 00000000000..9b719cf2735 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_securitypolicyconfigurations.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyConfigurations struct { + WafSecurityPolicy *WafSecurityPolicy `json:"wafSecurityPolicy,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_securitypolicyconfigurationsupdate.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_securitypolicyconfigurationsupdate.go new file mode 100644 index 00000000000..6bb180ac909 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_securitypolicyconfigurationsupdate.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyConfigurationsUpdate struct { + WafSecurityPolicy *WafSecurityPolicyUpdate `json:"wafSecurityPolicy,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontroller.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontroller.go new file mode 100644 index 00000000000..2c3e90dd16b --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontroller.go @@ -0,0 +1,18 @@ +package trafficcontrollerinterface + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficController struct { + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *TrafficControllerProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerproperties.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerproperties.go new file mode 100644 index 00000000000..253bd3d8c6d --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerproperties.go @@ -0,0 +1,13 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerProperties struct { + Associations *[]ResourceId `json:"associations,omitempty"` + ConfigurationEndpoints *[]string `json:"configurationEndpoints,omitempty"` + Frontends *[]ResourceId `json:"frontends,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + SecurityPolicies *[]ResourceId `json:"securityPolicies,omitempty"` + SecurityPolicyConfigurations *SecurityPolicyConfigurations `json:"securityPolicyConfigurations,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerupdate.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerupdate.go new file mode 100644 index 00000000000..0dd6d27db98 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerupdate.go @@ -0,0 +1,9 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerUpdate struct { + Properties *TrafficControllerUpdateProperties `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerupdateproperties.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerupdateproperties.go new file mode 100644 index 00000000000..990367e73e5 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_trafficcontrollerupdateproperties.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerUpdateProperties struct { + SecurityPolicyConfigurations *SecurityPolicyConfigurationsUpdate `json:"securityPolicyConfigurations,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_wafsecuritypolicy.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_wafsecuritypolicy.go new file mode 100644 index 00000000000..0a62c56c7f2 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_wafsecuritypolicy.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafSecurityPolicy struct { + Id string `json:"id"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_wafsecuritypolicyupdate.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_wafsecuritypolicyupdate.go new file mode 100644 index 00000000000..4424c74523b --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/model_wafsecuritypolicyupdate.go @@ -0,0 +1,8 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WafSecurityPolicyUpdate struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/predicates.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/predicates.go new file mode 100644 index 00000000000..3f8bcc32db3 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/predicates.go @@ -0,0 +1,32 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TrafficControllerOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p TrafficControllerOperationPredicate) Matches(input TrafficController) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/version.go b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/version.go new file mode 100644 index 00000000000..1fe935645c0 --- /dev/null +++ b/resource-manager/servicenetworking/2025-01-01/trafficcontrollerinterface/version.go @@ -0,0 +1,10 @@ +package trafficcontrollerinterface + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2025-01-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/trafficcontrollerinterface/2025-01-01" +}