Ejemplo n.º 1
0
// NewAuthorizerStore ...
func NewAuthorizerStore(endpoint string, insecure bool, authorizers ...Authorizer) (*AuthorizerStore, error) {
	endpoint = utils.FormatEndpoint(endpoint)

	client := &http.Client{
		Transport: registry.GetHTTPTransport(insecure),
		Timeout:   30 * time.Second,
	}

	resp, err := client.Get(buildPingURL(endpoint))
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	challenges := ParseChallengeFromResponse(resp)
	return &AuthorizerStore{
		authorizers: authorizers,
		challenges:  challenges,
	}, nil
}
Ejemplo n.º 2
0
// NewStandardTokenAuthorizer returns a standard token authorizer. The authorizer will request a token
// from token server and add it to the origin request
func NewStandardTokenAuthorizer(credential Credential, insecure bool, scopeType, scopeName string, scopeActions ...string) Authorizer {
	authorizer := &standardTokenAuthorizer{
		client: &http.Client{
			Transport: registry.GetHTTPTransport(insecure),
			Timeout:   30 * time.Second,
		},
		credential: credential,
	}

	if len(scopeType) != 0 || len(scopeName) != 0 {
		authorizer.scope = &scope{
			Type:    scopeType,
			Name:    scopeName,
			Actions: scopeActions,
		}
	}

	authorizer.tg = authorizer.generateToken

	return authorizer
}