"Fossies" - the Fresh Open Source Software Archive

Member "cri-o-1.25.1/vendor/github.com/Azure/azure-sdk-for-go/services/preview/containerregistry/runtime/2019-08-15-preview/containerregistry/accesstokens.go" (7 Oct 2022, 6659 Bytes) of package /linux/misc/cri-o-1.25.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package containerregistry
    2 
    3 // Copyright (c) Microsoft Corporation. All rights reserved.
    4 // Licensed under the MIT License. See License.txt in the project root for license information.
    5 //
    6 // Code generated by Microsoft (R) AutoRest Code Generator.
    7 // Changes may cause incorrect behavior and will be lost if the code is regenerated.
    8 
    9 import (
   10     "context"
   11     "github.com/Azure/go-autorest/autorest"
   12     "github.com/Azure/go-autorest/autorest/azure"
   13     "github.com/Azure/go-autorest/tracing"
   14     "net/http"
   15 )
   16 
   17 // AccessTokensClient is the metadata API definition for the Azure Container Registry runtime
   18 type AccessTokensClient struct {
   19     BaseClient
   20 }
   21 
   22 // NewAccessTokensClient creates an instance of the AccessTokensClient client.
   23 func NewAccessTokensClient(loginURI string) AccessTokensClient {
   24     return AccessTokensClient{New(loginURI)}
   25 }
   26 
   27 // Get exchange ACR Refresh token for an ACR Access Token
   28 // Parameters:
   29 // service - indicates the name of your Azure container registry.
   30 // scope - which is expected to be a valid scope, and can be specified more than once for multiple scope
   31 // requests. You obtained this from the Www-Authenticate response header from the challenge.
   32 // refreshToken - must be a valid ACR refresh token
   33 func (client AccessTokensClient) Get(ctx context.Context, service string, scope string, refreshToken string) (result AccessToken, err error) {
   34     if tracing.IsEnabled() {
   35         ctx = tracing.StartSpan(ctx, fqdn+"/AccessTokensClient.Get")
   36         defer func() {
   37             sc := -1
   38             if result.Response.Response != nil {
   39                 sc = result.Response.Response.StatusCode
   40             }
   41             tracing.EndSpan(ctx, sc, err)
   42         }()
   43     }
   44     req, err := client.GetPreparer(ctx, service, scope, refreshToken)
   45     if err != nil {
   46         err = autorest.NewErrorWithError(err, "containerregistry.AccessTokensClient", "Get", nil, "Failure preparing request")
   47         return
   48     }
   49 
   50     resp, err := client.GetSender(req)
   51     if err != nil {
   52         result.Response = autorest.Response{Response: resp}
   53         err = autorest.NewErrorWithError(err, "containerregistry.AccessTokensClient", "Get", resp, "Failure sending request")
   54         return
   55     }
   56 
   57     result, err = client.GetResponder(resp)
   58     if err != nil {
   59         err = autorest.NewErrorWithError(err, "containerregistry.AccessTokensClient", "Get", resp, "Failure responding to request")
   60         return
   61     }
   62 
   63     return
   64 }
   65 
   66 // GetPreparer prepares the Get request.
   67 func (client AccessTokensClient) GetPreparer(ctx context.Context, service string, scope string, refreshToken string) (*http.Request, error) {
   68     urlParameters := map[string]interface{}{
   69         "url": client.LoginURI,
   70     }
   71 
   72     formDataParameters := map[string]interface{}{
   73         "grant_type":    "refresh_token",
   74         "refresh_token": refreshToken,
   75         "scope":         scope,
   76         "service":       service,
   77     }
   78 
   79     preparer := autorest.CreatePreparer(
   80         autorest.AsPost(),
   81         autorest.WithCustomBaseURL("{url}", urlParameters),
   82         autorest.WithPath("/oauth2/token"),
   83         autorest.WithFormData(autorest.MapToValues(formDataParameters)))
   84     return preparer.Prepare((&http.Request{}).WithContext(ctx))
   85 }
   86 
   87 // GetSender sends the Get request. The method will close the
   88 // http.Response Body if it receives an error.
   89 func (client AccessTokensClient) GetSender(req *http.Request) (*http.Response, error) {
   90     return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   91 }
   92 
   93 // GetResponder handles the response to the Get request. The method always
   94 // closes the http.Response Body.
   95 func (client AccessTokensClient) GetResponder(resp *http.Response) (result AccessToken, err error) {
   96     err = autorest.Respond(
   97         resp,
   98         azure.WithErrorUnlessStatusCode(http.StatusOK),
   99         autorest.ByUnmarshallingJSON(&result),
  100         autorest.ByClosing())
  101     result.Response = autorest.Response{Response: resp}
  102     return
  103 }
  104 
  105 // GetFromLogin exchange Username, Password and Scope an ACR Access Token
  106 // Parameters:
  107 // service - indicates the name of your Azure container registry.
  108 // scope - expected to be a valid scope, and can be specified more than once for multiple scope requests. You
  109 // can obtain this from the Www-Authenticate response header from the challenge.
  110 func (client AccessTokensClient) GetFromLogin(ctx context.Context, service string, scope string) (result AccessToken, err error) {
  111     if tracing.IsEnabled() {
  112         ctx = tracing.StartSpan(ctx, fqdn+"/AccessTokensClient.GetFromLogin")
  113         defer func() {
  114             sc := -1
  115             if result.Response.Response != nil {
  116                 sc = result.Response.Response.StatusCode
  117             }
  118             tracing.EndSpan(ctx, sc, err)
  119         }()
  120     }
  121     req, err := client.GetFromLoginPreparer(ctx, service, scope)
  122     if err != nil {
  123         err = autorest.NewErrorWithError(err, "containerregistry.AccessTokensClient", "GetFromLogin", nil, "Failure preparing request")
  124         return
  125     }
  126 
  127     resp, err := client.GetFromLoginSender(req)
  128     if err != nil {
  129         result.Response = autorest.Response{Response: resp}
  130         err = autorest.NewErrorWithError(err, "containerregistry.AccessTokensClient", "GetFromLogin", resp, "Failure sending request")
  131         return
  132     }
  133 
  134     result, err = client.GetFromLoginResponder(resp)
  135     if err != nil {
  136         err = autorest.NewErrorWithError(err, "containerregistry.AccessTokensClient", "GetFromLogin", resp, "Failure responding to request")
  137         return
  138     }
  139 
  140     return
  141 }
  142 
  143 // GetFromLoginPreparer prepares the GetFromLogin request.
  144 func (client AccessTokensClient) GetFromLoginPreparer(ctx context.Context, service string, scope string) (*http.Request, error) {
  145     urlParameters := map[string]interface{}{
  146         "url": client.LoginURI,
  147     }
  148 
  149     queryParameters := map[string]interface{}{
  150         "scope":   autorest.Encode("query", scope),
  151         "service": autorest.Encode("query", service),
  152     }
  153 
  154     preparer := autorest.CreatePreparer(
  155         autorest.AsGet(),
  156         autorest.WithCustomBaseURL("{url}", urlParameters),
  157         autorest.WithPath("/oauth2/token"),
  158         autorest.WithQueryParameters(queryParameters))
  159     return preparer.Prepare((&http.Request{}).WithContext(ctx))
  160 }
  161 
  162 // GetFromLoginSender sends the GetFromLogin request. The method will close the
  163 // http.Response Body if it receives an error.
  164 func (client AccessTokensClient) GetFromLoginSender(req *http.Request) (*http.Response, error) {
  165     return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
  166 }
  167 
  168 // GetFromLoginResponder handles the response to the GetFromLogin request. The method always
  169 // closes the http.Response Body.
  170 func (client AccessTokensClient) GetFromLoginResponder(resp *http.Response) (result AccessToken, err error) {
  171     err = autorest.Respond(
  172         resp,
  173         azure.WithErrorUnlessStatusCode(http.StatusOK),
  174         autorest.ByUnmarshallingJSON(&result),
  175         autorest.ByClosing())
  176     result.Response = autorest.Response{Response: resp}
  177     return
  178 }