Skip to content

Commit

Permalink
Adding share and unshare cluster methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-px committed Aug 12, 2024
1 parent d83533a commit 0e81a54
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 0 deletions.
35 changes: 35 additions & 0 deletions drivers/backup/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,41 @@ func GetMembersOfGroup(group string) ([]string, error) {
return members, nil
}

// GetMembersOfGroupWithID fetches all available members of the group with groupID
func GetMembersOfGroupWithID(groupID string) ([]string, error) {
fn := "GetMembersOfGroup"
keycloakEndPoint, err := getKeycloakEndPoint(true)
if err != nil {
return nil, err
}

reqURL := fmt.Sprintf("%s/groups/%s/members", keycloakEndPoint, groupID)
method := "GET"
headers, err := GetCommonHTTPHeaders(PxCentralAdminUser, PxCentralAdminPwd)
if err != nil {
log.Errorf("%s: %v", fn, err)
return nil, err
}

response, err := processHTTPRequest(method, reqURL, headers, nil)
if err != nil {
log.Errorf("%s: %v", fn, err)
return nil, err
}
var members []string
var users []KeycloakGroupMemberRepresentation
err = json.Unmarshal(response, &users)
if err != nil {
log.Errorf("%s: %v", fn, err)
return nil, err
}
for _, userName := range users {
members = append(members, userName.Name)
}
log.Debugf("list of members : %v", members)
return members, nil
}

// AddGroup adds a new group
func AddGroup(group string) error {
fn := "AddGroup"
Expand Down
6 changes: 6 additions & 0 deletions drivers/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ type Cluster interface {

// GetClusterStatus returns status of the given cluster name in an organization
GetClusterStatus(orgID string, clusterName string, ctx context.Context) (api.ClusterInfo_StatusInfo_Status, error)

// ShareCluster share the cluster object
ShareCluster(ctx context.Context, req *api.ShareClusterRequest) (*api.ShareClusterResponse, error)

// UnShareCluster unshare the cluster object
UnShareCluster(ctx context.Context, req *api.UnShareClusterRequest) (*api.UnShareClusterResponse, error)
}

// BLocation obj interface
Expand Down
8 changes: 8 additions & 0 deletions drivers/backup/portworx/portworx.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,14 @@ func (p *portworx) GetClusterStatus(orgID string, clusterName string, ctx contex
return api.ClusterInfo_StatusInfo_Invalid, fmt.Errorf("cluster with name '%s' not found for org '%s'", clusterName, orgID)
}

func (p *portworx) ShareCluster(ctx context.Context, req *api.ShareClusterRequest) (*api.ShareClusterResponse, error) {
return p.clusterManager.ShareCluster(ctx, req)
}

func (p *portworx) UnShareCluster(ctx context.Context, req *api.UnShareClusterRequest) (*api.UnShareClusterResponse, error) {
return p.clusterManager.UnShareCluster(ctx, req)
}

// SetMissingClusterUID sets the missing cluster UID for cluster-related requests
func (p *portworx) SetMissingClusterUID(ctx context.Context, req interface{}) (interface{}, error) {
switch r := req.(type) {
Expand Down
Loading

0 comments on commit 0e81a54

Please sign in to comment.