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

examples: add example to illustrate the use of file watcher interceptor #7226

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Kailun2047
Copy link

@Kailun2047 Kailun2047 commented May 10, 2024

Summary of changes:

  • Add example to illustrate the use of file watcher authz interceptor

Fixes #5900

RELEASE NOTES: none

@Kailun2047 Kailun2047 marked this pull request as ready for review May 10, 2024 14:42
@Kailun2047 Kailun2047 changed the title authz: add example to illustrate the use of file watcher interceptor examples: add example to illustrate the use of file watcher interceptor May 10, 2024
@easwars easwars added the Type: Documentation Documentation or examples label May 13, 2024
@easwars easwars self-assigned this May 13, 2024
@easwars easwars added this to the 1.65 Release milestone May 13, 2024
Copy link
Contributor

@easwars easwars left a comment

Choose a reason for hiding this comment

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

Looks very good. Just some minor nits. Thanks for doing this.

examples/features/authz/README.md Show resolved Hide resolved
examples/features/authz/README.md Outdated Show resolved Hide resolved
@Kailun2047
Copy link
Author

@easwars Comments addressed. Please take another look when you get time. Thanks.

@dfawley dfawley assigned gtcooke94 and unassigned Kailun2047 May 14, 2024
@dfawley
Copy link
Member

dfawley commented May 21, 2024

@gtcooke94 Can you take a second pass on this review? Thanks!

Copy link
Contributor

@gtcooke94 gtcooke94 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A few comments

```

The client will first hit `codes.PermissionDenied` error when invoking
`UnaryEcho` although a legit username (`super-user`) is associated. This is
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: UnaryEcho although a legitimate username (super-user) is associated with the RPC.

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

)

var (
port = flag.Int("port", 50051, "the port to serve on")
port = flag.Int("port", 50051, "the port to serve on")
authzOpt = flag.String("authz-option", authzOptStatic, "the authz option (static or file watcher)")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: file watcher -> filewatcher

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

switch *authzOpt {
case authzOptStatic:
// Create an authorization interceptor using a static policy.
staticInt, err := authz.NewStatic(authzPolicy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer the full name Interceptor rather than shortening to Int, please change throughout

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

}
unaryAuthzInt, streamAuthzInt = fileWatcherInt.UnaryInterceptor, fileWatcherInt.StreamInterceptor
default:
log.Fatalf("Invalid authz option: %s", *authzOpt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this example server is specifically for authz, let's put this check earlier (after parsing flags), then error log and exit the process if an invalid authz option is specified.

Copy link
Author

Choose a reason for hiding this comment

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

Updated.

@gtcooke94 gtcooke94 assigned Kailun2047 and unassigned gtcooke94 May 22, 2024
@Kailun2047
Copy link
Author

@gtcooke94 Comments addressed. Please take another look when you get time. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Documentation Documentation or examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an example to illustrate the use of authz package
4 participants