summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs/file_system/chef_server
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-04-28 14:58:00 +0100
committerThom May <thom@chef.io>2016-05-05 14:35:25 +0100
commit927b683ed6b4d22bcc1a3b0f81ff7e662cc40f7f (patch)
treed2fadbdb8d6b331114b78fc9f5e8c0b9466e3a3e /lib/chef/chef_fs/file_system/chef_server
parent26b05126c47da7de27f899fbd3a4c290a3a92bf6 (diff)
downloadchef-927b683ed6b4d22bcc1a3b0f81ff7e662cc40f7f.tar.gz
Allow rest entries to define a display path
This gives us much more control over what an individual entry will display when formatted
Diffstat (limited to 'lib/chef/chef_fs/file_system/chef_server')
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/acl_entry.rb10
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb6
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/data_bag_entry.rb20
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/org_entry.rb4
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb4
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb4
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/policy_revision_entry.rb4
-rw-r--r--lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb5
8 files changed, 57 insertions, 0 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
index 68df3704bf..277cabe3a1 100644
--- a/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/acl_entry.rb
@@ -30,6 +30,16 @@ class Chef
"#{super}/_acl"
end
+ def display_path
+ pth = if parent.name == "acls"
+ "/acls/#{name}"
+ else
+ "/acls/#{parent.name}/#{name}"
+ end
+ # Chef::Log.warn "Display Path is #{pth}"
+ File.extname(pth).empty? ? pth + ".json" : pth
+ end
+
def delete(recurse)
raise Chef::ChefFS::FileSystem::OperationNotAllowedError.new(:delete, self, nil, "ACLs cannot be deleted")
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb b/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb
index 5ad0063807..ee0ecd3b40 100644
--- a/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb
@@ -17,6 +17,7 @@
#
require "chef/chef_fs/file_system/chef_server/rest_list_dir"
+require "chef/chef_fs/file_system/chef_server/data_bag_entry"
require "chef/chef_fs/file_system/exceptions"
require "chef/chef_fs/data_handler/data_bag_item_data_handler"
@@ -63,6 +64,11 @@ class Chef
end
end
end
+
+ def make_child_entry(name, exists = nil)
+ @children.find { |child| child.name == name } if @children
+ DataBagEntry.new(name, self, exists)
+ end
end
end
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/data_bag_entry.rb b/lib/chef/chef_fs/file_system/chef_server/data_bag_entry.rb
new file mode 100644
index 0000000000..3d70a61fb5
--- /dev/null
+++ b/lib/chef/chef_fs/file_system/chef_server/data_bag_entry.rb
@@ -0,0 +1,20 @@
+require "chef/chef_fs/file_system/chef_server/rest_list_entry"
+require "chef/chef_fs/data_handler/data_bag_item_data_handler"
+
+class Chef
+ module ChefFS
+ module FileSystem
+ module ChefServer
+ # /policies/NAME-REVISION.json
+ # Represents the actual data at /organizations/ORG/policies/NAME/revisions/REVISION
+ class DataBagEntry < RestListEntry
+ def display_path
+ pth = "/data_bags/#{parent.name}/#{name}"
+ File.extname(pth).empty? ? pth + ".json" : pth
+ end
+ end
+ end
+ end
+ end
+end
+
diff --git a/lib/chef/chef_fs/file_system/chef_server/org_entry.rb b/lib/chef/chef_fs/file_system/chef_server/org_entry.rb
index 87be36b932..7253de3449 100644
--- a/lib/chef/chef_fs/file_system/chef_server/org_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/org_entry.rb
@@ -17,6 +17,10 @@ class Chef
parent.api_path
end
+ def display_path
+ "/org.json"
+ end
+
def exists?
parent.exists?
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb
index 37b7af8b5e..adaffb99a7 100644
--- a/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb
@@ -27,6 +27,10 @@ class Chef
File.join(parent.api_path, "association_requests")
end
+ def display_path
+ "/invitations.json"
+ end
+
def exists?
parent.exists?
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
index 2e45b74450..7e9c7141c4 100644
--- a/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb
@@ -27,6 +27,10 @@ class Chef
File.join(parent.api_path, "users")
end
+ def display_path
+ "/members.json"
+ end
+
def exists?
parent.exists?
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/policy_revision_entry.rb b/lib/chef/chef_fs/file_system/chef_server/policy_revision_entry.rb
index d083383a0e..325b18e429 100644
--- a/lib/chef/chef_fs/file_system/chef_server/policy_revision_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/policy_revision_entry.rb
@@ -14,6 +14,10 @@ class Chef
"#{parent.api_path}/#{policy_name}/revisions/#{revision_id}"
end
+ def display_path
+ "/policies/#{policy_name}-#{revision_id}.json"
+ end
+
def write(file_contents)
raise OperationNotAllowedError.new(:write, self, nil, "cannot be updated: policy revisions are immutable once uploaded. If you want to change the policy, create a new revision with your changes")
end
diff --git a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
index 9b16bd80de..2cdf9edab3 100644
--- a/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
+++ b/lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb
@@ -47,6 +47,11 @@ class Chef
"#{parent.api_path}/#{api_child_name}"
end
+ def display_path
+ pth = api_path.start_with?("/") ? api_path : "/#{api_path}"
+ File.extname(pth).empty? ? pth + ".json" : pth
+ end
+
def org
parent.org
end