diff --git a/gen-client.sh b/gen-client.sh index 8c51982..97f5e5b 100755 --- a/gen-client.sh +++ b/gen-client.sh @@ -34,7 +34,10 @@ if language.lower() == "python": else: print("v4.3.1") elif language.lower() == "ruby": - print("v4.3.1") + if core_version >= Version("3.70.dev"): + print("v7.10.0") + else: + print("v4.3.1") elif language.lower() == "typescript": print("v5.2.1") else: diff --git a/templates/ruby/v7.10.0/gemspec.mustache b/templates/ruby/v7.10.0/gemspec.mustache new file mode 100644 index 0000000..3503583 --- /dev/null +++ b/templates/ruby/v7.10.0/gemspec.mustache @@ -0,0 +1,42 @@ +# -*- encoding: utf-8 -*- + +=begin +{{> api_info}} +=end + +$:.push File.expand_path("../lib", __FILE__) +require "{{gemName}}/version" + +Gem::Specification.new do |s| + s.name = "{{gemName}}{{^gemName}}{{{appName}}}{{/gemName}}" + s.version = {{moduleName}}::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["{{gemAuthor}}{{^gemAuthor}}OpenAPI-Generator{{/gemAuthor}}"] + s.email = ["{{gemAuthorEmail}}{{^gemAuthorEmail}}{{infoEmail}}{{/gemAuthorEmail}}"] + s.homepage = "{{gemHomepage}}{{^gemHomepage}}https://openapi-generator.tech{{/gemHomepage}}" + s.summary = "{{gemSummary}}{{^gemSummary}}{{{appName}}} Ruby Gem{{/gemSummary}}" + s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}" + s.license = "{{{gemLicense}}}{{^gemLicense}}Unlicense{{/gemLicense}}" + s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 2.7{{/gemRequiredRubyVersion}}" + s.metadata = {{{gemMetadata}}}{{^gemMetadata}}{}{{/gemMetadata}} + + {{#isFaraday}} + s.add_runtime_dependency 'faraday-net_http', '>= 2.0', '< 3.1' + s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 2.9' + s.add_runtime_dependency 'faraday-multipart' + s.add_runtime_dependency 'marcel' + {{/isFaraday}} + {{#isTyphoeus}} + s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' + {{/isTyphoeus}} + {{#isHttpx}} + s.add_runtime_dependency 'httpx', '~> 1.0', '>= 1.0.0' + {{/isHttpx}} + + s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' + + s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } + s.test_files = `find spec/*`.split("\n") + s.executables = [] + s.require_paths = ["lib"] +end diff --git a/test_bindings.rb b/test_bindings.rb new file mode 100644 index 0000000..3f7fb94 --- /dev/null +++ b/test_bindings.rb @@ -0,0 +1,148 @@ +require 'pulpcore_client' +require 'pulp_file_client' +require 'tempfile' +require 'digest' + + +PulpcoreClient.configure do |config| + config.host= "http://localhost:5001" + config.username= 'admin' + config.password= 'password' + config.debugging=true +end + +PulpFileClient.configure do |config| + config.host= "http://localhost:5001" + config.username= 'admin' + config.password= 'password' + config.debugging=true +end + + +@artifacts_api = PulpcoreClient::ArtifactsApi.new +@filerepositories_api = PulpFileClient::RepositoriesFileApi.new +@repoversions_api = PulpFileClient::RepositoriesFileVersionsApi.new +@filecontent_api = PulpFileClient::ContentFilesApi.new +@filedistributions_api = PulpFileClient::DistributionsFileApi.new +@filepublications_api = PulpFileClient::PublicationsFileApi.new +@fileremotes_api = PulpFileClient::RemotesFileApi.new +@tasks_api = PulpcoreClient::TasksApi.new +@uploads_api = PulpcoreClient::UploadsApi.new + + +def monitor_task(task_href) + # Polls the Task API until the task is in a completed state. + # + # Prints the task details and a success or failure message. Exits on failure. + # + # Args: + # task_href(str): The href of the task to monitor + # + # Returns: + # list[str]: List of hrefs that identify resource created by the task + task = @tasks_api.read(task_href) + until ["completed", "failed", "canceled"].include? task.state + sleep(2) + task = @tasks_api.read(task_href) + end + if task.state == 'completed' + task.created_resources + else + print("Task failed. Exiting.\n") + exit(2) + end +end + +def content_range(start, finish, total) + finish = finish > total ? total : finish + "bytes #{start}-#{finish}/#{total}" +end + +def upload_file_in_chunks(file_path) + # Uploads a file using the Uploads API + # + # The file located at 'file_path' is uploaded in chunks of 200kb. + # + # Args: + # file_path (str): path to the file being uploaded to Pulp + # + # Returns: + # upload object + response = "" + File.open(file_path, "rb") do |file| + total_size = File.size(file) + upload_data = PulpcoreClient::Upload.new({size: total_size}) + response = @uploads_api.create(upload_data) + upload_href = response.pulp_href + chunksize = 200000 + offset = 0 + sha256 = Digest::SHA256.new + until file.eof? + chunk = file.read(chunksize) + sha256.update(chunk) + begin + filechunk = Tempfile.new('fred') + filechunk.write(chunk) + filechunk.flush() + actual_chunk_size = File.size(filechunk) + response = @uploads_api.update(content_range(offset, offset + actual_chunk_size - 1, total_size), upload_href, filechunk) + offset += actual_chunk_size - 1 + ensure + filechunk.close + filechunk.unlink + end + end + upload_commit_response = @uploads_api.commit(upload_href, {sha256: sha256.hexdigest}) + created_resources = monitor_task(upload_commit_response.task) + @artifacts_api.read(created_resources[0]) + end +end + + +artifact = upload_file_in_chunks(File.new(File.expand_path(__FILE__))) + +# Create a File Remote +remote_url = 'https://fixtures.pulpproject.org/file/PULP_MANIFEST' +remote_data = PulpFileClient::FileFileRemote.new({name: 'bar38', url: remote_url}) +file_remote = @fileremotes_api.create(remote_data) + +# Create a Repository +repository_data = PulpFileClient::FileFileRepository.new({name: 'foo38'}) +file_repository = @filerepositories_api.create(repository_data) + +# Sync a Repository +repository_sync_data = PulpFileClient::RepositorySyncURL.new({remote: file_remote.pulp_href}) +sync_response = @filerepositories_api.sync(file_repository.pulp_href, repository_sync_data) + +# Monitor the sync task +created_resources = monitor_task(sync_response.task) + +repository_version_1 = @repoversions_api.read(created_resources[0]) + +# Create a FileContent from a local file +filecontent_response = @filecontent_api.create('foo.tar.gz', {file: File.new(File.expand_path(__FILE__))}) + +created_resources = monitor_task(filecontent_response.task) + +# Add the new FileContent to a repository version +repo_version_data = {add_content_units: [created_resources[0]]} +repo_version_response = @filerepositories_api.modify(file_repository.pulp_href, repo_version_data) + +# Monitor the repo version creation task +created_resources = monitor_task(repo_version_response.task) + +repository_version_2 = @repoversions_api.read(created_resources[0]) + +# List all the repository versions +@repoversions_api.list(file_repository.pulp_href) + +# Create a publication from the latest version of the repository +publish_data = PulpFileClient::FileFilePublication.new({repository: file_repository.pulp_href}) +publish_response = @filepublications_api.create(publish_data) + +# Monitor the publish task +created_resources = monitor_task(publish_response.task) +publication_href = created_resources[0] + +distribution_data = PulpFileClient::FileFileDistribution.new({name: 'baz38', base_path: 'foo38', publication: publication_href}) +distribution = @filedistributions_api.create(distribution_data) diff --git a/test_ruby.sh b/test_ruby.sh new file mode 100644 index 0000000..5d4193e --- /dev/null +++ b/test_ruby.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# coding=utf-8 + +# WARNING: DO NOT EDIT! +# +# This file was generated by plugin_template, and is managed by it. Please use +# './plugin-template --github pulp_file' to update this file. +# +# For more info visit https://github.com/pulp/plugin_template + +set -mveuo pipefail + +# make sure this script runs at the repo root + +# Needed for both starting the service and building the docs. +# Gets set in .github/settings.yml, but doesn't seem to inherited by +# this script. +# export DJANGO_SETTINGS_MODULE="pulpcore.app.settings" +# export PULP_SETTINGS="$PWD/.ci/ansible/settings/settings.py" +export PULP_URL="http://localhost:5001" +# export CONTENT_ORIGIN="http://pulp:80" + +# Configure "isolated" ruby on host machine +# https://stackoverflow.com/a/17413767 +TMPDIR="/tmp/ruby-venv" +rm -rf $TMPDIR +mkdir -p $TMPDIR/local/gems +export GEM_HOME=$TMPDIR/local/gems + +# ./generate.sh pulpcore python +# pip install ./pulpcore-client +# ./generate.sh pulp_file python +# pip install ./pulp_file-client + +# python .github/workflows/scripts/test_bindings.py + +rm -rf ./pulpcore-client +./generate.sh pulpcore ruby +pushd pulpcore-client + gem build pulpcore_client + gem install --both ./pulpcore_client-*.gem +popd + +rm -rf ./pulp_file-client +./generate.sh pulp_file ruby +pushd pulp_file-client +gem build pulp_file_client +gem install --both ./pulp_file_client-*.gem +popd + +ruby test_bindings.rb