Enable partition support for peering establishment (#13772)

Prior to this the dialing side of the peering would only ever work within the default partition. This commit allows properly parsing the partition field out of the API struct request body, query param and header.
pull/13773/head
Matt Keeler 2022-07-15 10:07:07 -04:00 committed by GitHub
parent c4e45bc6c8
commit 05b5e7e2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -130,6 +130,14 @@ func (s *HTTPHandlers) PeeringEstablish(resp http.ResponseWriter, req *http.Requ
return nil, HTTPError{StatusCode: http.StatusBadRequest, Reason: "PeeringToken is required in the payload when establishing a peering."}
}
var entMeta acl.EnterpriseMeta
if err := s.parseEntMetaPartition(req, &entMeta); err != nil {
return nil, err
}
if args.Partition == "" {
args.Partition = entMeta.PartitionOrEmpty()
}
out, err := s.agent.rpcClientPeering.Establish(req.Context(), args)
if err != nil {
return nil, err

View File

@ -98,8 +98,10 @@ type PeeringEstablishRequest struct {
PeerName string
// The peering token returned from the peer's GenerateToken endpoint.
PeeringToken string `json:",omitempty"`
Datacenter string `json:",omitempty"`
Token string `json:",omitempty"`
// Partition to be peered.
Partition string `json:",omitempty"`
Datacenter string `json:",omitempty"`
Token string `json:",omitempty"`
// Meta is a mapping of some string value to any other string value
Meta map[string]string `json:",omitempty"`
}

View File

@ -10,6 +10,7 @@ func EstablishRequestToAPI(s *EstablishRequest, t *api.PeeringEstablishRequest)
}
t.PeerName = s.PeerName
t.PeeringToken = s.PeeringToken
t.Partition = s.Partition
t.Datacenter = s.Datacenter
t.Token = s.Token
t.Meta = s.Meta
@ -20,6 +21,7 @@ func EstablishRequestFromAPI(t *api.PeeringEstablishRequest, s *EstablishRequest
}
s.PeerName = t.PeerName
s.PeeringToken = t.PeeringToken
s.Partition = t.Partition
s.Datacenter = t.Datacenter
s.Token = t.Token
s.Meta = t.Meta