Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-shell
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-shell
Commits
e865251e
Commit
e865251e
authored
Jul 19, 2018
by
Ash McKenzie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename HTTPHelper#host to #internal_api_endpoint
parent
dd4bd1d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
20 deletions
+20
-20
lib/gitlab_net.rb
lib/gitlab_net.rb
+11
-11
lib/http_helper.rb
lib/http_helper.rb
+1
-1
spec/gitlab_net_spec.rb
spec/gitlab_net_spec.rb
+8
-8
No files found.
lib/gitlab_net.rb
View file @
e865251e
...
...
@@ -35,7 +35,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
params
[
:user_id
]
=
actor
.
gsub
(
"user-"
,
""
)
end
url
=
"
#{
hos
t
}
/allowed"
url
=
"
#{
internal_api_endpoin
t
}
/allowed"
resp
=
post
(
url
,
params
)
if
resp
.
code
==
'200'
...
...
@@ -52,7 +52,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def
discover
(
key
)
key_id
=
key
.
gsub
(
"key-"
,
""
)
resp
=
get
(
"
#{
hos
t
}
/discover?key_id=
#{
key_id
}
"
)
resp
=
get
(
"
#{
internal_api_endpoin
t
}
/discover?key_id=
#{
key_id
}
"
)
JSON
.
parse
(
resp
.
body
)
rescue
nil
end
...
...
@@ -62,7 +62,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
key_id:
key
.
gsub
(
'key-'
,
''
)
}
resp
=
post
(
"
#{
hos
t
}
/lfs_authenticate"
,
params
)
resp
=
post
(
"
#{
internal_api_endpoin
t
}
/lfs_authenticate"
,
params
)
if
resp
.
code
==
'200'
GitlabLfsAuthentication
.
build_from_json
(
resp
.
body
)
...
...
@@ -70,14 +70,14 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def
broadcast_message
resp
=
get
(
"
#{
hos
t
}
/broadcast_message"
)
resp
=
get
(
"
#{
internal_api_endpoin
t
}
/broadcast_message"
)
JSON
.
parse
(
resp
.
body
)
rescue
{}
end
def
merge_request_urls
(
gl_repository
,
repo_path
,
changes
)
changes
=
changes
.
join
(
"
\n
"
)
unless
changes
.
is_a?
(
String
)
changes
=
changes
.
encode
(
'UTF-8'
,
'ASCII'
,
invalid: :replace
,
replace:
''
)
url
=
"
#{
hos
t
}
/merge_request_urls?project=
#{
URI
.
escape
(
repo_path
)
}
&changes=
#{
URI
.
escape
(
changes
)
}
"
url
=
"
#{
internal_api_endpoin
t
}
/merge_request_urls?project=
#{
URI
.
escape
(
repo_path
)
}
&changes=
#{
URI
.
escape
(
changes
)
}
"
url
+=
"&gl_repository=
#{
URI
.
escape
(
gl_repository
)
}
"
if
gl_repository
resp
=
get
(
url
)
...
...
@@ -91,11 +91,11 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def
check
get
(
"
#{
hos
t
}
/check"
,
read_timeout:
CHECK_TIMEOUT
)
get
(
"
#{
internal_api_endpoin
t
}
/check"
,
read_timeout:
CHECK_TIMEOUT
)
end
def
authorized_key
(
key
)
resp
=
get
(
"
#{
hos
t
}
/authorized_keys?key=
#{
URI
.
escape
(
key
,
'+/='
)
}
"
)
resp
=
get
(
"
#{
internal_api_endpoin
t
}
/authorized_keys?key=
#{
URI
.
escape
(
key
,
'+/='
)
}
"
)
JSON
.
parse
(
resp
.
body
)
if
resp
.
code
==
"200"
rescue
nil
...
...
@@ -103,7 +103,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def
two_factor_recovery_codes
(
key
)
key_id
=
key
.
gsub
(
'key-'
,
''
)
resp
=
post
(
"
#{
hos
t
}
/two_factor_recovery_codes"
,
key_id:
key_id
)
resp
=
post
(
"
#{
internal_api_endpoin
t
}
/two_factor_recovery_codes"
,
key_id:
key_id
)
JSON
.
parse
(
resp
.
body
)
if
resp
.
code
==
'200'
rescue
...
...
@@ -112,7 +112,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
def
notify_post_receive
(
gl_repository
,
repo_path
)
params
=
{
gl_repository:
gl_repository
,
project:
repo_path
}
resp
=
post
(
"
#{
hos
t
}
/notify_post_receive"
,
params
)
resp
=
post
(
"
#{
internal_api_endpoin
t
}
/notify_post_receive"
,
params
)
resp
.
code
==
'200'
rescue
...
...
@@ -125,7 +125,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
identifier:
identifier
,
changes:
changes
}
resp
=
post
(
"
#{
hos
t
}
/post_receive"
,
params
)
resp
=
post
(
"
#{
internal_api_endpoin
t
}
/post_receive"
,
params
)
raise
NotFound
if
resp
.
code
==
'404'
...
...
@@ -133,7 +133,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def
pre_receive
(
gl_repository
)
resp
=
post
(
"
#{
hos
t
}
/pre_receive"
,
gl_repository:
gl_repository
)
resp
=
post
(
"
#{
internal_api_endpoin
t
}
/pre_receive"
,
gl_repository:
gl_repository
)
raise
NotFound
if
resp
.
code
==
'404'
...
...
lib/http_helper.rb
View file @
e865251e
...
...
@@ -11,7 +11,7 @@ module HTTPHelper
"
#{
config
.
gitlab_url
}
/api/v4"
end
def
hos
t
def
internal_api_endpoin
t
"
#{
base_api_endpoint
}
/internal"
end
...
...
spec/gitlab_net_spec.rb
View file @
e865251e
...
...
@@ -5,14 +5,14 @@ require_relative '../lib/gitlab_access_status'
describe
GitlabNet
,
vcr:
true
do
let
(
:gitlab_net
)
{
GitlabNet
.
new
}
let
(
:changes
)
{
[
'0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4'
]
}
let
(
:
hos
t
)
{
'http://localhost:3000/api/v4/internal'
}
let
(
:
internal_api_endpoin
t
)
{
'http://localhost:3000/api/v4/internal'
}
let
(
:project
)
{
'gitlab-org/gitlab-test.git'
}
let
(
:key
)
{
'key-1'
}
let
(
:key2
)
{
'key-2'
}
let
(
:secret
)
{
"0a3938d9d95d807e94d937af3a4fbbea
\n
"
}
before
do
gitlab_net
.
stub
(
:
host
).
and_return
(
hos
t
)
gitlab_net
.
stub
(
:
internal_api_endpoint
).
and_return
(
internal_api_endpoin
t
)
gitlab_net
.
stub
(
:secret_token
).
and_return
(
secret
)
end
...
...
@@ -68,7 +68,7 @@ describe GitlabNet, vcr: true do
lfs_access
=
gitlab_net
.
lfs_authenticate
(
key
,
project
)
lfs_access
.
username
.
should
==
'root'
lfs_access
.
lfs_token
.
should
==
'Hyzhyde_wLUeyUQsR3tHGTG8eNocVQm4ssioTEsBSdb6KwCSzQ'
lfs_access
.
repository_http_path
.
should
==
URI
.
join
(
hos
t
.
sub
(
'api/v4'
,
''
),
project
).
to_s
lfs_access
.
repository_http_path
.
should
==
URI
.
join
(
internal_api_endpoin
t
.
sub
(
'api/v4'
,
''
),
project
).
to_s
end
end
end
...
...
@@ -100,13 +100,13 @@ describe GitlabNet, vcr: true do
let
(
:encoded_changes
)
{
"123456%20789012%20refs/heads/test%0A654321%20210987%20refs/tags/tag"
}
it
"sends the given arguments as encoded URL parameters"
do
gitlab_net
.
should_receive
(
:get
).
with
(
"
#{
hos
t
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
&gl_repository=
#{
gl_repository
}
"
)
gitlab_net
.
should_receive
(
:get
).
with
(
"
#{
internal_api_endpoin
t
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
&gl_repository=
#{
gl_repository
}
"
)
gitlab_net
.
merge_request_urls
(
gl_repository
,
project
,
changes
)
end
it
"omits the gl_repository parameter if it's nil"
do
gitlab_net
.
should_receive
(
:get
).
with
(
"
#{
hos
t
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
"
)
gitlab_net
.
should_receive
(
:get
).
with
(
"
#{
internal_api_endpoin
t
}
/merge_request_urls?project=
#{
project
}
&changes=
#{
encoded_changes
}
"
)
gitlab_net
.
merge_request_urls
(
nil
,
project
,
changes
)
end
...
...
@@ -361,12 +361,12 @@ describe GitlabNet, vcr: true do
it
(
"uses API version 4"
)
{
should
end_with
(
"api/v4"
)
}
end
describe
:
hos
t
do
describe
:
internal_api_endpoin
t
do
let
(
:net
)
{
GitlabNet
.
new
}
subject
{
net
.
send
:
hos
t
}
subject
{
net
.
send
:
internal_api_endpoin
t
}
it
{
should
include
(
net
.
send
(
:config
).
gitlab_url
)
}
it
(
"uses API version 4"
)
{
should
include
(
"api/v4
"
)
}
it
(
"uses API version 4"
)
{
should
end_with
(
"api/v4/internal
"
)
}
end
describe
:http_client_for
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment