Skip to content

Commit 207bff1

Browse files
committed
feat: made velorum de-/activatable
1 parent fd95c38 commit 207bff1

4 files changed

Lines changed: 36 additions & 2 deletions

File tree

app/services/velorum/models_service.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,28 @@
22

33
module Velorum
44
class ModelsService
5-
def initialize(client: Sagittarius::Velorum::Client.new)
5+
def initialize(client: nil, config: Sagittarius::Configuration.config[:velorum])
66
@client = client
7+
@config = config
78
end
89

910
def execute
11+
unless config[:enabled]
12+
raise GraphQL::ExecutionError.new(
13+
'Velorum is disabled',
14+
extensions: { code: 'VELORUM_DISABLED' }
15+
)
16+
end
17+
1018
client.models.models
1119
end
1220

1321
private
1422

15-
attr_reader :client
23+
attr_reader :config
24+
25+
def client
26+
@client ||= Sagittarius::Velorum::Client.new
27+
end
1628
end
1729
end

config/sagittarius.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rails:
2727
secret_key_base: MVMD6CtQwEWrQ28TdokQakbG2FG5abOn
2828

2929
velorum:
30+
enabled: true
3031
host: 'localhost:50052'
3132
security_token:
3233
jwt_ttl_minutes: 8

lib/sagittarius/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def self.defaults
5353
secret_key_base: 'MVMD6CtQwEWrQ28TdokQakbG2FG5abOn',
5454
},
5555
velorum: {
56+
enabled: true,
5657
host: 'localhost:50052',
5758
security_token: nil,
5859
jwt_ttl_minutes: 8,

spec/requests/graphql/query/velorum_models_query_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,24 @@
6363
)
6464
expect(client).to have_received(:models)
6565
end
66+
67+
context 'when Velorum is disabled' do
68+
before do
69+
allow(Sagittarius::Configuration).to receive(:config)
70+
.and_return(velorum: { enabled: false })
71+
end
72+
73+
it 'returns a GraphQL error without creating a Velorum client' do
74+
post_graphql(query)
75+
76+
expect(graphql_data_at(:velorum_models)).to be_nil
77+
expect(graphql_errors).to contain_exactly(
78+
a_hash_including(
79+
'message' => 'Velorum is disabled',
80+
'extensions' => a_hash_including('code' => 'VELORUM_DISABLED')
81+
)
82+
)
83+
expect(Sagittarius::Velorum::Client).not_to have_received(:new)
84+
end
85+
end
6686
end

0 commit comments

Comments
 (0)