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

     1  package consul
     2  
     3  import (
     4  	"github.com/hashicorp/nomad/command/agent/consul"
     5  	"github.com/hashicorp/nomad/nomad/structs"
     6  )
     7  
     8  // ConsulServiceAPI is the interface the Nomad Client uses to register and
     9  // remove services and checks from Consul.
    10  //
    11  // ACL requirements
    12  // - service:write
    13  type ConsulServiceAPI interface {
    14  	// RegisterWorkload with Consul. Adds all service entries and checks to Consul.
    15  	RegisterWorkload(*consul.WorkloadServices) error
    16  
    17  	// RemoveWorkload from Consul. Removes all service entries and checks.
    18  	RemoveWorkload(*consul.WorkloadServices)
    19  
    20  	// UpdateWorkload in Consul. Does not alter the service if only checks have
    21  	// changed.
    22  	UpdateWorkload(old, newTask *consul.WorkloadServices) error
    23  
    24  	// AllocRegistrations returns the registrations for the given allocation.
    25  	AllocRegistrations(allocID string) (*consul.AllocRegistration, error)
    26  
    27  	// UpdateTTL is used to update the TTL of a check.
    28  	UpdateTTL(id, output, status string) error
    29  }
    30  
    31  // TokenDeriverFunc takes an allocation and a set of tasks and derives a
    32  // service identity token for each. Requests go through nomad server.
    33  type TokenDeriverFunc func(*structs.Allocation, []string) (map[string]string, error)
    34  
    35  // ServiceIdentityAPI is the interface the Nomad Client uses to request Consul
    36  // Service Identity tokens through Nomad Server.
    37  //
    38  // ACL requirements
    39  // - acl:write (used by Server only)
    40  type ServiceIdentityAPI interface {
    41  	// DeriveSITokens contacts the nomad server and requests consul service
    42  	// identity tokens be generated for tasks in the allocation.
    43  	DeriveSITokens(alloc *structs.Allocation, tasks []string) (map[string]string, error)
    44  }