-
Notifications
You must be signed in to change notification settings - Fork 103
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
Conversation
There was a problem hiding this 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'") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
} | ||
|
||
func createPublicRegistryProvider(t *testing.T, client *Client, org *Organization) (*RegistryProvider, func()) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this 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"` |
There was a problem hiding this comment.
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
type RegistryProviderPermissions struct { | ||
CanDelete bool `jsonapi:"attr,can-delete,omitempty"` | ||
CanUploadAsset bool `jsonapi:"attr,can-upload-asset,omitempty"` |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
if options.RegistryName == PrivateRegistry && organization != options.Namespace { | ||
return nil, ErrInvalidPrivateProviderNamespaceDoesntMatchOrganization | ||
} |
There was a problem hiding this comment.
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?
if err := id.RegistryName.valid(); err != nil { | ||
return err | ||
} | ||
return nil |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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!
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. |
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:Then, for a registry provider version, you can test:
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.