Skip to content

Commit

Permalink
Return manager ID and hub clusterID for client org (#601)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha authored Oct 18, 2024
1 parent d17de31 commit 1cff94d
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 128 deletions.
27 changes: 18 additions & 9 deletions api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,28 @@ const (
)

type ClusterMetadata struct {
UID string `json:"uid" protobuf:"bytes,1,opt,name=uid"`
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
DisplayName string `json:"displayName,omitempty" protobuf:"bytes,3,opt,name=displayName"`
Provider HostingProvider `json:"provider,omitempty" protobuf:"bytes,4,opt,name=provider,casttype=HostingProvider"`
OwnerID string `json:"ownerID,omitempty" protobuf:"bytes,5,opt,name=ownerID"`
OwnerType string `json:"ownerType,omitempty" protobuf:"bytes,6,opt,name=ownerType"`
APIEndpoint string `json:"apiEndpoint,omitempty" protobuf:"bytes,7,opt,name=apiEndpoint"`
CABundle string `json:"caBundle,omitempty" protobuf:"bytes,8,opt,name=caBundle"`
UID string `json:"uid" protobuf:"bytes,1,opt,name=uid"`
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
DisplayName string `json:"displayName,omitempty" protobuf:"bytes,3,opt,name=displayName"`
Provider HostingProvider `json:"provider,omitempty" protobuf:"bytes,4,opt,name=provider,casttype=HostingProvider"`
OwnerID string `json:"ownerID,omitempty" protobuf:"bytes,5,opt,name=ownerID"`
OwnerType string `json:"ownerType,omitempty" protobuf:"bytes,6,opt,name=ownerType"`
APIEndpoint string `json:"apiEndpoint,omitempty" protobuf:"bytes,7,opt,name=apiEndpoint"`
CABundle string `json:"caBundle,omitempty" protobuf:"bytes,8,opt,name=caBundle"`
ManagerID string `json:"managerID,omitempty" protobuf:"bytes,9,opt,name=managerID"`
HubClusterID string `json:"hubClusterID,omitempty" protobuf:"bytes,10,opt,name=hubClusterID"`
}

func (md ClusterMetadata) Manager() string {
if md.ManagerID != "" && md.ManagerID != "0" {
return md.ManagerID
}
return md.OwnerID
}

func (md ClusterMetadata) State() string {
hasher := hmac.New(sha256.New, []byte(md.UID))
state := fmt.Sprintf("%s,%s", md.APIEndpoint, md.OwnerID)
state := fmt.Sprintf("%s,%s", md.APIEndpoint, md.Manager())
hasher.Write([]byte(state))
return base64.URLEncoding.EncodeToString(hasher.Sum(nil))
}
Expand Down
Loading

0 comments on commit 1cff94d

Please sign in to comment.