aemcrxpkgmgr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25e42cf987c2c0d2c02946a69e39c571f9b4f489
4
+ data.tar.gz: e85f1b2e45e9fc2862755bcc6a7f60dadee353a2
5
+ SHA512:
6
+ metadata.gz: e080da8e6823ebdf995bfe49798c90b9fb6cbcd819ef1c892aa1f51b63afb9bc797bd33ab6d491232414e053866848f46b1a94c827295840b4137363503a2064
7
+ data.tar.gz: aeab3ca6291b0f7174b7419235c7703c256ab9f0f0703184b8727163b472c62d481f2757108be3063f832f9dbfa65de9f66f516c1ed438dd6340438b33f7022e
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in aemcrxpkgmgr.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aemcrxpkgmgr (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ aemcrxpkgmgr!
30
+ bundler (~> 1.16)
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Aemcrxpkgmgr
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aemcrxpkgmgr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aemcrxpkgmgr'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aemcrxpkgmgr
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aemcrxpkgmgr.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aemcrxpkgmgr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'aemcrxpkgmgr'
8
+ spec.version = AemCrxPkgMgr::VERSION
9
+ spec.authors = ['Stefan - Zipkid - Goethals']
10
+ spec.email = ['stefan.goethals@vrt.be']
11
+
12
+ spec.summary = 'AEM CRX Package Manager script'
13
+ spec.description = 'AEM CRX Package Manager script'
14
+ spec.homepage = 'http://github.com/vrtdev'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
33
+ spec.add_development_dependency 'rake', '~> 10.0'
34
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aemcrxpkgmgr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/changelog.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ Version format based on http://semver.org/
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.0] - 2018-01-30
9
+ ## Added
10
+ - First working version
11
+
12
+ ## [0.0.0] - 2018-01-01
13
+ ### Added
14
+ - ...
15
+
16
+ ### Changed
17
+ - ...
18
+
19
+ ### Removed
20
+ - ...
data/exe/aemcrxpkgmgr ADDED
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'getoptlong'
4
+ require 'aemcrxpkgmgr'
5
+
6
+ def clidoc
7
+ puts <<-CLIDOC
8
+
9
+ #{$PROGRAM_NAME} [OPTION]
10
+
11
+ --help:
12
+ show help
13
+
14
+ -a --action:
15
+ Action to perform [query|delete_crx_zip]. Default 'query'
16
+
17
+ -h, --host:
18
+ host to connect to. Default 'http://localhost:4502'
19
+
20
+ -u --user:
21
+ username. Default 'admin'
22
+
23
+ -p --pass:
24
+ password
25
+
26
+ -q --query
27
+ query string
28
+
29
+ -v --versions:
30
+ include other versions of package
31
+
32
+ -k --keys:
33
+ Keys to extract from result. Default [name description version group path]
34
+ Pass as comma-delimited string
35
+
36
+ -o --output:
37
+ output format [single|yaml|json|pp|ruby]. Default 'yaml'
38
+ single: outputs a single result record, exit 1 if more records exist
39
+ yaml, json: ...
40
+ pp: Pretty Print
41
+ ruby: native Array/Hash output
42
+
43
+ -d --debug:
44
+ debug ....
45
+
46
+ CLIDOC
47
+ end
48
+
49
+ opts = GetoptLong.new(
50
+ ['--help', GetoptLong::NO_ARGUMENT],
51
+ ['--action', '-a', GetoptLong::REQUIRED_ARGUMENT],
52
+ ['--host', '-h', GetoptLong::REQUIRED_ARGUMENT],
53
+ ['--user', '-u', GetoptLong::REQUIRED_ARGUMENT],
54
+ ['--pass', '-p', GetoptLong::REQUIRED_ARGUMENT],
55
+ ['--query', '-q', GetoptLong::REQUIRED_ARGUMENT],
56
+ ['--versions', '-v', GetoptLong::NO_ARGUMENT],
57
+ ['--keys', '-k', GetoptLong::REQUIRED_ARGUMENT],
58
+ ['--output', '-o', GetoptLong::REQUIRED_ARGUMENT],
59
+ ['--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT]
60
+ )
61
+
62
+ action = 'query'
63
+ host = 'http://localhost:4502'
64
+ user = 'admin'
65
+ pass = ENV['AEM_PASSWORD']
66
+ query = ''
67
+ includeversions = false
68
+ keys_to_extract = %w[name description version group path]
69
+ output = 'yaml'
70
+ debug = 0
71
+
72
+ # rubocop:disable Metrics/BlockLength
73
+ opts.each do |opt, arg|
74
+ case opt
75
+ when '--help'
76
+ clidoc
77
+ exit
78
+ when '--action'
79
+ action = arg
80
+ when '--host'
81
+ host = arg
82
+ when '--user'
83
+ user = arg
84
+ when '--pass'
85
+ pass = arg
86
+ when '--query'
87
+ query = arg
88
+ when '--versions'
89
+ includeversions = true
90
+ when '--keys'
91
+ keys_to_extract = arg.split(/\s*,\s*/)
92
+ when '--output'
93
+ output = arg
94
+ when '--debug'
95
+ debug = if arg == ''
96
+ 1
97
+ else
98
+ arg.to_i
99
+ end
100
+ end
101
+ end
102
+ # rubocop:enable Metrics/BlockLength
103
+
104
+ aemcrxpkgmgr = AemCrxPkgMgr.new(
105
+ host: host,
106
+ user: user,
107
+ pass: pass,
108
+ includeversions: includeversions,
109
+ keys_to_extract: keys_to_extract,
110
+ output: output,
111
+ debug: debug
112
+ )
113
+
114
+ case action
115
+ when 'delete_crx_zip'
116
+ aemcrxpkgmgr.output = 'ruby'
117
+ aemcrxpkgmgr.keys_to_extract = ['path']
118
+ list = aemcrxpkgmgr.pkg_query query
119
+ result = aemcrxpkgmgr.delete_crx_zip list
120
+ else
121
+ result = aemcrxpkgmgr.pkg_query query
122
+ end
123
+
124
+ puts result
125
+
126
+ exit 0
127
+
128
+ # vim:set fileencoding=utf8 fileformat=unix filetype=ruby tabstop=2 expandtab:
@@ -0,0 +1,3 @@
1
+ class AemCrxPkgMgr
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,104 @@
1
+ require 'aemcrxpkgmgr/version'
2
+
3
+ require 'uri'
4
+ require 'yaml'
5
+ require 'json'
6
+ require 'net/http'
7
+ require 'pp'
8
+
9
+ # AEM CRX Package Manager
10
+ class AemCrxPkgMgr
11
+ attr_accessor :includeversions, :keys_to_extract, :output
12
+ def initialize(options = {})
13
+ @host = options[:host] || 'http://localhost:4502'
14
+ @user = options[:user] || 'admin'
15
+ @pass = options[:pass]
16
+ @includeversions = options[:includeversions] || false
17
+ @keys_to_extract = options[:keys_to_extract]
18
+ @output = options[:output] || 'ruby'
19
+ @debug = options[:debug]
20
+ end
21
+
22
+ def get(uri)
23
+ request = Net::HTTP::Get.new(uri)
24
+ request.basic_auth(@user, @pass)
25
+
26
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
27
+ http.request(request)
28
+ end
29
+ response
30
+ end
31
+
32
+ def pkg_query_uri(query)
33
+ uri = URI.parse(@host + '/crx/packmgr/list.jsp')
34
+ params = { q: query, includeVersions: @includeversions }
35
+ uri.query = URI.encode_www_form(params)
36
+ uri
37
+ end
38
+
39
+ def delete_crx_zip(list)
40
+ return unless list
41
+ @delete_crx_zip_ok = 0
42
+ @delete_crx_zip_status = []
43
+ list.each do |path|
44
+ delete_crx_zip_single path
45
+ end
46
+ @delete_crx_zip_ok == list.length
47
+ end
48
+
49
+ def delete_crx_request(uri)
50
+ req = Net::HTTP::Post.new(uri)
51
+ req.basic_auth(@user, @pass)
52
+ req.set_form_data('cmd' => 'delete')
53
+ req
54
+ end
55
+
56
+ def delete_crx_zip_single(path)
57
+ uri = URI(@host + '/crx/packmgr/service/script.html' + path)
58
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
59
+ http.request(delete_crx_request(uri))
60
+ end
61
+ @delete_crx_zip_status << response
62
+ @delete_crx_zip_ok += 1 if response.is_a? Net::HTTPSuccess
63
+ end
64
+
65
+ def pkg_query(query)
66
+ uri = pkg_query_uri(query)
67
+ response = get uri
68
+
69
+ raise "HTTP response code : #{response.code}, message : #{response.message}" unless response.is_a? Net::HTTPSuccess
70
+
71
+ @query_data = JSON.parse(response.body)['results']
72
+
73
+ extract_keys
74
+
75
+ format_output @query_data unless @query_data.empty?
76
+ end
77
+
78
+ def extract_keys
79
+ return if @keys_to_extract.length.zero?
80
+ @query_data.map! do |element|
81
+ if @keys_to_extract.length == 1
82
+ element[@keys_to_extract.first]
83
+ else
84
+ element.select { |key, _| @keys_to_extract.include? key }
85
+ end
86
+ end
87
+ end
88
+
89
+ def format_output(data)
90
+ case @output
91
+ when 'single' then output_single data
92
+ when 'yaml' then data.to_yaml
93
+ when 'json' then data.to_json
94
+ when 'pp' then pp(data, '')
95
+ else
96
+ data
97
+ end
98
+ end
99
+
100
+ def output_single(data)
101
+ raise 'Resultset contains more than 1 element and "single" was requested.' if data.length != 1
102
+ data.first
103
+ end
104
+ end
data/license.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright 2017 VRT.be
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aemcrxpkgmgr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stefan - Zipkid - Goethals
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: AEM CRX Package Manager script
56
+ email:
57
+ - stefan.goethals@vrt.be
58
+ executables:
59
+ - aemcrxpkgmgr
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Gemfile.lock
68
+ - README.md
69
+ - Rakefile
70
+ - aemcrxpkgmgr.gemspec
71
+ - bin/console
72
+ - bin/setup
73
+ - changelog.md
74
+ - exe/aemcrxpkgmgr
75
+ - lib/aemcrxpkgmgr.rb
76
+ - lib/aemcrxpkgmgr/version.rb
77
+ - license.txt
78
+ homepage: http://github.com/vrtdev
79
+ licenses: []
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.13
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: AEM CRX Package Manager script
102
+ test_files: []