-
Notifications
You must be signed in to change notification settings - Fork 27
Modify and Get operations for platform hub policy #407
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
Merged
denys-octopus
merged 3 commits into
mas/add-platform-hub-policies
from
mas/modify-platform-hub-policies
Mar 11, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
pkg/platformhubpolicies/platform_hub_policy_version_service.go
This file contains hidden or 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,96 @@ | ||
| package platformhubpolicies | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/newclient" | ||
| ) | ||
|
|
||
| // PlatformHubPolicyVersion represents an immutable published version of a Platform Hub policy. | ||
| type PlatformHubPolicyVersion struct { | ||
| ID string `json:"Id"` | ||
| Slug string `json:"Slug"` | ||
| Version string `json:"Version"` | ||
| PublishedDate time.Time `json:"PublishedDate"` | ||
| GitRef string `json:"GitRef"` | ||
| GitCommit string `json:"GitCommit"` | ||
| Name string `json:"Name"` | ||
| Description string `json:"Description,omitempty"` | ||
| ViolationReason string `json:"ViolationReason,omitempty"` | ||
| ViolationAction string `json:"ViolationAction"` | ||
| RegoScope string `json:"RegoScope"` | ||
| RegoConditions string `json:"RegoConditions"` | ||
| IsActive bool `json:"IsActive"` | ||
| } | ||
|
|
||
| // Publish publishes a Platform Hub policy version. | ||
| func Publish(client newclient.Client, gitRef string, slug string, version string) (PlatformHubPolicyVersion, error) { | ||
| path, pathError := client.URITemplateCache().Expand("/api/platformhub/{gitRef}/policies/{slug}/publish", map[string]any{"gitRef": gitRef, "slug": slug}) | ||
| if pathError != nil { | ||
| return PlatformHubPolicyVersion{}, pathError | ||
| } | ||
|
|
||
| body := struct { | ||
| Version string `json:"Version"` | ||
| }{Version: version} | ||
|
|
||
| publishedVersion, err := newclient.Post[PlatformHubPolicyVersion](client.HttpSession(), path, body) | ||
| if err != nil { | ||
| return PlatformHubPolicyVersion{}, err | ||
| } | ||
|
|
||
| return *publishedVersion, nil | ||
| } | ||
|
|
||
| // VersionsQuery represents query parameters for listing policy versions. | ||
| type VersionsQuery struct { | ||
| Slug string `uri:"slug"` | ||
| Skip int `uri:"skip,omitempty"` | ||
| Take int `uri:"take,omitempty"` | ||
| } | ||
|
|
||
| // GetVersions returns published versions of a Platform Hub policy. | ||
| func GetVersions(client newclient.Client, query VersionsQuery) ([]PlatformHubPolicyVersion, error) { | ||
| path, pathError := client.URITemplateCache().Expand("/api/platformhub/policies/{slug}/versions{?skip,take}", query) | ||
| if pathError != nil { | ||
| return nil, pathError | ||
| } | ||
|
|
||
| versions, err := newclient.Get[[]PlatformHubPolicyVersion](client.HttpSession(), path) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return *versions, nil | ||
| } | ||
|
|
||
| // ActivateVersion activates a published Platform Hub policy version. | ||
| func ActivateVersion(client newclient.Client, version PlatformHubPolicyVersion) (PlatformHubPolicyVersion, error) { | ||
| return modifyVersionStatus(client, version, true) | ||
| } | ||
|
|
||
| // DeactivateVersion deactivates a published Platform Hub policy version. | ||
| func DeactivateVersion(client newclient.Client, version PlatformHubPolicyVersion) (PlatformHubPolicyVersion, error) { | ||
| return modifyVersionStatus(client, version, false) | ||
| } | ||
|
|
||
| func modifyVersionStatus(client newclient.Client, version PlatformHubPolicyVersion, isActive bool) (PlatformHubPolicyVersion, error) { | ||
| path, pathError := client.URITemplateCache().Expand("/api/platformhub/policies/{slug}/versions/{version}/modify-status", map[string]any{ | ||
| "slug": version.Slug, | ||
| "version": version.Version, | ||
| }) | ||
| if pathError != nil { | ||
| return version, pathError | ||
| } | ||
|
|
||
| body := struct { | ||
| IsActive bool `json:"IsActive"` | ||
| }{IsActive: isActive} | ||
|
|
||
| modifiedVersion, err := newclient.Post[PlatformHubPolicyVersion](client.HttpSession(), path, body) | ||
| if err != nil { | ||
| return version, err | ||
| } | ||
|
|
||
| return *modifiedVersion, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be a separate test