Skip to content

Commit

Permalink
fix: overwrite org id if already set (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
livio-a authored Sep 13, 2023
1 parent dfb7673 commit 5ed3b56
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/client/middleware/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ type OrgInterceptor struct {
orgID string
}

//NewOrgInterceptor statically set the organisation context for every call
// NewOrgInterceptor statically set the organisation context for every call
//
//If you need to switch between multiple organisations for different requests, use the SetOrgID function
//directly on your calls (see example/mgmt/mgmt.go)
// If you need to switch between multiple organisations for different requests, use the SetOrgID function
// directly on your calls (see example/mgmt/mgmt.go)
func NewOrgInterceptor(orgID string) *OrgInterceptor {
return &OrgInterceptor{
orgID: orgID,
Expand All @@ -35,7 +35,12 @@ func (interceptor *OrgInterceptor) Stream() grpc.StreamClientInterceptor {
}
}

//SetOrgID passes the orgID used for the organization context (where the api calls are executed)
// SetOrgID passes the orgID used for the organization context (where the api calls are executed)
func SetOrgID(ctx context.Context, orgID string) context.Context {
return metadata.AppendToOutgoingContext(ctx, client.OrgHeader, orgID)
md, ok := metadata.FromOutgoingContext(ctx)
if !ok {
return metadata.AppendToOutgoingContext(ctx, client.OrgHeader, orgID)
}
md.Set(client.OrgHeader, orgID)
return metadata.NewOutgoingContext(ctx, md)
}

0 comments on commit 5ed3b56

Please sign in to comment.