Class: Chef::ChefFS::FileSystem::ChefServerRootDir

Inherits:
BaseFSDir show all
Defined in:
lib/chef/chef_fs/file_system/chef_server_root_dir.rb

Instance Attribute Summary collapse

Attributes inherited from BaseFSObject

#name, #parent, #path

Instance Method Summary collapse

Methods inherited from BaseFSDir

#child, #dir?

Methods inherited from BaseFSObject

#child, #compare_to, #dir?, #exists?, #root

Constructor Details

#initialize(root_name, chef_config, repo_mode) ⇒ ChefServerRootDir

Returns a new instance of ChefServerRootDir.



29
30
31
32
33
34
35
36
37
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 29

def initialize(root_name, chef_config, repo_mode)
  super("", nil)
  @chef_server_url = chef_config[:chef_server_url]
  @chef_username = chef_config[:node_name]
  @chef_private_key = chef_config[:client_key]
  @environment = chef_config[:environment]
  @repo_mode = repo_mode
  @root_name = root_name
end

Instance Attribute Details

#chef_private_keyObject (readonly)

Returns the value of attribute chef_private_key.



41
42
43
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 41

def chef_private_key
  @chef_private_key
end

#chef_server_urlObject (readonly)

Returns the value of attribute chef_server_url.



39
40
41
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 39

def chef_server_url
  @chef_server_url
end

#chef_usernameObject (readonly)

Returns the value of attribute chef_username.



40
41
42
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 40

def chef_username
  @chef_username
end

#environmentObject (readonly)

Returns the value of attribute environment.



42
43
44
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 42

def environment
  @environment
end

#repo_modeObject (readonly)

Returns the value of attribute repo_mode.



43
44
45
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 43

def repo_mode
  @repo_mode
end

Instance Method Details

#api_pathObject



49
50
51
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 49

def api_path
  ""
end

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 57

def can_have_child?(name, is_dir)
  is_dir && children.any? { |child| child.name == name }
end

#childrenObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 61

def children
  @children ||= begin
    result = [
      CookbooksDir.new(self),
      DataBagsDir.new(self),
      RestListDir.new("environments", self),
      RestListDir.new("roles", self)
    ]
    if repo_mode == 'everything'
      result += [
        RestListDir.new("clients", self),
        NodesDir.new(self),
        RestListDir.new("users", self)
      ]
    end
    result.sort_by { |child| child.name }
  end
end

#path_for_printingObject



53
54
55
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 53

def path_for_printing
  "#{@root_name}/"
end

#restObject



45
46
47
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 45

def rest
  Chef::REST.new(chef_server_url, chef_username, chef_private_key)
end