debian-mirror-gitlab/app/graphql/mutations/ci/runners_registration_token/reset.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.7 KiB
Ruby
Raw Normal View History

2021-09-04 01:27:46 +05:30
# frozen_string_literal: true
module Mutations
module Ci
module RunnersRegistrationToken
class Reset < BaseMutation
graphql_name 'RunnersRegistrationTokenReset'
authorize :update_runners_registration_token
2021-10-27 15:23:28 +05:30
ScopeID = ::GraphQL::Types::ID
2021-09-04 01:27:46 +05:30
argument :type, ::Types::Ci::RunnerTypeEnum,
required: true,
description: 'Scope of the object to reset the token for.'
argument :id, ScopeID,
required: false,
description: 'ID of the project or group to reset the token for. Omit if resetting instance runner token.'
field :token,
2021-10-27 15:23:28 +05:30
GraphQL::Types::String,
2021-09-04 01:27:46 +05:30
null: true,
2021-10-27 15:23:28 +05:30
description: 'Runner token after mutation.'
2021-09-04 01:27:46 +05:30
2022-07-16 23:28:13 +05:30
def resolve(type:, id: nil)
scope = authorized_find!(type: type, id: id)
new_token = reset_token(scope)
2021-09-04 01:27:46 +05:30
{
2022-07-16 23:28:13 +05:30
token: new_token,
errors: errors_on_object(scope)
2021-09-04 01:27:46 +05:30
}
end
private
2022-07-16 23:28:13 +05:30
def find_object(type:, id: nil)
2021-09-04 01:27:46 +05:30
case type
2022-07-16 23:28:13 +05:30
when 'instance_type'
raise Gitlab::Graphql::Errors::ArgumentError, "id must not be specified for '#{type}' scope" if id.present?
ApplicationSetting.current
2021-09-04 01:27:46 +05:30
when 'group_type'
GitlabSchema.object_from_id(id, expected_type: ::Group)
when 'project_type'
GitlabSchema.object_from_id(id, expected_type: ::Project)
end
end
2022-07-16 23:28:13 +05:30
def reset_token(scope)
2022-08-27 11:52:29 +05:30
return unless scope
result = ::Ci::Runners::ResetRegistrationTokenService.new(scope, current_user).execute
result.payload[:new_registration_token] if result.success?
2021-09-04 01:27:46 +05:30
end
end
end
end
end