66require_relative 'gitlab_logger'
77require_relative 'gitlab_access'
88require_relative 'gitlab_redis'
9+ require_relative 'gitlab_lfs_authentication'
910require_relative 'httpunix'
1011
1112class GitlabNet
@@ -15,15 +16,12 @@ class ApiUnreachableError < StandardError; end
1516 READ_TIMEOUT = 300
1617
1718 def check_access ( cmd , repo , actor , changes , protocol )
18- project_name = repo . gsub ( "'" , "" )
19- project_name = project_name . gsub ( /\. git\Z / , "" )
20- project_name = project_name . gsub ( /\A \/ / , "" )
2119 changes = changes . join ( "\n " ) unless changes . kind_of? ( String )
2220
2321 params = {
2422 action : cmd ,
2523 changes : changes ,
26- project : project_name ,
24+ project : project_name ( repo ) ,
2725 protocol : protocol
2826 }
2927
@@ -39,7 +37,7 @@ def check_access(cmd, repo, actor, changes, protocol)
3937 if resp . code == '200'
4038 GitAccessStatus . create_from_json ( resp . body )
4139 else
42- GitAccessStatus . new ( false , 'API is not accessible' , nil , nil )
40+ GitAccessStatus . new ( false , 'API is not accessible' , nil )
4341 end
4442 end
4543
@@ -49,6 +47,19 @@ def discover(key)
4947 JSON . parse ( resp . body ) rescue nil
5048 end
5149
50+ def lfs_authenticate ( key , repo )
51+ params = {
52+ project : project_name ( repo ) ,
53+ key_id : key . gsub ( 'key-' , '' )
54+ }
55+
56+ resp = post ( "#{ host } /lfs_authenticate" , params )
57+
58+ if resp . code == '200'
59+ GitlabLfsAuthentication . build_from_json ( resp . body )
60+ end
61+ end
62+
5263 def broadcast_message
5364 resp = get ( "#{ host } /broadcast_message" )
5465 JSON . parse ( resp . body ) rescue { }
@@ -107,6 +118,12 @@ def redis_client
107118
108119 protected
109120
121+ def project_name ( repo )
122+ project_name = repo . gsub ( "'" , "" )
123+ project_name = project_name . gsub ( /\. git\Z / , "" )
124+ project_name . gsub ( /\A \/ / , "" )
125+ end
126+
110127 def config
111128 @config ||= GitlabConfig . new
112129 end
0 commit comments