fix(shorebird_code_push_api): secrets access (#18)

This commit is contained in:
Felix Angelov
2023-03-06 12:01:06 -06:00
committed by GitHub
parent d2a5cccd3a
commit 196e4704ac
3 changed files with 8 additions and 9 deletions
@@ -16,16 +16,15 @@ Future<void> main() async {
..post('/api/v1/releases', uploadReleaseHandler)
..get('/api/v1/engines/<revision>', downloadEngineHandler);
final apiKeys = json.decode(
Platform.environment['CODE_PUSH_API_KEYS'] ?? '[]',
) as List;
final gcpKey = Platform.environment['GCP_SA'] ?? '';
final gcpKey = Platform.environment['GCP_SA']!;
final apiKeys =
(json.decode(Platform.environment['CODE_PUSH_API_KEYS']!) as List)
.cast<String>();
final handler = const Pipeline()
.addMiddleware(versionStoreProvider)
.addMiddleware(httpClientProvider(gcpKey))
.addMiddleware(apiKeyVerifier(keys: apiKeys.cast<String>()))
.addMiddleware(apiKeyVerifier(apiKeys))
.addHandler(router.call);
final server = await shelf_io.serve(
@@ -2,7 +2,7 @@ import 'dart:io';
import 'package:shelf/shelf.dart';
Middleware apiKeyVerifier({List<String> keys = const []}) {
Middleware apiKeyVerifier([List<String> keys = const []]) {
return (handler) {
return (request) async {
final apiKey = request.headers['x-api-key'];
@@ -20,7 +20,7 @@ void main() {
test('returns 401 if key is invalid', () async {
final handler = const Pipeline()
.addMiddleware(apiKeyVerifier(keys: keys))
.addMiddleware(apiKeyVerifier(keys))
.addHandler((_) => Response.ok('OK'));
final request = Request(
@@ -34,7 +34,7 @@ void main() {
test('returns 200 if key is valid', () async {
final handler = const Pipeline()
.addMiddleware(apiKeyVerifier(keys: keys))
.addMiddleware(apiKeyVerifier(keys))
.addHandler((_) => Response.ok('OK'));
final request = Request(