-
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.
ARO-4373 generate keypair and oidc docs for miwi clusters
- Loading branch information
1 parent
e575cff
commit 021d669
Showing
15 changed files
with
641 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
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
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
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
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,8 @@ | ||
package azblob | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:generate rm -rf ../mocks/$GOPACKAGE | ||
//go:generate go run ../../../vendor/github.com/golang/mock/mockgen -destination=../mocks/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/$GOPACKAGE Manager | ||
//go:generate go run ../../../vendor/golang.org/x/tools/cmd/goimports -local=github.com/Azure/ARO-RP -e -w ../mocks/$GOPACKAGE/$GOPACKAGE.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,102 @@ | ||
package azblob | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to" | ||
azstorage "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" | ||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" | ||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/bloberror" | ||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob" | ||
|
||
"github.com/Azure/ARO-RP/pkg/env" | ||
"github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/armstorage" | ||
) | ||
|
||
type Manager interface { | ||
CreateBlobContainer(ctx context.Context, resourceGroup string, account string, container string, publicAccess azstorage.PublicAccess) error | ||
DeleteBlobContainer(ctx context.Context, resourceGroupName string, accountName string, containerName string) error | ||
GetAZBlobClient(blobContainerURL string, options *azblob.ClientOptions) (AZBlobClient, error) | ||
} | ||
|
||
type manager struct { | ||
cred azcore.TokenCredential | ||
blobContainer armstorage.BlobContainersClient | ||
} | ||
|
||
func NewManager(env env.Interface, subscriptionID string, credential azcore.TokenCredential) (Manager, error) { | ||
client, err := armstorage.NewBlobContainersClient(env.Environment(), subscriptionID, credential) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &manager{ | ||
cred: credential, | ||
blobContainer: client, | ||
}, nil | ||
} | ||
|
||
func (m *manager) CreateBlobContainer(ctx context.Context, resourceGroup string, accountName string, containerName string, publicAccess azstorage.PublicAccess) error { | ||
needToCreateBlobContainer := false | ||
|
||
_, err := m.blobContainer.Get( | ||
ctx, | ||
resourceGroup, | ||
accountName, | ||
containerName, | ||
&azstorage.BlobContainersClientGetOptions{}, | ||
) | ||
if err != nil { | ||
if !bloberror.HasCode(err, bloberror.ContainerNotFound) { | ||
return err | ||
} | ||
needToCreateBlobContainer = true | ||
} | ||
|
||
if !needToCreateBlobContainer { | ||
return nil | ||
} | ||
|
||
_, err = m.blobContainer.Create( | ||
ctx, | ||
resourceGroup, | ||
accountName, | ||
containerName, | ||
azstorage.BlobContainer{ | ||
ContainerProperties: &azstorage.ContainerProperties{ | ||
PublicAccess: to.Ptr(azstorage.PublicAccessNone), | ||
}, | ||
}, | ||
&azstorage.BlobContainersClientCreateOptions{}, | ||
) | ||
|
||
return err | ||
} | ||
|
||
func (m *manager) DeleteBlobContainer(ctx context.Context, resourceGroupName string, accountName string, containerName string) error { | ||
_, err := m.blobContainer.Delete(ctx, resourceGroupName, accountName, containerName, &azstorage.BlobContainersClientDeleteOptions{}) | ||
return err | ||
} | ||
|
||
type AZBlobClient interface { | ||
UploadBuffer(ctx context.Context, containerName string, blobName string, buffer []byte, o *blockblob.UploadBufferOptions) (blockblob.UploadBufferResponse, error) | ||
} | ||
|
||
type azBlobClient struct { | ||
client *azblob.Client | ||
} | ||
|
||
func (m *manager) GetAZBlobClient(blobContainerURL string, options *azblob.ClientOptions) (AZBlobClient, error) { | ||
client, err := azblob.NewClient(blobContainerURL, m.cred, options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &azBlobClient{client: client}, nil | ||
} | ||
|
||
func (azBlobClient *azBlobClient) UploadBuffer(ctx context.Context, containerName string, blobName string, buffer []byte, o *blockblob.UploadBufferOptions) (blockblob.UploadBufferResponse, error) { | ||
return azBlobClient.client.UploadBuffer(ctx, containerName, blobName, buffer, o) | ||
} |
41 changes: 41 additions & 0 deletions
41
pkg/util/azureclient/azuresdk/armstorage/blobContainers.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,41 @@ | ||
package armstorage | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" | ||
|
||
"github.com/Azure/ARO-RP/pkg/util/azureclient" | ||
) | ||
|
||
// BlobContainersClient is a minimal interface for Azure BlobContainersClient | ||
type BlobContainersClient interface { | ||
Create(ctx context.Context, resourceGroupName string, accountName string, containerName string, blobContainer armstorage.BlobContainer, options *armstorage.BlobContainersClientCreateOptions) (armstorage.BlobContainersClientCreateResponse, error) | ||
Get(ctx context.Context, resourceGroupName string, accountName string, containerName string, options *armstorage.BlobContainersClientGetOptions) (armstorage.BlobContainersClientGetResponse, error) | ||
Delete(ctx context.Context, resourceGroupName string, accountName string, containerName string, options *armstorage.BlobContainersClientDeleteOptions) (armstorage.BlobContainersClientDeleteResponse, error) | ||
} | ||
|
||
type blobContainersClient struct { | ||
*armstorage.BlobContainersClient | ||
} | ||
|
||
var _ BlobContainersClient = &blobContainersClient{} | ||
|
||
// NewBlobContainersClient creates a new BlobContainersClient | ||
func NewBlobContainersClient(environment *azureclient.AROEnvironment, subscriptionID string, credential azcore.TokenCredential) (BlobContainersClient, error) { | ||
options := arm.ClientOptions{ | ||
ClientOptions: azcore.ClientOptions{ | ||
Cloud: environment.Cloud, | ||
}, | ||
} | ||
clientFactory, err := armstorage.NewClientFactory(subscriptionID, credential, &options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &blobContainersClient{BlobContainersClient: clientFactory.NewBlobContainersClient()}, nil | ||
} |
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,8 @@ | ||
package armstorage | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
//go:generate rm -rf ../../../../util/mocks/$GOPACKAGE | ||
//go:generate go run ../../../../../vendor/github.com/golang/mock/mockgen -destination=../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.go github.com/Azure/ARO-RP/pkg/util/azureclient/azuresdk/$GOPACKAGE BlobContainersClient | ||
//go:generate go run ../../../../../vendor/golang.org/x/tools/cmd/goimports -local=github.com/Azure/ARO-RP -e -w ../../../../util/mocks/azureclient/azuresdk/$GOPACKAGE/$GOPACKAGE.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,31 @@ | ||
package storage | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"context" | ||
|
||
mgmtstorage "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage" | ||
"github.com/Azure/go-autorest/autorest" | ||
|
||
"github.com/Azure/ARO-RP/pkg/util/azureclient" | ||
) | ||
|
||
type BlobContainersClient interface { | ||
Get(ctx context.Context, resourceGroupName string, accountName string, containerName string) (mgmtstorage.BlobContainer, error) | ||
Create(ctx context.Context, resourceGroupName string, accountName string, containerName string, blobContainer mgmtstorage.BlobContainer) (mgmtstorage.BlobContainer, error) | ||
Delete(ctx context.Context, resourceGroupName string, accountName string, containerName string) (result autorest.Response, err error) | ||
} | ||
|
||
type blobContainersClient struct { | ||
mgmtstorage.BlobContainersClient | ||
} | ||
|
||
func NewBlobContainersClient(environment *azureclient.AROEnvironment, subscriptionID string, authorizer autorest.Authorizer) *blobContainersClient { | ||
client := mgmtstorage.NewBlobContainersClientWithBaseURI(environment.ResourceManagerEndpoint, subscriptionID) | ||
client.Authorizer = authorizer | ||
return &blobContainersClient{ | ||
BlobContainersClient: client, | ||
} | ||
} |
Oops, something went wrong.