MCPcopy Create free account
hub / github.com/auth0/auth0-cli / apiCmdRun

Function apiCmdRun

internal/cli/api.go:120–195  ·  view source on GitHub ↗
(cli *cli, inputs *apiCmdInputs)

Source from the content-addressed store, hash-verified

118}
119
120func apiCmdRun(cli *cli, inputs *apiCmdInputs) func(cmd *cobra.Command, args []string) error {
121 return func(cmd *cobra.Command, args []string) error {
122 if len(args) == 0 {
123 return cmd.Help()
124 }
125
126 if err := inputs.fromArgs(args, cli.tenant); err != nil {
127 return fmt.Errorf("failed to parse command inputs: %w", err)
128 }
129
130 if inputs.Method == http.MethodDelete && !cli.force && canPrompt(cmd) {
131 message := "Are you sure you want to proceed? Deleting is a destructive action."
132 if confirmed := prompt.Confirm(message); !confirmed {
133 return nil
134 }
135 }
136
137 var response *http.Response
138 if err := ansi.Waiting(func() error {
139 request, err := cli.api.HTTPClient.NewRequest(
140 cmd.Context(),
141 inputs.Method,
142 inputs.URL.String(),
143 inputs.Data,
144 )
145 if err != nil {
146 return err
147 }
148
149 if cli.debug {
150 cli.renderer.Infof("Sending the following request: %+v", map[string]interface{}{
151 "method": request.Method,
152 "url": request.URL.String(),
153 "payload": inputs.Data,
154 })
155 }
156
157 response, err = cli.api.HTTPClient.Do(request)
158 return err
159 }); err != nil {
160 return fmt.Errorf("failed to send request: %w", err)
161 }
162 defer func() {
163 _ = response.Body.Close()
164 }()
165
166 if err := isInsufficientScopeError(response); err != nil {
167 return err
168 }
169
170 rawBodyJSON, err := io.ReadAll(response.Body)
171 if err != nil {
172 return err
173 }
174
175 if response.StatusCode >= http.StatusBadRequest {
176 return newAPIResponseError(response.StatusCode, response.Header, rawBodyJSON)
177 }

Callers 1

apiCmdFunction · 0.85

Calls 13

ConfirmFunction · 0.92
WaitingFunction · 0.92
ColorizeJSONFunction · 0.92
canPromptFunction · 0.85
isInsufficientScopeErrorFunction · 0.85
newAPIResponseErrorFunction · 0.85
ErrorfMethod · 0.80
NewRequestMethod · 0.80
InfofMethod · 0.80
DoMethod · 0.80
CloseMethod · 0.80
OutputMethod · 0.80

Tested by

no test coverage detected