Skip to content

Commit c917836

Browse files
committed
feat: changes from code review
1 parent 207bff1 commit c917836

12 files changed

Lines changed: 90 additions & 49 deletions

File tree

app/graphql/types/query_type.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class QueryType < Types::BaseObject
4343
field :users, Types::UserType.connection_type, null: false, description: 'Find users'
4444

4545
field :global_runtimes, Types::RuntimeType.connection_type, null: false, description: 'Find runtimes'
46-
field :velorum_models, [Types::VelorumModelType], null: false, description: 'Find models available through Velorum'
46+
field :velorum, Types::VelorumType, null: false, description: 'Get Velorum information'
4747

4848
def application
4949
{}
@@ -87,8 +87,8 @@ def global_runtimes
8787
Runtime.where(namespace: nil)
8888
end
8989

90-
def velorum_models
91-
::Velorum::ModelsService.new.execute
90+
def velorum
91+
{}
9292
end
9393

9494
def current_authentication

app/graphql/types/velorum_type.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
module Types
4+
class VelorumType < Types::BaseObject
5+
description 'Represents Velorum integration information'
6+
7+
field :enabled, Boolean, null: false, description: 'Whether Velorum is enabled'
8+
field :models, [Types::VelorumModelType], null: false, description: 'Find models available through Velorum'
9+
10+
def enabled
11+
config[:enabled]
12+
end
13+
14+
def models
15+
::Velorum::ModelsService.new(config: config).execute
16+
end
17+
18+
private
19+
20+
def config
21+
Sagittarius::Configuration.config[:velorum]
22+
end
23+
end
24+
end

app/services/velorum/models_service.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ def initialize(client: nil, config: Sagittarius::Configuration.config[:velorum])
88
end
99

1010
def execute
11-
unless config[:enabled]
12-
raise GraphQL::ExecutionError.new(
13-
'Velorum is disabled',
14-
extensions: { code: 'VELORUM_DISABLED' }
15-
)
16-
end
11+
return [] unless config[:enabled]
1712

1813
client.models.models
1914
end

config/sagittarius.example.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ rails:
2929
velorum:
3030
enabled: true
3131
host: 'localhost:50052'
32-
security_token:
32+
jwt_secret:
3333
jwt_ttl_minutes: 8
3434

3535
application_setting_overrides: {}

docs/graphql/object/query.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Root Query type
1414
| `globalRuntimes` | [`RuntimeConnection!`](../object/runtimeconnection.md) | Find runtimes |
1515
| `organizations` | [`OrganizationConnection!`](../object/organizationconnection.md) | Find organizations |
1616
| `users` | [`UserConnection!`](../object/userconnection.md) | Find users |
17-
| `velorumModels` | [`[VelorumModel!]!`](../object/velorummodel.md) | Find models available through Velorum |
17+
| `velorum` | [`Velorum!`](../object/velorum.md) | Get Velorum information |
1818

1919
## Fields with arguments
2020

docs/graphql/object/velorum.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Velorum
3+
---
4+
5+
Represents Velorum integration information
6+
7+
## Fields without arguments
8+
9+
| Name | Type | Description |
10+
|------|------|-------------|
11+
| `enabled` | [`Boolean!`](../scalar/boolean.md) | Whether Velorum is enabled |
12+
| `models` | [`[VelorumModel!]!`](../object/velorummodel.md) | Find models available through Velorum |

lib/sagittarius/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def self.defaults
5555
velorum: {
5656
enabled: true,
5757
host: 'localhost:50052',
58-
security_token: nil,
58+
jwt_secret: nil,
5959
jwt_ttl_minutes: 8,
6060
},
6161
application_setting_overrides: {},

lib/sagittarius/velorum/client.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
# frozen_string_literal: true
22

3-
require 'base64'
4-
require 'json'
5-
require 'openssl'
6-
73
module Sagittarius
84
module Velorum
95
class Client
106
def initialize(
117
host: Sagittarius::Configuration.config[:velorum][:host],
12-
security_token: ENV.fetch('VELORUM_SECURITY_TOKEN', Sagittarius::Configuration.config[:velorum][:security_token]),
8+
jwt_secret: Sagittarius::Configuration.config[:velorum][:jwt_secret],
139
jwt_ttl_minutes: Sagittarius::Configuration.config[:velorum][:jwt_ttl_minutes]
1410
)
1511
@host = host
16-
@security_token = security_token
12+
@jwt_secret = jwt_secret
1713
@jwt_ttl_minutes = jwt_ttl_minutes
1814
end
1915

@@ -23,7 +19,7 @@ def models
2319

2420
private
2521

26-
attr_reader :host, :security_token, :jwt_ttl_minutes
22+
attr_reader :host, :jwt_secret, :jwt_ttl_minutes
2723

2824
def stub
2925
@stub ||= Tucana::Velorum::InfoService::Stub.new(host, :this_channel_is_insecure)
@@ -36,9 +32,7 @@ def authentication_metadata
3632
end
3733

3834
def jwt
39-
if security_token.to_s.empty?
40-
raise ArgumentError, 'VELORUM_SECURITY_TOKEN or velorum.security_token must be configured'
41-
end
35+
raise ArgumentError, 'velorum.jwt_secret must be configured' if jwt_secret.to_s.empty?
4236

4337
header = {
4438
alg: 'HS256',
@@ -50,7 +44,7 @@ def jwt
5044
exp: now + jwt_ttl_minutes.to_i.minutes.to_i,
5145
}
5246
body = [header, payload].map { |part| base64_url_encode(part.to_json) }.join('.')
53-
signature = OpenSSL::HMAC.digest('SHA256', security_token, body)
47+
signature = OpenSSL::HMAC.digest('SHA256', jwt_secret, body)
5448

5549
"#{body}.#{base64_url_encode(signature)}"
5650
end

spec/graphql/types/query_type_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
users
1515
user
1616
global_runtimes
17-
velorum_models
17+
velorum
1818
namespace
1919
]
2020
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe Types::VelorumType do
6+
let(:fields) do
7+
%w[
8+
enabled
9+
models
10+
]
11+
end
12+
13+
it { expect(described_class.graphql_name).to eq('Velorum') }
14+
it { expect(described_class).to have_graphql_fields(fields) }
15+
end

0 commit comments

Comments
 (0)