skylark 0.0.0.alpha.0 → 0.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33874db7557822ca39a146b1a251dfa1a2b527e5
4
- data.tar.gz: 86b379aa33c8ca7cbaa17d4a356d24984fc963f4
3
+ metadata.gz: 2007b306b6bc887c49ad3b05960be25c59673bbd
4
+ data.tar.gz: d15341bea8daadd4f5e8e082217422aaf02ff4b1
5
5
  SHA512:
6
- metadata.gz: d76f6233da88eae6eff6ec531cfa402b9e70256079d670d46bc84c7108c528027bb50553eb8b915511177d719128d39069f15ff757c28ff8e8f0041e79a51cb9
7
- data.tar.gz: ddacd4c0e756634277d1e8eeffd995b1e6d5f36fca573e12e94fc0ed40f57674d537c2bad03e601f53a0a58bb011ffa158915bb50cd78c210387d83070a0c53e
6
+ metadata.gz: 50fec2e688e70b4a9674c2e0d0a9c7a9fc48cb9e20523ea102d947baaec9d4d2c15f61e444b3a14064c5e61a9917356bdd8fda5c12b41399cea8b36fe4d20c1d
7
+ data.tar.gz: aabf2f7b2569d47239de8596867aed9e4556b44018a245866a32f4f83a992bf9c3cc57d0c4f86fd0de1e36d40081be605c96005c92579d3303882bc2a8b09e4c
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Ignore built gems
2
+ *.gem
3
+
4
+ # Ignore the bundle cache.
5
+ Gemfile.lock
6
+
7
+ # Ignore coverage data
8
+ /coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,51 @@
1
+ # Contributing
2
+
3
+ So you want to contribute to Skylark development! Thanks in advance
4
+ for anything that you can provide for the project. We (well, just me
5
+ at the moment) welcome feedback, bug reports, and---perhaps most
6
+ importantly---pull requests.
7
+
8
+ ## Hacking
9
+
10
+ To contribute, you should have a relatively new version of Ruby. (The
11
+ gemspec greedily requires Ruby 2.3 or higher because I haven't had the
12
+ opportunity to test on anything lower.)
13
+
14
+ Make sure you have installed `bundler`,
15
+
16
+ ```console
17
+ $ gem install bundler
18
+ ```
19
+
20
+ and make sure you have all of the project dependencies installed,
21
+
22
+ ```console
23
+ $ bundle install
24
+ ```
25
+
26
+ Use a branching scheme like this:
27
+
28
+ * `<description-of-feature>` for feature additions
29
+
30
+ * `fix-<#>-<description-of-change>` for bug/performance fixes
31
+
32
+ **Fork** to your own personal or organization account (unless you
33
+ already are an authorized contributor on this project) and **make a
34
+ branch** for your work. Make multiple branches if your work is
35
+ divergent or has multiple different channels. Feel free to merge
36
+ between these branches in a way that makes sense. When ready,
37
+ **submit a pull request** with the base set to `master` on
38
+ `rye/skylark`. We will dispatch it to a different base if necessary.
39
+
40
+
41
+ ## Filing Issues/Pull Requests
42
+
43
+ In general,
44
+
45
+ * Please use English, and please be as communicative as possible.
46
+
47
+ * Please make sure you have notifications turned on for GitHub on the
48
+ specific Issue or PR you submit---we might try to follow-up quickly.
49
+ In general, we'll accept anything that matches the coding style and
50
+ produces a valuable on-target movement towards the project's
51
+ purpose.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2017 Kristofer Rye
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # skylark [![Gem Version](https://badge.fury.io/rb/skylark.svg)](https://badge.fury.io/rb/skylark) [![Build Status](https://travis-ci.org/rye/skylark.svg?branch=master)](https://travis-ci.org/rye/skylark) [![Code Climate](https://codeclimate.com/github/rye/skylark/badges/gpa.svg)](https://codeclimate.com/github/rye/skylark) [![Test Coverage](https://codeclimate.com/github/rye/skylark/badges/coverage.svg)](https://codeclimate.com/github/rye/skylark/coverage)
2
+
3
+ Skylark is a simple CLI-based LDAP scraper whose intended purpose is to
4
+ dump an entire LDAP search base out into a bunch of JSON files based
5
+ on the LDIF data dumped by the LDAP server. More precisely, every
6
+ object in the database gets its own JSON file.
7
+
8
+ ## Installation/Setup
9
+
10
+ Just clone the repository, cd into it, and run the following commands:
11
+
12
+ ```console
13
+ $ bundle install
14
+ $ bundle exec script/scrape config/<your configuration file>.yml
15
+ ```
data/bin/skylark ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ LIB_DIRECTORY = File.join(File.dirname(__FILE__), '..', 'lib')
4
+ $LOAD_PATH.unshift(File.expand_path(LIB_DIRECTORY)) unless $LOAD_PATH.map do |directory|
5
+ File.expand_path(directory)
6
+ end.include?(LIB_DIRECTORY)
7
+
8
+ require 'skylark'
9
+
10
+ Skylark::CLI.run ARGV
data/lib/skylark.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'skylark/argument_configuration'
2
+ require 'skylark/cli'
3
+ require 'skylark/ldap'
4
+ require 'skylark/version'
5
+ require 'skylark/yaml_configuration'
6
+
7
+ module Skylark
8
+
9
+ ROOT_DIRECTORY = File.expand_path('..', File.dirname(__FILE__))
10
+
11
+ end
@@ -0,0 +1,72 @@
1
+ require 'optparse'
2
+
3
+ require 'skylark/configuration'
4
+
5
+ module Skylark
6
+
7
+ class ArgumentConfiguration < Configuration
8
+ def self.parse(argv)
9
+ configuration = self.new
10
+
11
+ args = OptionParser.new do |parser|
12
+ configuration.define_options(parser)
13
+
14
+ parser.parse!(argv)
15
+
16
+ if argv.empty?
17
+ puts parser
18
+ $stderr.puts "Expected at least one filename; exiting."
19
+ exit
20
+ end
21
+
22
+ configuration[:spec_files] = argv.select do |argument|
23
+ argument_as_filename = File.expand_path(argument, Dir.pwd)
24
+ File.readable?(argument_as_filename)
25
+ end
26
+ end
27
+
28
+ configuration
29
+ end
30
+
31
+ def initialize
32
+ super
33
+
34
+ self[:spec_files] = []
35
+ self[:logger_level] = :warn
36
+ end
37
+
38
+ def define_options(parser)
39
+ parser.banner = <<-EOT
40
+ Usage: #{$0} [options] [--] <filename> [<filename>...]
41
+ EOT
42
+ parser.separator ""
43
+ parser.separator "OPTIONS:"
44
+
45
+ add_verbosity_option(parser)
46
+
47
+ parser.separator ""
48
+ parser.separator "GENERAL OPTIONS:"
49
+
50
+ parser.on_tail('-h', '--help', 'Show this usage message.') do
51
+ puts parser
52
+ exit
53
+ end
54
+
55
+ parser.on_tail('--version', 'Print the version.') do
56
+ puts Skytrain::VERSION
57
+ exit
58
+ end
59
+ end
60
+
61
+ def add_verbosity_option(parser)
62
+ parser.on('-d', '--debug-level LEVEL', 'Sets the debugging level to LEVEL.') do |level|
63
+ self[:logger_level] = level.downcase.to_sym
64
+ end
65
+
66
+ parser.on('-v', '--verbose', 'Sets the debugging level to a sensible verbose default.') do
67
+ self[:logger_level] = :debug
68
+ end
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,73 @@
1
+ require 'fileutils'
2
+ require 'base64'
3
+ require 'json'
4
+
5
+ require 'skylark/ldap'
6
+ require 'skylark/argument_configuration'
7
+ require 'skylark/yaml_configuration'
8
+ require 'skylark/version'
9
+
10
+ module Skylark
11
+
12
+ module CLI
13
+
14
+ def self.run(args = ARGV)
15
+ argument_configuration = ArgumentConfiguration.parse(args)
16
+
17
+ specs = argument_configuration[:spec_files].map do |spec_file|
18
+ spec_configuration = YAMLConfiguration.new(spec_file)
19
+ spec_configuration.read!
20
+ spec_configuration
21
+
22
+ if spec_configuration['searches'].is_a? Array
23
+ spec_configuration['searches'].each do |search|
24
+ dump_root_directory = File.join(ROOT_DIRECTORY, 'data', spec_configuration['server']['host'])
25
+
26
+ auth = {method: :simple, username: spec_configuration['server']['auth']['username'], password: spec_configuration['server']['auth']['password']}
27
+ encryption = {method: :simple_tls, tls_options: {verify_mode: OpenSSL::SSL::VERIFY_NONE}}
28
+
29
+ adapter = Skylark::LDAP::Adapter.new(host: spec_configuration['server']['host'], port: spec_configuration['server']['port'].to_i, auth: auth, encryption: encryption)
30
+
31
+ adapter.search(base: search['base']) do |entry|
32
+ hash = {}
33
+
34
+ entry.each do |entry_key|
35
+ if (attributes = entry[entry_key]).is_a?(Array)
36
+ attributes.map! do |attribute|
37
+ if attribute.encoding == Encoding::ASCII_8BIT
38
+ Base64.strict_encode64(attribute)
39
+ else
40
+ attribute
41
+ end
42
+ end
43
+
44
+ attributes = attributes.first if attributes.count <= 1
45
+
46
+ hash[entry_key] = attributes
47
+ end
48
+ end
49
+
50
+ names = Skylark::LDAP::DN.new(hash[:dn]).names
51
+ domain_name_components = names.reverse.select do |name|
52
+ in_domain_name ||= true && (in_domain_name = name.keys[0].match?(/dc/i))
53
+ end.reverse.to_a
54
+
55
+ search_subnames = (names - domain_name_components).reverse
56
+ dump_directory = File.join(dump_root_directory, *search_subnames.select{|name| name.keys.first != 'CN'}.map{|name| name.values.first})
57
+
58
+ FileUtils.mkdir_p(dump_directory)
59
+
60
+ filename = File.join(dump_directory, "#{entry[:cn].first || ('_OU=' + entry[:ou].first if !entry[:ou].empty?) || ('_' + entry[:dn].first if !entry[:dn].empty?)}.json")
61
+
62
+ open(filename, 'wb') do |io|
63
+ io.write JSON.pretty_generate(hash) + '\n'
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,5 @@
1
+ module Skylark
2
+
3
+ Configuration = Class.new(Hash)
4
+
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'skylark/ldap/adapter'
2
+ require 'skylark/ldap/dn'
@@ -0,0 +1,7 @@
1
+ require 'net/ldap'
2
+
3
+ module Skylark::LDAP
4
+
5
+ Adapter = Class.new(Net::LDAP)
6
+
7
+ end
@@ -0,0 +1,21 @@
1
+ module Skylark::LDAP
2
+
3
+ class DN
4
+ attr_reader :names
5
+
6
+ def initialize(dn_string)
7
+ parse!(dn_string)
8
+ end
9
+
10
+ def parse!(dn_string)
11
+ @names = parse(dn_string)
12
+ end
13
+
14
+ def parse(dn_string)
15
+ dn_string.scan(/(?<type>OU|CN|DC)=(?<data>[A-z][\w\ -]*),?/i).map do |match|
16
+ {match.first => match.last}
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,26 @@
1
+ module Skylark
2
+
3
+ class Version
4
+
5
+ attr_reader :major
6
+ attr_reader :minor
7
+ attr_reader :patch
8
+ attr_reader :prerelease
9
+
10
+ def initialize(major, minor = 0, patch = 0, prerelease = nil)
11
+ @major, @minor, @patch, @prerelease = major, minor, patch, prerelease
12
+ end
13
+
14
+ def to_s(mode = :standard)
15
+ case mode
16
+ when :standard
17
+ "v#{@major}.#{@minor}.#{@patch}#{('-' + @prerelease) if !!@prerelease}"
18
+ when :gemspec
19
+ "#{@major}.#{@minor}.#{@patch}#{('.' + @prerelease) if !!@prerelease}"
20
+ end
21
+ end
22
+ end
23
+
24
+ VERSION = Version.new(0, 0, 0, 'alpha.1')
25
+
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'yaml'
2
+
3
+ require 'skylark/configuration'
4
+
5
+ module Skylark
6
+
7
+ class YAMLConfiguration < Configuration
8
+
9
+ attr_reader :filename
10
+
11
+ def initialize(filename)
12
+ super
13
+
14
+ @filename = filename
15
+ end
16
+
17
+ def read!
18
+ self.merge!(parse_yaml(read_file(@filename)))
19
+ end
20
+
21
+ protected
22
+
23
+ def read_file(filename)
24
+ open(filename, 'rb') do |io|
25
+ io.read
26
+ end
27
+ end
28
+
29
+ def parse_yaml(data)
30
+ YAML.load(data)
31
+ end
32
+
33
+ end
34
+
35
+ end
data/skylark.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ LIB_DIRECTORY = File.join(File.dirname(__FILE__), 'lib')
2
+ $LOAD_PATH.unshift(File.expand_path(LIB_DIRECTORY)) unless $LOAD_PATH.map do |directory|
3
+ File.expand_path(directory)
4
+ end.include?(LIB_DIRECTORY)
5
+
6
+ require 'skylark/version'
7
+
8
+ Gem::Specification.new do |s|
9
+
10
+ s.name = %q[skylark]
11
+ s.version = Skylark::VERSION.to_s :gemspec
12
+
13
+ $stderr.puts "Building #{s.name} #{s.version}..."
14
+
15
+ s.authors = ['Kristofer Rye']
16
+ s.email = 'kristofer.rye+skylark@gmail.com'
17
+ s.homepage = 'https://github.com/rye/skylark' # TODO gh-pages
18
+
19
+ s.summary = 'A CLI-based LDAP scraper whose intended purpose is to dump an entire LDAP search into a bunch of JSON files.'
20
+
21
+ s.files = []
22
+ s.files << '.gitignore'
23
+ s.files << '.rspec'
24
+ s.files << 'bin/skylark'
25
+ s.files << Dir.glob('lib/**/*.rb')
26
+ s.files << Dir.glob('spec/**/*.rb')
27
+ s.files << 'skylark.gemspec'
28
+ s.files << 'CONTRIBUTING.md'
29
+ s.files << 'LICENSE.md'
30
+ s.files << 'README.md'
31
+
32
+ s.licenses = ['MIT']
33
+
34
+ s.platform = Gem::Platform::RUBY
35
+ s.required_ruby_version = ['>= 2.3.3', '<= 2.5']
36
+
37
+ s.add_dependency 'net-ldap', '~> 0.16'
38
+
39
+ s.add_development_dependency 'rake', '~> 12'
40
+ s.add_development_dependency 'rspec', '~> 3.6'
41
+
42
+ s.add_development_dependency 'codeclimate', '~> 0.65'
43
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
44
+
45
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'lib/skylark.rb' do
4
+
5
+ it 'can be required without error' do
6
+ expect do
7
+ require 'skylark'
8
+ end.not_to raise_error
9
+ end
10
+
11
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
metadata CHANGED
@@ -1,21 +1,109 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.alpha.0
4
+ version: 0.0.0.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristofer Rye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-05 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ldap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.16'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.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: '12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12'
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.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.65'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.65'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
13
83
  description:
14
84
  email: kristofer.rye+skylark@gmail.com
15
85
  executables: []
16
86
  extensions: []
17
87
  extra_rdoc_files: []
18
- files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - CONTRIBUTING.md
92
+ - LICENSE.md
93
+ - README.md
94
+ - bin/skylark
95
+ - lib/skylark.rb
96
+ - lib/skylark/argument_configuration.rb
97
+ - lib/skylark/cli.rb
98
+ - lib/skylark/configuration.rb
99
+ - lib/skylark/ldap.rb
100
+ - lib/skylark/ldap/adapter.rb
101
+ - lib/skylark/ldap/dn.rb
102
+ - lib/skylark/version.rb
103
+ - lib/skylark/yaml_configuration.rb
104
+ - skylark.gemspec
105
+ - spec/lib/skylark_spec.rb
106
+ - spec/spec_helper.rb
19
107
  homepage: https://github.com/rye/skylark
20
108
  licenses:
21
109
  - MIT
@@ -28,7 +116,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
28
116
  requirements:
29
117
  - - ">="
30
118
  - !ruby/object:Gem::Version
31
- version: '0'
119
+ version: 2.3.3
120
+ - - "<="
121
+ - !ruby/object:Gem::Version
122
+ version: '2.5'
32
123
  required_rubygems_version: !ruby/object:Gem::Requirement
33
124
  requirements:
34
125
  - - ">"
@@ -36,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
127
  version: 1.3.1
37
128
  requirements: []
38
129
  rubyforge_project:
39
- rubygems_version: 2.6.11
130
+ rubygems_version: 2.4.5
40
131
  signing_key:
41
132
  specification_version: 4
42
133
  summary: A CLI-based LDAP scraper whose intended purpose is to dump an entire LDAP