From 237f5751ec62fb83709095f717c7f92537ed98d2 Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Thu, 16 Dec 2021 16:56:33 +0200 Subject: [PATCH 1/8] Add Artifacts API client --- lib/travis/api/v3/artifacts_client.rb | 77 +++++++++++++++++++ lib/travis/api/v3/queries/artifacts_config.rb | 17 ++++ .../api/v3/renderer/artifacts_config.rb | 20 +++++ lib/travis/api/v3/routes.rb | 11 +++ lib/travis/api/v3/services.rb | 1 + .../v3/services/artifacts_config/create.rb | 10 +++ .../v3/services/artifacts_config/update.rb | 10 +++ lib/travis/config/defaults.rb | 3 +- 8 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 lib/travis/api/v3/artifacts_client.rb create mode 100644 lib/travis/api/v3/queries/artifacts_config.rb create mode 100644 lib/travis/api/v3/renderer/artifacts_config.rb create mode 100644 lib/travis/api/v3/services/artifacts_config/create.rb create mode 100644 lib/travis/api/v3/services/artifacts_config/update.rb diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb new file mode 100644 index 0000000000..b1bde1bfda --- /dev/null +++ b/lib/travis/api/v3/artifacts_client.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +module Travis::API::V3 + class ArtifactsClient + class ConfigurationError < StandardError; end + + def initialize(user_id) + @user_id = user_id + end + + def create_config(config, image_name = nil) + response = connection.post("/api/config/create", config: config, imageName: image_name) + + handle_errors_and_respond(response) do |body| + body + end + end + + def update_config(config, image_name = nil) + response = connection.post("/api/config/update", config: config, imageName: image_name) + + handle_errors_and_respond(response) do |body| + body + end + end + + private + + def handle_errors_and_respond(response) + pp response.body + case response.status + when 200, 201 + yield(response.body.transform_keys { |key| key.to_s.underscore }) if block_given? + when 202 + true + when 204 + true + when 400 + raise Travis::API::V3::ClientError, response.body.fetch('errors', []).join("\n") + when 403 + raise Travis::API::V3::InsufficientAccess, response.body['rejection_code'] + when 404 + raise Travis::API::V3::NotFound, response.body.fetch('errors', []).join("\n") + when 422 + raise Travis::API::V3::UnprocessableEntity, response.body.fetch('errors', []).join("\n") + else + raise Travis::API::V3::ServerError, 'Artifacts API failed' + end + end + + def connection(timeout: 10) + @connection ||= Faraday.new(url: artifacts_url, ssl: { ca_path: '/usr/lib/ssl/certs' }) do |conn| + conn.basic_auth '_', artifacts_auth_key + conn.headers['X-Travis-User-Id'] = @user_id.to_s + conn.headers['Content-Type'] = 'application/json' + conn.request :json + conn.response :json + conn.options[:open_timeout] = timeout + conn.options[:timeout] = timeout + conn.use OpenCensus::Trace::Integrations::FaradayMiddleware if Travis::Api::App::Middleware::OpenCensus.enabled? + conn.adapter :net_http + end + end + + def artifacts_url + Travis.config.artifacts.url || raise(ConfigurationError, 'No artifacts url configured') + end + + def artifacts_auth_key + Travis.config.artifacts.auth_key || raise(ConfigurationError, 'No artifacts auth key configured') + end + + def query_string_from_params(params) + params.delete_if { |_, v| v.nil? || v.empty? }.to_query + end + end +end \ No newline at end of file diff --git a/lib/travis/api/v3/queries/artifacts_config.rb b/lib/travis/api/v3/queries/artifacts_config.rb new file mode 100644 index 0000000000..ddafdde0c0 --- /dev/null +++ b/lib/travis/api/v3/queries/artifacts_config.rb @@ -0,0 +1,17 @@ +module Travis::API::V3 + class Queries::ArtifactsConfig < Query + params :config, :image_name + + def create(user_id) + artifacts_client(user_id).create_config(params['config'], params['image_name']) + end + + def update(user_id) + artifacts_client(user_id).update_config(params['config'], params['image_name']) + end + + def artifacts_client(user_id) + @_artifacts_client ||= ArtifactsClient.new(user_id) + end + end +end diff --git a/lib/travis/api/v3/renderer/artifacts_config.rb b/lib/travis/api/v3/renderer/artifacts_config.rb new file mode 100644 index 0000000000..bb5480567d --- /dev/null +++ b/lib/travis/api/v3/renderer/artifacts_config.rb @@ -0,0 +1,20 @@ +module Travis::API::V3 + module Renderer::ArtifactsConfig + extend self + + AVAILABLE_ATTRIBUTES = [:id, :image_name, :is_valid] + + def available_attributes + AVAILABLE_ATTRIBUTES + end + + def render(object, **) + { + '@type': 'artifacts_config'.freeze, + id: object['id'], + image_name: object['image_name'], + is_valid: object['is_valid'] + } + end + end +end \ No newline at end of file diff --git a/lib/travis/api/v3/routes.rb b/lib/travis/api/v3/routes.rb index 1826d80455..2d5008d54c 100644 --- a/lib/travis/api/v3/routes.rb +++ b/lib/travis/api/v3/routes.rb @@ -418,5 +418,16 @@ module Routes route '/leads' post :create end + + resource :artifacts do + route '/artifacts' + + resource :artifacts_config, as: :config do + route '/config' + + post :create, '/create' + post :update, '/update' + end + end end end diff --git a/lib/travis/api/v3/services.rb b/lib/travis/api/v3/services.rb index 59d5e67df9..0d44aaa3bc 100644 --- a/lib/travis/api/v3/services.rb +++ b/lib/travis/api/v3/services.rb @@ -5,6 +5,7 @@ module Services Accounts = Module.new { extend Services } Active = Module.new { extend Services } Allowance = Module.new { extend Services } + ArtifactsConfig = Module.new { extend Services } BetaFeature = Module.new { extend Services } BetaFeatures = Module.new { extend Services } BetaMigrationRequest = Module.new { extend Services } diff --git a/lib/travis/api/v3/services/artifacts_config/create.rb b/lib/travis/api/v3/services/artifacts_config/create.rb new file mode 100644 index 0000000000..1b4a7e0f6f --- /dev/null +++ b/lib/travis/api/v3/services/artifacts_config/create.rb @@ -0,0 +1,10 @@ +module Travis::API::V3 + class Services::ArtifactsConfig::Create < Service + params :config, :image_name + + def run! + raise LoginRequired unless access_control.full_access_or_logged_in? + result query(:artifacts_config).create(access_control.user.id) + end + end +end diff --git a/lib/travis/api/v3/services/artifacts_config/update.rb b/lib/travis/api/v3/services/artifacts_config/update.rb new file mode 100644 index 0000000000..2881c58ffb --- /dev/null +++ b/lib/travis/api/v3/services/artifacts_config/update.rb @@ -0,0 +1,10 @@ +module Travis::API::V3 + class Services::ArtifactsConfig::Update < Service + params :config, :image_name + + def run! + raise LoginRequired unless access_control.full_access_or_logged_in? + result query(:artifacts_config).update(access_control.user.id) + end + end +end diff --git a/lib/travis/config/defaults.rb b/lib/travis/config/defaults.rb index caedc2019c..f948dde159 100644 --- a/lib/travis/config/defaults.rb +++ b/lib/travis/config/defaults.rb @@ -88,7 +88,8 @@ def fallback_logs_api_auth_token force_authentication: false, yml: { url: 'https://yml.travis-ci.org', token: 'secret', auth_key: 'abc123' }, read_only: ENV['READ_ONLY'] || false, - vcs: {} + vcs: {}, + artifacts: { url: 'http://artifacts:5001', auth_key: 'VALIDTOKEN' } default :_access => [:key] From 26bae5f8a268265d45262e52b019e9bcbc877e3e Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Fri, 17 Dec 2021 16:48:13 +0200 Subject: [PATCH 2/8] Add artifacts image endpoints --- lib/travis/api/v3/artifacts_client.rb | 23 ++++++++++++++++++- lib/travis/api/v3/queries/artifacts_image.rb | 21 +++++++++++++++++ .../api/v3/renderer/artifacts_config.rb | 6 +++-- lib/travis/api/v3/routes.rb | 12 ++++++++-- lib/travis/api/v3/services.rb | 1 + .../api/v3/services/artifacts_image/delete.rb | 10 ++++++++ .../api/v3/services/artifacts_image/info.rb | 10 ++++++++ .../api/v3/services/artifacts_image/logs.rb | 10 ++++++++ 8 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 lib/travis/api/v3/queries/artifacts_image.rb create mode 100644 lib/travis/api/v3/services/artifacts_image/delete.rb create mode 100644 lib/travis/api/v3/services/artifacts_image/info.rb create mode 100644 lib/travis/api/v3/services/artifacts_image/logs.rb diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb index b1bde1bfda..5bb1d2d3e8 100644 --- a/lib/travis/api/v3/artifacts_client.rb +++ b/lib/travis/api/v3/artifacts_client.rb @@ -24,10 +24,31 @@ def update_config(config, image_name = nil) end end + def image_logs(image_name) + response = connection.get("/api/#{image_name}/logs") + + handle_errors_and_respond(response) do |body| + body + end + end + + def image_info(image_name) + response = connection.get("/api/#{image_name}/info") + + handle_errors_and_respond(response) do |body| + body + end + end + + def delete_image(image_name) + response = connection.delete("/api/#{image_name}", config: config, imageName: image_name) + + handle_errors_and_respond(response) + end + private def handle_errors_and_respond(response) - pp response.body case response.status when 200, 201 yield(response.body.transform_keys { |key| key.to_s.underscore }) if block_given? diff --git a/lib/travis/api/v3/queries/artifacts_image.rb b/lib/travis/api/v3/queries/artifacts_image.rb new file mode 100644 index 0000000000..750dad8136 --- /dev/null +++ b/lib/travis/api/v3/queries/artifacts_image.rb @@ -0,0 +1,21 @@ +module Travis::API::V3 + class Queries::ArtifactsImage < Query + params :image_name + + def logs(user_id) + artifacts_client(user_id).image_logs(params['image_name']) + end + + def info(user_id) + artifacts_client(user_id).image_info(params['image_name']) + end + + def delete(user_id) + artifacts_client(user_id).delete_image(params['image_name']) + end + + def artifacts_client(user_id) + @_artifacts_client ||= ArtifactsClient.new(user_id) + end + end +end diff --git a/lib/travis/api/v3/renderer/artifacts_config.rb b/lib/travis/api/v3/renderer/artifacts_config.rb index bb5480567d..56223a0f7f 100644 --- a/lib/travis/api/v3/renderer/artifacts_config.rb +++ b/lib/travis/api/v3/renderer/artifacts_config.rb @@ -2,7 +2,7 @@ module Travis::API::V3 module Renderer::ArtifactsConfig extend self - AVAILABLE_ATTRIBUTES = [:id, :image_name, :is_valid] + AVAILABLE_ATTRIBUTES = [:id, :image_name, :is_valid, :is_pushed, :push_sha] def available_attributes AVAILABLE_ATTRIBUTES @@ -13,7 +13,9 @@ def render(object, **) '@type': 'artifacts_config'.freeze, id: object['id'], image_name: object['image_name'], - is_valid: object['is_valid'] + is_valid: object['is_valid'], + is_pushed: object['is_pushed'], + push_sha: object['push_sha'] } end end diff --git a/lib/travis/api/v3/routes.rb b/lib/travis/api/v3/routes.rb index 2d5008d54c..b5e2f99618 100644 --- a/lib/travis/api/v3/routes.rb +++ b/lib/travis/api/v3/routes.rb @@ -419,15 +419,23 @@ module Routes post :create end - resource :artifacts do + hidden_resource :artifacts do route '/artifacts' - resource :artifacts_config, as: :config do + hidden_resource :artifacts_config, as: :config do route '/config' post :create, '/create' post :update, '/update' end + + hidden_resource :artifacts_image do + route '/{image_name}' + + get :logs, '/logs' + get :info, '/info' + delete :delete + end end end end diff --git a/lib/travis/api/v3/services.rb b/lib/travis/api/v3/services.rb index 0d44aaa3bc..4f13ce390a 100644 --- a/lib/travis/api/v3/services.rb +++ b/lib/travis/api/v3/services.rb @@ -6,6 +6,7 @@ module Services Active = Module.new { extend Services } Allowance = Module.new { extend Services } ArtifactsConfig = Module.new { extend Services } + ArtifactsImage = Module.new { extend Services } BetaFeature = Module.new { extend Services } BetaFeatures = Module.new { extend Services } BetaMigrationRequest = Module.new { extend Services } diff --git a/lib/travis/api/v3/services/artifacts_image/delete.rb b/lib/travis/api/v3/services/artifacts_image/delete.rb new file mode 100644 index 0000000000..498e758b1f --- /dev/null +++ b/lib/travis/api/v3/services/artifacts_image/delete.rb @@ -0,0 +1,10 @@ +module Travis::API::V3 + class Services::ArtifactsImage::Delete < Service + params :image_name + + def run! + raise LoginRequired unless access_control.full_access_or_logged_in? + query(:artifacts_image).delete(access_control.user.id) and deleted + end + end +end diff --git a/lib/travis/api/v3/services/artifacts_image/info.rb b/lib/travis/api/v3/services/artifacts_image/info.rb new file mode 100644 index 0000000000..a4591b6487 --- /dev/null +++ b/lib/travis/api/v3/services/artifacts_image/info.rb @@ -0,0 +1,10 @@ +module Travis::API::V3 + class Services::ArtifactsImage::Info < Service + params :image_name + + def run! + raise LoginRequired unless access_control.full_access_or_logged_in? + result query(:artifacts_info).info(access_control.user.id) + end + end +end diff --git a/lib/travis/api/v3/services/artifacts_image/logs.rb b/lib/travis/api/v3/services/artifacts_image/logs.rb new file mode 100644 index 0000000000..f68d031374 --- /dev/null +++ b/lib/travis/api/v3/services/artifacts_image/logs.rb @@ -0,0 +1,10 @@ +module Travis::API::V3 + class Services::ArtifactsImage::Logs < Service + params :image_name + + def run! + raise LoginRequired unless access_control.full_access_or_logged_in? + result query(:artifacts_image).logs(access_control.user.id) + end + end +end From 86c3d8f19b0b7288ce331cabd27e59d47cf04e80 Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Tue, 21 Dec 2021 17:08:50 +0200 Subject: [PATCH 3/8] Add artifacts_image_info --- lib/travis/api/v3/artifacts_client.rb | 6 +++--- .../api/v3/renderer/artifacts_image_info.rb | 21 +++++++++++++++++++ .../api/v3/services/artifacts_image/info.rb | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 lib/travis/api/v3/renderer/artifacts_image_info.rb diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb index 5bb1d2d3e8..ed6a8b11d6 100644 --- a/lib/travis/api/v3/artifacts_client.rb +++ b/lib/travis/api/v3/artifacts_client.rb @@ -57,13 +57,13 @@ def handle_errors_and_respond(response) when 204 true when 400 - raise Travis::API::V3::ClientError, response.body.fetch('errors', []).join("\n") + raise Travis::API::V3::ClientError, response.body.fetch('errors', response.body.fetch('Errors', [])).join("\n") when 403 raise Travis::API::V3::InsufficientAccess, response.body['rejection_code'] when 404 - raise Travis::API::V3::NotFound, response.body.fetch('errors', []).join("\n") + raise Travis::API::V3::NotFound, response.body.fetch('errors', response.body.fetch('Errors', [])).join("\n") when 422 - raise Travis::API::V3::UnprocessableEntity, response.body.fetch('errors', []).join("\n") + raise Travis::API::V3::UnprocessableEntity, response.body.fetch('errors', response.body.fetch('Errors', [])).join("\n") else raise Travis::API::V3::ServerError, 'Artifacts API failed' end diff --git a/lib/travis/api/v3/renderer/artifacts_image_info.rb b/lib/travis/api/v3/renderer/artifacts_image_info.rb new file mode 100644 index 0000000000..fd4e772dee --- /dev/null +++ b/lib/travis/api/v3/renderer/artifacts_image_info.rb @@ -0,0 +1,21 @@ +module Travis::API::V3 + module Renderer::ArtifactsImageInfo + extend self + + AVAILABLE_ATTRIBUTES = [:name, :config_content, :description, :image_size] + + def available_attributes + AVAILABLE_ATTRIBUTES + end + + def render(object, **) + { + '@type': 'artifacts_image_info'.freeze, + name: object['name'], + config_content: object['config_content'], + description: object['description'], + image_size: object['image_size'] + } + end + end +end \ No newline at end of file diff --git a/lib/travis/api/v3/services/artifacts_image/info.rb b/lib/travis/api/v3/services/artifacts_image/info.rb index a4591b6487..ce63c876b9 100644 --- a/lib/travis/api/v3/services/artifacts_image/info.rb +++ b/lib/travis/api/v3/services/artifacts_image/info.rb @@ -1,10 +1,11 @@ module Travis::API::V3 class Services::ArtifactsImage::Info < Service params :image_name + result_type :artifacts_image_info def run! raise LoginRequired unless access_control.full_access_or_logged_in? - result query(:artifacts_info).info(access_control.user.id) + result query(:artifacts_image).info(access_control.user.id) end end end From 639d796848b9765a64bc7bdc4eb9478f66caaf14 Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Wed, 22 Dec 2021 16:10:17 +0200 Subject: [PATCH 4/8] Add TAM image build status endpoint --- lib/travis/api/v3/artifacts_client.rb | 8 ++++++++ lib/travis/api/v3/queries/artifacts_image.rb | 4 ++++ .../renderer/artifacts_image_build_status.rb | 19 +++++++++++++++++++ .../api/v3/renderer/artifacts_image_logs.rb | 19 +++++++++++++++++++ lib/travis/api/v3/routes.rb | 1 + .../services/artifacts_image/build_status.rb | 12 ++++++++++++ .../api/v3/services/artifacts_image/logs.rb | 1 + 7 files changed, 64 insertions(+) create mode 100644 lib/travis/api/v3/renderer/artifacts_image_build_status.rb create mode 100644 lib/travis/api/v3/renderer/artifacts_image_logs.rb create mode 100644 lib/travis/api/v3/services/artifacts_image/build_status.rb diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb index ed6a8b11d6..cbf0f4afc3 100644 --- a/lib/travis/api/v3/artifacts_client.rb +++ b/lib/travis/api/v3/artifacts_client.rb @@ -46,6 +46,14 @@ def delete_image(image_name) handle_errors_and_respond(response) end + def image_build_status(image_name) + response = connection.get("/api/#{image_name}/build_status") + + handle_errors_and_respond(response) do |body| + body + end + end + private def handle_errors_and_respond(response) diff --git a/lib/travis/api/v3/queries/artifacts_image.rb b/lib/travis/api/v3/queries/artifacts_image.rb index 750dad8136..1e98831a5a 100644 --- a/lib/travis/api/v3/queries/artifacts_image.rb +++ b/lib/travis/api/v3/queries/artifacts_image.rb @@ -13,6 +13,10 @@ def info(user_id) def delete(user_id) artifacts_client(user_id).delete_image(params['image_name']) end + + def build_status(user_id) + artifacts_client(user_id).image_build_status(params['image_name']) + end def artifacts_client(user_id) @_artifacts_client ||= ArtifactsClient.new(user_id) diff --git a/lib/travis/api/v3/renderer/artifacts_image_build_status.rb b/lib/travis/api/v3/renderer/artifacts_image_build_status.rb new file mode 100644 index 0000000000..212be87fce --- /dev/null +++ b/lib/travis/api/v3/renderer/artifacts_image_build_status.rb @@ -0,0 +1,19 @@ +module Travis::API::V3 + module Renderer::ArtifactsImageBuildStatus + extend self + + AVAILABLE_ATTRIBUTES = [:name, :status] + + def available_attributes + AVAILABLE_ATTRIBUTES + end + + def render(object, **) + { + '@type': 'artifacts_image_build_status'.freeze, + name: object['name'], + status: object['status'] + } + end + end +end \ No newline at end of file diff --git a/lib/travis/api/v3/renderer/artifacts_image_logs.rb b/lib/travis/api/v3/renderer/artifacts_image_logs.rb new file mode 100644 index 0000000000..a7f8beb760 --- /dev/null +++ b/lib/travis/api/v3/renderer/artifacts_image_logs.rb @@ -0,0 +1,19 @@ +module Travis::API::V3 + module Renderer::ArtifactsImageLogs + extend self + + AVAILABLE_ATTRIBUTES = [:name, :log] + + def available_attributes + AVAILABLE_ATTRIBUTES + end + + def render(object, **) + { + '@type': 'artifacts_image_logs'.freeze, + name: object['name'], + log: object['log'] + } + end + end +end \ No newline at end of file diff --git a/lib/travis/api/v3/routes.rb b/lib/travis/api/v3/routes.rb index b5e2f99618..b99a308765 100644 --- a/lib/travis/api/v3/routes.rb +++ b/lib/travis/api/v3/routes.rb @@ -434,6 +434,7 @@ module Routes get :logs, '/logs' get :info, '/info' + get :build_status, '/build_status' delete :delete end end diff --git a/lib/travis/api/v3/services/artifacts_image/build_status.rb b/lib/travis/api/v3/services/artifacts_image/build_status.rb new file mode 100644 index 0000000000..68d587b893 --- /dev/null +++ b/lib/travis/api/v3/services/artifacts_image/build_status.rb @@ -0,0 +1,12 @@ +module Travis::API::V3 + class Services::ArtifactsImage::BuildStatus < Service + params :image_name + result_type :artifacts_image_build_status + + def run! + raise LoginRequired unless access_control.full_access_or_logged_in? + result query(:artifacts_image).build_status(access_control.user.id) + end + end + end + \ No newline at end of file diff --git a/lib/travis/api/v3/services/artifacts_image/logs.rb b/lib/travis/api/v3/services/artifacts_image/logs.rb index f68d031374..bed9897199 100644 --- a/lib/travis/api/v3/services/artifacts_image/logs.rb +++ b/lib/travis/api/v3/services/artifacts_image/logs.rb @@ -1,6 +1,7 @@ module Travis::API::V3 class Services::ArtifactsImage::Logs < Service params :image_name + result_type :artifacts_image_logs def run! raise LoginRequired unless access_control.full_access_or_logged_in? From b041387e41361cf3bc19b72d870655ace13e2846 Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Thu, 23 Dec 2021 17:53:50 +0200 Subject: [PATCH 5/8] Add artifacts image config warnings --- lib/travis/api/v3/renderer/artifacts_config.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/v3/renderer/artifacts_config.rb b/lib/travis/api/v3/renderer/artifacts_config.rb index 56223a0f7f..ac0f35c7a5 100644 --- a/lib/travis/api/v3/renderer/artifacts_config.rb +++ b/lib/travis/api/v3/renderer/artifacts_config.rb @@ -2,7 +2,7 @@ module Travis::API::V3 module Renderer::ArtifactsConfig extend self - AVAILABLE_ATTRIBUTES = [:id, :image_name, :is_valid, :is_pushed, :push_sha] + AVAILABLE_ATTRIBUTES = [:id, :image_name, :is_valid, :is_pushed, :push_sha, :warnings] def available_attributes AVAILABLE_ATTRIBUTES @@ -15,7 +15,8 @@ def render(object, **) image_name: object['image_name'], is_valid: object['is_valid'], is_pushed: object['is_pushed'], - push_sha: object['push_sha'] + push_sha: object['push_sha'], + warnings: object['warnings'] } end end From 032af5a9b70929cceaf3aed4ad4bc629c4aa5b30 Mon Sep 17 00:00:00 2001 From: Stanislav Kolotinskiy Date: Fri, 28 Jan 2022 10:18:51 +0200 Subject: [PATCH 6/8] Fix delete_image endpoint --- lib/travis/api/v3/artifacts_client.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb index cbf0f4afc3..f4cbc4091b 100644 --- a/lib/travis/api/v3/artifacts_client.rb +++ b/lib/travis/api/v3/artifacts_client.rb @@ -41,7 +41,7 @@ def image_info(image_name) end def delete_image(image_name) - response = connection.delete("/api/#{image_name}", config: config, imageName: image_name) + response = connection.delete("/api/#{image_name}") handle_errors_and_respond(response) end @@ -103,4 +103,4 @@ def query_string_from_params(params) params.delete_if { |_, v| v.nil? || v.empty? }.to_query end end -end \ No newline at end of file +end From 84cd67d885840674f8ad006ecda7536d9e56429e Mon Sep 17 00:00:00 2001 From: Andrii Mysko Date: Thu, 3 Feb 2022 14:13:28 +0200 Subject: [PATCH 7/8] Escape tam image name --- lib/travis/api/v3/artifacts_client.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb index f4cbc4091b..ad3ad44a2d 100644 --- a/lib/travis/api/v3/artifacts_client.rb +++ b/lib/travis/api/v3/artifacts_client.rb @@ -25,7 +25,7 @@ def update_config(config, image_name = nil) end def image_logs(image_name) - response = connection.get("/api/#{image_name}/logs") + response = connection.get("/api/#{CGI.escape(image_name)}/logs") handle_errors_and_respond(response) do |body| body @@ -33,7 +33,7 @@ def image_logs(image_name) end def image_info(image_name) - response = connection.get("/api/#{image_name}/info") + response = connection.get("/api/#{CGI.escape(image_name)}/info") handle_errors_and_respond(response) do |body| body @@ -41,13 +41,13 @@ def image_info(image_name) end def delete_image(image_name) - response = connection.delete("/api/#{image_name}") + response = connection.delete("/api/#{CGI.escape(image_name)}") handle_errors_and_respond(response) end def image_build_status(image_name) - response = connection.get("/api/#{image_name}/build_status") + response = connection.get("/api/#{CGI.escape(image_name)}/build_status") handle_errors_and_respond(response) do |body| body From 7cc460861f8493671ba9ad1a22412990195695e1 Mon Sep 17 00:00:00 2001 From: Stanislav Kolotinskiy Date: Thu, 3 Feb 2022 19:20:03 +0200 Subject: [PATCH 8/8] Fix image deletion --- lib/travis/api/v3/artifacts_client.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/travis/api/v3/artifacts_client.rb b/lib/travis/api/v3/artifacts_client.rb index ad3ad44a2d..53f19fbfe2 100644 --- a/lib/travis/api/v3/artifacts_client.rb +++ b/lib/travis/api/v3/artifacts_client.rb @@ -44,6 +44,8 @@ def delete_image(image_name) response = connection.delete("/api/#{CGI.escape(image_name)}") handle_errors_and_respond(response) + + true end def image_build_status(image_name)