MCPcopy
hub / github.com/Azure/aztfexport / subscriptionIdFromCLI

Function subscriptionIdFromCLI

main.go:735–752  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

733}
734
735func subscriptionIdFromCLI() (string, error) {
736 var stderr bytes.Buffer
737 var stdout bytes.Buffer
738 cmd := exec.Command("az", "account", "show", "--output", "json", "--query", "id")
739 cmd.Stderr = &stderr
740 cmd.Stdout = &stdout
741 if err := cmd.Run(); err != nil {
742 err = fmt.Errorf("failed to run azure cli: %v", err)
743 if stdErrStr := stderr.String(); stdErrStr != "" {
744 err = fmt.Errorf("%s: %s", err, strings.TrimSpace(stdErrStr))
745 }
746 return "", err
747 }
748 if stdout.String() == "" {
749 return "", fmt.Errorf("subscription id is not specified")
750 }
751 return strconv.Unquote(strings.TrimSpace(stdout.String()))
752}
753
754func realMain(ctx context.Context, cfg config.Config, batch, mockMeta, plainUI, genMapFile bool, profileType string, effectiveCLI string, tfClientPluginPath string) (result error) {
755 switch strings.ToLower(profileType) {

Callers 1

commandBeforeFuncFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected