MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / curl

Function curl

cmd/cloudflared/access/cmd.go:295–344  ·  view source on GitHub ↗

curl provides a wrapper around curl, passing Access JWT along in request

(c *cli.Context)

Source from the content-addressed store, hash-verified

293
294// curl provides a wrapper around curl, passing Access JWT along in request
295func curl(c *cli.Context) error {
296 err := sentry.Init(sentry.ClientOptions{
297 Dsn: sentryDSN,
298 Release: c.App.Version,
299 })
300 if err != nil {
301 return err
302 }
303 log := logger.CreateLoggerFromContext(c, logger.EnableTerminalLog)
304
305 args := c.Args()
306 if args.Len() < 1 {
307 log.Error().Msg("Please provide the access app and command you wish to run.")
308 return errors.New("incorrect args")
309 }
310
311 cmdArgs, allowRequest := parseAllowRequest(args.Slice())
312 appURL, err := getAppURL(cmdArgs, log)
313 if err != nil {
314 return err
315 }
316
317 appInfo, err := token.GetAppInfo(appURL)
318 if err != nil {
319 return err
320 }
321
322 // Verify that the existing token is still good; if not fetch a new one
323 if err := verifyTokenAtEdge(appURL, appInfo, c, log); err != nil {
324 log.Err(err).Msg("Could not verify token")
325 return err
326 }
327
328 tok, err := token.GetAppTokenIfExists(appInfo)
329 if err != nil || tok == "" {
330 if allowRequest {
331 log.Info().Msg("You don't have an Access token set. Please run access token <access application> to fetch one.")
332 return run("curl", cmdArgs...)
333 }
334 tok, err = token.FetchToken(appURL, appInfo, c.Bool(cfdflags.AutoCloseInterstitial), c.Bool(fedrampFlag), log)
335 if err != nil {
336 log.Err(err).Msg("Failed to refresh token")
337 return err
338 }
339 }
340
341 cmdArgs = append(cmdArgs, "-H")
342 cmdArgs = append(cmdArgs, fmt.Sprintf("%s: %s", carrier.CFAccessTokenHeader, tok))
343 return run("curl", cmdArgs...)
344}
345
346// run kicks off a shell task and pipe the results to the respective std pipes
347func run(cmd string, args ...string) error {

Callers

nothing calls this directly

Calls 12

CreateLoggerFromContextFunction · 0.92
GetAppInfoFunction · 0.92
GetAppTokenIfExistsFunction · 0.92
FetchTokenFunction · 0.92
parseAllowRequestFunction · 0.85
getAppURLFunction · 0.85
verifyTokenAtEdgeFunction · 0.85
runFunction · 0.85
LenMethod · 0.80
BoolMethod · 0.80
ErrorMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected