diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f3a18569d8c..49bafe439bc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ FEATURES: IMPROVEMENTS: * api: Add `StartedAt` field to `Node.DrainStrategy` [[GH-6698](https://github.com/hashicorp/nomad/issues/6698)] + * api: Added JSON representation of rules to policy endpoint response [[GH-6017](https://github.com/hashicorp/nomad/pull/6017)] * build: Updated to Go 1.12.13 [[GH-6606](https://github.com/hashicorp/nomad/issues/6606)] * core: Add support for running under Windows Service Manager [[GH-6220](https://github.com/hashicorp/nomad/issues/6220)] * cli: Show full ID in node and alloc individual status views [[GH-6425](https://github.com/hashicorp/nomad/issues/6425)] diff --git a/command/acl_policy_info_test.go b/command/acl_policy_info_test.go index 19bf13088a69..4147f0e6744a 100644 --- a/command/acl_policy_info_test.go +++ b/command/acl_policy_info_test.go @@ -5,7 +5,6 @@ import ( "strings" "testing" - "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/command/agent" "github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/structs" @@ -31,7 +30,7 @@ func TestACLPolicyInfoCommand(t *testing.T) { // Create a test ACLPolicy policy := &structs.ACLPolicy{ Name: "testPolicy", - Rules: acl.PolicyWrite, + Rules: "node { policy = \"read\" }", } policy.SetHash() assert.Nil(state.UpsertACLPolicies(1000, []*structs.ACLPolicy{policy})) diff --git a/nomad/acl_endpoint.go b/nomad/acl_endpoint.go index f45a46497f5b..7b160c73fc1e 100644 --- a/nomad/acl_endpoint.go +++ b/nomad/acl_endpoint.go @@ -11,6 +11,7 @@ import ( metrics "github.com/armon/go-metrics" log "github.com/hashicorp/go-hclog" memdb "github.com/hashicorp/go-memdb" + policy "github.com/hashicorp/nomad/acl" "github.com/hashicorp/nomad/helper/uuid" "github.com/hashicorp/nomad/nomad/state" "github.com/hashicorp/nomad/nomad/structs" @@ -263,6 +264,12 @@ func (a *ACL) GetPolicy(args *structs.ACLPolicySpecificRequest, reply *structs.S reply.Policy = out if out != nil { reply.Index = out.ModifyIndex + rules, err := policy.Parse(out.Rules) + + if err != nil { + return err + } + reply.Policy.RulesJSON = rules } else { // Use the last index that affected the policy table index, err := state.Index("acl_policy") diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index f1d38b3a67f7..cf3bb5443830 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -9062,9 +9062,10 @@ func IsServerSide(e error) bool { // ACLPolicy is used to represent an ACL policy type ACLPolicy struct { - Name string // Unique name - Description string // Human readable - Rules string // HCL or JSON format + Name string // Unique name + Description string // Human readable + Rules string // HCL or JSON format + RulesJSON *acl.Policy // Generated from Rules on read Hash []byte CreateIndex uint64 ModifyIndex uint64