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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40543f1c15fda3c849b1460f0f290a1aeb168307
|
4
|
+
data.tar.gz: 4645e15ea40435877234de9dd8a23009922ff9b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c4a018a6ef4dba530684ce33d0b96c2ab6e431b13d9276114df5645823de8177402f28dd16dc2487a4b0e9fbcccc0e5f8478781f18b02a47c784b11809f17d2
|
7
|
+
data.tar.gz: 1f36b85cddd4a66c46de5ef5ea44a42db7151297c73c5bda129cfde0286990c606d9e4ebda8dfe6e5a74fa7f8785676d6b8448240162422a833fc6ebbc64ee2e
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# ocp
|
2
|
+
Why another command line tool for the OpenShift Container Platform? The current Golang based command line tool <strong>oc</strong> is solid, plus its written in Golang! This is just an academic attempt to build a tool in Ruby.
|
3
|
+
|
4
|
+
The intent is to use it in ManageIQ/CloudForms.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
```bash
|
8
|
+
$ git clone https://github.com/kevensen/ocpcmd
|
9
|
+
$ cd ocpcmd
|
10
|
+
$ ./ocp.rb help
|
11
|
+
```
|
12
|
+
## Install as a Gem
|
13
|
+
```bash
|
14
|
+
$ git clone https://github.com/kevensen/ocpcmd
|
15
|
+
$ cd ocpcmd
|
16
|
+
$ gem build ./ocp.gemspec
|
17
|
+
$ gem install ocp-0.0.1.gem
|
18
|
+
```
|
19
|
+
### Use the Gem in IRB
|
20
|
+
```bash
|
21
|
+
$ irb
|
22
|
+
irb(main):001:0> require 'ocp'
|
23
|
+
=> true
|
24
|
+
irb(main):002:0> ocpconfig = OcpConfig.new
|
25
|
+
=> #<OcpConfig:0x007fb2058c3598 @master=nil, @token=nil, @noverifyssl=false, @output=:json, @debug=false, @pretty=false, @clientcertfile=nil, @clientkeyfile=nil, @clientcafile=nil, @clientcert=nil, @clientkey=nil>
|
26
|
+
irb(main):003:0> ocpconfig.set_config_by_file("path..to../config.yaml")
|
27
|
+
=> nil
|
28
|
+
irb(main):004:0> ocpapi = OcpApi.new
|
29
|
+
=> #<OcpApi:0x007fb2029acf48 @api_ver="v1", @client=#<OcpClient:0x007fb2029aced0 @method=nil, @url=nil, @token=nil, @noverifyssl=false, @pretty=false, @clientcert=nil, @clientkey=nil, @clientca=nil, @clientcafile=nil, @debug=nil>, @api="oapi", @version="v1", @name=nil>
|
30
|
+
irb(main):005:0> ocpapi.setup(ocpconfig)
|
31
|
+
=> nil
|
32
|
+
irb(main):006:0> puts "#{ocpapi}"
|
33
|
+
```
|
34
|
+
### Or Use the Gem from the Command Line
|
35
|
+
```bash
|
36
|
+
$ ocp getapi -c config.yaml
|
37
|
+
```
|
38
|
+
|
39
|
+
## Sample Config File
|
40
|
+
Place this file in the ocpcmd directory
|
41
|
+
```yaml
|
42
|
+
#
|
43
|
+
# YAML Config file for sat6cmd
|
44
|
+
#
|
45
|
+
|
46
|
+
|
47
|
+
# Connection config items
|
48
|
+
connection:
|
49
|
+
master: "https://master.example.com:8443"
|
50
|
+
token: a1nX8rtGt132nLJHkAiGVCJnI4Y4XvtUsThB4xthWOI
|
51
|
+
no_verify_ssl: false
|
52
|
+
```
|
53
|
+
|
54
|
+
## Another Sample Config File
|
55
|
+
If you want to access the API with the system:admin user, you can't use a token. This is because the system:admin user doesn't get a token! You need to copy three files to the machine running the gem:
|
56
|
+
|
57
|
+
1. /etc/origin/master/admin.crt
|
58
|
+
2. /etc/origin/master/admin.key
|
59
|
+
3. /etc/origin/master/ca.crt
|
60
|
+
|
61
|
+
Once you have these files, update your config.yaml accordingly.
|
62
|
+
```yaml
|
63
|
+
#
|
64
|
+
# YAML Config file for sat6cmd
|
65
|
+
#
|
66
|
+
|
67
|
+
|
68
|
+
# Connection config items
|
69
|
+
connection:
|
70
|
+
master: "https://master.example.com:8443"
|
71
|
+
client-certificate-file: admin.crt
|
72
|
+
client-key-file: admin.key
|
73
|
+
client-ca-file: ca.crt
|
74
|
+
no_verify_ssl: false
|
75
|
+
```
|
data/bin/ocp
ADDED
data/lib/base/Base.rb
ADDED
@@ -0,0 +1,76 @@
|
|
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
|
+
load 'lib/client/OcpClient.rb'
|
24
|
+
|
25
|
+
class Base
|
26
|
+
|
27
|
+
def initialize(version, api, path, namespace)
|
28
|
+
@client = OcpClient.instance
|
29
|
+
@api = api
|
30
|
+
@version = version
|
31
|
+
@path = path
|
32
|
+
@namespace = namespace
|
33
|
+
|
34
|
+
@endpoint = "/"+@api+"/"+@version
|
35
|
+
|
36
|
+
if !@namespace.nil?
|
37
|
+
@endpoint = @endpoint+"/namespaces/"+@namespace+"/"+@path
|
38
|
+
elsif !@path.nil?
|
39
|
+
@endpoint = @endpoint+"/"+@path
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup(ocpconfig)
|
45
|
+
@client.setup(ocpconfig)
|
46
|
+
end
|
47
|
+
|
48
|
+
def list
|
49
|
+
data = nil
|
50
|
+
data = @client.get(@endpoint)
|
51
|
+
return data
|
52
|
+
end
|
53
|
+
|
54
|
+
def create(body)
|
55
|
+
data = nil
|
56
|
+
data = @client.post(@endpoint,body)
|
57
|
+
return data
|
58
|
+
end
|
59
|
+
|
60
|
+
def update(body)
|
61
|
+
data = nil
|
62
|
+
data = @client.put(@endpoint,body)
|
63
|
+
return data
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete(name)
|
67
|
+
data = nil
|
68
|
+
data = @client.delete(@endpoint+"/"+name)
|
69
|
+
return data
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def is_a_number?(s)
|
74
|
+
s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
|
75
|
+
end
|
76
|
+
end
|
data/lib/base/v1/V1.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
#!/usr/bin/env ruby
|
3
|
+
#####################################################################################
|
4
|
+
# Copyright 2016 Kenneth Evensen <kenneth.evensen@redhat.com>
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
######################################################################################
|
19
|
+
#
|
20
|
+
# Contact Info: <kenneth.evensen@redhat.com> and <lester@redhat.com>
|
21
|
+
#
|
22
|
+
######################################################################################
|
23
|
+
|
24
|
+
load 'lib/base/Base.rb'
|
25
|
+
|
26
|
+
class V1 < Base
|
27
|
+
|
28
|
+
def initialize(api, path, namespace)
|
29
|
+
@api_ver = "v1"
|
30
|
+
super(@api_ver, api, path, namespace)
|
31
|
+
end
|
32
|
+
|
33
|
+
def api_version
|
34
|
+
return @api_ver
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
load 'lib/base/v1/V1.rb'
|
24
|
+
|
25
|
+
class Api < V1
|
26
|
+
|
27
|
+
def initialize(name=nil)
|
28
|
+
super(name, "api")
|
29
|
+
end
|
30
|
+
|
31
|
+
def showapi
|
32
|
+
data = nil
|
33
|
+
data = list
|
34
|
+
return data
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
|
24
|
+
|
25
|
+
class OAuthClientAuthorization < OcpApi
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super("oauthclientauthorizations")
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
data = nil
|
33
|
+
data = list
|
34
|
+
return data
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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 'json'
|
24
|
+
|
25
|
+
class ObjectMeta
|
26
|
+
|
27
|
+
attr_accessor :name
|
28
|
+
attr_accessor :namespace
|
29
|
+
attr_accessor :selflink
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@name = nil
|
33
|
+
@namespace = nil
|
34
|
+
@selflink = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_hash
|
38
|
+
metaHash = Hash.new
|
39
|
+
unless @name.nil?
|
40
|
+
metaHash[:name] = @name
|
41
|
+
end
|
42
|
+
|
43
|
+
unless @namespace.nil?
|
44
|
+
metaHash[:namespace] = @namespace
|
45
|
+
end
|
46
|
+
|
47
|
+
unless @selflink.nil?
|
48
|
+
metaHash[:selflink] = @selflink
|
49
|
+
end
|
50
|
+
|
51
|
+
metaHash[:resourceVersion] = "1001"
|
52
|
+
|
53
|
+
return metaHash
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_json
|
57
|
+
return JSON.generate(get_hash)
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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 'json'
|
24
|
+
|
25
|
+
class ObjectReference
|
26
|
+
attr_accessor :name
|
27
|
+
attr_accessor :kind
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@name = nil
|
31
|
+
@kind = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_hash
|
35
|
+
metaHash = Hash.new
|
36
|
+
unless @name.nil?
|
37
|
+
metaHash[:name] = @name
|
38
|
+
end
|
39
|
+
|
40
|
+
unless @kind.nil?
|
41
|
+
metaHash[:kind] = @kind
|
42
|
+
end
|
43
|
+
|
44
|
+
return metaHash
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_json
|
48
|
+
return JSON.generate(get_hash)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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 'json'
|
24
|
+
|
25
|
+
load 'lib/base/v1/V1.rb'
|
26
|
+
|
27
|
+
class OcpApi < V1
|
28
|
+
|
29
|
+
def initialize(path=nil, namespace=nil)
|
30
|
+
super("oapi", path, namespace)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
data = nil
|
35
|
+
data = list
|
36
|
+
return data
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
|
24
|
+
|
25
|
+
class Policy < OcpApi
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super("policies")
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
data = nil
|
33
|
+
data = list
|
34
|
+
return data
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
load 'lib/base/v1/ocpapi/ObjectMeta.rb'
|
24
|
+
|
25
|
+
class Project < OcpApi
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super("projects")
|
29
|
+
end
|
30
|
+
|
31
|
+
def listprojects
|
32
|
+
data = nil
|
33
|
+
data = list
|
34
|
+
return data
|
35
|
+
end
|
36
|
+
|
37
|
+
def deleteproject(name)
|
38
|
+
data = nil
|
39
|
+
data = delete(name)
|
40
|
+
return data
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
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
|
+
load 'lib/base/v1/ocpapi/ObjectMeta.rb'
|
24
|
+
load 'lib/exceptions/NoObjectNameException.rb'
|
25
|
+
|
26
|
+
class ProjectRequest < OcpApi
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
super("projectrequests")
|
30
|
+
end
|
31
|
+
|
32
|
+
def createprojectrequest(entityname, displayname, description)
|
33
|
+
body = nil
|
34
|
+
data = nil
|
35
|
+
unless entityname.nil?
|
36
|
+
objectmeta = ObjectMeta.new
|
37
|
+
objectmeta.name = entityname
|
38
|
+
objectmeta.namespace = entityname
|
39
|
+
body = {'displayName' => displayname,
|
40
|
+
'description' => description,
|
41
|
+
'metadata' => objectmeta.get_hash}
|
42
|
+
data = create(body)
|
43
|
+
return data
|
44
|
+
else
|
45
|
+
raise NoObjectNameException.new(@name)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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
|
+
|
24
|
+
|
25
|
+
class Role < OcpApi
|
26
|
+
|
27
|
+
def initialize(namespace=nil)
|
28
|
+
unless namespace.nil?
|
29
|
+
super("roles", namespace)
|
30
|
+
else
|
31
|
+
super("roles")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
data = nil
|
37
|
+
data = list
|
38
|
+
return data
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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
|
+
load 'lib/base/v1/ocpapi/ObjectReference.rb'
|
24
|
+
|
25
|
+
class RoleBinding < OcpApi
|
26
|
+
|
27
|
+
def initialize(namespace=nil)
|
28
|
+
unless namespace.nil?
|
29
|
+
super("rolebindings",namespace)
|
30
|
+
@users = Array.new
|
31
|
+
@subjects = Array.new
|
32
|
+
@namespace = namespace
|
33
|
+
else
|
34
|
+
super("rolebindings")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_role_binding(user, role)
|
39
|
+
data = create(create_body(user, role))
|
40
|
+
return data
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_role_binding(user, role)
|
44
|
+
data = update(create_body(user, role))
|
45
|
+
return data
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_s
|
49
|
+
data = nil
|
50
|
+
data = list
|
51
|
+
return data
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def create_body(user, role)
|
57
|
+
@users.push(user)
|
58
|
+
subj = ObjectReference.new
|
59
|
+
subj.kind = "User"
|
60
|
+
subj.name = user
|
61
|
+
|
62
|
+
@subjects << subj.get_hash
|
63
|
+
|
64
|
+
roleRef = ObjectReference.new
|
65
|
+
roleRef.name = role
|
66
|
+
|
67
|
+
objMeta = ObjectMeta.new
|
68
|
+
objMeta.name = role
|
69
|
+
objMeta.namespace = @namespace
|
70
|
+
|
71
|
+
body = {
|
72
|
+
'metadata' => objMeta.get_hash,
|
73
|
+
'groupNames' => nil,
|
74
|
+
'userNames' => @users,
|
75
|
+
'subjects' => @subjects,
|
76
|
+
'roleRef' => roleRef.get_hash
|
77
|
+
}
|
78
|
+
return body
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|