summaryrefslogtreecommitdiff
path: root/git-mirror-gitlab-ee
diff options
context:
space:
mode:
Diffstat (limited to 'git-mirror-gitlab-ee')
-rwxr-xr-xgit-mirror-gitlab-ee32
1 files changed, 22 insertions, 10 deletions
diff --git a/git-mirror-gitlab-ee b/git-mirror-gitlab-ee
index 394a5f7..425bb48 100755
--- a/git-mirror-gitlab-ee
+++ b/git-mirror-gitlab-ee
@@ -29,17 +29,17 @@ class GitLabEE < GitLabCE
class Project < GitLabCE::Project
def mirrorURL
unless @cache.has_key?(:mirror)
- req = Net::HTTP::Get.new(URI(_info["web_url"]+"/mirror"))
- req.add_field("PRIVATE-TOKEN", @api_key)
+ req = Net::HTTP::Get.new(URI(self.info["web_url"]+"/mirror"))
+ req.add_field("PRIVATE-TOKEN", @gl.config['apikey'])
res = @gl.connection(req.uri).request(req)
if res.code != "200"
throw res
end
- @cache[:mirror_res]=res
+
doc = Nokogiri::HTML(res.body)
- @cache[:mirror_cookie] = res["set-cookie"]
- @cache[:mirror_token] = doc.css('input[name="authenticity_token"]').first["value"]
+ @cache[:session] = res["set-cookie"]
+ @cache[:mirror_transaction] = doc.css('input[name="authenticity_token"]').first["value"]
is_mirror = doc.css("#project_mirror").first["checked"]
if !is_mirror
@cache[:mirror] = nil
@@ -51,26 +51,27 @@ class GitLabEE < GitLabCE
end
def mirrorURL=(url)
+ libremessages('msg2', 'Setting mirror URL for %s', @project_id)
self.mirrorURL()
req = Net::HTTP::Patch.new(URI(self.info["web_url"]+"/mirror"))
req.add_field("PRIVATE-TOKEN", @gl.config['apikey']) # authenticate
- req.add_field("Cookie", @cache[:mirror_cookie]) # session id
+ req.add_field("Cookie", @cache[:session]) # session id
req.form_data = {
"utf8" => "✓",
- "authenticity_token" => @cache[:mirror_token], # session state
+ "authenticity_token" => @cache[:mirror_transaction], # session state
"project[mirror]" => (url.nil? ? "0" : "1"),
"project[import_url]" => url.to_s,
+ "project[mirror_user_id]" => @gl.user_id,
}
-
res = @gl.connection(req.uri).request(req)
if res.code != "302"
throw res
end
@cache.delete(:mirror)
- @cache.delete(:mirror_token)
- @cache.delete(:mirror_cookie)
+ @cache.delete(:mirror_transaction)
+ @cache.delete(:session)
return URI(url)
end
@@ -96,6 +97,17 @@ class GitLabEE < GitLabCE
return (self.mirrorURL.nil? ? "passive" : "active")
end
end
+
+ def user_id
+ req = Net::HTTP::Get.new(self.config['apiurl'] + 'user')
+ req.add_field("PRIVATE-TOKEN", self.config['apikey'])
+ res = self.connection(req.uri).request(req)
+ if res.code != "200"
+ raise Error.new(res)
+ end
+ user = JSON::parse(res.body)
+ return user["id"]
+ end
end
if __FILE__ == $0