Skip to content

Commit d27b5a5

Browse files
committed
✨ Allow to use STRAVA_CLIENT_SECRET_FILE and STRAVA_REFRESH_TOKEN_FILE instead of STRAVA_CLIENT_SECRET and STRAVA_REFRESH_TOKEN
1 parent 280ef2e commit d27b5a5

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

config/services.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ parameters:
77
env(APP_DEBUG): 0
88
env(LOCK_DSN): 'flock'
99
env(TZ): ''
10+
_strava_refresh_token: '%env(string:STRAVA_REFRESH_TOKEN)%'
11+
_strava_client_secret: '%env(string:STRAVA_CLIENT_SECRET)%'
1012

1113
services:
1214
# default configuration for services in *this* file
@@ -156,11 +158,11 @@ services:
156158

157159
App\Domain\Strava\StravaClientSecret:
158160
factory: [ null, 'fromString' ]
159-
arguments: ['%env(string:STRAVA_CLIENT_SECRET)%']
161+
arguments: ['%env(default:_strava_client_secret:file:STRAVA_CLIENT_SECRET_FILE)%']
160162

161163
App\Domain\Strava\StravaRefreshToken:
162164
factory: [ null, 'fromString' ]
163-
arguments: ['%env(string:STRAVA_REFRESH_TOKEN)%']
165+
arguments: ['%env(default:_strava_refresh_token:file:STRAVA_REFRESH_TOKEN_FILE)%']
164166

165167
App\Domain\Athlete\AthleteBirthDate:
166168
factory: [ null, 'fromString' ]

docs/getting-started/installation.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ TZ=Etc/GMT
109109
# CADDY_LOG_LEVEL=ERROR
110110
```
111111

112+
> [!IMPORTANT] Instead of passing secrets directly via the `STRAVA_CLIENT_SECRET` and `STRAVA_REFRESH_TOKEN` environment variables, you can use [Docker Compose secrets](https://docs.docker.com/compose/how-tos/use-secrets/).
113+
>
114+
> Define `STRAVA_CLIENT_SECRET_FILE` and `STRAVA_REFRESH_TOKEN_FILE` to point to the secret files (typically located in /run/secrets/). When the standard environment variables are not set, the application will automatically read the values from these files.
115+
>
116+
> This approach is recommended when running the application with Docker Compose, as it avoids exposing sensitive values in environment variables.
117+
112118
## config.yaml
113119

114120
[include](../configuration/config-yaml-example.md ':include')

src/Console/Debug/DebugEnvironmentConsoleCommand.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4545
->setRows([
4646
['APP_VERSION', AppVersion::getSemanticVersion()],
4747
['STRAVA_CLIENT_ID', $autoRedactSensitiveInfo ? $redactedString : getenv('STRAVA_CLIENT_ID')],
48-
['STRAVA_CLIENT_SECRET', $autoRedactSensitiveInfo ? $redactedString : getenv('STRAVA_CLIENT_SECRET')],
49-
['STRAVA_REFRESH_TOKEN', $autoRedactSensitiveInfo ? $redactedString : getenv('STRAVA_REFRESH_TOKEN')],
48+
['STRAVA_CLIENT_SECRET', $autoRedactSensitiveInfo ? $redactedString : $this->getenvOrFile('STRAVA_CLIENT_SECRET')],
49+
['STRAVA_REFRESH_TOKEN', $autoRedactSensitiveInfo ? $redactedString : $this->getenvOrFile('STRAVA_REFRESH_TOKEN')],
5050
['TZ', getenv('TZ')],
5151
]);
5252
$table->render();
@@ -66,4 +66,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6666

6767
return Command::SUCCESS;
6868
}
69+
70+
protected function getenvOrFile(string $var): ?string
71+
{
72+
$value = getenv($var);
73+
if (false !== $value && '' !== $value) {
74+
return $value;
75+
}
76+
77+
$file = getenv($var.'_FILE');
78+
if ($file && is_readable($file)) {
79+
return trim((string) file_get_contents($file));
80+
}
81+
82+
return null;
83+
}
6984
}

0 commit comments

Comments
 (0)