Skip to content

Commit

Permalink
feat: upgrade deps and add other proto clients (#223)
Browse files Browse the repository at this point in the history
This upgrades the dependencies, removes renovate
(since all deps are wider ranges) and adds
other service clients
  • Loading branch information
buehler committed Mar 15, 2024
1 parent 3c422e8 commit c1e8bf0
Show file tree
Hide file tree
Showing 23 changed files with 887 additions and 234 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ jobs:
steps:
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.DEPLOY_TOKEN }}
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- uses: arduino/setup-protoc@v1
- uses: bufbuild/buf-setup-action@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: enable protoc dart
run: dart pub global activate protoc_plugin
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: extractions/setup-just@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- run: just install-tools
- run: dart pub get
- run: just
- name: release
uses: cycjimmy/semantic-release-action@v3
with:
Expand Down
40 changes: 17 additions & 23 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,25 @@ on:

jobs:
lint_and_test:
strategy:
fail-fast: true
matrix:
sdk:
- 2.18.0
- stable
name: Linting and Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}
sdk: stable
- uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: extractions/setup-just@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: enable protoc dart
run: dart pub global activate protoc_plugin
- name: build gRPC
run: ./tool/generate_grpc.sh
- run: just install-tools
- run: dart pub get
- name: build barrel files
run: ./tool/generate_barrel_files.dart
- run: just
- run: dart analyze
- run: dart test

Expand All @@ -54,21 +48,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- uses: bufbuild/buf-setup-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: extractions/setup-just@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: enable protoc dart
run: dart pub global activate protoc_plugin
- run: just install-tools
- run: dart pub get
- name: build gRPC
run: ./tool/generate_grpc.sh
- name: build barrel files
run: ./tool/generate_barrel_files.dart
- run: just
- run: echo '### Publish Pub Package Result' >> $GITHUB_STEP_SUMMARY
- run: dart pub publish --dry-run >> $GITHUB_STEP_SUMMARY
continue-on-error: true
Expand Down
15 changes: 0 additions & 15 deletions .gitmodules

This file was deleted.

2 changes: 2 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ pubspec.lock
external/

renovate.json
.releaserc.json
analysis_options.yaml
justfile
2 changes: 1 addition & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@semantic-release/exec",
{
"verifyConditionsCmd": "if [ -z \"$CREDENTIALS\" ]; then exit 1; fi && mkdir -p ~/.config/dart && echo \"$CREDENTIALS\" > ~/.config/dart/pub-credentials.json",
"prepareCmd": "./tool/generate_grpc.sh && ./tool/generate_barrel_files.dart && sed -i 's/^version: .*$/version: ${nextRelease.version}/' pubspec.yaml",
"prepareCmd": "sed -i 's/^version: .*$/version: ${nextRelease.version}/' pubspec.yaml",
"publishCmd": "dart pub publish -f"
}
],
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ analyzer:
- lib/src/grpc/generated
- external/
- example/
- tool/
7 changes: 7 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
managed:
enabled: true
plugins:
- plugin: dart
out: lib/src/grpc/generated
opt: grpc
1 change: 0 additions & 1 deletion external/googleapis
Submodule googleapis deleted from 6782d0
1 change: 0 additions & 1 deletion external/grpc-gateway
Submodule grpc-gateway deleted from 8abb8b
1 change: 0 additions & 1 deletion external/protobuf
Submodule protobuf deleted from 39f763
1 change: 0 additions & 1 deletion external/protoc-gen-validate
Submodule protoc-gen-validate deleted from 4966ec
1 change: 0 additions & 1 deletion external/zitadel
Submodule zitadel deleted from 057ac9
15 changes: 15 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
proto_dir := "./lib/src/grpc/generated"

default: clean generate-grpc

clean:
@rm -rf {{proto_dir}}

generate-grpc: && generate-barrel-files
buf generate https://github.com/zitadel/zitadel.git --path ./proto/zitadel --include-imports --include-wkt

generate-barrel-files:
dart tool/barrel_file_generator.dart

install-tools:
dart pub global activate protoc_plugin
26 changes: 18 additions & 8 deletions lib/src/credentials/service_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class ServiceAccount {
}

static String _discoveryEndpoint(String endpoint) =>
endpoint.endsWith(discoveryEndpointPath) ? endpoint : '$endpoint$discoveryEndpointPath';
endpoint.endsWith(discoveryEndpointPath)
? endpoint
: '$endpoint$discoveryEndpointPath';

/// Create a JSON map from the application.
Map<String, dynamic> toJson() => {
Expand Down Expand Up @@ -92,7 +94,8 @@ class ServiceAccount {
/// 'https://issuer.zitadel.ch',
/// AuthenticationOptions(apiAccess: true));
/// ```
Future<String> authenticate(String audience, [AuthenticationOptions? options]) async {
Future<String> authenticate(String audience,
[AuthenticationOptions? options]) async {
options ??= AuthenticationOptions();

final discoveryResponse = await get(
Expand All @@ -114,7 +117,8 @@ class ServiceAccount {
);

if (response.statusCode > 299) {
throw Exception('An error occurred. Status Code: ${response.statusCode}.');
throw Exception(
'An error occurred. Status Code: ${response.statusCode}.');
}

final json = jsonDecode(utf8.decode(response.bodyBytes));
Expand All @@ -127,13 +131,18 @@ class ServiceAccount {
'iss': userId,
'sub': userId,
'iat': DateTime.now().toUtc().millisecondsSinceEpoch ~/ 1000,
'exp': DateTime.now().toUtc().add(Duration(hours: 1)).millisecondsSinceEpoch ~/ 1000,
'exp': DateTime.now()
.toUtc()
.add(Duration(hours: 1))
.millisecondsSinceEpoch ~/
1000,
'aud': audience,
});

final builder = JsonWebSignatureBuilder();
builder.jsonContent = claims.toJson();
builder.addRecipient(JsonWebKey.fromPem(key, keyId: keyId), algorithm: 'RS256');
builder.addRecipient(JsonWebKey.fromPem(key, keyId: keyId),
algorithm: 'RS256');

final signature = builder.build();

Expand Down Expand Up @@ -181,8 +190,9 @@ class AuthenticationOptions {
String createScopes() => [
'openid',
if (apiAccess) apiAccessScope,
for (var scope in additionalScopes) scope,
for (var audience in projectAudiences) 'urn:zitadel:iam:org:project:id:$audience:aud',
for (var role in roles) 'urn:zitadel:iam:org:project:role:$role',
for (final scope in additionalScopes) scope,
for (final audience in projectAudiences)
'urn:zitadel:iam:org:project:id:$audience:aud',
for (final role in roles) 'urn:zitadel:iam:org:project:role:$role',
].join(' ');
}
Loading

0 comments on commit c1e8bf0

Please sign in to comment.