sfrest 0.0.24 → 0.0.29

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
  SHA256:
3
- metadata.gz: 9ee79c665b3444d5bd753652f9244ae3920cd8f9240cc9a628b883139ea18b40
4
- data.tar.gz: 67a0c06a31049777e955259513c725f57a339af862f7dbecdec5146a7ac09ab1
3
+ metadata.gz: 2c294e5ab1ba9e6a0a6be84b0c222ca5beae8326438db8c16dbee4a68d189599
4
+ data.tar.gz: ce5a155559c66f8b7831a7cb14964fc2ca4ca2465492bdfa479fdd22defc5bb9
5
5
  SHA512:
6
- metadata.gz: 027e57b3b115f1af636acc5691a6bc68c7a44b666255104689c7b58b38a2cc99340bdd59b019263dcb36f56199fbcf4c69e67d7762c834adfc84c42060d4afc3
7
- data.tar.gz: '0817a732028ef2d5fa907b3cc64b1babb0d9ea38b5a896277a167306c048f59898ec8714c39cd04e47d397e90233c319b911119a3e259985639d36533bbe53b8'
6
+ metadata.gz: edbdd8905bcc0ce249042f77e0e04a797ca852933adb4c9c546e83ad329f67711ce3ba2311650e44ea9a08b891f82b6f2e01e2052b3b9c1b65458f14e74d2d8a
7
+ data.tar.gz: 03e34c3a38581414209a546cdd0da6f6b9ee17c64f65539f6984f92e5ee7b4ae8d44dbe5552db5fbdce9a741607fdb4eec51c6f49c4bbad2a788246decdb70d1
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Simple wrappper around RestClient.Resource
2
4
  $LOAD_PATH.unshift(__dir__) unless
3
5
  $LOAD_PATH.include?(__dir__) ||
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Get all the audit devents.
3
5
  class Audit
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Backup a site or restore onto that site
3
5
  class Backup
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # List codebases on the factory.
3
5
  class Codebase
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Find colletions, return their data.
3
5
  class Collection
@@ -61,7 +63,7 @@ module SFRest
61
63
  not_done = true
62
64
  count = 0
63
65
  while not_done
64
- current_path = '/api/v1/collections?page=' << page.to_s
66
+ current_path = '/api/v1/collections?page='.dup << page.to_s
65
67
  res = @conn.get(current_path)
66
68
  if res['collections'] == []
67
69
  not_done = false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Generic http methods
3
5
  # accessors for all the sub classes.
@@ -77,16 +79,18 @@ module SFRest
77
79
 
78
80
  # http request via delete
79
81
  # @param [string] uri
82
+ # @param [string] payload - This string will be supplied in the body of the request, similar to POST.
80
83
  # @return [Object] ruby representation of the json response
81
84
  # if the reponse body does not parse, raises
82
85
  # a SFRest::InvalidResponse
83
- def delete(uri)
86
+ def delete(uri, payload = '')
84
87
  headers = { 'Content-Type' => 'application/json' }
85
88
  res = Excon.delete(@base_url + uri.to_s,
86
89
  headers: headers,
87
90
  user: username,
88
91
  password: password,
89
- ssl_verify_peer: false)
92
+ ssl_verify_peer: false,
93
+ body: payload)
90
94
  api_response res
91
95
  end
92
96
 
@@ -177,8 +181,8 @@ module SFRest
177
181
 
178
182
  REST_METHODS.each do |m|
179
183
  define_method(m) do
180
- m.capitalize!
181
- sfrest_klass = "SFRest::#{m}"
184
+ klazz = m.dup.capitalize!
185
+ sfrest_klass = "SFRest::#{klazz}"
182
186
  Object.const_get(sfrest_klass).new(self)
183
187
  end
184
188
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Find Staging envs and stage a set of sites
3
5
  class Domains
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Error classes for SFRest
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # SF Group management
3
5
  class Group
@@ -15,14 +17,98 @@ module SFRest
15
17
  @conn.post(current_path, payload)
16
18
  end
17
19
 
20
+ # Deletes the group with the specified id
21
+ # @param [Integer] group_id Id of the group to fetch
22
+ def delete_group(group_id)
23
+ current_path = '/api/v1/groups/' + group_id.to_s
24
+ @conn.delete(current_path)
25
+ end
26
+
27
+ # Renames existing group.
28
+ # @param [Integer] group_id Id of the group to rename.
29
+ # @param [String] groupname New name for the group.
30
+ def rename_group(group_id, groupname)
31
+ current_path = '/api/v1/groups/' + group_id.to_s + '/update'
32
+ payload = { 'group_name' => groupname }.to_json
33
+ @conn.put(current_path, payload)
34
+ end
35
+
18
36
  # Gets a site group with a specified group id.
19
37
  # @param [Integer] group_id Id of the group to fetch
20
38
  # @return [Hash] group object from the SF Api
21
39
  def get_group(group_id = 0)
22
- current_path = '/api/v1/groups/' << group_id.to_s
40
+ current_path = '/api/v1/groups/' + group_id.to_s
41
+ @conn.get(current_path)
42
+ end
43
+
44
+ # Gets all users that are members of this group
45
+ # @param [Integer] group_id Id of the group to fetch
46
+ # @return [Hash] {'count' => count, 'members' => Hash }
47
+ def get_members(group_id = 0)
48
+ current_path = '/api/v1/groups/' + group_id.to_s + '/members'
23
49
  @conn.get(current_path)
24
50
  end
25
51
 
52
+ # Add users to this group
53
+ # @param [Integer] group_id Id of the group
54
+ # @param [Array] uids of the users that need to be added
55
+ # @return [Hash] {'count' => count, 'uids_added' => Hash }
56
+ def add_members(group_id, uids)
57
+ current_path = '/api/v1/groups/' + group_id.to_s + '/members'
58
+ payload = { 'uids' => uids.map(&:to_i) }.to_json
59
+ @conn.post(current_path, payload)
60
+ end
61
+
62
+ # Remove members from this group
63
+ # @param [Integer] group_id Id of the group
64
+ # @param [Array] uids of the users that need to be removed
65
+ # @return [Hash] {'group_id' => 123, 'uids_removed' => [1, 2, ...]}
66
+ def remove_members(group_id, uids)
67
+ current_path = '/api/v1/groups/' + group_id.to_s + '/members'
68
+ payload = { 'uids' => uids.map(&:to_i) }.to_json
69
+ @conn.delete(current_path, payload)
70
+ end
71
+
72
+ # Promote users to group admins
73
+ # @param [Integer] group_id Id of the group
74
+ # @param [Array] uids of the users that need to be promoted
75
+ # @return [Hash] {'count' => count, 'uids_promoted' => [1, 2, ...] }
76
+ def promote_to_admins(group_id, uids)
77
+ current_path = '/api/v1/groups/' + group_id.to_s + '/admins'
78
+ payload = { 'uids' => uids.map(&:to_i) }.to_json
79
+ @conn.post(current_path, payload)
80
+ end
81
+
82
+ # Demote users from group admins
83
+ # @param [Integer] group_id Id of the group
84
+ # @param [Array] uids of the users that need to be demoted
85
+ # @return [Hash] {'count' => count, 'uids_demoted' => Hash }
86
+ def demote_from_admins(group_id, uids)
87
+ current_path = '/api/v1/groups/' + group_id.to_s + '/admins'
88
+ payload = { 'uids' => uids.map(&:to_i) }.to_json
89
+ @conn.delete(current_path, payload)
90
+ end
91
+
92
+ # Add sites to this group
93
+ # @param [Integer] group_id Id of the group
94
+ # @param [Array] site_ids Ids of the sites that need to be added
95
+ # @return [Hash] {'group_id' => 123, 'site_ids_added' => [1, 2, ...]}
96
+ def add_sites(group_id, site_ids)
97
+ current_path = '/api/v1/groups/' + group_id.to_s + '/sites'
98
+ payload = { 'site_ids' => site_ids }.to_json
99
+ @conn.post(current_path, payload)
100
+ end
101
+
102
+ # Remove sites from this group
103
+ # @param [Integer] group_id Id of the group
104
+ # @param [Array] site_ids Ids of the sites that need to be removed.
105
+ # @return [Hash] {'group_id' => 123, 'site_ids_removed' => [1, 2, ...], 'site_ids_failed' => [3, 4, ...]}
106
+ def remove_sites(group_id, site_ids)
107
+ current_path = '/api/v1/groups/' + group_id.to_s + '/sites'
108
+ payload = { 'site_ids' => site_ids }.to_json
109
+ @conn.delete(current_path, payload)
110
+ end
111
+
26
112
  # Gets a list of all site groups.
27
113
  # @return [Hash] all the groups on the factory plus a count
28
114
  # {'count' => count, 'groups' => Hash }
@@ -32,7 +118,7 @@ module SFRest
32
118
  not_done = true
33
119
  count = 0
34
120
  while not_done
35
- current_path = '/api/v1/groups?page=' << page.to_s
121
+ current_path = '/api/v1/groups?page='.dup << page.to_s
36
122
  res = @conn.get(current_path)
37
123
  if res['groups'] == []
38
124
  not_done = false
@@ -50,5 +136,28 @@ module SFRest
50
136
  end
51
137
  { 'count' => count, 'groups' => groups }
52
138
  end
139
+
140
+ # gets the group ID for the group named groupname
141
+ # will page through all the groups available searching for the group
142
+ # @param [String] group the name of the group
143
+ # @return [Integer] the id of groupname
144
+ def get_group_id(groupname)
145
+ res = group_list
146
+ id = group_data_from_results(res, groupname, 'group_id')
147
+ return id if id
148
+ end
149
+
150
+ # Extract the group data for 'key' based on the site result object
151
+ # @param [Hash] res result from a request to /sites
152
+ # @param [String] groupname
153
+ # @param [String] key one of the user data returned (id, site, domain...)
154
+ # @return [Object] Integer, String, Array, Hash depending on the site data
155
+ def group_data_from_results(res, groupname, key)
156
+ groups = res['groups']
157
+ groups.each do |group|
158
+ return group[key] if group['group_name'] == groupname
159
+ end
160
+ nil
161
+ end
53
162
  end
54
163
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Retrieve Site Factory info.
3
5
  class Info
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # make a url querypath
3
5
  # so that if the are multiple items in a get request
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # create, delete, update, roles
3
5
  class Role
@@ -16,7 +18,7 @@ module SFRest
16
18
  not_done = true
17
19
  count = 0
18
20
  while not_done
19
- current_path = '/api/v1/roles?page=' << page.to_s
21
+ current_path = '/api/v1/roles?page='.dup << page.to_s
20
22
  res = @conn.get(current_path)
21
23
  if res['roles'] == []
22
24
  not_done = false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Find sites, create a site,
3
5
  class Site
@@ -64,7 +66,7 @@ module SFRest
64
66
  count = 0
65
67
  sites = []
66
68
  while not_done
67
- current_path = '/api/v1/sites?page=' << page.to_s
69
+ current_path = '/api/v1/sites?page='.dup << page.to_s
68
70
  current_path <<= '&show_incomplete=true' if show_incomplete
69
71
  res = @conn.get(current_path)
70
72
  if res['sites'] == []
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Find Staging envs and stage a set of sites
3
5
  class Stage
@@ -28,21 +30,26 @@ module SFRest
28
30
  # @param [Boolean] email_site_status send an email about the staging status of each site
29
31
  # @param [Boolean] wipe_target_environment recreate the target stage wiping all data
30
32
  # @param [synchronize_all_users] only stage the user accounts required for the related collections and groups
33
+ # @param [Array] Stacks Array of stack ids to wipe
31
34
  #
32
35
  # @return [Integer] Id of the staging task created.
36
+ # rubocop:disable Metrics/ParameterLists
33
37
  def enhanced_stage(env: 'test',
34
38
  sites: nil,
35
39
  email_site_status: false,
36
40
  wipe_target_environment: false,
37
- synchronize_all_users: true)
41
+ synchronize_all_users: true,
42
+ wipe_stacks: nil)
38
43
  raise InvalidApiVersion, staging_versions unless staging_versions.include? 2
39
44
 
40
45
  payload = { 'to_env' => env, 'sites' => sites,
41
46
  'detailed_status' => email_site_status,
42
47
  'wipe_target_environment' => wipe_target_environment,
43
- 'synchronize_all_users' => synchronize_all_users }.to_json
48
+ 'synchronize_all_users' => synchronize_all_users,
49
+ 'wipe_stacks' => wipe_stacks }.to_json
44
50
  @conn.post('/api/v2/stage', payload)
45
51
  end
52
+ # rubocop:enable Metrics/ParameterLists
46
53
 
47
54
  # Query for available staging environments
48
55
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Deal with tasks, find them, pause them...
3
5
  class Task
@@ -23,7 +25,7 @@ module SFRest
23
25
  # @param [Integer] status
24
26
  # @return [Boolean]
25
27
  def status_not_started?(status)
26
- return true if (status.to_i & STATUS_TO_BE_RUN) > 0
28
+ return true if (status.to_i & STATUS_TO_BE_RUN).positive?
27
29
 
28
30
  false
29
31
  end
@@ -42,7 +44,7 @@ module SFRest
42
44
  # @param [Integer] status
43
45
  # @return [Boolean]
44
46
  def status_running?(status)
45
- return true if (status.to_i & STATUS_RUNNING) > 0
47
+ return true if (status.to_i & STATUS_RUNNING).positive?
46
48
 
47
49
  false
48
50
  end
@@ -70,7 +72,7 @@ module SFRest
70
72
  # @param [Integer] status
71
73
  # @return [Boolean]
72
74
  def status_done?(status)
73
- return true if (status.to_i & STATUS_DONE) > 0
75
+ return true if (status.to_i & STATUS_DONE).positive?
74
76
 
75
77
  false
76
78
  end
@@ -207,7 +209,7 @@ module SFRest
207
209
  # Get a specific task's logs
208
210
  # @param [Integer] task_id
209
211
  def get_task_logs(task_id)
210
- current_path = '/api/v1/tasks/' << task_id.to_s << '/logs'
212
+ current_path = '/api/v1/tasks/' + task_id.to_s + '/logs'
211
213
  @conn.get(current_path)
212
214
  end
213
215
 
@@ -220,8 +222,8 @@ module SFRest
220
222
  begin
221
223
  res = @conn.get(current_path)
222
224
  paused = res['wip_pause_global']
223
- rescue SFRest::SFError => error
224
- paused = false if error.message =~ /Variable not found/
225
+ rescue SFRest::SFError => e
226
+ paused = false if e.message =~ /Variable not found/
225
227
  end
226
228
  paused
227
229
  end
@@ -231,7 +233,7 @@ module SFRest
231
233
  # @param [Integer] task_id
232
234
  # @param [String] level family|task
233
235
  def pause_task(task_id, level = 'family')
234
- current_path = '/api/v1/pause/' << task_id.to_s
236
+ current_path = '/api/v1/pause/' + task_id.to_s
235
237
  payload = { 'paused' => true, 'level' => level }.to_json
236
238
  @conn.post(current_path, payload)
237
239
  end
@@ -241,7 +243,7 @@ module SFRest
241
243
  # @param [Integer] task_id
242
244
  # @param [String] level family|task
243
245
  def resume_task(task_id, level = 'family')
244
- current_path = '/api/v1/pause/' << task_id.to_s
246
+ current_path = '/api/v1/pause/' + task_id.to_s
245
247
  payload = { 'paused' => false, 'level' => level }.to_json
246
248
  @conn.post(current_path, payload)
247
249
  end
@@ -259,7 +261,7 @@ module SFRest
259
261
  # This will delete the task and its children
260
262
  # @param [Integer] task_id
261
263
  def delete_task(task_id)
262
- current_path = '/api/v1/tasks/' << task_id.to_s
264
+ current_path = '/api/v1/tasks/' + task_id.to_s
263
265
  @conn.delete(current_path)
264
266
  end
265
267
 
@@ -267,7 +269,7 @@ module SFRest
267
269
  # @param [String] type softpaused | softpause-for-update
268
270
  # @return [Array] Array of wip classes
269
271
  def get_task_class_info(type = '')
270
- current_path = '/api/v1/classes/' << type
272
+ current_path = '/api/v1/classes/' + type
271
273
  @conn.get(current_path)
272
274
  end
273
275
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Tell the Factory that there is theme work to do
3
5
  class Theme
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Drive updates on the Site Factory
3
5
  class Update
@@ -24,7 +26,7 @@ module SFRest
24
26
 
25
27
  # Lists vcs refs.
26
28
  def list_vcs_refs(type = 'sites', stack_id = 1)
27
- current_path = '/api/v1/vcs?type=' << type << '&stack_id=' << stack_id.to_s
29
+ current_path = '/api/v1/vcs?type=' + type + '&stack_id=' + stack_id.to_s
28
30
  @conn.get(current_path)
29
31
  end
30
32
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Get all the audit devents.
3
5
  class Usage
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Do User actions within the Site Factory
3
5
  class User
@@ -14,7 +16,7 @@ module SFRest
14
16
  not_done = true
15
17
  count = 0
16
18
  while not_done
17
- current_path = '/api/v1/users?page=' << page.to_s
19
+ current_path = '/api/v1/users?page=' + page.to_s
18
20
  res = @conn.get(current_path)
19
21
  if res['users'] == []
20
22
  not_done = false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Perform actions against variables in the Factory
3
5
  class Variable
@@ -14,7 +16,7 @@ module SFRest
14
16
 
15
17
  # Gets the value of a specific variable.
16
18
  def get_variable(name)
17
- current_path = '/api/v1/variables?name=' << name
19
+ current_path = '/api/v1/variables?name=' + name
18
20
  @conn.get(current_path)
19
21
  end
20
22
 
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SFRest
2
4
  # Just tracks the version of sfrest.
3
- VERSION = '0.0.24'.freeze
5
+ VERSION = '0.0.29'
4
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - ACSF Engineering
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-20 00:00:00.000000000 Z
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.24'
97
97
  description: Wrapper methods around the ACSF Rest API.
98
- email:
98
+ email:
99
99
  executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
@@ -125,7 +125,7 @@ homepage: http://github.com/acquia/sf-sdk-ruby
125
125
  licenses:
126
126
  - APACHE-2.0
127
127
  metadata: {}
128
- post_install_message:
128
+ post_install_message:
129
129
  rdoc_options: []
130
130
  require_paths:
131
131
  - lib
@@ -140,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.0.2
144
- signing_key:
143
+ rubygems_version: 3.0.3
144
+ signing_key:
145
145
  specification_version: 4
146
146
  summary: Acquia Site Factory Rest API.
147
147
  test_files: []