|
|
|
@ -123,9 +123,9 @@ func (l *localState) isPaused() bool {
|
|
|
|
|
return atomic.LoadInt32(&l.paused) == 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddServiceToken configures the provided token for the service ID.
|
|
|
|
|
// SetServiceToken configures the provided token for the service ID.
|
|
|
|
|
// The token will be used to perform service registration operations.
|
|
|
|
|
func (l *localState) AddServiceToken(id, token string) {
|
|
|
|
|
func (l *localState) SetServiceToken(id, token string) {
|
|
|
|
|
l.Lock()
|
|
|
|
|
defer l.Unlock()
|
|
|
|
|
l.serviceTokens[id] = token
|
|
|
|
@ -133,8 +133,14 @@ func (l *localState) AddServiceToken(id, token string) {
|
|
|
|
|
|
|
|
|
|
// ServiceToken returns the configured ACL token for the given
|
|
|
|
|
// service ID. If none is present, the agent's token is returned.
|
|
|
|
|
// Assumes a lock is already established on the state.
|
|
|
|
|
func (l *localState) ServiceToken(id string) string {
|
|
|
|
|
l.RLock()
|
|
|
|
|
defer l.RUnlock()
|
|
|
|
|
return l.serviceToken(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// serviceToken returns an ACL token associated with a service.
|
|
|
|
|
func (l *localState) serviceToken(id string) string {
|
|
|
|
|
token := l.serviceTokens[id]
|
|
|
|
|
if token == "" {
|
|
|
|
|
token = l.config.ACLToken
|
|
|
|
@ -183,18 +189,24 @@ func (l *localState) Services() map[string]*structs.NodeService {
|
|
|
|
|
return services
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddCheckToken is used to configure an ACL token for a specific
|
|
|
|
|
// SetCheckToken is used to configure an ACL token for a specific
|
|
|
|
|
// health check. The token is used during check registration operations.
|
|
|
|
|
func (l *localState) AddCheckToken(id, token string) {
|
|
|
|
|
func (l *localState) SetCheckToken(id, token string) {
|
|
|
|
|
l.Lock()
|
|
|
|
|
defer l.Unlock()
|
|
|
|
|
l.checkTokens[id] = token
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CheckToken is used to return the configured health check token, or
|
|
|
|
|
// if none is configured, the default agent ACL token. Assumes a lock
|
|
|
|
|
// has already been taken on the state.
|
|
|
|
|
// if none is configured, the default agent ACL token.
|
|
|
|
|
func (l *localState) CheckToken(id string) string {
|
|
|
|
|
l.RLock()
|
|
|
|
|
defer l.RUnlock()
|
|
|
|
|
return l.checkToken(id)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// checkToken returns an ACL token associated with a check.
|
|
|
|
|
func (l *localState) checkToken(id string) string {
|
|
|
|
|
token := l.checkTokens[id]
|
|
|
|
|
if token == "" {
|
|
|
|
|
token = l.config.ACLToken
|
|
|
|
@ -482,7 +494,7 @@ func (l *localState) deleteService(id string) error {
|
|
|
|
|
Datacenter: l.config.Datacenter,
|
|
|
|
|
Node: l.config.NodeName,
|
|
|
|
|
ServiceID: id,
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.ServiceToken(id)},
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.serviceToken(id)},
|
|
|
|
|
}
|
|
|
|
|
var out struct{}
|
|
|
|
|
err := l.iface.RPC("Catalog.Deregister", &req, &out)
|
|
|
|
@ -503,7 +515,7 @@ func (l *localState) deleteCheck(id string) error {
|
|
|
|
|
Datacenter: l.config.Datacenter,
|
|
|
|
|
Node: l.config.NodeName,
|
|
|
|
|
CheckID: id,
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.CheckToken(id)},
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.checkToken(id)},
|
|
|
|
|
}
|
|
|
|
|
var out struct{}
|
|
|
|
|
err := l.iface.RPC("Catalog.Deregister", &req, &out)
|
|
|
|
@ -521,7 +533,7 @@ func (l *localState) syncService(id string) error {
|
|
|
|
|
Node: l.config.NodeName,
|
|
|
|
|
Address: l.config.AdvertiseAddr,
|
|
|
|
|
Service: l.services[id],
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.ServiceToken(id)},
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.serviceToken(id)},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the service has associated checks that are out of sync,
|
|
|
|
@ -579,7 +591,7 @@ func (l *localState) syncCheck(id string) error {
|
|
|
|
|
Address: l.config.AdvertiseAddr,
|
|
|
|
|
Service: service,
|
|
|
|
|
Check: l.checks[id],
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.CheckToken(id)},
|
|
|
|
|
WriteRequest: structs.WriteRequest{Token: l.checkToken(id)},
|
|
|
|
|
}
|
|
|
|
|
var out struct{}
|
|
|
|
|
err := l.iface.RPC("Catalog.Register", &req, &out)
|
|
|
|
|