Skip to content

Commit

Permalink
chore: Move Cedar Protobuf types to cedar-dart
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Sep 11, 2024
1 parent 9a53377 commit 5cbacae
Show file tree
Hide file tree
Showing 83 changed files with 13,151 additions and 6,388 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: protos clean

DART_OUT := $(PWD)/dart/lib/src/proto
GO_OUT := $(PWD)/go/proto

protos:
buf lint
buf generate
cd dart; dart format .; dart analyze --fatal-infos --fatal-warnings .
cd go; go mod tidy

clean:
rm -rf $(DART_OUT)
rm -rf $(GO_OUT)
10 changes: 2 additions & 8 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@ 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
module: buf.build/celest-dev/cedar
inputs:
- directory: proto
- directory: third_party
paths:
- third_party/dart/dart_options.proto
- module: buf.build/celest-dev/cedar
plugins:
- remote: buf.build/protocolbuffers/dart:v21.1.2
include_imports: true
Expand Down
6 changes: 6 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/celest-dev/cedar
commit: 37266fb8032240bc887fea377784e864
digest: b5:d69e51c2a8a2e037c1f5fceb96f0420c4f6e8ae8d44d1de427380070d5f6119175dcaf2eb7c7d5385ebde266d60d500744953a8bf81881bbb02d9c0237766462
6 changes: 3 additions & 3 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
version: v2
deps:
- buf.build/celest-dev/cedar
modules:
- path: proto
- path: third_party
name: buf.build/celest-dev/corks
breaking:
use:
- PACKAGE
lint:
use:
- MINIMAL
ignore:
- third_party
disallow_comment_ignores: true
4 changes: 4 additions & 0 deletions dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1

- chore: Move Cedar protobufs to the [cedar-dart](https://github.com/celest-dev/cedar-dart) repo

## 0.2.0

- feat: Improve and expand Cork model
Expand Down
14 changes: 2 additions & 12 deletions dart/lib/corks_proto.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
export 'src/proto.dart' show AnyHelper;
export 'src/proto/cedar/v3/context.pb.dart';
export 'src/proto/cedar/v3/context.pbjson.dart';
export 'src/proto/cedar/v3/entity.pb.dart';
export 'src/proto/cedar/v3/entity.pbjson.dart';
export 'src/proto/cedar/v3/entity_id.pb.dart';
export 'src/proto/cedar/v3/entity_id.pbjson.dart';
export 'src/proto/cedar/v3/expr.pb.dart';
export 'src/proto/cedar/v3/expr.pbjson.dart';
export 'src/proto/cedar/v3/policy.pb.dart';
export 'src/proto/cedar/v3/policy.pbjson.dart';
export 'src/proto/cedar/v3/value.pb.dart';
export 'src/proto/cedar/v3/value.pbjson.dart';
export 'src/proto/corks/cedar/v3/cork.pb.dart';
export 'src/proto/corks/cedar/v3/cork.pbjson.dart';
export 'src/proto/corks/v1/cork.pb.dart';
export 'src/proto/corks/v1/cork.pbjson.dart';
export 'src/proto/google/protobuf/any.pb.dart';
35 changes: 19 additions & 16 deletions dart/lib/src/cedar_cork.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
import 'dart:collection';
import 'dart:typed_data';

import 'package:cedar/ast.dart' as cedar;
import 'package:cedar/cedar.dart' as cedar;
import 'package:cedar/src/proto/cedar/v3/entity.pb.dart' as proto;
import 'package:cedar/src/proto/cedar/v3/entity_uid.pb.dart' as proto;
import 'package:cedar/src/proto/cedar/v3/expr.pb.dart' as proto;
import 'package:corks_cedar/corks_cedar.dart';
import 'package:corks_cedar/corks_proto.dart' as proto;
import 'package:corks_cedar/src/interop/proto_interop.dart';
import 'package:meta/meta.dart';

/// A builder for [Cork]s backed by Cedar.
extension type CedarCorkBuilder(CorkBuilder _builder) implements CorkBuilder {
@redeclare
set issuer(cedar.CedarEntityId issuer) {
set issuer(cedar.EntityUid issuer) {
_builder.issuer = issuer.toProto();
}

@redeclare
set bearer(cedar.CedarEntityId bearer) {
set bearer(cedar.EntityUid bearer) {
_builder.bearer = bearer.toProto();
}

@redeclare
set audience(cedar.CedarEntityId audience) {
set audience(cedar.EntityUid audience) {
_builder.audience = audience.toProto();
}

@redeclare
set claims(cedar.CedarEntity claims) {
set claims(cedar.Entity claims) {
_builder.claims = claims.toProto();
}

@redeclare
void addCaveat(cedar.JsonExpr caveat) {
void addCaveat(cedar.Expr caveat) {
_builder.addCaveat(caveat.toProto());
}
}
Expand All @@ -54,32 +57,32 @@ extension type CedarCork(Cork _cork) implements Cork {
CedarCorkBuilder(Cork.builder(id));

@redeclare
cedar.CedarEntityId get issuer =>
proto.EntityId().unpackAny(_cork.issuer).fromProto();
cedar.EntityUid get issuer =>
cedar.EntityUid.fromProto(proto.EntityUid().unpackAny(_cork.issuer));

@redeclare
cedar.CedarEntityId get bearer =>
proto.EntityId().unpackAny(_cork.bearer).fromProto();
cedar.EntityUid get bearer =>
cedar.EntityUid.fromProto(proto.EntityUid().unpackAny(_cork.bearer));

@redeclare
cedar.CedarEntityId? get audience {
cedar.EntityUid? get audience {
if (_cork.audience case final audience?) {
return proto.EntityId().unpackAny(audience).fromProto();
return cedar.EntityUid.fromProto(proto.EntityUid().unpackAny(audience));
}
return null;
}

@redeclare
cedar.CedarEntity? get claims {
cedar.Entity? get claims {
if (_cork.claims case final claims?) {
return proto.Entity().unpackAny(claims).fromProto();
return cedar.Entity.fromProto(proto.Entity().unpackAny(claims));
}
return null;
}

@redeclare
List<cedar.JsonExpr> get caveats => UnmodifiableListView([
List<cedar.Expr> get caveats => UnmodifiableListView([
for (final caveat in _cork.caveats)
proto.Expr().unpackAny(caveat).fromProto(),
cedar.Expr.fromProto(proto.Expr().unpackAny(caveat)),
]);
}
Loading

0 comments on commit 5cbacae

Please sign in to comment.