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

chore(cedar): Add protobuf types #46

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.PHONY: protos clean

protos:
buf lint
buf generate
cd packages/cedar; dart format .

clean:
rm -rf packages/cedar/lib/src/proto
21 changes: 21 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: v2
managed:
enabled: true
override:
- file_option: go_package
value: github.com/celest-dev/corks/go/proto/dart;dartoptionspb
path: dart/dart_options.proto
- file_option: go_package_prefix
value: github.com/celest-dev/corks/go/proto
disable:
- path: google
inputs:
- directory: proto
- directory: third_party
paths:
- third_party/dart/dart_options.proto
plugins:
- remote: buf.build/protocolbuffers/dart:v21.1.2
include_imports: true
include_wkt: true
out: packages/cedar/lib/src/proto
13 changes: 13 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: v2
modules:
- path: proto
- path: third_party
breaking:
use:
- PACKAGE
lint:
use:
- MINIMAL
ignore:
- third_party
disallow_comment_ignores: true
6 changes: 6 additions & 0 deletions packages/cedar/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
include: package:lints/recommended.yaml

analyzer:
exclude:
- lib/src/proto/**/*.pb.dart
- lib/src/proto/**/*.pbenum.dart
- lib/src/proto/**/*.pbjson.dart
19 changes: 19 additions & 0 deletions packages/cedar/lib/src/ast/annotation.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:collection';

import 'package:cedar/ast.dart';
import 'package:cedar/src/proto/cedar/v3/policy.pb.dart' as pb;
import 'package:collection/collection.dart';

final class Annotations with IterableMixin<Annotation> {
Annotations(this.annotations);
Expand All @@ -9,6 +11,10 @@ final class Annotations with IterableMixin<Annotation> {
return Annotations(json.cast());
}

factory Annotations.fromProto(pb.Annotations annotations) {
return Annotations(annotations.annotations);
}

final Map<String, String> annotations;

operator [](String key) => annotations[key];
Expand Down Expand Up @@ -43,6 +49,19 @@ final class Annotations with IterableMixin<Annotation> {
Iterator<Annotation> get iterator => iterable.iterator;

Map<String, String> toJson() => annotations;

pb.Annotations toProto() {
return pb.Annotations(annotations: annotations);
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Annotations &&
const MapEquality().equals(annotations, other.annotations);

@override
int get hashCode => const MapEquality().hash(annotations);
}

Annotations annotation(String key, String value) {
Expand Down
Loading