Skip to content

Commit

Permalink
DG-28970 | Add backup_requests method (#73)
Browse files Browse the repository at this point in the history
* DG-28970 | Add backup_requests method

* DG-28970 | Enhance test coverage

* DG-28970  | Refactor backup requests and add assertions

* DG-28970  | Refactor backup requests and add assertions

* DG-28970 | Refactor backup process in system tests

* DG-28970 | Extract assert_backup_result method

* DG-28970 | Fixed pipeline error

* DG-28970 | Fixed pipeline error

* DG-28970 | Resolved conflicts for specific files

---------

Co-authored-by: Swapnil Srivastava <[email protected]>
  • Loading branch information
swapnil91 and Swapnil Srivastava authored Dec 18, 2024
1 parent a4f5bfb commit 3362214
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/sfrest/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,53 @@ def create_backup(site_id, datum = nil)
@conn.post(current_path, datum.to_json)
end

def execute_backup(options = {})
api = options[:api]
rconn = options[:rconn]
acsf = options[:acsf]
site_nid = options[:site_nid]
name = options[:name]
components = options[:components]
user = options[:user]

case api
when 'rest'
execute_rest_backup(rconn, site_nid, name, components)
when 'drush'
execute_drush_backup(acsf, site_nid, name, components, user)
else
raise "Unsupported API: #{api}"
end
end

def execute_rest_backup(rconn, site_nid, name, components)
payload = {
'label' => name,
'components' => components
}.to_json
rconn.post "/api/v1/sites/#{site_nid}/backup", payload
end

def execute_drush_backup(acsf, site_nid, name, components, user)
drush_components = components.is_a?(Array) ? components.join(',') : components
drush_cmd = "sf-backup #{site_nid} \"#{name}\" --components=\"#{drush_components}\" --user=#{user} --format=json"
drush_cmd_update = acsf.drush drush_cmd
result = acsf.factory_ssh.exec!(drush_cmd_update).strip
JSON.parse(result)
end

def parse_response(response)
raise "Unexpected response type: #{response.class}" unless response.is_a?(Hash)

[response['task_id'], response['message']]
end

def parse_components(components_json)
JSON.parse(components_json)
rescue JSON::ParserError
components_json # Keep the original string if it's not valid JSON
end

# Gets a url to download a backup
# @param [Integer] site_id Node id of site
# @param [Integer] backup_id Id of backup to delete
Expand Down

0 comments on commit 3362214

Please sign in to comment.