Class: Bixby::Agent
- Inherits:
-
Object
- Object
- Bixby::Agent
- Defined in:
- lib/bixby-agent/agent.rb,
lib/bixby-agent/version.rb,
lib/bixby-agent/agent/config.rb,
lib/bixby-agent/agent/crypto.rb,
lib/bixby-agent/agent/handshake.rb,
lib/bixby-agent/agent/shell_exec.rb
Defined Under Namespace
Modules: Config, Crypto, Handshake, ShellExec
Constant Summary collapse
- DEFAULT_ROOT_DIR =
"/opt/bixby"
- VERSION =
File.new(File.("../../../VERSION", __FILE__)).read.strip
Constants included from Config
Instance Attribute Summary collapse
-
#access_key ⇒ Object
Returns the value of attribute access_key.
-
#client ⇒ Object
Returns the value of attribute client.
-
#mac_address ⇒ Object
Returns the value of attribute mac_address.
-
#manager_uri ⇒ Object
Returns the value of attribute manager_uri.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
- .create(root_dir = nil, use_config = true) ⇒ Object
-
.setup_env ⇒ Object
Setup the environment for shelling out.
Instance Method Summary collapse
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
-
#manager_ws_uri ⇒ String
Get the WebSocket API URI.
Methods included from ShellExec
Methods included from Handshake
#create_uuid, #get_hostname, #get_mac_address, #mac_changed?, #register_agent
Methods included from Crypto
#create_keypair, #crypto_enabled?, #decrypt_from_server, #encrypt_for_server, #have_server_key?, #keypair, #private_key, #private_key_file, #public_key, #server_key, #server_key_file
Methods included from Config
#config_dir, #config_file, included, #init_config_dir, #new=, #new?, #save_config
Constructor Details
Instance Attribute Details
#access_key ⇒ Object
Returns the value of attribute access_key.
25 26 27 |
# File 'lib/bixby-agent/agent.rb', line 25 def access_key @access_key end |
#client ⇒ Object
Returns the value of attribute client.
25 26 27 |
# File 'lib/bixby-agent/agent.rb', line 25 def client @client end |
#mac_address ⇒ Object
Returns the value of attribute mac_address.
25 26 27 |
# File 'lib/bixby-agent/agent.rb', line 25 def mac_address @mac_address end |
#manager_uri ⇒ Object
Returns the value of attribute manager_uri.
25 26 27 |
# File 'lib/bixby-agent/agent.rb', line 25 def manager_uri @manager_uri end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
25 26 27 |
# File 'lib/bixby-agent/agent.rb', line 25 def secret_key @secret_key end |
#uuid ⇒ Object
Returns the value of attribute uuid.
25 26 27 |
# File 'lib/bixby-agent/agent.rb', line 25 def uuid @uuid end |
Class Method Details
.create(root_dir = nil, use_config = true) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bixby-agent/agent.rb', line 28 def self.create(root_dir=nil, use_config = true) agent = load_config(root_dir) if use_config if agent.nil? then # create a new one if unable to load agent = new() end # pass config to some modules Bixby.agent = agent return agent if agent.new? Bixby.manager_uri = agent.manager_uri Bixby.client = Bixby::Client.new(agent.access_key, agent.secret_key) return agent end |
.setup_env ⇒ Object
Setup the environment for shelling out. Makes sure the correct Ruby version is on the path and that bixby-agent will be loaded by default
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/bixby-agent/agent.rb', line 57 def self.setup_env # make sure the correct ruby version is on the path c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end ruby_dir = File.(c['bindir']) shell = Mixlib::ShellOut.new("which ruby") shell.run_command if not $?.success? or File.dirname(shell.stdout.strip) != ruby_dir then ENV["PATH"] = ruby_dir + File::PATH_SEPARATOR + ENV["PATH"] end # create RUBYLIB paths paths = [] if ENV.include? "RUBYLIB" and not ENV["RUBYLIB"].empty? then paths = ENV["RUBYLIB"].split(/:/) end $:.each { |p| if p =~ %r(/gems/) and not paths.include? p then paths << p end } self_lib = File.(File.join(File.dirname(__FILE__), '../..', 'lib')) paths << self_lib if not paths.include? self_lib ENV["RUBYLIB"] = paths.join(":") ENV["RUBYOPT"] = '-rbixby-client/script' end |
Instance Method Details
#manager_ws_uri ⇒ String
Get the WebSocket API URI
88 89 90 91 92 93 94 |
# File 'lib/bixby-agent/agent.rb', line 88 def manager_ws_uri # convert manager uri to websocket uri = URI.parse(manager_uri) uri.scheme = (uri.scheme == "https" ? "wss" : "ws") uri.path = "/wsapi" return uri.to_s end |