Commit 9798b19e authored by David Fernandez's avatar David Fernandez

Merge branch '356085-handle-response-from-registry-api' into 'master'

Handle 404 responses from the container registry import status API

See merge request gitlab-org/gitlab!83070
parents fdc50f26 cbb541ad
......@@ -53,8 +53,14 @@ module ContainerRegistry
# https://gitlab.com/gitlab-org/container-registry/-/blob/master/docs-gitlab/api.md#get-repository-import-status
def import_status(path)
with_import_token_faraday do |faraday_client|
body_hash = response_body(faraday_client.get(import_url_for(path)))
body_hash['status'] || 'error'
response = faraday_client.get(import_url_for(path))
# Temporary solution for https://gitlab.com/gitlab-org/gitlab/-/issues/356085#solutions
# this will trigger a `retry_pre_import`
break 'pre_import_failed' unless response.success?
body_hash = response_body(response)
body_hash&.fetch('status') || 'error'
end
end
......
......@@ -107,6 +107,7 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
describe '#import_status' do
subject { client.import_status(path) }
context 'with successful response' do
before do
stub_import_status(path, status)
end
......@@ -124,6 +125,15 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
end
end
context 'with non successful response' do
before do
stub_import_status(path, nil, status_code: 404)
end
it { is_expected.to eq('pre_import_failed') }
end
end
describe '#repository_details' do
let(:path) { 'namespace/path/to/repository' }
let(:response) { { foo: :bar, this: :is_a_test } }
......@@ -230,11 +240,11 @@ RSpec.describe ContainerRegistry::GitlabApiClient do
.to_return(status: status_code, body: '')
end
def stub_import_status(path, status)
def stub_import_status(path, status, status_code: 200)
stub_request(:get, "#{registry_api_url}/gitlab/v1/import/#{path}/")
.with(headers: { 'Accept' => described_class::JSON_TYPE, 'Authorization' => "bearer #{import_token}" })
.to_return(
status: 200,
status: status_code,
body: { status: status }.to_json,
headers: { content_type: 'application/json' }
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment