Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-1493: Added support for permissions #142

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions client/permission.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package client

import (
"fmt"

clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1"
"github.com/spectrocloud/palette-sdk-go/api/models"
)

// PermissionScope defines the scope of a permission.
type PermissionScope string

const (
// PermissionScopeProject represents a project-level scope.
PermissionScopeProject PermissionScope = "project"

// PermissionScopeTenant represents a tenant-level scope.
PermissionScopeTenant PermissionScope = "tenant"

// PermissionScopeResource represents a resource-level scope.
PermissionScopeResource PermissionScope = "resource"
)

// GetPermissionByName retrieves an existing permission by name and permissionScope(project, tenant & resource).
func (h *V1Client) GetPermissionByName(permissionName string, permissionScope PermissionScope) (*models.V1Permission, error) {
// ACL scoped to tenant only
permScope := string(permissionScope)
params := clientv1.NewV1PermissionsListParams().WithScope(&permScope)
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)
}
Loading