Skip to content

Introduce API for platform hub compliance policies#406

Merged
denys-octopus merged 8 commits intomainfrom
mas/add-platform-hub-policies
Mar 19, 2026
Merged

Introduce API for platform hub compliance policies#406
denys-octopus merged 8 commits intomainfrom
mas/add-platform-hub-policies

Conversation

@denys-octopus
Copy link
Contributor

@denys-octopus denys-octopus commented Mar 6, 2026

Background

We want to allow user to manage compliance policies via go-client.

Part of MAS-6 (I want to create a new policy in Platform Hub)

Result

This PR introduces new package with exposed function to add new compliance policy. Other functionalities will be added in next pull requests.

Example of usage

// Create new
draft := platformhubpolicies.PolicyDraft{
    GitRef:          "refs/heads/main",
    Slug:            "my_policy",
    Name:            "My policy",
    ScopeRego:       scope,
    ConditionsRego:  conditions,
    ViolationAction: "block",
}
createdPolicy, _ := platformhubpolicies.Add(octopusClient, draft, "Create new policy commit message")

// Get By Slug and Update
policy, _ := platformhubpolicies.GetBySlug(octopusClient, createdPolicy.GetGitRef(), createdPolicy.GetSlug())
policy.SetName("My policy Updated")
policy.SetViolationAction("warn")

updatedPolicy, _ := platformhubpolicies.Update(octopusClient, policy, "Update policy commit message")

// List policies
policiesResult, _ := platformhubpolicies.List(octopusClient, platformhubpolicies.PoliciesQuery{
    GitRef: "refs/heads/main",
    Skip:   0,
    Take:   30,
})

for _, p := range policiesResult.Policies {
    fmt.Printf("%s (slug: %s, action: %s)\n", p.GetName(), p.GetSlug(), p.GetViolationAction())
}

// Publish
publishedVersion1, _ := platformhubpolicies.Publish(octopusClient, updatedPolicy, "1.0.0")
publishedVersion2, _ := platformhubpolicies.Publish(octopusClient, updatedPolicy, "2.0.0")

// Activate published version
activatedVersion, _ := platformhubpolicies.ActivateVersion(octopusClient, publishedVersion2)

// List published versions
versionsResult, _ := platformhubpolicies.ListVersions(octopusClient, platformhubpolicies.PublishedPoliciesQuery{
    Slug: "my_policy",
    Skip: 0,
    Take: 20,
})

for _, v := range versionsResult.Items {
    fmt.Printf("%s v%s (active: %t)\n", v.GetSlug(), v.GetVersion(), v.IsActivated())
}

Copy link

@shaun-od shaun-od left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of notes, can we check with the owners of the GO client if they need to review as well.

# This is the 1st commit message:

Introduce platform hub policies operations

# This is the commit message #2:

Remove redundant file

# This is the commit message #3:

Remove redundant file

# This is a combination of 3 commits.
# This is the 1st commit message:

Introduce platform hub policies operations

# This is the commit message #2:

Remove redundant file

# This is the commit message #3:

Remove redundant file
@denys-octopus denys-octopus force-pushed the mas/add-platform-hub-policies branch from 5fba0fc to b62d98a Compare March 11, 2026 22:50
@denys-octopus denys-octopus changed the title Introduce API for adding new platform hub compliance policy Introduce API for platform hub compliance policies Mar 11, 2026
Copy link

@shaun-od shaun-od left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than there is a comment about whether the publish should be on the policy entity instead? Lets chat about it.

Copy link

@shaun-od shaun-od left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my perspective. There is one change we are going to make but I'm happy with either approach.

…ng the version object

At this moment we don't have an operation for consumer to load single specific version.
Copy link
Contributor

@liam-mackie liam-mackie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor notes around the PlatformHubPolicyVersion which are nits - might be good to discuss, but it's a difference of opinion, rather than a real reason to block the PR.

Types provides better explanation for package consumer about operation and required input values
To follow "List" pattern from policy methods
Copy link

@shaun-od shaun-od left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of things to look at, happy to chat if needed

)

// PolicyCandidate represents a set of information to create new Hub policy.
type PolicyCandidate struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sold on candidate as the suffix, would PolicyDraft be better but I am not sold on that name either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to PolicyDraft - for me, sounds more appropriate than ..Cadidate

}

// GetBySlug returns the Platform Hub policy that matches given policy key.
func GetBySlug(client newclient.Client, key PolicyKey) (Policy, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does a user create a key if they don't already have a policy created to get it by slug? I wonder whether this method should take the gitRef and slug as parameters? What do other things do when they have GetBySlug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, changed to two separate arguments.

For example runbook Git operations passing all required values as separate arguments

Avoid forcing user to create a type which implements previously used PolicyKey interface
Copy link

@shaun-od shaun-od left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@denys-octopus denys-octopus merged commit 5df21a7 into main Mar 19, 2026
6 checks passed
@denys-octopus denys-octopus deleted the mas/add-platform-hub-policies branch March 19, 2026 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants