From de224fd22687b2fe962fe0c4bddf0c64c8c90561 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Wed, 24 Jul 2019 14:22:28 -0400 Subject: [PATCH] Convert Vmdb::PermissionsStore to a blacklist Since it's now a blacklist, there's no need for a sample file with the full possible whitelist --- config/permissions.tmpl.yml | 59 ----------------------- lib/vmdb/permission_stores/yaml.rb | 4 +- spec/lib/vmdb/permission_stores_spec.rb | 4 +- spec/models/ext_management_system_spec.rb | 9 +--- 4 files changed, 5 insertions(+), 71 deletions(-) delete mode 100644 config/permissions.tmpl.yml diff --git a/config/permissions.tmpl.yml b/config/permissions.tmpl.yml deleted file mode 100644 index ee3d132cd70..00000000000 --- a/config/permissions.tmpl.yml +++ /dev/null @@ -1,59 +0,0 @@ ---- -- :aut -- :automate -- :ansible -- :at -- :bst -- :clo -- :cnt -- :compute -- :con -- :conf -- :help -- :inf -- :monitor -- :monitor_alerts -- :dwh -- :net -- :opt -- :ost -- :phy -- :set -- :sto -- :svc -- :vi -- ems-type:ansible_tower_automation -- ems-type:azure -- ems-type:azure_network -- ems-type:azure_stack -- ems-type:azure_stack_network -- ems-type:cinder -- ems-type:ec2 -- ems-type:ec2_network -- ems-type:ec2_ebs_storage -- ems-type:embedded_ansible_automation -- ems-type:s3 -- ems-type:foreman_configuration -- ems-type:foreman_provisioning -- ems-type:gce -- ems-type:gce_network -- ems-type:hawkular -- ems-type:hawkular_datawarehouse -- ems-type:kubernetes -- ems-type:kubernetes_monitor -- ems-type:kubevirt -- ems-type:lenovo_ph_infra -- ems-type:nuage_network -- ems-type:openshift -- ems-type:openshift_monitor -- ems-type:openstack -- ems-type:openstack_infra -- ems-type:openstack_network -- ems-type:redfish_ph_infra -- ems-type:redhat_network -- ems-type:rhevm -- ems-type:scvmm -- ems-type:swift -- ems-type:vmware_cloud -- ems-type:vmware_cloud_network -- ems-type:vmwarews diff --git a/lib/vmdb/permission_stores/yaml.rb b/lib/vmdb/permission_stores/yaml.rb index 63e136cb54c..e9a5d50aab9 100644 --- a/lib/vmdb/permission_stores/yaml.rb +++ b/lib/vmdb/permission_stores/yaml.rb @@ -8,11 +8,11 @@ def self.create(config) class YAML def initialize(file) - @permissions = Psych.load_file(file) + @blacklist = Psych.load_file(file) end def can?(permission) - @permissions.include?(permission) + !@blacklist.include?(permission) end def supported_ems_type?(type) diff --git a/spec/lib/vmdb/permission_stores_spec.rb b/spec/lib/vmdb/permission_stores_spec.rb index b6457f743a4..5ea12423ddc 100644 --- a/spec/lib/vmdb/permission_stores_spec.rb +++ b/spec/lib/vmdb/permission_stores_spec.rb @@ -49,7 +49,7 @@ describe '::YAML' do it '#can?' do - stub_vmdb_permission_store_with_types(["foo"]) do + stub_vmdb_permission_store_with_types(["bar"]) do instance = Vmdb::PermissionStores.instance expect(instance.can?('foo')).to be_truthy expect(instance.can?('bar')).to be_falsey @@ -57,7 +57,7 @@ end it '#supported_ems_type?' do - stub_vmdb_permission_store_with_types(["ems-type:foo"]) do + stub_vmdb_permission_store_with_types(["ems-type:bar"]) do instance = Vmdb::PermissionStores.instance expect(instance.supported_ems_type?('foo')).to be_truthy expect(instance.supported_ems_type?('bar')).to be_falsey diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index b37f2c72b8a..9bc4f030a27 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -97,14 +97,7 @@ it "with removed permissions" do stub_vmdb_permission_store_with_types(["ems-type:vmwarews"]) do - expect(described_class.supported_types_and_descriptions_hash).to eq("vmwarews" => "VMware vCenter") - end - end - - it "permissions.tmpl.yml should contain all EMS types" do - types = YAML.load_file(Rails.root.join("config/permissions.tmpl.yml")) - stub_vmdb_permission_store_with_types(types) do - expect(described_class.supported_types_and_descriptions_hash).to eq(all_types_and_descriptions) + expect(described_class.supported_types_and_descriptions_hash).to_not include("vmwarews") end end end