Class: Collavre::Admin::OrchestrationController

Inherits:
Collavre::ApplicationController show all
Defined in:
app/controllers/collavre/admin/orchestration_controller.rb

Defined Under Namespace

Classes: PolicyValidationError

Instance Method Summary collapse

Instance Method Details

#showObject



8
9
10
# File 'app/controllers/collavre/admin/orchestration_controller.rb', line 8

def show
  @policies_yaml = policies_to_yaml
end

#updateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/collavre/admin/orchestration_controller.rb', line 12

def update
  yaml_content = params[:policies_yaml].to_s

  begin
    parsed = YAML.safe_load(yaml_content, permitted_classes: [ Symbol ])
    validate_policies!(parsed)
    apply_policies!(parsed)

    redirect_to admin_orchestration_path, notice: t("admin.orchestration.updated")
  rescue Psych::SyntaxError => e
    flash.now[:alert] = t("admin.orchestration.yaml_syntax_error", message: e.message)
    @policies_yaml = yaml_content
    render :show, status: :unprocessable_entity
  rescue PolicyValidationError => e
    flash.now[:alert] = e.message
    @policies_yaml = yaml_content
    render :show, status: :unprocessable_entity
  end
end