mooset 0.0.3 → 0.0.4
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 +4 -4
- data/.drone.yml +15 -0
- data/.gitignore +1 -0
- data/Rakefile +0 -1
- data/lib/mooset/application.rb +11 -12
- data/lib/mooset/endpoints/gitlab/group.rb +1 -1
- data/lib/mooset/endpoints/gitlab/group_search.rb +1 -2
- data/lib/mooset/endpoints/gitlab/user_search.rb +1 -2
- data/lib/mooset/endpoints/gitlab.rb +0 -10
- data/lib/mooset/endpoints/ldap/ldap_search.rb +1 -2
- data/lib/mooset/endpoints/ldap.rb +0 -4
- data/lib/mooset/endpoints/null/group.rb +9 -0
- data/lib/mooset/endpoints/null/group_search.rb +32 -0
- data/lib/mooset/endpoints/null/user.rb +9 -0
- data/lib/mooset/endpoints/null/user_search.rb +23 -0
- data/lib/mooset/endpoints/null.rb +2 -44
- data/lib/mooset/endpoints/resource.rb +9 -0
- data/lib/mooset/endpoints.rb +6 -1
- data/lib/mooset/findable.rb +64 -0
- data/lib/mooset/{resource.rb → model.rb} +8 -5
- data/lib/mooset/models/group.rb +5 -1
- data/lib/mooset/models/user.rb +5 -1
- data/lib/mooset/synchronize_group.rb +1 -1
- data/lib/mooset/version.rb +1 -1
- data/lib/mooset.rb +3 -1
- data/mooset.gemspec +1 -0
- data/spec/mooset/endpoints/gitlab/user_search_spec.rb +142 -0
- data/spec/mooset/endpoints/gitlab_spec.rb +9 -0
- data/spec/mooset/endpoints/ldap_spec.rb +4 -2
- data/spec/spec_helper.rb +12 -0
- data/spec/support/an_endpoint.rb +10 -0
- data/spec/support/has_resource.rb +8 -0
- metadata +33 -7
- data/lib/mooset/configuration.rb +0 -21
- data/lib/mooset/endpoints/findable.rb +0 -62
- data/lib/mooset/storage/memory.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b093bf686448abfb179a9a60f6c370c476a9f301
|
4
|
+
data.tar.gz: b4ecd462864322ac24333f0c0015b3d8457e1ffc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06001439352cdda129beae947f94bb4c017a1d2bd40efa9cbcf971000424cb9e2e23f07cb25e7e5b5d838294ee2462535d6c98de08e216cbe076d191c1f61fae
|
7
|
+
data.tar.gz: 4d4e54909d05db0ddfa47e4767978a51d56b967aa6268b8b90b31711e85589257d44f2fa09abffaf8c32f6683bd1107a6a039423858949a74e96d09845ea761f
|
data/.drone.yml
ADDED
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/lib/mooset/application.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require 'optparse'
|
2
3
|
require 'irb'
|
3
|
-
require 'logger'
|
4
4
|
|
5
5
|
module Mooset
|
6
6
|
class Application
|
@@ -8,7 +8,6 @@ module Mooset
|
|
8
8
|
|
9
9
|
def define(endpoint_name, factory, opts = {})
|
10
10
|
opts[:endpoint_name] = endpoint_name
|
11
|
-
opts[:logger] = logger
|
12
11
|
|
13
12
|
endpoints[endpoint_name] = Mooset::Endpoints::Endpoint.create(factory, opts)
|
14
13
|
end
|
@@ -17,20 +16,12 @@ module Mooset
|
|
17
16
|
@endpoints ||= {}
|
18
17
|
end
|
19
18
|
|
20
|
-
def logger
|
21
|
-
@logger ||= begin
|
22
|
-
l = ::Logger.new(logfile || STDOUT)
|
23
|
-
l.level = ::Logger::WARN
|
24
|
-
l
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
19
|
def instances
|
29
20
|
@instances ||= {}
|
30
21
|
end
|
31
22
|
|
32
23
|
def synchronize_group(from:, to:, **opts)
|
33
|
-
operations << Mooset::
|
24
|
+
operations << Mooset::SynchronizeGroup.new(endpoints[from], endpoints[to], opts)
|
34
25
|
end
|
35
26
|
|
36
27
|
def operations
|
@@ -64,7 +55,7 @@ module Mooset
|
|
64
55
|
opts.banner = "Usage: #{$0} [options]"
|
65
56
|
opts.on("-f", "--logfile FILE", "Logfile", s.method(:logfile=))
|
66
57
|
opts.on("-v", "--verbose", "Verbose") do |x|
|
67
|
-
s.logger.level = ::Logger::
|
58
|
+
s.logger.level = ::Logger::DEBUG
|
68
59
|
end
|
69
60
|
|
70
61
|
opts.on("-c", "--config FILE", "Config file", s.method(:config_filename=))
|
@@ -72,6 +63,8 @@ module Mooset
|
|
72
63
|
opts.parse!(argv)
|
73
64
|
end
|
74
65
|
|
66
|
+
LSpace[:logger] = s.logger
|
67
|
+
|
75
68
|
if s.config_filename
|
76
69
|
s.read_config
|
77
70
|
s.run! unless s.interactive
|
@@ -80,5 +73,11 @@ module Mooset
|
|
80
73
|
s.start_irb if s.interactive
|
81
74
|
end
|
82
75
|
|
76
|
+
def logger
|
77
|
+
@logger ||= ::Logger.new(logfile || STDOUT).tap do |l|
|
78
|
+
l.level = ::Logger::INFO
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
83
82
|
end
|
84
83
|
end
|
@@ -20,16 +20,6 @@ module Mooset
|
|
20
20
|
resource :groups do
|
21
21
|
GroupSearch.new(self)
|
22
22
|
end
|
23
|
-
|
24
|
-
def write(user)
|
25
|
-
unless storage.exists?(user)
|
26
|
-
connection.create_user(user.email, '123123123',{
|
27
|
-
extern_uid: user.extern_uid,
|
28
|
-
username: user.username,
|
29
|
-
provider: 'ldap',
|
30
|
-
})
|
31
|
-
end
|
32
|
-
end
|
33
23
|
end
|
34
24
|
end
|
35
25
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Mooset
|
2
|
+
module Endpoints
|
3
|
+
class Null
|
4
|
+
class GroupSearch < Resource
|
5
|
+
def create(u)
|
6
|
+
model = Group.new(u.attributes)
|
7
|
+
model.send :define_singleton_method, :'<<' do |other|
|
8
|
+
logger.info "#{self} << #{other}"
|
9
|
+
end
|
10
|
+
|
11
|
+
model
|
12
|
+
end
|
13
|
+
|
14
|
+
import :gitlab do |gr|
|
15
|
+
g = create(gr)
|
16
|
+
g.send :define_singleton_method, :members do
|
17
|
+
[]
|
18
|
+
end
|
19
|
+
g
|
20
|
+
end
|
21
|
+
|
22
|
+
import :ldap do |gr|
|
23
|
+
g = create(gr)
|
24
|
+
g.send :define_singleton_method, :members do
|
25
|
+
[]
|
26
|
+
end
|
27
|
+
g
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Mooset
|
2
|
+
module Endpoints
|
3
|
+
class Null
|
4
|
+
class UserSearch < Resource
|
5
|
+
def create(u)
|
6
|
+
User.new(id: u.id, username: u.username, email: u.email)
|
7
|
+
end
|
8
|
+
|
9
|
+
def import(from, *args)
|
10
|
+
User.new(args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_from_hash(hash)
|
14
|
+
User.new(hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_from_object(object, *args)
|
18
|
+
User.new(object.attributes)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,54 +1,12 @@
|
|
1
1
|
module Mooset
|
2
2
|
module Endpoints
|
3
3
|
class Null < Endpoint
|
4
|
-
class U
|
5
|
-
#include Findable
|
6
|
-
|
7
|
-
def create(u)
|
8
|
-
Models::User.new(id: u.id, username: u.username, email: u.email)
|
9
|
-
end
|
10
|
-
|
11
|
-
def import(from, *args)
|
12
|
-
@logger.info(from, *args)
|
13
|
-
end
|
14
|
-
|
15
|
-
#import :ldap do |u|
|
16
|
-
#create(u)
|
17
|
-
#end
|
18
|
-
end
|
19
|
-
|
20
|
-
class G
|
21
|
-
include Findable
|
22
|
-
|
23
|
-
def create(u)
|
24
|
-
model = Models::Group.new(id: u.id, name: u.name)
|
25
|
-
model.send :define_singleton_method, :'<<' do |other|
|
26
|
-
@logger.info "#{self.id} << #{other.id}"
|
27
|
-
end
|
28
|
-
|
29
|
-
model
|
30
|
-
end
|
31
|
-
|
32
|
-
import :gitlab do |o|
|
33
|
-
logger.info o
|
34
|
-
end
|
35
|
-
|
36
|
-
import :ldap do |gr|
|
37
|
-
g = create(gr)
|
38
|
-
g.send :define_singleton_method, :members do
|
39
|
-
[]
|
40
|
-
end
|
41
|
-
g
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
4
|
resource :users do
|
47
|
-
|
5
|
+
UserSearch.new
|
48
6
|
end
|
49
7
|
|
50
8
|
resource :groups do
|
51
|
-
|
9
|
+
GroupSearch.new
|
52
10
|
end
|
53
11
|
end
|
54
12
|
end
|
data/lib/mooset/endpoints.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'mooset/endpoints/endpoint'
|
2
|
-
require 'mooset/endpoints/
|
2
|
+
require 'mooset/endpoints/resource'
|
3
3
|
require 'mooset/endpoints/gitlab'
|
4
4
|
require 'mooset/endpoints/gitlab/user'
|
5
5
|
require 'mooset/endpoints/gitlab/group'
|
@@ -11,7 +11,12 @@ require 'mooset/endpoints/ldap/user'
|
|
11
11
|
require 'mooset/endpoints/ldap/group'
|
12
12
|
require 'mooset/endpoints/ldap/ou'
|
13
13
|
require 'mooset/endpoints/ldap/ldap_search'
|
14
|
+
|
14
15
|
require 'mooset/endpoints/null'
|
16
|
+
require 'mooset/endpoints/null/user'
|
17
|
+
require 'mooset/endpoints/null/group'
|
18
|
+
require 'mooset/endpoints/null/user_search'
|
19
|
+
require 'mooset/endpoints/null/group_search'
|
15
20
|
|
16
21
|
module Mooset
|
17
22
|
module Endpoints
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Mooset
|
2
|
+
module Findable
|
3
|
+
module ClassMethods
|
4
|
+
def import(name, &block)
|
5
|
+
define_method(import_method_name(name), &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def finder(name, &block)
|
9
|
+
define_method(finder_method_name(name), &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def finder_method_name(name)
|
13
|
+
"find_by_#{name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def import_method_name(name)
|
17
|
+
"import_from_#{name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
def import(object)
|
23
|
+
logger.debug "import #{object}"
|
24
|
+
|
25
|
+
method = self.class.import_method_name(object.provider)
|
26
|
+
|
27
|
+
public_send(method, object)
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_from_object(object, *args)
|
31
|
+
finder = object.finders.find { |x| respond_to? self.class.finder_method_name(x) }
|
32
|
+
|
33
|
+
if finder && object[finder]
|
34
|
+
public_send(self.class.finder_method_name(finder), object[finder], *args)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_from_hash(hash)
|
39
|
+
key, value = hash.find { |(k, _)| respond_to? self.class.finder_method_name(k) }
|
40
|
+
|
41
|
+
args = hash.tap do |h|
|
42
|
+
h.delete(key)
|
43
|
+
end
|
44
|
+
|
45
|
+
if key && value
|
46
|
+
public_send(self.class.finder_method_name(key), value, args)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def find(opts, *args)
|
51
|
+
logger.debug "find #{opts}"
|
52
|
+
|
53
|
+
return find_from_hash(opts, *args) if opts.is_a? Hash
|
54
|
+
|
55
|
+
find_from_object(opts, args)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.included(receiver)
|
60
|
+
receiver.extend ClassMethods
|
61
|
+
receiver.send :include, InstanceMethods
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Mooset
|
2
|
-
class
|
2
|
+
class Model
|
3
3
|
include Virtus.model
|
4
4
|
|
5
5
|
attr_reader :endpoint
|
6
|
+
lspace_reader :logger
|
6
7
|
|
7
8
|
def self.finders(finder_list)
|
8
9
|
define_method :finders do
|
@@ -11,12 +12,10 @@ module Mooset
|
|
11
12
|
end
|
12
13
|
|
13
14
|
def initialize(*args)
|
14
|
-
|
15
|
+
hash = args[0] || {}
|
16
|
+
@endpoint = hash.delete(:endpoint)
|
15
17
|
|
16
18
|
super(*args)
|
17
|
-
|
18
|
-
@logger = ::Logger.new(STDOUT)
|
19
|
-
@logger.info "{endpoint_name} -- build #{self.class.name} #{args.join(" ")}"
|
20
19
|
end
|
21
20
|
|
22
21
|
def to_json(*args)
|
@@ -26,5 +25,9 @@ module Mooset
|
|
26
25
|
def finders
|
27
26
|
[]
|
28
27
|
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
"#{self.class.name.split('::').last}[#{provider}]"
|
31
|
+
end
|
29
32
|
end
|
30
33
|
end
|
data/lib/mooset/models/group.rb
CHANGED
data/lib/mooset/models/user.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
module Mooset
|
2
2
|
module Models
|
3
|
-
class User <
|
3
|
+
class User < Model
|
4
4
|
attribute :id
|
5
5
|
attribute :username
|
6
6
|
attribute :email
|
7
7
|
attribute :full_name
|
8
8
|
attribute :memberof
|
9
9
|
attribute :useraccountcontrol
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"#{super}::[#{self.username}](#{self.id})"
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
data/lib/mooset/version.rb
CHANGED
data/lib/mooset.rb
CHANGED
@@ -2,10 +2,12 @@ module Mooset
|
|
2
2
|
end
|
3
3
|
|
4
4
|
require "virtus"
|
5
|
+
require "lspace"
|
5
6
|
require "mooset/version"
|
6
7
|
require "mooset/monads"
|
7
8
|
|
8
|
-
require "mooset/
|
9
|
+
require "mooset/findable"
|
10
|
+
require "mooset/model"
|
9
11
|
require "mooset/models/user"
|
10
12
|
require "mooset/models/group"
|
11
13
|
|
data/mooset.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "gitlab", "~> 3.3.0"
|
22
22
|
spec.add_dependency "virtus", "~> 1.0.3"
|
23
23
|
spec.add_dependency "net-ldap", "~> 0.10"
|
24
|
+
spec.add_dependency "lspace", "~> 0.13"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mooset::Endpoints::Gitlab::UserSearch do
|
4
|
+
let(:connection) { double }
|
5
|
+
subject(:user_search) { Mooset::Endpoints::Gitlab::UserSearch.new(double(connection: connection)) }
|
6
|
+
|
7
|
+
let(:user1) { OpenStruct.new({
|
8
|
+
name: "Admin",
|
9
|
+
username: 'root',
|
10
|
+
id: 1,
|
11
|
+
state: 'active',
|
12
|
+
avatar_url: '',
|
13
|
+
email: 'root@gitlab',
|
14
|
+
identities: [OpenStruct.new({extern_uid: 'ldap_id', provider: 'ldap'})]
|
15
|
+
}) }
|
16
|
+
|
17
|
+
let(:user2) { OpenStruct.new({
|
18
|
+
name: "User2",
|
19
|
+
username: 'user2',
|
20
|
+
id: 1,
|
21
|
+
state: 'active',
|
22
|
+
avatar_url: '',
|
23
|
+
email: 'user2@local',
|
24
|
+
identities: [OpenStruct.new({extern_uid: 'ldap_user2', provider: 'ldap'})]
|
25
|
+
}) }
|
26
|
+
|
27
|
+
describe 'find' do
|
28
|
+
describe '#all' do
|
29
|
+
context 'without a block' do
|
30
|
+
it 'returns an Enumerator' do
|
31
|
+
expect(user_search.all).to be_a(Enumerator)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns all the users' do
|
36
|
+
expect(connection).to receive(:users).with(page: 1).and_return([user1])
|
37
|
+
expect(connection).to receive(:users).with(page: 2).and_return([])
|
38
|
+
|
39
|
+
@users = user_search.all.to_a
|
40
|
+
expect(@users.length).to eq(1)
|
41
|
+
|
42
|
+
expect(@users.first.id).to eq(1)
|
43
|
+
expect(@users.first.gitlab_id).to eq(1)
|
44
|
+
expect(@users.first.username).to eq('root')
|
45
|
+
expect(@users.first.full_name).to eq('Admin')
|
46
|
+
expect(@users.first.state).to eq('active')
|
47
|
+
expect(@users.first.email).to eq('root@gitlab')
|
48
|
+
expect(@users.first.access_level).to eq(nil)
|
49
|
+
expect(@users.first.ldap_id).to eq('ldap_id')
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ':id' do
|
53
|
+
before do
|
54
|
+
expect(connection).to receive(:user).with(1).and_return(user1)
|
55
|
+
@user = user_search.find(id: 1)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns the user resource" do
|
59
|
+
expect(@user.id).to eq(1)
|
60
|
+
expect(@user.gitlab_id).to eq(1)
|
61
|
+
expect(@user.username).to eq('root')
|
62
|
+
expect(@user.full_name).to eq('Admin')
|
63
|
+
expect(@user.state).to eq('active')
|
64
|
+
expect(@user.email).to eq('root@gitlab')
|
65
|
+
expect(@user.access_level).to eq(nil)
|
66
|
+
expect(@user.ldap_id).to eq('ldap_id')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'slow finders' do
|
71
|
+
before do
|
72
|
+
expect(connection).to receive(:users).with(page: 1).and_return([user1, user2])
|
73
|
+
expect(connection).to receive(:users).with(page: 2).and_return([])
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ':username' do
|
77
|
+
it 'returns the correct user' do
|
78
|
+
@user = user_search.find(username: 'user2')
|
79
|
+
expect(@user.username).to eq('user2')
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ':email' do
|
84
|
+
it 'returns the correct user' do
|
85
|
+
@user = user_search.find(email: 'user2@local')
|
86
|
+
expect(@user.email).to eq('user2@local')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ':dn' do
|
91
|
+
it 'returns the correct user' do
|
92
|
+
@user = user_search.find(dn: 'ldap_user2')
|
93
|
+
expect(@user.ldap_id).to eq('ldap_user2')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#create' do
|
101
|
+
it 'creates a gitlab user' do
|
102
|
+
expect(connection).to receive(:create_user).with('email@local', 'password', {}).and_return(user1)
|
103
|
+
@user = user_search.create('email@local', 'password')
|
104
|
+
|
105
|
+
expect(@user.username).to eq('root')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#import' do
|
110
|
+
describe 'from ldap' do
|
111
|
+
before do
|
112
|
+
@ldap_user = OpenStruct.new({
|
113
|
+
full_name: 'Full name',
|
114
|
+
username: 'username',
|
115
|
+
dn: 'dn',
|
116
|
+
provider: 'ldap',
|
117
|
+
email: 'email@local'
|
118
|
+
})
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'creates a gitlab user' do
|
122
|
+
expect(connection).to receive(:create_user).with('email@local', anything, {
|
123
|
+
name: 'Full name',
|
124
|
+
username: 'username',
|
125
|
+
extern_uid: 'dn',
|
126
|
+
provider: 'ldap'
|
127
|
+
}).and_return(user1)
|
128
|
+
|
129
|
+
@user = user_search.import(@ldap_user)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#group_members' do
|
135
|
+
context 'without block' do
|
136
|
+
it 'returns an Enumerator' do
|
137
|
+
expect(user_search.group_members(1)).to be_a(Enumerator)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
@@ -5,7 +5,10 @@ describe Mooset::Endpoints::Ldap do
|
|
5
5
|
let(:bind_dn) { double }
|
6
6
|
let(:port) { double }
|
7
7
|
let(:host) { double }
|
8
|
-
|
8
|
+
subject(:ldap) { Mooset::Endpoints::Ldap.new(endpoint_name: :ldap, host: host, port: port, bind_dn: bind_dn, bind_password: bind_password) }
|
9
|
+
|
10
|
+
it { should have_resource(:users) }
|
11
|
+
it { should have_resource(:groups) }
|
9
12
|
|
10
13
|
describe "#connection" do
|
11
14
|
subject(:connection) { ldap.connection }
|
@@ -17,4 +20,3 @@ describe Mooset::Endpoints::Ldap do
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
20
|
-
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rspec'
|
3
|
+
require 'logger'
|
4
|
+
require 'lspace/rspec'
|
3
5
|
|
4
6
|
ROOT = Pathname(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
5
7
|
$LOAD_PATH << File.join(ROOT, 'lib')
|
6
8
|
|
7
9
|
require 'mooset'
|
10
|
+
|
11
|
+
Dir[File.join(ROOT, "spec/support/**/*.rb")].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.color = true
|
15
|
+
|
16
|
+
config.before(:each) do
|
17
|
+
LSpace[:logger] = Logger.new('test.log')
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
RSpec.shared_examples "an endpoint" do |names|
|
2
|
+
it 'does things' do
|
3
|
+
expect(subject.class.respond_to?(:resources)).to eq(true)
|
4
|
+
expect(subject.class.resources).to eq(names)
|
5
|
+
|
6
|
+
names.each do |name|
|
7
|
+
expect(subject.send(name)).to be_a(::Mooset::Endpoints::Resource)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mooset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandru Keszeg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitlab
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: lspace
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.13'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.13'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,6 +144,7 @@ executables:
|
|
130
144
|
extensions: []
|
131
145
|
extra_rdoc_files: []
|
132
146
|
files:
|
147
|
+
- ".drone.yml"
|
133
148
|
- ".gitignore"
|
134
149
|
- Gemfile
|
135
150
|
- LICENSE.txt
|
@@ -139,10 +154,8 @@ files:
|
|
139
154
|
- config/sample
|
140
155
|
- lib/mooset.rb
|
141
156
|
- lib/mooset/application.rb
|
142
|
-
- lib/mooset/configuration.rb
|
143
157
|
- lib/mooset/endpoints.rb
|
144
158
|
- lib/mooset/endpoints/endpoint.rb
|
145
|
-
- lib/mooset/endpoints/findable.rb
|
146
159
|
- lib/mooset/endpoints/gitlab.rb
|
147
160
|
- lib/mooset/endpoints/gitlab/group.rb
|
148
161
|
- lib/mooset/endpoints/gitlab/group_search.rb
|
@@ -155,16 +168,25 @@ files:
|
|
155
168
|
- lib/mooset/endpoints/ldap/ou.rb
|
156
169
|
- lib/mooset/endpoints/ldap/user.rb
|
157
170
|
- lib/mooset/endpoints/null.rb
|
171
|
+
- lib/mooset/endpoints/null/group.rb
|
172
|
+
- lib/mooset/endpoints/null/group_search.rb
|
173
|
+
- lib/mooset/endpoints/null/user.rb
|
174
|
+
- lib/mooset/endpoints/null/user_search.rb
|
175
|
+
- lib/mooset/endpoints/resource.rb
|
176
|
+
- lib/mooset/findable.rb
|
177
|
+
- lib/mooset/model.rb
|
158
178
|
- lib/mooset/models/group.rb
|
159
179
|
- lib/mooset/models/user.rb
|
160
180
|
- lib/mooset/monads.rb
|
161
|
-
- lib/mooset/resource.rb
|
162
|
-
- lib/mooset/storage/memory.rb
|
163
181
|
- lib/mooset/synchronize_group.rb
|
164
182
|
- lib/mooset/version.rb
|
165
183
|
- mooset.gemspec
|
184
|
+
- spec/mooset/endpoints/gitlab/user_search_spec.rb
|
185
|
+
- spec/mooset/endpoints/gitlab_spec.rb
|
166
186
|
- spec/mooset/endpoints/ldap_spec.rb
|
167
187
|
- spec/spec_helper.rb
|
188
|
+
- spec/support/an_endpoint.rb
|
189
|
+
- spec/support/has_resource.rb
|
168
190
|
homepage: ''
|
169
191
|
licenses:
|
170
192
|
- MIT
|
@@ -185,10 +207,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
207
|
version: '0'
|
186
208
|
requirements: []
|
187
209
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.
|
210
|
+
rubygems_version: 2.4.6
|
189
211
|
signing_key:
|
190
212
|
specification_version: 4
|
191
213
|
summary: A Ruby library and client for user migration.
|
192
214
|
test_files:
|
215
|
+
- spec/mooset/endpoints/gitlab/user_search_spec.rb
|
216
|
+
- spec/mooset/endpoints/gitlab_spec.rb
|
193
217
|
- spec/mooset/endpoints/ldap_spec.rb
|
194
218
|
- spec/spec_helper.rb
|
219
|
+
- spec/support/an_endpoint.rb
|
220
|
+
- spec/support/has_resource.rb
|
data/lib/mooset/configuration.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Mooset
|
2
|
-
class Configuration
|
3
|
-
attr_reader :definitions, :tasks, :config_filename
|
4
|
-
|
5
|
-
def initialize(config_filename)
|
6
|
-
@config_filename = config_filename
|
7
|
-
@definitions = {}
|
8
|
-
@tasks = []
|
9
|
-
|
10
|
-
instance_eval File.read(@config_filename), @config_filename
|
11
|
-
end
|
12
|
-
|
13
|
-
def define(name, factory, *args)
|
14
|
-
@definitions[name] = Mooset::Endpoints::Endpoint.create(factory, *args)
|
15
|
-
end
|
16
|
-
|
17
|
-
def synchronize_users(from: nil, to: nil, query: nil)
|
18
|
-
@tasks << { from: from, to: to, query: query }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Mooset
|
2
|
-
module Endpoints
|
3
|
-
module Findable
|
4
|
-
module ClassMethods
|
5
|
-
def import(name, &block)
|
6
|
-
define_method(import_method_name(name), &block)
|
7
|
-
end
|
8
|
-
|
9
|
-
def finder(name, &block)
|
10
|
-
define_method(finder_method_name(name), &block)
|
11
|
-
end
|
12
|
-
|
13
|
-
def finder_method_name(name)
|
14
|
-
"find_by_#{name}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def import_method_name(name)
|
18
|
-
"import_from_#{name}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module InstanceMethods
|
23
|
-
def import(object)
|
24
|
-
method = self.class.import_method_name(object.provider)
|
25
|
-
|
26
|
-
public_send(method, object)
|
27
|
-
end
|
28
|
-
|
29
|
-
def find_from_object(object, *args)
|
30
|
-
finder = object.finders.find { |x| respond_to? self.class.finder_method_name(x) }
|
31
|
-
|
32
|
-
if finder && object[finder]
|
33
|
-
public_send(self.class.finder_method_name(finder), object[finder], *args)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def find_from_hash(hash)
|
38
|
-
key, value = hash.find { |(k, _)| respond_to? self.class.finder_method_name(k) }
|
39
|
-
|
40
|
-
args = hash.tap do |h|
|
41
|
-
h.delete(key)
|
42
|
-
end
|
43
|
-
|
44
|
-
if key && value
|
45
|
-
public_send(self.class.finder_method_name(key), value, args)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def find(opts, *args)
|
50
|
-
return find_from_hash(opts, *args) if opts.is_a? Hash
|
51
|
-
|
52
|
-
find_from_object(opts, args)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.included(receiver)
|
57
|
-
receiver.extend ClassMethods
|
58
|
-
receiver.send :include, InstanceMethods
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Mooset
|
2
|
-
module Storage
|
3
|
-
class Memory
|
4
|
-
attr_reader :name
|
5
|
-
|
6
|
-
def initialize(name)
|
7
|
-
@name = name
|
8
|
-
@objects = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def set(id, object)
|
12
|
-
@objects[id] = object
|
13
|
-
end
|
14
|
-
|
15
|
-
def exists?(id)
|
16
|
-
!@objects[id].nil?
|
17
|
-
end
|
18
|
-
|
19
|
-
def get(id)
|
20
|
-
@objects[id]
|
21
|
-
end
|
22
|
-
|
23
|
-
def fetch(id, &block)
|
24
|
-
if exists?(id)
|
25
|
-
get(id)
|
26
|
-
else
|
27
|
-
object = block.call
|
28
|
-
set(id, object)
|
29
|
-
object
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|