Skip to content

Commit c3a98b0

Browse files
Remove references to V3 internal API
In the main Rails app we use exactly the same code for /api/v3/internal and /api/v4/internal This means that we can move gitlab-shell to V4 in preparation for sunsetting V3
1 parent 1472f04 commit c3a98b0

19 files changed

+28
-42
lines changed

lib/gitlab_net.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {})
3333
params.merge!(user_id: actor.gsub("user-", ""))
3434
end
3535

36-
url = "#{host_v3}/allowed"
36+
url = "#{host}/allowed"
3737
resp = post(url, params)
3838

3939
if resp.code == '200'
@@ -45,7 +45,7 @@ def check_access(cmd, gl_repository, repo, actor, changes, protocol, env: {})
4545

4646
def discover(key)
4747
key_id = key.gsub("key-", "")
48-
resp = get("#{host_v3}/discover?key_id=#{key_id}")
48+
resp = get("#{host}/discover?key_id=#{key_id}")
4949
JSON.parse(resp.body) rescue nil
5050
end
5151

@@ -55,41 +55,41 @@ def lfs_authenticate(key, repo)
5555
key_id: key.gsub('key-', '')
5656
}
5757

58-
resp = post("#{host_v3}/lfs_authenticate", params)
58+
resp = post("#{host}/lfs_authenticate", params)
5959

6060
if resp.code == '200'
6161
GitlabLfsAuthentication.build_from_json(resp.body)
6262
end
6363
end
6464

6565
def broadcast_message
66-
resp = get("#{host_v3}/broadcast_message")
66+
resp = get("#{host}/broadcast_message")
6767
JSON.parse(resp.body) rescue {}
6868
end
6969

7070
def merge_request_urls(gl_repository, repo_path, changes)
7171
changes = changes.join("\n") unless changes.kind_of?(String)
7272
changes = changes.encode('UTF-8', 'ASCII', invalid: :replace, replace: '')
73-
url = "#{host_v3}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
73+
url = "#{host}/merge_request_urls?project=#{URI.escape(repo_path)}&changes=#{URI.escape(changes)}"
7474
url += "&gl_repository=#{URI.escape(gl_repository)}" if gl_repository
7575
resp = get(url)
7676
JSON.parse(resp.body) rescue []
7777
end
7878

7979
def check
80-
get("#{host_v3}/check", read_timeout: CHECK_TIMEOUT)
80+
get("#{host}/check", read_timeout: CHECK_TIMEOUT)
8181
end
8282

8383
def authorized_key(key)
84-
resp = get("#{host_v3}/authorized_keys?key=#{URI.escape(key, '+/=')}")
84+
resp = get("#{host}/authorized_keys?key=#{URI.escape(key, '+/=')}")
8585
JSON.parse(resp.body) if resp.code == "200"
8686
rescue
8787
nil
8888
end
8989

9090
def two_factor_recovery_codes(key)
9191
key_id = key.gsub('key-', '')
92-
resp = post("#{host_v3}/two_factor_recovery_codes", key_id: key_id)
92+
resp = post("#{host}/two_factor_recovery_codes", key_id: key_id)
9393

9494
JSON.parse(resp.body) if resp.code == '200'
9595
rescue
@@ -139,10 +139,6 @@ def config
139139
@config ||= GitlabConfig.new
140140
end
141141

142-
def host_v3
143-
"#{config.gitlab_url}/api/v3/internal"
144-
end
145-
146142
def host
147143
"#{config.gitlab_url}/api/v4/internal"
148144
end

spec/gitlab_net_spec.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
describe GitlabNet, vcr: true do
77
let(:gitlab_net) { GitlabNet.new }
88
let(:changes) { ['0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'] }
9-
let(:host_v3) { 'https://dev.gitlab.org/api/v3/internal' }
109
let(:host) { 'https://dev.gitlab.org/api/v4/internal' }
1110

1211
before do
13-
gitlab_net.stub(:host_v3).and_return(host_v3)
1412
gitlab_net.stub(:host).and_return(host)
1513
gitlab_net.stub(:secret_token).and_return('a123')
1614
end
@@ -100,13 +98,13 @@
10098
let(:encoded_changes) { "123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag" }
10199

102100
it "sends the given arguments as encoded URL parameters" do
103-
gitlab_net.should_receive(:get).with("#{host_v3}/merge_request_urls?project=#{repo_path}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
101+
gitlab_net.should_receive(:get).with("#{host}/merge_request_urls?project=#{repo_path}&changes=#{encoded_changes}&gl_repository=#{gl_repository}")
104102

105103
gitlab_net.merge_request_urls(gl_repository, repo_path, changes)
106104
end
107105

108106
it "omits the gl_repository parameter if it's nil" do
109-
gitlab_net.should_receive(:get).with("#{host_v3}/merge_request_urls?project=#{repo_path}&changes=#{encoded_changes}")
107+
gitlab_net.should_receive(:get).with("#{host}/merge_request_urls?project=#{repo_path}&changes=#{encoded_changes}")
110108

111109
gitlab_net.merge_request_urls(nil, repo_path, changes)
112110
end
@@ -280,14 +278,6 @@
280278
it("uses API version 4") { should include("api/v4") }
281279
end
282280

283-
describe :host_v3 do
284-
let(:net) { GitlabNet.new }
285-
subject { net.send :host_v3 }
286-
287-
it { should include(net.send(:config).gitlab_url) }
288-
it("uses API version 3") { should include("api/v3") }
289-
end
290-
291281
describe :http_client_for do
292282
subject { gitlab_net.send :http_client_for, URI('https://localhost/') }
293283
before do

spec/vcr_cassettes/allowed-pull.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/allowed-push.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/broadcast_message-none.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/broadcast_message-ok.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/check-ok.yml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/denied-pull.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/denied-push-with-user.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/vcr_cassettes/denied-push.yml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)