|
Packit |
63bb0d |
package azblob
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
import (
|
|
Packit |
63bb0d |
"context"
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
"github.com/Azure/azure-pipeline-go/pipeline"
|
|
Packit |
63bb0d |
)
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// Credential represent any credential type; it is used to create a credential policy Factory.
|
|
Packit |
63bb0d |
type Credential interface {
|
|
Packit |
63bb0d |
pipeline.Factory
|
|
Packit |
63bb0d |
credentialMarker()
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
type credentialFunc pipeline.FactoryFunc
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
func (f credentialFunc) New(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.Policy {
|
|
Packit |
63bb0d |
return f(next, po)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// credentialMarker is a package-internal method that exists just to satisfy the Credential interface.
|
|
Packit |
63bb0d |
func (credentialFunc) credentialMarker() {}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
//////////////////////////////
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// NewAnonymousCredential creates an anonymous credential for use with HTTP(S) requests that read public resource
|
|
Packit |
63bb0d |
// or for use with Shared Access Signatures (SAS).
|
|
Packit |
63bb0d |
func NewAnonymousCredential() Credential {
|
|
Packit |
63bb0d |
return anonymousCredentialFactory
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
var anonymousCredentialFactory Credential = &anonymousCredentialPolicyFactory{} // Singleton
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// anonymousCredentialPolicyFactory is the credential's policy factory.
|
|
Packit |
63bb0d |
type anonymousCredentialPolicyFactory struct {
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// New creates a credential policy object.
|
|
Packit |
63bb0d |
func (f *anonymousCredentialPolicyFactory) New(next pipeline.Policy, po *pipeline.PolicyOptions) pipeline.Policy {
|
|
Packit |
63bb0d |
return &anonymousCredentialPolicy{next: next}
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// credentialMarker is a package-internal method that exists just to satisfy the Credential interface.
|
|
Packit |
63bb0d |
func (*anonymousCredentialPolicyFactory) credentialMarker() {}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// anonymousCredentialPolicy is the credential's policy object.
|
|
Packit |
63bb0d |
type anonymousCredentialPolicy struct {
|
|
Packit |
63bb0d |
next pipeline.Policy
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// Do implements the credential's policy interface.
|
|
Packit |
63bb0d |
func (p anonymousCredentialPolicy) Do(ctx context.Context, request pipeline.Request) (pipeline.Response, error) {
|
|
Packit |
63bb0d |
// For anonymous credentials, this is effectively a no-op
|
|
Packit |
63bb0d |
return p.next.Do(ctx, request)
|
|
Packit |
63bb0d |
}
|