Commit 59e9e7cd authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'FacVain-master-patch-89839' into 'master'

Create and use a new Error class instead StandardError in Security Orchestration Policies

See merge request gitlab-org/gitlab!79667
parents e2e53c15 e2250af7
...@@ -5,6 +5,8 @@ module Security ...@@ -5,6 +5,8 @@ module Security
class ProcessPolicyService class ProcessPolicyService
include BaseServiceUtility include BaseServiceUtility
Error = Class.new(StandardError)
def initialize(policy_configuration:, params:) def initialize(policy_configuration:, params:)
@policy_configuration = policy_configuration @policy_configuration = policy_configuration
@params = params @params = params
...@@ -29,7 +31,7 @@ module Security ...@@ -29,7 +31,7 @@ module Security
return error('Invalid policy YAML', :bad_request, pass_back: { details: policy_configuration_validation_errors(policy_hash) }) unless policy_configuration_valid?(policy_hash) return error('Invalid policy YAML', :bad_request, pass_back: { details: policy_configuration_validation_errors(policy_hash) }) unless policy_configuration_valid?(policy_hash)
success(policy_hash: policy_hash) success(policy_hash: policy_hash)
rescue StandardError => e rescue Error => e
error(e.message) error(e.message)
end end
...@@ -43,13 +45,13 @@ module Security ...@@ -43,13 +45,13 @@ module Security
return return
end end
raise StandardError, "Policy already exists with same name" if policy_exists?(policy_hash, policy[:name], type) raise Error, "Policy already exists with same name" if policy_exists?(policy_hash, policy[:name], type)
policy_hash[type] += [policy] policy_hash[type] += [policy]
end end
def replace_in_policy_hash(policy_hash, name, policy, type) def replace_in_policy_hash(policy_hash, name, policy, type)
raise StandardError, "Policy already exists with same name" if name && name != policy[:name] && policy_exists?(policy_hash, policy[:name], type) raise Error, "Policy already exists with same name" if name && name != policy[:name] && policy_exists?(policy_hash, policy[:name], type)
existing_policy_index = check_if_policy_exists!(policy_hash, name || policy[:name], type) existing_policy_index = check_if_policy_exists!(policy_hash, name || policy[:name], type)
policy_hash[type][existing_policy_index] = policy policy_hash[type][existing_policy_index] = policy
...@@ -62,7 +64,7 @@ module Security ...@@ -62,7 +64,7 @@ module Security
def check_if_policy_exists!(policy_hash, policy_name, type) def check_if_policy_exists!(policy_hash, policy_name, type)
existing_policy_index = policy_exists?(policy_hash, policy_name, type) existing_policy_index = policy_exists?(policy_hash, policy_name, type)
raise StandardError, "Policy does not exist" if existing_policy_index.nil? raise Error, "Policy does not exist" if existing_policy_index.nil?
existing_policy_index existing_policy_index
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment