no_creds.go raw

   1  package credentials
   2  
   3  import (
   4  	"context"
   5  
   6  	"google.golang.org/grpc/codes"
   7  	"google.golang.org/grpc/status"
   8  )
   9  
  10  var _ NonExchangeableCredentials = (*NoCredentials)(nil)
  11  
  12  // NoCredentials implements Credentials, it allows to create unauthenticated connections
  13  type NoCredentials struct{}
  14  
  15  // NoAuthentication returns an instance of NoCredentials, allowing the creation of unauthenticated connections.
  16  // Authentication could be added later via injection of gRPC metadata authorization header
  17  func NoAuthentication() *NoCredentials {
  18  	return &NoCredentials{}
  19  }
  20  func (creds *NoCredentials) YandexCloudAPICredentials() {}
  21  
  22  // IAMToken always returns gRPC error with status UNAUTHENTICATED
  23  func (creds *NoCredentials) IAMToken(ctx context.Context) (*CredentialsToken, error) {
  24  	return nil, status.Error(codes.Unauthenticated, "unauthenticated connection")
  25  }
  26