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 private registry provider version #405

Closed
wants to merge 2 commits into from

Conversation

annawinkler
Copy link
Contributor

@annawinkler annawinkler commented May 17, 2022

Description

This PR was broken out of this PR.

This PR adds support for the private registry provider version API. The first PR for these set of changes is this one.

Testing plan

To test these changes locally, create a local go project, and in the go.mod include a line similar to the following:

replace github.com/hashicorp/go-tfe => /Users/YOURUSER/go/src/github.com/hashicorp/go-tfe

Then, for a registry provider version, you can test:

  • Create
  • Delete
  • Read
  • List

External links

Output from tests

Including output from tests may require access to a TFE instance. Ignore this section if you have no environment to test against.

$ TFE_ADDRESS="https://example" TFE_TOKEN="example" TF_ACC="1" go test ./... -v -tags=integration -run TestFunctionsAffectedByChange

...

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

(As I mentioned in slack, I only got about halfway through this review)


ErrInvalidRegistryName = errors.New("invalid value for registry-name")

ErrInvalidRegistryNameType = errors.New("invalid type for registry-name. Please use 'RegistryName'")
Copy link
Collaborator

@brandonc brandonc May 18, 2022

Choose a reason for hiding this comment

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

I don't think this error is used (And if I understand the point of the error, the value should be "registry-providers")

prv, err := client.RegistryProviders.Create(ctx, org.Name, options)

if err != nil {
t.Fatal(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should return something here, since prv may be nil and the next line will panic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the line does we want it to - Fatal is equivalent to Log plus FailNow. FailNow stops execution, calls runtime.Goexit, and continues execution with the next test or benchmark.

}
}

func createPublicRegistryProvider(t *testing.T, client *Client, org *Organization) (*RegistryProvider, func()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💅 this and the previous method have so much in common, I'm wondering if there should be a third method that parameterizes PublicRegistry/PrivateRegistry ?

prvv, err := client.RegistryProviderVersions.Create(ctx, providerID, options)

if err != nil {
t.Fatal(err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same 'return' concern as above


// List of available includes
const (
RegistryProviderVersionsInclude RegistryProviderIncludeOps = "registry-provider-versions"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see this documented or in the API. Is it possible to include this relationship?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 You're right, when I re-reviewed the documentation, it is not clear that this include is an option. I tested it locally with this request:

curl --location --request GET 'https://LOCALURL/api/v2/organizations/amazing-org/registry-providers/private/amazing-org/zebra-provider?include=registry-provider-versions' \
--header 'Content-Type: application/vnd.api+json' \
--header 'Authorization: Bearer TOKEN' \
--header 'Cookie: __profilin=p%3Dt' \
--data-raw '{
  "data": {
    "type": "registry-providers",
    "attributes": {
      "name": "test-registry-provider-5de6cb61-b5ea-e72e-13a2-c9aab0b5c3ac",
      "namespace": "amazing-org",
      "registry-name": "private"
    }
  }
}'

And the response does include the registry provider versions (see the attached json). I think we'll need to update the docs. What are your thoughts?

response.txt

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Looks really close! It would be a good time to update the README Coverage and CHANGELOG with the new endpoints


type RegistryProviderPermissions struct {
CanDelete bool `jsonapi:"attr,can-delete,omitempty"`
CanUploadAsset bool `jsonapi:"attr,can-upload-asset,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see this field in the documentation or API serializer. I think it's only in the RegistryProviderVersions API

Comment on lines +70 to +72
type RegistryProviderPermissions struct {
CanDelete bool `jsonapi:"attr,can-delete,omitempty"`
CanUploadAsset bool `jsonapi:"attr,can-upload-asset,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

These fields are marked omitempty but it's not possible for this type to be empty. Looking at the provider API, it looks like these permissions fields are always present anyway, so the Permissions field probably doesn't need to be a pointer.

}

// RegistryProviderID is the multi key ID for addressing a provider
type RegistryProviderID struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this needs jsonapi metadata since it is only used as a compound key and not serialized into a jsonapi request body.

Comment on lines +158 to +160
if options.RegistryName == PrivateRegistry && organization != options.Namespace {
return nil, ErrInvalidPrivateProviderNamespaceDoesntMatchOrganization
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

:thinkies: I wonder if we should just let the API handle this error since it feels like it crosses over into API design & behavior?

Comment on lines +257 to +260
if err := id.RegistryName.valid(); err != nil {
return err
}
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

💅 this is the same as return id.RegistryName.valid() as the last statement


// RegistryProviderVersionID is the multi key ID for addressing a version provider
type RegistryProviderVersionID struct {
RegistryProviderID
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool use of embedded struct

// RegistryProviderVersionID is the multi key ID for addressing a version provider
type RegistryProviderVersionID struct {
RegistryProviderID
Version string `jsonapi:"attr,version"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this needs jsonapi metadata.

type RegistryProviderVersionCreateOptions struct {
Version string `jsonapi:"attr,version"`
KeyID string `jsonapi:"attr,key-id"`
Protocols []string `jsonapi:"attr,protocols"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should strongly type these versions: ProviderAPI4, ProviderAPI5, ProviderAPI6 ? Might reduce confusion, but then we would have to maintain it. It looks like the API is strict about what is accepted here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that idea!

return r.client.do(ctx, req, nil)
}

func (v RegistryProviderVersion) ShasumsUploadURL() (string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking across the repo, it looks like we've been really relaxed about wrapping Links with go functions. But I like it!

@annawinkler
Copy link
Contributor Author

I'm going to close this PR in favor of the one large one. I'll address the comments here in the one big PR.

@annawinkler annawinkler deleted the aw/add-registry-provider-version branch June 8, 2022 22:42
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.

None yet

3 participants