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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-shell
Commits
0c25846d
Commit
0c25846d
authored
Feb 10, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-shell into fix/ruby-2.2-webrick
parents
79e05b28
6a88498b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
config.yml.example
config.yml.example
+3
-2
lib/gitlab_net.rb
lib/gitlab_net.rb
+20
-6
spec/gitlab_net_spec.rb
spec/gitlab_net_spec.rb
+1
-1
No files found.
config.yml.example
View file @
0c25846d
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
# GitLab user. git by default
# GitLab user. git by default
user: git
user: git
# U
rl to gitlab instance. Used for api calls
.
# U
RL to GitLab instance, used for API calls. Default: http://localhost:8080
.
#
Default: http://localhost:8080
#
For relative URL support read http://doc.gitlab.com/ce/install/relative_url.html
# You only have to change the default if you have configured Unicorn
# You only have to change the default if you have configured Unicorn
# to listen on a custom port, or if you have configured Unicorn to
# to listen on a custom port, or if you have configured Unicorn to
# only listen on a Unix domain socket. For Unix domain sockets use
# only listen on a Unix domain socket. For Unix domain sockets use
...
@@ -17,6 +17,7 @@ gitlab_url: "http://localhost:8080"
...
@@ -17,6 +17,7 @@ gitlab_url: "http://localhost:8080"
# See installation.md#using-https for additional HTTPS configuration details.
# See installation.md#using-https for additional HTTPS configuration details.
http_settings:
http_settings:
# read_timeout: 300
# user: someone
# user: someone
# password: somepass
# password: somepass
# ca_file: /etc/ssl/cert.pem
# ca_file: /etc/ssl/cert.pem
...
...
lib/gitlab_net.rb
View file @
0c25846d
...
@@ -10,6 +10,9 @@ require_relative 'httpunix'
...
@@ -10,6 +10,9 @@ require_relative 'httpunix'
class
GitlabNet
class
GitlabNet
class
ApiUnreachableError
<
StandardError
;
end
class
ApiUnreachableError
<
StandardError
;
end
CHECK_TIMEOUT
=
5
READ_TIMEOUT
=
300
def
check_access
(
cmd
,
repo
,
actor
,
changes
)
def
check_access
(
cmd
,
repo
,
actor
,
changes
)
project_name
=
repo
.
gsub
(
"'"
,
""
)
project_name
=
repo
.
gsub
(
"'"
,
""
)
project_name
=
project_name
.
gsub
(
/\.git\Z/
,
""
)
project_name
=
project_name
.
gsub
(
/\.git\Z/
,
""
)
...
@@ -50,7 +53,7 @@ class GitlabNet
...
@@ -50,7 +53,7 @@ class GitlabNet
end
end
def
check
def
check
get
(
"
#{
host
}
/check"
)
get
(
"
#{
host
}
/check"
,
read_timeout:
CHECK_TIMEOUT
)
end
end
protected
protected
...
@@ -63,13 +66,15 @@ class GitlabNet
...
@@ -63,13 +66,15 @@ class GitlabNet
"
#{
config
.
gitlab_url
}
/api/v3/internal"
"
#{
config
.
gitlab_url
}
/api/v3/internal"
end
end
def
http_client_for
(
uri
)
def
http_client_for
(
uri
,
options
=
{}
)
if
uri
.
is_a?
(
URI
::
HTTPUNIX
)
if
uri
.
is_a?
(
URI
::
HTTPUNIX
)
http
=
Net
::
HTTPUNIX
.
new
(
uri
.
hostname
)
http
=
Net
::
HTTPUNIX
.
new
(
uri
.
hostname
)
else
else
http
=
Net
::
HTTP
.
new
(
uri
.
host
,
uri
.
port
)
http
=
Net
::
HTTP
.
new
(
uri
.
host
,
uri
.
port
)
end
end
http
.
read_timeout
=
options
[
:read_timeout
]
||
read_timeout
if
uri
.
is_a?
(
URI
::
HTTPS
)
if
uri
.
is_a?
(
URI
::
HTTPS
)
http
.
use_ssl
=
true
http
.
use_ssl
=
true
http
.
cert_store
=
cert_store
http
.
cert_store
=
cert_store
...
@@ -92,19 +97,24 @@ class GitlabNet
...
@@ -92,19 +97,24 @@ class GitlabNet
request
request
end
end
def
request
(
method
,
url
,
params
=
{})
def
request
(
method
,
url
,
params
=
{}
,
options
=
{}
)
$logger
.
debug
"Performing
#{
method
.
to_s
.
upcase
}
#{
url
}
"
$logger
.
debug
"Performing
#{
method
.
to_s
.
upcase
}
#{
url
}
"
uri
=
URI
.
parse
(
url
)
uri
=
URI
.
parse
(
url
)
http
=
http_client_for
(
uri
)
http
=
http_client_for
(
uri
,
options
)
request
=
http_request_for
(
method
,
uri
,
params
)
request
=
http_request_for
(
method
,
uri
,
params
)
begin
begin
start_time
=
Time
.
new
response
=
http
.
start
{
http
.
request
(
request
)
}
response
=
http
.
start
{
http
.
request
(
request
)
}
rescue
=>
e
rescue
=>
e
$logger
.
warn
"Failed to connect to internal API <
#{
method
.
to_s
.
upcase
}
#{
url
}
>:
#{
e
.
inspect
}
"
$logger
.
warn
"Failed to connect to internal API <
#{
method
.
to_s
.
upcase
}
#{
url
}
>:
#{
e
.
inspect
}
"
raise
ApiUnreachableError
raise
ApiUnreachableError
ensure
$logger
.
info
do
sprintf
(
'%s %s %0.5f'
,
method
.
to_s
.
upcase
,
url
,
Time
.
new
-
start_time
)
end
end
end
if
response
.
code
==
"200"
if
response
.
code
==
"200"
...
@@ -116,8 +126,8 @@ class GitlabNet
...
@@ -116,8 +126,8 @@ class GitlabNet
response
response
end
end
def
get
(
url
)
def
get
(
url
,
options
=
{}
)
request
(
:get
,
url
)
request
(
:get
,
url
,
{},
options
)
end
end
def
post
(
url
,
params
)
def
post
(
url
,
params
)
...
@@ -144,4 +154,8 @@ class GitlabNet
...
@@ -144,4 +154,8 @@ class GitlabNet
def
secret_token
def
secret_token
@secret_token
||=
File
.
read
config
.
secret_file
@secret_token
||=
File
.
read
config
.
secret_file
end
end
def
read_timeout
config
.
http_settings
[
'read_timeout'
]
||
READ_TIMEOUT
end
end
end
spec/gitlab_net_spec.rb
View file @
0c25846d
...
@@ -143,7 +143,7 @@ describe GitlabNet, vcr: true do
...
@@ -143,7 +143,7 @@ describe GitlabNet, vcr: true do
subject
{
gitlab_net
.
send
:http_client_for
,
URI
(
'https://localhost/'
)
}
subject
{
gitlab_net
.
send
:http_client_for
,
URI
(
'https://localhost/'
)
}
before
do
before
do
gitlab_net
.
stub!
:cert_store
gitlab_net
.
stub!
:cert_store
gitlab_net
.
send
(
:config
).
http_settings
.
stub
(
:[]
).
with
(
'self_signed_cert'
)
{
true
}
gitlab_net
.
send
(
:config
).
stub
(
:http_settings
)
{
{
'self_signed_cert'
=>
true
}
}
end
end
its
(
:verify_mode
)
{
should
eq
(
OpenSSL
::
SSL
::
VERIFY_NONE
)
}
its
(
:verify_mode
)
{
should
eq
(
OpenSSL
::
SSL
::
VERIFY_NONE
)
}
...
...
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