-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #298 from NorskHelsenett/feature/move-rorresourceo…
…wner-to-separate-package Feature/move rorresourceowner to separate package
- Loading branch information
Showing
12 changed files
with
91 additions
and
39 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
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
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
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
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
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
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
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,48 @@ | ||
package rorresourceowner | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/NorskHelsenett/ror/pkg/models/aclmodels" | ||
) | ||
|
||
var ( | ||
// aclmodels.ErrInvalidScope is returned when the scope is invalid | ||
ErrInvalidScope = errors.New("invalid scope") | ||
ErrInvalidSubject = errors.New("invalid subject") | ||
) | ||
|
||
// The RorResourceOwnerReference or ownereref references the owner og a resource. | ||
// Its used to chek acl and select resources for valid Scopes. | ||
type RorResourceOwnerReference struct { | ||
Scope aclmodels.Acl2Scope `json:"scope"` // cluster, workspace,... | ||
Subject aclmodels.Acl2Subject `json:"subject"` // ror id eg clusterId or workspaceName | ||
} | ||
|
||
// Validate validates the ResourceOwnerReference | ||
func (r *RorResourceOwnerReference) Validate() (bool, error) { | ||
if r.Scope == "" { | ||
return false, ErrInvalidScope | ||
} | ||
if r.Subject == "" { | ||
return false, ErrInvalidSubject | ||
} | ||
if !r.Scope.IsValid() { | ||
return false, ErrInvalidScope | ||
} | ||
if !r.Subject.HasValidScope(r.Scope) { | ||
return false, ErrInvalidScope | ||
} | ||
return true, nil | ||
} | ||
|
||
func (r RorResourceOwnerReference) String() string { | ||
return string(r.Scope) + ":" + string(r.Subject) | ||
} | ||
|
||
func (r RorResourceOwnerReference) GetQueryParams() map[string]string { | ||
response := make(map[string]string) | ||
response["ownerScope"] = string(r.Scope) | ||
response["ownerSubject"] = string(r.Subject) | ||
return response | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package rortypes | ||
|
||
import ( | ||
"github.com/NorskHelsenett/ror/pkg/models/aclmodels/rorresourceowner" | ||
) | ||
|
||
type ResourceVulnerabilityEvent struct { | ||
Spec ResourceVulnerabilityEventSpec `json:"spec"` | ||
} | ||
|
||
type ResourceVulnerabilityEventSpec struct { | ||
Owner RorResourceOwnerReference `json:"owner"` | ||
Message string `json:"message"` | ||
Owner rorresourceowner.RorResourceOwnerReference `json:"owner"` | ||
Message string `json:"message"` | ||
} |