ocp 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +75 -0
- data/bin/ocp +7 -0
- data/lib/base/Base.rb +76 -0
- data/lib/base/v1/V1.rb +37 -0
- data/lib/base/v1/api/Api.rb +38 -0
- data/lib/base/v1/ocpapi/OAuthClientAuthorization.rb +38 -0
- data/lib/base/v1/ocpapi/ObjectMeta.rb +59 -0
- data/lib/base/v1/ocpapi/ObjectReference.rb +51 -0
- data/lib/base/v1/ocpapi/OcpApi.rb +39 -0
- data/lib/base/v1/ocpapi/Policy.rb +38 -0
- data/lib/base/v1/ocpapi/Project.rb +43 -0
- data/lib/base/v1/ocpapi/ProjectRequest.rb +49 -0
- data/lib/base/v1/ocpapi/Role.rb +42 -0
- data/lib/base/v1/ocpapi/RoleBinding.rb +81 -0
- data/lib/client/OcpClient.rb +193 -0
- data/lib/commander/OcpCommander.rb +225 -0
- data/lib/config/OcpConfig.rb +140 -0
- data/lib/exceptions/MissingRequiredOptionException.rb +32 -0
- data/lib/exceptions/NoObjectNameException.rb +30 -0
- data/lib/ocp.rb +8 -0
- metadata +64 -0
@@ -0,0 +1,193 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#####################################################################################
|
3
|
+
# Copyright 2016 Kenneth Evensen <kenneth.evensen@redhat.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
######################################################################################
|
18
|
+
#
|
19
|
+
# Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
|
20
|
+
#
|
21
|
+
######################################################################################
|
22
|
+
|
23
|
+
require 'rest-client'
|
24
|
+
require 'json'
|
25
|
+
require 'singleton'
|
26
|
+
|
27
|
+
class OcpClient
|
28
|
+
include Singleton
|
29
|
+
|
30
|
+
attr_reader :url
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@method = nil
|
34
|
+
@url = nil
|
35
|
+
@token = nil
|
36
|
+
@noverifyssl = false
|
37
|
+
@pretty = false
|
38
|
+
@clientcert = nil
|
39
|
+
@clientkey = nil
|
40
|
+
@clientca = nil
|
41
|
+
@clientcafile = nil
|
42
|
+
@debug = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup(ocpconfig)
|
46
|
+
@noverifyssl = ocpconfig.noverifyssl
|
47
|
+
@url = ocpconfig.master
|
48
|
+
@pretty = ocpconfig.pretty
|
49
|
+
@debug = ocpconfig.debug
|
50
|
+
@token = ocpconfig.token
|
51
|
+
@clientcert = ocpconfig.clientcert
|
52
|
+
@clientkey = ocpconfig.clientkey
|
53
|
+
@clientca = ocpconfig.clientca
|
54
|
+
@clientcafile = ocpconfig.clientcafile
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def get(location)
|
60
|
+
return call(location,nil,:get)
|
61
|
+
end
|
62
|
+
|
63
|
+
def post(location, body)
|
64
|
+
return call(location,body,:post)
|
65
|
+
end
|
66
|
+
|
67
|
+
def put(location, body)
|
68
|
+
return call(location,body,:put)
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete(location)
|
72
|
+
return call(location,nil,:delete)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def call(location, body, method)
|
78
|
+
|
79
|
+
if @debug
|
80
|
+
puts "Location - #{location}"
|
81
|
+
puts "Method - #{method}"
|
82
|
+
unless body.nil?
|
83
|
+
puts "Body - #{JSON.pretty_generate(body)}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if !@clientcert.nil? and !@clientkey.nil?
|
88
|
+
return callbycert(location, body, method)
|
89
|
+
else
|
90
|
+
return callbytoken(location, body, method)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def callbytoken(location, body=nil, method)
|
96
|
+
|
97
|
+
if @debug
|
98
|
+
puts "Client Token - #{@token}"
|
99
|
+
end
|
100
|
+
|
101
|
+
response = nil
|
102
|
+
begin
|
103
|
+
if body.nil?
|
104
|
+
response = RestClient::Request.new(
|
105
|
+
:method => method,
|
106
|
+
:url => @url+location+"?"+query_params,
|
107
|
+
:verify_ssl => !@noverifyssl,
|
108
|
+
:headers => { :accept => :json,
|
109
|
+
:content_type => :json,
|
110
|
+
:Authorization => "Bearer #{@token}"}
|
111
|
+
).execute
|
112
|
+
else
|
113
|
+
response = RestClient::Request.new(
|
114
|
+
:method => method,
|
115
|
+
:url => @url+location+"?"+query_params,
|
116
|
+
:verify_ssl => !@noverifyssl,
|
117
|
+
:headers => { :accept => :json,
|
118
|
+
:content_type => :json,
|
119
|
+
:Authorization => "Bearer #{@token}"},
|
120
|
+
:payload => JSON.generate(body)
|
121
|
+
).execute
|
122
|
+
end
|
123
|
+
rescue => exception
|
124
|
+
puts "Exception: " << exception.response
|
125
|
+
end
|
126
|
+
|
127
|
+
if @debug and !exception.nil?
|
128
|
+
puts "Response Code: #{exception.response.code}"
|
129
|
+
end
|
130
|
+
|
131
|
+
if !response.nil? and @pretty
|
132
|
+
results = JSON.pretty_generate(JSON.parse(response.to_str))
|
133
|
+
return results
|
134
|
+
elsif !response.nil?
|
135
|
+
return response
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
def callbycert(location, body=nil, method)
|
141
|
+
|
142
|
+
if @debug
|
143
|
+
puts "Client Cert - #{@clientcert}"
|
144
|
+
puts "Client Key - #{@clientkey}"
|
145
|
+
puts "CA File - #{@clientcafile}"
|
146
|
+
end
|
147
|
+
|
148
|
+
response = nil
|
149
|
+
begin
|
150
|
+
if body.nil?
|
151
|
+
response = RestClient::Request.new(
|
152
|
+
:method => method,
|
153
|
+
:url => @url+location+"?"+query_params,
|
154
|
+
:verify_ssl => !@noverifyssl,
|
155
|
+
:ssl_client_cert => @clientcert,
|
156
|
+
:ssl_client_key => @clientkey,
|
157
|
+
:ssl_ca_file => @clientcafile,
|
158
|
+
:headers => { :accept => :json,
|
159
|
+
:content_type => :json}
|
160
|
+
).execute
|
161
|
+
else
|
162
|
+
response = RestClient::Request.new(
|
163
|
+
:method => method,
|
164
|
+
:url => @url+location+"?"+query_params,
|
165
|
+
:verify_ssl => !@noverifyssl,
|
166
|
+
:ssl_client_cert => @clientcert,
|
167
|
+
:ssl_client_key => @clientkey,
|
168
|
+
:ssl_ca_file => @clientcafile,
|
169
|
+
:headers => { :accept => :json,
|
170
|
+
:content_type => :json},
|
171
|
+
:payload => JSON.generate(body)
|
172
|
+
).execute
|
173
|
+
end
|
174
|
+
rescue => exception
|
175
|
+
if @debug
|
176
|
+
puts "Exception: " << exception.response
|
177
|
+
end
|
178
|
+
return exception.response.code
|
179
|
+
end
|
180
|
+
|
181
|
+
if !response.nil? and @pretty
|
182
|
+
results = JSON.pretty_generate(JSON.parse(response.to_str))
|
183
|
+
return results
|
184
|
+
elsif !response.nil?
|
185
|
+
return response
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def query_params
|
190
|
+
return "pretty=#{@pretty}"
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
@@ -0,0 +1,225 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'commander'
|
4
|
+
|
5
|
+
|
6
|
+
load 'lib/exceptions/MissingRequiredOptionException.rb'
|
7
|
+
load 'lib/config/OcpConfig.rb'
|
8
|
+
|
9
|
+
load 'lib/base/v1/ocpapi/OcpApi.rb'
|
10
|
+
load 'lib/base/v1/ocpapi/OAuthClientAuthorization.rb'
|
11
|
+
load 'lib/base/v1/ocpapi/Policy.rb'
|
12
|
+
load 'lib/base/v1/ocpapi/ProjectRequest.rb'
|
13
|
+
load 'lib/base/v1/ocpapi/Role.rb'
|
14
|
+
load 'lib/base/v1/ocpapi/RoleBinding.rb'
|
15
|
+
load 'lib/base/v1/ocpapi/Project.rb'
|
16
|
+
load 'lib/base/v1/api/Api.rb'
|
17
|
+
|
18
|
+
|
19
|
+
class OcpCommander
|
20
|
+
include Commander::Methods
|
21
|
+
# include whatever modules you need
|
22
|
+
|
23
|
+
def run
|
24
|
+
|
25
|
+
program :name, 'ocp'
|
26
|
+
program :version, '0.0.1'
|
27
|
+
program :description, 'A Ruby command line tool to interact with OpenShift Container Platform'
|
28
|
+
|
29
|
+
global_option('-t','--token [TOKEN]','Provide a token. This option will over-ride what is in a config file')
|
30
|
+
global_option('--clientcertfile [CLIENTCERT]','Provide a path to the client certificate file. This option will over-ride what is in a config file')
|
31
|
+
global_option('--clientkeyfile [CLIENTKEY]','Provide a path to the client key file. This option will over-ride what is in a config file')
|
32
|
+
global_option('--clientcafile [CLIENTCA]','Provide a path to the client CA certificate file. This option will over-ride what is in a config file')
|
33
|
+
global_option('-c','--config [CONFIG]','Provide a config file. See README.md for an example')
|
34
|
+
global_option('-m','--master [MASTER]','OpenShift Cluster to which wish to connect. This option will over-ride what is in a config file')
|
35
|
+
global_option('-n','--noverifyssl','Do not verify SSL certificate of master. This option will over-ride what is in a config file')
|
36
|
+
global_option('-o','--output [OUTPUT]',[:yaml, :json], "Select the output format")
|
37
|
+
global_option('-d','--debug', "Dump debug information to console")
|
38
|
+
global_option('-p','--pretty', "Generate pretty output where possible")
|
39
|
+
|
40
|
+
command :getocpapi do |c|
|
41
|
+
c.syntax = 'ocp getocpapi [options]'
|
42
|
+
c.description = 'Retrieve the OpenShift Container Platform API'
|
43
|
+
c.action do |args, options|
|
44
|
+
# Do something or c.when_called Ocp::Commands::Getoapi,
|
45
|
+
ocpconfig = OcpConfig.new
|
46
|
+
ocpconfig.set_config_with_options(options)
|
47
|
+
if ocpconfig.debug
|
48
|
+
puts "Config: #{ocpconfig.inspect}"
|
49
|
+
end
|
50
|
+
ocpapi = OcpApi.new
|
51
|
+
ocpapi.setup(ocpconfig)
|
52
|
+
puts "#{ocpapi}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
command :getapi do |c|
|
57
|
+
c.syntax = 'ocp getapi [options]'
|
58
|
+
c.summary = 'Retrieve the Kubernetes API'
|
59
|
+
c.description = ''
|
60
|
+
c.action do |args, options|
|
61
|
+
# Do something or c.when_called Ocp::Commands::Getapi
|
62
|
+
ocpconfig = OcpConfig.new
|
63
|
+
ocpconfig.set_config_with_options(options)
|
64
|
+
if ocpconfig.debug
|
65
|
+
puts "Config: #{ocpconfig.inspect}"
|
66
|
+
end
|
67
|
+
api = Api.new
|
68
|
+
api.setup(ocpconfig)
|
69
|
+
puts "#{api.showapi}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
command :createproject do |c|
|
74
|
+
c.syntax = 'ocp createproject [options]'
|
75
|
+
c.summary = 'Create a project request'
|
76
|
+
c.description = 'Create a project request'
|
77
|
+
c.option '--name PROJECTNAME', String, 'The name for the project'
|
78
|
+
c.option '--description [DESCRIPTION]', String, 'The description for the project'
|
79
|
+
c.option '--displayname [DISPLAYNAME]', String, 'The displayname for the project'
|
80
|
+
c.action do |args, options|
|
81
|
+
# Do something or c.when_called Ocp::Commands::Getapi
|
82
|
+
|
83
|
+
ocpconfig = OcpConfig.new
|
84
|
+
ocpconfig.set_config_with_options(options)
|
85
|
+
if ocpconfig.debug
|
86
|
+
puts "Config: #{ocpconfig.inspect}"
|
87
|
+
end
|
88
|
+
projreq = ProjectRequest.new
|
89
|
+
projreq.setup(ocpconfig)
|
90
|
+
|
91
|
+
data = projreq.createprojectrequest(options.name, options.description, options.displayname)
|
92
|
+
|
93
|
+
puts "#{data}"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
command :deleteproject do |c|
|
98
|
+
c.syntax = 'ocp deleteproject [options]'
|
99
|
+
c.summary = 'Delete a project'
|
100
|
+
c.description = 'Delete a project'
|
101
|
+
c.option '--name PROJECTNAME', String, 'The name for the project'
|
102
|
+
c.action do |args, options|
|
103
|
+
# Do something or c.when_called Ocp::Commands::Getapi
|
104
|
+
|
105
|
+
ocpconfig = OcpConfig.new
|
106
|
+
ocpconfig.set_config_with_options(options)
|
107
|
+
if ocpconfig.debug
|
108
|
+
puts "Config: #{ocpconfig.inspect}"
|
109
|
+
end
|
110
|
+
project = Project.new
|
111
|
+
project.setup(ocpconfig)
|
112
|
+
|
113
|
+
data = project.deleteproject(options.name)
|
114
|
+
|
115
|
+
puts "#{data}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
command :listpolicies do |c|
|
120
|
+
c.syntax = 'ocp listpolicies [options]'
|
121
|
+
c.description = 'Retrieve the Policies for a NameSpace'
|
122
|
+
c.option '--name PROJECTNAME', String, 'The name for the project'
|
123
|
+
c.action do |args, options|
|
124
|
+
# Do something or c.when_called Ocp::Commands::Getoapi,
|
125
|
+
ocpconfig = OcpConfig.new
|
126
|
+
ocpconfig.set_config_with_options(options)
|
127
|
+
if ocpconfig.debug
|
128
|
+
puts "Config: #{ocpconfig.inspect}"
|
129
|
+
end
|
130
|
+
policy = Policy.new
|
131
|
+
policy.setup(ocpconfig)
|
132
|
+
puts "#{policy}"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
command :listoauthclientauthorizations do |c|
|
137
|
+
c.syntax = 'ocp oauthclientauthorizations [options]'
|
138
|
+
c.description = 'Retrieve the OAuthClientAuthorizations'
|
139
|
+
c.action do |args, options|
|
140
|
+
# Do something or c.when_called Ocp::Commands::Getoapi,
|
141
|
+
ocpconfig = OcpConfig.new
|
142
|
+
ocpconfig.set_config_with_options(options)
|
143
|
+
if ocpconfig.debug
|
144
|
+
puts "Config: #{ocpconfig.inspect}"
|
145
|
+
end
|
146
|
+
oauthpolicy = OAuthClientAuthorization.new
|
147
|
+
oauthpolicy.setup(ocpconfig)
|
148
|
+
puts "#{oauthpolicy}"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
command :listroles do |c|
|
153
|
+
c.syntax = 'ocp listroles [options]'
|
154
|
+
c.description = 'Retrieve the Roles'
|
155
|
+
c.option '--name [PROJECTNAME]', String, 'Optionally the name of the project'
|
156
|
+
c.action do |args, options|
|
157
|
+
# Do something or c.when_called Ocp::Commands::Getoapi,
|
158
|
+
ocpconfig = OcpConfig.new
|
159
|
+
ocpconfig.set_config_with_options(options)
|
160
|
+
if ocpconfig.debug
|
161
|
+
puts "Config: #{ocpconfig.inspect}"
|
162
|
+
end
|
163
|
+
roles = nil
|
164
|
+
if options.name.nil?
|
165
|
+
roles = Role.new
|
166
|
+
else
|
167
|
+
roles = Role.new(options.name)
|
168
|
+
end
|
169
|
+
roles.setup(ocpconfig)
|
170
|
+
|
171
|
+
puts "#{roles}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
command :listrolebindings do |c|
|
176
|
+
c.syntax = 'ocp listrolebindings [options]'
|
177
|
+
c.description = 'Retrieve the Roles Bindings'
|
178
|
+
c.option '--name [PROJECTNAME]', String, 'Optionally the name of the project'
|
179
|
+
c.action do |args, options|
|
180
|
+
# Do something or c.when_called Ocp::Commands::Getoapi,
|
181
|
+
ocpconfig = OcpConfig.new
|
182
|
+
ocpconfig.set_config_with_options(options)
|
183
|
+
if ocpconfig.debug
|
184
|
+
puts "Config: #{ocpconfig.inspect}"
|
185
|
+
end
|
186
|
+
roles = nil
|
187
|
+
if options.name.nil?
|
188
|
+
roles = RoleBinding.new
|
189
|
+
else
|
190
|
+
roles = RoleBinding.new(options.name)
|
191
|
+
end
|
192
|
+
roles.setup(ocpconfig)
|
193
|
+
|
194
|
+
|
195
|
+
puts "#{roles}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
command :create_role_binding do |c|
|
200
|
+
c.syntax = 'ocp createrolebinding [options]'
|
201
|
+
c.description = 'Create a Project Roles Binding'
|
202
|
+
c.option '--name PROJECTNAME', String, 'The name of the project'
|
203
|
+
c.option '--user USERNAME', String, 'The name of the user'
|
204
|
+
c.option '--role ROLE', String, 'The role to add to the user'
|
205
|
+
c.action do |args, options|
|
206
|
+
# Do something or c.when_called Ocp::Commands::Getoapi,
|
207
|
+
ocpconfig = OcpConfig.new
|
208
|
+
ocpconfig.set_config_with_options(options)
|
209
|
+
if ocpconfig.debug
|
210
|
+
puts "Config: #{ocpconfig.inspect}"
|
211
|
+
end
|
212
|
+
|
213
|
+
roles = RoleBinding.new(options.name)
|
214
|
+
|
215
|
+
roles.setup(ocpconfig)
|
216
|
+
resp = roles.create_role_binding(options.user, options.role)
|
217
|
+
puts "#{resp}"
|
218
|
+
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
run!
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#####################################################################################
|
3
|
+
# Copyright 2015 Kenneth Evensen <kenneth.evensen@redhat.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
#####################################################################################
|
18
|
+
#
|
19
|
+
# Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
|
20
|
+
#
|
21
|
+
#####################################################################################
|
22
|
+
|
23
|
+
require 'yaml'
|
24
|
+
require 'openssl'
|
25
|
+
|
26
|
+
class OcpConfig
|
27
|
+
attr_reader :master
|
28
|
+
attr_reader :token
|
29
|
+
attr_reader :clientcertfile
|
30
|
+
attr_reader :clientkeyfile
|
31
|
+
attr_reader :clientcafile
|
32
|
+
attr_reader :clientcert
|
33
|
+
attr_reader :clientkey
|
34
|
+
attr_reader :clientca
|
35
|
+
attr_reader :noverifyssl
|
36
|
+
attr_reader :output
|
37
|
+
attr_reader :debug
|
38
|
+
attr_reader :pretty
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
@master = nil
|
42
|
+
@token = nil
|
43
|
+
@noverifyssl = false
|
44
|
+
@output = :json
|
45
|
+
@debug = false
|
46
|
+
@pretty = false
|
47
|
+
@clientcertfile = nil
|
48
|
+
@clientkeyfile = nil
|
49
|
+
@clientcafile = nil
|
50
|
+
@clientcert = nil
|
51
|
+
@clientkey = nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_config_by_parameters(host, noverifyssl, pretty, debug , token=nil, clientcertfile=nil, clientkeyfile=nil, clientcafile=nil)
|
55
|
+
@noverifyssl = verifyssl
|
56
|
+
@url = host
|
57
|
+
@pretty = pretty
|
58
|
+
@debug = debug
|
59
|
+
|
60
|
+
unless clientcertfile.nil? or clientkeyfile.nil?
|
61
|
+
@clientcertfile = clientcertfile
|
62
|
+
@clientkeyfile = clientkeyfile
|
63
|
+
end
|
64
|
+
|
65
|
+
unless clientcafile.nil?
|
66
|
+
@clientcafile = clientcafile
|
67
|
+
end
|
68
|
+
|
69
|
+
unless @clientcertfile.nil? or @clientkeyfile.nil?
|
70
|
+
@clientcert = OpenSSL::X509::Certificate.new File.read @clientcertfile
|
71
|
+
@clientkey = OpenSSL::PKey::RSA.new File.read @clientkeyfile
|
72
|
+
end
|
73
|
+
|
74
|
+
unless @clientcafile.nil?
|
75
|
+
@clientca = OpenSSL::X509::Certificate.new File.read @clientcafile
|
76
|
+
end
|
77
|
+
|
78
|
+
unless token.nil?
|
79
|
+
@token = token
|
80
|
+
end
|
81
|
+
|
82
|
+
validate_options
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_config_with_options(options)
|
87
|
+
|
88
|
+
unless options.configfile.nil?
|
89
|
+
set_config_by_file(options.configfile)
|
90
|
+
else
|
91
|
+
set_config_by_file("config.yaml")
|
92
|
+
end
|
93
|
+
set_config_by_parameters(options.master, options.noverifyssl,
|
94
|
+
options.pretty, options.debug, options.token,
|
95
|
+
options.clientcertfile, options.clientkeyfile,
|
96
|
+
options.clientcafile)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def set_config_by_file(configfile)
|
102
|
+
|
103
|
+
config = read_config(configfile)
|
104
|
+
|
105
|
+
unless config.nil?
|
106
|
+
@token = config["connection"]["token"]
|
107
|
+
@master = config["connection"]["master"]
|
108
|
+
@noverifyssl = config["connection"]["no_verify_ssl"]
|
109
|
+
@clientcertfile = config["connection"]["client-certificate-file"]
|
110
|
+
@clientkeyfile = config["connection"]["client-key-file"]
|
111
|
+
@clientcafile = config["connection"]["client-ca-file"]
|
112
|
+
end
|
113
|
+
return nil
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def validate_options
|
119
|
+
|
120
|
+
if @token.nil? and (@clientcertfile.nil? or @clientkeyfile.nil?)
|
121
|
+
raise MissingRequiredOptionException.new("token OR clientcertfile AND clientkeyfile")
|
122
|
+
elsif @master.nil?
|
123
|
+
raise MissingRequiredOptionException.new("master")
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def read_config(configfile)
|
128
|
+
begin
|
129
|
+
unless configfile.nil?
|
130
|
+
return YAML.load_file(configfile)
|
131
|
+
else
|
132
|
+
return YAML.load_file("config.yaml")
|
133
|
+
end
|
134
|
+
rescue => exception
|
135
|
+
puts exception.message
|
136
|
+
puts "Unable to read config file #{configfile}. Proceeding"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#####################################################################################
|
3
|
+
# Copyright 2015 Kenneth Evensen <kenneth.evensen@redhat.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
#####################################################################################
|
18
|
+
#
|
19
|
+
# Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
|
20
|
+
#
|
21
|
+
#####################################################################################
|
22
|
+
|
23
|
+
class MissingRequiredOptionException < StandardError
|
24
|
+
attr_reader :kind
|
25
|
+
def initialize(kind)
|
26
|
+
|
27
|
+
@kind = kind
|
28
|
+
msg = "You are missing a required option. It must be specified on the command line or configuration file: #{kind}"
|
29
|
+
super(msg)
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#####################################################################################
|
3
|
+
# Copyright 2015 Kenneth Evensen <kenneth.evensen@redhat.com>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
#####################################################################################
|
18
|
+
#
|
19
|
+
# Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
|
20
|
+
#
|
21
|
+
#####################################################################################
|
22
|
+
|
23
|
+
class NoObjectNameException < StandardError
|
24
|
+
attr_reader :kind
|
25
|
+
def initialize(kind)
|
26
|
+
@kind = kind
|
27
|
+
msg = "An entity name must be specified for #{@kind}"
|
28
|
+
super(msg)
|
29
|
+
end
|
30
|
+
end
|
data/lib/ocp.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
load 'exceptions/MissingRequiredOptionException.rb'
|
2
|
+
load 'lib/config/OcpConfig.rb'
|
3
|
+
load 'lib/commander/OcpCommander.rb'
|
4
|
+
load 'lib/base/v1/ocpapi/OcpApi.rb'
|
5
|
+
load 'lib/base/v1/ocpapi/OAuthClientAuthorization.rb'
|
6
|
+
load 'lib/base/v1/ocpapi/ProjectRequest.rb'
|
7
|
+
load 'lib/base/v1/ocpapi/Project.rb'
|
8
|
+
load 'lib/base/v1/api/Api.rb'
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ocp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ken Evensen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby based OpenShift Container Platform Gem
|
14
|
+
email: kevensen@redhat.com
|
15
|
+
executables:
|
16
|
+
- ocp
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/base/Base.rb
|
21
|
+
- lib/base/v1/api/Api.rb
|
22
|
+
- lib/base/v1/ocpapi/OAuthClientAuthorization.rb
|
23
|
+
- lib/base/v1/ocpapi/ObjectMeta.rb
|
24
|
+
- lib/base/v1/ocpapi/ObjectReference.rb
|
25
|
+
- lib/base/v1/ocpapi/OcpApi.rb
|
26
|
+
- lib/base/v1/ocpapi/Policy.rb
|
27
|
+
- lib/base/v1/ocpapi/Project.rb
|
28
|
+
- lib/base/v1/ocpapi/ProjectRequest.rb
|
29
|
+
- lib/base/v1/ocpapi/Role.rb
|
30
|
+
- lib/base/v1/ocpapi/RoleBinding.rb
|
31
|
+
- lib/base/v1/V1.rb
|
32
|
+
- lib/client/OcpClient.rb
|
33
|
+
- lib/commander/OcpCommander.rb
|
34
|
+
- lib/config/OcpConfig.rb
|
35
|
+
- lib/exceptions/MissingRequiredOptionException.rb
|
36
|
+
- lib/exceptions/NoObjectNameException.rb
|
37
|
+
- lib/ocp.rb
|
38
|
+
- bin/ocp
|
39
|
+
- README.md
|
40
|
+
homepage: https://github.com/kevensen/ocpcmd
|
41
|
+
licenses:
|
42
|
+
- GPL
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.0.14.1
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: ocp tool
|
64
|
+
test_files: []
|