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

Update bundle commands to allow JWKS format #1777

Merged
merged 7 commits into from
Aug 10, 2020

Conversation

amartinezfayo
Copy link
Member

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality
bundle and experimental bundle commands.

Description of change

  • Added a format flag for the bundle list, bundle show and bundle set commands that allows pem and jwks formats for those commands.
  • Added a deprecation notice for the experimental bundle list,experimental bundle show and experimental bundle set commands.

Which issue this PR fixes
Fixes #1743.

set` commands that allows `pem` and `jwks` formats for those commands.
- Add a deprecation notice for the `experimental bundle list`,
`experimental bundle show` and `experimental bundle set` commands.

Fixes spiffe#1743.

Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
Signed-off-by: Agustín Martínez Fayó <amartinezfayo@gmail.com>
-----END CERTIFICATE-----
`

allBundlesJWKS = `****************************************
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: break line

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the expected format.

}
`

allBundlesPEM = `****************************************
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: break line

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the expected format.

key1Pkix: key1Pkix,
ds: ds,
registrationClient: fakeregistrationclient.New(t, "spiffe://example.test", ds, nil),
stdin: stdin,
Copy link
Collaborator

Choose a reason for hiding this comment

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

may we assing testEnv instead? and get stdin/out/err from there?

s.Require().Equal(`Usage of bundle show:
func TestShowHelp(t *testing.T) {
test := setupTest(t)
defer test.cleanup()
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: now that we use golang 1.14 you can use t.Cleanup instead, and it can go inside setupTest(t)

expectedOut: cert1JWKS,
},
} {
test := setupTest(t)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: is there a reason why it is not inside run body? (easier to read that way)
or maybe it can go out for? looks like it is always the same

Copy link
Member Author

Choose a reason for hiding this comment

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

no good reason, I'll change that

s.Require().Len(resp.Bundle.RootCas, 1)
s.Require().Equal(s.cert1.Raw, resp.Bundle.RootCas[0].DerBytes)
require.NoError(t, err)
require.NotNil(t, resp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can not you create a response and use assert proto equal instead?

}
}

if strings.ToLower(format) == formatPEM {
Copy link
Collaborator

Choose a reason for hiding this comment

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

to avoid lower you can return always lowered string from validate

}

bundle := &registration.FederatedBundle{
Bundle: bundleutil.BundleProtoFromRootCAs(id, rootCAs),
if strings.ToLower(format) == formatPEM {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe a switch with allowed types make it easier to read

return err
}

if header {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is never true

Copy link
Member Author

Choose a reason for hiding this comment

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

This function is only used by the bundle show command, so it shouldn't really be part of this common file. I'll move it to show.go and remove the header parameter.

****************************************
`
formatPEM = "pem"
formatJWKS = "jwks"
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about "spiffe" for this format instead of JWKS?

Copy link
Member Author

Choose a reason for hiding this comment

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

works for me!

Copy link
Member

@azdagron azdagron left a comment

Choose a reason for hiding this comment

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

Thanks, @amartinezfayo!

Comment on lines -73 to -75
s.stdin = new(bytes.Buffer)
s.stdout = new(bytes.Buffer)
s.stderr = new(bytes.Buffer)
Copy link
Member

Choose a reason for hiding this comment

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

nit: the advantage of this was to not have type assertions everywhere you want to check the contents of the buffer...

Copy link
Member Author

Choose a reason for hiding this comment

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

yea, I thought about that, but I was ok with either way

@amartinezfayo amartinezfayo merged commit d24aab2 into spiffe:master Aug 10, 2020
@amartinezfayo amartinezfayo deleted the bundle-format branch September 1, 2021 14:14
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.

Federation Graduation (the missing bits)
3 participants