Skip to content

Commit

Permalink
securitygroups
Browse files Browse the repository at this point in the history
  • Loading branch information
bitoku committed Jul 3, 2024
1 parent 032ec5b commit ec2b148
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/util/azureclient/azuresdk/armnetwork/securitygroups.go
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 pkg/util/azureclient/azuresdk/armnetwork/securitygroups_addons.go
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
}

0 comments on commit ec2b148

Please sign in to comment.