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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dda5f9e739b125714ed5d9a9d97fd0ca98f2cfcb
4
- data.tar.gz: deeb646c6177712fa9d37a6232ce4d07b0fb0cc1
3
+ metadata.gz: a8e47474e013afef88f37a76c601e11a3244add2
4
+ data.tar.gz: 67e0cc31a9d46ed63467af6110e66aa6ca2d15f0
5
5
  SHA512:
6
- metadata.gz: f549bc9354c9032b6bc8856c036399fab0f876bd17d128041706eea3536ab5b15e4001a962a9c1a50c5a2b951e69eca10d2a9e565d81da22e106e14facaeb981
7
- data.tar.gz: 45343165ba1269aa33e18234d91b4730bf4b52cae2ed3c15920f949b7c83b0ce0f6edde7ae345f27204a77fd5647d66719ad84bc004eccf9b721b558d1eeafa7
6
+ metadata.gz: 766df1bc4efe60b8fd84940974437179929db4b98d306ffb81260248b9d0fc72159c24765ff343e0294f4df6bed8de2c7487348a79c9bebb2e12e591dcc8e4c4
7
+ data.tar.gz: a4176f74b542c6571cbf558216b66da28d6ed59fc010894817e3d4d66bf1dea8666f3d39dc249e3485660a00303e82dc226314635f0544a58bd98471f21aa7de
data/README.md CHANGED
@@ -1,262 +1,32 @@
1
- # Docs and scripts on how to Rancher
2
-
3
- To use the `bin/console` script, set these env vars:
4
- ```
5
- RANCHER_URL
6
- RANCHER_ACCESS_KEY
7
- RANCHER_SECRET_KEY
8
- ```
9
-
10
- To create a new environment (known as a `project` to the API):
11
-
12
- (Hint: `brew install jq` for pretty output)
13
-
14
- Get a real username and password:
15
- user: apiuser
16
- pass: rancher
17
-
18
- Ask for a JSON Web Token
19
-
20
- ```
21
- curl 'http://localhost:8080/v1/token' \
22
- -H 'Origin: http://localhost:8080' \
23
- -H 'Accept-Encoding: gzip, deflate' \
24
- -H 'Accept-Language: en-US,en;q=0.8' \
25
- -H 'Content-Type: application/json' \
26
- -H 'x-api-no-challenge: true' \
27
- -H 'Accept: application/json' \
28
- -H 'Referer: http://localhost:8080/login' \
29
- -H 'X-Requested-With: XMLHttpRequest' \
30
- -H 'Connection: keep-alive' \
31
- --data-binary '{"code":"apiuser:rancher"}' \
32
- --compressed \
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 @@ module Rancher
3
3
  class Manager
4
4
  attr_reader :conn
5
5
 
6
- def initialize(conn)
7
- @conn = conn
6
+ def initialize(conn = nil, host: nil)
7
+ @conn = conn || ManagementApi.connection(host)
8
8
  end
9
9
 
10
10
  def create_project(name)
@@ -1,5 +1,5 @@
1
1
  module Rancher
2
2
  module ManagementApi
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -3,8 +3,8 @@ require "faraday"
3
3
 
4
4
  module Rancher
5
5
  module ManagementApi
6
- def self.connection(host = ENV["RANCHER_URL"])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rancher-management_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Plummer