Class: Chef::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_url) ⇒ Server

Returns a new instance of Server.


9
10
11
# File 'lib/chef/server.rb', line 9

def initialize(root_url)
  @root_url = root_url
end

Instance Attribute Details

#root_urlObject

Returns the value of attribute root_url


8
9
10
# File 'lib/chef/server.rb', line 8

def root_url
  @root_url
end

Class Method Details

.from_chef_server_url(url) ⇒ Object


13
14
15
16
# File 'lib/chef/server.rb', line 13

def self.from_chef_server_url(url)
  url = url.gsub(/\/organizations\/+[^\/]+\/*$/, '')
  Chef::Server.new(url)
end

Instance Method Details

#direct_account_access?Boolean

Returns:

  • (Boolean)

35
36
37
38
39
40
# File 'lib/chef/server.rb', line 35

def 
  Chef::ServerAPI.new("http://127.0.0.1:9465").get("users")
  true
rescue
  false
end

#parse_server_version(line) ⇒ Object


18
19
20
21
22
# File 'lib/chef/server.rb', line 18

def parse_server_version(line)
  # first line from the /version endpoint will either be this format "chef-server 12.17.5\n"
  # or, when habitat, this format "Package: chef-server/chef-server-nginx/12.17.42/20180413212943\n"
  Gem::Version.new(line.include?('/') ? line.split('/')[2] : line.split(' ').last.gsub(/\+.*$/, ''))
end

#supports_defaulting_to_pivotal?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/chef/server.rb', line 42

def supports_defaulting_to_pivotal?
  version >= Gem::Version.new('12.1.0')
end

#supports_public_key_read_access?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/chef/server.rb', line 46

def supports_public_key_read_access?
  version >= Gem::Version.new('12.5.0')
end

#supports_user_acls?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/chef/server.rb', line 31

def supports_user_acls?
  version >= Gem::Version.new("11.0.1")
end

#versionObject


24
25
26
27
28
29
# File 'lib/chef/server.rb', line 24

def version
  @version ||= begin
                 ver_line = Chef::ServerAPI.new(root_url).get('version').each_line.first
                 parse_server_version(ver_line)
               end
end