ManageIQ/manageiq-api

View on GitHub
app/controllers/api/automate_workspaces_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module Api
  class AutomateWorkspacesController < BaseController
    def edit_resource(type, id, data = {})
      raise BadRequestError, "must contain at least one attribute to edit" if data.blank?
      obj = resource_search(id, type)
      obj.merge_output!(data)
    end

    def decrypt_resource(type, id = nil, data = nil)
      obj = resource_search(id, type)
      decrypt(obj, data)
    end

    def encrypt_resource(type, id = nil, data = nil)
      obj = resource_search(id, type)
      obj.encrypt(data['object'], data['attribute'], data['value'])
    end

    private

    def decrypt(obj, data)
      {'object'    => data['object'],
       'attribute' => data['attribute'],
       'value'     => obj.decrypt(data['object'], data['attribute'])}
    end

    def normalize_attr(attr, value)
      return "password::********" if value.kind_of?(String) && value.start_with?("password::")
      super
    end
  end
end