Skip to content

Commit

Permalink
Add param for key for ganui api. (#3179)
Browse files Browse the repository at this point in the history
* -

* Update common_server.dart
  • Loading branch information
polina-c authored Mar 5, 2025
1 parent 117067f commit eae13fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
30 changes: 26 additions & 4 deletions pkgs/dart_services/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ Future<void> main(List<String> args) async {
'The name of the Cloud Storage bucket for compilation artifacts.',
defaultsTo: 'nnbd_artifacts',
)
..addOption(
'genui-key',
valueHelp: 'key',
help:
'Genui api key to be passed with request. '
'Not needed for hosted instance, just for local development.',
defaultsTo: null,
)
..addFlag(
'help',
abbr: 'h',
Expand Down Expand Up @@ -71,6 +79,7 @@ Future<void> main(List<String> args) async {
final redisServerUri = results['redis-url'] as String?;
final storageBucket =
results['storage-bucket'] as String? ?? 'nnbd_artifacts';
final genUiKey = results['genui-key'] as String?;

final cloudRunEnvVars = Platform.environment.entries
.where((entry) => entry.key.startsWith('K_'))
Expand All @@ -91,6 +100,7 @@ Starting dart-services:
sdk,
redisServerUri,
storageBucket,
genUiKey: genUiKey,
);

_logger.info('Listening on port ${server.port}');
Expand All @@ -101,12 +111,14 @@ class EndpointsServer {
int port,
Sdk sdk,
String? redisServerUri,
String storageBucket,
) async {
String storageBucket, {
String? genUiKey,
}) async {
final endpointsServer = EndpointsServer._(
sdk,
redisServerUri,
storageBucket,
genUiKey: genUiKey,
);
await endpointsServer._init();

Expand All @@ -125,7 +137,12 @@ class EndpointsServer {

late final CommonServerApi commonServer;

EndpointsServer._(Sdk sdk, String? redisServerUri, String storageBucket) {
EndpointsServer._(
Sdk sdk,
String? redisServerUri,
String storageBucket, {
String? genUiKey,
}) {
// The name of the Cloud Run revision being run, for more detail please see:
// https://cloud.google.com/run/docs/reference/container-contract#env-vars
final serverVersion = Platform.environment['K_REVISION'];
Expand All @@ -136,7 +153,12 @@ class EndpointsServer {
: RedisCache(redisServerUri, sdk, serverVersion);

commonServer = CommonServerApi(
CommonServerImpl(sdk, cache, storageBucket: storageBucket),
CommonServerImpl(
sdk,
cache,
storageBucket: storageBucket,
genUiKey: genUiKey,
),
);

final pipeline = const Pipeline()
Expand Down
1 change: 1 addition & 0 deletions pkgs/dart_services/lib/src/common_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CommonServerImpl {
this.sdk,
this.cache, {
this.storageBucket = 'nnbd_artifacts',
genUiKey,
});

Future<void> init() async {
Expand Down

0 comments on commit eae13fd

Please sign in to comment.