umbreo_cli 1.0.141

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.env +2 -0
  3. data/Gemfile +23 -0
  4. data/Gemfile.lock +106 -0
  5. data/README.md +1625 -0
  6. data/Rakefile +44 -0
  7. data/bin/manifests/init.pp +20 -0
  8. data/bin/umbreo +1684 -0
  9. data/bin/umbreo.json +34 -0
  10. data/lib/umbreo.rb +49 -0
  11. data/lib/umbreo/helpers/alert_message.rb +58 -0
  12. data/lib/umbreo/helpers/error_exception.rb +15 -0
  13. data/lib/umbreo/helpers/file_generator.rb +13 -0
  14. data/lib/umbreo/helpers/json_base_convert.rb +30 -0
  15. data/lib/umbreo/helpers/table.rb +45 -0
  16. data/lib/umbreo/models/amazon_web_service_provider.rb +260 -0
  17. data/lib/umbreo/models/authentication.rb +99 -0
  18. data/lib/umbreo/models/blueprint.rb +241 -0
  19. data/lib/umbreo/models/cloud_provider.rb +143 -0
  20. data/lib/umbreo/models/configuration.rb +98 -0
  21. data/lib/umbreo/models/digital_ocean_provider.rb +204 -0
  22. data/lib/umbreo/models/google_compute_engine_provider.rb +232 -0
  23. data/lib/umbreo/models/instance.rb +170 -0
  24. data/lib/umbreo/models/module.rb +61 -0
  25. data/lib/umbreo/models/openstack_provider.rb +260 -0
  26. data/lib/umbreo/models/profile.rb +61 -0
  27. data/lib/umbreo/models/provider.rb +164 -0
  28. data/lib/umbreo/models/service.rb +244 -0
  29. data/lib/umbreo/models/service_provider.rb +185 -0
  30. data/lib/umbreo/models/stack.rb +181 -0
  31. data/lib/umbreo/models/system.rb +43 -0
  32. data/lib/umbreo/models/umbreo_stack_template.rb +163 -0
  33. data/lib/umbreo/models/xenserver_provider.rb +200 -0
  34. data/lib/umbreo/version.rb +3 -0
  35. data/manifests/init.pp +20 -0
  36. data/manifests1/init.pp +9 -0
  37. data/umbreo.gemspec +28 -0
  38. metadata +241 -0
@@ -0,0 +1,99 @@
1
+ module Umbreo
2
+ module Models
3
+ class Authentication
4
+
5
+ #
6
+ # Init data
7
+ #
8
+ def initialize(email = nil, password = nil)
9
+ config = Configuration.new
10
+
11
+ @email = email
12
+ @password = password
13
+ @endpoint = (config.read_file_authentication[:end_point] rescue nil) || SERVER_END_POINT
14
+ @message = Helpers::AlertMessage
15
+ @errors = []
16
+ end
17
+
18
+ #
19
+ # Check credentails validation
20
+ #
21
+ def valid?
22
+ @errors << "Email or Password Can not be blank!" if @email.blank? || @password.blank?
23
+ if @email.present?
24
+ @errors << "Invalid format email" if @email.match(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i).blank?
25
+ end
26
+
27
+ @errors.blank?
28
+ end
29
+
30
+ #
31
+ # return error from validation
32
+ #
33
+ def error
34
+ @errors.first
35
+ end
36
+
37
+ #
38
+ # Access server and get access token
39
+ #
40
+ def sign_in_and_retrieve_token!
41
+ begin
42
+ _request = Typhoeus.post(
43
+ "#{@endpoint}/api/v1/users/retrieve_token",
44
+ body: {
45
+ email: @email,
46
+ password: @password,
47
+ }
48
+ )
49
+
50
+ @data = JSON.parse _request.response_body
51
+ rescue Exception => e
52
+ @data = { message: "An error of type #{e.class} happened, #{e.message}"}
53
+ end
54
+ end
55
+
56
+ #
57
+ # remove file configuration
58
+ #
59
+ def sign_out
60
+ config = Configuration.new
61
+ config.delete
62
+ puts 'Local credentials cleared.'
63
+ end
64
+
65
+ #
66
+ # Action after retrive token
67
+ #
68
+ def sign_in_callback
69
+ if @data['success']
70
+ @message.show_success_message("Setting up configuration file at ~/.umbreoconfig...")
71
+
72
+ config = Configuration.new
73
+ end_point_url = config.read_file_authentication[:end_point] rescue nil
74
+ config.write_file_authentication(@data, end_point_url)
75
+
76
+ sleep 1
77
+ puts "Logged in as #{ Rainbow(@data['email']).cyan }"
78
+ else
79
+ @message.show_error_message(@data['message'])
80
+ end
81
+ end
82
+
83
+ #
84
+ # check current_user
85
+ #
86
+ def retrieve_credentails!
87
+ config = Configuration.new
88
+
89
+ if config.is_valid_user?
90
+ config.read_file_authentication
91
+ else
92
+ @message.show_error_message("Invalid credentials. Please try to login `umbreo login` again.")
93
+ exit!(0)
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,241 @@
1
+ module Umbreo
2
+ module Models
3
+ class Blueprint
4
+
5
+ OPERATING_SYSTEM = %w(linux windows)
6
+
7
+ def initialize(credentials = {}, name_or_id = nil, status = false)
8
+ if credentials.present?
9
+ @email = credentials[:email]
10
+ @api_key = credentials[:api_key]
11
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
12
+ end
13
+
14
+ @name_or_id = name_or_id
15
+ @status = status
16
+ @errors = []
17
+ end
18
+
19
+ def retrieve_data(filter = {})
20
+ Helpers::ErrorException.rescue do
21
+ url = if @status
22
+ "#{@endpoint}/api/v1/blueprints/custom"
23
+ else
24
+ "#{@endpoint}/api/v1/blueprints"
25
+ end
26
+
27
+ data = Typhoeus.get(
28
+ url,
29
+ body: {
30
+ authenticate_token: @api_key,
31
+ email: @email,
32
+ filter: filter
33
+ }
34
+ )
35
+
36
+ @data = JSON.parse data.response_body
37
+ end
38
+ end
39
+
40
+ def all(filter = {})
41
+ @errors << "Please choose correct one of os |#{OPERATING_SYSTEM.join(", ")}|" if OPERATING_SYSTEM.exclude?(filter[:os].to_s) && filter[:os].present?
42
+ @errors << "Search keyword is required." if filter[:keyword].blank? && filter[:search]
43
+
44
+ if valid?
45
+ retrieve_data(filter)
46
+
47
+ if @data['roles'].present?
48
+ page = " | Page: #{filter[:page]} of #{@data['total_page']} pages"
49
+ header = if @status
50
+ "List My Custom Blueprint#{ page if @data['total_page'] > 1 }"
51
+ else
52
+ "List Blueprint#{ page if @data['total_page'] > 1 }"
53
+ end
54
+
55
+ Helpers::Table.show_table(@data['roles'], header, ['ID', 'Name', 'Slug', 'OS', 'Description'])
56
+ else
57
+ Helpers::AlertMessage.show_error_message(@data["message"])
58
+ end
59
+ else
60
+ Helpers::AlertMessage.show_error_message(error)
61
+ end
62
+ end
63
+
64
+ def show
65
+ Helpers::ErrorException.rescue do
66
+ url = if @status
67
+ "#{@endpoint}/api/v1/blueprints/show_custom"
68
+ else
69
+ "#{@endpoint}/api/v1/blueprints/show"
70
+ end
71
+
72
+ response = Typhoeus.get(
73
+ url,
74
+ body: {
75
+ authenticate_token: @api_key,
76
+ email: @email,
77
+ id: @name_or_id
78
+ }
79
+ )
80
+
81
+ response = JSON.parse response.response_body rescue nil
82
+
83
+ if response['success']
84
+ Helpers::AlertMessage.show_content_information_message(response['id']) { "ID: #message" }
85
+ Helpers::AlertMessage.show_content_information_message(response['name']) { "Name: #message" }
86
+ Helpers::AlertMessage.show_content_information_message(response['description']) { "Description: #message" }
87
+ Helpers::AlertMessage.show_content_information_message(response['os']) { "OS: #message" }
88
+ else
89
+ Helpers::AlertMessage.show_error_message(response['message'])
90
+ end
91
+ end
92
+ end
93
+
94
+ def delete
95
+ data = Typhoeus.delete(
96
+ "#{@endpoint}/api/v1/blueprints/#{@name_or_id}",
97
+ body: {
98
+ authenticate_token: @api_key,
99
+ email: @email
100
+ }
101
+ )
102
+
103
+ @data = JSON.parse data.response_body
104
+
105
+ if @data["success"]
106
+ Helpers::AlertMessage.show_success_message(@data["message"])
107
+ else
108
+ Helpers::AlertMessage.show_error_message(@data["message"])
109
+ end
110
+ end
111
+
112
+ def create!(attributes = {})
113
+ @create_name = attributes[:name]
114
+ @create_description = attributes[:description]
115
+ @create_os = attributes[:os]
116
+ @create_system = attributes[:system]
117
+ @create_profiles = attributes[:profiles]
118
+
119
+ create_validation!
120
+
121
+ if valid?
122
+ Helpers::ErrorException.rescue do
123
+ data = Typhoeus.post(
124
+ "#{@endpoint}/api/v1/blueprints",
125
+ body: {
126
+ authenticate_token: @api_key,
127
+ email: @email,
128
+ user_role: {
129
+ name: @create_name,
130
+ description: @create_description,
131
+ os: @create_os,
132
+ umbreo_profile_ids: @create_profiles
133
+ }
134
+ }
135
+ )
136
+
137
+ @data = JSON.parse data.response_body
138
+
139
+ if @data["success"]
140
+ Helpers::AlertMessage.show_success_message(@data['message'])
141
+ else
142
+ Helpers::AlertMessage.show_error_message(@data['message'])
143
+ end
144
+ end
145
+ else
146
+ Helpers::AlertMessage.show_error_message(error)
147
+ end
148
+ end
149
+
150
+ def create_validation!
151
+ @errors << "Name of blueprint is required" if @create_name.blank?
152
+ @errors << "Operating system is required" if @create_os.blank?
153
+ @errors << "System is required" if @create_system.blank?
154
+ @errors << "Profiles is required" if @create_profiles.blank?
155
+ end
156
+
157
+ #
158
+ # get json files params of blueprint
159
+ #
160
+ def export
161
+ @errors << "ID or Slug is required." if @name_or_id.blank?
162
+
163
+ if valid?
164
+ Helpers::ErrorException.rescue do
165
+ data = Typhoeus.get(
166
+ "#{@endpoint}/api/v1/blueprints/export",
167
+ body: {
168
+ authenticate_token: @api_key,
169
+ email: @email,
170
+ id: @name_or_id,
171
+ status: @status
172
+ }
173
+ )
174
+
175
+ @data = JSON.parse data.response_body rescue nil
176
+ role = @data["user_role"] || @data["umbreo_role"]
177
+
178
+ if role.present?
179
+ name_file = role["name"].downcase.titleize.delete(" ").underscore
180
+ Helpers::FileGenerator.create(name_file, role)
181
+ Helpers::AlertMessage.show_success_message("Success export blueprint. your blueprint is saved on json file with name #{name_file}.json")
182
+ else
183
+ Helpers::AlertMessage.show_error_message(@data["message"])
184
+ end
185
+ end
186
+ else
187
+ Helpers::AlertMessage.show_error_message(error)
188
+ end
189
+ end
190
+
191
+ #
192
+ # check valid json params
193
+ #
194
+ def validate(file_path)
195
+ @errors << "File directory is required." if file_path.blank?
196
+ begin
197
+ file = File.open(file_path, "r")
198
+ content = file.read
199
+ json = JSON.parse(content)
200
+ encode = Helpers::JsonBaseConvert.encode(json)
201
+ rescue
202
+ @errors << "Error on file. Please check again."
203
+ end
204
+ @errors << "Content of file is required." if content.blank?
205
+
206
+ if valid?
207
+ Helpers::ErrorException.rescue do
208
+
209
+ response = Typhoeus.get(
210
+ "#{@endpoint}/api/v1/blueprints/validate",
211
+ body: {
212
+ authenticate_token: @api_key,
213
+ email: @email,
214
+ content: encode
215
+ }
216
+ )
217
+
218
+ @response = JSON.parse response.response_body
219
+
220
+ if @response["success"]
221
+ Helpers::AlertMessage.show_success_message(@response["message"])
222
+ else
223
+ Helpers::AlertMessage.show_error_message(@response["message"])
224
+ end
225
+ end
226
+ else
227
+ Helpers::AlertMessage.show_error_message(error)
228
+ end
229
+ end
230
+
231
+ def error
232
+ @errors.first
233
+ end
234
+
235
+ def valid?
236
+ @errors.blank?
237
+ end
238
+
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,143 @@
1
+ module Umbreo
2
+ module Models
3
+ class CloudProvider
4
+
5
+ #
6
+ # available provider with slug name
7
+ #
8
+ CLOUDS = [:aws, :gcompute, :docean, :openstack, :XenServer]
9
+
10
+ #
11
+ # Init Global Variable
12
+ #
13
+ def initialize(credentials = {}, slug_or_id = nil)
14
+ if credentials.present?
15
+ @email = credentials[:email]
16
+ @api_key = credentials[:api_key]
17
+ @endpoint = credentials[:end_point] || SERVER_END_POINT
18
+ end
19
+
20
+ @errors = []
21
+ @slug_or_id = slug_or_id
22
+ end
23
+
24
+ #
25
+ # get all available data cloud provider
26
+ #
27
+ def retrieve_data
28
+ Helpers::ErrorException.rescue do
29
+ data = Typhoeus.get(
30
+ "#{@endpoint}/api/v1/cloud_providers",
31
+ body: {
32
+ authenticate_token: @api_key,
33
+ email: @email
34
+ }
35
+ )
36
+
37
+ @data = JSON.parse data.response_body
38
+ end
39
+ end
40
+
41
+ #
42
+ # callback for retrieve data
43
+ #
44
+ def all
45
+ retrieve_data
46
+
47
+ if @data['umbreo_cloud_providers'].present?
48
+ Helpers::Table.show_table(@data['umbreo_cloud_providers'], "List Cloud Provider", ['ID', 'Name', 'Slug', 'Description'])
49
+ else
50
+ Helpers::AlertMessage.show_error_message(@data["message"])
51
+ end
52
+ end
53
+
54
+ #
55
+ # export params json of cloud provider
56
+ #
57
+ def export
58
+ @errors << "ID or Slug is required." if @slug_or_id.blank?
59
+ @errors << "ID or Slug is not found." if CLOUDS.exclude? @slug_or_id.to_sym
60
+
61
+ if valid?
62
+ Helpers::ErrorException.rescue do
63
+ response = Typhoeus.get(
64
+ "#{@endpoint}/api/v1/cloud_providers/export",
65
+ body: {
66
+ authenticate_token: @api_key,
67
+ email: @email,
68
+ id: @slug_or_id
69
+ }
70
+ )
71
+
72
+ @response = JSON.parse response.response_body rescue nil
73
+ if @response["umbreo_cloud_provider"].present?
74
+ name_file = @response["umbreo_cloud_provider"]["name"].downcase.titleize.delete(" ").delete("/").underscore
75
+ Helpers::FileGenerator.create(name_file, @response["umbreo_cloud_provider"])
76
+ Helpers::AlertMessage.show_success_message("Success export cloud provider. your cloud_provider is saved on json file with name #{name_file}.json")
77
+ else
78
+ Helpers::AlertMessage.show_error_message(@response["message"])
79
+ end
80
+ end
81
+ else
82
+ Helpers::AlertMessage.show_error_message(error)
83
+ end
84
+ end
85
+
86
+ #
87
+ # check valid json params
88
+ #
89
+ def validate(file_path)
90
+ @errors << "File directory is required." if file_path.blank?
91
+
92
+ begin
93
+ file = File.open(file_path, "r")
94
+ content = file.read
95
+ json = JSON.parse(content)
96
+ encode = Helpers::JsonBaseConvert.encode(json)
97
+ rescue
98
+ @errors << "Error on file. Please check again."
99
+ end
100
+ @errors << "Content of file is required." if content.blank?
101
+
102
+ if valid?
103
+ Helpers::ErrorException.rescue do
104
+
105
+ response = Typhoeus.get(
106
+ "#{@endpoint}/api/v1/cloud_providers/validate",
107
+ body: {
108
+ authenticate_token: @api_key,
109
+ email: @email,
110
+ content: encode
111
+ }
112
+ )
113
+
114
+ @response = JSON.parse response.response_body
115
+
116
+ if @response["success"]
117
+ Helpers::AlertMessage.show_success_message(@response["message"])
118
+ else
119
+ Helpers::AlertMessage.show_error_message(@response["message"])
120
+ end
121
+ end
122
+ else
123
+ Helpers::AlertMessage.show_error_message(error)
124
+ end
125
+ end
126
+
127
+ #
128
+ # check if no errors
129
+ #
130
+ def valid?
131
+ @errors.blank?
132
+ end
133
+
134
+ #
135
+ # get first of errors
136
+ #
137
+ def error
138
+ @errors.first
139
+ end
140
+
141
+ end
142
+ end
143
+ end