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

Add template skeletons #967

Merged
merged 4 commits into from
Oct 28, 2019
Merged

Add template skeletons #967

merged 4 commits into from
Oct 28, 2019

Conversation

orenbm
Copy link
Member

@orenbm orenbm commented Oct 24, 2019

What does this PR do (include background context, if relevant)?

Adds a template connector skeleton. It includes all the code that needs to be in a new connector with guidance to fill the rest

What ticket does this PR close?

Connected to #1211

@orenbm orenbm requested a review from jonahx October 24, 2019 21:29
@izgeri izgeri requested a review from suefran October 24, 2019 21:35
@orenbm orenbm force-pushed the add-template-skeletons branch from 8f618cd to 1b37d19 Compare October 24, 2019 21:36
@izgeri
Copy link
Contributor

izgeri commented Oct 24, 2019

@orenbm it would be great if the connector plugin README referred to these templates for people who want to build a tcp or http connector

I'm also interested in feedback from the team about the location of the templates, as it could appear to someone that they are actual connectors based on their current location.


test:
image: secretless-dev # this image is built in bin/build
command: go test -v ./test/template_connector
Copy link
Contributor

Choose a reason for hiding this comment

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

This current standard is to have a bash ./test file. Using go test would be an optional choice each connector integration folder could make.

Perhaps this would be a better standard, but it may not be flexible enough. In any case, that's a discussion we should have in the channel.


./stop

docker-compose up -d secretless
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment that they would add the other containers to start. Or maybe we just do docker-compose up to start them all?

Copy link
Member Author

Choose a reason for hiding this comment

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

i have this comment after the line above:
# This is where you should prepare the container of the platform you are connecting to secretless

you think it's not clear enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

@orenbm I'd move the comment above

_ "github.com/denisenkom/go-mssqldb"
)

func TestTemplateConnector(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment to change name

Copy link

@suefran suefran left a comment

Choose a reason for hiding this comment

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

Looks good from my perspective! Just a few edits. Thanks!

}
}

// NewConnector returns an http.Connector that decorates each incoming http
Copy link

Choose a reason for hiding this comment

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

.......that decorates each incoming HTTP......

@@ -16,6 +16,7 @@ type InternalPluginLookupFunc func() (plugin.AvailablePlugins, error)

// GetInternalPluginsFunc returns currently available built-in plugins.
func GetInternalPluginsFunc() (plugin.AvailablePlugins, error) {
// New connectors should have an entry in the map below, according to their type (http/tcp)
Copy link

Choose a reason for hiding this comment

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

we've been trying to standardize on HTTP and TCP when referring to them outside of a command that requires specific syntax.


docker-compose up -d secretless

# This is where you should prepare the container of the platform you are connecting to secretless
Copy link

Choose a reason for hiding this comment

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

add a period.


func TestTemplateConnector(t *testing.T) {
t.Run("An empty test", func(t *testing.T) {
// We use go std test lib & testify/assert as our standard testing lib on secretless
Copy link

Choose a reason for hiding this comment

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

add period.

Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

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

@orenbm Some comments - mostly nits. Per comments from @izgeri I also believe that these template connectors may need a better place to live or be turned into "real example" plugins that are just pass-throughs as well as examples

"github.com/cyberark/secretless-broker/pkg/secretless/log"
"github.com/cyberark/secretless-broker/pkg/secretless/plugin/connector"

gohttp "net/http"
Copy link
Contributor

Choose a reason for hiding this comment

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

the imports should be arranged:

<stdlib libraries>

<third-party libs>

<internal libs>

@@ -0,0 +1,24 @@
package template
Copy link
Contributor

Choose a reason for hiding this comment

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

This location for the template connector isn't optimal. Generally we don't want any unused code in internal/

// TODO: add logic according to
// https://github.com/cyberark/secretless-broker/blob/master/pkg/secretless/plugin/connector/README.md#http-connector

return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are really trying to create an inclusive example, giving the error a variable would be better:

var err error


return err

// https://github.com/cyberark/secretless-broker/blob/master/pkg/secretless/plugin/connector/README.md#plugininfo
return map[string]string{
"pluginAPIVersion": "",
"type": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

// TODO: add logic according to
// https://github.com/cyberark/secretless-broker/blob/master/pkg/secretless/plugin/connector/README.md#tcp-connector

return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This skeleton should have a bit more stuff probably (it should connect to the backend and return a net.Conn).

Copy link
Member Author

Choose a reason for hiding this comment

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

how can i connect to a backend without knowing what it is?
Or do you think I should add it as a comment?

whenever i linked to a doc i didn't add more details so it won't be duplicated. wdyt? @sgnn7

Copy link
Contributor

Choose a reason for hiding this comment

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

You can add an example of it trying to parse "host" and "port" from credentialValuesByID

Copy link
Member Author

Choose a reason for hiding this comment

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

i couldn't find a generic way to write that. I updated the function description to better describe its process

// https://github.com/cyberark/secretless-broker/blob/master/pkg/secretless/plugin/connector/README.md#plugininfo
return map[string]string{
"pluginAPIVersion": "",
"type": "",
Copy link
Contributor

Choose a reason for hiding this comment

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

version: '3.0'

services:
# TODO: add a service for the platform you want to connect with secretless
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording here is odd - we don't want to connect a service to secretless but instead connect secretless to a service

# TODO: add a service for the platform you want to connect with secretless

secretless:
image: secretless-broker # this image is built in bin/build
Copy link
Contributor

Choose a reason for hiding this comment

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

s/built in/built by/

- ./secretless.yml:/secretless.yml

test:
image: secretless-dev # this image is built in bin/build
Copy link
Contributor

Choose a reason for hiding this comment

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

s/built in/built by/

@@ -0,0 +1 @@
# fill in according to https://docs.secretless.io/Latest/en/Content/Get%20Started/configuration.htm
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this should have at least some starter skeleton config

@orenbm
Copy link
Member Author

orenbm commented Oct 25, 2019

@izgeri @sgnn7 @jonahx I restructured the templates and added a README. please review :)

@orenbm
Copy link
Member Author

orenbm commented Oct 25, 2019

@orenbm it would be great if the connector plugin README referred to these templates for people who want to build a tcp or http connector

sure, once these changes are merged i will link them in the README

I'm also interested in feedback from the team about the location of the templates, as it could appear to someone that they are actual connectors based on their current location.

I just rearranged them according to the feedback. Hope it's clearer now.

jonahx
jonahx previously approved these changes Oct 26, 2019
Copy link
Contributor

@jonahx jonahx left a comment

Choose a reason for hiding this comment

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

Nice. I approved but noticed some other people had commented, so you may want to check with them before merging.

}

// This function has access to the client http.Request and the credentials (as a map), and is expected to decorate the
// request with Authorization headers.
Copy link
Contributor

Choose a reason for hiding this comment

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

line too long: wrap at 80 (you can set a hotkey in GoLand to make this easier)

Also, I'd say:

and is expected to modify the request so that it will authenticate. This typically means adding required authorization headers.

because some auth systems require other types of modifications, and in theory there is no limit on what they might require.

go.mod Outdated
@@ -8,6 +8,7 @@ require (
github.com/cyberark/conjur-api-go v0.5.2
github.com/cyberark/conjur-authn-k8s-client v0.13.0
github.com/cyberark/summon v0.7.0
github.com/denisenkom/go-mssqldb v0.0.0-20191001013358-cfbb681360f0
Copy link
Contributor

Choose a reason for hiding this comment

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

the changes to go.* are unrelated to this code, afaict. do they need to be included in this PR?


To add a new connector do the following:

1. Copy the relevant template directory (HTTP/TCP) into `internal/plugin/connectors/<protocol>`.
Copy link
Contributor

Choose a reason for hiding this comment

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

is protocol the language we're using for http vs tcp? it would be good to use consistent language to refer to this - I think I've seen it elsewhere as connector type

Copy link
Member Author

Choose a reason for hiding this comment

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

i didn't find something consistent. I see "handler type", "connection type", "config type"
I guess "connector type" makes sense

Copy link
Contributor

Choose a reason for hiding this comment

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

connector type 👍


1. Copy the relevant template directory (HTTP/TCP) into `internal/plugin/connectors/<protocol>`.
1. Inside each template directory you will find the required files & structs implemented, with
instructions to fill them with the content of the new connector
Copy link
Contributor

Choose a reason for hiding this comment

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

are the instructions in the form of TODOs or otherwise? would be good to be clear about how to find the instructions here

1. Copy the relevant template directory (HTTP/TCP) into `internal/plugin/connectors/<protocol>`.
1. Inside each template directory you will find the required files & structs implemented, with
instructions to fill them with the content of the new connector
1. Add an entry to the `Plugins` map defined in GetInternalPluginsFunc() of `internal_plugins.go`,
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a link to a file, so the user doesn't have to search the code for this

instructions to fill them with the content of the new connector
1. Add an entry to the `Plugins` map defined in GetInternalPluginsFunc() of `internal_plugins.go`,
according to their type (HTTP/TCP)
1. Copy the `template_connector_test` directory into `test` and rename it to `<connector_name>_connector`
Copy link
Contributor

Choose a reason for hiding this comment

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

can you link to template_connector_test here?

@@ -0,0 +1,28 @@
# Using templates to implement Secretless Connector Plugins
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this content should be moved to examples/connector_templates instead of putting it in templates? I'm basing this suggestion on the go project layout standards

Copy link
Contributor

@izgeri izgeri left a comment

Choose a reason for hiding this comment

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

I left several comments for things that should be revised before we merge.

@orenbm orenbm force-pushed the add-template-skeletons branch 4 times, most recently from 7f6bedc to 17706c2 Compare October 28, 2019 15:49
Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

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

@orenbm Just one tiny nit from me

scripts
using
the `run_integration` script. In most cases, you will also call `junit` on
the xml file that `run_integration` outputs in your test's subdirectory.
Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph has some odd whitespace formatting/line breaks

@orenbm orenbm force-pushed the add-template-skeletons branch 2 times, most recently from a3c3616 to 8a7c10a Compare October 28, 2019 16:36
@orenbm orenbm force-pushed the add-template-skeletons branch 2 times, most recently from 7436c4f to d8326b6 Compare October 28, 2019 16:47
sgnn7
sgnn7 previously approved these changes Oct 28, 2019
@orenbm orenbm requested a review from izgeri October 28, 2019 18:05
@orenbm orenbm dismissed suefran’s stale review October 28, 2019 18:05

fixed all requests


To add a new connector do the following:

1. Copy the relevant template directory (HTTP/TCP) into `internal/plugin/connectors/<connector type>`.
Copy link
Contributor

Choose a reason for hiding this comment

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

how do you know which one to copy? is it worth referring to the connector docs to learn more if you're not sure which one you need to copy?

Copy link
Member Author

Choose a reason for hiding this comment

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

@izgeri is this line ok?

If you're not sure which connector type is suitable, please refer to the [connector technical overview](https://github.com/cyberark/secretless-broker/tree/master/pkg/secretless/plugin/connector#technical-overview)

izgeri
izgeri previously approved these changes Oct 28, 2019
Copy link
Contributor

@izgeri izgeri left a comment

Choose a reason for hiding this comment

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

Added one more minor comment, address if you think it makes sense. Otherwise LGTM.

In the current structure it seems as if the template connector is an actual connector.
This commit moves all the templates to a `examples/connector_templates` directory, with a README inside explaining what needs to be done
@orenbm orenbm dismissed stale reviews from izgeri and sgnn7 via 80e322c October 28, 2019 18:19
@orenbm orenbm force-pushed the add-template-skeletons branch from d8326b6 to 80e322c Compare October 28, 2019 18:19
@orenbm orenbm merged commit d6323b2 into master Oct 28, 2019
@orenbm orenbm deleted the add-template-skeletons branch October 28, 2019 20:37
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.

5 participants