rancher-management_api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -262
- data/lib/rancher/management_api/manager.rb +2 -2
- data/lib/rancher/management_api/version.rb +1 -1
- data/lib/rancher/management_api.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8e47474e013afef88f37a76c601e11a3244add2
|
4
|
+
data.tar.gz: 67e0cc31a9d46ed63467af6110e66aa6ca2d15f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 766df1bc4efe60b8fd84940974437179929db4b98d306ffb81260248b9d0fc72159c24765ff343e0294f4df6bed8de2c7487348a79c9bebb2e12e591dcc8e4c4
|
7
|
+
data.tar.gz: a4176f74b542c6571cbf558216b66da28d6ed59fc010894817e3d4d66bf1dea8666f3d39dc249e3485660a00303e82dc226314635f0544a58bd98471f21aa7de
|
data/README.md
CHANGED
@@ -1,262 +1,32 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
| jq '.'
|
34
|
-
```
|
35
|
-
|
36
|
-
Response:
|
37
|
-
```
|
38
|
-
{
|
39
|
-
"id": null,
|
40
|
-
"type": "token",
|
41
|
-
"links": {},
|
42
|
-
"actions": {},
|
43
|
-
"accountId": "1a7",
|
44
|
-
"authProvider": "localAuthConfig",
|
45
|
-
"clientId": null,
|
46
|
-
"code": null,
|
47
|
-
"enabled": true,
|
48
|
-
"hostname": null,
|
49
|
-
"jwt": "LGV5U6TuyEsJQC9J2CRHSLeVyMX5WYTAx8jGyicr",
|
50
|
-
"scheme": null,
|
51
|
-
"security": true,
|
52
|
-
"user": "apiuser",
|
53
|
-
"userIdentity": {
|
54
|
-
"externalId": "1a7",
|
55
|
-
"profilePicture": null,
|
56
|
-
"name": "Api User",
|
57
|
-
"externalIdType": "rancher_id",
|
58
|
-
"profileUrl": null,
|
59
|
-
"login": "apiuser",
|
60
|
-
"role": null,
|
61
|
-
"projectId": null,
|
62
|
-
"all": null,
|
63
|
-
"id": "rancher_id:1a7"
|
64
|
-
},
|
65
|
-
"userType": "user"
|
66
|
-
}
|
67
|
-
```
|
68
|
-
|
69
|
-
Use the `jwt` key to populate our cookie and request to create a project:
|
70
|
-
|
71
|
-
```
|
72
|
-
curl 'http://localhost:8080/v1/project' \
|
73
|
-
-H 'Origin: http://localhost:8080' \
|
74
|
-
-H 'Accept-Encoding: gzip, deflate' \
|
75
|
-
-H 'Accept-Language: en-US,en;q=0.8' \
|
76
|
-
-H 'Content-Type: application/json' \
|
77
|
-
-H 'x-api-no-challenge: true' \
|
78
|
-
-H 'Accept: application/json' \
|
79
|
-
-H 'Referer: http://localhost:8080/settings/env/add' \
|
80
|
-
-H 'X-Requested-With: XMLHttpRequest' \
|
81
|
-
-H 'Cookie: PL=rancher; token=LGV5U6TuyEsJQC9J2CRHSLeVyMX5WYTAx8jGyicr' \
|
82
|
-
-H 'Connection: keep-alive' \
|
83
|
-
--data-binary '{"swarm":false,"kubernetes":false,"mesos":false,"virtualMachine":false,"publicDns":false,"type":"project","name":"test4","description":null,"projectMembers":[{"externalId":"1a7","profilePicture":null,"name":"Api User","externalIdType":"rancher_id","profileUrl":null,"login":"apiuser","role":"owner","projectId":null,"all":null,"id":"rancher_id:1a7","type":"identity"}],"created":null,"kind":null,"removed":null,"uuid":null,"members":[{"externalId":"1a7","profilePicture":null,"name":"Api User","externalIdType":"rancher_id","profileUrl":null,"login":"apiuser","role":"owner","projectId":null,"all":null,"id":"rancher_id:1a7","type":"identity"}]}' \
|
84
|
-
--compressed \
|
85
|
-
| jq '.'
|
86
|
-
```
|
87
|
-
|
88
|
-
Response:
|
89
|
-
|
90
|
-
```
|
91
|
-
{
|
92
|
-
"id": "1a12",
|
93
|
-
"type": "project",
|
94
|
-
"links": {
|
95
|
-
"self": "http://localhost:8080/v1/projects/1a12",
|
96
|
-
"auditLogs": "http://localhost:8080/v1/projects/1a12/auditlogs",
|
97
|
-
"backupTargets": "http://localhost:8080/v1/projects/1a12/backuptargets",
|
98
|
-
"backups": "http://localhost:8080/v1/projects/1a12/backups",
|
99
|
-
"certificates": "http://localhost:8080/v1/projects/1a12/certificates",
|
100
|
-
"containerEvents": "http://localhost:8080/v1/projects/1a12/containerevents",
|
101
|
-
"credentials": "http://localhost:8080/v1/projects/1a12/credentials",
|
102
|
-
"environments": "http://localhost:8080/v1/projects/1a12/environments",
|
103
|
-
"externalEvents": "http://localhost:8080/v1/projects/1a12/externalevents",
|
104
|
-
"healthcheckInstanceHostMaps": "http://localhost:8080/v1/projects/1a12/healthcheckinstancehostmaps",
|
105
|
-
"hosts": "http://localhost:8080/v1/projects/1a12/hosts",
|
106
|
-
"images": "http://localhost:8080/v1/projects/1a12/images",
|
107
|
-
"instanceLinks": "http://localhost:8080/v1/projects/1a12/instancelinks",
|
108
|
-
"instances": "http://localhost:8080/v1/projects/1a12/instances",
|
109
|
-
"ipAddresses": "http://localhost:8080/v1/projects/1a12/ipaddresses",
|
110
|
-
"labels": "http://localhost:8080/v1/projects/1a12/labels",
|
111
|
-
"mounts": "http://localhost:8080/v1/projects/1a12/mounts",
|
112
|
-
"networks": "http://localhost:8080/v1/projects/1a12/networks",
|
113
|
-
"physicalHosts": "http://localhost:8080/v1/projects/1a12/physicalhosts",
|
114
|
-
"ports": "http://localhost:8080/v1/projects/1a12/ports",
|
115
|
-
"projectMembers": "http://localhost:8080/v1/projects/1a12/projectmembers",
|
116
|
-
"serviceConsumeMaps": "http://localhost:8080/v1/projects/1a12/serviceconsumemaps",
|
117
|
-
"serviceEvents": "http://localhost:8080/v1/projects/1a12/serviceevents",
|
118
|
-
"serviceExposeMaps": "http://localhost:8080/v1/projects/1a12/serviceexposemaps",
|
119
|
-
"services": "http://localhost:8080/v1/projects/1a12/services",
|
120
|
-
"snapshots": "http://localhost:8080/v1/projects/1a12/snapshots",
|
121
|
-
"storagePools": "http://localhost:8080/v1/projects/1a12/storagepools",
|
122
|
-
"userPreferences": "http://localhost:8080/v1/projects/1a12/userpreferences",
|
123
|
-
"volumes": "http://localhost:8080/v1/projects/1a12/volumes",
|
124
|
-
"accounts": "http://localhost:8080/v1/projects/1a12/accounts",
|
125
|
-
"addOutputsInputs": "http://localhost:8080/v1/projects/1a12/addoutputsinputs",
|
126
|
-
"amazonec2Configs": "http://localhost:8080/v1/projects/1a12/amazonec2configs",
|
127
|
-
"apiKeys": "http://localhost:8080/v1/projects/1a12/apikeys",
|
128
|
-
"azureConfigs": "http://localhost:8080/v1/projects/1a12/azureconfigs",
|
129
|
-
"composeProjects": "http://localhost:8080/v1/projects/1a12/composeprojects",
|
130
|
-
"composeServices": "http://localhost:8080/v1/projects/1a12/composeservices",
|
131
|
-
"containerExecs": "http://localhost:8080/v1/projects/1a12/containerexecs",
|
132
|
-
"containers": "http://localhost:8080/v1/projects/1a12/containers",
|
133
|
-
"digitaloceanConfigs": "http://localhost:8080/v1/projects/1a12/digitaloceanconfigs",
|
134
|
-
"dnsServices": "http://localhost:8080/v1/projects/1a12/dnsservices",
|
135
|
-
"dockerBuilds": "http://localhost:8080/v1/projects/1a12/dockerbuilds",
|
136
|
-
"environmentUpgrades": "http://localhost:8080/v1/projects/1a12/environmentupgrades",
|
137
|
-
"externalDnsEvents": "http://localhost:8080/v1/projects/1a12/externaldnsevents",
|
138
|
-
"externalHostEvents": "http://localhost:8080/v1/projects/1a12/externalhostevents",
|
139
|
-
"externalServiceEvents": "http://localhost:8080/v1/projects/1a12/externalserviceevents",
|
140
|
-
"externalServices": "http://localhost:8080/v1/projects/1a12/externalservices",
|
141
|
-
"externalStoragePoolEvents": "http://localhost:8080/v1/projects/1a12/externalstoragepoolevents",
|
142
|
-
"externalVolumeEvents": "http://localhost:8080/v1/projects/1a12/externalvolumeevents",
|
143
|
-
"hostAccesses": "http://localhost:8080/v1/projects/1a12/hostaccesses",
|
144
|
-
"identities": "http://localhost:8080/v1/projects/1a12/identities",
|
145
|
-
"kubernetesServices": "http://localhost:8080/v1/projects/1a12/kubernetesservices",
|
146
|
-
"loadBalancerConfigs": "http://localhost:8080/v1/projects/1a12/loadbalancerconfigs",
|
147
|
-
"loadBalancerServices": "http://localhost:8080/v1/projects/1a12/loadbalancerservices",
|
148
|
-
"machineDrivers": "http://localhost:8080/v1/projects/1a12/machinedrivers",
|
149
|
-
"machines": "http://localhost:8080/v1/projects/1a12/machines",
|
150
|
-
"packetConfigs": "http://localhost:8080/v1/projects/1a12/packetconfigs",
|
151
|
-
"passwords": "http://localhost:8080/v1/projects/1a12/passwords",
|
152
|
-
"projects": "http://localhost:8080/v1/projects/1a12/projects",
|
153
|
-
"pullTasks": "http://localhost:8080/v1/projects/1a12/pulltasks",
|
154
|
-
"register": "http://localhost:8080/v1/projects/1a12/register",
|
155
|
-
"registrationTokens": "http://localhost:8080/v1/projects/1a12/registrationtokens",
|
156
|
-
"registries": "http://localhost:8080/v1/projects/1a12/registries",
|
157
|
-
"registryCredentials": "http://localhost:8080/v1/projects/1a12/registrycredentials",
|
158
|
-
"scalePolicys": "http://localhost:8080/v1/projects/1a12/scalepolicys",
|
159
|
-
"schemas": "http://localhost:8080/v1/projects/1a12/schemas",
|
160
|
-
"serviceProxies": "http://localhost:8080/v1/projects/1a12/serviceproxies",
|
161
|
-
"settings": "http://localhost:8080/v1/projects/1a12/settings",
|
162
|
-
"snapshotBackupInputs": "http://localhost:8080/v1/projects/1a12/snapshotbackupinputs",
|
163
|
-
"statsAccesses": "http://localhost:8080/v1/projects/1a12/statsaccesses",
|
164
|
-
"typeDocumentations": "http://localhost:8080/v1/projects/1a12/typedocumentations",
|
165
|
-
"virtualMachines": "http://localhost:8080/v1/projects/1a12/virtualmachines",
|
166
|
-
"hostStats": "http://localhost:8080/v1/projects/1a12/projects/1a12/hoststats"
|
167
|
-
},
|
168
|
-
"actions": {},
|
169
|
-
"name": "test4",
|
170
|
-
"state": "registering",
|
171
|
-
"created": "2016-07-29T18:08:23Z",
|
172
|
-
"createdTS": 1469815703000,
|
173
|
-
"description": null,
|
174
|
-
"kind": "project",
|
175
|
-
"kubernetes": false,
|
176
|
-
"members": [
|
177
|
-
{
|
178
|
-
"externalId": "1a7",
|
179
|
-
"externalIdType": "rancher_id",
|
180
|
-
"role": "owner"
|
181
|
-
}
|
182
|
-
],
|
183
|
-
"mesos": false,
|
184
|
-
"publicDns": false,
|
185
|
-
"removed": null,
|
186
|
-
"servicesPortRange": null,
|
187
|
-
"swarm": false,
|
188
|
-
"transitioning": "yes",
|
189
|
-
"transitioningMessage": "In Progress",
|
190
|
-
"transitioningProgress": null,
|
191
|
-
"uuid": "db31b902-6d96-4669-bab3-749d4c5871cb",
|
192
|
-
"virtualMachine": false
|
193
|
-
}```
|
194
|
-
|
195
|
-
## To create an api key
|
196
|
-
|
197
|
-
Use the JWT and the returned project id:
|
198
|
-
|
199
|
-
```
|
200
|
-
curl 'http://localhost:8080/v1/projects/1a8/apikey' \
|
201
|
-
-H 'Cookie: PL=rancher; token=avZcQ1kseRmc5MxACSwAN62Vv2CD7oGFn441rtHM' \
|
202
|
-
-H 'Origin: http://localhost:8080' \
|
203
|
-
-H 'Accept-Encoding: gzip, deflate' \
|
204
|
-
-H 'Accept-Language: en-US,en;q=0.8' \
|
205
|
-
-H 'Content-Type: application/json' \
|
206
|
-
-H 'x-api-no-challenge: true' \
|
207
|
-
-H 'Accept: application/json' \
|
208
|
-
-H 'Referer: http://localhost:8080/env/1a8/api' \
|
209
|
-
-H 'X-Requested-With: XMLHttpRequest' \
|
210
|
-
-H 'Connection: keep-alive' \
|
211
|
-
--data-binary '{"type":"apikey","accountId":"1a8","name":"mycoolname","description":"my cool description","created":null,"kind":null,"removed":null,"uuid":null}' \
|
212
|
-
--compressed \
|
213
|
-
| jq '.'
|
214
|
-
```
|
215
|
-
|
216
|
-
Response:
|
217
|
-
|
218
|
-
```
|
219
|
-
{
|
220
|
-
"id": "1c6",
|
221
|
-
"type": "apiKey",
|
222
|
-
"links": {
|
223
|
-
"self": "http://localhost:8080/v1/projects/1a8/apikeys/1c6",
|
224
|
-
"account": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/account",
|
225
|
-
"images": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/images",
|
226
|
-
"instances": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/instances",
|
227
|
-
"certificate": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/certificate"
|
228
|
-
},
|
229
|
-
"actions": {
|
230
|
-
"activate": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/?action=activate",
|
231
|
-
"remove": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/?action=remove",
|
232
|
-
"deactivate": "http://localhost:8080/v1/projects/1a8/apikeys/1c6/?action=deactivate"
|
233
|
-
},
|
234
|
-
"name": "mycoolname",
|
235
|
-
"state": "registering",
|
236
|
-
"accountId": "1a8",
|
237
|
-
"created": "2016-07-29T18:22:37Z",
|
238
|
-
"createdTS": 1469816557000,
|
239
|
-
"description": "my cool description",
|
240
|
-
"kind": "apiKey",
|
241
|
-
"publicValue": "375AD58E3AAF7191D3C0",
|
242
|
-
"removed": null,
|
243
|
-
"secretValue": "aS2tSzVn6okWKUKGCFeg1hjp3vzxe2Y367v7uQqS",
|
244
|
-
"transitioning": "yes",
|
245
|
-
"transitioningMessage": "In Progress",
|
246
|
-
"transitioningProgress": null,
|
247
|
-
"uuid": "da6e0500-b2e9-4fa8-849e-0495b26e46bd"
|
248
|
-
}
|
249
|
-
```
|
250
|
-
|
251
|
-
The `publicValue` is the RANCHER_ACCESS_KEY, and the `secretValue` is the RANCHER_SECRET_KEY
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
```
|
257
|
-
manager = Rancher::ManagementApi::Token.build_manager(username, password)
|
258
|
-
project = manager.create_project(...)
|
259
|
-
api_key = project.create_api_key(...)
|
260
|
-
api_key.access_key
|
261
|
-
api_key.secret_key
|
262
|
-
```
|
1
|
+
# Rancher::ManagementApi Gem
|
2
|
+
|
3
|
+
## Usage
|
4
|
+
|
5
|
+
1. Create a manager:
|
6
|
+
a. If your Rancher has access control:
|
7
|
+
```ruby
|
8
|
+
manager = Rancher::ManagementApi::Token.build_manager(
|
9
|
+
host: "http://localhost:8080",
|
10
|
+
username: "youruser",
|
11
|
+
password: "yourpassword"
|
12
|
+
)
|
13
|
+
```
|
14
|
+
b. Or just create a manager:
|
15
|
+
```ruby
|
16
|
+
manager = Rancher::ManagementApi::Manager.new(
|
17
|
+
host: "http://localhost:8080",
|
18
|
+
)
|
19
|
+
```
|
20
|
+
2. Create a project (known in the UI as an Environment):
|
21
|
+
```ruby
|
22
|
+
project = manager.create_project("my environment name")
|
23
|
+
```
|
24
|
+
3. Create a new API key:
|
25
|
+
```ruby
|
26
|
+
api_key = project.create_api_key("my api key name")
|
27
|
+
```
|
28
|
+
4. Save your api_key's secret:
|
29
|
+
```ruby
|
30
|
+
puts "Your new RANCHER_ACCESS_KEY=#{api_key.publicValue}"
|
31
|
+
puts "Your new RANCHER_SECRET_KEY=#{api_key.secretValue}"
|
32
|
+
```
|
@@ -3,8 +3,8 @@ require "faraday"
|
|
3
3
|
|
4
4
|
module Rancher
|
5
5
|
module ManagementApi
|
6
|
-
def self.connection(host =
|
7
|
-
Faraday.new(url: host) do |faraday|
|
6
|
+
def self.connection(host = nil)
|
7
|
+
Faraday.new(url: host || ENV["RANCHER_URL"]) do |faraday|
|
8
8
|
faraday.headers["Content-Type"] = "application/json"
|
9
9
|
faraday.headers["Accept"] = "application/json"
|
10
10
|
faraday.adapter Faraday.default_adapter
|