Skip to content

Commit 1078024

Browse files
committed
Update environment variable handling
1 parent cfa0537 commit 1078024

5 files changed

Lines changed: 35 additions & 10 deletions

File tree

bin/discord

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ require_relative '../lib/pyxis'
55
require 'discordrb'
66
require 'discordrb/webhooks'
77

8-
token = File.read(ENV.fetch('PYXIS_DC_RELEASE_TOOLS_TOKEN'))
9-
bot = Discordrb::Bot.new(token: token, intents: %i[servers])
8+
bot = Discordrb::Bot.new(token: Pyxis::Environment.discord_bot_token, intents: %i[servers])
109

1110
def build_command(name, description)
1211
{

lib/pyxis/environment.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module Pyxis
4+
module Environment
5+
module_function
6+
7+
def discord_bot_token
8+
File.read(ENV.fetch('PYXIS_DC_RELEASE_TOOLS_TOKEN'))
9+
end
10+
11+
def github_release_tools_private_key
12+
File.read(ENV.fetch('PYXIS_GH_RELEASE_TOOLS_PRIVATE_KEY'))
13+
end
14+
15+
def github_release_tools_approver_private_key
16+
File.read(ENV.fetch('PYXIS_GH_RELEASE_TOOLS_APPROVER_PRIVATE_KEY'))
17+
end
18+
19+
def gitlab_release_tools_token
20+
File.read(ENV.fetch('PYXIS_GL_RELEASE_TOOLS_PRIVATE_TOKEN'))
21+
end
22+
23+
def dry_run
24+
ENV.fetch('DRY_RUN', 'true').downcase
25+
end
26+
end
27+
end

lib/pyxis/github_client.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ class GithubClient
88
release_tools: {
99
app_id: 857194,
1010
installation_id: 69940866,
11-
private_key_location: ENV.fetch('PYXIS_GH_RELEASE_TOOLS_PRIVATE_KEY'),
11+
private_key: Pyxis::Environment.github_release_tools_private_key,
1212
},
1313
release_tools_approver: {
1414
app_id: 1373592,
1515
installation_id: 70116032,
16-
private_key_location: ENV.fetch('PYXIS_GH_RELEASE_TOOLS_APPROVER_PRIVATE_KEY'),
16+
private_key: Pyxis::Environment.github_release_tools_approver_private_key,
1717
},
1818
}.freeze
1919

@@ -33,7 +33,7 @@ def without_auto_pagination(octokit)
3333

3434
def create_installation_access_token(instance, options = {})
3535
config = CLIENT_CONFIGS[instance]
36-
global_client = Octokit::Client.new(bearer_token: create_jwt(config[:private_key_location], config[:app_id]))
36+
global_client = Octokit::Client.new(bearer_token: create_jwt(config[:private_key], config[:app_id]))
3737
logger.debug('Created JWT for client', app: global_client.app.slug)
3838
installation_token = Pyxis::GlobalStatus.with_faraday_dry_run_bypass do
3939
global_client.create_app_installation_access_token(config[:installation_id], options)
@@ -54,8 +54,7 @@ def create_octokit(instance)
5454
Octokit::Client.new(bearer_token: installation_token[:token])
5555
end
5656

57-
def create_jwt(private_key_path, client_id)
58-
private_pem = File.read(private_key_path)
57+
def create_jwt(private_pem, client_id)
5958
private_key = OpenSSL::PKey::RSA.new(private_pem)
6059

6160
payload = {

lib/pyxis/gitlab_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class GitlabClient
88

99
CLIENT_CONFIGS = {
1010
release_tools: {
11-
private_token: ENV.fetch('PYXIS_GL_RELEASE_TOOLS_PRIVATE_TOKEN'),
11+
private_token: Pyxis::Environment.gitlab_release_tools_token,
1212
user_id: 20643824,
1313
},
1414
}.freeze
@@ -24,7 +24,7 @@ def self.create_client(instance)
2424
options = {
2525
url: GITLAB_URL,
2626
headers: {
27-
'Private-Token': File.read(client_config[:private_token]),
27+
'Private-Token': client_config[:private_token],
2828
},
2929
}
3030

lib/pyxis/global_status.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module GlobalStatus
55
module_function
66

77
def dry_run?
8-
ENV.fetch('DRY_RUN', 'true').downcase == 'true'
8+
Pyxis::Environment.dry_run == 'true'
99
end
1010

1111
def with_faraday_dry_run_bypass

0 commit comments

Comments
 (0)