agent/structs: String format for Intention, used for logging

This commit is contained in:
Mitchell Hashimoto 2018-03-25 15:06:10 -10:00
parent fb7bccc690
commit 6dc2db94ea
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 11 additions and 2 deletions

View File

@ -921,7 +921,7 @@ func (s *HTTPServer) AgentConnectAuthorize(resp http.ResponseWriter, req *http.R
if !ok { if !ok {
return &connectAuthorizeResp{ return &connectAuthorizeResp{
Authorized: false, Authorized: false,
Reason: fmt.Sprintf("Client ID must be a valid SPIFFE service URI"), Reason: "Client ID must be a valid SPIFFE service URI",
}, nil }, nil
} }
@ -951,7 +951,7 @@ func (s *HTTPServer) AgentConnectAuthorize(resp http.ResponseWriter, req *http.R
if auth, ok := uriService.Authorize(ixn); ok { if auth, ok := uriService.Authorize(ixn); ok {
return &connectAuthorizeResp{ return &connectAuthorizeResp{
Authorized: auth, Authorized: auth,
Reason: fmt.Sprintf("Matched intention %s", ixn.ID), Reason: fmt.Sprintf("Matched intention: %s", ixn.String()),
}, nil }, nil
} }
} }

View File

@ -164,6 +164,15 @@ func (x *Intention) GetACLPrefix() (string, bool) {
return x.DestinationName, x.DestinationName != "" return x.DestinationName, x.DestinationName != ""
} }
// String returns a human-friendly string for this intention.
func (x *Intention) String() string {
return fmt.Sprintf("%s %s/%s => %s/%s (ID: %s",
strings.ToUpper(string(x.Action)),
x.SourceNS, x.SourceName,
x.DestinationNS, x.DestinationName,
x.ID)
}
// IntentionAction is the action that the intention represents. This // IntentionAction is the action that the intention represents. This
// can be "allow" or "deny" to whitelist or blacklist intentions. // can be "allow" or "deny" to whitelist or blacklist intentions.
type IntentionAction string type IntentionAction string