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
ea81dd8c
Commit
ea81dd8c
authored
Apr 21, 2020
by
Mike Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PackageFileRegistryResolver for GraphQL
Not yet accessible via the API
parent
c3e08d1c
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
265 additions
and
0 deletions
+265
-0
ee/app/graphql/resolvers/geo/package_file_registries_resolver.rb
...graphql/resolvers/geo/package_file_registries_resolver.rb
+9
-0
ee/app/graphql/resolvers/geo/registries_resolver.rb
ee/app/graphql/resolvers/geo/registries_resolver.rb
+52
-0
ee/app/graphql/types/geo/package_file_registry_type.rb
ee/app/graphql/types/geo/package_file_registry_type.rb
+15
-0
ee/app/graphql/types/geo/registry_state_enum.rb
ee/app/graphql/types/geo/registry_state_enum.rb
+15
-0
ee/app/graphql/types/geo/registry_type.rb
ee/app/graphql/types/geo/registry_type.rb
+21
-0
ee/app/models/geo/base_registry.rb
ee/app/models/geo/base_registry.rb
+2
-0
ee/app/models/geo/package_file_registry.rb
ee/app/models/geo/package_file_registry.rb
+4
-0
ee/app/policies/geo/registry_policy.rb
ee/app/policies/geo/registry_policy.rb
+9
-0
ee/lib/gitlab/geo/replicator.rb
ee/lib/gitlab/geo/replicator.rb
+4
-0
ee/spec/graphql/resolvers/geo/package_file_registries_resolver_spec.rb
...ql/resolvers/geo/package_file_registries_resolver_spec.rb
+7
-0
ee/spec/graphql/types/geo/package_file_registry_type_spec.rb
ee/spec/graphql/types/geo/package_file_registry_type_spec.rb
+13
-0
ee/spec/graphql/types/geo/registry_state_enum_spec.rb
ee/spec/graphql/types/geo/registry_state_enum_spec.rb
+11
-0
ee/spec/policies/geo/registry_policy_spec.rb
ee/spec/policies/geo/registry_policy_spec.rb
+25
-0
ee/spec/support/shared_examples/graphql/geo/geo_registries_resolver_shared_examples.rb
...es/graphql/geo/geo_registries_resolver_shared_examples.rb
+65
-0
ee/spec/support/shared_examples/graphql/geo/geo_registry_type_shared_examples.rb
...examples/graphql/geo/geo_registry_type_shared_examples.rb
+13
-0
No files found.
ee/app/graphql/resolvers/geo/package_file_registries_resolver.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
module
Resolvers
module
Geo
class
PackageFileRegistriesResolver
<
BaseResolver
include
RegistriesResolver
end
end
end
ee/app/graphql/resolvers/geo/registries_resolver.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
module
Resolvers
module
Geo
module
RegistriesResolver
extend
ActiveSupport
::
Concern
included
do
def
self
.
replicator_class
Gitlab
::
Geo
::
Replicator
.
for_class_name
(
self
.
name
)
end
delegate
:registry_class
,
:registry_finder_class
,
to: :replicator_class
type
replicator_class
.
graphql_registry_type
,
null:
true
argument
:ids
,
[
GraphQL
::
ID_TYPE
],
required:
false
,
description:
'Filters registries by their ID'
def
resolve
(
ids:
nil
)
return
registry_class
.
none
unless
geo_node_is_current?
registry_finder_class
.
new
(
context
[
:current_user
],
ids:
registry_ids
(
ids
)
).
execute
end
private
def
replicator_class
self
.
class
.
replicator_class
end
def
registry_ids
(
ids
)
ids
&
.
map
{
|
id
|
GlobalID
.
parse
(
id
)
&
.
model_id
}
&
.
compact
end
# We can't query other nodes' tracking databases
def
geo_node_is_current?
geo_node
&
.
current?
end
def
geo_node
object
end
end
end
end
end
ee/app/graphql/types/geo/package_file_registry_type.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
module
Types
module
Geo
# rubocop:disable Graphql/AuthorizeTypes because it is included
class
PackageFileRegistryType
<
BaseObject
include
::
Types
::
Geo
::
RegistryType
graphql_name
'PackageFileRegistry'
description
'Represents the sync and verification state of a package file'
field
:package_file_id
,
GraphQL
::
ID_TYPE
,
null:
false
,
description:
'ID of the PackageFile'
end
end
end
ee/app/graphql/types/geo/registry_state_enum.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
module
Types
module
Geo
class
RegistryStateEnum
<
BaseEnum
graphql_name
'RegistryState'
description
'State of a Geo registry.'
value
'PENDING'
,
value: :pending
,
description:
'Registry waiting to be synced'
value
'STARTED'
,
value: :started
,
description:
'Registry currently syncing'
value
'SYNCED'
,
value: :synced
,
description:
'Registry that is synced'
value
'FAILED'
,
value: :failed
,
description:
'Registry that failed to sync'
end
end
end
ee/app/graphql/types/geo/registry_type.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
module
Types
module
Geo
module
RegistryType
extend
ActiveSupport
::
Concern
included
do
authorize
:read_geo_registry
field
:id
,
GraphQL
::
ID_TYPE
,
null:
false
,
description:
"ID of the
#{
graphql_name
}
"
field
:state
,
Types
::
Geo
::
RegistryStateEnum
,
null:
true
,
method: :state_name
,
description:
"Sync state of the
#{
graphql_name
}
"
field
:retry_count
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
"Number of consecutive failed sync attempts of the
#{
graphql_name
}
"
field
:last_sync_failure
,
GraphQL
::
STRING_TYPE
,
null:
true
,
description:
"Error message during sync of the
#{
graphql_name
}
"
field
:retry_at
,
Types
::
TimeType
,
null:
true
,
description:
"Timestamp after which the
#{
graphql_name
}
should be resynced"
field
:last_synced_at
,
Types
::
TimeType
,
null:
true
,
description:
"Timestamp of the most recent successful sync of the
#{
graphql_name
}
"
field
:created_at
,
Types
::
TimeType
,
null:
true
,
description:
"Timestamp when the
#{
graphql_name
}
was created"
end
end
end
end
ee/app/models/geo/base_registry.rb
View file @
ea81dd8c
...
...
@@ -5,6 +5,8 @@ class Geo::BaseRegistry < Geo::TrackingBase
self
.
abstract_class
=
true
include
GlobalID
::
Identification
def
self
.
pluck_model_ids_in_range
(
range
)
where
(
self
::
MODEL_FOREIGN_KEY
=>
range
).
pluck
(
self
::
MODEL_FOREIGN_KEY
)
end
...
...
ee/app/models/geo/package_file_registry.rb
View file @
ea81dd8c
...
...
@@ -3,6 +3,10 @@
class
Geo::PackageFileRegistry
<
Geo
::
BaseRegistry
include
::
Delay
def
self
.
declarative_policy_class
'Geo::RegistryPolicy'
end
STATE_VALUES
=
{
pending:
0
,
started:
1
,
...
...
ee/app/policies/geo/registry_policy.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
module
Geo
class
RegistryPolicy
<
::
BasePolicy
condition
(
:can_read_all_geo
,
scope: :user
)
{
can?
(
:read_all_geo
,
:global
)
}
rule
{
can_read_all_geo
}.
enable
:read_geo_registry
end
end
ee/lib/gitlab/geo/replicator.rb
View file @
ea81dd8c
...
...
@@ -69,6 +69,10 @@ module Gitlab
const_get
(
"::Geo::
#{
replicable_name
.
camelize
}
RegistryFinder"
,
false
)
end
def
self
.
graphql_registry_type
const_get
(
"::Types::Geo::
#{
replicable_name
.
camelize
}
RegistryType"
,
false
)
end
# Given a `replicable_name`, return the corresponding replicator
#
# @param [String] replicable_name the replicable slug
...
...
ee/spec/graphql/resolvers/geo/package_file_registries_resolver_spec.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
require
'spec_helper'
describe
Resolvers
::
Geo
::
PackageFileRegistriesResolver
do
it_behaves_like
'a Geo registries resolver'
,
:package_file_registry
end
ee/spec/graphql/types/geo/package_file_registry_type_spec.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
require
'spec_helper'
describe
GitlabSchema
.
types
[
'PackageFileRegistry'
]
do
it_behaves_like
'a Geo registry type'
it
'has the expected fields (other than those included in RegistryType)'
do
expected_fields
=
%i[package_file_id]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
).
at_least
end
end
ee/spec/graphql/types/geo/registry_state_enum_spec.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
require
'spec_helper'
describe
GitlabSchema
.
types
[
'RegistryState'
]
do
it
{
expect
(
described_class
.
graphql_name
).
to
eq
(
'RegistryState'
)
}
it
'exposes the correct registry states'
do
expect
(
described_class
.
values
.
keys
).
to
include
(
*
%w[PENDING STARTED SYNCED FAILED]
)
end
end
ee/spec/policies/geo/registry_policy_spec.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
require
'spec_helper'
describe
Geo
::
RegistryPolicy
do
let!
(
:registry
)
{
create
(
:package_file_registry
)
}
subject
(
:policy
)
{
described_class
.
new
(
current_user
,
registry
)
}
context
'when the user is an admin'
do
let
(
:current_user
)
{
create
(
:user
,
:admin
)
}
it
'allows read_geo_registry for any registry'
do
expect
(
policy
).
to
be_allowed
(
:read_geo_registry
)
end
end
context
'when the user is not an admin'
do
let
(
:current_user
)
{
create
(
:user
)
}
it
'disallows read_geo_registry for any registry'
do
expect
(
policy
).
to
be_disallowed
(
:read_geo_registry
)
end
end
end
ee/spec/support/shared_examples/graphql/geo/geo_registries_resolver_shared_examples.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
RSpec
.
shared_examples_for
'a Geo registries resolver'
do
|
registry_factory_name
|
include
GraphqlHelpers
include
EE
::
GeoHelpers
describe
'#resolve'
do
let_it_be
(
:secondary
)
{
create
(
:geo_node
)
}
let_it_be
(
:registry1
)
{
create
(
registry_factory_name
)
}
let_it_be
(
:registry2
)
{
create
(
registry_factory_name
)
}
let_it_be
(
:registry3
)
{
create
(
registry_factory_name
)
}
let
(
:registries
)
{
[
registry1
,
registry2
,
registry3
]
}
let
(
:gql_context
)
{
{
current_user:
current_user
}
}
context
'when the parent object is the current node'
do
before
do
stub_current_geo_node
(
secondary
)
end
context
'when the user has permission to view Geo data'
do
let_it_be
(
:current_user
)
{
create
(
:admin
)
}
context
'when the ids argument is null'
do
it
'returns registries, in order'
do
expect
(
resolve_registries
.
to_a
).
to
eq
(
registries
)
end
end
context
'when the ids argument is present'
do
it
'returns the requested registries, in order'
do
requested_ids
=
[
registry3
.
to_global_id
,
registry1
.
to_global_id
]
args
=
{
ids:
requested_ids
}
expected
=
[
registry1
,
registry3
]
expect
(
resolve_registries
(
args
).
to_a
).
to
eq
(
expected
)
end
end
end
context
'when the user does not have permission to view Geo data'
do
let_it_be
(
:current_user
)
{
create
(
:user
)
}
it
'returns nothing'
do
expect
(
resolve_registries
).
to
be_empty
end
end
end
context
'when the parent object is not the current node'
do
context
'when the user has permission to view Geo data'
do
let_it_be
(
:current_user
)
{
create
(
:admin
)
}
it
"returns nothing, because we can't query other nodes' tracking databases"
do
result
=
resolve
(
described_class
,
obj:
create
(
:geo_node
),
args:
{},
ctx:
gql_context
)
expect
(
result
).
to
be_empty
end
end
end
end
def
resolve_registries
(
args
=
{})
resolve
(
described_class
,
obj:
secondary
,
args:
args
,
ctx:
gql_context
)
end
end
ee/spec/support/shared_examples/graphql/geo/geo_registry_type_shared_examples.rb
0 → 100644
View file @
ea81dd8c
# frozen_string_literal: true
RSpec
.
shared_examples_for
'a Geo registry type'
do
|
registry_factory_name
|
it
{
expect
(
described_class
).
to
require_graphql_authorizations
(
:read_geo_registry
)
}
it
'has the expected fields'
do
expected_fields
=
%i[
id state retry_count last_sync_failure retry_at last_synced_at created_at
]
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
).
at_least
end
end
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