ldap_cli 0.2.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
+ SHA256:
3
+ metadata.gz: b22ffdc1aec4e62904e47fff2be7625c99b02ac99938d588027e34738a59ead8
4
+ data.tar.gz: 89aaa80e800aca63a9be2197dc87375296abfdee1d47171585d5c2fb91d85daf
5
+ SHA512:
6
+ metadata.gz: a4d82df7d1cee5ce642bd977a72fa4b13104c6942f46aa0fdd906dbc59d7ef58798d1d1efdc5afa6f38a9cfd9cd4a759e5fa1998583657131b274f41fb9cba45
7
+ data.tar.gz: a88af1c7136bca48ba23e59995f5449d55b54768cf3a09ba6367fb09fa3e9681b4d91eabc51f82ff830dbba654ce0317d87a2f9a5cb20d69634d34b9751295f5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at reddynagagangadhar@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in ldap-cli.gemspec
8
+ gemspec
9
+
10
+ gem 'net-ldap'
11
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ldap_cli (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.2)
13
+ net-ldap (0.16.1)
14
+ parallel (1.17.0)
15
+ parser (2.6.3.0)
16
+ ast (~> 2.4.0)
17
+ powerpack (0.1.2)
18
+ pry (0.12.2)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.9.0)
21
+ rainbow (2.2.2)
22
+ rake
23
+ rake (10.5.0)
24
+ rspec (3.8.0)
25
+ rspec-core (~> 3.8.0)
26
+ rspec-expectations (~> 3.8.0)
27
+ rspec-mocks (~> 3.8.0)
28
+ rspec-core (3.8.2)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-expectations (3.8.4)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-mocks (3.8.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.8.0)
36
+ rspec-support (3.8.2)
37
+ rubocop (0.49.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.3.3.1, < 3.0)
40
+ powerpack (~> 0.1)
41
+ rainbow (>= 1.99.1, < 3.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (~> 1.0, >= 1.0.1)
44
+ ruby-progressbar (1.10.1)
45
+ unicode-display_width (1.6.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.17)
52
+ ldap_cli!
53
+ net-ldap
54
+ pry
55
+ rake (~> 10.0)
56
+ rspec (~> 3.0)
57
+ rubocop (~> 0.49.0)
58
+
59
+ BUNDLED WITH
60
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Naga Gangadhar
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'ldap-cli'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install ldap-cli
16
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'ldap/cli'
7
+ require 'pry'
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require 'irb'
17
+ 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/ldap-cli.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ldap/cli/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ldap_cli'
9
+ spec.version = Ldap::Cli::VERSION
10
+ spec.authors = ['Naga Gangadhar']
11
+ spec.email = ['reddynagagangadhar@gmail.com']
12
+
13
+ spec.summary = 'Ldap::Cli for Ruby is reading/writing entries in a
14
+ LDAP directory to/from CSV files'
15
+ spec.description = 'Ldap::Cli for Ruby is command-line interface tool
16
+ for reading/writing entries in an LDAP directory to/from CSV files.'
17
+ spec.homepage = 'https://github.com/rngangadhar/ldap-cli'
18
+ spec.license = 'MIT'
19
+
20
+ # Prevent pushing this gem to RubyGems.org.
21
+ # To allow pushes either set the "allowed_push_host" to allow pushing
22
+ # to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
25
+ else
26
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ 'public gem pushes.'
28
+ end
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
31
+ f.match(%r{^(test|spec|features)/})
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.17'
38
+ spec.add_development_dependency 'net-ldap', '~> 0.16.1'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rubocop', '~> 0.49.0'
42
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ldap
4
+ class Cli
5
+ VERSION = '0.2.0'.freeze
6
+ end
7
+ end
data/lib/ldap/cli.rb ADDED
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ldap/cli/version'
4
+ require 'rubygems'
5
+ require 'net/ldap'
6
+ require 'csv'
7
+ require 'pry'
8
+
9
+ module Ldap
10
+ class Error < StandardError; end
11
+ # Tool for reading/writing entries in an LDAP directory to/from CSV files
12
+ class Cli
13
+ attr_accessor :ldap, :headers, :table_dn, :errors
14
+
15
+ def initialize(config, headers, table_dn)
16
+ @ldap = Net::LDAP.new config
17
+ @headers = headers
18
+ @table_dn = table_dn
19
+ end
20
+
21
+ def bind
22
+ ldap.bind
23
+ end
24
+
25
+ def delete(args)
26
+ ldap.delete(args)
27
+ end
28
+
29
+ def valid_headers(input_headers = [])
30
+ no_header = 'Require headers to process the file.'
31
+ raise no_header unless (input_headers - headers).empty?
32
+ end
33
+
34
+ def import(input_file_path = nil)
35
+ @errors = []
36
+ CSV.foreach(input_file_path, headers: true, skip_blanks: true) do |row|
37
+ valid_headers row.headers
38
+ save_record(row)
39
+ end
40
+ end
41
+
42
+ def export(args = {})
43
+ @output_file_path = args[:output_file_path]
44
+ @filter = args[:filter]
45
+ add_header
46
+ export_data
47
+ end
48
+
49
+ private
50
+
51
+ def save_record(row)
52
+ dn = dn_value(row)
53
+ attr = row.to_h
54
+ attr['objectclass'] = ['inetOrgPerson']
55
+ if search(row['uid']).empty?
56
+ ldap.add(dn: dn, attributes: attr)
57
+ else
58
+ ldap.modify dn: dn, attributes: attr
59
+ end
60
+ save_record_log(ldap, row)
61
+ end
62
+
63
+ def dn_value(row)
64
+ "uid=#{row['uid']}, #{table_dn}"
65
+ end
66
+
67
+ def search(uid)
68
+ ldap.search(
69
+ base: table_dn,
70
+ filter: "uid=#{uid}",
71
+ scope: 1
72
+ )
73
+ end
74
+
75
+ def add_header
76
+ CSV.open(@output_file_path, 'w+', force_quotes: false) do |csv|
77
+ csv << headers
78
+ end
79
+ end
80
+
81
+ def export_data
82
+ CSV.open(@output_file_path, 'a+', force_quotes: false) do |csv|
83
+ ldap.search(base: table_dn, filter: @filter, scope: 1) do |entry|
84
+ csv << headers.map { |x| entry.send(x).first }
85
+ end
86
+ end
87
+ end
88
+
89
+ def save_record_log(ldap, row)
90
+ status = ldap.get_operation_result['message']
91
+ error_message = ldap.get_operation_result.error_message
92
+ if status == 'Success'
93
+ puts "Entry created successfully for uid #{row['uid']}"
94
+ elsif error_message.include?('did not contain any modifications')
95
+ puts error_message
96
+ else
97
+ @errors << error_message
98
+ puts error_message
99
+ end
100
+ end
101
+ end
102
+ end
data/lib/ldap_cli.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ldap/cli'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ldap_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Naga Gangadhar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-07-16 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-ldap
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.16.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.16.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.49.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.49.0
83
+ description: |-
84
+ Ldap::Cli for Ruby is command-line interface tool
85
+ for reading/writing entries in an LDAP directory to/from CSV files.
86
+ email:
87
+ - reddynagagangadhar@gmail.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - ldap-cli.gemspec
101
+ - lib/ldap/cli.rb
102
+ - lib/ldap/cli/version.rb
103
+ - lib/ldap_cli.rb
104
+ homepage: https://github.com/rngangadhar/ldap-cli
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.0.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Ldap::Cli for Ruby is reading/writing entries in a LDAP directory to/from
128
+ CSV files
129
+ test_files: []