deis-workflow 0.0.1
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/lib/deis-workflow.rb +145 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c37acad89fff04c11021e58f146d57a33fdf5f3f
|
4
|
+
data.tar.gz: 7e9b5ae119d11029dc2bf681b94a689088449911
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 899017b01be8401c6765a8b9d78f0ee2ebfcc1ee6135e71e458f93f2ab2b6b282dbb1422e4ea528e05d50e3865a1e3c5fc365cebee18e6ca02674807e5a3ede3
|
7
|
+
data.tar.gz: f4f1b3784dcdb766ffcef5521675c2e4a62ae67e2859951129d0fdbc5832b968a70b20ec9cadcf241f07c12aa1ee265ad67726ec5c0b1f604c92fc7846d5ebff
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'httparty'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module DeisWorkflow
|
7
|
+
class Client
|
8
|
+
|
9
|
+
def initialize(uri, api_key)
|
10
|
+
@api_key = api_key
|
11
|
+
@controller_uri = uri
|
12
|
+
@headers = { 'Authorization' => 'token %s' % @api_key, 'Content-Type' => 'application/json' }
|
13
|
+
end
|
14
|
+
|
15
|
+
# returns an api_key for that user
|
16
|
+
def self.login(username, password, uri)
|
17
|
+
HTTParty.post(
|
18
|
+
"#{uri}/v2/auth/login/",
|
19
|
+
:body => JSON.dump({
|
20
|
+
:username => username,
|
21
|
+
:password => password
|
22
|
+
}),
|
23
|
+
:headers => { 'Content-Type' => 'application/json' }
|
24
|
+
).parsed_response['token']
|
25
|
+
end
|
26
|
+
|
27
|
+
### Cluster level methods
|
28
|
+
|
29
|
+
def whoami
|
30
|
+
get('/v2/auth/whoami').parsed_response['username']
|
31
|
+
end
|
32
|
+
|
33
|
+
def users_list
|
34
|
+
get('/v2/users').parsed_response['results']
|
35
|
+
end
|
36
|
+
|
37
|
+
# registers a new user to the cluster
|
38
|
+
# returns a generated password
|
39
|
+
def register(username, email)
|
40
|
+
password = SecureRandom.urlsafe_base64
|
41
|
+
post('/v2/auth/register/', {
|
42
|
+
:username => username,
|
43
|
+
:password => password,
|
44
|
+
:email => email
|
45
|
+
})
|
46
|
+
# TODO handle the same user registering twice
|
47
|
+
password
|
48
|
+
end
|
49
|
+
|
50
|
+
### App level methods
|
51
|
+
|
52
|
+
def apps_list_all
|
53
|
+
get("/v2/apps").parsed_response
|
54
|
+
end
|
55
|
+
|
56
|
+
def app_exists?(app_name)
|
57
|
+
get("#{app_path(app_name)}").success?
|
58
|
+
end
|
59
|
+
|
60
|
+
def app_create(app_name)
|
61
|
+
post("/v2/apps", {
|
62
|
+
:id => app_name
|
63
|
+
}).success?
|
64
|
+
end
|
65
|
+
|
66
|
+
def app_logs(app_name)
|
67
|
+
get("#{app_path(app_name)}/logs/").parsed_response
|
68
|
+
end
|
69
|
+
|
70
|
+
### App pod related methods
|
71
|
+
|
72
|
+
def app_scale(app_name, pod_type, desired_pod_count)
|
73
|
+
post("#{app_path(app_name)}/scale/", {
|
74
|
+
pod_type.to_sym => desired_pod_count
|
75
|
+
}).success?
|
76
|
+
end
|
77
|
+
|
78
|
+
def app_list_pods(app_name)
|
79
|
+
get("#{app_path(app_name)}/pods/").parsed_response
|
80
|
+
end
|
81
|
+
|
82
|
+
def app_restart(app_name)
|
83
|
+
post("#{app_path(app_name)}/pods/restart/").success?
|
84
|
+
end
|
85
|
+
|
86
|
+
### App permissions methods
|
87
|
+
|
88
|
+
def perms_create(app_name, username)
|
89
|
+
post("#{app_path(app_name)}/perms/", {
|
90
|
+
:username => username
|
91
|
+
}).success?
|
92
|
+
end
|
93
|
+
|
94
|
+
def perms_delete(app_name, username)
|
95
|
+
delete("#{app_path(app_name)}/perms/#{username}/").success?
|
96
|
+
end
|
97
|
+
|
98
|
+
def perms_list(app_name)
|
99
|
+
get("#{app_path(app_name)}/perms/").parsed_response['users']
|
100
|
+
end
|
101
|
+
|
102
|
+
### App config methods
|
103
|
+
|
104
|
+
def config_list(app_name)
|
105
|
+
get("#{app_path(app_name)}/config/").parsed_response['values']
|
106
|
+
end
|
107
|
+
|
108
|
+
# values should be a hash
|
109
|
+
# unset by assigning values to nil
|
110
|
+
def config_set(app_name, values)
|
111
|
+
post("#{app_path(app_name)}/config/", {
|
112
|
+
:values => values
|
113
|
+
}).success?
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def app_path(app_name)
|
119
|
+
"/v2/apps/#{app_name}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def get(path)
|
123
|
+
HTTParty.get(
|
124
|
+
"#{@controller_uri}#{path}",
|
125
|
+
:headers => @headers
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
def post(path, body = nil)
|
130
|
+
HTTParty.post(
|
131
|
+
"#{@controller_uri}#{path}",
|
132
|
+
:body => JSON.dump(body),
|
133
|
+
:headers => @headers
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
def delete(path)
|
138
|
+
HTTParty.post(
|
139
|
+
"#{@controller_uri}#{path}",
|
140
|
+
:headers => @headers
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deis-workflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Davies
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A Deis Workflow Controller API library for Ruby
|
28
|
+
email: thomas@redant.com.au
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/deis-workflow.rb
|
34
|
+
homepage: http://rubygems.org/gems/deis-workflow
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.0.14
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Deis Workflow library
|
58
|
+
test_files: []
|