Commit b99fff14 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'agent-token-delete' into 'master'

GraphQL mutation for deleting a cluster agent token

See merge request gitlab-org/gitlab!40338
parents 5c55a32d c9086f89
...@@ -1802,6 +1802,36 @@ type ClusterAgentTokenCreatePayload { ...@@ -1802,6 +1802,36 @@ type ClusterAgentTokenCreatePayload {
token: ClusterAgentToken token: ClusterAgentToken
} }
"""
Autogenerated input type of ClusterAgentTokenDelete
"""
input ClusterAgentTokenDeleteInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
Global ID of the cluster agent token that will be deleted
"""
id: ClustersAgentTokenID!
}
"""
Autogenerated return type of ClusterAgentTokenDelete
"""
type ClusterAgentTokenDeletePayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
Errors encountered during execution of the mutation.
"""
errors: [String!]!
}
""" """
Identifier of Clusters::Agent Identifier of Clusters::Agent
""" """
...@@ -10030,6 +10060,7 @@ type Mutation { ...@@ -10030,6 +10060,7 @@ type Mutation {
boardListUpdateLimitMetrics(input: BoardListUpdateLimitMetricsInput!): BoardListUpdateLimitMetricsPayload boardListUpdateLimitMetrics(input: BoardListUpdateLimitMetricsInput!): BoardListUpdateLimitMetricsPayload
clusterAgentDelete(input: ClusterAgentDeleteInput!): ClusterAgentDeletePayload clusterAgentDelete(input: ClusterAgentDeleteInput!): ClusterAgentDeletePayload
clusterAgentTokenCreate(input: ClusterAgentTokenCreateInput!): ClusterAgentTokenCreatePayload clusterAgentTokenCreate(input: ClusterAgentTokenCreateInput!): ClusterAgentTokenCreatePayload
clusterAgentTokenDelete(input: ClusterAgentTokenDeleteInput!): ClusterAgentTokenDeletePayload
commitCreate(input: CommitCreateInput!): CommitCreatePayload commitCreate(input: CommitCreateInput!): CommitCreatePayload
configureSast(input: ConfigureSastInput!): ConfigureSastPayload configureSast(input: ConfigureSastInput!): ConfigureSastPayload
createAlertIssue(input: CreateAlertIssueInput!): CreateAlertIssuePayload createAlertIssue(input: CreateAlertIssueInput!): CreateAlertIssuePayload
......
...@@ -4944,6 +4944,94 @@ ...@@ -4944,6 +4944,94 @@
"enumValues": null, "enumValues": null,
"possibleTypes": null "possibleTypes": null
}, },
{
"kind": "INPUT_OBJECT",
"name": "ClusterAgentTokenDeleteInput",
"description": "Autogenerated input type of ClusterAgentTokenDelete",
"fields": null,
"inputFields": [
{
"name": "id",
"description": "Global ID of the cluster agent token that will be deleted",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ClustersAgentTokenID",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "ClusterAgentTokenDeletePayload",
"description": "Autogenerated return type of ClusterAgentTokenDelete",
"fields": [
{
"name": "clientMutationId",
"description": "A unique identifier for the client performing the mutation.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "errors",
"description": "Errors encountered during execution of the mutation.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{ {
"kind": "SCALAR", "kind": "SCALAR",
"name": "ClustersAgentID", "name": "ClustersAgentID",
...@@ -28343,6 +28431,33 @@ ...@@ -28343,6 +28431,33 @@
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
}, },
{
"name": "clusterAgentTokenDelete",
"description": null,
"args": [
{
"name": "input",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "ClusterAgentTokenDeleteInput",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "ClusterAgentTokenDeletePayload",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "commitCreate", "name": "commitCreate",
"description": null, "description": null,
...@@ -314,6 +314,15 @@ Autogenerated return type of ClusterAgentTokenCreate ...@@ -314,6 +314,15 @@ Autogenerated return type of ClusterAgentTokenCreate
| `secret` | String | Token secret value. Make sure you save it - you won't be able to access it again | | `secret` | String | Token secret value. Make sure you save it - you won't be able to access it again |
| `token` | ClusterAgentToken | Token created after mutation | | `token` | ClusterAgentToken | Token created after mutation |
## ClusterAgentTokenDeletePayload
Autogenerated return type of ClusterAgentTokenDelete
| Name | Type | Description |
| --- | ---- | ---------- |
| `clientMutationId` | String | A unique identifier for the client performing the mutation. |
| `errors` | String! => Array | Errors encountered during execution of the mutation. |
## Commit ## Commit
| Name | Type | Description | | Name | Type | Description |
......
...@@ -9,6 +9,7 @@ module EE ...@@ -9,6 +9,7 @@ module EE
mount_mutation ::Mutations::Clusters::Agents::Create mount_mutation ::Mutations::Clusters::Agents::Create
mount_mutation ::Mutations::Clusters::Agents::Delete mount_mutation ::Mutations::Clusters::Agents::Delete
mount_mutation ::Mutations::Clusters::AgentTokens::Create mount_mutation ::Mutations::Clusters::AgentTokens::Create
mount_mutation ::Mutations::Clusters::AgentTokens::Delete
mount_mutation ::Mutations::Issues::SetIteration mount_mutation ::Mutations::Issues::SetIteration
mount_mutation ::Mutations::Issues::SetWeight mount_mutation ::Mutations::Issues::SetWeight
mount_mutation ::Mutations::Issues::SetEpic mount_mutation ::Mutations::Issues::SetEpic
......
# frozen_string_literal: true
module Mutations
module Clusters
module AgentTokens
class Delete < BaseMutation
graphql_name 'ClusterAgentTokenDelete'
authorize :admin_cluster
argument :id,
::Types::GlobalIDType[::Clusters::AgentToken],
required: true,
description: 'Global ID of the cluster agent token that will be deleted'
def resolve(id:)
token = authorized_find!(id: id)
token.destroy
{ errors: errors_on_object(token) }
end
private
def find_object(id:)
GitlabSchema.find_by_gid(id)
end
end
end
end
end
---
title: Add GraphQL endpoint for deleting a cluster agent token
merge_request: 40338
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Clusters::AgentTokens::Delete do
let(:token) { create(:cluster_agent_token) }
let(:user) { create(:user) }
let(:mutation) do
described_class.new(
object: double,
context: { current_user: user },
field: double
)
end
it { expect(described_class.graphql_name).to eq('ClusterAgentTokenDelete') }
it { expect(described_class).to require_graphql_authorizations(:admin_cluster) }
describe '#resolve' do
let(:global_id) { token.to_global_id }
subject { mutation.resolve(id: global_id) }
context 'without user permissions' do
it 'fails to delete the cluster agent', :aggregate_failures do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
expect { token.reload }.not_to raise_error
end
end
context 'with user permissions' do
before do
token.agent.project.add_maintainer(user)
end
it 'deletes a cluster agent', :aggregate_failures do
expect { subject }.to change { ::Clusters::AgentToken.count }.by(-1)
expect { token.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
context 'with invalid params' do
let(:global_id) { token.id }
it 'raises an error if the cluster agent id is invalid', :aggregate_failures do
expect { subject }.to raise_error(NoMethodError)
expect { token.reload }.not_to raise_error
end
end
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