class ThreeScaleToolbox::Commands::PoliciesCommand::ImportSubcommand
Public Class Methods
command()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 8 def self.command Cri::Command.define do name 'import' usage 'import [opts] <remote> <product>' summary 'import product policy chain' description 'import product policy chain' option :f, :file, 'Read from file', argument: :required option :u, :url, 'Read from url', argument: :required param :remote param :service_ref runner ImportSubcommand end end
Public Instance Methods
run()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 24 def run res = product.update_policies('policies_config' => policies) if res.is_a?(Hash) && (errors = res['errors']) raise ThreeScaleToolbox::Error, "Product policies have not been imported. #{errors}" end if res.is_a?(Array) && (error_item = res.find { |i| i.key?('errors') }) raise ThreeScaleToolbox::Error, "Product policies have not been imported. #{error_item['errors']}" end end
Private Instance Methods
find_product()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 48 def find_product Entities::Service.find(remote: remote, ref: service_ref).tap do |svc| raise ThreeScaleToolbox::Error, "Product #{service_ref} does not exist" if svc.nil? end end
policies()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 55 def policies @policies ||= load_resource(options[:file] || options[:url] || '-') end
product()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 44 def product @product ||= find_product end
remote()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 36 def remote @remote ||= threescale_client(arguments[:remote]) end
service_ref()
click to toggle source
# File lib/3scale_toolbox/commands/policies_command/import_command.rb, line 40 def service_ref arguments[:service_ref] end