Module: Socialcast::CommandLine
- Defined in:
- lib/socialcast.rb,
lib/socialcast/command_line/cli.rb,
lib/socialcast/command_line/message.rb,
lib/socialcast/command_line/version.rb,
lib/socialcast/command_line/provisioner.rb,
lib/socialcast/command_line/authenticate.rb,
lib/socialcast/command_line/ldap_connector.rb,
lib/socialcast/command_line/provision_user.rb,
lib/socialcast/command_line/provision_photo.rb
Defined Under Namespace
Modules: Provisioner
Classes: Authenticate, CLI, LDAPConnector, Message, ProvisionPhoto, ProvisionUser
Constant Summary
collapse
- VERSION =
'1.4.1'
Class Method Summary
collapse
Class Method Details
.authentication(options) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/socialcast.rb', line 50
def self.authentication(options)
if options[:external_system]
{ :headers => { :Authorization => "SocialcastApiClient #{credentials[:api_client_identifier]}:#{credentials[:api_client_secret]}" } }
else
{ :user => credentials[:user], :password => credentials[:password] }
end
end
|
.config_dir ⇒ Object
15
16
17
18
19
|
# File 'lib/socialcast.rb', line 15
def self.config_dir
config_dir = File.expand_path '~/.socialcast'
FileUtils.mkdir config_dir, :mode => 0700 unless File.exist?(config_dir)
config_dir
end
|
.credentials ⇒ Object
25
26
27
28
|
# File 'lib/socialcast.rb', line 25
def self.credentials
fail 'Unknown Socialcast credentials. Run `socialcast authenticate` to initialize' unless File.exist?(credentials_file)
YAML.load_file(credentials_file)
end
|
.credentials=(options) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/socialcast.rb', line 30
def self.credentials=(options)
File.open(credentials_file, "a+") do |f|
existing_content = YAML.load(f.read) || {}
f.truncate(0)
f.write(existing_content.merge(options).to_yaml)
end
File.chmod 0600, credentials_file
end
|
.credentials_file ⇒ Object
21
22
23
|
# File 'lib/socialcast.rb', line 21
def self.credentials_file
ENV['SC_CREDENTIALS_FILE'] || File.join(config_dir, 'credentials.yml')
end
|
.resource_for_path(path, options = {}, debug = false) ⇒ Object
configure restclient for api call
40
41
42
43
44
45
46
47
48
|
# File 'lib/socialcast.rb', line 40
def self.resource_for_path(path, options = {}, debug = false)
RestClient.log = Logger.new(STDOUT) if debug
RestClient.proxy = credentials[:proxy] if credentials[:proxy]
rest_client_options = options.merge(authentication(options))
rest_client_options[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE if rest_client_options.delete('skip_ssl_validation')
url = ['https://', credentials[:domain], path].join
RestClient::Resource.new url, rest_client_options
end
|