Module: NexusCli::GlobalSettingsActions

Included in:
OSSRemote, ProRemote
Defined in:
lib/nexus_cli/mixins/global_settings_actions.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#get_global_settingsFile

Retrieves the global settings of the Nexus server

Returns:

  • (File)

    a File with the global settings.



10
11
12
13
14
15
16
17
18
# File 'lib/nexus_cli/mixins/global_settings_actions.rb', line 10

def get_global_settings
  json = get_global_settings_json
  pretty_json = JSON.pretty_generate(JSON.parse(json))
  Dir.mkdir(File.expand_path("~/.nexus")) unless Dir.exists?(File.expand_path("~/.nexus"))
  destination = File.join(File.expand_path("~/.nexus"), "global_settings.json")
  artifact_file = File.open(destination, 'wb') do |file|
    file.write(pretty_json)
  end
end

#get_global_settings_jsonObject



20
21
22
23
24
25
26
27
28
# File 'lib/nexus_cli/mixins/global_settings_actions.rb', line 20

def get_global_settings_json
  response = nexus.get(nexus_url("service/local/global_settings/current"), :header => DEFAULT_ACCEPT_HEADER)
  case response.status
  when 200
    return response.content
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#reset_global_settingsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nexus_cli/mixins/global_settings_actions.rb', line 46

def reset_global_settings
  response = nexus.get(nexus_url("service/local/global_settings/default"), :header => DEFAULT_ACCEPT_HEADER)
  case response.status
  when 200
    default_json = response.content
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end

  response = nexus.put(nexus_url("service/local/global_settings/current"), :body => default_json, :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 204
    return true
  else
    raise UnexpectedStatusCodeException.new(response.status)
  end
end

#upload_global_settings(json = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/nexus_cli/mixins/global_settings_actions.rb', line 30

def upload_global_settings(json=nil)
  global_settings = nil
  if json == nil
    global_settings = File.read(File.join(File.expand_path("~/.nexus"), "global_settings.json"))
  else
    global_settings = json
  end
  response = nexus.put(nexus_url("service/local/global_settings/current"), :body => global_settings, :header => DEFAULT_CONTENT_TYPE_HEADER)
  case response.status
  when 204
    return true
  when 400
    raise BadSettingsException.new(response.content)
  end
end