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

#chef_object, #child, #compare_to, #create_child, #delete, #dir?, #exists?, #read, #root, #write

Constructor Details

#initialize(root_name, chef_config, options = {}) ⇒ ChefServerRootDir

Returns a new instance of ChefServerRootDir.



37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 37

def initialize(root_name, chef_config, options = {})
  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 = chef_config[:repo_mode]
  @root_name = root_name
  @cookbook_version = options[:cookbook_version] # Used in knife diff and download for server cookbook version
end

Instance Attribute Details

#chef_private_keyObject (readonly)

Returns the value of attribute chef_private_key.



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

def chef_private_key
  @chef_private_key
end

#chef_server_urlObject (readonly)

Returns the value of attribute chef_server_url.



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

def chef_server_url
  @chef_server_url
end

#chef_usernameObject (readonly)

Returns the value of attribute chef_username.



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

def chef_username
  @chef_username
end

#cookbook_versionObject (readonly)

Returns the value of attribute cookbook_version.



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

def cookbook_version
  @cookbook_version
end

#environmentObject (readonly)

Returns the value of attribute environment.



51
52
53
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 51

def environment
  @environment
end

#repo_modeObject (readonly)

Returns the value of attribute repo_mode.



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

def repo_mode
  @repo_mode
end

Instance Method Details

#api_pathObject



71
72
73
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 71

def api_path
  ""
end

#can_have_child?(name, is_dir) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 79

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

#chef_restObject



67
68
69
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 67

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

#childrenObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 91

def children
  @children ||= begin
    result = [
      CookbooksDir.new(self),
      DataBagsDir.new(self),
      EnvironmentsDir.new(self),
      RestListDir.new("roles", self, nil, Chef::ChefFS::DataHandler::RoleDataHandler.new)
    ]
    if repo_mode == 'hosted_everything'
      result += [
        AclsDir.new(self),
        RestListDir.new("clients", self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new),
        RestListDir.new("containers", self, nil, Chef::ChefFS::DataHandler::ContainerDataHandler.new),
        RestListDir.new("groups", self, nil, Chef::ChefFS::DataHandler::GroupDataHandler.new),
        NodesDir.new(self)
      ]
    elsif repo_mode != 'static'
      result += [
        RestListDir.new("clients", self, nil, Chef::ChefFS::DataHandler::ClientDataHandler.new),
        NodesDir.new(self),
        RestListDir.new("users", self, nil, Chef::ChefFS::DataHandler::UserDataHandler.new)
      ]
    end
    result.sort_by { |child| child.name }
  end
end

#fs_descriptionObject



55
56
57
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 55

def fs_description
  "Chef server at #{chef_server_url} (user #{chef_username}), repo_mode = #{repo_mode}"
end

#get_json(path) ⇒ Object



63
64
65
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 63

def get_json(path)
  Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key).get(path)
end

#orgObject



83
84
85
86
87
88
89
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 83

def org
  @org ||= if URI.parse(chef_server_url).path =~ /^\/+organizations\/+([^\/]+)$/
    $1
  else
    nil
  end
end

#path_for_printingObject



75
76
77
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 75

def path_for_printing
  "#{@root_name}/"
end

#restObject



59
60
61
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 59

def rest
  Chef::ServerAPI.new(chef_server_url, :client_name => chef_username, :signing_key_filename => chef_private_key, :raw_output => true)
end