socialcast 1.0.0.beta1 → 1.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- data/config/ldap.yml +44 -0
- data/lib/socialcast.rb +3 -0
- data/lib/socialcast/cli.rb +94 -1
- data/lib/socialcast/version.rb +1 -1
- data/socialcast.gemspec +1 -0
- metadata +21 -4
data/config/ldap.yml
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
# LDAP connection information
|
3
|
+
connections:
|
4
|
+
example_connection_1:
|
5
|
+
username: "cn=Directory Manager"
|
6
|
+
password: "password"
|
7
|
+
host: ldap.yourdomain.com
|
8
|
+
port: 389
|
9
|
+
basedn: "ou=smallpeople,ou=qa,dc=socialcast,dc=com"
|
10
|
+
filter: "(mail=*)"
|
11
|
+
example_connection_2:
|
12
|
+
username: "cn=Directory Manager"
|
13
|
+
password: "password"
|
14
|
+
host: ldap.yourdomain.com
|
15
|
+
port: 389
|
16
|
+
basedn: "ou=tinypeople,ou=qa,dc=yourdomain,dc=com"
|
17
|
+
filter: "(mail=*)"
|
18
|
+
example_encrypted_connection:
|
19
|
+
username: "cn=Directory Manager"
|
20
|
+
password: "password"
|
21
|
+
host: ldap.yourdomain.com
|
22
|
+
port: 389
|
23
|
+
basedn: "ou=largepeople,ou=qa,dc=yourdomain,dc=com"
|
24
|
+
filter: "(mail=*)"
|
25
|
+
encryption: simple_tls
|
26
|
+
|
27
|
+
# LDAP attribute mappings
|
28
|
+
mappings:
|
29
|
+
first_name: givenName
|
30
|
+
last_name: sn
|
31
|
+
email: mail
|
32
|
+
#only use employee_number if the email is unknown
|
33
|
+
#employee_number: emp_id
|
34
|
+
#only use unique_identifier if you do not wish to use email as the main user identification method
|
35
|
+
#unique_identifier: samaccountname
|
36
|
+
|
37
|
+
delete_users_file: false
|
38
|
+
# test being true implies that you wish to skip_emails
|
39
|
+
test: true
|
40
|
+
skip_emails: true
|
41
|
+
|
42
|
+
# (optional) http_proxy setting
|
43
|
+
# only needed if the script must connect to Socialcast through a proxy
|
44
|
+
# http_proxy: "http://username:password@proxy.company.com:3128"
|
data/lib/socialcast.rb
CHANGED
@@ -20,4 +20,7 @@ module Socialcast
|
|
20
20
|
raise 'Unknown Socialcast credentials. Run `socialcast authenticate` to initialize' unless File.exist?(credentials_file)
|
21
21
|
YAML.load_file(credentials_file)
|
22
22
|
end
|
23
|
+
def grab_value(entry)
|
24
|
+
entry.is_a?(Array) ? entry.first : entry
|
25
|
+
end
|
23
26
|
end
|
data/lib/socialcast/cli.rb
CHANGED
@@ -5,11 +5,14 @@ require 'highline'
|
|
5
5
|
require 'socialcast'
|
6
6
|
require 'socialcast/message'
|
7
7
|
|
8
|
+
require 'zlib'
|
9
|
+
require 'builder'
|
10
|
+
require 'net/ldap'
|
11
|
+
|
8
12
|
module Socialcast
|
9
13
|
class CLI < Thor
|
10
14
|
include Thor::Actions
|
11
15
|
include Socialcast
|
12
|
-
default_task :share
|
13
16
|
|
14
17
|
desc "authenticate", "Authenticate using your Socialcast credentials"
|
15
18
|
method_option :user, :type => :string, :aliases => '-u', :desc => 'email address for the authenticated user'
|
@@ -63,5 +66,95 @@ module Socialcast
|
|
63
66
|
|
64
67
|
say "Message has been shared"
|
65
68
|
end
|
69
|
+
|
70
|
+
desc 'provision', 'provision users from ldap compatible user repository'
|
71
|
+
method_option :setup, :default => false
|
72
|
+
method_option :config, :default => 'ldap.yml', :aliases => '-c'
|
73
|
+
method_option :output, :default => 'users.xml.gz', :aliases => '-o'
|
74
|
+
method_option :delete_users_file, :default => true
|
75
|
+
def provision
|
76
|
+
config_file = File.join Dir.pwd, options[:config]
|
77
|
+
|
78
|
+
if options[:setup]
|
79
|
+
create_file config_file do
|
80
|
+
File.read File.join(File.dirname(__FILE__), '..', '..', 'config', 'ldap.yml')
|
81
|
+
end
|
82
|
+
return
|
83
|
+
end
|
84
|
+
|
85
|
+
config = YAML.load_file config_file
|
86
|
+
required_mappings = %w{email first_name last_name}
|
87
|
+
required_mappings.each do |field|
|
88
|
+
unless config["mappings"].has_key? field
|
89
|
+
fail "Missing required mapping: #{field}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
output_file = File.join Dir.pwd, options[:output]
|
94
|
+
Zlib::GzipWriter.open(output_file) do |gz|
|
95
|
+
xml = Builder::XmlMarkup.new(:target => gz, :indent => 1)
|
96
|
+
xml.instruct!
|
97
|
+
xml.export do |export|
|
98
|
+
export.users(:type => "array") do |users|
|
99
|
+
config["connections"].each_pair do |key, connection|
|
100
|
+
say "Connecting to #{key} at #{[connection["host"], connection["port"]].join(':')} with filter #{connection["basedn"]}"
|
101
|
+
|
102
|
+
ldap = Net::LDAP.new :host => connection["host"], :port => connection["port"], :base => connection["basedn"]
|
103
|
+
ldap.encryption connection['encryption'].to_sym if connection['encryption']
|
104
|
+
ldap.auth connection["username"], connection["password"]
|
105
|
+
say "Connected"
|
106
|
+
say "Searching..."
|
107
|
+
count = 0
|
108
|
+
ldap.search(:return_result => false, :filter => connection["filter"], :base => connection["basedn"]) do |entry|
|
109
|
+
next if grab_value(entry[config["mappings"]["email"]]).blank? || (config["mappings"].has_key?("unique_identifier") && grab_value(entry[config["mappings"]["unique_identifier"]]).blank?)
|
110
|
+
users.user do |user|
|
111
|
+
primary_attributes = %w{unique_identifier first_name last_name employee_number}
|
112
|
+
primary_attributes.each do |attribute|
|
113
|
+
next unless config['mappings'].has_key?(attribute)
|
114
|
+
user.tag! attribute, grab_value(entry[config["mappings"][attribute]])
|
115
|
+
end
|
116
|
+
contact_attributes = %w{email location cell_phone office_phone}
|
117
|
+
user.tag! 'contact-info' do |contact_info|
|
118
|
+
contact_attributes.each do |attribute|
|
119
|
+
next unless config['mappings'].has_key?(attribute)
|
120
|
+
contact_info.tag! attribute, grab_value(entry[config["mappings"][attribute]])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
custom_attributes = config['mappings'].keys - (primary_attributes + contact_attributes)
|
124
|
+
user.tag! 'custom-fields', :type => "array" do |custom_fields|
|
125
|
+
custom_attributes.each do |attribute|
|
126
|
+
custom_fields.tag! 'custom-field' do |custom_field|
|
127
|
+
custom_field.id(attribute)
|
128
|
+
custom_field.value(grab_value(entry[config["mappings"][attribute]]))
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end # user
|
133
|
+
count += 1
|
134
|
+
say "Scanned #{count} users..." if ((count % 100) == 0)
|
135
|
+
end # search
|
136
|
+
end # connections
|
137
|
+
end # users
|
138
|
+
end # export
|
139
|
+
end # gzip
|
140
|
+
|
141
|
+
say "Finished Scanning"
|
142
|
+
say "Sending to Socialcast"
|
143
|
+
|
144
|
+
RestClient.log = Logger.new(STDOUT)
|
145
|
+
RestClient.proxy = config["http_proxy"] if config["http_proxy"]
|
146
|
+
url = ['https://', credentials[:domain], '/api/users/provision'].join
|
147
|
+
private_resource = RestClient::Resource.new url, :user => credentials[:username], :password => credentials[:password], :timeout => 660
|
148
|
+
File.open(output_file, 'r') do |file|
|
149
|
+
request_params = {:file => file}
|
150
|
+
request_params[:skip_emails] = "true" if config["skip_emails"]
|
151
|
+
request_params[:test] = "true" if config["test"]
|
152
|
+
private_resource.post request_params
|
153
|
+
end
|
154
|
+
|
155
|
+
File.delete(output_file) if options[:delete_users_file]
|
156
|
+
|
157
|
+
say "Finished"
|
158
|
+
end
|
66
159
|
end
|
67
160
|
end
|
data/lib/socialcast/version.rb
CHANGED
data/socialcast.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_runtime_dependency 'json', '>= 1.4.6'
|
20
20
|
s.add_runtime_dependency 'thor', '>= 0.14.6'
|
21
21
|
s.add_runtime_dependency 'highline', '>= 1.6.2'
|
22
|
+
s.add_runtime_dependency 'scashin133-net-ldap', '>= 0.1.4'
|
22
23
|
|
23
24
|
s.files = `git ls-files`.split("\n")
|
24
25
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socialcast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196357
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 1.0.0.
|
11
|
+
- 3
|
12
|
+
version: 1.0.0.beta3
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Ryan Sonnek
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-06-
|
21
|
+
date: 2011-06-30 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
24
|
name: shoulda
|
@@ -98,6 +98,22 @@ dependencies:
|
|
98
98
|
version: 1.6.2
|
99
99
|
type: :runtime
|
100
100
|
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: scashin133-net-ldap
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 19
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 1
|
113
|
+
- 4
|
114
|
+
version: 0.1.4
|
115
|
+
type: :runtime
|
116
|
+
version_requirements: *id006
|
101
117
|
description: publish messages to your stream from a command line interface
|
102
118
|
email:
|
103
119
|
- ryan@socialcast.com
|
@@ -116,6 +132,7 @@ files:
|
|
116
132
|
- README.md
|
117
133
|
- Rakefile
|
118
134
|
- bin/socialcast
|
135
|
+
- config/ldap.yml
|
119
136
|
- lib/socialcast.rb
|
120
137
|
- lib/socialcast/cli.rb
|
121
138
|
- lib/socialcast/message.rb
|