Skip to content
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

Add ability to load azd env vars into shell #4078

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/cspell.global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ ignoreWords:
- infradelete
- inputhelper
- ippre
- jmespath
- JOBOBJECT
- kubernetes
- kusto
Expand Down
4 changes: 2 additions & 2 deletions cli/azd/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
"program": "${workspaceFolder}",
"console": "integratedTerminal",
"args": [
"auth", "login"
"env", "list", "-o", "json", "-q", "[?IsDefault].DotEnvPath"
//"pipeline", "config", "--principal-name", "foo", "--provider", "github"
//"package", "api", "--debug"
//"provision"
//"up"
//"env", "new"
],
//"cwd": "~/workspace/cwd/path",
"cwd": "/workspaces/todo-csharp-sql",
// "env": {
// "INT_TAG_VALUE":"1989"
// }
Expand Down
2 changes: 1 addition & 1 deletion cli/azd/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func envActions(root *actions.ActionDescriptor) *actions.ActionDescriptor {
Command: newEnvGetValuesCmd(),
FlagsResolver: newEnvGetValuesFlags,
ActionResolver: newEnvGetValuesAction,
OutputFormats: []output.Format{output.JsonFormat, output.EnvVarsFormat},
OutputFormats: []output.Format{output.JsonFormat, output.EnvVarsFormat, output.ExportFormat},
DefaultFormat: output.EnvVarsFormat,
})

Expand Down
65 changes: 65 additions & 0 deletions cli/azd/cmd/middleware/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package middleware

import (
"context"
"encoding/json"
"fmt"

"github.com/azure/azure-dev/cli/azd/cmd/actions"
"github.com/azure/azure-dev/cli/azd/internal"
"github.com/jmespath/go-jmespath"
)

type QueryMiddleware struct {
global *internal.GlobalCommandOptions
}

func (m *QueryMiddleware) Run(ctx context.Context, next NextFn) (*actions.ActionResult, error) {
// Execute the next middleware or action in the chain
fmt.Println(m.global.Query)
result, err := next(ctx)
if err != nil {
return nil, err
}

if m.global.Query == "" {
return result, nil
}

// Convert the result to JSON
resultJSON, err := json.Marshal(result)
if err != nil {
return nil, fmt.Errorf("marshalling action result: %w", err)
}

// Apply the JMESPath query
var jsonResult interface{}
err = json.Unmarshal(resultJSON, &jsonResult)
if err != nil {
return nil, fmt.Errorf("unmarshalling action result: %w", err)
}

filteredResult, err := jmespath.Search(m.global.Query, jsonResult)
if err != nil {
return nil, fmt.Errorf("applying JMESPath query: %w", err)
}

// Convert the filtered result back to an ActionResult
filteredResultJSON, err := json.Marshal(filteredResult)
if err != nil {
return nil, fmt.Errorf("marshalling filtered result: %w", err)
}

var actionResult actions.ActionResult
err = json.Unmarshal(filteredResultJSON, &actionResult)
if err != nil {
return nil, fmt.Errorf("unmarshalling filtered result: %w", err)
}

return &actionResult, nil
}

// NewQueryMiddleware is the registration function for the QueryMiddleware
func NewQueryMiddleware(global *internal.GlobalCommandOptions) Middleware {
return &QueryMiddleware{global: global}
}
2 changes: 1 addition & 1 deletion cli/azd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func NewRootCmd(
"no-prompt",
false,
"Accepts the default value instead of prompting, or it fails if there is no default.")
rootCmd.PersistentFlags().StringVarP(&opts.Query, "query", "q", "", "Run jmespath query on results")

// The telemetry system is responsible for reading these flags value and using it to configure the telemetry
// system, but we still need to add it to our flag set so that when we parse the command line with Cobra we
Expand Down Expand Up @@ -336,7 +337,6 @@ func NewRootCmd(
UseMiddlewareWhen("telemetry", middleware.NewTelemetryMiddleware, func(descriptor *actions.ActionDescriptor) bool {
return !descriptor.Options.DisableTelemetry
})

// Register common dependencies for the IoC rootContainer
if rootContainer == nil {
rootContainer = ioc.NewNestedContainer(nil)
Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-auth-login.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ Flags
--use-device-code : When true, log in by using a device code instead of a browser.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-auth-logout.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for logout.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-auth.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Flags
-h, --help : Gets help for auth.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Use azd auth [command] --help to view examples and more information about a specific command.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config-get.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for get.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config-list-alpha.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for list-alpha.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Examples
Displays a list of all available features in the alpha stage
Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config-reset.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Flags
-h, --help : Gets help for reset.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config-set.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for set.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config-show.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for show.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config-unset.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for unset.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-config.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ Flags
-h, --help : Gets help for config.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Use azd config [command] --help to view examples and more information about a specific command.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-deploy.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ Flags
-h, --help : Gets help for deploy.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Examples
Deploy all services in the current project to Azure.
Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-down.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ Flags
--purge : Does not require confirmation before it permanently deletes resources that are soft-deleted by default (for example, key vaults).

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Examples
Delete all resources for an application. You will be prompted to confirm your decision.
Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-env-get-value.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Flags
-h, --help : Gets help for get-value.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-env-get-values.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ Flags
-h, --help : Gets help for get-values.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-env-list.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for list.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-env-new.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ Flags
--subscription string : Name or ID of an Azure subscription to use for the new environment

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-env-refresh.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ Flags
--hint string : Hint to help identify the environment to refresh

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
7 changes: 4 additions & 3 deletions cli/azd/cmd/testdata/TestUsage-azd-env-select.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Flags
-h, --help : Gets help for select.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.

Expand Down
20 changes: 20 additions & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-env-set-shell-context.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Set the current environment variables to the shell context.

Usage
azd env set-shell-context [flags]

Flags
--docs : Opens the documentation for azd env set-shell-context in your web browser.
-e, --environment string : The name of the environment to use.
-h, --help : Gets help for set-shell-context.

Global Flags
-C, --cwd string : Sets the current working directory.
--debug : Enables debugging and diagnostics logging.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.
-q, --query string : Run jmespath query on results

Find a bug? Want to let us know how we're doing? Fill out this brief survey: https://aka.ms/azure-dev/hats.


Loading
Loading