Skip to content
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

Allow users to get/delete templates by name only #89

Merged

Conversation

maxsmythe
Copy link
Contributor

Signed-off-by: Max Smythe smythe@google.com

Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
@@ -24,13 +24,13 @@ import (

const constraintGroup = "constraints.gatekeeper.sh"

type ClientOpt func(*Client) error
type Opt func(*Client) error
Copy link

Choose a reason for hiding this comment

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

Do we have any compatibility guarantees that would discourage such an API change? Is Gatekeeper the primary consumer of the Constraint Framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. I haven't added semver to leave room for stuff like this. Further this should be mostly transparent as ClientOpt/Opt are only used as inputs to the creation functions.

Forseti is the only other consumer of the CF that I am aware of: https://github.com/forseti-security/config-validator

expectedCount = 1
expectedHandled = map[string]bool{"h1": true}
}
if r.HandledCount() != expectedCount {
Copy link

Choose a reason for hiding this comment

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

It's not clear whether r is valid and non-nil on this line if we received an error from RemoveTemplate above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

r is always returned as other handlers may have had the chance to process before an error was raised.

Copy link

Choose a reason for hiding this comment

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

If that's the case I might suggest some combination of these:

  • Returning the responses as a value rather than a pointer
  • Checking for nil receiver in HandledCount and Results
  • Documenting that responses is valid even upon error

I generally assume return values are invalid when an error is returned, which is also echoed here: https://github.com/golang/go/wiki/CodeReviewComments#in-band-errors

Instead of requiring clients to check for an in-band error value, a function should return an additional value to indicate whether its other return values are valid. This return value may be an error, or a boolean when no explanation is needed. It should be the final return value.

...but I recognize the need to report additional information on partial success.

Copy link
Contributor Author

@maxsmythe maxsmythe Mar 24, 2020

Choose a reason for hiding this comment

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

Re: value instead of pointer...

Given that the amount of memory it takes to represent this object potentially scales with the number of responses, I'm wary of using a value. Since it's currently represented by a map, that may not be an issue, though I like the idea of guaranteeing we are only ever copying-by-reference.

Re: checking for a nil receiver...

That's a good idea, then the helper functions could return empty results

Re: documentation... ya, there is definitely interface documentation work to be done

Looking through that doc, the "how to do errors" gets a bit hand-wavy at points b/c they can't predict all uses. I think this is one. I think what we have strikes a reasonable balance between the two competing needs and follows the main point, which is "report errors out-of-band to avoid the need for introspection"

Note that if a user is not interested in the result if an error is returned, usage of this function devolves into standard Go code.

Copy link

Choose a reason for hiding this comment

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

Sounds reasonable 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the checking for a nil receiver and documented that results are still valid even when error is returned.

Copy link
Member

Choose a reason for hiding this comment

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

good call out!

Signed-off-by: Max Smythe <smythe@google.com>
Copy link

@shomron shomron left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@shomron shomron left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

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

LGTM

@ritazh
Copy link
Member

ritazh commented Mar 25, 2020

Once this is merged, can we pls vendor the latest to gk? :)

@maxsmythe maxsmythe merged commit 1a8f361 into open-policy-agent:master Mar 25, 2020
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