Repository: hashicorp/nomad
File: nomad/structs/consul.go (Go)

Code before:
	"regexp"
)

const (
	// ConsulDefaultCluster is the name used for the Consul cluster that doesn't
	// have a name.
	ConsulDefaultCluster = "default"

	// ConsulServiceIdentityNamePrefix is used in naming identities of consul
	// services
	ConsulServiceIdentityNamePrefix = "consul-service"

	// ConsulTaskIdentityNamePrefix is used in naming identities of consul tasks
	ConsulTaskIdentityNamePrefix = "consul"

	// ConsulWorkloadsDefaultAuthMethodName is the default JWT auth method name
	// that has to be configured in Consul in order to authenticate Nomad
	// services and tasks.
	ConsulWorkloadsDefaultAuthMethodName = "nomad-workloads"
)

type ConsulACLToken struct {
	Cluster  string
	TokenID  string
	ACLToken string
}

// Consul represents optional per-group consul configuration.
type Consul struct {
	// Namespace in which to operate in Consul.
	Namespace string

	// Cluster (by name) to send API requests to
	Cluster string

	// Partition is the Consul admin partition where the workload should
	// run. Note that this should never be defaulted to "default" because
	// non-ENT Consul clusters don't have admin partitions
	Partition string
}

// Copy the Consul block.
func (c *Consul) Copy() *Consul {
	if c == nil {
		return nil
	}
	return &Consul{
		Namespace: c.Namespace,
		Cluster:   c.Cluster,
		Partition: c.Partition,
	}

Review comment (suggestion):
This only exists in the client state and never gets sent over the wire, so I'd probably put this struct in `client/structs`

Also, if we're going to have a struct for writing to the client state db anyways, maybe we should grab the fields we care about from the `consulapi.ACLToken` and put them in this struct? That'll save us from having to JSON encode the ACL token.

Code after:
	"regexp"
)

const (
	// ConsulDefaultCluster is the name used for the Consul cluster that doesn't
	// have a name.
	ConsulDefaultCluster = "default"

	// ConsulServiceIdentityNamePrefix is used in naming identities of consul
	// services
	ConsulServiceIdentityNamePrefix = "consul-service"

	// ConsulTaskIdentityNamePrefix is used in naming identities of consul tasks
	ConsulTaskIdentityNamePrefix = "consul"

	// ConsulWorkloadsDefaultAuthMethodName is the default JWT auth method name
	// that has to be configured in Consul in order to authenticate Nomad
	// services and tasks.
	ConsulWorkloadsDefaultAuthMethodName = "nomad-workloads"
)

// Consul represents optional per-group consul configuration.
type Consul struct {
	// Namespace in which to operate in Consul.
	Namespace string

	// Cluster (by name) to send API requests to
	Cluster string

	// Partition is the Consul admin partition where the workload should
	// run. Note that this should never be defaulted to "default" because
	// non-ENT Consul clusters don't have admin partitions
	Partition string
}

// Copy the Consul block.
func (c *Consul) Copy() *Consul {
	if c == nil {
		return nil
	}
	return &Consul{
		Namespace: c.Namespace,
		Cluster:   c.Cluster,
		Partition: c.Partition,
	}
}

// Equal returns whether c and o are the same.
func (c *Consul) Equal(o *Consul) bool {
	if c == nil || o == nil {
		return c == o