MCPcopy
hub / github.com/netbirdio/netbird / get

Method get

management/server/idp/azure.go:396–436  ·  view source on GitHub ↗

get perform Get requests.

(ctx context.Context, resource string, q url.Values)

Source from the content-addressed store, hash-verified

394
395// get perform Get requests.
396func (am *AzureManager) get(ctx context.Context, resource string, q url.Values) ([]byte, error) {
397 jwtToken, err := am.credentials.Authenticate(ctx)
398 if err != nil {
399 return nil, err
400 }
401
402 var reqURL string
403 if strings.HasPrefix(resource, "https") {
404 // Already an absolute URL for paging
405 reqURL = resource
406 } else {
407 reqURL = fmt.Sprintf("%s/%s?%s", am.GraphAPIEndpoint, resource, q.Encode())
408 }
409
410 req, err := http.NewRequest(http.MethodGet, reqURL, nil)
411 if err != nil {
412 return nil, err
413 }
414 req.Header.Add("authorization", "Bearer "+jwtToken.AccessToken)
415 req.Header.Add("content-type", "application/json")
416
417 resp, err := am.httpClient.Do(req)
418 if err != nil {
419 if am.appMetrics != nil {
420 am.appMetrics.IDPMetrics().CountRequestError()
421 }
422
423 return nil, err
424 }
425 defer resp.Body.Close()
426
427 if resp.StatusCode != http.StatusOK {
428 if am.appMetrics != nil {
429 am.appMetrics.IDPMetrics().CountRequestStatusError()
430 }
431
432 return nil, fmt.Errorf("unable to get %s, statusCode %d", reqURL, resp.StatusCode)
433 }
434
435 return io.ReadAll(resp.Body)
436}
437
438// userData construct user data from keycloak profile.
439func (ap azureProfile) userData() *UserData {

Callers 3

GetUserDataByIDMethod · 0.95
GetUserByEmailMethod · 0.95
getAllUsersMethod · 0.95

Calls 9

NewRequestMethod · 0.80
CountRequestErrorMethod · 0.80
ErrorfMethod · 0.80
AuthenticateMethod · 0.65
AddMethod · 0.65
DoMethod · 0.65
IDPMetricsMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected