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

Fixes #33221 - Hide upload section for Collection repository #9540

Merged
merged 1 commit into from Aug 12, 2021

Conversation

sjha4
Copy link
Member

@sjha4 sjha4 commented Aug 5, 2021

Was looking into the uploads flow for collections and seems like it has to be a workflow of sorts to have these fields: https://docs.pulpproject.org/pulp_ansible/restapi.html#operation/content_ansible_collection_versions_create

For the purposes of current release, hiding the upload section on repo details and adding a user friendly error to the API.

@theforeman-bot
Copy link

Issues: #33221

@sjha4 sjha4 changed the title Fixes #33221 - Hide upload section for Repository collections Fixes #33221 - Hide upload section for Collection repository Aug 5, 2021
@sjha4
Copy link
Member Author

sjha4 commented Aug 9, 2021

Opened issue: https://pulp.plan.io/issues/9220 in pulp to enable easier upload of collections without the several user specified required fields.

Copy link
Member

@rverdile rverdile 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 overall. Can't see the upload section!

One potential issue I notice is I can cause an error by making an API request to create an upload request. This is the create method in content_uploads_controller.rb. Might not be an actual use-case though.

Request:
curl --user admin:changeme --header "Content-Type: application/json" --request POST --data '{"size":"8000","content_type":"ansible collection"}' https://centos7-katello-devel-nfs.localhost.example.com/katello/api/repositories/2/content_uploads.

Also, ansible collections aren't marked as uploaded (RepositoryTypeManager.uploadable_content_types). I wonder if there's a way to check that rather than block ansible repositories entirely? That might require changes that are out of scope for this card though, because content_type isn't a required param.

@sjha4
Copy link
Member Author

sjha4 commented Aug 10, 2021

@rverdile : Let me update the content_upload controller. The upload itslef won't work but we should probably fail graciously. The current code will throw a null reference.

@sjha4 sjha4 force-pushed the hide_upload_ansible_collections branch from 4726f88 to 0960aea Compare August 10, 2021 13:37
@@ -13,6 +13,8 @@ class Api::V2::ContentUploadsController < Api::V2::ApiController
param :content_type, RepositoryTypeManager.uploadable_content_types(false).map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree', 'rpm', 'srpm')")
def create
content_type = params[:content_type] || ::Katello::RepositoryTypeManager.find(@repository.content_type).default_managed_content_type.label
fail _("Content type is not supported for upload!") unless content_type
Copy link
Member

Choose a reason for hiding this comment

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

I can cause two different errors here.

The first one is if I don't specify content_type in the API request, the return message is "undefined method label for nil:NilClass","errors":["undefined method label for nil:NilClass"].

The second one is if I pass ansible collections as content_type, the return message is "uninitialized constant Katello::Pulp3::AnsibleCollection::CONTENT_TYPE","errors":["uninitialized constant Katello::Pulp3::AnsibleCollection::CONTENT_TYPE"]

But I think the solution you used for repositories_controller would work fine here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you check these on the updated commit..

I am a little surprised you were able to pass ansible_collections as a param and not fail at the param validation itself or maybe I am reading it wrong:
param :content_type, RepositoryTypeManager.uploadable_content_types(false).map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree', 'rpm', 'srpm')")

RepositoryTypeManager.uploadable_content_types(false).map(&:label) does not return ansible_collections so it should ideally fail before going any further. In any case, I added that check inside the controller to prevent that.

@sjha4 sjha4 force-pushed the hide_upload_ansible_collections branch 3 times, most recently from 1d9a547 to 56cdd38 Compare August 10, 2021 14:27
@sjha4 sjha4 force-pushed the hide_upload_ansible_collections branch from 56cdd38 to 3e24128 Compare August 10, 2021 15:13
Copy link
Member

@rverdile rverdile 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!

Copy link
Member

@ianballou ianballou left a comment

Choose a reason for hiding this comment

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

Looks fine!

@sjha4 sjha4 merged commit 5ad117c into Katello:master Aug 12, 2021
jlsherrill pushed a commit to jlsherrill/katello that referenced this pull request Aug 30, 2021
jlsherrill pushed a commit that referenced this pull request Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants