-
Notifications
You must be signed in to change notification settings - Fork 2k
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
api: Add parsed rules to policy response #6017
Changes from 6 commits
0fae6f1
069f595
837d484
0d4275b
ffb10e6
3206229
5356a78
0f860f4
1eb3cf8
7c7637c
241ed98
e5a2d13
4f1dbc3
8b18396
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd recommend not shadowing the name here, when reading the code it can make interpretation difficult when there are multiple names for one package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my previous attempt at this had it called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah - I guess so :( - That's unfortunate but makes sense 👍 |
||
"github.com/hashicorp/nomad/helper/uuid" | ||
"github.com/hashicorp/nomad/nomad/state" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
|
@@ -263,6 +264,14 @@ 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) | ||
|
||
backspace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed it, thanks. |
||
reply.Policy.RulesJSON = rules | ||
} | ||
} else { | ||
// Use the last index that affected the policy table | ||
index, err := state.Index("acl_policy") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9006,6 +9006,7 @@ type ACLPolicy struct { | |
Name string // Unique name | ||
Description string // Human readable | ||
Rules string // HCL or JSON format | ||
RulesJSON *acl.Policy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no particular attachment to this name, it’s awkward, I’m open to suggestions! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s just the rules portion though, right? The whole thing is the policy already. I don’t knowwwwwah haha There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also document that this field is generated from Rules on read. It's a bit unusual to have a field only in As far as naming, yeah it's awkward, but I think it fits. I feel like we confuse "ACL", "Rules", "Policies", "Capabilities", etc regularly but as this field is just a specific encoding of another field, we should follow the other field's naming. |
||
Hash []byte | ||
CreateIndex uint64 | ||
ModifyIndex uint64 | ||
|
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.
When I changed the parse error-handling to
return err
as @schmichael suggested, it caused a test failure becausewrite
, as stored here, isn’t valid HCL. Since theRules
aren’t actually being used anywhere in the test, I changed it to store valid HCL instead.