Class: Chef::ChefFS::FileSystem::ChefServerRootDir
- Inherits:
-
BaseFSDir
- Object
- BaseFSObject
- BaseFSDir
- Chef::ChefFS::FileSystem::ChefServerRootDir
- Defined in:
- lib/chef/chef_fs/file_system/chef_server_root_dir.rb
Instance Attribute Summary collapse
-
#chef_private_key ⇒ Object
readonly
Returns the value of attribute chef_private_key.
-
#chef_server_url ⇒ Object
readonly
Returns the value of attribute chef_server_url.
-
#chef_username ⇒ Object
readonly
Returns the value of attribute chef_username.
-
#cookbook_version ⇒ Object
readonly
Returns the value of attribute cookbook_version.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#repo_mode ⇒ Object
readonly
Returns the value of attribute repo_mode.
Attributes inherited from BaseFSObject
Instance Method Summary collapse
- #api_path ⇒ Object
- #can_have_child?(name, is_dir) ⇒ Boolean
- #chef_rest ⇒ Object
- #children ⇒ Object
- #fs_description ⇒ Object
- #get_json(path) ⇒ Object
-
#initialize(root_name, chef_config, options = {}) ⇒ ChefServerRootDir
constructor
A new instance of ChefServerRootDir.
- #org ⇒ Object
- #path_for_printing ⇒ Object
- #rest ⇒ Object
Methods inherited from BaseFSDir
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, = {}) 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 = [:cookbook_version] # Used in knife diff and download for server cookbook version end |
Instance Attribute Details
#chef_private_key ⇒ Object (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_url ⇒ Object (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_username ⇒ Object (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_version ⇒ Object (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 |
#environment ⇒ Object (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_mode ⇒ Object (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_path ⇒ Object
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
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_rest ⇒ Object
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 |
#children ⇒ Object
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_description ⇒ Object
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 |
#org ⇒ Object
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_printing ⇒ Object
75 76 77 |
# File 'lib/chef/chef_fs/file_system/chef_server_root_dir.rb', line 75 def path_for_printing "#{@root_name}/" end |
#rest ⇒ Object
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 |