-
Notifications
You must be signed in to change notification settings - Fork 119
Adding Providers details for env show command with --preview flag #10925
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,15 @@ type EnvRecipes struct { | |||||||||||||||||||||
| RecipeLocation string | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // EnvProviders represents a provider and its properties for an environment. | ||||||||||||||||||||||
| type EnvProviders struct { | ||||||||||||||||||||||
| // Provider is the type of the provider (e.g., "azure", "aws", "kubernetes"). | ||||||||||||||||||||||
| Provider string | ||||||||||||||||||||||
| // Properties contains the provider details in a comma-separated key-value format. | ||||||||||||||||||||||
| // e.g., "subscriptionId: 'sub-id', resourceGroupName: 'rg-name'" for azure provider." | ||||||||||||||||||||||
| Properties string | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Runner is the runner implementation for the `rad env show` preview command. | ||||||||||||||||||||||
| type Runner struct { | ||||||||||||||||||||||
| ConfigHolder *framework.ConfigHolder | ||||||||||||||||||||||
|
|
@@ -136,6 +145,32 @@ func (r *Runner) Run(ctx context.Context) error { | |||||||||||||||||||||
| return err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| envProviders := []EnvProviders{} | ||||||||||||||||||||||
| if resp.EnvironmentResource.Properties.Providers != nil { | ||||||||||||||||||||||
| if resp.EnvironmentResource.Properties.Providers.Azure != nil { | ||||||||||||||||||||||
| azureProvider := EnvProviders{ | ||||||||||||||||||||||
| Provider: "azure", | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| azureProvider.Properties = "subscriptionId: '" + *resp.EnvironmentResource.Properties.Providers.Azure.SubscriptionID + "', resourceGroupName: '" + *resp.EnvironmentResource.Properties.Providers.Azure.ResourceGroupName + "'" | ||||||||||||||||||||||
|
||||||||||||||||||||||
| envProviders = append(envProviders, azureProvider) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if resp.EnvironmentResource.Properties.Providers.Aws != nil { | ||||||||||||||||||||||
| awsProvider := EnvProviders{ | ||||||||||||||||||||||
| Provider: "aws", | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| awsProvider.Properties = "accountId: '" + *resp.EnvironmentResource.Properties.Providers.Aws.AccountID + "', region: '" + *resp.EnvironmentResource.Properties.Providers.Aws.Region + "'" | ||||||||||||||||||||||
|
||||||||||||||||||||||
| awsProvider.Properties = "accountId: '" + *resp.EnvironmentResource.Properties.Providers.Aws.AccountID + "', region: '" + *resp.EnvironmentResource.Properties.Providers.Aws.Region + "'" | |
| accountID := "" | |
| if resp.EnvironmentResource.Properties.Providers.Aws.AccountID != nil { | |
| accountID = *resp.EnvironmentResource.Properties.Providers.Aws.AccountID | |
| } | |
| region := "" | |
| if resp.EnvironmentResource.Properties.Providers.Aws.Region != nil { | |
| region = *resp.EnvironmentResource.Properties.Providers.Aws.Region | |
| } | |
| awsProvider.Properties = "accountId: '" + accountID + "', region: '" + region + "'" |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using direct string concatenation with the + operator. For better performance and idiomatic Go code, use strings.Builder or fmt.Sprintf when building strings from multiple parts. This is particularly important since this code constructs display strings for potentially multiple providers.
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential nil pointer dereference when accessing Kubernetes Namespace field. If the Namespace field is nil, dereferencing will cause a panic. Add nil checks before dereferencing this pointer or use helper functions to safely access pointer values.
| k8sProvider.Properties = "namespace: '" + *resp.EnvironmentResource.Properties.Providers.Kubernetes.Namespace + "'" | |
| namespace := "" | |
| if resp.EnvironmentResource.Properties.Providers.Kubernetes.Namespace != nil { | |
| namespace = *resp.EnvironmentResource.Properties.Providers.Kubernetes.Namespace | |
| } | |
| k8sProvider.Properties = "namespace: '" + namespace + "'" |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using direct string concatenation with the + operator. For better performance and idiomatic Go code, use strings.Builder or fmt.Sprintf when building strings from multiple parts. This is particularly important since this code constructs display strings for potentially multiple providers.
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provider formatting logic is repetitive and could be refactored into a helper function to reduce code duplication. Consider extracting a function that takes provider type, field names, and values to construct the Properties string. This would make the code more maintainable and reduce the risk of inconsistent formatting across providers.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,13 +118,47 @@ func Test_Run(t *testing.T) { | |
| RecipePacks: []*string{ | ||
| to.Ptr("/planes/radius/local/resourceGroups/test-group/providers/Radius.Core/recipePacks/test-recipe-pack"), | ||
| }, | ||
| Providers: &corerpv20250801.Providers{ | ||
| Azure: &corerpv20250801.ProvidersAzure{ | ||
| SubscriptionID: to.Ptr("test-subscription-id"), | ||
| ResourceGroupName: to.Ptr("test-resource-group"), | ||
| }, | ||
| Aws: &corerpv20250801.ProvidersAws{ | ||
| AccountID: to.Ptr("test-account-id"), | ||
| Region: to.Ptr("test-region"), | ||
| }, | ||
| Kubernetes: &corerpv20250801.ProvidersKubernetes{ | ||
| Namespace: to.Ptr("test-namespace"), | ||
| }, | ||
| }, | ||
|
Comment on lines
+121
to
+133
|
||
| }, | ||
| }, | ||
| Options: objectformats.GetResourceTableFormat(), | ||
| }, | ||
| output.LogOutput{ | ||
| Format: "", | ||
| }, | ||
| output.FormattedOutput{ | ||
| Format: "table", | ||
| Obj: []EnvProviders{ | ||
| { | ||
| Provider: "azure", | ||
| Properties: "subscriptionId: 'test-subscription-id', resourceGroupName: 'test-resource-group'", | ||
| }, | ||
| { | ||
| Provider: "aws", | ||
| Properties: "accountId: 'test-account-id', region: 'test-region'", | ||
| }, | ||
| { | ||
| Provider: "kubernetes", | ||
| Properties: "namespace: 'test-namespace'", | ||
| }, | ||
| }, | ||
| Options: objectformats.GetProvidersForEnvironmentTableFormat(), | ||
| }, | ||
| output.LogOutput{ | ||
| Format: "", | ||
| }, | ||
| output.FormattedOutput{ | ||
| Format: "table", | ||
| Obj: []EnvRecipes{ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,7 +169,7 @@ func getConfigurationV20250801(environment *v20250801preview.EnvironmentResource | |
| } | ||
| if envDatamodel.Properties.Providers.AWS != nil { | ||
| config.Providers.AWS = datamodel.ProvidersAWS{ | ||
| Scope: envDatamodel.Properties.Providers.AWS.Scope, | ||
| Scope: "/planes/aws/aws/accounts/" + envDatamodel.Properties.Providers.AWS.AccountID + "/regions/" + envDatamodel.Properties.Providers.AWS.Region, | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an extra period at the end of the example comment that should be removed for consistency with other comment lines.