-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-key-management) Add Graphql types and queries for ApiKey mod…
…el (#2743) Added new graphql types and queries for ApiKey model.
- Loading branch information
Showing
11 changed files
with
506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
class ApiKeyResolver < Resolvers::BaseResolver | ||
include AuthenticableApiUser | ||
include RequiredOrganization | ||
|
||
REQUIRED_PERMISSION = 'developers:keys:manage' | ||
|
||
argument :id, ID, required: true, description: 'Uniq ID of the API key' | ||
|
||
description 'Query the API key' | ||
|
||
type Types::ApiKeys::Object, null: false | ||
|
||
def resolve(id: nil) | ||
current_organization.api_keys.find(id) | ||
rescue ActiveRecord::RecordNotFound | ||
not_found_error(resource: 'api_key') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
class ApiKeysResolver < Resolvers::BaseResolver | ||
include AuthenticableApiUser | ||
include RequiredOrganization | ||
|
||
REQUIRED_PERMISSION = 'developers:keys:manage' | ||
|
||
description 'Query the API keys of current organization' | ||
|
||
argument :limit, Integer, required: false | ||
argument :page, Integer, required: false | ||
|
||
type Types::ApiKeys::SanitizedObject.collection_type, null: false | ||
|
||
def resolve(page: nil, limit: nil) | ||
current_organization.api_keys.page(page).limit(limit) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
module ApiKeys | ||
class Object < Types::BaseObject | ||
graphql_name 'ApiKey' | ||
|
||
field :id, ID, null: false | ||
field :value, String, null: false | ||
|
||
field :created_at, GraphQL::Types::ISO8601DateTime, null: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
module ApiKeys | ||
class SanitizedObject < Object | ||
graphql_name 'SanitizedApiKey' | ||
|
||
def value | ||
"••••••••" + object.value.last(3) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.