Use the examples directory for example plugin code#23255
Conversation
7268705 to
151fa63
Compare
alexfornuto
left a comment
There was a problem hiding this comment.
I'm not a go programmer so I don't know if this makes sense, but if the sections that we break out and describe individually in these guides could be separate files imported into a main file, we could use partials inside the code blocks and ensure that the docs remain up-to-date if/when the examples change.
|
@alexfornuto I think that's a really good idea, though it will result in a slightly strange-looking program, since we'll have a collection of very small Edit: another aspect of this is that we would need to include |
b129612 to
013198c
Compare
ec2487c to
00155b8
Compare
00155b8 to
e69d130
Compare
e69d130 to
5b09226
Compare
Joerger
left a comment
There was a problem hiding this comment.
This is an awesome guide and sample project!
I'm not a go programmer so I don't know if this makes sense, but if the sections that we break out and describe individually in these guides could be separate files imported into a main file, we could use partials inside the code blocks and ensure that the docs remain up-to-date if/when the examples change.
+1 to this idea. I wouldn't split it into 10 files or anything, but I think you could reasonbly chunk it like this or similar:
func mainrunandhandleEventupdateSpreadsheetupdateRowandcreateRowmakeRowData
... another aspect of this is that we would need to include
package mainat the top of each partial, which will also look strange within the guide itself.
IMO overall it's a worthwhile tradeoff, and as a Go programmer I wouldn't be confused by it.
| panic(err) | ||
| } | ||
|
|
||
| gs := googleSheetsPlugin{ |
There was a problem hiding this comment.
nit: From the perspective of using this example as a base for one's own custom plugin, it would be cool to make the code a bit more modular. For example, rather than having a googleSheetsPlugin, we could have something like:
type accessRequestPlugin struct {
teleportClient *client.Client
eventHandler interface {
HandleEvent(ctx context.Context, event types.Event) error
}
}
type googleSheetsClient struct {
sheetsClient *sheets.SpreadsheetsService
}
func (*googleSheetsClient) HandleEvent(ctx context.Context, event types.Event) error {
...
}
plugin := accessRequestPlugin{
teleportClient: ...,
eventHandler: googleSheetsClient{
sheetsClient: ...,
}
}
Then the user could just swap out eventHandler with their own implementation very intuitively. This would also make splitting the code into separate files more natural.
I think this PR is a big improvement regardless, so this is more of a follow up suggestion than a blocker.
There was a problem hiding this comment.
This sounds great, especially if we want to make it the recommended way for a user to build/test their own Access Request plugin. If this is the way we want to go, I can look into making this change.
When writing this guide, though, I had imagined the example as something that would demonstrate some key libraries in a runnable way, but not the basis for an actual production plugin. Is there anything else we'd need to add to the accessRequestPlugin type to make it more generally usable?
There was a problem hiding this comment.
Nothing off the top of my head, just having a teleport Client and some customizable event handler seems sufficient as a base.
9d62f53 to
c87caa8
Compare
|
Going to put this one in draft and plan to rework the example application so it doesn't rely on |
9765142 to
d557902
Compare
alexfornuto
left a comment
There was a problem hiding this comment.
Copy changes look good, with one nit.
This way, we can reuse the actual program in the Access Request plugin API guide and avoid unintended discrepancies and drift.
Need to test this out, but it compiles
- Types that are no longer reachable via public interfaces - The description of the demo implementation that used the old `watcherjob` package
Respond to Joerger feedback
Co-authored-by: Brian Joerger <bjoerger@goteleport.com>
- Split up "types.go". Reserve a single file for configuration values so these are visible in a single place within the guide. - Return an error on an unsuccessful HTTP request when creating or updating a row - Simplify requestStates lookup - Clearly mark values that a user must change - Update the text of the guide to match changes to the program
1d3667d to
63f10ac
Compare
|
@zmb3 Friendly ping to see if I resolved your feedback |
Closes #27696
Also edit the Access Request plugin API guide to use this directory, rather than having the reader copy/paste individual code snippets. This makes the guide easier to follow, and users will have a compilable example before they proceed through the guide.
See this discussion for context. I will also apply similar changes to my in-progress API guides.