megam_gogs 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/megam/gogs.rb +87 -136
- data/lib/megam/gogs/version.rb +1 -1
- data/megam_gogs.gemspec +4 -4
- metadata +16 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5d9cbbef21aa3502f4a3cdeb9214e2bef525fb1
|
4
|
+
data.tar.gz: 8680ce39fc66b2cf7c38d1ab6418a3bc3b8c4666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88c8335639ad6b338d32e576df00eba9505028a172fcd31d801e84b0ee4a73ebd0a13ee292f9032ac68537ad422d4c904e66c67c5995f8105d1e41c0c329baf5
|
7
|
+
data.tar.gz: 7e833e8f0a7c16e51775e4a185b19ed8ce5e06f85a30c57e7d321f5d5858f6ffb8c3e9c22df8080dd25eca7b311105ef354dc790a7665a66aa3396dcd0670573
|
data/lib/megam/gogs.rb
CHANGED
@@ -1,185 +1,136 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'time'
|
2
|
+
require 'uri'
|
3
|
+
require 'zlib'
|
4
4
|
require 'openssl'
|
5
5
|
require 'net/http'
|
6
6
|
require 'excon'
|
7
7
|
require 'base64'
|
8
8
|
require 'yaml'
|
9
9
|
|
10
|
-
__LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__),
|
11
|
-
unless $LOAD_PATH.include?(__LIB_DIR__)
|
12
|
-
$LOAD_PATH.unshift(__LIB_DIR__)
|
13
|
-
end
|
14
|
-
|
15
|
-
require "megam/gogs/version"
|
16
|
-
require "megam/gogs/accounts"
|
17
|
-
require "megam/gogs/dumpout"
|
18
|
-
require "megam/gogs/errors"
|
19
|
-
require "megam/gogs/repos"
|
20
|
-
require "megam/gogs/tokens"
|
10
|
+
__LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
11
|
+
$LOAD_PATH.unshift(__LIB_DIR__) unless $LOAD_PATH.include?(__LIB_DIR__)
|
21
12
|
|
22
|
-
require
|
23
|
-
require
|
24
|
-
require
|
13
|
+
require 'megam/gogs/version'
|
14
|
+
require 'megam/gogs/accounts'
|
15
|
+
require 'megam/gogs/dumpout'
|
16
|
+
require 'megam/gogs/errors'
|
17
|
+
require 'megam/gogs/repos'
|
18
|
+
require 'megam/gogs/tokens'
|
25
19
|
|
20
|
+
require 'megam/core/gogs_repo'
|
21
|
+
require 'megam/core/gogs_account'
|
22
|
+
require 'megam/core/gogs_tokens'
|
26
23
|
|
27
24
|
module Megam
|
28
25
|
class Gogs
|
29
|
-
|
30
|
-
AUTH_PREFIX = 'Authorization'
|
26
|
+
AUTH_PREFIX = 'Authorization'
|
31
27
|
HEADERS = {
|
32
28
|
'Accept' => 'application/json',
|
33
29
|
'Accept-Encoding' => 'gzip',
|
34
30
|
'User-Agent' => "megam-gogs/#{Megam::Gogs::VERSION}",
|
35
31
|
'X-Ruby-Version' => RUBY_VERSION,
|
36
32
|
'X-Ruby-Platform' => RUBY_PLATFORM
|
37
|
-
|
38
33
|
}
|
39
|
-
|
40
|
-
if File.exist?("#{ENV['MEGAM_HOME']}/nilavu.yml")
|
41
|
-
common = YAML.load_file("#{ENV['MEGAM_HOME']}/nilavu.yml") #COMMON YML
|
42
|
-
puts "=> Loaded #{ENV['MEGAM_HOME']}/nilavu.yml"
|
43
|
-
else
|
44
|
-
puts "=> Warning ! MEGAM_HOME environment variable not set."
|
45
|
-
common={"api" => {}, "storage" => {}, "varai" => {}, "auth" => {}, "monitor" => {}, "gogs" => {'host' => "", 'port' => ""}}
|
46
|
-
end
|
47
|
-
|
48
|
-
gogs_host = "#{common['gogs']['host']}" || ENV['GOGS_HOST']
|
49
|
-
gogs_port = "#{common['gogs']['port']}" || ENV['GOGS_PORT']
|
50
34
|
|
51
35
|
OPTIONS = {
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
36
|
+
headers: {},
|
37
|
+
host: "localhost",
|
38
|
+
port: "6001",
|
39
|
+
nonblock: false,
|
40
|
+
scheme: 'http'
|
57
41
|
}
|
58
42
|
|
59
|
-
API_REST =
|
60
|
-
|
43
|
+
API_REST = '/api/v1'
|
61
44
|
|
62
45
|
def text
|
63
46
|
@text ||= Megam::Dumpout.new(STDOUT, STDERR, STDIN)
|
64
47
|
end
|
65
48
|
|
66
|
-
|
67
|
-
@last_response
|
68
|
-
end
|
49
|
+
attr_reader :last_response
|
69
50
|
|
70
51
|
# It is assumed that every API call will NOT use an API_KEY/email.
|
71
|
-
def initialize(options={})
|
52
|
+
def initialize(options = {})
|
72
53
|
@options = OPTIONS.merge(options)
|
73
54
|
end
|
74
55
|
|
75
|
-
def request(params
|
76
|
-
|
77
|
-
start = Time.now
|
78
|
-
|
79
|
-
dummy_params = {
|
80
|
-
:expects => params[:expects],
|
81
|
-
:method => params[:method],
|
82
|
-
:body => params[:body]
|
83
|
-
}
|
84
|
-
|
85
|
-
|
86
|
-
text.msg "#{text.color("START", :cyan, :bold)}"
|
87
|
-
params.each do |pkey, pvalue|
|
88
|
-
text.msg("> #{pkey}: #{pvalue}")
|
89
|
-
end
|
90
|
-
|
91
|
-
if params[:token].nil?
|
92
|
-
|
93
|
-
|
94
|
-
@uname = params[:username]
|
95
|
-
@pass = params[:password]
|
96
|
-
@cred = "#{@uname}:#{@pass}"
|
97
|
-
@final_cred64 = Base64.encode64(@cred)
|
98
|
-
|
99
|
-
@final_hash = { :creds => "Basic #{@final_cred64}" }
|
100
|
-
|
101
|
-
response = connection_repo.request(dummy_params, &block)
|
102
|
-
|
103
|
-
puts response.inspect
|
104
|
-
text.msg("END(#{(Time.now - start).to_s}s)")
|
105
|
-
# reset (non-persistent) connection
|
106
|
-
#@connection_repo.reset
|
107
|
-
|
108
|
-
else
|
56
|
+
def request(params, &block)
|
57
|
+
start = Time.now
|
109
58
|
|
110
|
-
|
111
|
-
|
112
|
-
|
59
|
+
dummy_params = {
|
60
|
+
expects: params[:expects],
|
61
|
+
method: params[:method],
|
62
|
+
body: params[:body]
|
63
|
+
}
|
113
64
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
response
|
121
|
-
|
122
|
-
end
|
123
|
-
|
124
|
-
private
|
125
|
-
|
126
|
-
#Make a lazy connection.
|
127
|
-
def connection_repo
|
128
|
-
@options[:path] =API_REST + @options[:path]
|
129
|
-
#headers_hash = encode_header(@options)
|
130
|
-
|
131
|
-
@options[:headers] = HEADERS.merge({
|
132
|
-
AUTH_PREFIX => @final_hash[:creds],
|
65
|
+
text.msg "#{text.color('START', :cyan, :bold)}"
|
66
|
+
params.each do |pkey, pvalue|
|
67
|
+
text.msg("> #{pkey}: #{pvalue}")
|
68
|
+
end
|
133
69
|
|
134
|
-
|
70
|
+
if params[:token].nil?
|
71
|
+
@uname = params[:username]
|
72
|
+
@pass = params[:password]
|
73
|
+
@cred = "#{@uname}:#{@pass}"
|
74
|
+
@final_cred64 = Base64.encode64(@cred)
|
135
75
|
|
76
|
+
@final_hash = { creds: "Basic #{@final_cred64}" }
|
136
77
|
|
78
|
+
response = connection_repo.request(dummy_params, &block)
|
79
|
+
text.msg("END(#{(Time.now - start)}s)")
|
80
|
+
else
|
137
81
|
|
138
|
-
|
82
|
+
@tokens = params[:token]
|
83
|
+
@final_token = { token: "token #{@tokens}" }
|
84
|
+
response = connection_token.request(dummy_params, &block)
|
139
85
|
|
86
|
+
puts response.inspect
|
87
|
+
text.msg("END(#{(Time.now - start)}s)")
|
88
|
+
# reset (non-persistent) connection
|
89
|
+
# @connection_token.reset
|
90
|
+
end
|
140
91
|
|
141
|
-
|
142
|
-
text.msg("> HTTP #{@options[:scheme]}://#{@options[:host]}")
|
143
|
-
@options.each do |key, value|
|
144
|
-
text.msg("> #{key}: #{value}")
|
145
|
-
end
|
146
|
-
text.msg("End HTTP Request Data.")
|
147
|
-
if @options[:scheme] == "https"
|
148
|
-
@connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}",@options)
|
149
|
-
else
|
150
|
-
Excon.defaults[:ssl_verify_peer] = false
|
151
|
-
@connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:6001",@options)
|
92
|
+
response
|
152
93
|
end
|
153
|
-
@connection
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
def connection_token
|
158
|
-
@options[:path] =API_REST + @options[:path]
|
159
|
-
#headers_hash = encode_header(@options)
|
160
94
|
|
161
|
-
|
162
|
-
AUTH_PREFIX => @final_token[:token],
|
95
|
+
private
|
163
96
|
|
164
|
-
|
97
|
+
# Make a lazy connection.
|
98
|
+
def connection_repo
|
99
|
+
@options[:path] = API_REST + @options[:path]
|
165
100
|
|
166
|
-
|
101
|
+
@options[:headers] = HEADERS.merge(AUTH_PREFIX => @final_hash[:creds]).merge(@options[:headers])
|
167
102
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
@connection
|
103
|
+
text.msg('HTTP Request Data:')
|
104
|
+
text.msg("> HTTP #{@options[:scheme]}://#{@options[:host]}")
|
105
|
+
@options.each do |key, value|
|
106
|
+
text.msg("> #{key}: #{value}")
|
107
|
+
end
|
108
|
+
text.msg('End HTTP Request Data.')
|
109
|
+
if @options[:scheme] == 'https'
|
110
|
+
@connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}", @options)
|
111
|
+
else
|
112
|
+
Excon.defaults[:ssl_verify_peer] = false
|
113
|
+
@connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:6001", @options)
|
114
|
+
end
|
115
|
+
@connection
|
182
116
|
end
|
183
117
|
|
118
|
+
def connection_token
|
119
|
+
@options[:path] = API_REST + @options[:path]
|
120
|
+
@options[:headers] = HEADERS.merge(AUTH_PREFIX => @final_token[:token]).merge(@options[:headers])
|
121
|
+
text.msg('HTTP Request Data:')
|
122
|
+
text.msg("> HTTP #{@options[:scheme]}://#{@options[:host]}")
|
123
|
+
@options.each do |key, value|
|
124
|
+
text.msg("> #{key}: #{value}")
|
125
|
+
end
|
126
|
+
text.msg('End HTTP Request Data.')
|
127
|
+
if @options[:scheme] == 'https'
|
128
|
+
@connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}", @options)
|
129
|
+
else
|
130
|
+
Excon.defaults[:ssl_verify_peer] = false
|
131
|
+
@connection = Excon.new("#{@options[:scheme]}://#{@options[:host]}:6001", @options)
|
132
|
+
end
|
133
|
+
@connection
|
134
|
+
end
|
184
135
|
end
|
185
136
|
end
|
data/lib/megam/gogs/version.rb
CHANGED
data/megam_gogs.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = "megam_gogs"
|
7
7
|
s.version = Megam::Gogs::VERSION
|
8
8
|
s.authors = ["Raj Thilak,Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar"]
|
9
|
-
s.email = ["rajthilak@megam.
|
9
|
+
s.email = ["rajthilak@megam.io","nkishore@megam.io","alrin@megam.io, getyesh@megam.io"]
|
10
10
|
s.homepage = "http://github.com/megamsys/megam_gogs.rb"
|
11
11
|
s.license = "Apache V2"
|
12
12
|
sextra_rdoc_files = ["README.md", "LICENSE" ]
|
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,fea,tures}/*`.split("\n")
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
|
-
s.add_runtime_dependency 'highline', '~> 1.
|
19
|
+
s.add_runtime_dependency 'highline', '~> 1.7'
|
20
20
|
s.add_runtime_dependency 'nokogiri', '~> 1.6'
|
21
|
-
s.add_development_dependency 'minitest', '~> 5.
|
22
|
-
s.add_development_dependency 'rake', '~> 10.
|
21
|
+
s.add_development_dependency 'minitest', '~> 5.6'
|
22
|
+
s.add_development_dependency 'rake', '~> 10.4'
|
23
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megam_gogs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raj Thilak,Kishorekumar Neelamegam, Thomas Alrin, Yeshwanth Kumar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,34 +44,34 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '5.
|
47
|
+
version: '5.6'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '5.
|
54
|
+
version: '5.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '10.
|
61
|
+
version: '10.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '10.
|
68
|
+
version: '10.4'
|
69
69
|
description: Ruby Client for the Gogs (gogs.io). Performs REST based HTTP call to
|
70
70
|
gogs.io server
|
71
71
|
email:
|
72
|
-
- rajthilak@megam.
|
73
|
-
- nkishore@megam.
|
74
|
-
- alrin@megam.
|
72
|
+
- rajthilak@megam.io
|
73
|
+
- nkishore@megam.io
|
74
|
+
- alrin@megam.io, getyesh@megam.io
|
75
75
|
executables: []
|
76
76
|
extensions: []
|
77
77
|
extra_rdoc_files: []
|
@@ -118,8 +118,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.4.
|
121
|
+
rubygems_version: 2.4.6
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Ruby Client for the Gogs (gogs.io)
|
125
|
-
test_files:
|
125
|
+
test_files:
|
126
|
+
- test/test_helper.rb
|
127
|
+
- test/test_repo.rb
|
128
|
+
- test/test_tokens.rb
|