-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLT-1493: Added support for permissions
- Loading branch information
1 parent
b4855be
commit 8f1212d
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1" | ||
"github.com/spectrocloud/palette-sdk-go/api/models" | ||
) | ||
|
||
// GetPermissionByName retrieves an existing permission by name and permissionScope(project, tenant & resource). | ||
func (h *V1Client) GetPermissionByName(permissionName string, permissionScope string) (*models.V1Permission, error) { | ||
// ACL scoped to tenant only | ||
params := clientv1.NewV1PermissionsListParams().WithScope(&permissionScope) | ||
resp, err := h.Client.V1PermissionsList(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, permission := range resp.Payload { | ||
if permission.Name == permissionName { | ||
return permission, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("permission name '%s' not found in scope '%s'", permissionName, permissionScope) | ||
} |