Class: Kaui::AdminTenant

Inherits:
KillBillClient::Model::Tenant
  • Object
show all
Defined in:
app/models/kaui/admin_tenant.rb

Class Method Summary collapse

Class Method Details

.format_plugin_config(plugin_key, plugin_type, props) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/models/kaui/admin_tenant.rb', line 106

def format_plugin_config(plugin_key, plugin_type, props)
  return nil unless props.present?
  if plugin_type == 'ruby'
    require 'yaml'
    hsh = {}
    hsh[plugin_key.to_sym] = {}
    props.each do |k,v|
      hsh[plugin_key.to_sym][k.to_sym] = v.to_sym
    end
    hsh[plugin_key.to_sym]
    hsh.to_yaml
  elsif plugin_type == 'java'
    res = ""
    props.each do |k, v|
      res = "#{res}#{k.to_s}=#{v.to_s}\n"
    end
    res
  else
    props['raw_config']
  end
end

.get_oss_plugin_info(plugin_directory) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/kaui/admin_tenant.rb', line 40

def get_oss_plugin_info(plugin_directory)


  # Serialize the plugin state for the view:
  #  plugin_name#plugin_type:prop1,prop2,prop3;plugin_name#plugin_type:prop1,prop2,prop3;...
  #
  plugin_config = plugin_directory.inject({}) do |hsh, (k,v)|
    hsh["#{k}##{v[:type]}"] = v[:require] || []
    hsh
  end
  plugin_config.map { |e,v| "#{e}:#{v.join(",")}" }.join(";")
end

.get_plugin_repositoryObject



29
30
31
32
33
34
35
36
37
38
# File 'app/models/kaui/admin_tenant.rb', line 29

def get_plugin_repository
  require 'open-uri'
  require 'yaml'

  source = URI.parse('https://raw.githubusercontent.com/killbill/killbill-cloud/master/kpm/lib/kpm/plugins_directory.yml').read
  YAML.load(source)
rescue
  # Ignore gracefully
  {}
end

.get_tenant_plugin_config(plugin_directory, options) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/models/kaui/admin_tenant.rb', line 53

def get_tenant_plugin_config(plugin_directory, options)

  require 'yaml'

  raw_tenant_config = KillBillClient::Model::Tenant::search_tenant_config("PLUGIN_CONFIG_", options)

  tenant_config = raw_tenant_config.inject({}) do |hsh, e|

    # Strip prefix '/PLUGIN_CONFIG_'
    killbill_key = e.key.gsub!(/PLUGIN_CONFIG_/, '')

    # Extract killbill key for oss plugins based on convention 'killbill-KEY'
    plugin_key = killbill_key.gsub(/killbill-/, '') if killbill_key.start_with?('killbill-')
    # hack:: rewrite key, to allow the ui to find the right configuration inputs
    plugin_key = rewrite_plugin_key(plugin_key)
    # If such key exists, lookup in plugin directory
    plugin_repo_entry = plugin_directory[plugin_key.to_sym] unless plugin_key.nil?
    # Extract plugin_type based on plugin_directory entry if exists
    plugin_type = plugin_repo_entry.nil? ? :unknown : plugin_repo_entry[:type].to_sym

    # Deserialize config based on type
    if plugin_type == :ruby
      yml = YAML.load(e.values[0])
      # Hash of properties
      hsh[plugin_key] = yml[plugin_key.to_sym]
    elsif plugin_type == :java
      # Construct hash of properties based on java properties (k1=v1\nk2=v2\n...)
      hsh[plugin_key] = e.values[0].split("\n").inject({}) do |h, p0|
        k, v = p0.split('=');
        h[k] = v;
        h
      end
    else
      # Construct simple hash with one property :raw_config
      hsh[killbill_key] = {:raw_config => e.values[0]}
    end
    hsh
  end

  # Serialize the whole thing a as string of the form:
  # plugin_key1::key1=value1|key2=value2|..;plugin_key2::...
  tenant_config.map do |plugin_key, props|
    serialized_props = props.inject("") do |s, (k, v)|
      e="#{k.to_s}=#{v.to_s}";
      s == "" ? s="#{e}" : s="#{s}|#{e}";
      s
    end
    "#{plugin_key}::#{serialized_props}"
  end.join(";")

end

.rewrite_plugin_key(plugin_key) ⇒ Object

hack when the plugin name after killbill is not the same as the plugin key, this mainly affects ruby plugin configuration, as it use the key to retrieve the configuration.



130
131
132
133
134
135
136
137
138
# File 'app/models/kaui/admin_tenant.rb', line 130

def rewrite_plugin_key(plugin_key)
  if plugin_key.start_with?('paypal')
    'paypal_express'
  elsif plugin_key.start_with?('firstdata')
    'firstdata_e4'
  else
    "#{plugin_key}"
  end
end

.upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



5
6
7
# File 'app/models/kaui/admin_tenant.rb', line 5

def upload_catalog(catalog_xml, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Catalog.upload_tenant_catalog(catalog_xml, user, reason, comment, options)
end

.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



21
22
23
# File 'app/models/kaui/admin_tenant.rb', line 21

def upload_catalog_translation(catalog_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Invoice.upload_catalog_translation(catalog_translation, locale, delete_if_exists, user, reason, comment, options)
end

.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



13
14
15
# File 'app/models/kaui/admin_tenant.rb', line 13

def upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Invoice.upload_invoice_template(invoice_template, is_manual_pay, delete_if_exists, user, reason, comment, options)
end

.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



17
18
19
# File 'app/models/kaui/admin_tenant.rb', line 17

def upload_invoice_translation(invoice_translation, locale, delete_if_exists, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Invoice.upload_invoice_translation(invoice_translation, locale, delete_if_exists, user, reason, comment, options)
end

.upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



9
10
11
# File 'app/models/kaui/admin_tenant.rb', line 9

def upload_overdue_config(overdue_config_xml, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Overdue.upload_tenant_overdue_config_xml(overdue_config_xml, user, reason, comment, options)
end

.upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



25
26
27
# File 'app/models/kaui/admin_tenant.rb', line 25

def upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {})
  KillBillClient::Model::Tenant.upload_tenant_plugin_config(plugin_name, plugin_config, user, reason, comment, options)
end