lib/pulp_python_client/api/pypi_legacy_api.rb



=begin
#Pulp 3 API

#Fetch, Upload, Organize, and Distribute Software Packages

The version of the OpenAPI document: v3
Contact: pulp-list@redhat.com
Generated by: https://openapi-generator.tech
Generator version: 7.10.0

=end

require 'cgi'

module PulpPythonClient
  class PypiLegacyApi
    attr_accessor :api_client

    def initialize(api_client = ApiClient.default)
      @api_client = api_client
    end
    # Upload a package
    # Upload package to the index.  This is the endpoint that tools like Twine and Poetry use for their upload commands.
    # @param path [String] 
    # @param content [File] A Python package release file to upload to the index.
    # @param sha256_digest [String] SHA256 of package to validate upload integrity.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :x_task_diagnostics List of profilers to use on tasks.
    # @option opts [String] :action Defaults to &#x60;file_upload&#x60;, don&#39;t change it or request will fail! (default to 'file_upload')
    # @option opts [ProtocolVersionEnum] :protocol_version Protocol version to use for the upload. Only version 1 is supported.  * &#x60;1&#x60; - 1
    # @option opts [FiletypeEnum] :filetype Type of artifact to upload.  * &#x60;bdist_wheel&#x60; - bdist_wheel * &#x60;sdist&#x60; - sdist
    # @option opts [MetadataVersionEnum] :metadata_version Metadata version of the uploaded package.  * &#x60;1.0&#x60; - 1.0 * &#x60;1.1&#x60; - 1.1 * &#x60;1.2&#x60; - 1.2 * &#x60;2.0&#x60; - 2.0 * &#x60;2.1&#x60; - 2.1 * &#x60;2.2&#x60; - 2.2 * &#x60;2.3&#x60; - 2.3 * &#x60;2.4&#x60; - 2.4
    # @option opts [Object] :attestations 
    # @return [PackageUploadTaskResponse]
    def create(path, content, sha256_digest, opts = {})
      data, _status_code, _headers = create_with_http_info(path, content, sha256_digest, opts)
      data
    end

    # Upload a package
    # Upload package to the index.  This is the endpoint that tools like Twine and Poetry use for their upload commands.
    # @param path [String] 
    # @param content [File] A Python package release file to upload to the index.
    # @param sha256_digest [String] SHA256 of package to validate upload integrity.
    # @param [Hash] opts the optional parameters
    # @option opts [Array<String>] :x_task_diagnostics List of profilers to use on tasks.
    # @option opts [String] :action Defaults to &#x60;file_upload&#x60;, don&#39;t change it or request will fail! (default to 'file_upload')
    # @option opts [ProtocolVersionEnum] :protocol_version Protocol version to use for the upload. Only version 1 is supported.  * &#x60;1&#x60; - 1
    # @option opts [FiletypeEnum] :filetype Type of artifact to upload.  * &#x60;bdist_wheel&#x60; - bdist_wheel * &#x60;sdist&#x60; - sdist
    # @option opts [MetadataVersionEnum] :metadata_version Metadata version of the uploaded package.  * &#x60;1.0&#x60; - 1.0 * &#x60;1.1&#x60; - 1.1 * &#x60;1.2&#x60; - 1.2 * &#x60;2.0&#x60; - 2.0 * &#x60;2.1&#x60; - 2.1 * &#x60;2.2&#x60; - 2.2 * &#x60;2.3&#x60; - 2.3 * &#x60;2.4&#x60; - 2.4
    # @option opts [Object] :attestations 
    # @return [Array<(PackageUploadTaskResponse, Integer, Hash)>] PackageUploadTaskResponse data, response status code and response headers
    def create_with_http_info(path, content, sha256_digest, opts = {})
      if @api_client.config.debugging
        @api_client.config.logger.debug 'Calling API: PypiLegacyApi.create ...'
      end
      # verify the required parameter 'path' is set
      if @api_client.config.client_side_validation && path.nil?
        fail ArgumentError, "Missing the required parameter 'path' when calling PypiLegacyApi.create"
      end
      # verify the required parameter 'content' is set
      if @api_client.config.client_side_validation && content.nil?
        fail ArgumentError, "Missing the required parameter 'content' when calling PypiLegacyApi.create"
      end
      # verify the required parameter 'sha256_digest' is set
      if @api_client.config.client_side_validation && sha256_digest.nil?
        fail ArgumentError, "Missing the required parameter 'sha256_digest' when calling PypiLegacyApi.create"
      end
      if @api_client.config.client_side_validation && sha256_digest.to_s.length > 64
        fail ArgumentError, 'invalid value for "sha256_digest" when calling PypiLegacyApi.create, the character length must be smaller than or equal to 64.'
      end

      if @api_client.config.client_side_validation && sha256_digest.to_s.length < 64
        fail ArgumentError, 'invalid value for "sha256_digest" when calling PypiLegacyApi.create, the character length must be great than or equal to 64.'
      end

      if @api_client.config.client_side_validation && !opts[:'action'].nil? && opts[:'action'].to_s.length < 1
        fail ArgumentError, 'invalid value for "opts[:"action"]" when calling PypiLegacyApi.create, the character length must be great than or equal to 1.'
      end

      # resource path
      local_var_path = '/pypi/{path}/legacy/'.sub('{' + 'path' + '}', CGI.escape(path.to_s).gsub('%2F', '/'))

      # query parameters
      query_params = opts[:query_params] || {}

      # header parameters
      header_params = opts[:header_params] || {}
      # HTTP header 'Accept' (if needed)
      header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
      # HTTP header 'Content-Type'
      content_type = @api_client.select_header_content_type(['multipart/form-data', 'application/x-www-form-urlencoded'])
      if !content_type.nil?
          header_params['Content-Type'] = content_type
      end
      header_params[:'X-Task-Diagnostics'] = @api_client.build_collection_param(opts[:'x_task_diagnostics'], :csv) if !opts[:'x_task_diagnostics'].nil?

      # form parameters
      form_params = opts[:form_params] || {}
      form_params['content'] = content
      form_params['sha256_digest'] = sha256_digest
      form_params['action'] = opts[:'action'] if !opts[:'action'].nil?
      form_params['protocol_version'] = opts[:'protocol_version'] if !opts[:'protocol_version'].nil?
      form_params['filetype'] = opts[:'filetype'] if !opts[:'filetype'].nil?
      form_params['metadata_version'] = opts[:'metadata_version'] if !opts[:'metadata_version'].nil?
      form_params['attestations'] = opts[:'attestations'] if !opts[:'attestations'].nil?

      # http body (model)
      post_body = opts[:debug_body]

      # return_type
      return_type = opts[:debug_return_type] || 'PackageUploadTaskResponse'

      # auth_names
      auth_names = opts[:debug_auth_names] || ['basicAuth']

      new_options = opts.merge(
        :operation => :"PypiLegacyApi.create",
        :header_params => header_params,
        :query_params => query_params,
        :form_params => form_params,
        :body => post_body,
        :auth_names => auth_names,
        :return_type => return_type
      )

      data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
      if @api_client.config.debugging
        @api_client.config.logger.debug "API called: PypiLegacyApi#create\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
      end
      return data, status_code, headers
    end
  end
end