Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding shared private link resource for the Azure web pubsub resource #15550

Merged
merged 15 commits into from
Jul 20, 2022
22 changes: 16 additions & 6 deletions internal/services/signalr/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
)

type Client struct {
SignalRClient *signalr.SignalRClient
WebPubsubClient *webpubsub.Client
WebPubsubHubsClient *webpubsub.HubsClient
SignalRClient *signalr.SignalRClient
WebPubsubClient *webpubsub.Client
WebPubsubHubsClient *webpubsub.HubsClient
WebPubsubSharedPrivateLinkResourceClient *webpubsub.SharedPrivateLinkResourcesClient
WebPubsubPrivateLinkedResourceClient *webpubsub.PrivateLinkResourcesClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -22,9 +24,17 @@ func NewClient(o *common.ClientOptions) *Client {
webpubsubHubsClient := webpubsub.NewHubsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&webpubsubHubsClient.Client, o.ResourceManagerAuthorizer)

webPubsubSharedPrivateLinkResourceClient := webpubsub.NewSharedPrivateLinkResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&webPubsubSharedPrivateLinkResourceClient.Client, o.ResourceManagerAuthorizer)

webPubsubPrivateLinkResourceClient := webpubsub.NewPrivateLinkResourcesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&webPubsubPrivateLinkResourceClient.Client, o.ResourceManagerAuthorizer)

return &Client{
SignalRClient: &signalRClient,
WebPubsubClient: &webpubsubClient,
WebPubsubHubsClient: &webpubsubHubsClient,
SignalRClient: &signalRClient,
WebPubsubClient: &webpubsubClient,
WebPubsubHubsClient: &webpubsubHubsClient,
WebPubsubSharedPrivateLinkResourceClient: &webPubsubSharedPrivateLinkResourceClient,
WebPubsubPrivateLinkedResourceClient: &webPubsubPrivateLinkResourceClient,
}
}
4 changes: 2 additions & 2 deletions internal/services/signalr/parse/web_pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (id WebPubsubId) String() string {
}

func (id WebPubsubId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/WebPubSub/%s"
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WebPubSubName)
}

Expand All @@ -57,7 +57,7 @@ func WebPubsubID(input string) (*WebPubsubId, error) {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.WebPubSubName, err = id.PopSegment("WebPubSub"); err != nil {
if resourceId.WebPubSubName, err = id.PopSegment("webPubSub"); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/services/signalr/parse/web_pubsub_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (id WebPubsubHubId) String() string {
}

func (id WebPubsubHubId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/WebPubSub/%s/hubs/%s"
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/hubs/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WebPubSubName, id.HubName)
}

Expand All @@ -60,7 +60,7 @@ func WebPubsubHubID(input string) (*WebPubsubHubId, error) {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.WebPubSubName, err = id.PopSegment("WebPubSub"); err != nil {
if resourceId.WebPubSubName, err = id.PopSegment("webPubSub"); err != nil {
return nil, err
}
if resourceId.HubName, err = id.PopSegment("hubs"); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/services/signalr/parse/web_pubsub_hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ resourceids.Id = WebPubsubHubId{}

func TestWebPubsubHubIDFormatter(t *testing.T) {
actual := NewWebPubsubHubID("12345678-1234-9876-4563-123456789012", "resGroup1", "Webpubsub1", "Webpubsubhub1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1/hubs/Webpubsubhub1"
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/hubs/Webpubsubhub1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
Expand Down Expand Up @@ -63,25 +63,25 @@ func TestWebPubsubHubID(t *testing.T) {

{
// missing value for WebPubSubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/",
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/",
Error: true,
},

{
// missing HubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1/",
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/",
Error: true,
},

{
// missing value for HubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1/hubs/",
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/hubs/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1/hubs/Webpubsubhub1",
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/hubs/Webpubsubhub1",
Expected: &WebPubsubHubId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type WebPubsubSharedPrivateLinkResourceId struct {
SubscriptionId string
ResourceGroup string
WebPubSubName string
SharedPrivateLinkResourceName string
}

func NewWebPubsubSharedPrivateLinkResourceID(subscriptionId, resourceGroup, webPubSubName, sharedPrivateLinkResourceName string) WebPubsubSharedPrivateLinkResourceId {
return WebPubsubSharedPrivateLinkResourceId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
WebPubSubName: webPubSubName,
SharedPrivateLinkResourceName: sharedPrivateLinkResourceName,
}
}

func (id WebPubsubSharedPrivateLinkResourceId) String() string {
segments := []string{
fmt.Sprintf("Shared Private Link Resource Name %q", id.SharedPrivateLinkResourceName),
fmt.Sprintf("Web Pub Sub Name %q", id.WebPubSubName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Web Pubsub Shared Private Link Resource", segmentsStr)
}

func (id WebPubsubSharedPrivateLinkResourceId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.SignalRService/webPubSub/%s/sharedPrivateLinkResources/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WebPubSubName, id.SharedPrivateLinkResourceName)
}

// WebPubsubSharedPrivateLinkResourceID parses a WebPubsubSharedPrivateLinkResource ID into an WebPubsubSharedPrivateLinkResourceId struct
func WebPubsubSharedPrivateLinkResourceID(input string) (*WebPubsubSharedPrivateLinkResourceId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := WebPubsubSharedPrivateLinkResourceId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.WebPubSubName, err = id.PopSegment("webPubSub"); err != nil {
return nil, err
}
if resourceId.SharedPrivateLinkResourceName, err = id.PopSegment("sharedPrivateLinkResources"); err != nil {
return nil, err
}

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

return &resourceId, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.Id = WebPubsubSharedPrivateLinkResourceId{}

func TestWebPubsubSharedPrivateLinkResourceIDFormatter(t *testing.T) {
actual := NewWebPubsubSharedPrivateLinkResourceID("12345678-1234-9876-4563-123456789012", "resGroup1", "Webpubsub1", "resource1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/sharedPrivateLinkResources/resource1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestWebPubsubSharedPrivateLinkResourceID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *WebPubsubSharedPrivateLinkResourceId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing WebPubSubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/",
Error: true,
},

{
// missing value for WebPubSubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/",
Error: true,
},

{
// missing SharedPrivateLinkResourceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/",
Error: true,
},

{
// missing value for SharedPrivateLinkResourceName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/sharedPrivateLinkResources/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/sharedPrivateLinkResources/resource1",
Expected: &WebPubsubSharedPrivateLinkResourceId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
WebPubSubName: "Webpubsub1",
SharedPrivateLinkResourceName: "resource1",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.SIGNALRSERVICE/WEBPUBSUB/WEBPUBSUB1/SHAREDPRIVATELINKRESOURCES/RESOURCE1",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := WebPubsubSharedPrivateLinkResourceID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", 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.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.WebPubSubName != v.Expected.WebPubSubName {
t.Fatalf("Expected %q but got %q for WebPubSubName", v.Expected.WebPubSubName, actual.WebPubSubName)
}
if actual.SharedPrivateLinkResourceName != v.Expected.SharedPrivateLinkResourceName {
t.Fatalf("Expected %q but got %q for SharedPrivateLinkResourceName", v.Expected.SharedPrivateLinkResourceName, actual.SharedPrivateLinkResourceName)
}
}
}
6 changes: 3 additions & 3 deletions internal/services/signalr/parse/web_pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ resourceids.Id = WebPubsubId{}

func TestWebPubsubIDFormatter(t *testing.T) {
actual := NewWebPubsubID("12345678-1234-9876-4563-123456789012", "resGroup1", "Webpubsub1").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1"
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
Expand Down Expand Up @@ -63,13 +63,13 @@ func TestWebPubsubID(t *testing.T) {

{
// missing value for WebPubSubName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/",
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1",
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1",
Expected: &WebPubsubId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "resGroup1",
Expand Down
16 changes: 9 additions & 7 deletions internal/services/signalr/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ func (r Registration) WebsiteCategories() []string {
// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_signalr_service": dataSourceArmSignalRService(),
"azurerm_web_pubsub": dataSourceWebPubsub(),
"azurerm_signalr_service": dataSourceArmSignalRService(),
"azurerm_web_pubsub": dataSourceWebPubsub(),
"azurerm_web_pubsub_private_link_resource": dataSourceWebPubsubPrivateLinkResource(),
}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{
"azurerm_signalr_service": resourceArmSignalRService(),
"azurerm_signalr_service_network_acl": resourceArmSignalRServiceNetworkACL(),
"azurerm_web_pubsub": resourceWebPubSub(),
"azurerm_web_pubsub_hub": resourceWebPubsubHub(),
"azurerm_web_pubsub_network_acl": resourceWebpubsubNetworkACL(),
"azurerm_signalr_service": resourceArmSignalRService(),
"azurerm_signalr_service_network_acl": resourceArmSignalRServiceNetworkACL(),
"azurerm_web_pubsub": resourceWebPubSub(),
"azurerm_web_pubsub_hub": resourceWebPubsubHub(),
"azurerm_web_pubsub_network_acl": resourceWebpubsubNetworkACL(),
"azurerm_web_pubsub_shared_private_link_resource": resourceWebpubsubSharedPrivateLinkService(),
}
}
5 changes: 3 additions & 2 deletions internal/services/signalr/resourceids.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package signalr

//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=WebPubsub -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=WebPubsubHub -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/WebPubSub/Webpubsub1/hubs/Webpubsubhub1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=WebPubsub -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=WebPubsubHub -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/hubs/Webpubsubhub1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=WebPubsubSharedPrivateLinkResource -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.SignalRService/webPubSub/Webpubsub1/sharedPrivateLinkResources/resource1
Loading