github.com/Axway/agent-sdk@v1.1.101/pkg/watchmanager/rpcauth.go (about)

     1  package watchmanager
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type rpcCredential interface {
     8  	GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error)
     9  	RequireTransportSecurity() bool
    10  }
    11  
    12  type rpcAuth struct {
    13  	tenantID    string
    14  	tokenGetter TokenGetter
    15  }
    16  
    17  // newRPCAuth - Create a new RPC authenticator which uses the token getter to fetch token
    18  func newRPCAuth(tenantID string, tokenGetter TokenGetter) rpcCredential {
    19  	auth := rpcAuth{
    20  		tenantID:    tenantID,
    21  		tokenGetter: tokenGetter,
    22  	}
    23  	return auth
    24  }
    25  
    26  // GetRequestMetadata - sets the http header prior to transport
    27  func (t rpcAuth) GetRequestMetadata(_ context.Context, _ ...string) (map[string]string, error) {
    28  	token, err := t.tokenGetter()
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	return map[string]string{
    34  		"x-axway-tenant-id": t.tenantID,
    35  		"authorization":     "Bearer " + token,
    36  	}, nil
    37  }
    38  
    39  // RequireTransportSecurity - leave as false for now
    40  func (rpcAuth) RequireTransportSecurity() bool {
    41  	return false
    42  }