diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/client.go b/resource-manager/deviceprovisioningservices/2022-02-05/client.go new file mode 100644 index 00000000000..afab8bc317a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/client.go @@ -0,0 +1,44 @@ +package v2022_02_05 + +import ( + "github.com/Azure/go-autorest/autorest" + "github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/delete" + "github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/get" + "github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/patch" + "github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/post" + "github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/put" +) + +type Client struct { + DELETE *delete.DELETEClient + GET *get.GETClient + PATCH *patch.PATCHClient + POST *post.POSTClient + PUT *put.PUTClient +} + +func NewClientWithBaseURI(endpoint string, configureAuthFunc func(c *autorest.Client)) Client { + + dELETEClient := delete.NewDELETEClientWithBaseURI(endpoint) + configureAuthFunc(&dELETEClient.Client) + + gETClient := get.NewGETClientWithBaseURI(endpoint) + configureAuthFunc(&gETClient.Client) + + pATCHClient := patch.NewPATCHClientWithBaseURI(endpoint) + configureAuthFunc(&pATCHClient.Client) + + pOSTClient := post.NewPOSTClientWithBaseURI(endpoint) + configureAuthFunc(&pOSTClient.Client) + + pUTClient := put.NewPUTClientWithBaseURI(endpoint) + configureAuthFunc(&pUTClient.Client) + + return Client{ + DELETE: &dELETEClient, + GET: &gETClient, + PATCH: &pATCHClient, + POST: &pOSTClient, + PUT: &pUTClient, + } +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/README.md b/resource-manager/deviceprovisioningservices/2022-02-05/delete/README.md new file mode 100644 index 00000000000..3739404199a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/README.md @@ -0,0 +1,60 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/delete` Documentation + +The `delete` SDK allows for interaction with the Azure Resource Manager Service `deviceprovisioningservices` (API Version `2022-02-05`). + +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/deviceprovisioningservices/2022-02-05/delete" +``` + + +### Client Initialization + +```go +client := delete.NewDELETEClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `DELETEClient.DpsCertificateDelete` + +```go +ctx := context.TODO() +id := delete.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + +read, err := client.DpsCertificateDelete(ctx, id, delete.DefaultDpsCertificateDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `DELETEClient.IotDpsResourceDelete` + +```go +ctx := context.TODO() +id := delete.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +if err := client.IotDpsResourceDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `DELETEClient.IotDpsResourceDeletePrivateEndpointConnection` + +```go +ctx := context.TODO() +id := delete.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + +if err := client.IotDpsResourceDeletePrivateEndpointConnectionThenPoll(ctx, id); err != nil { + // handle the error +} +``` diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/client.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/client.go new file mode 100644 index 00000000000..7fd6361ebb9 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/client.go @@ -0,0 +1,18 @@ +package delete + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DELETEClient struct { + Client autorest.Client + baseUri string +} + +func NewDELETEClientWithBaseURI(endpoint string) DELETEClient { + return DELETEClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/constants.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/constants.go new file mode 100644 index 00000000000..aa830d1553e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/constants.go @@ -0,0 +1,68 @@ +package delete + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificatePurpose string + +const ( + CertificatePurposeClientAuthentication CertificatePurpose = "clientAuthentication" + CertificatePurposeServerAuthentication CertificatePurpose = "serverAuthentication" +) + +func PossibleValuesForCertificatePurpose() []string { + return []string{ + string(CertificatePurposeClientAuthentication), + string(CertificatePurposeServerAuthentication), + } +} + +func parseCertificatePurpose(input string) (*CertificatePurpose, error) { + vals := map[string]CertificatePurpose{ + "clientauthentication": CertificatePurposeClientAuthentication, + "serverauthentication": CertificatePurposeServerAuthentication, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificatePurpose(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStatusApproved), + string(PrivateLinkServiceConnectionStatusDisconnected), + string(PrivateLinkServiceConnectionStatusPending), + string(PrivateLinkServiceConnectionStatusRejected), + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": PrivateLinkServiceConnectionStatusApproved, + "disconnected": PrivateLinkServiceConnectionStatusDisconnected, + "pending": PrivateLinkServiceConnectionStatusPending, + "rejected": PrivateLinkServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStatus(input) + return &out, nil +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_certificate.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_certificate.go new file mode 100644 index 00000000000..d3a22a9dede --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_certificate.go @@ -0,0 +1,137 @@ +package delete + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, provisioningServiceName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(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 := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateValue"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_certificate_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_certificate_test.go new file mode 100644 index 00000000000..55e32eaf85c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_certificate_test.go @@ -0,0 +1,324 @@ +package delete + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } + + if id.CertificateName != "certificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateValue") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + CertificateName: "cErTiFiCaTeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId 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/deviceprovisioningservices/2022-02-05/delete/id_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_privateendpointconnection.go new file mode 100644 index 00000000000..07094995564 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_privateendpointconnection.go @@ -0,0 +1,137 @@ +package delete + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ResourceName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, resourceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(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 := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_privateendpointconnection_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..a46c5f6be52 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_privateendpointconnection_test.go @@ -0,0 +1,324 @@ +package delete + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + + 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.ResourceName != "resourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceName'", id.ResourceName, "resourceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceName: "rEsOuRcEvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId 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/deviceprovisioningservices/2022-02-05/delete/id_provisioningservice.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_provisioningservice.go new file mode 100644 index 00000000000..e07a0286fba --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_provisioningservice.go @@ -0,0 +1,124 @@ +package delete + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +// ProvisioningServiceId is a struct representing the Resource ID for a Provisioning Service +type ProvisioningServiceId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string +} + +// NewProvisioningServiceID returns a new ProvisioningServiceId struct +func NewProvisioningServiceID(subscriptionId string, resourceGroupName string, provisioningServiceName string) ProvisioningServiceId { + return ProvisioningServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + } +} + +// ParseProvisioningServiceID parses 'input' into a ProvisioningServiceId +func ParseProvisioningServiceID(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProvisioningServiceIDInsensitively parses 'input' case-insensitively into a ProvisioningServiceId +// note: this method should only be used for API response data and not user input +func ParseProvisioningServiceIDInsensitively(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProvisioningServiceID checks that 'input' can be parsed as a Provisioning Service ID +func ValidateProvisioningServiceID(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 := ParseProvisioningServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provisioning Service ID +func (id ProvisioningServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provisioning Service ID +func (id ProvisioningServiceId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + } +} + +// String returns a human-readable description of this Provisioning Service ID +func (id ProvisioningServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + } + return fmt.Sprintf("Provisioning Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_provisioningservice_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_provisioningservice_test.go new file mode 100644 index 00000000000..7e286c3f2fe --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/id_provisioningservice_test.go @@ -0,0 +1,279 @@ +package delete + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +func TestNewProvisioningServiceID(t *testing.T) { + id := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } +} + +func TestFormatProvisioningServiceID(t *testing.T) { + actual := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProvisioningServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestParseProvisioningServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestSegmentsForProvisioningServiceId(t *testing.T) { + segments := ProvisioningServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProvisioningServiceId 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/deviceprovisioningservices/2022-02-05/delete/method_dpscertificatedelete_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_dpscertificatedelete_autorest.go new file mode 100644 index 00000000000..bf66a33a878 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_dpscertificatedelete_autorest.go @@ -0,0 +1,135 @@ +package delete + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpsCertificateDeleteOperationResponse struct { + HttpResponse *http.Response +} + +type DpsCertificateDeleteOperationOptions struct { + CertificateCreated *string + CertificateHasPrivateKey *bool + CertificateIsVerified *bool + CertificateLastUpdated *string + CertificateName *string + CertificateNonce *string + CertificatePurpose *CertificatePurpose + CertificateRawBytes *string + IfMatch *string +} + +func DefaultDpsCertificateDeleteOperationOptions() DpsCertificateDeleteOperationOptions { + return DpsCertificateDeleteOperationOptions{} +} + +func (o DpsCertificateDeleteOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o DpsCertificateDeleteOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.CertificateCreated != nil { + out["certificate.created"] = *o.CertificateCreated + } + + if o.CertificateHasPrivateKey != nil { + out["certificate.hasPrivateKey"] = *o.CertificateHasPrivateKey + } + + if o.CertificateIsVerified != nil { + out["certificate.isVerified"] = *o.CertificateIsVerified + } + + if o.CertificateLastUpdated != nil { + out["certificate.lastUpdated"] = *o.CertificateLastUpdated + } + + if o.CertificateName != nil { + out["certificate.name"] = *o.CertificateName + } + + if o.CertificateNonce != nil { + out["certificate.nonce"] = *o.CertificateNonce + } + + if o.CertificatePurpose != nil { + out["certificate.purpose"] = *o.CertificatePurpose + } + + if o.CertificateRawBytes != nil { + out["certificate.rawBytes"] = *o.CertificateRawBytes + } + + return out +} + +// DpsCertificateDelete ... +func (c DELETEClient) DpsCertificateDelete(ctx context.Context, id CertificateId, options DpsCertificateDeleteOperationOptions) (result DpsCertificateDeleteOperationResponse, err error) { + req, err := c.preparerForDpsCertificateDelete(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "DpsCertificateDelete", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "DpsCertificateDelete", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDpsCertificateDelete(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "DpsCertificateDelete", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDpsCertificateDelete prepares the DpsCertificateDelete request. +func (c DELETEClient) preparerForDpsCertificateDelete(ctx context.Context, id CertificateId, options DpsCertificateDeleteOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDpsCertificateDelete handles the response to the DpsCertificateDelete request. The method always +// closes the http.Response Body. +func (c DELETEClient) responderForDpsCertificateDelete(resp *http.Response) (result DpsCertificateDeleteOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusNoContent, http.StatusOK), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_iotdpsresourcedelete_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_iotdpsresourcedelete_autorest.go new file mode 100644 index 00000000000..97e917e192e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_iotdpsresourcedelete_autorest.go @@ -0,0 +1,78 @@ +package delete + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// IotDpsResourceDelete ... +func (c DELETEClient) IotDpsResourceDelete(ctx context.Context, id ProvisioningServiceId) (result IotDpsResourceDeleteOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "IotDpsResourceDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForIotDpsResourceDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "IotDpsResourceDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// IotDpsResourceDeleteThenPoll performs IotDpsResourceDelete then polls until it's completed +func (c DELETEClient) IotDpsResourceDeleteThenPoll(ctx context.Context, id ProvisioningServiceId) error { + result, err := c.IotDpsResourceDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing IotDpsResourceDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after IotDpsResourceDelete: %+v", err) + } + + return nil +} + +// preparerForIotDpsResourceDelete prepares the IotDpsResourceDelete request. +func (c DELETEClient) preparerForIotDpsResourceDelete(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForIotDpsResourceDelete sends the IotDpsResourceDelete request. The method will close the +// http.Response Body if it receives an error. +func (c DELETEClient) senderForIotDpsResourceDelete(ctx context.Context, req *http.Request) (future IotDpsResourceDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_iotdpsresourcedeleteprivateendpointconnection_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_iotdpsresourcedeleteprivateendpointconnection_autorest.go new file mode 100644 index 00000000000..01beec73463 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/method_iotdpsresourcedeleteprivateendpointconnection_autorest.go @@ -0,0 +1,78 @@ +package delete + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceDeletePrivateEndpointConnectionOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// IotDpsResourceDeletePrivateEndpointConnection ... +func (c DELETEClient) IotDpsResourceDeletePrivateEndpointConnection(ctx context.Context, id PrivateEndpointConnectionId) (result IotDpsResourceDeletePrivateEndpointConnectionOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceDeletePrivateEndpointConnection(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "IotDpsResourceDeletePrivateEndpointConnection", nil, "Failure preparing request") + return + } + + result, err = c.senderForIotDpsResourceDeletePrivateEndpointConnection(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "delete.DELETEClient", "IotDpsResourceDeletePrivateEndpointConnection", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// IotDpsResourceDeletePrivateEndpointConnectionThenPoll performs IotDpsResourceDeletePrivateEndpointConnection then polls until it's completed +func (c DELETEClient) IotDpsResourceDeletePrivateEndpointConnectionThenPoll(ctx context.Context, id PrivateEndpointConnectionId) error { + result, err := c.IotDpsResourceDeletePrivateEndpointConnection(ctx, id) + if err != nil { + return fmt.Errorf("performing IotDpsResourceDeletePrivateEndpointConnection: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after IotDpsResourceDeletePrivateEndpointConnection: %+v", err) + } + + return nil +} + +// preparerForIotDpsResourceDeletePrivateEndpointConnection prepares the IotDpsResourceDeletePrivateEndpointConnection request. +func (c DELETEClient) preparerForIotDpsResourceDeletePrivateEndpointConnection(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForIotDpsResourceDeletePrivateEndpointConnection sends the IotDpsResourceDeletePrivateEndpointConnection request. The method will close the +// http.Response Body if it receives an error. +func (c DELETEClient) senderForIotDpsResourceDeletePrivateEndpointConnection(ctx context.Context, req *http.Request) (future IotDpsResourceDeletePrivateEndpointConnectionOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpoint.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpoint.go new file mode 100644 index 00000000000..6780f760547 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpoint.go @@ -0,0 +1,8 @@ +package delete + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpointconnection.go new file mode 100644 index 00000000000..e4670ef1ba7 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package delete + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties PrivateEndpointConnectionProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpointconnectionproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..e37ca26d814 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privateendpointconnectionproperties.go @@ -0,0 +1,9 @@ +package delete + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privatelinkserviceconnectionstate.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..76413c76966 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package delete + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status PrivateLinkServiceConnectionStatus `json:"status"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/delete/version.go b/resource-manager/deviceprovisioningservices/2022-02-05/delete/version.go new file mode 100644 index 00000000000..7cc2ff5e42d --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/delete/version.go @@ -0,0 +1,12 @@ +package delete + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-05" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/delete/%s", defaultApiVersion) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/README.md b/resource-manager/deviceprovisioningservices/2022-02-05/get/README.md new file mode 100644 index 00000000000..d7e5f45cd2a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/README.md @@ -0,0 +1,183 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/get` Documentation + +The `get` SDK allows for interaction with the Azure Resource Manager Service `deviceprovisioningservices` (API Version `2022-02-05`). + +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/deviceprovisioningservices/2022-02-05/get" +``` + + +### Client Initialization + +```go +client := get.NewGETClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `GETClient.DpsCertificateGet` + +```go +ctx := context.TODO() +id := get.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + +read, err := client.DpsCertificateGet(ctx, id, get.DefaultDpsCertificateGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.DpsCertificateList` + +```go +ctx := context.TODO() +id := get.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +read, err := client.DpsCertificateList(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.IotDpsResourceGet` + +```go +ctx := context.TODO() +id := get.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +read, err := client.IotDpsResourceGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.IotDpsResourceGetPrivateEndpointConnection` + +```go +ctx := context.TODO() +id := get.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + +read, err := client.IotDpsResourceGetPrivateEndpointConnection(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.IotDpsResourceGetPrivateLinkResources` + +```go +ctx := context.TODO() +id := get.NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "groupIdValue") + +read, err := client.IotDpsResourceGetPrivateLinkResources(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.IotDpsResourceListByResourceGroup` + +```go +ctx := context.TODO() +id := get.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.IotDpsResourceListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.IotDpsResourceListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GETClient.IotDpsResourceListBySubscription` + +```go +ctx := context.TODO() +id := get.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.IotDpsResourceListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.IotDpsResourceListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `GETClient.IotDpsResourceListPrivateEndpointConnections` + +```go +ctx := context.TODO() +id := get.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +read, err := client.IotDpsResourceListPrivateEndpointConnections(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.IotDpsResourceListPrivateLinkResources` + +```go +ctx := context.TODO() +id := get.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +read, err := client.IotDpsResourceListPrivateLinkResources(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `GETClient.IotDpsResourcelistValidSkus` + +```go +ctx := context.TODO() +id := get.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +// alternatively `client.IotDpsResourcelistValidSkus(ctx, id)` can be used to do batched pagination +items, err := client.IotDpsResourcelistValidSkusComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/client.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/client.go new file mode 100644 index 00000000000..bc1f54fda25 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/client.go @@ -0,0 +1,18 @@ +package get + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GETClient struct { + Client autorest.Client + baseUri string +} + +func NewGETClientWithBaseURI(endpoint string) GETClient { + return GETClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/constants.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/constants.go new file mode 100644 index 00000000000..052ffcfee23 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/constants.go @@ -0,0 +1,281 @@ +package get + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessRightsDescription string + +const ( + AccessRightsDescriptionDeviceConnect AccessRightsDescription = "DeviceConnect" + AccessRightsDescriptionEnrollmentRead AccessRightsDescription = "EnrollmentRead" + AccessRightsDescriptionEnrollmentWrite AccessRightsDescription = "EnrollmentWrite" + AccessRightsDescriptionRegistrationStatusRead AccessRightsDescription = "RegistrationStatusRead" + AccessRightsDescriptionRegistrationStatusWrite AccessRightsDescription = "RegistrationStatusWrite" + AccessRightsDescriptionServiceConfig AccessRightsDescription = "ServiceConfig" +) + +func PossibleValuesForAccessRightsDescription() []string { + return []string{ + string(AccessRightsDescriptionDeviceConnect), + string(AccessRightsDescriptionEnrollmentRead), + string(AccessRightsDescriptionEnrollmentWrite), + string(AccessRightsDescriptionRegistrationStatusRead), + string(AccessRightsDescriptionRegistrationStatusWrite), + string(AccessRightsDescriptionServiceConfig), + } +} + +func parseAccessRightsDescription(input string) (*AccessRightsDescription, error) { + vals := map[string]AccessRightsDescription{ + "deviceconnect": AccessRightsDescriptionDeviceConnect, + "enrollmentread": AccessRightsDescriptionEnrollmentRead, + "enrollmentwrite": AccessRightsDescriptionEnrollmentWrite, + "registrationstatusread": AccessRightsDescriptionRegistrationStatusRead, + "registrationstatuswrite": AccessRightsDescriptionRegistrationStatusWrite, + "serviceconfig": AccessRightsDescriptionServiceConfig, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessRightsDescription(input) + return &out, nil +} + +type AllocationPolicy string + +const ( + AllocationPolicyGeoLatency AllocationPolicy = "GeoLatency" + AllocationPolicyHashed AllocationPolicy = "Hashed" + AllocationPolicyStatic AllocationPolicy = "Static" +) + +func PossibleValuesForAllocationPolicy() []string { + return []string{ + string(AllocationPolicyGeoLatency), + string(AllocationPolicyHashed), + string(AllocationPolicyStatic), + } +} + +func parseAllocationPolicy(input string) (*AllocationPolicy, error) { + vals := map[string]AllocationPolicy{ + "geolatency": AllocationPolicyGeoLatency, + "hashed": AllocationPolicyHashed, + "static": AllocationPolicyStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AllocationPolicy(input) + return &out, nil +} + +type IPFilterActionType string + +const ( + IPFilterActionTypeAccept IPFilterActionType = "Accept" + IPFilterActionTypeReject IPFilterActionType = "Reject" +) + +func PossibleValuesForIPFilterActionType() []string { + return []string{ + string(IPFilterActionTypeAccept), + string(IPFilterActionTypeReject), + } +} + +func parseIPFilterActionType(input string) (*IPFilterActionType, error) { + vals := map[string]IPFilterActionType{ + "accept": IPFilterActionTypeAccept, + "reject": IPFilterActionTypeReject, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPFilterActionType(input) + return &out, nil +} + +type IPFilterTargetType string + +const ( + IPFilterTargetTypeAll IPFilterTargetType = "all" + IPFilterTargetTypeDeviceApi IPFilterTargetType = "deviceApi" + IPFilterTargetTypeServiceApi IPFilterTargetType = "serviceApi" +) + +func PossibleValuesForIPFilterTargetType() []string { + return []string{ + string(IPFilterTargetTypeAll), + string(IPFilterTargetTypeDeviceApi), + string(IPFilterTargetTypeServiceApi), + } +} + +func parseIPFilterTargetType(input string) (*IPFilterTargetType, error) { + vals := map[string]IPFilterTargetType{ + "all": IPFilterTargetTypeAll, + "deviceapi": IPFilterTargetTypeDeviceApi, + "serviceapi": IPFilterTargetTypeServiceApi, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPFilterTargetType(input) + return &out, nil +} + +type IotDpsSku string + +const ( + IotDpsSkuSOne IotDpsSku = "S1" +) + +func PossibleValuesForIotDpsSku() []string { + return []string{ + string(IotDpsSkuSOne), + } +} + +func parseIotDpsSku(input string) (*IotDpsSku, error) { + vals := map[string]IotDpsSku{ + "s1": IotDpsSkuSOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IotDpsSku(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStatusApproved), + string(PrivateLinkServiceConnectionStatusDisconnected), + string(PrivateLinkServiceConnectionStatusPending), + string(PrivateLinkServiceConnectionStatusRejected), + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": PrivateLinkServiceConnectionStatusApproved, + "disconnected": PrivateLinkServiceConnectionStatusDisconnected, + "pending": PrivateLinkServiceConnectionStatusPending, + "rejected": PrivateLinkServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type State string + +const ( + StateActivating State = "Activating" + StateActivationFailed State = "ActivationFailed" + StateActive State = "Active" + StateDeleted State = "Deleted" + StateDeleting State = "Deleting" + StateDeletionFailed State = "DeletionFailed" + StateFailingOver State = "FailingOver" + StateFailoverFailed State = "FailoverFailed" + StateResuming State = "Resuming" + StateSuspended State = "Suspended" + StateSuspending State = "Suspending" + StateTransitioning State = "Transitioning" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateActivating), + string(StateActivationFailed), + string(StateActive), + string(StateDeleted), + string(StateDeleting), + string(StateDeletionFailed), + string(StateFailingOver), + string(StateFailoverFailed), + string(StateResuming), + string(StateSuspended), + string(StateSuspending), + string(StateTransitioning), + } +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "activating": StateActivating, + "activationfailed": StateActivationFailed, + "active": StateActive, + "deleted": StateDeleted, + "deleting": StateDeleting, + "deletionfailed": StateDeletionFailed, + "failingover": StateFailingOver, + "failoverfailed": StateFailoverFailed, + "resuming": StateResuming, + "suspended": StateSuspended, + "suspending": StateSuspending, + "transitioning": StateTransitioning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/id_certificate.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_certificate.go new file mode 100644 index 00000000000..9ddd00dd34c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_certificate.go @@ -0,0 +1,137 @@ +package get + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, provisioningServiceName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(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 := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateValue"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/id_certificate_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_certificate_test.go new file mode 100644 index 00000000000..9c42e2c27ce --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_certificate_test.go @@ -0,0 +1,324 @@ +package get + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } + + if id.CertificateName != "certificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateValue") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + CertificateName: "cErTiFiCaTeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId 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/deviceprovisioningservices/2022-02-05/get/id_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privateendpointconnection.go new file mode 100644 index 00000000000..d2ceeec9964 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privateendpointconnection.go @@ -0,0 +1,137 @@ +package get + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ResourceName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, resourceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(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 := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privateendpointconnection_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..da054439d1c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privateendpointconnection_test.go @@ -0,0 +1,324 @@ +package get + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + + 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.ResourceName != "resourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceName'", id.ResourceName, "resourceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceName: "rEsOuRcEvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId 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/deviceprovisioningservices/2022-02-05/get/id_privatelinkresource.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privatelinkresource.go new file mode 100644 index 00000000000..e859addb3a0 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privatelinkresource.go @@ -0,0 +1,137 @@ +package get + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateLinkResourceId{} + +// PrivateLinkResourceId is a struct representing the Resource ID for a Private Link Resource +type PrivateLinkResourceId struct { + SubscriptionId string + ResourceGroupName string + ResourceName string + GroupId string +} + +// NewPrivateLinkResourceID returns a new PrivateLinkResourceId struct +func NewPrivateLinkResourceID(subscriptionId string, resourceGroupName string, resourceName string, groupId string) PrivateLinkResourceId { + return PrivateLinkResourceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + GroupId: groupId, + } +} + +// ParsePrivateLinkResourceID parses 'input' into a PrivateLinkResourceId +func ParsePrivateLinkResourceID(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { + return nil, fmt.Errorf("the segment 'groupId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateLinkResourceIDInsensitively parses 'input' case-insensitively into a PrivateLinkResourceId +// note: this method should only be used for API response data and not user input +func ParsePrivateLinkResourceIDInsensitively(input string) (*PrivateLinkResourceId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateLinkResourceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateLinkResourceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.GroupId, ok = parsed.Parsed["groupId"]; !ok { + return nil, fmt.Errorf("the segment 'groupId' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateLinkResourceID checks that 'input' can be parsed as a Private Link Resource ID +func ValidatePrivateLinkResourceID(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 := ParsePrivateLinkResourceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Link Resource ID +func (id PrivateLinkResourceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/privateLinkResources/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName, id.GroupId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Link Resource ID +func (id PrivateLinkResourceId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.StaticSegment("staticPrivateLinkResources", "privateLinkResources", "privateLinkResources"), + resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), + } +} + +// String returns a human-readable description of this Private Link Resource ID +func (id PrivateLinkResourceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Group: %q", id.GroupId), + } + return fmt.Sprintf("Private Link Resource (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privatelinkresource_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privatelinkresource_test.go new file mode 100644 index 00000000000..fc565c6e73a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_privatelinkresource_test.go @@ -0,0 +1,324 @@ +package get + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateLinkResourceId{} + +func TestNewPrivateLinkResourceID(t *testing.T) { + id := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "groupIdValue") + + 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.ResourceName != "resourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceName'", id.ResourceName, "resourceValue") + } + + if id.GroupId != "groupIdValue" { + t.Fatalf("Expected %q but got %q for Segment 'GroupId'", id.GroupId, "groupIdValue") + } +} + +func TestFormatPrivateLinkResourceID(t *testing.T) { + actual := NewPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "groupIdValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources/groupIdValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateLinkResourceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources/groupIdValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources/groupIdValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceID(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestParsePrivateLinkResourceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateLinkResourceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeLiNkReSoUrCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources/groupIdValue", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + GroupId: "groupIdValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateLinkResources/groupIdValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeLiNkReSoUrCeS/gRoUpIdVaLuE", + Expected: &PrivateLinkResourceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceName: "rEsOuRcEvAlUe", + GroupId: "gRoUpIdVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeLiNkReSoUrCeS/gRoUpIdVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateLinkResourceIDInsensitively(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.GroupId != v.Expected.GroupId { + t.Fatalf("Expected %q but got %q for GroupId", v.Expected.GroupId, actual.GroupId) + } + + } +} + +func TestSegmentsForPrivateLinkResourceId(t *testing.T) { + segments := PrivateLinkResourceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateLinkResourceId 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/deviceprovisioningservices/2022-02-05/get/id_provisioningservice.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_provisioningservice.go new file mode 100644 index 00000000000..80881cfb89f --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_provisioningservice.go @@ -0,0 +1,124 @@ +package get + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +// ProvisioningServiceId is a struct representing the Resource ID for a Provisioning Service +type ProvisioningServiceId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string +} + +// NewProvisioningServiceID returns a new ProvisioningServiceId struct +func NewProvisioningServiceID(subscriptionId string, resourceGroupName string, provisioningServiceName string) ProvisioningServiceId { + return ProvisioningServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + } +} + +// ParseProvisioningServiceID parses 'input' into a ProvisioningServiceId +func ParseProvisioningServiceID(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProvisioningServiceIDInsensitively parses 'input' case-insensitively into a ProvisioningServiceId +// note: this method should only be used for API response data and not user input +func ParseProvisioningServiceIDInsensitively(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProvisioningServiceID checks that 'input' can be parsed as a Provisioning Service ID +func ValidateProvisioningServiceID(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 := ParseProvisioningServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provisioning Service ID +func (id ProvisioningServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provisioning Service ID +func (id ProvisioningServiceId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + } +} + +// String returns a human-readable description of this Provisioning Service ID +func (id ProvisioningServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + } + return fmt.Sprintf("Provisioning Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/id_provisioningservice_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_provisioningservice_test.go new file mode 100644 index 00000000000..a5eff7e33a1 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/id_provisioningservice_test.go @@ -0,0 +1,279 @@ +package get + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +func TestNewProvisioningServiceID(t *testing.T) { + id := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } +} + +func TestFormatProvisioningServiceID(t *testing.T) { + actual := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProvisioningServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestParseProvisioningServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestSegmentsForProvisioningServiceId(t *testing.T) { + segments := ProvisioningServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProvisioningServiceId 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/deviceprovisioningservices/2022-02-05/get/method_dpscertificateget_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_dpscertificateget_autorest.go new file mode 100644 index 00000000000..bf55f2d745b --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_dpscertificateget_autorest.go @@ -0,0 +1,97 @@ +package get + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpsCertificateGetOperationResponse struct { + HttpResponse *http.Response + Model *CertificateResponse +} + +type DpsCertificateGetOperationOptions struct { + IfMatch *string +} + +func DefaultDpsCertificateGetOperationOptions() DpsCertificateGetOperationOptions { + return DpsCertificateGetOperationOptions{} +} + +func (o DpsCertificateGetOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o DpsCertificateGetOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +// DpsCertificateGet ... +func (c GETClient) DpsCertificateGet(ctx context.Context, id CertificateId, options DpsCertificateGetOperationOptions) (result DpsCertificateGetOperationResponse, err error) { + req, err := c.preparerForDpsCertificateGet(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "DpsCertificateGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "DpsCertificateGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDpsCertificateGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "DpsCertificateGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDpsCertificateGet prepares the DpsCertificateGet request. +func (c GETClient) preparerForDpsCertificateGet(ctx context.Context, id CertificateId, options DpsCertificateGetOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDpsCertificateGet handles the response to the DpsCertificateGet request. The method always +// closes the http.Response Body. +func (c GETClient) responderForDpsCertificateGet(resp *http.Response) (result DpsCertificateGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_dpscertificatelist_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_dpscertificatelist_autorest.go new file mode 100644 index 00000000000..6f96a29b91a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_dpscertificatelist_autorest.go @@ -0,0 +1,69 @@ +package get + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpsCertificateListOperationResponse struct { + HttpResponse *http.Response + Model *CertificateListDescription +} + +// DpsCertificateList ... +func (c GETClient) DpsCertificateList(ctx context.Context, id ProvisioningServiceId) (result DpsCertificateListOperationResponse, err error) { + req, err := c.preparerForDpsCertificateList(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "DpsCertificateList", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "DpsCertificateList", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDpsCertificateList(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "DpsCertificateList", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDpsCertificateList prepares the DpsCertificateList request. +func (c GETClient) preparerForDpsCertificateList(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/certificates", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDpsCertificateList handles the response to the DpsCertificateList request. The method always +// closes the http.Response Body. +func (c GETClient) responderForDpsCertificateList(resp *http.Response) (result DpsCertificateListOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourceget_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourceget_autorest.go new file mode 100644 index 00000000000..b0f3d1615c2 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourceget_autorest.go @@ -0,0 +1,68 @@ +package get + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceGetOperationResponse struct { + HttpResponse *http.Response + Model *ProvisioningServiceDescription +} + +// IotDpsResourceGet ... +func (c GETClient) IotDpsResourceGet(ctx context.Context, id ProvisioningServiceId) (result IotDpsResourceGetOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceGet prepares the IotDpsResourceGet request. +func (c GETClient) preparerForIotDpsResourceGet(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceGet handles the response to the IotDpsResourceGet request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceGet(resp *http.Response) (result IotDpsResourceGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcegetprivateendpointconnection_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcegetprivateendpointconnection_autorest.go new file mode 100644 index 00000000000..1f267b85ff2 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcegetprivateendpointconnection_autorest.go @@ -0,0 +1,68 @@ +package get + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceGetPrivateEndpointConnectionOperationResponse struct { + HttpResponse *http.Response + Model *PrivateEndpointConnection +} + +// IotDpsResourceGetPrivateEndpointConnection ... +func (c GETClient) IotDpsResourceGetPrivateEndpointConnection(ctx context.Context, id PrivateEndpointConnectionId) (result IotDpsResourceGetPrivateEndpointConnectionOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceGetPrivateEndpointConnection(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGetPrivateEndpointConnection", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGetPrivateEndpointConnection", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceGetPrivateEndpointConnection(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGetPrivateEndpointConnection", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceGetPrivateEndpointConnection prepares the IotDpsResourceGetPrivateEndpointConnection request. +func (c GETClient) preparerForIotDpsResourceGetPrivateEndpointConnection(ctx context.Context, id PrivateEndpointConnectionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceGetPrivateEndpointConnection handles the response to the IotDpsResourceGetPrivateEndpointConnection request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceGetPrivateEndpointConnection(resp *http.Response) (result IotDpsResourceGetPrivateEndpointConnectionOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcegetprivatelinkresources_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcegetprivatelinkresources_autorest.go new file mode 100644 index 00000000000..29ac2d4974e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcegetprivatelinkresources_autorest.go @@ -0,0 +1,68 @@ +package get + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceGetPrivateLinkResourcesOperationResponse struct { + HttpResponse *http.Response + Model *GroupIdInformation +} + +// IotDpsResourceGetPrivateLinkResources ... +func (c GETClient) IotDpsResourceGetPrivateLinkResources(ctx context.Context, id PrivateLinkResourceId) (result IotDpsResourceGetPrivateLinkResourcesOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceGetPrivateLinkResources(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGetPrivateLinkResources", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGetPrivateLinkResources", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceGetPrivateLinkResources(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceGetPrivateLinkResources", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceGetPrivateLinkResources prepares the IotDpsResourceGetPrivateLinkResources request. +func (c GETClient) preparerForIotDpsResourceGetPrivateLinkResources(ctx context.Context, id PrivateLinkResourceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceGetPrivateLinkResources handles the response to the IotDpsResourceGetPrivateLinkResources request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceGetPrivateLinkResources(resp *http.Response) (result IotDpsResourceGetPrivateLinkResourcesOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistbyresourcegroup_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistbyresourcegroup_autorest.go new file mode 100644 index 00000000000..2a5764fabee --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package get + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]ProvisioningServiceDescription + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (IotDpsResourceListByResourceGroupOperationResponse, error) +} + +type IotDpsResourceListByResourceGroupCompleteResult struct { + Items []ProvisioningServiceDescription +} + +func (r IotDpsResourceListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r IotDpsResourceListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp IotDpsResourceListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// IotDpsResourceListByResourceGroup ... +func (c GETClient) IotDpsResourceListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp IotDpsResourceListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForIotDpsResourceListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// IotDpsResourceListByResourceGroupComplete retrieves all of the results into a single object +func (c GETClient) IotDpsResourceListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (IotDpsResourceListByResourceGroupCompleteResult, error) { + return c.IotDpsResourceListByResourceGroupCompleteMatchingPredicate(ctx, id, ProvisioningServiceDescriptionOperationPredicate{}) +} + +// IotDpsResourceListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c GETClient) IotDpsResourceListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ProvisioningServiceDescriptionOperationPredicate) (resp IotDpsResourceListByResourceGroupCompleteResult, err error) { + items := make([]ProvisioningServiceDescription, 0) + + page, err := c.IotDpsResourceListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := IotDpsResourceListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForIotDpsResourceListByResourceGroup prepares the IotDpsResourceListByResourceGroup request. +func (c GETClient) preparerForIotDpsResourceListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Devices/provisioningServices", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForIotDpsResourceListByResourceGroupWithNextLink prepares the IotDpsResourceListByResourceGroup request with the given nextLink token. +func (c GETClient) preparerForIotDpsResourceListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceListByResourceGroup handles the response to the IotDpsResourceListByResourceGroup request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceListByResourceGroup(resp *http.Response) (result IotDpsResourceListByResourceGroupOperationResponse, err error) { + type page struct { + Values []ProvisioningServiceDescription `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result IotDpsResourceListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistbysubscription_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistbysubscription_autorest.go new file mode 100644 index 00000000000..5698432ce2f --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistbysubscription_autorest.go @@ -0,0 +1,187 @@ +package get + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ProvisioningServiceDescription + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (IotDpsResourceListBySubscriptionOperationResponse, error) +} + +type IotDpsResourceListBySubscriptionCompleteResult struct { + Items []ProvisioningServiceDescription +} + +func (r IotDpsResourceListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r IotDpsResourceListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp IotDpsResourceListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// IotDpsResourceListBySubscription ... +func (c GETClient) IotDpsResourceListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp IotDpsResourceListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForIotDpsResourceListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// IotDpsResourceListBySubscriptionComplete retrieves all of the results into a single object +func (c GETClient) IotDpsResourceListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (IotDpsResourceListBySubscriptionCompleteResult, error) { + return c.IotDpsResourceListBySubscriptionCompleteMatchingPredicate(ctx, id, ProvisioningServiceDescriptionOperationPredicate{}) +} + +// IotDpsResourceListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c GETClient) IotDpsResourceListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ProvisioningServiceDescriptionOperationPredicate) (resp IotDpsResourceListBySubscriptionCompleteResult, err error) { + items := make([]ProvisioningServiceDescription, 0) + + page, err := c.IotDpsResourceListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := IotDpsResourceListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForIotDpsResourceListBySubscription prepares the IotDpsResourceListBySubscription request. +func (c GETClient) preparerForIotDpsResourceListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Devices/provisioningServices", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForIotDpsResourceListBySubscriptionWithNextLink prepares the IotDpsResourceListBySubscription request with the given nextLink token. +func (c GETClient) preparerForIotDpsResourceListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceListBySubscription handles the response to the IotDpsResourceListBySubscription request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceListBySubscription(resp *http.Response) (result IotDpsResourceListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ProvisioningServiceDescription `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result IotDpsResourceListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistprivateendpointconnections_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistprivateendpointconnections_autorest.go new file mode 100644 index 00000000000..ce017de2c9c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistprivateendpointconnections_autorest.go @@ -0,0 +1,69 @@ +package get + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceListPrivateEndpointConnectionsOperationResponse struct { + HttpResponse *http.Response + Model *[]PrivateEndpointConnection +} + +// IotDpsResourceListPrivateEndpointConnections ... +func (c GETClient) IotDpsResourceListPrivateEndpointConnections(ctx context.Context, id ProvisioningServiceId) (result IotDpsResourceListPrivateEndpointConnectionsOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListPrivateEndpointConnections(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListPrivateEndpointConnections", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListPrivateEndpointConnections", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceListPrivateEndpointConnections(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListPrivateEndpointConnections", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceListPrivateEndpointConnections prepares the IotDpsResourceListPrivateEndpointConnections request. +func (c GETClient) preparerForIotDpsResourceListPrivateEndpointConnections(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateEndpointConnections", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceListPrivateEndpointConnections handles the response to the IotDpsResourceListPrivateEndpointConnections request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceListPrivateEndpointConnections(resp *http.Response) (result IotDpsResourceListPrivateEndpointConnectionsOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistprivatelinkresources_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistprivatelinkresources_autorest.go new file mode 100644 index 00000000000..4fc48894a5c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistprivatelinkresources_autorest.go @@ -0,0 +1,69 @@ +package get + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceListPrivateLinkResourcesOperationResponse struct { + HttpResponse *http.Response + Model *PrivateLinkResources +} + +// IotDpsResourceListPrivateLinkResources ... +func (c GETClient) IotDpsResourceListPrivateLinkResources(ctx context.Context, id ProvisioningServiceId) (result IotDpsResourceListPrivateLinkResourcesOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListPrivateLinkResources(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListPrivateLinkResources", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListPrivateLinkResources", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceListPrivateLinkResources(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourceListPrivateLinkResources", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceListPrivateLinkResources prepares the IotDpsResourceListPrivateLinkResources request. +func (c GETClient) preparerForIotDpsResourceListPrivateLinkResources(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/privateLinkResources", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceListPrivateLinkResources handles the response to the IotDpsResourceListPrivateLinkResources request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourceListPrivateLinkResources(resp *http.Response) (result IotDpsResourceListPrivateLinkResourcesOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistvalidskus_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistvalidskus_autorest.go new file mode 100644 index 00000000000..50484e1bd1d --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/method_iotdpsresourcelistvalidskus_autorest.go @@ -0,0 +1,186 @@ +package get + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourcelistValidSkusOperationResponse struct { + HttpResponse *http.Response + Model *[]IotDpsSkuDefinition + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (IotDpsResourcelistValidSkusOperationResponse, error) +} + +type IotDpsResourcelistValidSkusCompleteResult struct { + Items []IotDpsSkuDefinition +} + +func (r IotDpsResourcelistValidSkusOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r IotDpsResourcelistValidSkusOperationResponse) LoadMore(ctx context.Context) (resp IotDpsResourcelistValidSkusOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// IotDpsResourcelistValidSkus ... +func (c GETClient) IotDpsResourcelistValidSkus(ctx context.Context, id ProvisioningServiceId) (resp IotDpsResourcelistValidSkusOperationResponse, err error) { + req, err := c.preparerForIotDpsResourcelistValidSkus(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourcelistValidSkus", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourcelistValidSkus", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForIotDpsResourcelistValidSkus(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourcelistValidSkus", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// IotDpsResourcelistValidSkusComplete retrieves all of the results into a single object +func (c GETClient) IotDpsResourcelistValidSkusComplete(ctx context.Context, id ProvisioningServiceId) (IotDpsResourcelistValidSkusCompleteResult, error) { + return c.IotDpsResourcelistValidSkusCompleteMatchingPredicate(ctx, id, IotDpsSkuDefinitionOperationPredicate{}) +} + +// IotDpsResourcelistValidSkusCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c GETClient) IotDpsResourcelistValidSkusCompleteMatchingPredicate(ctx context.Context, id ProvisioningServiceId, predicate IotDpsSkuDefinitionOperationPredicate) (resp IotDpsResourcelistValidSkusCompleteResult, err error) { + items := make([]IotDpsSkuDefinition, 0) + + page, err := c.IotDpsResourcelistValidSkus(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := IotDpsResourcelistValidSkusCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForIotDpsResourcelistValidSkus prepares the IotDpsResourcelistValidSkus request. +func (c GETClient) preparerForIotDpsResourcelistValidSkus(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/skus", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForIotDpsResourcelistValidSkusWithNextLink prepares the IotDpsResourcelistValidSkus request with the given nextLink token. +func (c GETClient) preparerForIotDpsResourcelistValidSkusWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourcelistValidSkus handles the response to the IotDpsResourcelistValidSkus request. The method always +// closes the http.Response Body. +func (c GETClient) responderForIotDpsResourcelistValidSkus(resp *http.Response) (result IotDpsResourcelistValidSkusOperationResponse, err error) { + type page struct { + Values []IotDpsSkuDefinition `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result IotDpsResourcelistValidSkusOperationResponse, err error) { + req, err := c.preparerForIotDpsResourcelistValidSkusWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourcelistValidSkus", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourcelistValidSkus", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourcelistValidSkus(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "get.GETClient", "IotDpsResourcelistValidSkus", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificatelistdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificatelistdescription.go new file mode 100644 index 00000000000..83bfeabc33c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificatelistdescription.go @@ -0,0 +1,8 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateListDescription struct { + Value *[]CertificateResponse `json:"value,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificateproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificateproperties.go new file mode 100644 index 00000000000..5ea2f62b6d7 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificateproperties.go @@ -0,0 +1,14 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateProperties struct { + Certificate *string `json:"certificate,omitempty"` + Created *string `json:"created,omitempty"` + Expiry *string `json:"expiry,omitempty"` + IsVerified *bool `json:"isVerified,omitempty"` + Subject *string `json:"subject,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Updated *string `json:"updated,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificateresponse.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificateresponse.go new file mode 100644 index 00000000000..a37841fc88b --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_certificateresponse.go @@ -0,0 +1,17 @@ +package get + +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 CertificateResponse struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CertificateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_groupidinformation.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_groupidinformation.go new file mode 100644 index 00000000000..f6f60f200a1 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_groupidinformation.go @@ -0,0 +1,11 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupIdInformation struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties GroupIdInformationProperties `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_groupidinformationproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_groupidinformationproperties.go new file mode 100644 index 00000000000..251c6b19903 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_groupidinformationproperties.go @@ -0,0 +1,10 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GroupIdInformationProperties struct { + GroupId *string `json:"groupId,omitempty"` + RequiredMembers *[]string `json:"requiredMembers,omitempty"` + RequiredZoneNames *[]string `json:"requiredZoneNames,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpspropertiesdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpspropertiesdescription.go new file mode 100644 index 00000000000..3fdb127e186 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpspropertiesdescription.go @@ -0,0 +1,19 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsPropertiesDescription struct { + AllocationPolicy *AllocationPolicy `json:"allocationPolicy,omitempty"` + AuthorizationPolicies *[]SharedAccessSignatureAuthorizationRuleAccessRightsDescription `json:"authorizationPolicies,omitempty"` + DeviceProvisioningHostName *string `json:"deviceProvisioningHostName,omitempty"` + EnableDataResidency *bool `json:"enableDataResidency,omitempty"` + IPFilterRules *[]IPFilterRule `json:"ipFilterRules,omitempty"` + IdScope *string `json:"idScope,omitempty"` + IotHubs *[]IotHubDefinitionDescription `json:"iotHubs,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + ServiceOperationsHostName *string `json:"serviceOperationsHostName,omitempty"` + State *State `json:"state,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpsskudefinition.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpsskudefinition.go new file mode 100644 index 00000000000..f0989a88521 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpsskudefinition.go @@ -0,0 +1,8 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsSkuDefinition struct { + Name *IotDpsSku `json:"name,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpsskuinfo.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpsskuinfo.go new file mode 100644 index 00000000000..724e847a1a5 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iotdpsskuinfo.go @@ -0,0 +1,10 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsSkuInfo struct { + Capacity *int64 `json:"capacity,omitempty"` + Name *IotDpsSku `json:"name,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iothubdefinitiondescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iothubdefinitiondescription.go new file mode 100644 index 00000000000..b21230ee6b4 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_iothubdefinitiondescription.go @@ -0,0 +1,12 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotHubDefinitionDescription struct { + AllocationWeight *int64 `json:"allocationWeight,omitempty"` + ApplyAllocationPolicy *bool `json:"applyAllocationPolicy,omitempty"` + ConnectionString string `json:"connectionString"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_ipfilterrule.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_ipfilterrule.go new file mode 100644 index 00000000000..85454616edf --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_ipfilterrule.go @@ -0,0 +1,11 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFilterRule struct { + Action IPFilterActionType `json:"action"` + FilterName string `json:"filterName"` + IPMask string `json:"ipMask"` + Target *IPFilterTargetType `json:"target,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpoint.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpoint.go new file mode 100644 index 00000000000..34362679edb --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpoint.go @@ -0,0 +1,8 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpointconnection.go new file mode 100644 index 00000000000..62900bfc22e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package get + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties PrivateEndpointConnectionProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpointconnectionproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..952d3844bb8 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privateendpointconnectionproperties.go @@ -0,0 +1,9 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privatelinkresources.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privatelinkresources.go new file mode 100644 index 00000000000..670b29d183d --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privatelinkresources.go @@ -0,0 +1,8 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkResources struct { + Value *[]GroupIdInformation `json:"value,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privatelinkserviceconnectionstate.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..54f470f9c79 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status PrivateLinkServiceConnectionStatus `json:"status"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_provisioningservicedescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_provisioningservicedescription.go new file mode 100644 index 00000000000..9596ce5a060 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_provisioningservicedescription.go @@ -0,0 +1,20 @@ +package get + +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 ProvisioningServiceDescription struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties IotDpsPropertiesDescription `json:"properties"` + Sku IotDpsSkuInfo `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go new file mode 100644 index 00000000000..542c53179d2 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go @@ -0,0 +1,11 @@ +package get + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedAccessSignatureAuthorizationRuleAccessRightsDescription struct { + KeyName string `json:"keyName"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Rights AccessRightsDescription `json:"rights"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/get/predicates.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/predicates.go new file mode 100644 index 00000000000..d4d6fba3966 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/predicates.go @@ -0,0 +1,42 @@ +package get + +type IotDpsSkuDefinitionOperationPredicate struct { +} + +func (p IotDpsSkuDefinitionOperationPredicate) Matches(input IotDpsSkuDefinition) bool { + + return true +} + +type ProvisioningServiceDescriptionOperationPredicate struct { + Etag *string + Id *string + Location *string + Name *string + Type *string +} + +func (p ProvisioningServiceDescriptionOperationPredicate) Matches(input ProvisioningServiceDescription) bool { + + if p.Etag != nil && (input.Etag == nil && *p.Etag != *input.Etag) { + return false + } + + 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/deviceprovisioningservices/2022-02-05/get/version.go b/resource-manager/deviceprovisioningservices/2022-02-05/get/version.go new file mode 100644 index 00000000000..10d6fa9c1cf --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/get/version.go @@ -0,0 +1,12 @@ +package get + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-05" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/get/%s", defaultApiVersion) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/README.md b/resource-manager/deviceprovisioningservices/2022-02-05/patch/README.md new file mode 100644 index 00000000000..37c472ca47c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/README.md @@ -0,0 +1,37 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/patch` Documentation + +The `patch` SDK allows for interaction with the Azure Resource Manager Service `deviceprovisioningservices` (API Version `2022-02-05`). + +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/deviceprovisioningservices/2022-02-05/patch" +``` + + +### Client Initialization + +```go +client := patch.NewPATCHClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PATCHClient.IotDpsResourceUpdate` + +```go +ctx := context.TODO() +id := patch.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +payload := patch.TagsResource{ + // ... +} + + +if err := client.IotDpsResourceUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/client.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/client.go new file mode 100644 index 00000000000..82d86dc6c70 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/client.go @@ -0,0 +1,18 @@ +package patch + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PATCHClient struct { + Client autorest.Client + baseUri string +} + +func NewPATCHClientWithBaseURI(endpoint string) PATCHClient { + return PATCHClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/constants.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/constants.go new file mode 100644 index 00000000000..741d950d285 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/constants.go @@ -0,0 +1,281 @@ +package patch + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessRightsDescription string + +const ( + AccessRightsDescriptionDeviceConnect AccessRightsDescription = "DeviceConnect" + AccessRightsDescriptionEnrollmentRead AccessRightsDescription = "EnrollmentRead" + AccessRightsDescriptionEnrollmentWrite AccessRightsDescription = "EnrollmentWrite" + AccessRightsDescriptionRegistrationStatusRead AccessRightsDescription = "RegistrationStatusRead" + AccessRightsDescriptionRegistrationStatusWrite AccessRightsDescription = "RegistrationStatusWrite" + AccessRightsDescriptionServiceConfig AccessRightsDescription = "ServiceConfig" +) + +func PossibleValuesForAccessRightsDescription() []string { + return []string{ + string(AccessRightsDescriptionDeviceConnect), + string(AccessRightsDescriptionEnrollmentRead), + string(AccessRightsDescriptionEnrollmentWrite), + string(AccessRightsDescriptionRegistrationStatusRead), + string(AccessRightsDescriptionRegistrationStatusWrite), + string(AccessRightsDescriptionServiceConfig), + } +} + +func parseAccessRightsDescription(input string) (*AccessRightsDescription, error) { + vals := map[string]AccessRightsDescription{ + "deviceconnect": AccessRightsDescriptionDeviceConnect, + "enrollmentread": AccessRightsDescriptionEnrollmentRead, + "enrollmentwrite": AccessRightsDescriptionEnrollmentWrite, + "registrationstatusread": AccessRightsDescriptionRegistrationStatusRead, + "registrationstatuswrite": AccessRightsDescriptionRegistrationStatusWrite, + "serviceconfig": AccessRightsDescriptionServiceConfig, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessRightsDescription(input) + return &out, nil +} + +type AllocationPolicy string + +const ( + AllocationPolicyGeoLatency AllocationPolicy = "GeoLatency" + AllocationPolicyHashed AllocationPolicy = "Hashed" + AllocationPolicyStatic AllocationPolicy = "Static" +) + +func PossibleValuesForAllocationPolicy() []string { + return []string{ + string(AllocationPolicyGeoLatency), + string(AllocationPolicyHashed), + string(AllocationPolicyStatic), + } +} + +func parseAllocationPolicy(input string) (*AllocationPolicy, error) { + vals := map[string]AllocationPolicy{ + "geolatency": AllocationPolicyGeoLatency, + "hashed": AllocationPolicyHashed, + "static": AllocationPolicyStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AllocationPolicy(input) + return &out, nil +} + +type IPFilterActionType string + +const ( + IPFilterActionTypeAccept IPFilterActionType = "Accept" + IPFilterActionTypeReject IPFilterActionType = "Reject" +) + +func PossibleValuesForIPFilterActionType() []string { + return []string{ + string(IPFilterActionTypeAccept), + string(IPFilterActionTypeReject), + } +} + +func parseIPFilterActionType(input string) (*IPFilterActionType, error) { + vals := map[string]IPFilterActionType{ + "accept": IPFilterActionTypeAccept, + "reject": IPFilterActionTypeReject, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPFilterActionType(input) + return &out, nil +} + +type IPFilterTargetType string + +const ( + IPFilterTargetTypeAll IPFilterTargetType = "all" + IPFilterTargetTypeDeviceApi IPFilterTargetType = "deviceApi" + IPFilterTargetTypeServiceApi IPFilterTargetType = "serviceApi" +) + +func PossibleValuesForIPFilterTargetType() []string { + return []string{ + string(IPFilterTargetTypeAll), + string(IPFilterTargetTypeDeviceApi), + string(IPFilterTargetTypeServiceApi), + } +} + +func parseIPFilterTargetType(input string) (*IPFilterTargetType, error) { + vals := map[string]IPFilterTargetType{ + "all": IPFilterTargetTypeAll, + "deviceapi": IPFilterTargetTypeDeviceApi, + "serviceapi": IPFilterTargetTypeServiceApi, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPFilterTargetType(input) + return &out, nil +} + +type IotDpsSku string + +const ( + IotDpsSkuSOne IotDpsSku = "S1" +) + +func PossibleValuesForIotDpsSku() []string { + return []string{ + string(IotDpsSkuSOne), + } +} + +func parseIotDpsSku(input string) (*IotDpsSku, error) { + vals := map[string]IotDpsSku{ + "s1": IotDpsSkuSOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IotDpsSku(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStatusApproved), + string(PrivateLinkServiceConnectionStatusDisconnected), + string(PrivateLinkServiceConnectionStatusPending), + string(PrivateLinkServiceConnectionStatusRejected), + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": PrivateLinkServiceConnectionStatusApproved, + "disconnected": PrivateLinkServiceConnectionStatusDisconnected, + "pending": PrivateLinkServiceConnectionStatusPending, + "rejected": PrivateLinkServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type State string + +const ( + StateActivating State = "Activating" + StateActivationFailed State = "ActivationFailed" + StateActive State = "Active" + StateDeleted State = "Deleted" + StateDeleting State = "Deleting" + StateDeletionFailed State = "DeletionFailed" + StateFailingOver State = "FailingOver" + StateFailoverFailed State = "FailoverFailed" + StateResuming State = "Resuming" + StateSuspended State = "Suspended" + StateSuspending State = "Suspending" + StateTransitioning State = "Transitioning" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateActivating), + string(StateActivationFailed), + string(StateActive), + string(StateDeleted), + string(StateDeleting), + string(StateDeletionFailed), + string(StateFailingOver), + string(StateFailoverFailed), + string(StateResuming), + string(StateSuspended), + string(StateSuspending), + string(StateTransitioning), + } +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "activating": StateActivating, + "activationfailed": StateActivationFailed, + "active": StateActive, + "deleted": StateDeleted, + "deleting": StateDeleting, + "deletionfailed": StateDeletionFailed, + "failingover": StateFailingOver, + "failoverfailed": StateFailoverFailed, + "resuming": StateResuming, + "suspended": StateSuspended, + "suspending": StateSuspending, + "transitioning": StateTransitioning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/id_provisioningservice.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/id_provisioningservice.go new file mode 100644 index 00000000000..d704e9e280c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/id_provisioningservice.go @@ -0,0 +1,124 @@ +package patch + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +// ProvisioningServiceId is a struct representing the Resource ID for a Provisioning Service +type ProvisioningServiceId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string +} + +// NewProvisioningServiceID returns a new ProvisioningServiceId struct +func NewProvisioningServiceID(subscriptionId string, resourceGroupName string, provisioningServiceName string) ProvisioningServiceId { + return ProvisioningServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + } +} + +// ParseProvisioningServiceID parses 'input' into a ProvisioningServiceId +func ParseProvisioningServiceID(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProvisioningServiceIDInsensitively parses 'input' case-insensitively into a ProvisioningServiceId +// note: this method should only be used for API response data and not user input +func ParseProvisioningServiceIDInsensitively(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProvisioningServiceID checks that 'input' can be parsed as a Provisioning Service ID +func ValidateProvisioningServiceID(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 := ParseProvisioningServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provisioning Service ID +func (id ProvisioningServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provisioning Service ID +func (id ProvisioningServiceId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + } +} + +// String returns a human-readable description of this Provisioning Service ID +func (id ProvisioningServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + } + return fmt.Sprintf("Provisioning Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/id_provisioningservice_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/id_provisioningservice_test.go new file mode 100644 index 00000000000..6fb94b80e25 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/id_provisioningservice_test.go @@ -0,0 +1,279 @@ +package patch + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +func TestNewProvisioningServiceID(t *testing.T) { + id := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } +} + +func TestFormatProvisioningServiceID(t *testing.T) { + actual := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProvisioningServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestParseProvisioningServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestSegmentsForProvisioningServiceId(t *testing.T) { + segments := ProvisioningServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProvisioningServiceId 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/deviceprovisioningservices/2022-02-05/patch/method_iotdpsresourceupdate_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/method_iotdpsresourceupdate_autorest.go new file mode 100644 index 00000000000..6eaf14f5ad3 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/method_iotdpsresourceupdate_autorest.go @@ -0,0 +1,79 @@ +package patch + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// IotDpsResourceUpdate ... +func (c PATCHClient) IotDpsResourceUpdate(ctx context.Context, id ProvisioningServiceId, input TagsResource) (result IotDpsResourceUpdateOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "patch.PATCHClient", "IotDpsResourceUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForIotDpsResourceUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "patch.PATCHClient", "IotDpsResourceUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// IotDpsResourceUpdateThenPoll performs IotDpsResourceUpdate then polls until it's completed +func (c PATCHClient) IotDpsResourceUpdateThenPoll(ctx context.Context, id ProvisioningServiceId, input TagsResource) error { + result, err := c.IotDpsResourceUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing IotDpsResourceUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after IotDpsResourceUpdate: %+v", err) + } + + return nil +} + +// preparerForIotDpsResourceUpdate prepares the IotDpsResourceUpdate request. +func (c PATCHClient) preparerForIotDpsResourceUpdate(ctx context.Context, id ProvisioningServiceId, input TagsResource) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForIotDpsResourceUpdate sends the IotDpsResourceUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c PATCHClient) senderForIotDpsResourceUpdate(ctx context.Context, req *http.Request) (future IotDpsResourceUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iotdpspropertiesdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iotdpspropertiesdescription.go new file mode 100644 index 00000000000..ff4d2ace72a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iotdpspropertiesdescription.go @@ -0,0 +1,19 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsPropertiesDescription struct { + AllocationPolicy *AllocationPolicy `json:"allocationPolicy,omitempty"` + AuthorizationPolicies *[]SharedAccessSignatureAuthorizationRuleAccessRightsDescription `json:"authorizationPolicies,omitempty"` + DeviceProvisioningHostName *string `json:"deviceProvisioningHostName,omitempty"` + EnableDataResidency *bool `json:"enableDataResidency,omitempty"` + IPFilterRules *[]IPFilterRule `json:"ipFilterRules,omitempty"` + IdScope *string `json:"idScope,omitempty"` + IotHubs *[]IotHubDefinitionDescription `json:"iotHubs,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + ServiceOperationsHostName *string `json:"serviceOperationsHostName,omitempty"` + State *State `json:"state,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iotdpsskuinfo.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iotdpsskuinfo.go new file mode 100644 index 00000000000..4174592513a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iotdpsskuinfo.go @@ -0,0 +1,10 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsSkuInfo struct { + Capacity *int64 `json:"capacity,omitempty"` + Name *IotDpsSku `json:"name,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iothubdefinitiondescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iothubdefinitiondescription.go new file mode 100644 index 00000000000..6105eb7946f --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_iothubdefinitiondescription.go @@ -0,0 +1,12 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotHubDefinitionDescription struct { + AllocationWeight *int64 `json:"allocationWeight,omitempty"` + ApplyAllocationPolicy *bool `json:"applyAllocationPolicy,omitempty"` + ConnectionString string `json:"connectionString"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_ipfilterrule.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_ipfilterrule.go new file mode 100644 index 00000000000..577f79d5e90 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_ipfilterrule.go @@ -0,0 +1,11 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFilterRule struct { + Action IPFilterActionType `json:"action"` + FilterName string `json:"filterName"` + IPMask string `json:"ipMask"` + Target *IPFilterTargetType `json:"target,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpoint.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpoint.go new file mode 100644 index 00000000000..c23cd8c768e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpoint.go @@ -0,0 +1,8 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpointconnection.go new file mode 100644 index 00000000000..25b4c5bc68d --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package patch + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties PrivateEndpointConnectionProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpointconnectionproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..e5050be7dd3 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privateendpointconnectionproperties.go @@ -0,0 +1,9 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privatelinkserviceconnectionstate.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..dc9e492369f --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status PrivateLinkServiceConnectionStatus `json:"status"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_provisioningservicedescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_provisioningservicedescription.go new file mode 100644 index 00000000000..1c6d1c874da --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_provisioningservicedescription.go @@ -0,0 +1,20 @@ +package patch + +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 ProvisioningServiceDescription struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties IotDpsPropertiesDescription `json:"properties"` + Sku IotDpsSkuInfo `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go new file mode 100644 index 00000000000..1e201dbe61a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go @@ -0,0 +1,11 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedAccessSignatureAuthorizationRuleAccessRightsDescription struct { + KeyName string `json:"keyName"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Rights AccessRightsDescription `json:"rights"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_tagsresource.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_tagsresource.go new file mode 100644 index 00000000000..38669b65d97 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/model_tagsresource.go @@ -0,0 +1,8 @@ +package patch + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type TagsResource struct { + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/patch/version.go b/resource-manager/deviceprovisioningservices/2022-02-05/patch/version.go new file mode 100644 index 00000000000..6fbe127506e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/patch/version.go @@ -0,0 +1,12 @@ +package patch + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-05" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/patch/%s", defaultApiVersion) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/README.md b/resource-manager/deviceprovisioningservices/2022-02-05/post/README.md new file mode 100644 index 00000000000..ca88e0f36f2 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/README.md @@ -0,0 +1,111 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/post` Documentation + +The `post` SDK allows for interaction with the Azure Resource Manager Service `deviceprovisioningservices` (API Version `2022-02-05`). + +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/deviceprovisioningservices/2022-02-05/post" +``` + + +### Client Initialization + +```go +client := post.NewPOSTClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `POSTClient.DpsCertificateGenerateVerificationCode` + +```go +ctx := context.TODO() +id := post.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + +read, err := client.DpsCertificateGenerateVerificationCode(ctx, id, post.DefaultDpsCertificateGenerateVerificationCodeOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `POSTClient.DpsCertificateVerifyCertificate` + +```go +ctx := context.TODO() +id := post.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + +payload := post.VerificationCodeRequest{ + // ... +} + + +read, err := client.DpsCertificateVerifyCertificate(ctx, id, payload, post.DefaultDpsCertificateVerifyCertificateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `POSTClient.IotDpsResourceCheckProvisioningServiceNameAvailability` + +```go +ctx := context.TODO() +id := post.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +payload := post.OperationInputs{ + // ... +} + + +read, err := client.IotDpsResourceCheckProvisioningServiceNameAvailability(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `POSTClient.IotDpsResourceListKeys` + +```go +ctx := context.TODO() +id := post.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +// alternatively `client.IotDpsResourceListKeys(ctx, id)` can be used to do batched pagination +items, err := client.IotDpsResourceListKeysComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `POSTClient.IotDpsResourceListKeysForKeyName` + +```go +ctx := context.TODO() +id := post.NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "keyValue") + +read, err := client.IotDpsResourceListKeysForKeyName(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/deviceprovisioningservices/2022-02-05/post/client.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/client.go new file mode 100644 index 00000000000..f9cf3832310 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/client.go @@ -0,0 +1,18 @@ +package post + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type POSTClient struct { + Client autorest.Client + baseUri string +} + +func NewPOSTClientWithBaseURI(endpoint string) POSTClient { + return POSTClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/constants.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/constants.go new file mode 100644 index 00000000000..0161997a22c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/constants.go @@ -0,0 +1,102 @@ +package post + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessRightsDescription string + +const ( + AccessRightsDescriptionDeviceConnect AccessRightsDescription = "DeviceConnect" + AccessRightsDescriptionEnrollmentRead AccessRightsDescription = "EnrollmentRead" + AccessRightsDescriptionEnrollmentWrite AccessRightsDescription = "EnrollmentWrite" + AccessRightsDescriptionRegistrationStatusRead AccessRightsDescription = "RegistrationStatusRead" + AccessRightsDescriptionRegistrationStatusWrite AccessRightsDescription = "RegistrationStatusWrite" + AccessRightsDescriptionServiceConfig AccessRightsDescription = "ServiceConfig" +) + +func PossibleValuesForAccessRightsDescription() []string { + return []string{ + string(AccessRightsDescriptionDeviceConnect), + string(AccessRightsDescriptionEnrollmentRead), + string(AccessRightsDescriptionEnrollmentWrite), + string(AccessRightsDescriptionRegistrationStatusRead), + string(AccessRightsDescriptionRegistrationStatusWrite), + string(AccessRightsDescriptionServiceConfig), + } +} + +func parseAccessRightsDescription(input string) (*AccessRightsDescription, error) { + vals := map[string]AccessRightsDescription{ + "deviceconnect": AccessRightsDescriptionDeviceConnect, + "enrollmentread": AccessRightsDescriptionEnrollmentRead, + "enrollmentwrite": AccessRightsDescriptionEnrollmentWrite, + "registrationstatusread": AccessRightsDescriptionRegistrationStatusRead, + "registrationstatuswrite": AccessRightsDescriptionRegistrationStatusWrite, + "serviceconfig": AccessRightsDescriptionServiceConfig, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessRightsDescription(input) + return &out, nil +} + +type CertificatePurpose string + +const ( + CertificatePurposeClientAuthentication CertificatePurpose = "clientAuthentication" + CertificatePurposeServerAuthentication CertificatePurpose = "serverAuthentication" +) + +func PossibleValuesForCertificatePurpose() []string { + return []string{ + string(CertificatePurposeClientAuthentication), + string(CertificatePurposeServerAuthentication), + } +} + +func parseCertificatePurpose(input string) (*CertificatePurpose, error) { + vals := map[string]CertificatePurpose{ + "clientauthentication": CertificatePurposeClientAuthentication, + "serverauthentication": CertificatePurposeServerAuthentication, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CertificatePurpose(input) + return &out, nil +} + +type NameUnavailabilityReason string + +const ( + NameUnavailabilityReasonAlreadyExists NameUnavailabilityReason = "AlreadyExists" + NameUnavailabilityReasonInvalid NameUnavailabilityReason = "Invalid" +) + +func PossibleValuesForNameUnavailabilityReason() []string { + return []string{ + string(NameUnavailabilityReasonAlreadyExists), + string(NameUnavailabilityReasonInvalid), + } +} + +func parseNameUnavailabilityReason(input string) (*NameUnavailabilityReason, error) { + vals := map[string]NameUnavailabilityReason{ + "alreadyexists": NameUnavailabilityReasonAlreadyExists, + "invalid": NameUnavailabilityReasonInvalid, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := NameUnavailabilityReason(input) + return &out, nil +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/id_certificate.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_certificate.go new file mode 100644 index 00000000000..1908f63a394 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_certificate.go @@ -0,0 +1,137 @@ +package post + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, provisioningServiceName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(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 := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateValue"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/id_certificate_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_certificate_test.go new file mode 100644 index 00000000000..b930dc75822 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_certificate_test.go @@ -0,0 +1,324 @@ +package post + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } + + if id.CertificateName != "certificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateValue") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + CertificateName: "cErTiFiCaTeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId 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/deviceprovisioningservices/2022-02-05/post/id_key.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_key.go new file mode 100644 index 00000000000..d9872478df6 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_key.go @@ -0,0 +1,137 @@ +package post + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = KeyId{} + +// KeyId is a struct representing the Resource ID for a Key +type KeyId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string + KeyName string +} + +// NewKeyID returns a new KeyId struct +func NewKeyID(subscriptionId string, resourceGroupName string, provisioningServiceName string, keyName string) KeyId { + return KeyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + KeyName: keyName, + } +} + +// ParseKeyID parses 'input' into a KeyId +func ParseKeyID(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(KeyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := KeyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.KeyName, ok = parsed.Parsed["keyName"]; !ok { + return nil, fmt.Errorf("the segment 'keyName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseKeyIDInsensitively parses 'input' case-insensitively into a KeyId +// note: this method should only be used for API response data and not user input +func ParseKeyIDInsensitively(input string) (*KeyId, error) { + parser := resourceids.NewParserFromResourceIdType(KeyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := KeyId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.KeyName, ok = parsed.Parsed["keyName"]; !ok { + return nil, fmt.Errorf("the segment 'keyName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateKeyID checks that 'input' can be parsed as a Key ID +func ValidateKeyID(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 := ParseKeyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Key ID +func (id KeyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/keys/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName, id.KeyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Key ID +func (id KeyId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + resourceids.StaticSegment("staticKeys", "keys", "keys"), + resourceids.UserSpecifiedSegment("keyName", "keyValue"), + } +} + +// String returns a human-readable description of this Key ID +func (id KeyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + fmt.Sprintf("Key Name: %q", id.KeyName), + } + return fmt.Sprintf("Key (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/id_key_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_key_test.go new file mode 100644 index 00000000000..3cf94bf88eb --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_key_test.go @@ -0,0 +1,324 @@ +package post + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = KeyId{} + +func TestNewKeyID(t *testing.T) { + id := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "keyValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } + + if id.KeyName != "keyValue" { + t.Fatalf("Expected %q but got %q for Segment 'KeyName'", id.KeyName, "keyValue") + } +} + +func TestFormatKeyID(t *testing.T) { + actual := NewKeyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "keyValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys/keyValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseKeyID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys/keyValue", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys/keyValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestParseKeyIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *KeyId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/kEyS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys/keyValue", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + KeyName: "keyValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/keys/keyValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/kEyS/kEyVaLuE", + Expected: &KeyId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + KeyName: "kEyVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/kEyS/kEyVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseKeyIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.KeyName != v.Expected.KeyName { + t.Fatalf("Expected %q but got %q for KeyName", v.Expected.KeyName, actual.KeyName) + } + + } +} + +func TestSegmentsForKeyId(t *testing.T) { + segments := KeyId{}.Segments() + if len(segments) == 0 { + t.Fatalf("KeyId 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/deviceprovisioningservices/2022-02-05/post/id_provisioningservice.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_provisioningservice.go new file mode 100644 index 00000000000..4534e29a6d6 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_provisioningservice.go @@ -0,0 +1,124 @@ +package post + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +// ProvisioningServiceId is a struct representing the Resource ID for a Provisioning Service +type ProvisioningServiceId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string +} + +// NewProvisioningServiceID returns a new ProvisioningServiceId struct +func NewProvisioningServiceID(subscriptionId string, resourceGroupName string, provisioningServiceName string) ProvisioningServiceId { + return ProvisioningServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + } +} + +// ParseProvisioningServiceID parses 'input' into a ProvisioningServiceId +func ParseProvisioningServiceID(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProvisioningServiceIDInsensitively parses 'input' case-insensitively into a ProvisioningServiceId +// note: this method should only be used for API response data and not user input +func ParseProvisioningServiceIDInsensitively(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProvisioningServiceID checks that 'input' can be parsed as a Provisioning Service ID +func ValidateProvisioningServiceID(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 := ParseProvisioningServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provisioning Service ID +func (id ProvisioningServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provisioning Service ID +func (id ProvisioningServiceId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + } +} + +// String returns a human-readable description of this Provisioning Service ID +func (id ProvisioningServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + } + return fmt.Sprintf("Provisioning Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/id_provisioningservice_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_provisioningservice_test.go new file mode 100644 index 00000000000..7737c008e17 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/id_provisioningservice_test.go @@ -0,0 +1,279 @@ +package post + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +func TestNewProvisioningServiceID(t *testing.T) { + id := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } +} + +func TestFormatProvisioningServiceID(t *testing.T) { + actual := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProvisioningServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestParseProvisioningServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestSegmentsForProvisioningServiceId(t *testing.T) { + segments := ProvisioningServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProvisioningServiceId 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/deviceprovisioningservices/2022-02-05/post/method_dpscertificategenerateverificationcode_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_dpscertificategenerateverificationcode_autorest.go new file mode 100644 index 00000000000..4b354ec9af0 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_dpscertificategenerateverificationcode_autorest.go @@ -0,0 +1,138 @@ +package post + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpsCertificateGenerateVerificationCodeOperationResponse struct { + HttpResponse *http.Response + Model *VerificationCodeResponse +} + +type DpsCertificateGenerateVerificationCodeOperationOptions struct { + CertificateCreated *string + CertificateHasPrivateKey *bool + CertificateIsVerified *bool + CertificateLastUpdated *string + CertificateName *string + CertificateNonce *string + CertificatePurpose *CertificatePurpose + CertificateRawBytes *string + IfMatch *string +} + +func DefaultDpsCertificateGenerateVerificationCodeOperationOptions() DpsCertificateGenerateVerificationCodeOperationOptions { + return DpsCertificateGenerateVerificationCodeOperationOptions{} +} + +func (o DpsCertificateGenerateVerificationCodeOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o DpsCertificateGenerateVerificationCodeOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.CertificateCreated != nil { + out["certificate.created"] = *o.CertificateCreated + } + + if o.CertificateHasPrivateKey != nil { + out["certificate.hasPrivateKey"] = *o.CertificateHasPrivateKey + } + + if o.CertificateIsVerified != nil { + out["certificate.isVerified"] = *o.CertificateIsVerified + } + + if o.CertificateLastUpdated != nil { + out["certificate.lastUpdated"] = *o.CertificateLastUpdated + } + + if o.CertificateName != nil { + out["certificate.name"] = *o.CertificateName + } + + if o.CertificateNonce != nil { + out["certificate.nonce"] = *o.CertificateNonce + } + + if o.CertificatePurpose != nil { + out["certificate.purpose"] = *o.CertificatePurpose + } + + if o.CertificateRawBytes != nil { + out["certificate.rawBytes"] = *o.CertificateRawBytes + } + + return out +} + +// DpsCertificateGenerateVerificationCode ... +func (c POSTClient) DpsCertificateGenerateVerificationCode(ctx context.Context, id CertificateId, options DpsCertificateGenerateVerificationCodeOperationOptions) (result DpsCertificateGenerateVerificationCodeOperationResponse, err error) { + req, err := c.preparerForDpsCertificateGenerateVerificationCode(ctx, id, options) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "DpsCertificateGenerateVerificationCode", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "DpsCertificateGenerateVerificationCode", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDpsCertificateGenerateVerificationCode(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "DpsCertificateGenerateVerificationCode", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDpsCertificateGenerateVerificationCode prepares the DpsCertificateGenerateVerificationCode request. +func (c POSTClient) preparerForDpsCertificateGenerateVerificationCode(ctx context.Context, id CertificateId, options DpsCertificateGenerateVerificationCodeOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/generateVerificationCode", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDpsCertificateGenerateVerificationCode handles the response to the DpsCertificateGenerateVerificationCode request. The method always +// closes the http.Response Body. +func (c POSTClient) responderForDpsCertificateGenerateVerificationCode(resp *http.Response) (result DpsCertificateGenerateVerificationCodeOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/method_dpscertificateverifycertificate_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_dpscertificateverifycertificate_autorest.go new file mode 100644 index 00000000000..a15ee491613 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_dpscertificateverifycertificate_autorest.go @@ -0,0 +1,139 @@ +package post + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpsCertificateVerifyCertificateOperationResponse struct { + HttpResponse *http.Response + Model *CertificateResponse +} + +type DpsCertificateVerifyCertificateOperationOptions struct { + CertificateCreated *string + CertificateHasPrivateKey *bool + CertificateIsVerified *bool + CertificateLastUpdated *string + CertificateName *string + CertificateNonce *string + CertificatePurpose *CertificatePurpose + CertificateRawBytes *string + IfMatch *string +} + +func DefaultDpsCertificateVerifyCertificateOperationOptions() DpsCertificateVerifyCertificateOperationOptions { + return DpsCertificateVerifyCertificateOperationOptions{} +} + +func (o DpsCertificateVerifyCertificateOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o DpsCertificateVerifyCertificateOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + if o.CertificateCreated != nil { + out["certificate.created"] = *o.CertificateCreated + } + + if o.CertificateHasPrivateKey != nil { + out["certificate.hasPrivateKey"] = *o.CertificateHasPrivateKey + } + + if o.CertificateIsVerified != nil { + out["certificate.isVerified"] = *o.CertificateIsVerified + } + + if o.CertificateLastUpdated != nil { + out["certificate.lastUpdated"] = *o.CertificateLastUpdated + } + + if o.CertificateName != nil { + out["certificate.name"] = *o.CertificateName + } + + if o.CertificateNonce != nil { + out["certificate.nonce"] = *o.CertificateNonce + } + + if o.CertificatePurpose != nil { + out["certificate.purpose"] = *o.CertificatePurpose + } + + if o.CertificateRawBytes != nil { + out["certificate.rawBytes"] = *o.CertificateRawBytes + } + + return out +} + +// DpsCertificateVerifyCertificate ... +func (c POSTClient) DpsCertificateVerifyCertificate(ctx context.Context, id CertificateId, input VerificationCodeRequest, options DpsCertificateVerifyCertificateOperationOptions) (result DpsCertificateVerifyCertificateOperationResponse, err error) { + req, err := c.preparerForDpsCertificateVerifyCertificate(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "DpsCertificateVerifyCertificate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "DpsCertificateVerifyCertificate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDpsCertificateVerifyCertificate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "DpsCertificateVerifyCertificate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDpsCertificateVerifyCertificate prepares the DpsCertificateVerifyCertificate request. +func (c POSTClient) preparerForDpsCertificateVerifyCertificate(ctx context.Context, id CertificateId, input VerificationCodeRequest, options DpsCertificateVerifyCertificateOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(fmt.Sprintf("%s/verify", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDpsCertificateVerifyCertificate handles the response to the DpsCertificateVerifyCertificate request. The method always +// closes the http.Response Body. +func (c POSTClient) responderForDpsCertificateVerifyCertificate(resp *http.Response) (result DpsCertificateVerifyCertificateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcecheckprovisioningservicenameavailability_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcecheckprovisioningservicenameavailability_autorest.go new file mode 100644 index 00000000000..233847561bd --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcecheckprovisioningservicenameavailability_autorest.go @@ -0,0 +1,71 @@ +package post + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceCheckProvisioningServiceNameAvailabilityOperationResponse struct { + HttpResponse *http.Response + Model *NameAvailabilityInfo +} + +// IotDpsResourceCheckProvisioningServiceNameAvailability ... +func (c POSTClient) IotDpsResourceCheckProvisioningServiceNameAvailability(ctx context.Context, id commonids.SubscriptionId, input OperationInputs) (result IotDpsResourceCheckProvisioningServiceNameAvailabilityOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceCheckProvisioningServiceNameAvailability(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceCheckProvisioningServiceNameAvailability", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceCheckProvisioningServiceNameAvailability", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceCheckProvisioningServiceNameAvailability(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceCheckProvisioningServiceNameAvailability", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceCheckProvisioningServiceNameAvailability prepares the IotDpsResourceCheckProvisioningServiceNameAvailability request. +func (c POSTClient) preparerForIotDpsResourceCheckProvisioningServiceNameAvailability(ctx context.Context, id commonids.SubscriptionId, input OperationInputs) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Devices/checkProvisioningServiceNameAvailability", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceCheckProvisioningServiceNameAvailability handles the response to the IotDpsResourceCheckProvisioningServiceNameAvailability request. The method always +// closes the http.Response Body. +func (c POSTClient) responderForIotDpsResourceCheckProvisioningServiceNameAvailability(resp *http.Response) (result IotDpsResourceCheckProvisioningServiceNameAvailabilityOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcelistkeys_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcelistkeys_autorest.go new file mode 100644 index 00000000000..bbcc2a006c3 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcelistkeys_autorest.go @@ -0,0 +1,186 @@ +package post + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceListKeysOperationResponse struct { + HttpResponse *http.Response + Model *[]SharedAccessSignatureAuthorizationRuleAccessRightsDescription + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (IotDpsResourceListKeysOperationResponse, error) +} + +type IotDpsResourceListKeysCompleteResult struct { + Items []SharedAccessSignatureAuthorizationRuleAccessRightsDescription +} + +func (r IotDpsResourceListKeysOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r IotDpsResourceListKeysOperationResponse) LoadMore(ctx context.Context) (resp IotDpsResourceListKeysOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// IotDpsResourceListKeys ... +func (c POSTClient) IotDpsResourceListKeys(ctx context.Context, id ProvisioningServiceId) (resp IotDpsResourceListKeysOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListKeys(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeys", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeys", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForIotDpsResourceListKeys(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeys", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// IotDpsResourceListKeysComplete retrieves all of the results into a single object +func (c POSTClient) IotDpsResourceListKeysComplete(ctx context.Context, id ProvisioningServiceId) (IotDpsResourceListKeysCompleteResult, error) { + return c.IotDpsResourceListKeysCompleteMatchingPredicate(ctx, id, SharedAccessSignatureAuthorizationRuleAccessRightsDescriptionOperationPredicate{}) +} + +// IotDpsResourceListKeysCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c POSTClient) IotDpsResourceListKeysCompleteMatchingPredicate(ctx context.Context, id ProvisioningServiceId, predicate SharedAccessSignatureAuthorizationRuleAccessRightsDescriptionOperationPredicate) (resp IotDpsResourceListKeysCompleteResult, err error) { + items := make([]SharedAccessSignatureAuthorizationRuleAccessRightsDescription, 0) + + page, err := c.IotDpsResourceListKeys(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := IotDpsResourceListKeysCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForIotDpsResourceListKeys prepares the IotDpsResourceListKeys request. +func (c POSTClient) preparerForIotDpsResourceListKeys(ctx context.Context, id ProvisioningServiceId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/listkeys", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForIotDpsResourceListKeysWithNextLink prepares the IotDpsResourceListKeys request with the given nextLink token. +func (c POSTClient) preparerForIotDpsResourceListKeysWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceListKeys handles the response to the IotDpsResourceListKeys request. The method always +// closes the http.Response Body. +func (c POSTClient) responderForIotDpsResourceListKeys(resp *http.Response) (result IotDpsResourceListKeysOperationResponse, err error) { + type page struct { + Values []SharedAccessSignatureAuthorizationRuleAccessRightsDescription `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result IotDpsResourceListKeysOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListKeysWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeys", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeys", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceListKeys(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeys", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcelistkeysforkeyname_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcelistkeysforkeyname_autorest.go new file mode 100644 index 00000000000..67b5dc86afd --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/method_iotdpsresourcelistkeysforkeyname_autorest.go @@ -0,0 +1,69 @@ +package post + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceListKeysForKeyNameOperationResponse struct { + HttpResponse *http.Response + Model *SharedAccessSignatureAuthorizationRuleAccessRightsDescription +} + +// IotDpsResourceListKeysForKeyName ... +func (c POSTClient) IotDpsResourceListKeysForKeyName(ctx context.Context, id KeyId) (result IotDpsResourceListKeysForKeyNameOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceListKeysForKeyName(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeysForKeyName", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeysForKeyName", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForIotDpsResourceListKeysForKeyName(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "post.POSTClient", "IotDpsResourceListKeysForKeyName", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForIotDpsResourceListKeysForKeyName prepares the IotDpsResourceListKeysForKeyName request. +func (c POSTClient) preparerForIotDpsResourceListKeysForKeyName(ctx context.Context, id KeyId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/listkeys", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForIotDpsResourceListKeysForKeyName handles the response to the IotDpsResourceListKeysForKeyName request. The method always +// closes the http.Response Body. +func (c POSTClient) responderForIotDpsResourceListKeysForKeyName(resp *http.Response) (result IotDpsResourceListKeysForKeyNameOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_certificateproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_certificateproperties.go new file mode 100644 index 00000000000..f02c6513ee9 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_certificateproperties.go @@ -0,0 +1,14 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateProperties struct { + Certificate *string `json:"certificate,omitempty"` + Created *string `json:"created,omitempty"` + Expiry *string `json:"expiry,omitempty"` + IsVerified *bool `json:"isVerified,omitempty"` + Subject *string `json:"subject,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Updated *string `json:"updated,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_certificateresponse.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_certificateresponse.go new file mode 100644 index 00000000000..ae14fb9eeac --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_certificateresponse.go @@ -0,0 +1,17 @@ +package post + +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 CertificateResponse struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CertificateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_nameavailabilityinfo.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_nameavailabilityinfo.go new file mode 100644 index 00000000000..e7b72f48d36 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_nameavailabilityinfo.go @@ -0,0 +1,10 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type NameAvailabilityInfo struct { + Message *string `json:"message,omitempty"` + NameAvailable *bool `json:"nameAvailable,omitempty"` + Reason *NameUnavailabilityReason `json:"reason,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_operationinputs.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_operationinputs.go new file mode 100644 index 00000000000..21b60d1ac18 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_operationinputs.go @@ -0,0 +1,8 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type OperationInputs struct { + Name string `json:"name"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go new file mode 100644 index 00000000000..f5f0d565775 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go @@ -0,0 +1,11 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedAccessSignatureAuthorizationRuleAccessRightsDescription struct { + KeyName string `json:"keyName"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Rights AccessRightsDescription `json:"rights"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderequest.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderequest.go new file mode 100644 index 00000000000..55bb120d234 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderequest.go @@ -0,0 +1,8 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VerificationCodeRequest struct { + Certificate *string `json:"certificate,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderesponse.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderesponse.go new file mode 100644 index 00000000000..3aef9255655 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderesponse.go @@ -0,0 +1,12 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VerificationCodeResponse struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *VerificationCodeResponseProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderesponseproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderesponseproperties.go new file mode 100644 index 00000000000..57b0b2025b3 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/model_verificationcoderesponseproperties.go @@ -0,0 +1,15 @@ +package post + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VerificationCodeResponseProperties struct { + Certificate *string `json:"certificate,omitempty"` + Created *string `json:"created,omitempty"` + Expiry *string `json:"expiry,omitempty"` + IsVerified *bool `json:"isVerified,omitempty"` + Subject *string `json:"subject,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Updated *string `json:"updated,omitempty"` + VerificationCode *string `json:"verificationCode,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/predicates.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/predicates.go new file mode 100644 index 00000000000..63e2ee7c861 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/predicates.go @@ -0,0 +1,24 @@ +package post + +type SharedAccessSignatureAuthorizationRuleAccessRightsDescriptionOperationPredicate struct { + KeyName *string + PrimaryKey *string + SecondaryKey *string +} + +func (p SharedAccessSignatureAuthorizationRuleAccessRightsDescriptionOperationPredicate) Matches(input SharedAccessSignatureAuthorizationRuleAccessRightsDescription) bool { + + if p.KeyName != nil && *p.KeyName != input.KeyName { + return false + } + + if p.PrimaryKey != nil && (input.PrimaryKey == nil && *p.PrimaryKey != *input.PrimaryKey) { + return false + } + + if p.SecondaryKey != nil && (input.SecondaryKey == nil && *p.SecondaryKey != *input.SecondaryKey) { + return false + } + + return true +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/post/version.go b/resource-manager/deviceprovisioningservices/2022-02-05/post/version.go new file mode 100644 index 00000000000..629130f3618 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/post/version.go @@ -0,0 +1,12 @@ +package post + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-05" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/post/%s", defaultApiVersion) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/README.md b/resource-manager/deviceprovisioningservices/2022-02-05/put/README.md new file mode 100644 index 00000000000..404eb979776 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/README.md @@ -0,0 +1,75 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/deviceprovisioningservices/2022-02-05/put` Documentation + +The `put` SDK allows for interaction with the Azure Resource Manager Service `deviceprovisioningservices` (API Version `2022-02-05`). + +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/deviceprovisioningservices/2022-02-05/put" +``` + + +### Client Initialization + +```go +client := put.NewPUTClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PUTClient.DpsCertificateCreateOrUpdate` + +```go +ctx := context.TODO() +id := put.NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + +payload := put.CertificateResponse{ + // ... +} + + +read, err := client.DpsCertificateCreateOrUpdate(ctx, id, payload, put.DefaultDpsCertificateCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PUTClient.IotDpsResourceCreateOrUpdate` + +```go +ctx := context.TODO() +id := put.NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + +payload := put.ProvisioningServiceDescription{ + // ... +} + + +if err := client.IotDpsResourceCreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `PUTClient.IotDpsResourceCreateOrUpdatePrivateEndpointConnection` + +```go +ctx := context.TODO() +id := put.NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + +payload := put.PrivateEndpointConnection{ + // ... +} + + +if err := client.IotDpsResourceCreateOrUpdatePrivateEndpointConnectionThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/client.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/client.go new file mode 100644 index 00000000000..a74c08e17fd --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/client.go @@ -0,0 +1,18 @@ +package put + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PUTClient struct { + Client autorest.Client + baseUri string +} + +func NewPUTClientWithBaseURI(endpoint string) PUTClient { + return PUTClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/constants.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/constants.go new file mode 100644 index 00000000000..c8c073c5e5c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/constants.go @@ -0,0 +1,281 @@ +package put + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AccessRightsDescription string + +const ( + AccessRightsDescriptionDeviceConnect AccessRightsDescription = "DeviceConnect" + AccessRightsDescriptionEnrollmentRead AccessRightsDescription = "EnrollmentRead" + AccessRightsDescriptionEnrollmentWrite AccessRightsDescription = "EnrollmentWrite" + AccessRightsDescriptionRegistrationStatusRead AccessRightsDescription = "RegistrationStatusRead" + AccessRightsDescriptionRegistrationStatusWrite AccessRightsDescription = "RegistrationStatusWrite" + AccessRightsDescriptionServiceConfig AccessRightsDescription = "ServiceConfig" +) + +func PossibleValuesForAccessRightsDescription() []string { + return []string{ + string(AccessRightsDescriptionDeviceConnect), + string(AccessRightsDescriptionEnrollmentRead), + string(AccessRightsDescriptionEnrollmentWrite), + string(AccessRightsDescriptionRegistrationStatusRead), + string(AccessRightsDescriptionRegistrationStatusWrite), + string(AccessRightsDescriptionServiceConfig), + } +} + +func parseAccessRightsDescription(input string) (*AccessRightsDescription, error) { + vals := map[string]AccessRightsDescription{ + "deviceconnect": AccessRightsDescriptionDeviceConnect, + "enrollmentread": AccessRightsDescriptionEnrollmentRead, + "enrollmentwrite": AccessRightsDescriptionEnrollmentWrite, + "registrationstatusread": AccessRightsDescriptionRegistrationStatusRead, + "registrationstatuswrite": AccessRightsDescriptionRegistrationStatusWrite, + "serviceconfig": AccessRightsDescriptionServiceConfig, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AccessRightsDescription(input) + return &out, nil +} + +type AllocationPolicy string + +const ( + AllocationPolicyGeoLatency AllocationPolicy = "GeoLatency" + AllocationPolicyHashed AllocationPolicy = "Hashed" + AllocationPolicyStatic AllocationPolicy = "Static" +) + +func PossibleValuesForAllocationPolicy() []string { + return []string{ + string(AllocationPolicyGeoLatency), + string(AllocationPolicyHashed), + string(AllocationPolicyStatic), + } +} + +func parseAllocationPolicy(input string) (*AllocationPolicy, error) { + vals := map[string]AllocationPolicy{ + "geolatency": AllocationPolicyGeoLatency, + "hashed": AllocationPolicyHashed, + "static": AllocationPolicyStatic, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AllocationPolicy(input) + return &out, nil +} + +type IPFilterActionType string + +const ( + IPFilterActionTypeAccept IPFilterActionType = "Accept" + IPFilterActionTypeReject IPFilterActionType = "Reject" +) + +func PossibleValuesForIPFilterActionType() []string { + return []string{ + string(IPFilterActionTypeAccept), + string(IPFilterActionTypeReject), + } +} + +func parseIPFilterActionType(input string) (*IPFilterActionType, error) { + vals := map[string]IPFilterActionType{ + "accept": IPFilterActionTypeAccept, + "reject": IPFilterActionTypeReject, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPFilterActionType(input) + return &out, nil +} + +type IPFilterTargetType string + +const ( + IPFilterTargetTypeAll IPFilterTargetType = "all" + IPFilterTargetTypeDeviceApi IPFilterTargetType = "deviceApi" + IPFilterTargetTypeServiceApi IPFilterTargetType = "serviceApi" +) + +func PossibleValuesForIPFilterTargetType() []string { + return []string{ + string(IPFilterTargetTypeAll), + string(IPFilterTargetTypeDeviceApi), + string(IPFilterTargetTypeServiceApi), + } +} + +func parseIPFilterTargetType(input string) (*IPFilterTargetType, error) { + vals := map[string]IPFilterTargetType{ + "all": IPFilterTargetTypeAll, + "deviceapi": IPFilterTargetTypeDeviceApi, + "serviceapi": IPFilterTargetTypeServiceApi, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IPFilterTargetType(input) + return &out, nil +} + +type IotDpsSku string + +const ( + IotDpsSkuSOne IotDpsSku = "S1" +) + +func PossibleValuesForIotDpsSku() []string { + return []string{ + string(IotDpsSkuSOne), + } +} + +func parseIotDpsSku(input string) (*IotDpsSku, error) { + vals := map[string]IotDpsSku{ + "s1": IotDpsSkuSOne, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := IotDpsSku(input) + return &out, nil +} + +type PrivateLinkServiceConnectionStatus string + +const ( + PrivateLinkServiceConnectionStatusApproved PrivateLinkServiceConnectionStatus = "Approved" + PrivateLinkServiceConnectionStatusDisconnected PrivateLinkServiceConnectionStatus = "Disconnected" + PrivateLinkServiceConnectionStatusPending PrivateLinkServiceConnectionStatus = "Pending" + PrivateLinkServiceConnectionStatusRejected PrivateLinkServiceConnectionStatus = "Rejected" +) + +func PossibleValuesForPrivateLinkServiceConnectionStatus() []string { + return []string{ + string(PrivateLinkServiceConnectionStatusApproved), + string(PrivateLinkServiceConnectionStatusDisconnected), + string(PrivateLinkServiceConnectionStatusPending), + string(PrivateLinkServiceConnectionStatusRejected), + } +} + +func parsePrivateLinkServiceConnectionStatus(input string) (*PrivateLinkServiceConnectionStatus, error) { + vals := map[string]PrivateLinkServiceConnectionStatus{ + "approved": PrivateLinkServiceConnectionStatusApproved, + "disconnected": PrivateLinkServiceConnectionStatusDisconnected, + "pending": PrivateLinkServiceConnectionStatusPending, + "rejected": PrivateLinkServiceConnectionStatusRejected, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PrivateLinkServiceConnectionStatus(input) + return &out, nil +} + +type PublicNetworkAccess string + +const ( + PublicNetworkAccessDisabled PublicNetworkAccess = "Disabled" + PublicNetworkAccessEnabled PublicNetworkAccess = "Enabled" +) + +func PossibleValuesForPublicNetworkAccess() []string { + return []string{ + string(PublicNetworkAccessDisabled), + string(PublicNetworkAccessEnabled), + } +} + +func parsePublicNetworkAccess(input string) (*PublicNetworkAccess, error) { + vals := map[string]PublicNetworkAccess{ + "disabled": PublicNetworkAccessDisabled, + "enabled": PublicNetworkAccessEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PublicNetworkAccess(input) + return &out, nil +} + +type State string + +const ( + StateActivating State = "Activating" + StateActivationFailed State = "ActivationFailed" + StateActive State = "Active" + StateDeleted State = "Deleted" + StateDeleting State = "Deleting" + StateDeletionFailed State = "DeletionFailed" + StateFailingOver State = "FailingOver" + StateFailoverFailed State = "FailoverFailed" + StateResuming State = "Resuming" + StateSuspended State = "Suspended" + StateSuspending State = "Suspending" + StateTransitioning State = "Transitioning" +) + +func PossibleValuesForState() []string { + return []string{ + string(StateActivating), + string(StateActivationFailed), + string(StateActive), + string(StateDeleted), + string(StateDeleting), + string(StateDeletionFailed), + string(StateFailingOver), + string(StateFailoverFailed), + string(StateResuming), + string(StateSuspended), + string(StateSuspending), + string(StateTransitioning), + } +} + +func parseState(input string) (*State, error) { + vals := map[string]State{ + "activating": StateActivating, + "activationfailed": StateActivationFailed, + "active": StateActive, + "deleted": StateDeleted, + "deleting": StateDeleting, + "deletionfailed": StateDeletionFailed, + "failingover": StateFailingOver, + "failoverfailed": StateFailoverFailed, + "resuming": StateResuming, + "suspended": StateSuspended, + "suspending": StateSuspending, + "transitioning": StateTransitioning, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := State(input) + return &out, nil +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/id_certificate.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_certificate.go new file mode 100644 index 00000000000..74e5453cfa5 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_certificate.go @@ -0,0 +1,137 @@ +package put + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +// CertificateId is a struct representing the Resource ID for a Certificate +type CertificateId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string + CertificateName string +} + +// NewCertificateID returns a new CertificateId struct +func NewCertificateID(subscriptionId string, resourceGroupName string, provisioningServiceName string, certificateName string) CertificateId { + return CertificateId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + CertificateName: certificateName, + } +} + +// ParseCertificateID parses 'input' into a CertificateId +func ParseCertificateID(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseCertificateIDInsensitively parses 'input' case-insensitively into a CertificateId +// note: this method should only be used for API response data and not user input +func ParseCertificateIDInsensitively(input string) (*CertificateId, error) { + parser := resourceids.NewParserFromResourceIdType(CertificateId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := CertificateId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + if id.CertificateName, ok = parsed.Parsed["certificateName"]; !ok { + return nil, fmt.Errorf("the segment 'certificateName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateCertificateID checks that 'input' can be parsed as a Certificate ID +func ValidateCertificateID(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 := ParseCertificateID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Certificate ID +func (id CertificateId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/certificates/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName, id.CertificateName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Certificate ID +func (id CertificateId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + resourceids.StaticSegment("staticCertificates", "certificates", "certificates"), + resourceids.UserSpecifiedSegment("certificateName", "certificateValue"), + } +} + +// String returns a human-readable description of this Certificate ID +func (id CertificateId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + fmt.Sprintf("Certificate Name: %q", id.CertificateName), + } + return fmt.Sprintf("Certificate (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/id_certificate_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_certificate_test.go new file mode 100644 index 00000000000..45489827440 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_certificate_test.go @@ -0,0 +1,324 @@ +package put + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = CertificateId{} + +func TestNewCertificateID(t *testing.T) { + id := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } + + if id.CertificateName != "certificateValue" { + t.Fatalf("Expected %q but got %q for Segment 'CertificateName'", id.CertificateName, "certificateValue") + } +} + +func TestFormatCertificateID(t *testing.T) { + actual := NewCertificateID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue", "certificateValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseCertificateID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestParseCertificateIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *CertificateId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + CertificateName: "certificateValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/certificates/certificateValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE", + Expected: &CertificateId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + CertificateName: "cErTiFiCaTeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/cErTiFiCaTeS/cErTiFiCaTeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseCertificateIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + if actual.CertificateName != v.Expected.CertificateName { + t.Fatalf("Expected %q but got %q for CertificateName", v.Expected.CertificateName, actual.CertificateName) + } + + } +} + +func TestSegmentsForCertificateId(t *testing.T) { + segments := CertificateId{}.Segments() + if len(segments) == 0 { + t.Fatalf("CertificateId 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/deviceprovisioningservices/2022-02-05/put/id_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_privateendpointconnection.go new file mode 100644 index 00000000000..f2da4208405 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_privateendpointconnection.go @@ -0,0 +1,137 @@ +package put + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection +type PrivateEndpointConnectionId struct { + SubscriptionId string + ResourceGroupName string + ResourceName string + PrivateEndpointConnectionName string +} + +// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct +func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, resourceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId { + return PrivateEndpointConnectionId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ResourceName: resourceName, + PrivateEndpointConnectionName: privateEndpointConnectionName, + } +} + +// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId +func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId +// note: this method should only be used for API response data and not user input +func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) { + parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := PrivateEndpointConnectionId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ResourceName, ok = parsed.Parsed["resourceName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceName' was not found in the resource id %q", input) + } + + if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok { + return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID +func ValidatePrivateEndpointConnectionID(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 := ParsePrivateEndpointConnectionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s/privateEndpointConnections/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName, id.PrivateEndpointConnectionName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), + resourceids.StaticSegment("staticPrivateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"), + resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"), + } +} + +// String returns a human-readable description of this Private Endpoint Connection ID +func (id PrivateEndpointConnectionId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Resource Name: %q", id.ResourceName), + fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName), + } + return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/id_privateendpointconnection_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_privateendpointconnection_test.go new file mode 100644 index 00000000000..74e697d75fd --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_privateendpointconnection_test.go @@ -0,0 +1,324 @@ +package put + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = PrivateEndpointConnectionId{} + +func TestNewPrivateEndpointConnectionID(t *testing.T) { + id := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue") + + 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.ResourceName != "resourceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceName'", id.ResourceName, "resourceValue") + } + + if id.PrivateEndpointConnectionName != "privateEndpointConnectionValue" { + t.Fatalf("Expected %q but got %q for Segment 'PrivateEndpointConnectionName'", id.PrivateEndpointConnectionName, "privateEndpointConnectionValue") + } +} + +func TestFormatPrivateEndpointConnectionID(t *testing.T) { + actual := NewPrivateEndpointConnectionID("12345678-1234-9876-4563-123456789012", "example-resource-group", "resourceValue", "privateEndpointConnectionValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParsePrivateEndpointConnectionID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionID(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestParsePrivateEndpointConnectionIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *PrivateEndpointConnectionId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ResourceName: "resourceValue", + PrivateEndpointConnectionName: "privateEndpointConnectionValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/resourceValue/privateEndpointConnections/privateEndpointConnectionValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + Expected: &PrivateEndpointConnectionId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ResourceName: "rEsOuRcEvAlUe", + PrivateEndpointConnectionName: "pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/rEsOuRcEvAlUe/pRiVaTeEnDpOiNtCoNnEcTiOnS/pRiVaTeEnDpOiNtCoNnEcTiOnVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParsePrivateEndpointConnectionIDInsensitively(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.ResourceName != v.Expected.ResourceName { + t.Fatalf("Expected %q but got %q for ResourceName", v.Expected.ResourceName, actual.ResourceName) + } + + if actual.PrivateEndpointConnectionName != v.Expected.PrivateEndpointConnectionName { + t.Fatalf("Expected %q but got %q for PrivateEndpointConnectionName", v.Expected.PrivateEndpointConnectionName, actual.PrivateEndpointConnectionName) + } + + } +} + +func TestSegmentsForPrivateEndpointConnectionId(t *testing.T) { + segments := PrivateEndpointConnectionId{}.Segments() + if len(segments) == 0 { + t.Fatalf("PrivateEndpointConnectionId 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/deviceprovisioningservices/2022-02-05/put/id_provisioningservice.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_provisioningservice.go new file mode 100644 index 00000000000..f8e9e28e526 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_provisioningservice.go @@ -0,0 +1,124 @@ +package put + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +// ProvisioningServiceId is a struct representing the Resource ID for a Provisioning Service +type ProvisioningServiceId struct { + SubscriptionId string + ResourceGroupName string + ProvisioningServiceName string +} + +// NewProvisioningServiceID returns a new ProvisioningServiceId struct +func NewProvisioningServiceID(subscriptionId string, resourceGroupName string, provisioningServiceName string) ProvisioningServiceId { + return ProvisioningServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProvisioningServiceName: provisioningServiceName, + } +} + +// ParseProvisioningServiceID parses 'input' into a ProvisioningServiceId +func ParseProvisioningServiceID(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseProvisioningServiceIDInsensitively parses 'input' case-insensitively into a ProvisioningServiceId +// note: this method should only be used for API response data and not user input +func ParseProvisioningServiceIDInsensitively(input string) (*ProvisioningServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(ProvisioningServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ProvisioningServiceId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ProvisioningServiceName, ok = parsed.Parsed["provisioningServiceName"]; !ok { + return nil, fmt.Errorf("the segment 'provisioningServiceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateProvisioningServiceID checks that 'input' can be parsed as a Provisioning Service ID +func ValidateProvisioningServiceID(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 := ParseProvisioningServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Provisioning Service ID +func (id ProvisioningServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Devices/provisioningServices/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProvisioningServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Provisioning Service ID +func (id ProvisioningServiceId) 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("staticMicrosoftDevices", "Microsoft.Devices", "Microsoft.Devices"), + resourceids.StaticSegment("staticProvisioningServices", "provisioningServices", "provisioningServices"), + resourceids.UserSpecifiedSegment("provisioningServiceName", "provisioningServiceValue"), + } +} + +// String returns a human-readable description of this Provisioning Service ID +func (id ProvisioningServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Provisioning Service Name: %q", id.ProvisioningServiceName), + } + return fmt.Sprintf("Provisioning Service (%s)", strings.Join(components, "\n")) +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/id_provisioningservice_test.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_provisioningservice_test.go new file mode 100644 index 00000000000..ba3d0ea90e4 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/id_provisioningservice_test.go @@ -0,0 +1,279 @@ +package put + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ProvisioningServiceId{} + +func TestNewProvisioningServiceID(t *testing.T) { + id := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue") + + 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.ProvisioningServiceName != "provisioningServiceValue" { + t.Fatalf("Expected %q but got %q for Segment 'ProvisioningServiceName'", id.ProvisioningServiceName, "provisioningServiceValue") + } +} + +func TestFormatProvisioningServiceID(t *testing.T) { + actual := NewProvisioningServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "provisioningServiceValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseProvisioningServiceID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceID(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestParseProvisioningServiceIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ProvisioningServiceId + }{ + { + // 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.Devices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ProvisioningServiceName: "provisioningServiceValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Devices/provisioningServices/provisioningServiceValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE", + Expected: &ProvisioningServiceId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ProvisioningServiceName: "pRoViSiOnInGsErViCeVaLuE", + }, + }, + { + // 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.dEvIcEs/pRoViSiOnInGsErViCeS/pRoViSiOnInGsErViCeVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseProvisioningServiceIDInsensitively(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.ProvisioningServiceName != v.Expected.ProvisioningServiceName { + t.Fatalf("Expected %q but got %q for ProvisioningServiceName", v.Expected.ProvisioningServiceName, actual.ProvisioningServiceName) + } + + } +} + +func TestSegmentsForProvisioningServiceId(t *testing.T) { + segments := ProvisioningServiceId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ProvisioningServiceId 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/deviceprovisioningservices/2022-02-05/put/method_dpscertificatecreateorupdate_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/method_dpscertificatecreateorupdate_autorest.go new file mode 100644 index 00000000000..bd65b8737c3 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/method_dpscertificatecreateorupdate_autorest.go @@ -0,0 +1,98 @@ +package put + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DpsCertificateCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + Model *CertificateResponse +} + +type DpsCertificateCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultDpsCertificateCreateOrUpdateOperationOptions() DpsCertificateCreateOrUpdateOperationOptions { + return DpsCertificateCreateOrUpdateOperationOptions{} +} + +func (o DpsCertificateCreateOrUpdateOperationOptions) toHeaders() map[string]interface{} { + out := make(map[string]interface{}) + + if o.IfMatch != nil { + out["If-Match"] = *o.IfMatch + } + + return out +} + +func (o DpsCertificateCreateOrUpdateOperationOptions) toQueryString() map[string]interface{} { + out := make(map[string]interface{}) + + return out +} + +// DpsCertificateCreateOrUpdate ... +func (c PUTClient) DpsCertificateCreateOrUpdate(ctx context.Context, id CertificateId, input CertificateResponse, options DpsCertificateCreateOrUpdateOperationOptions) (result DpsCertificateCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForDpsCertificateCreateOrUpdate(ctx, id, input, options) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "DpsCertificateCreateOrUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "DpsCertificateCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForDpsCertificateCreateOrUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "DpsCertificateCreateOrUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForDpsCertificateCreateOrUpdate prepares the DpsCertificateCreateOrUpdate request. +func (c PUTClient) preparerForDpsCertificateCreateOrUpdate(ctx context.Context, id CertificateId, input CertificateResponse, options DpsCertificateCreateOrUpdateOperationOptions) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + for k, v := range options.toQueryString() { + queryParameters[k] = autorest.Encode("query", v) + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithHeaders(options.toHeaders()), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForDpsCertificateCreateOrUpdate handles the response to the DpsCertificateCreateOrUpdate request. The method always +// closes the http.Response Body. +func (c PUTClient) responderForDpsCertificateCreateOrUpdate(resp *http.Response) (result DpsCertificateCreateOrUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/method_iotdpsresourcecreateorupdate_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/method_iotdpsresourcecreateorupdate_autorest.go new file mode 100644 index 00000000000..ab1dfddfa2b --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/method_iotdpsresourcecreateorupdate_autorest.go @@ -0,0 +1,79 @@ +package put + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceCreateOrUpdateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// IotDpsResourceCreateOrUpdate ... +func (c PUTClient) IotDpsResourceCreateOrUpdate(ctx context.Context, id ProvisioningServiceId, input ProvisioningServiceDescription) (result IotDpsResourceCreateOrUpdateOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceCreateOrUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "IotDpsResourceCreateOrUpdate", nil, "Failure preparing request") + return + } + + result, err = c.senderForIotDpsResourceCreateOrUpdate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "IotDpsResourceCreateOrUpdate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// IotDpsResourceCreateOrUpdateThenPoll performs IotDpsResourceCreateOrUpdate then polls until it's completed +func (c PUTClient) IotDpsResourceCreateOrUpdateThenPoll(ctx context.Context, id ProvisioningServiceId, input ProvisioningServiceDescription) error { + result, err := c.IotDpsResourceCreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing IotDpsResourceCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after IotDpsResourceCreateOrUpdate: %+v", err) + } + + return nil +} + +// preparerForIotDpsResourceCreateOrUpdate prepares the IotDpsResourceCreateOrUpdate request. +func (c PUTClient) preparerForIotDpsResourceCreateOrUpdate(ctx context.Context, id ProvisioningServiceId, input ProvisioningServiceDescription) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForIotDpsResourceCreateOrUpdate sends the IotDpsResourceCreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (c PUTClient) senderForIotDpsResourceCreateOrUpdate(ctx context.Context, req *http.Request) (future IotDpsResourceCreateOrUpdateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/method_iotdpsresourcecreateorupdateprivateendpointconnection_autorest.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/method_iotdpsresourcecreateorupdateprivateendpointconnection_autorest.go new file mode 100644 index 00000000000..4f79b396044 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/method_iotdpsresourcecreateorupdateprivateendpointconnection_autorest.go @@ -0,0 +1,79 @@ +package put + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsResourceCreateOrUpdatePrivateEndpointConnectionOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// IotDpsResourceCreateOrUpdatePrivateEndpointConnection ... +func (c PUTClient) IotDpsResourceCreateOrUpdatePrivateEndpointConnection(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (result IotDpsResourceCreateOrUpdatePrivateEndpointConnectionOperationResponse, err error) { + req, err := c.preparerForIotDpsResourceCreateOrUpdatePrivateEndpointConnection(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "IotDpsResourceCreateOrUpdatePrivateEndpointConnection", nil, "Failure preparing request") + return + } + + result, err = c.senderForIotDpsResourceCreateOrUpdatePrivateEndpointConnection(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "put.PUTClient", "IotDpsResourceCreateOrUpdatePrivateEndpointConnection", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// IotDpsResourceCreateOrUpdatePrivateEndpointConnectionThenPoll performs IotDpsResourceCreateOrUpdatePrivateEndpointConnection then polls until it's completed +func (c PUTClient) IotDpsResourceCreateOrUpdatePrivateEndpointConnectionThenPoll(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) error { + result, err := c.IotDpsResourceCreateOrUpdatePrivateEndpointConnection(ctx, id, input) + if err != nil { + return fmt.Errorf("performing IotDpsResourceCreateOrUpdatePrivateEndpointConnection: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after IotDpsResourceCreateOrUpdatePrivateEndpointConnection: %+v", err) + } + + return nil +} + +// preparerForIotDpsResourceCreateOrUpdatePrivateEndpointConnection prepares the IotDpsResourceCreateOrUpdatePrivateEndpointConnection request. +func (c PUTClient) preparerForIotDpsResourceCreateOrUpdatePrivateEndpointConnection(ctx context.Context, id PrivateEndpointConnectionId, input PrivateEndpointConnection) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForIotDpsResourceCreateOrUpdatePrivateEndpointConnection sends the IotDpsResourceCreateOrUpdatePrivateEndpointConnection request. The method will close the +// http.Response Body if it receives an error. +func (c PUTClient) senderForIotDpsResourceCreateOrUpdatePrivateEndpointConnection(ctx context.Context, req *http.Request) (future IotDpsResourceCreateOrUpdatePrivateEndpointConnectionOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_certificateproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_certificateproperties.go new file mode 100644 index 00000000000..1ca24f67dd3 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_certificateproperties.go @@ -0,0 +1,14 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CertificateProperties struct { + Certificate *string `json:"certificate,omitempty"` + Created *string `json:"created,omitempty"` + Expiry *string `json:"expiry,omitempty"` + IsVerified *bool `json:"isVerified,omitempty"` + Subject *string `json:"subject,omitempty"` + Thumbprint *string `json:"thumbprint,omitempty"` + Updated *string `json:"updated,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_certificateresponse.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_certificateresponse.go new file mode 100644 index 00000000000..e412e34f91f --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_certificateresponse.go @@ -0,0 +1,17 @@ +package put + +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 CertificateResponse struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *CertificateProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iotdpspropertiesdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iotdpspropertiesdescription.go new file mode 100644 index 00000000000..2c8b22afa19 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iotdpspropertiesdescription.go @@ -0,0 +1,19 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsPropertiesDescription struct { + AllocationPolicy *AllocationPolicy `json:"allocationPolicy,omitempty"` + AuthorizationPolicies *[]SharedAccessSignatureAuthorizationRuleAccessRightsDescription `json:"authorizationPolicies,omitempty"` + DeviceProvisioningHostName *string `json:"deviceProvisioningHostName,omitempty"` + EnableDataResidency *bool `json:"enableDataResidency,omitempty"` + IPFilterRules *[]IPFilterRule `json:"ipFilterRules,omitempty"` + IdScope *string `json:"idScope,omitempty"` + IotHubs *[]IotHubDefinitionDescription `json:"iotHubs,omitempty"` + PrivateEndpointConnections *[]PrivateEndpointConnection `json:"privateEndpointConnections,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + PublicNetworkAccess *PublicNetworkAccess `json:"publicNetworkAccess,omitempty"` + ServiceOperationsHostName *string `json:"serviceOperationsHostName,omitempty"` + State *State `json:"state,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iotdpsskuinfo.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iotdpsskuinfo.go new file mode 100644 index 00000000000..352b16a48ec --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iotdpsskuinfo.go @@ -0,0 +1,10 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotDpsSkuInfo struct { + Capacity *int64 `json:"capacity,omitempty"` + Name *IotDpsSku `json:"name,omitempty"` + Tier *string `json:"tier,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iothubdefinitiondescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iothubdefinitiondescription.go new file mode 100644 index 00000000000..b5ff6a45b7b --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_iothubdefinitiondescription.go @@ -0,0 +1,12 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IotHubDefinitionDescription struct { + AllocationWeight *int64 `json:"allocationWeight,omitempty"` + ApplyAllocationPolicy *bool `json:"applyAllocationPolicy,omitempty"` + ConnectionString string `json:"connectionString"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_ipfilterrule.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_ipfilterrule.go new file mode 100644 index 00000000000..675d5261b2c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_ipfilterrule.go @@ -0,0 +1,11 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type IPFilterRule struct { + Action IPFilterActionType `json:"action"` + FilterName string `json:"filterName"` + IPMask string `json:"ipMask"` + Target *IPFilterTargetType `json:"target,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpoint.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpoint.go new file mode 100644 index 00000000000..9debd27fc1a --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpoint.go @@ -0,0 +1,8 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpoint struct { + Id *string `json:"id,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpointconnection.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpointconnection.go new file mode 100644 index 00000000000..06b7e7528f1 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpointconnection.go @@ -0,0 +1,16 @@ +package put + +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 PrivateEndpointConnection struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties PrivateEndpointConnectionProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpointconnectionproperties.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpointconnectionproperties.go new file mode 100644 index 00000000000..44ca081312c --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privateendpointconnectionproperties.go @@ -0,0 +1,9 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateEndpointConnectionProperties struct { + PrivateEndpoint *PrivateEndpoint `json:"privateEndpoint,omitempty"` + PrivateLinkServiceConnectionState PrivateLinkServiceConnectionState `json:"privateLinkServiceConnectionState"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privatelinkserviceconnectionstate.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privatelinkserviceconnectionstate.go new file mode 100644 index 00000000000..a02370e4a5f --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_privatelinkserviceconnectionstate.go @@ -0,0 +1,10 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PrivateLinkServiceConnectionState struct { + ActionsRequired *string `json:"actionsRequired,omitempty"` + Description string `json:"description"` + Status PrivateLinkServiceConnectionStatus `json:"status"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_provisioningservicedescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_provisioningservicedescription.go new file mode 100644 index 00000000000..796fed7928e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_provisioningservicedescription.go @@ -0,0 +1,20 @@ +package put + +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 ProvisioningServiceDescription struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties IotDpsPropertiesDescription `json:"properties"` + Sku IotDpsSkuInfo `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go new file mode 100644 index 00000000000..451b157379e --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/model_sharedaccesssignatureauthorizationruleaccessrightsdescription.go @@ -0,0 +1,11 @@ +package put + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SharedAccessSignatureAuthorizationRuleAccessRightsDescription struct { + KeyName string `json:"keyName"` + PrimaryKey *string `json:"primaryKey,omitempty"` + Rights AccessRightsDescription `json:"rights"` + SecondaryKey *string `json:"secondaryKey,omitempty"` +} diff --git a/resource-manager/deviceprovisioningservices/2022-02-05/put/version.go b/resource-manager/deviceprovisioningservices/2022-02-05/put/version.go new file mode 100644 index 00000000000..b24c2ee0236 --- /dev/null +++ b/resource-manager/deviceprovisioningservices/2022-02-05/put/version.go @@ -0,0 +1,12 @@ +package put + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2022-02-05" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/put/%s", defaultApiVersion) +}