-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
pkg/util/azureclient/azuresdk/armnetwork/securitygroups.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package armnetwork | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2" | ||
|
||
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/azcore" | ||
) | ||
|
||
// SecurityGroupsClient is a minimal interface for azure SecurityGroupsClient | ||
type SecurityGroupsClient interface { | ||
Get(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *armnetwork.SecurityGroupsClientGetOptions) (armnetwork.SecurityGroupsClientGetResponse, error) | ||
SecurityGroupsClientAddons | ||
} | ||
|
||
type securityGroupsClient struct { | ||
*armnetwork.SecurityGroupsClient | ||
} | ||
|
||
// NewSecurityGroupsClient creates a new SecurityGroupsClient | ||
func NewSecurityGroupsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (SecurityGroupsClient, error) { | ||
clientFactory, err := armnetwork.NewClientFactory(subscriptionID, credential, options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &securityGroupsClient{SecurityGroupsClient: clientFactory.NewSecurityGroupsClient()}, nil | ||
} |
48 changes: 48 additions & 0 deletions
48
pkg/util/azureclient/azuresdk/armnetwork/securitygroups_addons.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package armnetwork | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v2" | ||
) | ||
|
||
// SecurityGroupsClientAddons contains addons for SecurityGroupsClient | ||
type SecurityGroupsClientAddons interface { | ||
CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters armnetwork.SecurityGroup, options *armnetwork.SecurityGroupsClientBeginCreateOrUpdateOptions) error | ||
DeleteAndWait(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *armnetwork.SecurityGroupsClientBeginDeleteOptions) error | ||
List(ctx context.Context, resourceGroupName string, options *armnetwork.SecurityGroupsClientListOptions) ([]*armnetwork.SecurityGroup, error) | ||
} | ||
|
||
func (c *securityGroupsClient) CreateOrUpdateAndWait(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, parameters armnetwork.SecurityGroup, options *armnetwork.SecurityGroupsClientBeginCreateOrUpdateOptions) error { | ||
poller, err := c.SecurityGroupsClient.BeginCreateOrUpdate(ctx, resourceGroupName, networkSecurityGroupName, parameters, options) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = poller.PollUntilDone(ctx, nil) | ||
return err | ||
} | ||
|
||
func (c *securityGroupsClient) DeleteAndWait(ctx context.Context, resourceGroupName string, networkSecurityGroupName string, options *armnetwork.SecurityGroupsClientBeginDeleteOptions) error { | ||
poller, err := c.SecurityGroupsClient.BeginDelete(ctx, resourceGroupName, networkSecurityGroupName, options) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = poller.PollUntilDone(ctx, nil) | ||
return err | ||
} | ||
|
||
func (c *securityGroupsClient) List(ctx context.Context, resourceGroupName string, options *armnetwork.SecurityGroupsClientListOptions) (result []*armnetwork.SecurityGroup, err error) { | ||
pager := c.SecurityGroupsClient.NewListPager(resourceGroupName, options) | ||
|
||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
result = append(result, page.Value...) | ||
} | ||
return result, nil | ||
} |