kpm 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a964f963d2c0c0b64e07c6d64c756ff2942fb94
4
+ data.tar.gz: 42429923060c944a9135b2d05607dc330c1c3b4a
5
+ SHA512:
6
+ metadata.gz: 73795dce14f6a0b598f47e57d940fb017dcc3976906bf069309cb661b8302b66d62e6c0aebb5ba56f38fd60b12afffe88763cd1a0f27873a376305e22e9345ea
7
+ data.tar.gz: 58b38cb7b290599fd00de043c65dcbda2b5b5e9461e56dd9b04fd3affc9f50f82400d293d8fc45160f86a9d41df30fb8fd9cbdf5fa58350c1b944b2fe25d55e8
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+
3
+ # Install tasks to build and release the plugin
4
+ require 'bundler/setup'
5
+ Bundler::GemHelper.install_tasks
data/bin/kpm ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path("../../lib", __FILE__)
3
+ require 'kpm'
4
+
5
+ begin
6
+ KPM::Cli.start
7
+ rescue => e
8
+ KPM.ui.say e.message, :red
9
+ exit 1
10
+ end
@@ -0,0 +1,21 @@
1
+ killbill:
2
+ # If no version is specified, LATEST is assumed
3
+ version: LATEST
4
+ webapp_path: /var/tmp/tomcat/webapps/ROOT
5
+ plugins_dir: /var/tmp/bundles
6
+ plugins:
7
+ java:
8
+ - name: analytics-plugin
9
+ version: 0.6.0
10
+ ruby:
11
+ - name: logging-plugin
12
+ version: LATEST
13
+ - name: zendesk-plugin
14
+ version: 1.3.0
15
+ nexus:
16
+ ssl_verify: false
17
+ url: https://repository.sonatype.org
18
+ repository: central-proxy
19
+ # You can use https://github.com/reidmorrison/symmetric-encryption for encryption
20
+ #username: bob
21
+ #password: bob
data/kpm.gemspec ADDED
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright 2014 The Billing Project, LLC
3
+ #
4
+ # The Billing Project licenses this file to you under the Apache License, version 2.0
5
+ # (the "License"); you may not use this file except in compliance with the
6
+ # License. You may obtain a copy of the License at:
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations
14
+ # under the License.
15
+ #
16
+
17
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
18
+ require 'kpm/version'
19
+
20
+ Gem::Specification.new do |s|
21
+ s.name = 'kpm'
22
+ s.version = KPM::Version.to_s
23
+ s.summary = 'Kill Bill package manager.'
24
+ s.description = 'A package manager for Kill Bill.'
25
+
26
+ s.required_ruby_version = '>= 1.8.6'
27
+
28
+ s.license = 'Apache License (2.0)'
29
+
30
+ s.author = 'Kill Bill core team'
31
+ s.email = 'killbilling-users@googlegroups.com'
32
+ s.homepage = 'http://kill-bill.org'
33
+
34
+ s.files = `git ls-files`.split("\n")
35
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
+ s.bindir = 'bin'
37
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
38
+ s.require_paths = ["lib"]
39
+
40
+ s.rdoc_options << '--exclude' << '.'
41
+
42
+ s.add_dependency 'highline', '~> 1.6.21'
43
+ s.add_dependency 'nexus_cli', '~> 4.1.0'
44
+ s.add_dependency 'thor', '~> 0.19.1'
45
+
46
+ s.add_development_dependency 'rake', '>= 10.0.0'
47
+ s.add_development_dependency 'rspec', '~> 2.12.0'
48
+ end
49
+
@@ -0,0 +1,22 @@
1
+ require 'nexus_cli'
2
+
3
+ module KPM
4
+ class BaseArtifact
5
+ class << self
6
+ KILLBILL_GROUP_ID = 'org.kill-bill.billing'
7
+ KILLBILL_JAVA_PLUGIN_GROUP_ID = 'org.kill-bill.billing.plugin.java'
8
+ KILLBILL_RUBY_PLUGIN_GROUP_ID = 'org.kill-bill.billing.plugin.ruby'
9
+
10
+ def nexus_remote(overrides={}, ssl_verify=true)
11
+ nexus_remote ||= NexusCli::RemoteFactory.create(nexus_defaults.merge(overrides || {}), ssl_verify)
12
+ end
13
+
14
+ def nexus_defaults
15
+ {
16
+ url: 'https://repository.sonatype.org',
17
+ repository: 'central-proxy'
18
+ }
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/kpm/cli.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'thor'
2
+
3
+ module KPM
4
+ class Cli < Thor
5
+ include KPM::Tasks
6
+ end
7
+ end
@@ -0,0 +1,83 @@
1
+ require 'logger'
2
+ require 'yaml'
3
+
4
+ module KPM
5
+ class Installer
6
+ LATEST_VERSION = 'LATEST'
7
+
8
+ def self.from_file(config_path, logger=nil)
9
+ Installer.new(YAML::load_file(config_path), logger)
10
+ end
11
+
12
+ def initialize(raw_config, logger=nil)
13
+ raise(ArgumentError, 'killbill section must be specified') if raw_config['killbill'].nil?
14
+ @config = raw_config['killbill']
15
+
16
+ if logger.nil?
17
+ @logger = Logger.new(STDOUT)
18
+ @logger.level = Logger::INFO
19
+ else
20
+ @logger = logger
21
+ end
22
+ end
23
+
24
+ def install
25
+ install_killbill_server
26
+ install_plugins
27
+ end
28
+
29
+ private
30
+
31
+ def install_killbill_server
32
+ version = @config['version'] || LATEST_VERSION
33
+ webapp_path = @config['webapp_path'] || KPM::root
34
+
35
+ webapp_dir = File.dirname(webapp_path)
36
+ FileUtils.mkdir_p(webapp_dir)
37
+
38
+ @logger.info "Installing Kill Bill server #{version} to #{webapp_path}"
39
+ file = KillbillServerArtifact.pull(version, webapp_dir, @config['nexus'], @config['nexus']['ssl_verify'])
40
+ FileUtils.mv file[:file_path], webapp_path
41
+ end
42
+
43
+ def install_plugins
44
+ bundles_dir = @config['plugins_dir']
45
+
46
+ install_java_plugins(bundles_dir)
47
+ install_ruby_plugins(bundles_dir)
48
+ end
49
+
50
+ def install_java_plugins(bundles_dir)
51
+ return if @config['plugins'].nil? or @config['plugins']['java'].nil?
52
+
53
+ @config['plugins']['java'].each do |plugin|
54
+ artifact_id = plugin['name']
55
+ version = plugin['version'] || LATEST_VERSION
56
+ destination = "#{bundles_dir}/plugins/java/#{artifact_id}/#{version}"
57
+
58
+ FileUtils.mkdir_p(destination)
59
+
60
+ @logger.info "Installing Kill Bill Java plugin #{artifact_id} #{version} to #{destination}"
61
+ KillbillPluginArtifact.pull(artifact_id, version, :java, destination, @config['nexus'], @config['nexus']['ssl_verify'])
62
+ end
63
+ end
64
+
65
+ def install_ruby_plugins(bundles_dir)
66
+ return if @config['plugins'].nil? or @config['plugins']['ruby'].nil?
67
+
68
+ @config['plugins']['ruby'].each do |plugin|
69
+ artifact_id = plugin['name']
70
+ version = plugin['version'] || LATEST_VERSION
71
+ destination = "#{bundles_dir}/plugins/ruby"
72
+
73
+ FileUtils.mkdir_p(destination)
74
+
75
+ @logger.info "Installing Kill Bill Ruby plugin #{artifact_id} #{version} to #{destination}"
76
+ archive = KillbillPluginArtifact.pull(artifact_id, version, :ruby, destination, @config['nexus'], @config['nexus']['ssl_verify'])
77
+
78
+ Utils.unpack_tgz(archive[:file_path], destination)
79
+ FileUtils.rm archive[:file_path]
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,37 @@
1
+ require 'rexml/document'
2
+ require 'set'
3
+
4
+ module KPM
5
+ class KillbillPluginArtifact < BaseArtifact
6
+ class << self
7
+ def pull(artifact_id, version='LATEST', type=:java, destination=nil, overrides={}, ssl_verify=true)
8
+ if type == :java
9
+ group_id = KILLBILL_JAVA_PLUGIN_GROUP_ID
10
+ packaging = 'jar'
11
+ else
12
+ group_id = KILLBILL_RUBY_PLUGIN_GROUP_ID
13
+ packaging = 'tar.gz'
14
+ end
15
+ coordinates = "#{group_id}:#{artifact_id}:#{packaging}:#{version}"
16
+ nexus_remote(overrides, ssl_verify).pull_artifact(coordinates, destination)
17
+ end
18
+
19
+ def versions(overrides={}, ssl_verify=true)
20
+ plugins = { :java => {}, :ruby => {} }
21
+
22
+ nexus = nexus_remote(overrides, ssl_verify)
23
+
24
+ [[:java, KILLBILL_JAVA_PLUGIN_GROUP_ID], [:ruby, KILLBILL_RUBY_PLUGIN_GROUP_ID]].each do |type_and_group_id|
25
+ response = REXML::Document.new nexus.search_for_artifacts(type_and_group_id[1])
26
+ response.elements.each('search-results/data/artifact') do |element|
27
+ artifact_id = element.elements['artifactId'].text
28
+ plugins[type_and_group_id[0]][artifact_id] ||= SortedSet.new
29
+ plugins[type_and_group_id[0]][artifact_id] << element.elements['version'].text
30
+ end
31
+ end
32
+
33
+ plugins
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ require 'rexml/document'
2
+ require 'set'
3
+
4
+ module KPM
5
+ class KillbillServerArtifact < BaseArtifact
6
+ class << self
7
+ KILLBILL_SERVER_ARTIFACT_ID = 'killbill-server'
8
+ KILLBILL_SERVER_WAR = "#{KILLBILL_GROUP_ID}:#{KILLBILL_SERVER_ARTIFACT_ID}:war:jar-with-dependencies"
9
+
10
+ def pull(version='LATEST', destination=nil, overrides={}, ssl_verify=true)
11
+ nexus_remote(overrides, ssl_verify).pull_artifact("#{KILLBILL_SERVER_WAR}:#{version}", destination)
12
+ end
13
+
14
+ def versions(overrides={}, ssl_verify=true)
15
+ response = REXML::Document.new nexus_remote(overrides, ssl_verify).search_for_artifacts(KILLBILL_SERVER_WAR)
16
+ versions = SortedSet.new
17
+ response.elements.each("search-results/data/artifact/version") { |element| versions << element.text }
18
+ versions
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/kpm/tasks.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'highline'
2
+ require 'thor'
3
+
4
+ module KPM
5
+ module Tasks
6
+ def self.included(base)
7
+ base.send :include, ::Thor::Actions
8
+ base.class_eval do
9
+
10
+ class_option :overrides,
11
+ :type => :hash,
12
+ :default => nil,
13
+ :desc => "A hashed list of overrides. Available options are 'url', 'repository', 'username', and 'password'."
14
+
15
+ class_option :ssl_verify,
16
+ :type => :boolean,
17
+ :default => true,
18
+ :desc => "Set to false to disable SSL Verification."
19
+
20
+ desc "install", "Install Kill Bill server and plugins according to the specified YAML configuration file."
21
+ def install(config_file)
22
+ Installer.from_file(config_file).install
23
+ end
24
+
25
+ method_option :destination,
26
+ :type => :string,
27
+ :default => nil,
28
+ :desc => "A different folder other than the current working directory."
29
+ desc "pull_kb_server_war version", "Pulls Kill Bill server war from Sonatype and places it on your machine."
30
+ def pull_kb_server_war(version='LATEST')
31
+ response = KillbillServerArtifact.pull(version, options[:destination], options[:overrides], options[:ssl_verify])
32
+ say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
33
+ end
34
+
35
+ desc "search_for_kb_server", "Searches for all versions of Kill Bill server and prints them to the screen."
36
+ def search_for_kb_server
37
+ say "Available versions: #{KillbillServerArtifact.versions(options[:overrides], options[:ssl_verify]).to_a.join(', ')}", :green
38
+ end
39
+
40
+ method_option :destination,
41
+ :type => :string,
42
+ :default => nil,
43
+ :desc => "A different folder other than the current working directory."
44
+ desc "pull_java_plugin artifact_id", "Pulls a java plugin from Sonatype and places it on your machine."
45
+ def pull_java_plugin(artifact_id, version='LATEST')
46
+ response = KillbillPluginArtifact.pull(artifact_id, version, :java, options[:destination], options[:overrides], options[:ssl_verify])
47
+ say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
48
+ end
49
+
50
+ method_option :destination,
51
+ :type => :string,
52
+ :default => nil,
53
+ :desc => "A different folder other than the current working directory."
54
+ desc "pull_ruby_plugin artifact_id", "Pulls a ruby plugin from Sonatype and places it on your machine."
55
+ def pull_ruby_plugin(artifact_id, version='LATEST')
56
+ response = KillbillPluginArtifact.pull(artifact_id, version, :ruby, options[:destination], options[:overrides], options[:ssl_verify])
57
+ say "Artifact has been retrieved and can be found at path: #{response[:file_path]}", :green
58
+ end
59
+
60
+ desc "search_for_plugins", "Searches for all available plugins and prints them to the screen."
61
+ def search_for_plugins
62
+ all_plugins = KillbillPluginArtifact.versions(options[:overrides], options[:ssl_verify])
63
+
64
+ result = ''
65
+ all_plugins.each do |type, plugins|
66
+ result << "Available #{type} plugins:\n"
67
+ Hash[plugins.sort].each do |name, versions|
68
+ result << " #{name}: #{versions.to_a.join(', ')}\n"
69
+ end
70
+ end
71
+
72
+ say result, :green
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
data/lib/kpm/utils.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'pathname'
2
+ require 'rubygems/package'
3
+ require 'zlib'
4
+
5
+ module KPM
6
+ class Utils
7
+ class << self
8
+ TAR_LONGLINK = '././@LongLink'
9
+
10
+ def unpack_tgz(tar_gz_archive, destination)
11
+ Gem::Package::TarReader.new(Zlib::GzipReader.open(tar_gz_archive)) do |tar|
12
+ dest = nil
13
+ tar.each do |entry|
14
+ if entry.full_name == TAR_LONGLINK
15
+ dest = File.join destination, path_with_skipped_top_level_dir(entry.read.strip)
16
+ next
17
+ end
18
+ dest ||= File.join destination, path_with_skipped_top_level_dir(entry.full_name)
19
+
20
+ if entry.directory?
21
+ File.delete dest if File.file? dest
22
+ FileUtils.mkdir_p dest, :mode => entry.header.mode, :verbose => false
23
+ elsif entry.file?
24
+ FileUtils.rm_rf dest if File.directory? dest
25
+ File.open dest, "wb" do |f|
26
+ f.print entry.read
27
+ end
28
+ FileUtils.chmod entry.header.mode, dest, :verbose => false
29
+ elsif entry.header.typeflag == '2' # Symlink
30
+ File.symlink entry.header.linkname, dest
31
+ end
32
+ dest = nil
33
+ end
34
+ end
35
+ end
36
+
37
+ def path_with_skipped_top_level_dir(path)
38
+ Pathname(path).each_filename.to_a[1..-1].join(File::SEPARATOR)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ module KPM
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+ PRE = nil
7
+
8
+ VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
9
+
10
+ class << self
11
+ def inspect
12
+ VERSION.dup
13
+ end
14
+
15
+ alias to_s inspect
16
+ end
17
+ end
18
+ end
data/lib/kpm.rb ADDED
@@ -0,0 +1,19 @@
1
+ module KPM
2
+ autoload :Utils, 'kpm/utils'
3
+ autoload :BaseArtifact, 'kpm/base_artifact'
4
+ autoload :KillbillServerArtifact, 'kpm/killbill_server_artifact'
5
+ autoload :KillbillPluginArtifact, 'kpm/killbill_plugin_artifact'
6
+ autoload :Installer, 'kpm/installer'
7
+ autoload :Tasks, 'kpm/tasks'
8
+ autoload :Cli, 'kpm/cli'
9
+
10
+ class << self
11
+ def root
12
+ @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
13
+ end
14
+
15
+ def ui
16
+ @ui ||= Thor::Shell::Color.new
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kpm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kill Bill core team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.21
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.21
27
+ - !ruby/object:Gem::Dependency
28
+ name: nexus_cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 10.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.12.0
83
+ description: A package manager for Kill Bill.
84
+ email: killbilling-users@googlegroups.com
85
+ executables:
86
+ - kpm
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - Rakefile
93
+ - bin/kpm
94
+ - install_example.yml
95
+ - kpm.gemspec
96
+ - lib/kpm.rb
97
+ - lib/kpm/base_artifact.rb
98
+ - lib/kpm/cli.rb
99
+ - lib/kpm/installer.rb
100
+ - lib/kpm/killbill_plugin_artifact.rb
101
+ - lib/kpm/killbill_server_artifact.rb
102
+ - lib/kpm/tasks.rb
103
+ - lib/kpm/utils.rb
104
+ - lib/kpm/version.rb
105
+ homepage: http://kill-bill.org
106
+ licenses:
107
+ - Apache License (2.0)
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options:
111
+ - "--exclude"
112
+ - "."
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 1.8.6
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Kill Bill package manager.
131
+ test_files: []