-
Notifications
You must be signed in to change notification settings - Fork 341
compose: Add azd add support for storage accounts (blob service)
#4765
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
Merged
JeffreyCA
merged 6 commits into
Azure:main
from
JeffreyCA:jeffreyca/compose/storage-blob
Feb 11, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
71d7d46
Add `azd add` support for storage accounts
JeffreyCA 7e6da4e
Fix RFC 1123 regex to allow one-length character
JeffreyCA b630ebe
Remove KeylessAuth property and prompt
JeffreyCA d8e929e
Update storage account role assignments
JeffreyCA b48141e
Fix test
JeffreyCA 84501cb
Disable storage account key access by default
JeffreyCA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,129 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package add | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/internal/names" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/input" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/output" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/project" | ||
| ) | ||
|
|
||
| const ( | ||
| StorageDataTypeBlob = "Blobs" | ||
| ) | ||
|
|
||
| func allStorageDataTypes() []string { | ||
| return []string{StorageDataTypeBlob} | ||
| } | ||
|
|
||
| func fillStorageDetails( | ||
| ctx context.Context, | ||
| r *project.ResourceConfig, | ||
| console input.Console, | ||
| p PromptOptions) (*project.ResourceConfig, error) { | ||
| if _, exists := p.PrjConfig.Resources["storage"]; exists { | ||
| return nil, fmt.Errorf("only one Storage resource is allowed at this time") | ||
| } | ||
|
|
||
| if r.Name == "" { | ||
| r.Name = "storage" | ||
| } | ||
|
|
||
| modelProps, ok := r.Props.(project.StorageProps) | ||
| if !ok { | ||
| return nil, fmt.Errorf("invalid resource properties") | ||
| } | ||
|
|
||
| selectedDataTypes, err := selectStorageDataTypes(ctx, console) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| for _, option := range selectedDataTypes { | ||
| switch option { | ||
| case StorageDataTypeBlob: | ||
| if err := fillBlobDetails(ctx, console, &modelProps); err != nil { | ||
| return nil, err | ||
| } | ||
| default: | ||
| return nil, fmt.Errorf("unsupported data type: %s", option) | ||
| } | ||
| } | ||
|
|
||
| r.Props = modelProps | ||
| return r, nil | ||
| } | ||
|
|
||
| func selectStorageDataTypes(ctx context.Context, console input.Console) ([]string, error) { | ||
| var selectedDataOptions []string | ||
| for { | ||
| var err error | ||
| selectedDataOptions, err = console.MultiSelect(ctx, input.ConsoleOptions{ | ||
| Message: "What type of data do you want to store?", | ||
| Options: allStorageDataTypes(), | ||
| DefaultValue: []string{StorageDataTypeBlob}, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if len(selectedDataOptions) == 0 { | ||
| console.Message(ctx, output.WithErrorFormat("At least one data type must be selected")) | ||
| continue | ||
| } | ||
| break | ||
| } | ||
| return selectedDataOptions, nil | ||
| } | ||
|
|
||
| func fillBlobDetails(ctx context.Context, console input.Console, modelProps *project.StorageProps) error { | ||
| for { | ||
| containerName, err := console.Prompt(ctx, input.ConsoleOptions{ | ||
| Message: "Input a blob container name to be created:", | ||
| Help: "Blob container name\n\n" + | ||
| "A blob container organizes a set of blobs, similar to a directory in a file system.", | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := validateContainerName(containerName); err != nil { | ||
| console.Message(ctx, err.Error()) | ||
| continue | ||
| } | ||
| modelProps.Containers = append(modelProps.Containers, containerName) | ||
| break | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // validateContainerName validates storage account container names. | ||
| // Reference: | ||
| // https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata | ||
| func validateContainerName(name string) error { | ||
| if len(name) < 3 { | ||
| return errors.New("name must be 3 characters or more") | ||
| } | ||
|
|
||
| if strings.Contains(name, "--") { | ||
| return errors.New("name cannot contain consecutive hyphens") | ||
| } | ||
|
|
||
| if strings.ToLower(name) != name { | ||
| return errors.New("name must be all lower case") | ||
| } | ||
|
|
||
| err := names.ValidateLabelName(name) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.