Skip to content

Commit 0aac773

Browse files
authored
refactor!: dont use keys from env (#31)
after thinking about it more, I think it is more solid to persist the keys to the config file, as before. This avoids any potential for interfering with existing environment variables. Signed-off-by: Nico Braun <[email protected]>
1 parent 595bca9 commit 0aac773

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

action.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ const { tests } = require("./src/providers");
66
const { RunOptions, RunTarget } = require("github-action-ts-run-api");
77

88
(async () => {
9-
for (const [provider, { giveInputs, wantLines }] of Object.entries(tests)) {
10-
console.log(`\n---\nTesting provider: ${provider}`);
9+
for (const [name, { giveInputs, wantLines }] of Object.entries(tests)) {
10+
console.log(`\n---\nTesting provider: ${name}`);
1111

1212
const target = RunTarget.mainJs("action.yml");
1313
const options = RunOptions.create()
1414
.setFakeFsOptions({ rmFakedTempDirAfterRun: false })
15-
.setInputs({ ...giveInputs, provider });
15+
.setInputs(giveInputs);
1616

1717
const res = await target.run(options);
1818
try {
@@ -21,7 +21,7 @@ const { RunOptions, RunTarget } = require("github-action-ts-run-api");
2121
const b = readFileSync(join(res.tempDirPath, "s3cmd.conf"));
2222
const data = b.toString();
2323
for (const line of wantLines) {
24-
assert.ok(data.includes(line), `${provider}: missing line: ${line}`);
24+
assert.ok(data.includes(line), `${name}: missing line: ${line}`);
2525
}
2626
} finally {
2727
res.cleanUpFakedDirs();

dist/index.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -24937,9 +24937,9 @@ function write(path, lines) {
2493724937
}
2493824938
}
2493924939

24940-
function configure(provider) {
24940+
function configure(settings, access_key, secret_key) {
2494124941
const path = process.env.S3CMD_CONFIG || join(homedir(), ".s3cfg");
24942-
return write(path, build(provider));
24942+
return write(path, build({ ...settings, access_key, secret_key }));
2494324943
}
2494424944

2494524945
module.exports = {
@@ -24972,6 +24972,7 @@ exports.aws = ({ region = "US" }) => ({
2497224972

2497324973
tests.aws = {
2497424974
giveInputs: {
24975+
provider: "aws",
2497524976
region: "us-east-1",
2497624977
},
2497724978
wantLines: [
@@ -24991,6 +24992,7 @@ exports.digitalocean = ({ region = "nyc3" }) => ({
2499124992

2499224993
tests.digitalocean = {
2499324994
giveInputs: {
24995+
provider: "digitalocean",
2499424996
region: "nyc3",
2499524997
},
2499624998
wantLines: [
@@ -25010,6 +25012,7 @@ exports.linode = ({ region = "eu-central-1" }) => ({
2501025012

2501125013
tests.linode = {
2501225014
giveInputs: {
25015+
provider: "linode",
2501325016
region: "us-central-1",
2501425017
},
2501525018
wantLines: [
@@ -25029,6 +25032,7 @@ exports.scaleway = ({ region = "fr-par" }) => ({
2502925032

2503025033
tests.scaleway = {
2503125034
giveInputs: {
25035+
provider: "scaleway",
2503225036
region: "fr-par",
2503325037
},
2503425038
wantLines: [
@@ -25048,6 +25052,7 @@ exports.cloudflare = ({ account_id = "", region = "auto" }) => ({
2504825052

2504925053
tests.cloudflare = {
2505025054
giveInputs: {
25055+
provider: "cloudflare",
2505125056
account_id: "your_account_id",
2505225057
region: "auto",
2505325058
},
@@ -25068,12 +25073,14 @@ exports.vultr = ({ region = "ewr1" }) => ({
2506825073

2506925074
tests.vultr = {
2507025075
giveInputs: {
25076+
provider: "vultr",
2507125077
region: "ewr1",
2507225078
},
2507325079
wantLines: [
2507425080
"bucket_location = ewr1",
2507525081
"host_base = ewr1.vultrobjects.com",
2507625082
"host_bucket = %(bucket)s.ewr1.vultrobjects.com",
25083+
"website_endpoint = ",
2507725084
],
2507825085
};
2507925086

@@ -25086,6 +25093,7 @@ exports.clevercloud = ({ region = "US" }) => ({
2508625093

2508725094
tests.clevercloud = {
2508825095
giveInputs: {
25096+
provider: "clevercloud",
2508925097
region: "US",
2509025098
},
2509125099
wantLines: [
@@ -25105,29 +25113,34 @@ exports.hcloud = ({ region = "fsn1" }) => ({
2510525113

2510625114
tests.hcloud = {
2510725115
giveInputs: {
25116+
provider: "hcloud",
2510825117
region: "fsn1",
2510925118
},
2511025119
wantLines: [
2511125120
"bucket_location = fsn1",
2511225121
"host_base = fsn1.your-objectstorage.com",
2511325122
"host_bucket = %(bucket)s.fsn1.your-objectstorage.com",
25123+
"website_endpoint = ",
2511425124
],
2511525125
};
2511625126

2511725127
exports.synologyc2 = ({ region = "us-001" }) => ({
2511825128
bucket_location: region,
2511925129
host_base: `${region}.s3.synologyc2.net`,
25120-
host_bucket: ``,
25130+
host_bucket: "",
2512125131
website_endpoint: "",
2512225132
});
2512325133

2512425134
tests.synologyc2 = {
2512525135
giveInputs: {
25136+
provider: "synologyc2",
2512625137
region: "us-001",
2512725138
},
2512825139
wantLines: [
2512925140
"bucket_location = us-001",
2513025141
"host_base = us-001.s3.synologyc2.net",
25142+
"host_bucket = ",
25143+
"website_endpoint = ",
2513125144
],
2513225145
};
2513325146

@@ -25140,12 +25153,14 @@ exports.wasabi = ({ region = "ap-southeast-1" }) => ({
2514025153

2514125154
tests.wasabi = {
2514225155
giveInputs: {
25156+
provider: "wasabi",
2514325157
region: "ap-southeast-1",
2514425158
},
2514525159
wantLines: [
2514625160
"bucket_location = ap-southeast-1",
2514725161
"host_base = s3.ap-southeast-1.wasabisys.com",
2514825162
"host_bucket = %(bucket)s.s3.ap-southeast-1.wasabisys.com",
25163+
"website_endpoint = ",
2514925164
],
2515025165
};
2515125166

@@ -25158,12 +25173,14 @@ exports.yandex = ({ region = "ru-central1" }) => ({
2515825173

2515925174
tests.yandex = {
2516025175
giveInputs: {
25176+
provider: "yandex",
2516125177
region: "ru-central1",
2516225178
},
2516325179
wantLines: [
2516425180
"bucket_location = ru-central1",
2516525181
"host_base = storage.yandexcloud.net",
2516625182
"host_bucket = %(bucket)s.storage.yandexcloud.net",
25183+
"website_endpoint = ",
2516725184
],
2516825185
};
2516925186

@@ -27143,19 +27160,13 @@ if (process.env.RUNNER_TEMP) {
2714327160
core.debug(`S3CMD_CONFIG=${process.env.S3CMD_CONFIG}`);
2714427161
}
2714527162

27146-
// expose the access and secret key as github action variables.
27147-
// registering them as secret, just to be sure. normally they should be
27148-
// be registered already. registering leads to masking in logs
27149-
core.setSecret(core.getInput("access_key"));
27150-
core.setSecret(core.getInput("secret_key"));
27151-
core.exportVariable("AWS_ACCESS_KEY", core.getInput("access_key"));
27152-
core.exportVariable("AWS_SECRET_KEY", core.getInput("secret_key"));
27153-
2715427163
configure(
2715527164
providers[core.getInput("provider")]({
2715627165
region: core.getInput("region"),
2715727166
account_id: core.getInput("account_id"),
2715827167
}),
27168+
core.getInput("access_key"),
27169+
core.getInput("secret_key"),
2715927170
);
2716027171

2716127172
return 0;

src/config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ function write(path, lines) {
1616
}
1717
}
1818

19-
function configure(provider) {
19+
function configure(settings, access_key, secret_key) {
2020
const path = process.env.S3CMD_CONFIG || join(homedir(), ".s3cfg");
21-
return write(path, build(provider));
21+
return write(path, build({ ...settings, access_key, secret_key }));
2222
}
2323

2424
module.exports = {

src/index.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,13 @@ if (process.env.RUNNER_TEMP) {
4141
core.debug(`S3CMD_CONFIG=${process.env.S3CMD_CONFIG}`);
4242
}
4343

44-
// expose the access and secret key as github action variables.
45-
// registering them as secret, just to be sure. normally they should be
46-
// be registered already. registering leads to masking in logs
47-
core.setSecret(core.getInput("access_key"));
48-
core.setSecret(core.getInput("secret_key"));
49-
core.exportVariable("AWS_ACCESS_KEY", core.getInput("access_key"));
50-
core.exportVariable("AWS_SECRET_KEY", core.getInput("secret_key"));
51-
5244
configure(
5345
providers[core.getInput("provider")]({
5446
region: core.getInput("region"),
5547
account_id: core.getInput("account_id"),
5648
}),
49+
core.getInput("access_key"),
50+
core.getInput("secret_key"),
5751
);
5852

5953
return 0;

src/providers.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports.aws = ({ region = "US" }) => ({
1616

1717
tests.aws = {
1818
giveInputs: {
19+
provider: "aws",
1920
region: "us-east-1",
2021
},
2122
wantLines: [
@@ -35,6 +36,7 @@ exports.digitalocean = ({ region = "nyc3" }) => ({
3536

3637
tests.digitalocean = {
3738
giveInputs: {
39+
provider: "digitalocean",
3840
region: "nyc3",
3941
},
4042
wantLines: [
@@ -54,6 +56,7 @@ exports.linode = ({ region = "eu-central-1" }) => ({
5456

5557
tests.linode = {
5658
giveInputs: {
59+
provider: "linode",
5760
region: "us-central-1",
5861
},
5962
wantLines: [
@@ -73,6 +76,7 @@ exports.scaleway = ({ region = "fr-par" }) => ({
7376

7477
tests.scaleway = {
7578
giveInputs: {
79+
provider: "scaleway",
7680
region: "fr-par",
7781
},
7882
wantLines: [
@@ -92,6 +96,7 @@ exports.cloudflare = ({ account_id = "", region = "auto" }) => ({
9296

9397
tests.cloudflare = {
9498
giveInputs: {
99+
provider: "cloudflare",
95100
account_id: "your_account_id",
96101
region: "auto",
97102
},
@@ -112,12 +117,14 @@ exports.vultr = ({ region = "ewr1" }) => ({
112117

113118
tests.vultr = {
114119
giveInputs: {
120+
provider: "vultr",
115121
region: "ewr1",
116122
},
117123
wantLines: [
118124
"bucket_location = ewr1",
119125
"host_base = ewr1.vultrobjects.com",
120126
"host_bucket = %(bucket)s.ewr1.vultrobjects.com",
127+
"website_endpoint = ",
121128
],
122129
};
123130

@@ -130,6 +137,7 @@ exports.clevercloud = ({ region = "US" }) => ({
130137

131138
tests.clevercloud = {
132139
giveInputs: {
140+
provider: "clevercloud",
133141
region: "US",
134142
},
135143
wantLines: [
@@ -149,29 +157,34 @@ exports.hcloud = ({ region = "fsn1" }) => ({
149157

150158
tests.hcloud = {
151159
giveInputs: {
160+
provider: "hcloud",
152161
region: "fsn1",
153162
},
154163
wantLines: [
155164
"bucket_location = fsn1",
156165
"host_base = fsn1.your-objectstorage.com",
157166
"host_bucket = %(bucket)s.fsn1.your-objectstorage.com",
167+
"website_endpoint = ",
158168
],
159169
};
160170

161171
exports.synologyc2 = ({ region = "us-001" }) => ({
162172
bucket_location: region,
163173
host_base: `${region}.s3.synologyc2.net`,
164-
host_bucket: ``,
174+
host_bucket: "",
165175
website_endpoint: "",
166176
});
167177

168178
tests.synologyc2 = {
169179
giveInputs: {
180+
provider: "synologyc2",
170181
region: "us-001",
171182
},
172183
wantLines: [
173184
"bucket_location = us-001",
174185
"host_base = us-001.s3.synologyc2.net",
186+
"host_bucket = ",
187+
"website_endpoint = ",
175188
],
176189
};
177190

@@ -184,12 +197,14 @@ exports.wasabi = ({ region = "ap-southeast-1" }) => ({
184197

185198
tests.wasabi = {
186199
giveInputs: {
200+
provider: "wasabi",
187201
region: "ap-southeast-1",
188202
},
189203
wantLines: [
190204
"bucket_location = ap-southeast-1",
191205
"host_base = s3.ap-southeast-1.wasabisys.com",
192206
"host_bucket = %(bucket)s.s3.ap-southeast-1.wasabisys.com",
207+
"website_endpoint = ",
193208
],
194209
};
195210

@@ -202,11 +217,13 @@ exports.yandex = ({ region = "ru-central1" }) => ({
202217

203218
tests.yandex = {
204219
giveInputs: {
220+
provider: "yandex",
205221
region: "ru-central1",
206222
},
207223
wantLines: [
208224
"bucket_location = ru-central1",
209225
"host_base = storage.yandexcloud.net",
210226
"host_bucket = %(bucket)s.storage.yandexcloud.net",
227+
"website_endpoint = ",
211228
],
212229
};

0 commit comments

Comments
 (0)