synchronize-users 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: 6d2897ac45438f6e6570a135aeb8378c1e7b9c33
4
+ data.tar.gz: 2a174bea51266178ce799d6c1682ef850a05bd46
5
+ SHA512:
6
+ metadata.gz: cd75b9c9df0e2a106d9643007655d8e4696b26e6b2008bfaebd916220145948c9b17297ce0615ed5207c292c24dd88a3ea52bbfe55e304d9ae1aaedde71a9491
7
+ data.tar.gz: cf1c6c6a7afeec8037b62631c228940460063638894d2de7d1128b12a202cb76eb1a8a65607598408a880dfe6ad22303b01231f449fd7eb5a2a795d7bbcc1ae7
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ synchronize-users (0.0.1)
5
+ mooset (= 0.0.5)
6
+ pry
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aruba (0.6.2)
12
+ childprocess (>= 0.3.6)
13
+ cucumber (>= 1.1.1)
14
+ rspec-expectations (>= 2.7.0)
15
+ axiom-types (0.1.1)
16
+ descendants_tracker (~> 0.0.4)
17
+ ice_nine (~> 0.11.0)
18
+ thread_safe (~> 0.3, >= 0.3.1)
19
+ builder (3.2.2)
20
+ childprocess (0.5.6)
21
+ ffi (~> 1.0, >= 1.0.11)
22
+ coderay (1.1.0)
23
+ coercible (1.0.0)
24
+ descendants_tracker (~> 0.0.1)
25
+ cucumber (2.0.0)
26
+ builder (>= 2.1.2)
27
+ cucumber-core (~> 1.1.3)
28
+ diff-lcs (>= 1.1.3)
29
+ gherkin (~> 2.12)
30
+ multi_json (>= 1.7.5, < 2.0)
31
+ multi_test (>= 0.1.2)
32
+ cucumber-core (1.1.3)
33
+ gherkin (~> 2.12.0)
34
+ descendants_tracker (0.0.4)
35
+ thread_safe (~> 0.3, >= 0.3.1)
36
+ diff-lcs (1.2.5)
37
+ equalizer (0.0.11)
38
+ ffi (1.9.9)
39
+ gherkin (2.12.2)
40
+ multi_json (~> 1.3)
41
+ gitlab (3.3.0)
42
+ httparty
43
+ terminal-table
44
+ httparty (0.13.5)
45
+ json (~> 1.8)
46
+ multi_xml (>= 0.5.2)
47
+ ice_nine (0.11.1)
48
+ json (1.8.3)
49
+ lspace (0.13)
50
+ method_source (0.8.2)
51
+ mooset (0.0.5)
52
+ gitlab (~> 3.3.0)
53
+ lspace (~> 0.13)
54
+ net-ldap (~> 0.10)
55
+ virtus (~> 1.0.3)
56
+ multi_json (1.11.1)
57
+ multi_test (0.1.2)
58
+ multi_xml (0.5.5)
59
+ net-ldap (0.11)
60
+ pry (0.10.1)
61
+ coderay (~> 1.1.0)
62
+ method_source (~> 0.8.1)
63
+ slop (~> 3.4)
64
+ rake (10.4.2)
65
+ rdoc (4.2.0)
66
+ json (~> 1.4)
67
+ rspec-expectations (3.3.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.3.0)
70
+ rspec-support (3.3.0)
71
+ slop (3.6.0)
72
+ terminal-table (1.5.2)
73
+ thread_safe (0.3.5)
74
+ virtus (1.0.5)
75
+ axiom-types (~> 0.1)
76
+ coercible (~> 1.0)
77
+ descendants_tracker (~> 0.0, >= 0.0.3)
78
+ equalizer (~> 0.0, >= 0.0.9)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ aruba
85
+ rake
86
+ rdoc
87
+ synchronize-users!
data/README.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = synchronize-users
2
+
3
+ Describe your project here
4
+
5
+ :include:synchronize-users.rdoc
6
+
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/clean'
4
+ require 'rubygems'
5
+ require 'rubygems/package_task'
6
+ require 'rdoc/task'
7
+ require 'cucumber'
8
+ require 'cucumber/rake/task'
9
+ Rake::RDocTask.new do |rd|
10
+ rd.main = "README.rdoc"
11
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
12
+ rd.title = 'Your application title'
13
+ end
14
+
15
+ spec = eval(File.read('synchronize-users.gemspec'))
16
+
17
+ Gem::PackageTask.new(spec) do |pkg|
18
+ end
19
+ CUKE_RESULTS = 'results.html'
20
+ CLEAN << CUKE_RESULTS
21
+ desc 'Run features'
22
+ Cucumber::Rake::Task.new(:features) do |t|
23
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
24
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
25
+ t.cucumber_opts = opts
26
+ t.fork = false
27
+ end
28
+
29
+ desc 'Run features tagged as work-in-progress (@wip)'
30
+ Cucumber::Rake::Task.new('features:wip') do |t|
31
+ tag_opts = ' --tags ~@pending'
32
+ tag_opts = ' --tags @wip'
33
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
34
+ t.fork = false
35
+ end
36
+
37
+ task :cucumber => :features
38
+ task 'cucumber:wip' => 'features:wip'
39
+ task :wip => 'features:wip'
40
+ require 'rake/testtask'
41
+ Rake::TestTask.new do |t|
42
+ t.libs << "test"
43
+ t.test_files = FileList['test/*_test.rb']
44
+ end
45
+
46
+ task :default => [:test,:features]
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ #require 'gli'
3
+ begin # XXX: Remove this begin/rescue before distributing your app
4
+ require 'synchronize-users'
5
+ rescue LoadError
6
+ STDERR.puts "In development, you need to use `bundle exec bin/synchronize-users` to run your app"
7
+ STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
+ STDERR.puts "Feel free to remove this message from bin/synchronize-users now"
9
+ exit 64
10
+ end
11
+
12
+ SynchronizeUsers::App.run(ARGV)
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,8 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "synchronize-users"
8
+ Then the exit status should be 0
@@ -0,0 +1,37 @@
1
+ require 'synchronize-users/version.rb'
2
+
3
+ require 'mooset'
4
+ require 'synchronize-users/app.rb'
5
+ require 'synchronize-users/sync.rb'
6
+ require 'synchronize-users/target_group.rb'
7
+ require 'synchronize-users/from_group.rb'
8
+
9
+ module SynchronizeUsers
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.load_config(config)
15
+ instance_eval File.read(config), config
16
+
17
+ configuration
18
+ end
19
+
20
+ def self.configure
21
+ self.configuration ||= Configuration.new
22
+ yield(configuration)
23
+ end
24
+
25
+ class Configuration
26
+ attr_reader :gitlab, :ldap
27
+ attr_accessor :from, :to
28
+
29
+ def gitlab=(opts)
30
+ @gitlab = Mooset::Endpoints::Endpoint.create(:gitlab, opts)
31
+ end
32
+
33
+ def ldap=(opts)
34
+ @ldap = Mooset::Endpoints::Endpoint.create(:ldap, opts)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ module SynchronizeUsers
2
+ class App
3
+ attr_accessor :config_filename, :config, :logfile
4
+
5
+ def run!
6
+ app = SynchronizeUsers::Sync.new(@config)
7
+ app.run!
8
+ end
9
+
10
+ def read_config
11
+ @config = SynchronizeUsers.load_config(config_filename)
12
+ end
13
+
14
+ def self.run(argv)
15
+ s = self.new
16
+
17
+ OptionParser.new do |opts|
18
+ opts.banner = "Usage: #{$0} [options]"
19
+ opts.on("-f", "--logfile FILE", "Logfile", s.method(:logfile=))
20
+ opts.on("-v", "--verbose", "Verbose") do |x|
21
+ s.logger.level = ::Logger::DEBUG
22
+ end
23
+
24
+ opts.on("-c", "--config FILE", "Config file", s.method(:config_filename=))
25
+ opts.parse!(argv)
26
+ end
27
+
28
+ LSpace[:logger] = s.logger
29
+
30
+ if s.config_filename
31
+ s.read_config
32
+ s.run!
33
+ end
34
+ end
35
+
36
+ def logger
37
+ @logger ||= ::Logger.new(logfile || STDOUT).tap do |l|
38
+ l.level = ::Logger::INFO
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,18 @@
1
+ module SynchronizeUsers
2
+ class FromGroup
3
+ def initialize(connection, query, target_group)
4
+ @connection = connection
5
+ @query = query
6
+ @target_group = target_group
7
+ end
8
+
9
+ def each_new_user
10
+ @connection.find(@query).each do |group|
11
+ group.members.each do |member|
12
+ yield member unless @target_group.has_user?(member)
13
+ end
14
+ end
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module SynchronizeUsers
2
+ class Sync
3
+ lspace_reader :logger
4
+
5
+ def initialize(config)
6
+ @config = config
7
+
8
+ @target_group = TargetGroup.new(@config.gitlab.groups,
9
+ @config.to)
10
+
11
+ @from_group = FromGroup.new(@config.ldap.groups,
12
+ @config.from,
13
+ @target_group)
14
+ end
15
+
16
+ def run!
17
+ @from_group.each_new_user do |user|
18
+ @target_group.import_user(user) do |result|
19
+ result.on_new_user { |source| @target_group.create_user(source) }
20
+ result.on_error { |e| logger.error e }
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,57 @@
1
+ module SynchronizeUsers
2
+ class TargetGroup
3
+
4
+ class Result
5
+ def self.new_user(source) new(:new_user, source) end
6
+ def self.error(e) new(:error, e) end
7
+
8
+ def initialize(status, object = nil)
9
+ @status = status
10
+ @object = object
11
+ end
12
+
13
+ def on_new_user
14
+ yield(@object) if @status == :new_user
15
+ end
16
+
17
+ def on_error
18
+ yield(@object) if @status == :error
19
+ end
20
+ end
21
+
22
+ def initialize(connection, name)
23
+ @connection = connection
24
+ @name = name
25
+
26
+ initialize_group!
27
+ end
28
+
29
+ def initialize_group!
30
+ @group = @connection.find(name: @name) || @connection.create(@name, @name)
31
+ end
32
+
33
+ def has_user?(user)
34
+ !!members.find { |m| m.username == user.username}
35
+ end
36
+
37
+ def members
38
+ @members ||= @group.members
39
+ end
40
+
41
+ def create_user(user)
42
+ @connection.endpoint.users.import(user)
43
+ end
44
+
45
+ def import_user(source)
46
+ to_user = @connection.endpoint.users.find(source)
47
+
48
+ if !to_user
49
+ to_user = yield Result.new_user(source)
50
+ end
51
+
52
+ @group << to_user
53
+ rescue => e
54
+ yield Result.error(e)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module SynchronizeUsers
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,25 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','synchronize-users','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'synchronize-users'
5
+ s.version = SynchronizeUsers::VERSION
6
+ s.author = 'Alexandru Keszeg'
7
+ s.email = 'akeszeg@gmail.com'
8
+ s.homepage = 'http://github.com/artworx/synchronize-users'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'Synchronize LDAP users to gitlab'
11
+ s.files = `git ls-files`.split("
12
+ ")
13
+ s.require_paths << 'lib'
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = ['README.rdoc','synchronize-users.rdoc']
16
+ s.rdoc_options << '--title' << 'synchronize-users' << '--main' << 'README.rdoc' << '-ri'
17
+ s.bindir = 'bin'
18
+ s.executables << 'synchronize-users'
19
+ s.add_development_dependency('rake')
20
+ s.add_development_dependency('rdoc')
21
+ s.add_development_dependency('aruba')
22
+ #s.add_runtime_dependency('gli','2.13.1')
23
+ s.add_runtime_dependency('mooset','0.0.5')
24
+ s.add_runtime_dependency('pry')
25
+ end
@@ -0,0 +1,5 @@
1
+ = synchronize-users
2
+
3
+ Generate this with
4
+ synchronize-users rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+
3
+ # Add test libraries you want to use here, e.g. mocha
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ # Add global extensions to the test case class here
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: synchronize-users
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alexandru Keszeg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mooset
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.5
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email: akeszeg@gmail.com
85
+ executables:
86
+ - synchronize-users
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - README.rdoc
90
+ - synchronize-users.rdoc
91
+ files:
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README.rdoc
95
+ - Rakefile
96
+ - bin/synchronize-users
97
+ - features/step_definitions/synchronize-users_steps.rb
98
+ - features/support/env.rb
99
+ - features/synchronize-users.feature
100
+ - lib/synchronize-users.rb
101
+ - lib/synchronize-users/app.rb
102
+ - lib/synchronize-users/from_group.rb
103
+ - lib/synchronize-users/sync.rb
104
+ - lib/synchronize-users/target_group.rb
105
+ - lib/synchronize-users/version.rb
106
+ - synchronize-users.gemspec
107
+ - synchronize-users.rdoc
108
+ - test/default_test.rb
109
+ - test/test_helper.rb
110
+ homepage: http://github.com/artworx/synchronize-users
111
+ licenses: []
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options:
115
+ - "--title"
116
+ - synchronize-users
117
+ - "--main"
118
+ - README.rdoc
119
+ - "-ri"
120
+ require_paths:
121
+ - lib
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.7
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Synchronize LDAP users to gitlab
139
+ test_files: []