class ScalingoBackupsManager::Addon
Constants
- DEFAULT_DATABASE_API_ROOT_URL
Attributes
addon[RW]
application[RW]
config[RW]
sftp_config[RW]
Public Class Methods
find(app, id, config: {}, sftp_config: {})
click to toggle source
# File lib/scalingo_backups_manager/addon.rb, line 12 def self.find(app, id, config: {}, sftp_config: {}) addon = Configuration.client.addons.find(app.id, id).data self.new(app, addon, config: config, sftp_config: sftp_config) end
new(app, addon, config: {}, sftp_config: {})
click to toggle source
# File lib/scalingo_backups_manager/addon.rb, line 17 def initialize(app, addon, config: {}, sftp_config: {}) raise "Application must be set" unless app && app.is_a?(ScalingoBackupsManager::Application) @application = app @addon = addon @sftp_config = sftp_config @config = config end
Public Instance Methods
backups()
click to toggle source
# File lib/scalingo_backups_manager/addon.rb, line 53 def backups response = client.authenticated_connection.get("#{database_api_url}/backups").body return [] unless response[:database_backups] && response[:database_backups].size > 0 bcks = [] response[:database_backups].each do |backup| bcks.push ScalingoBackupsManager::Backup.new(self, backup[:id]) end bcks end
client(options: {})
click to toggle source
# File lib/scalingo_backups_manager/addon.rb, line 30 def client(options: {}) return @client if @client scalingo = Scalingo::Client.new scalingo.authenticate_with(access_token: ENV["SCALINGO_API_TOKEN"]) response = scalingo.addons.token(application.id, id).data if response.try(:[], :token) bearer_token = response[:token] else raise "An error occured during addon authentication" end addon_cli_config = Scalingo::Client.new addon_cli_config.token = bearer_token @client = Scalingo::API::Client.new(database_api_url(options), scalingo: addon_cli_config) end
database_api_url(options: {})
click to toggle source
# File lib/scalingo_backups_manager/addon.rb, line 25 def database_api_url(options: {}) return @database_api_url if @database_api_url @database_api_url = "#{options[:database_api_root_url] || DEFAULT_DATABASE_API_ROOT_URL}/api/databases/#{id}" end