Skip to content

Commit

Permalink
remove helper methods from policy data types
Browse files Browse the repository at this point in the history
  • Loading branch information
Lodek committed Jun 6, 2024
1 parent dc907a9 commit d5c1de1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
8 changes: 4 additions & 4 deletions acp/source_hub_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ func (a *sourceHubBridge) ValidateResourceExistsOnValidDPI(
policy := maybePolicy.Value()

// So far we validated that the policy exists, now lets validate that resource exists.
resourceResponse := policy.GetResourceByName(resourceName)
if resourceResponse == nil {
resourceResponse, ok := policy.Resources[resourceName]
if !ok {
return newErrResourceDoesNotExistOnTargetPolicy(resourceName, policyID)
}

// Now that we have validated that policyID exists and it contains a corresponding
// resource with the matching name, validate that all required permissions
// for DPI actually exist on the target resource.
for _, requiredPermission := range dpiRequiredPermissions {
permissionResponse := resourceResponse.GetPermissionByName(requiredPermission)
if permissionResponse == nil {
permissionResponse, ok := resourceResponse.Permissions[requiredPermission]
if !ok {
return newErrResourceIsMissingRequiredPermission(
resourceName,
requiredPermission,
Expand Down
10 changes: 0 additions & 10 deletions acp/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,13 @@ type policy struct {
Resources map[string]*resource
}

// GetResourceByName returns a Resource with the given name or nil
func (p *policy) GetResourceByName(name string) *resource {
return p.Resources[name]
}

// resource is a data container carrying the necessary data
// to verify whether it meets DPI requirements.
type resource struct {
Name string
Permissions map[string]*permission
}

// GetPermissionByName returns a permission with the given name or nil
func (r *resource) GetPermissionByName(name string) *permission {
return r.Permissions[name]
}

// permission is a data container carrying the necessary data
// to verify whether it meets DPI requirements.
type permission struct {
Expand Down

0 comments on commit d5c1de1

Please sign in to comment.