Top Level Namespace

Defined Under Namespace

Modules: Conjur

Instance Method Summary collapse

Instance Method Details

#install_plugin(name, version) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/conjur/command/plugin.rb', line 91

def install_plugin(name, version)
  uninstall_plugin(name) rescue Exception

  gem_name = name.start_with?('conjur-asset-') ? name : "conjur-asset-#{name}"

  cmd = Gem::Commands::InstallCommand.new
  cmd.handle_options ['--no-ri', '--no-rdoc', gem_name, '--version', "#{version}"]

  begin
    cmd.execute
  rescue Gem::SystemExitException => e
    if e.exit_code != 0
      raise e
    end
  end

  modify_plugin_list('add', name)
end

#latest_conjur_releaseObject



6
7
8
9
10
11
12
# File 'lib/conjur/conjurize.rb', line 6

def latest_conjur_release
  url = 'https://api.github.com/repos/conjur-cookbooks/conjur/releases'
  resp = open(url)
  json = JSON.parse(resp.read)
  latest = json[0]['assets'].select {|asset| asset['name'] =~ /conjur-v\d.\d.\d.tar.gz/}[0]
  latest['browser_download_url']
end

#modify_plugin_list(op, plugin_name) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/conjur/command/plugin.rb', line 122

def modify_plugin_list(op, plugin_name)
  config_exists = false
  Conjur::Config.default_config_files.each do |f|
    if File.file?(f)
      config_exists = true
      config = YAML.load(IO.read(f)).stringify_keys rescue {}

      config['plugins'] ||= []
      config['plugins'] += [plugin_name] if op == 'add'
      config['plugins'] -= [plugin_name] if op == 'remove'
      config['plugins'].uniq!

      File.write(f, YAML.dump(config))
    end
  end
  exit_now! 'No Conjur config file found, run "conjur init"' unless config_exists
end

#uninstall_plugin(name) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/conjur/command/plugin.rb', line 110

def uninstall_plugin(name)
  if Conjur::Config.plugins.include?(name)
    gem_name = name.start_with?('conjur-asset-') ? name : "conjur-asset-#{name}"

    cmd = Gem::Commands::UninstallCommand.new
    cmd.handle_options ['-x', '-I', '-a', gem_name]
    cmd.execute

    modify_plugin_list('remove', name)
  end
end