Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
51d62854
Commit
51d62854
authored
Apr 09, 2021
by
Matthias Käppler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch '322128-token-order' into 'master'"
This reverts merge request !57520
parent
3f139e5d
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
17 additions
and
62 deletions
+17
-62
app/models/clusters/agent.rb
app/models/clusters/agent.rb
+0
-1
app/models/clusters/agent_token.rb
app/models/clusters/agent_token.rb
+1
-3
changelogs/unreleased/322128-token-order.yml
changelogs/unreleased/322128-token-order.yml
+0
-5
db/migrate/20210407152925_add_cluster_agent_token_last_used.rb
...grate/20210407152925_add_cluster_agent_token_last_used.rb
+0
-20
db/schema_migrations/20210407152925
db/schema_migrations/20210407152925
+0
-1
db/structure.sql
db/structure.sql
+0
-2
ee/app/graphql/resolvers/clusters/agent_tokens_resolver.rb
ee/app/graphql/resolvers/clusters/agent_tokens_resolver.rb
+1
-1
ee/app/graphql/resolvers/clusters/agents_resolver.rb
ee/app/graphql/resolvers/clusters/agents_resolver.rb
+1
-1
ee/spec/graphql/resolvers/clusters/agent_tokens_resolver_spec.rb
.../graphql/resolvers/clusters/agent_tokens_resolver_spec.rb
+4
-4
ee/spec/requests/api/graphql/project/cluster_agents_spec.rb
ee/spec/requests/api/graphql/project/cluster_agents_spec.rb
+10
-10
spec/models/clusters/agent_spec.rb
spec/models/clusters/agent_spec.rb
+0
-1
spec/models/clusters/agent_token_spec.rb
spec/models/clusters/agent_token_spec.rb
+0
-13
No files found.
app/models/clusters/agent.rb
View file @
51d62854
...
...
@@ -8,7 +8,6 @@ module Clusters
belongs_to
:project
,
class_name:
'::Project'
# Otherwise, it will load ::Clusters::Project
has_many
:agent_tokens
,
class_name:
'Clusters::AgentToken'
has_many
:last_used_agent_tokens
,
->
{
order_last_used_at_desc
},
class_name:
'Clusters::AgentToken'
scope
:ordered_by_name
,
->
{
order
(
:name
)
}
scope
:with_name
,
->
(
name
)
{
where
(
name:
name
)
}
...
...
app/models/clusters/agent_token.rb
View file @
51d62854
...
...
@@ -6,7 +6,7 @@ module Clusters
include
TokenAuthenticatable
add_authentication_token_field
:token
,
encrypted: :required
,
token_generator:
->
{
Devise
.
friendly_token
(
50
)
}
cached_attr_reader
:last_
us
ed_at
cached_attr_reader
:last_
contact
ed_at
self
.
table_name
=
'cluster_agent_tokens'
...
...
@@ -21,8 +21,6 @@ module Clusters
validates
:description
,
length:
{
maximum:
1024
}
validates
:name
,
presence:
true
,
length:
{
maximum:
255
}
scope
:order_last_used_at_desc
,
->
{
order
(
::
Gitlab
::
Database
.
nulls_last_order
(
'last_used_at'
,
'DESC'
))
}
def
track_usage
track_values
=
{
last_used_at:
Time
.
current
.
utc
}
...
...
changelogs/unreleased/322128-token-order.yml
deleted
100644 → 0
View file @
3f139e5d
---
title
:
Add ability to order cluster token by last used
merge_request
:
57520
author
:
type
:
changed
db/migrate/20210407152925_add_cluster_agent_token_last_used.rb
deleted
100644 → 0
View file @
3f139e5d
# frozen_string_literal: true
class
AddClusterAgentTokenLastUsed
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
INDEX
=
'index_cluster_agent_tokens_on_last_used_at'
disable_ddl_transaction!
def
up
add_concurrent_index
:cluster_agent_tokens
,
:last_used_at
,
name:
INDEX
,
order:
{
last_used_at:
'DESC NULLS LAST'
}
end
def
down
remove_concurrent_index_by_name
:cluster_agent_tokens
,
INDEX
end
end
db/schema_migrations/20210407152925
deleted
100644 → 0
View file @
3f139e5d
079ca92ac58519ce8f575c4cb94bfe6cf209e0c9eac20d3d3a294f5b468bc586
\ No newline at end of file
db/structure.sql
View file @
51d62854
...
...
@@ -22309,8 +22309,6 @@ CREATE INDEX index_cluster_agent_tokens_on_agent_id ON cluster_agent_tokens USIN
CREATE INDEX index_cluster_agent_tokens_on_created_by_user_id ON cluster_agent_tokens USING btree (created_by_user_id);
CREATE INDEX index_cluster_agent_tokens_on_last_used_at ON cluster_agent_tokens USING btree (last_used_at DESC NULLS LAST);
CREATE UNIQUE INDEX index_cluster_agent_tokens_on_token_encrypted ON cluster_agent_tokens USING btree (token_encrypted);
CREATE INDEX index_cluster_agents_on_created_by_user_id ON cluster_agents USING btree (created_by_user_id);
ee/app/graphql/resolvers/clusters/agent_tokens_resolver.rb
View file @
51d62854
...
...
@@ -12,7 +12,7 @@ module Resolvers
def
resolve
(
**
args
)
return
::
Clusters
::
AgentToken
.
none
unless
can_read_agent_tokens?
agent
.
last_used_
agent_tokens
agent
.
agent_tokens
end
private
...
...
ee/app/graphql/resolvers/clusters/agents_resolver.rb
View file @
51d62854
...
...
@@ -28,7 +28,7 @@ module Resolvers
private
def
preloads
{
tokens:
[
:last_used_agent_tokens
,
{
last_used_agent_tokens: :agent
}]
}
{
tokens:
:agent_tokens
}
end
end
end
...
...
ee/spec/graphql/resolvers/clusters/agent_tokens_resolver_spec.rb
View file @
51d62854
...
...
@@ -14,8 +14,8 @@ RSpec.describe Resolvers::Clusters::AgentTokensResolver do
let
(
:feature_available
)
{
true
}
let
(
:ctx
)
{
Hash
(
current_user:
user
)
}
let!
(
:matching_token1
)
{
create
(
:cluster_agent_token
,
agent:
agent
,
last_used_at:
5
.
days
.
ago
)
}
let!
(
:mat
ching_token2
)
{
create
(
:cluster_agent_token
,
agent:
agent
,
last_used_at:
2
.
days
.
ago
)
}
let!
(
:matching_token1
)
{
create
(
:cluster_agent_token
,
agent:
agent
)
}
let!
(
:mat
hcing_token2
)
{
create
(
:cluster_agent_token
,
agent:
agent
)
}
let!
(
:other_token
)
{
create
(
:cluster_agent_token
)
}
subject
{
resolve
(
described_class
,
obj:
agent
,
ctx:
ctx
)
}
...
...
@@ -24,8 +24,8 @@ RSpec.describe Resolvers::Clusters::AgentTokensResolver do
stub_licensed_features
(
cluster_agents:
feature_available
)
end
it
'returns tokens associated with the agent
, ordered by last_used_at
'
do
expect
(
subject
).
to
eq
([
matching_token2
,
matching_token1
]
)
it
'returns tokens associated with the agent'
do
expect
(
subject
).
to
contain_exactly
(
matching_token1
,
mathcing_token2
)
end
context
'feature is not available'
do
...
...
ee/spec/requests/api/graphql/project/cluster_agents_spec.rb
View file @
51d62854
...
...
@@ -50,22 +50,22 @@ RSpec.describe 'Project.cluster_agents' do
end
context
'selecting tokens'
do
let_it_be
(
:token_1
)
{
create
(
:cluster_agent_token
,
agent:
agents
.
first
)
}
let_it_be
(
:token_2
)
{
create
(
:cluster_agent_token
,
agent:
agents
.
second
)
}
let_it_be
(
:token_3
)
{
create
(
:cluster_agent_token
,
agent:
agents
.
second
,
last_used_at:
2
.
days
.
ago
)
}
let
(
:cluster_agents_fields
)
{
[
:id
,
query_nodes
(
:tokens
,
of:
'ClusterAgentToken'
)]
}
it
'can select tokens in last_used_at order'
do
before
do
create
(
:cluster_agent_token
,
agent:
agents
.
first
)
create
(
:cluster_agent_token
,
agent:
agents
.
second
)
end
it
'can select tokens'
do
post_graphql
(
query
,
current_user:
current_user
)
tokens
=
graphql_data_at
(
:project
,
:cluster_agents
,
:nodes
,
:tokens
,
:nodes
)
expect
(
tokens
).
to
match
([
a_hash_including
(
'id'
=>
global_id_of
(
token_1
)),
a_hash_including
(
'id'
=>
global_id_of
(
token_3
)),
a_hash_including
(
'id'
=>
global_id_of
(
token_2
))
])
expect
(
tokens
).
to
contain_exactly
(
a_hash_including
(
'id'
=>
be_present
),
a_hash_including
(
'id'
=>
be_present
)
)
end
it
'does not suffer from N+1 performance issues'
do
...
...
spec/models/clusters/agent_spec.rb
View file @
51d62854
...
...
@@ -8,7 +8,6 @@ RSpec.describe Clusters::Agent do
it
{
is_expected
.
to
belong_to
(
:created_by_user
).
class_name
(
'User'
).
optional
}
it
{
is_expected
.
to
belong_to
(
:project
).
class_name
(
'::Project'
)
}
it
{
is_expected
.
to
have_many
(
:agent_tokens
).
class_name
(
'Clusters::AgentToken'
)
}
it
{
is_expected
.
to
have_many
(
:last_used_agent_tokens
).
class_name
(
'Clusters::AgentToken'
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
63
)
}
...
...
spec/models/clusters/agent_token_spec.rb
View file @
51d62854
...
...
@@ -9,19 +9,6 @@ RSpec.describe Clusters::AgentToken do
it
{
is_expected
.
to
validate_length_of
(
:name
).
is_at_most
(
255
)
}
it
{
is_expected
.
to
validate_presence_of
(
:name
)
}
describe
'scopes'
do
describe
'.order_last_used_at_desc'
do
let_it_be
(
:token_1
)
{
create
(
:cluster_agent_token
,
last_used_at:
7
.
days
.
ago
)
}
let_it_be
(
:token_2
)
{
create
(
:cluster_agent_token
,
last_used_at:
nil
)
}
let_it_be
(
:token_3
)
{
create
(
:cluster_agent_token
,
last_used_at:
2
.
days
.
ago
)
}
it
'sorts by last_used_at descending, with null values at last'
do
expect
(
described_class
.
order_last_used_at_desc
)
.
to
eq
([
token_3
,
token_1
,
token_2
])
end
end
end
describe
'#token'
do
it
'is generated on save'
do
agent_token
=
build
(
:cluster_agent_token
,
token_encrypted:
nil
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment