github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/client/consul/identities.go (about)

     1  package consul
     2  
     3  import (
     4  	"github.com/hashicorp/go-hclog"
     5  	"github.com/hashicorp/nomad/nomad/structs"
     6  )
     7  
     8  // Implementation of ServiceIdentityAPI used to interact with Nomad Server from
     9  // Nomad Client for acquiring Consul Service Identity tokens.
    10  //
    11  // This client is split from the other consul client(s) to avoid a circular
    12  // dependency between themselves and client.Client
    13  type identitiesClient struct {
    14  	tokenDeriver TokenDeriverFunc
    15  	logger       hclog.Logger
    16  }
    17  
    18  func NewIdentitiesClient(logger hclog.Logger, tokenDeriver TokenDeriverFunc) *identitiesClient {
    19  	return &identitiesClient{
    20  		tokenDeriver: tokenDeriver,
    21  		logger:       logger,
    22  	}
    23  }
    24  
    25  func (c *identitiesClient) DeriveSITokens(alloc *structs.Allocation, tasks []string) (map[string]string, error) {
    26  	tokens, err := c.tokenDeriver(alloc, tasks)
    27  	if err != nil {
    28  		c.logger.Error("error deriving SI token", "error", err, "alloc_id", alloc.ID, "task_names", tasks)
    29  		return nil, err
    30  	}
    31  	return tokens, nil
    32  }