Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gel rename #46

Draft
wants to merge 4 commits into
base: server-6-updates
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ on:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
# Skip tests when doing a release to avoid the workflow race
# when the release PR gets merged by the bot.
if: needs.prep.outputs.version == 0
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.edgedb-version == 'nightly' }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
Expand Down
101 changes: 50 additions & 51 deletions lib/src/connect_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,26 +250,26 @@ class ResolvedConnectConfig {
'invalid tlsSecurity value, must be of type TLSSecurity');
}
final origTlsSec = tlsSec;
final clientSecurity = getEnvVar('EDGEDB_CLIENT_SECURITY');
if (clientSecurity != null) {
final clientSecurity = getPrefixedEnvVar('CLIENT_SECURITY');
if (clientSecurity.value != null) {
if (!{'default', 'insecure_dev_mode', 'strict'}
.contains(clientSecurity)) {
.contains(clientSecurity.value)) {
throw InterfaceError(
"invalid EDGEDB_CLIENT_SECURITY value: '$clientSecurity', "
"invalid ${clientSecurity.source} value: '$clientSecurity', "
"must be one of 'default', 'insecure_dev_mode' or 'strict'");
}
if (clientSecurity == 'insecure_dev_mode') {
if (clientSecurity.value == 'insecure_dev_mode') {
if (tlsSec == TLSSecurity.defaultSecurity) {
tlsSec = TLSSecurity.insecure;
}
} else if (clientSecurity == 'strict') {
} else if (clientSecurity.value == 'strict') {
if (tlsSec == TLSSecurity.insecure ||
tlsSec == TLSSecurity.noHostVerification) {
throw InterfaceError(
"'tlsSecurity' value (${tlsSec.value}) conflicts with "
"EDGEDB_CLIENT_SECURITY value ($clientSecurity), "
"${clientSecurity.source} value ($clientSecurity), "
"'tlsSecurity' value cannot be lower than security level "
"set by EDGEDB_CLIENT_SECURITY");
"set by ${clientSecurity.source}");
}
tlsSec = TLSSecurity.strict;
}
Expand All @@ -278,7 +278,7 @@ class ResolvedConnectConfig {
tlsSec,
'${tlsSecurity.source}'
'${tlsSec != origTlsSec ? " (modified from '${origTlsSec.value}' "
"by EDGEDB_CLIENT_SECURITY env var)" : ''}');
"by ${clientSecurity.source} env var)" : ''}');
}
}

Expand Down Expand Up @@ -513,6 +513,19 @@ int parseDuration(dynamic rawDuration) {
return duration;
}

SourcedValue<String?> getPrefixedEnvVar(String key) {
final val = getEnvVar('GEL_$key');
final oldVal = getEnvVar('EDGEDB_$key');
return SourcedValue(val ?? oldVal,
'${val == null && oldVal != null ? 'EDGEDB' : 'GEL'}_$key');
}

SourcedValue<String?> getSourcedEnvVar(String key) {
final envVar = getPrefixedEnvVar(key);
envVar.source = "'${envVar.source}' environment variable";
return envVar;
}

Future<ResolvedConnectConfig> parseConnectConfig(ConnectConfig config) async {
final resolvedConfig = ResolvedConnectConfig();

Expand Down Expand Up @@ -547,8 +560,7 @@ Future<ResolvedConnectConfig> parseConnectConfig(ConnectConfig config) async {
user: SourcedValue(config.user, "'user' option"),
password: SourcedValue(config.password, "'password' option"),
secretKey: SourcedValue(config.secretKey, "'secretKey' option"),
cloudProfile: SourcedValue(getEnvVar('EDGEDB_CLOUD_PROFILE'),
"'EDGEDB_CLOUD_PROFILE' environment variable"),
cloudProfile: getSourcedEnvVar('CLOUD_PROFILE'),
tlsCA: SourcedValue(config.tlsCA, "'tlsCA' option"),
tlsCAFile: SourcedValue(config.tlsCAFile, "'tlsCAFile' option"),
tlsSecurity: SourcedValue(config.tlsSecurity, "'tlsSecurity' option"),
Expand All @@ -560,50 +572,37 @@ Future<ResolvedConnectConfig> parseConnectConfig(ConnectConfig config) async {
if (!hasCompoundOptions) {
// resolve config from env vars

var port = getEnvVar('EDGEDB_PORT');
final port = getSourcedEnvVar('PORT');
final portVal = port.value;
if (resolvedConfig._port == null &&
port != null &&
port.startsWith('tcp://')) {
portVal != null &&
portVal.startsWith('tcp://')) {
// EDGEDB_PORT is set by 'docker --link' so ignore and warn
log('EDGEDB_PORT in \'tcp://host:port\' format, so will be ignored');
port = null;
port.value = null;
}

hasCompoundOptions = await resolveConfigOptions(
resolvedConfig,
"Cannot have more than one of the following connection environment variables: "
"'EDGEDB_DSN', 'EDGEDB_INSTANCE', 'EDGEDB_CREDENTIALS', "
"'EDGEDB_CREDENTIALS_FILE' or 'EDGEDB_HOST'",
"'GEL_DSN', 'GEL_INSTANCE', 'GEL_CREDENTIALS', "
"'GEL_CREDENTIALS_FILE' or 'GEL_HOST'",
null,
dsn: SourcedValue(
getEnvVar('EDGEDB_DSN'), "'EDGEDB_DSN' environment variable"),
instanceName: SourcedValue(getEnvVar('EDGEDB_INSTANCE'),
"'EDGEDB_INSTANCE' environment variable"),
credentials: SourcedValue(getEnvVar('EDGEDB_CREDENTIALS'),
"'EDGEDB_CREDENTIALS' environment variable"),
credentialsFile: SourcedValue(getEnvVar('EDGEDB_CREDENTIALS_FILE'),
"'EDGEDB_CREDENTIALS_FILE' environment variable"),
host: SourcedValue(
getEnvVar('EDGEDB_HOST'), "'EDGEDB_HOST' environment variable"),
port: SourcedValue(port, "'EDGEDB_PORT' environment variable"),
database: SourcedValue(getEnvVar('EDGEDB_DATABASE'),
"'EDGEDB_DATABASE' environment variable"),
branch: SourcedValue(
getEnvVar('EDGEDB_BRANCH'), "'EDGEDB_BRANCH' environment variable"),
user: SourcedValue(
getEnvVar('EDGEDB_USER'), "'EDGEDB_USER' environment variable"),
password: SourcedValue(getEnvVar('EDGEDB_PASSWORD'),
"'EDGEDB_PASSWORD' environment variable"),
secretKey: SourcedValue(getEnvVar('EDGEDB_SECRET_KEY'),
"'EDGEDB_SECRET_KEY' environment variable"),
tlsCA: SourcedValue(
getEnvVar('EDGEDB_TLS_CA'), "'EDGEDB_TLS_CA' environment variable"),
tlsCAFile: SourcedValue(getEnvVar('EDGEDB_TLS_CA_FILE'),
"'EDGEDB_TLS_CA_FILE' environment variable"),
tlsSecurity: SourcedValue(getEnvVar('EDGEDB_CLIENT_TLS_SECURITY'),
"'EDGEDB_CLIENT_TLS_SECURITY' environment variable"),
waitUntilAvailable: SourcedValue(getEnvVar('EDGEDB_WAIT_UNTIL_AVAILABLE'),
"'EDGEDB_WAIT_UNTIL_AVAILABLE' environment variable"),
dsn: getSourcedEnvVar('DSN'),
instanceName: getSourcedEnvVar('INSTANCE'),
credentials: getSourcedEnvVar('CREDENTIALS'),
credentialsFile: getSourcedEnvVar('CREDENTIALS_FILE'),
host: getSourcedEnvVar('HOST'),
port: port,
database: getSourcedEnvVar('DATABASE'),
branch: getSourcedEnvVar('BRANCH'),
user: getSourcedEnvVar('USER'),
password: getSourcedEnvVar('PASSWORD'),
secretKey: getSourcedEnvVar('SECRET_KEY'),
tlsCA: getSourcedEnvVar('TLS_CA'),
tlsCAFile: getSourcedEnvVar('TLS_CA_FILE'),
tlsSecurity: getSourcedEnvVar('CLIENT_TLS_SECURITY'),
waitUntilAvailable: getSourcedEnvVar('WAIT_UNTIL_AVAILABLE'),
);
}

Expand All @@ -614,8 +613,8 @@ Future<ResolvedConnectConfig> parseConnectConfig(ConnectConfig config) async {
throw ClientConnectionError(
"no 'edgedb.toml' found and no connection options specified"
" either via arguments to `connect()` API or via environment"
" variables EDGEDB_HOST, EDGEDB_INSTANCE, EDGEDB_DSN, "
"EDGEDB_CREDENTIALS or EDGEDB_CREDENTIALS_FILE");
" variables GEL_HOST, GEL_INSTANCE, GEL_DSN, "
"GEL_CREDENTIALS or GEL_CREDENTIALS_FILE");
}
final stashPath = await getStashPath(projectDir);
final instancePath =
Expand All @@ -642,7 +641,7 @@ Future<ResolvedConnectConfig> parseConnectConfig(ConnectConfig config) async {
} else {
throw ClientConnectionError(
"Found 'edgedb.toml' but the project is not initialized. "
"Run `edgedb project init`.");
"Run `gel project init`.");
}
}

Expand Down Expand Up @@ -732,7 +731,7 @@ Future<bool> resolveConfigOptions(ResolvedConnectConfig resolvedConfig,
}
final validHost = host?.value != null ? validateHost(host!.value!) : '';
resolvedDsn = SourcedValue(
'edgedb://${validHost.contains(':') ? '[${Uri.encodeFull(validHost)}]' : validHost}',
'gel://${validHost.contains(':') ? '[${Uri.encodeFull(validHost)}]' : validHost}',
host?.value != null ? host!.source : port!.source);
} else {
resolvedDsn = SourcedValue.from(dsn!);
Expand All @@ -752,7 +751,7 @@ Future<bool> resolveConfigOptions(ResolvedConnectConfig resolvedConfig,
source = instanceName.source;
} else {
if (!RegExp(
r'^([A-Za-z0-9](-?[A-Za-z0-9])*)/([A-Za-z0-9](-?[A-Za-z0-9])*)$')
r'^([A-Za-z0-9_-](-?[A-Za-z0-9_])*)/([A-Za-z0-9](-?[A-Za-z0-9])*)$')
.hasMatch(instanceName.value!)) {
throw InterfaceError(
"invalid DSN or instance name: '${instanceName.value}'");
Expand Down
14 changes: 13 additions & 1 deletion test/connect_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ void main() {
'Try running "git submodule update --init".');
}

Map<String, dynamic> exceptions = {};

for (var testcase in connectionTestcases) {
await runConnectionTest(testcase);
try {
await runConnectionTest(testcase);
} catch (err) {
exceptions[testcase['name']] = err;
}
}

if (exceptions.isNotEmpty) {
throw Exception('''${exceptions.length} connection testcases failed:

${exceptions.entries.map((e) => '--- ${e.key} ---\n${e.value}').join('\n\n')}''');
}
});

Expand Down
Loading