Class: Clusters::AgentTokens::CreateService
- Inherits:
-
Object
- Object
- Clusters::AgentTokens::CreateService
- Defined in:
- app/services/clusters/agent_tokens/create_service.rb
Constant Summary collapse
- ALLOWED_PARAMS =
%i[agent_id description name].freeze
- ACTIVE_TOKENS_LIMIT =
2
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(agent:, current_user:, params:) ⇒ CreateService
constructor
A new instance of CreateService.
Constructor Details
#initialize(agent:, current_user:, params:) ⇒ CreateService
Returns a new instance of CreateService.
11 12 13 14 15 |
# File 'app/services/clusters/agent_tokens/create_service.rb', line 11 def initialize(agent:, current_user:, params:) @agent = agent @current_user = current_user @params = params end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
9 10 11 |
# File 'app/services/clusters/agent_tokens/create_service.rb', line 9 def agent @agent end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
9 10 11 |
# File 'app/services/clusters/agent_tokens/create_service.rb', line 9 def current_user @current_user end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'app/services/clusters/agent_tokens/create_service.rb', line 9 def params @params end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/services/clusters/agent_tokens/create_service.rb', line 17 def execute return unless current_user.can?(:create_cluster, agent.project) return error_active_tokens_limit_reached if active_tokens_limit_reached? token = ::Clusters::AgentToken.new(filtered_params.merge(agent_id: agent.id, created_by_user: current_user)) if token.save log_activity_event(token) ServiceResponse.success(payload: { secret: token.token, token: token }) else ServiceResponse.error(message: token.errors.) end end |