xcskarel 0.0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc917e748937343f867741161f46519d733738b7
4
- data.tar.gz: f328fc4bebedbbd58a5efc57c849e3cb7d2bd256
3
+ metadata.gz: 8554a8191907bcc3d6b14bde66f344d3d6e9bf2c
4
+ data.tar.gz: 132b062bb5c4ee7259cb4052cdf011160cc7af03
5
5
  SHA512:
6
- metadata.gz: 060b26ec640e74de1bc6dbea08c6b62cb9d4d38451dadedad82d4acef05be5a6d136bc221df150c4ffba9b5594ba3d96209dd29656776b384ca841bed9627ca0
7
- data.tar.gz: f1bb9596366e72848d97f833da51a380b9a8e422d092249fc3a5d7aaf0673f7b541089aa16033044faedf1797b144db77d3853853eedaea5037fc172a7c4cec1
6
+ metadata.gz: a0a88b3aec7d56c1ceac71cf936941a3f67a43362f9ac7090e230e69f7ab9dec3208c9ed323b194fc7beef611901881ae7d0732044983376f6adf8c0ec6e18ed
7
+ data.tar.gz: 40936af2da7f3212bb3fe90b7d6206d765038cefa503b603df63932b1799188878ea506653bbbaf15c95a19e022dd7f8606b9fd988c1e48c4afd3795944c647c
data/bin/xcskarel ADDED
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.push File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'xcskarel'
6
+ require 'rubygems'
7
+ require 'commander'
8
+
9
+ XCSKarel.set_no_log(true)
10
+
11
+ class XCSKarelApplication
12
+ include Commander::Methods
13
+
14
+ def add_xcs_options(c)
15
+ c.option '--host Hostname', '(required) Xcode Server\'s hostname or IP address'
16
+ c.option '--user Username', 'Xcode Server username'
17
+ c.option '--pass Password', 'Xcode Server password'
18
+ end
19
+
20
+ def create_server_from_options(options)
21
+ raise "No hostname was specified, please see `xcskarel --help`" unless options.host
22
+ XCSKarel::Server.new(options.host, options.user, options.pass)
23
+ end
24
+
25
+ def run
26
+ program :name, 'xcskarel'
27
+ program :version, XCSKarel::VERSION
28
+ program :description, 'Tool for managing your Xcode Server & Bot configurations'
29
+ program :help, 'Author', 'Honza Dvorsky <http://honzadvorsky.com>'
30
+ program :help, 'GitHub', 'https://github.com/czechboy0/xcskarel'
31
+
32
+ global_option('--verbose', 'Print internal logs') { XCSKarel.set_no_log(false) }
33
+ global_option('--no_pretty', 'Disables output JSON prettification')
34
+ global_option('--no_filter', 'Prints full JSON payload for objects instead of just filtering the important ones')
35
+
36
+ command :bots do |c|
37
+ c.syntax = 'xcskarel bots [options]'
38
+ c.description = 'Fetches all Bots found on the specified server'
39
+ c.example 'get all bot names & identifiers', 'xcskarel bots --hostname 127.0.0.1'
40
+ c.example 'get all bot metadata', 'xcskarel bots --no_filter --hostname 127.0.0.1'
41
+ add_xcs_options(c)
42
+ c.action do |args, options|
43
+ server = create_server_from_options(options)
44
+ all_bots = server.get_bots
45
+ unless options.no_filter
46
+ all_bots = XCSKarel.filter_array(all_bots, ['name', '_id'])
47
+ end
48
+ out = options.no_pretty ? JSON.generate(all_bots) : JSON.pretty_generate(all_bots)
49
+ puts out
50
+ end
51
+ end
52
+
53
+ command :integrations do |c|
54
+ c.syntax = 'xcskarel integrations [options]'
55
+ c.description = 'Fetches all Integrations for a specified Bot identifier'
56
+ c.example 'get all integration identifiers, numbers & results', 'xcskarel integrations --bot BOT_ID --hostname 127.0.0.1'
57
+ add_xcs_options(c)
58
+ c.option '--bot BOT_ID', '(required) Bot identifier'
59
+ c.action do |args, options|
60
+ raise "No Bot id was specified, please see `xcskarel integrations --help`" unless options.bot
61
+ server = create_server_from_options(options)
62
+ all_integrations = server.get_integrations(options.bot)
63
+ unless options.no_filter
64
+ all_integrations = XCSKarel.filter_array(all_integrations, ['number', '_id', 'currentStep', 'result'])
65
+ end
66
+ out = options.no_pretty ? JSON.generate(all_integrations) : JSON.pretty_generate(all_integrations)
67
+ puts out
68
+ end
69
+ end
70
+
71
+ run!
72
+ end
73
+ end
74
+
75
+ XCSKarelApplication.new.run
76
+
77
+
78
+
79
+
@@ -0,0 +1,28 @@
1
+
2
+ require 'set'
3
+
4
+ module XCSKarel
5
+ # returns a copy of the passed-in hash with only the provided keypaths kept
6
+ # e.g. "name" will keep the key "name" at the top level.
7
+ # TODO: support even nested keypaths
8
+ def self.filter_key_paths(hash, key_paths)
9
+ new_hash = Hash.new
10
+ keys = Set.new(key_paths)
11
+ hash.each do |k,v|
12
+ if keys.member?(k)
13
+ new_hash[k] = v
14
+ end
15
+ end
16
+ return new_hash
17
+ end
18
+
19
+ # filters each element
20
+ def self.filter_array(array, key_paths)
21
+ new_array = Array.new
22
+ keys = Set.new(key_paths)
23
+ array.each do |i|
24
+ new_array << filter_key_paths(i, key_paths)
25
+ end
26
+ return new_array
27
+ end
28
+ end
data/lib/karel/log.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'logger'
2
+ require 'colored'
3
+
4
+ module XCSKarel
5
+
6
+ @@NO_LOG = false
7
+
8
+ def self.set_no_log(no_log)
9
+ @@NO_LOG = no_log
10
+ end
11
+
12
+ def self.log
13
+
14
+ @@log ||= Logger.new($stdout)
15
+
16
+ @@log.formatter = proc do |severity, datetime, progname, msg|
17
+
18
+ unless @@NO_LOG
19
+ string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
20
+ second = "#{msg}\n"
21
+
22
+ if severity == "DEBUG"
23
+ string = string.magenta
24
+ elsif severity == "INFO"
25
+ string = string.white
26
+ elsif severity == "WARN"
27
+ string = string.yellow
28
+ elsif severity == "ERROR"
29
+ string = string.red
30
+ elsif severity == "FATAL"
31
+ string = string.red.bold
32
+ end
33
+
34
+ [string, second].join("")
35
+ end
36
+
37
+ end
38
+ @@log
39
+ end
40
+ end
@@ -0,0 +1,90 @@
1
+ require 'excon'
2
+ require 'pry'
3
+ require 'karel/log'
4
+ require 'json'
5
+ require 'base64'
6
+
7
+ module XCSKarel
8
+
9
+ class Server
10
+
11
+ attr_reader :host
12
+ attr_reader :user
13
+ attr_reader :pass
14
+ attr_reader :port
15
+
16
+ def initialize(host, user=nil, pass=nil, allow_self_signed=true)
17
+ @port = 20343
18
+ @host = validate_host(host)
19
+ @user = user
20
+ @pass = pass
21
+ validate_connection(allow_self_signed)
22
+ end
23
+
24
+ def get_bots
25
+ response = get_endpoint('/bots')
26
+ raise "You are unauthorized to access data on #{@host}, please check that you're passing in a correct username and password.".red if response.status == 401
27
+ raise "Failed to fetch Bots from Xcode Server at #{@host}, response: #{response.status}: #{response.body}.".red if response.status != 200
28
+ JSON.parse(response.body)['results']
29
+ end
30
+
31
+ def get_integrations(bot_id)
32
+ response = get_endpoint("/bots/#{bot_id}/integrations?limit=10")
33
+ raise "Failed to fetch Integrations for Bot #{bot_id} from Xcode Server at #{@host}, response: #{response.status}: #{response.body}".red if response.status != 200
34
+ JSON.parse(response.body)['results']
35
+ end
36
+
37
+ def headers
38
+ headers = {
39
+ 'user-agent' => 'xcskarel', # XCS wants user agent. for some API calls. not for others. sigh.
40
+ 'X-XCSAPIVersion' => 6 # XCS API version with this API, currently 6 with Xcode 7 Beta 6.
41
+ }
42
+
43
+ if @user && @pass
44
+ userpass = "#{@user}:#{@pass}"
45
+ headers['Authorization'] = "Basic #{Base64.strict_encode64(userpass)}"
46
+ end
47
+
48
+ return headers
49
+ end
50
+
51
+ def get_endpoint(endpoint)
52
+ url = url_for_endpoint(endpoint)
53
+ headers = self.headers || {}
54
+ response = Excon.get(url, :headers => headers)
55
+ XCSKarel.log.debug "GET endpoint #{endpoint} => #{url} => Response #{response.data[:status_line].gsub("\n", "")}"
56
+ return response
57
+ end
58
+
59
+ private
60
+
61
+ def url_for_endpoint(endpoint)
62
+ "#{@host}:#{@port}/api#{endpoint}"
63
+ end
64
+
65
+ def validate_host(host)
66
+ comps = host.split(":")
67
+ raise "Scheme must be unspecified or https, nothing else" if comps.count > 1 && comps[0] != 'https'
68
+ host_with_https = comps.count > 1 ? host : "https://#{host}"
69
+ return host_with_https
70
+ end
71
+
72
+ def validate_connection(allow_self_signed)
73
+
74
+ # check for allowing self-signed certs
75
+ Excon.defaults[:ssl_verify_peer] = !allow_self_signed
76
+
77
+ # TODO: logout/login to validate user/pass
78
+
79
+ # try to connect to the host
80
+ begin
81
+ response = get_endpoint("/ping")
82
+ rescue Exception => e
83
+ raise "Failed to validate - #{e}.\nPlease make sure your Xcode Server is up and running at #{host}".red
84
+ else
85
+ raise "Failed to validate - Endpoint at \"#{url}\" responded with #{response.data[:status_line]}".red if response.status != 204
86
+ XCSKarel.log.info "Validation of host #{@host} succeeded.".green
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module XCSKarel
2
+ VERSION = '0.2'
3
+ end
data/lib/xcskarel.rb CHANGED
@@ -1,6 +1,5 @@
1
1
 
2
- class XCSKarel
3
- def self.hi
4
- puts "Hello"
5
- end
6
- end
2
+ require 'karel/server'
3
+ require 'karel/version'
4
+ require 'karel/log'
5
+ require 'karel/filter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcskarel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Honza Dvorsky
@@ -9,15 +9,120 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-08-26 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Tool for managing your Xcode Bot configurations
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.45.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.45.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: logger
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.8
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: colored
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: commander
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 4.3.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 4.3.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.2.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.2.0
111
+ description: Tool for managing your Xcode Server & Bot configurations from the command
112
+ line
14
113
  email: http://honzadvorsky.com
15
- executables: []
114
+ executables:
115
+ - xcskarel
16
116
  extensions: []
17
117
  extra_rdoc_files: []
18
118
  files:
119
+ - bin/xcskarel
120
+ - lib/karel/filter.rb
121
+ - lib/karel/log.rb
122
+ - lib/karel/server.rb
123
+ - lib/karel/version.rb
19
124
  - lib/xcskarel.rb
20
- homepage: http://rubygems.org/gems/xcskarel
125
+ homepage: http://github.com/czechboy0/xcskarel
21
126
  licenses:
22
127
  - MIT
23
128
  metadata: {}
@@ -29,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
134
  requirements:
30
135
  - - ">="
31
136
  - !ruby/object:Gem::Version
32
- version: '0'
137
+ version: 2.0.0
33
138
  required_rubygems_version: !ruby/object:Gem::Requirement
34
139
  requirements:
35
140
  - - ">="
@@ -40,6 +145,6 @@ rubyforge_project:
40
145
  rubygems_version: 2.4.5
41
146
  signing_key:
42
147
  specification_version: 4
43
- summary: Manage Xcode Bot configurations
148
+ summary: Manage your Xcode Server & Bots from the command line
44
149
  test_files: []
45
150
  has_rdoc: