Skip to content

Commit

Permalink
chore: Rename type hierarchies
Browse files Browse the repository at this point in the history
Avoid using `Cedar` prefixes for anything, only those classes where the clarity is worth the cost

TODO: Create Entities type with factory from List
TODO: Move CedarEngine to core and improve interface for policy/entity management
  • Loading branch information
dnys1 committed Sep 2, 2024
1 parent fd98997 commit 806d73a
Show file tree
Hide file tree
Showing 65 changed files with 2,172 additions and 3,003 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/cedar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
run: dart pub get
- name: Test
run: dart test --fail-fast
- name: Test (dart2js)
run: dart test -p chrome --fail-fast
- name: Test (dart2wasm)
run: dart test -p chrome -c dart2wasm --fail-fast
1 change: 1 addition & 0 deletions packages/cedar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.2.0

- feat: Add Dart evaluation
- chore!: Rename several types from `CedarX` to just `X` to improve readability and consistency with Rust impl

## 0.1.3

Expand Down
47 changes: 47 additions & 0 deletions packages/cedar/example/todo_app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:cedar/cedar.dart';

void main() {
const policies = '''
// Policy 0: Any User can create a list and see what lists they own
permit (
principal,
action in [Action::"CreateList", Action::"GetLists"],
resource == Application::"TinyTodo"
);
// Policy 1: A User can perform any action on a List they own
permit (principal, action, resource)
when { resource has owner && resource.owner == principal };
''';
final policySet = PolicySet.parse(policies);

final app = Entity(
uid: EntityUid.of('Application', 'TinyTodo'),
);
final user = Entity(
uid: EntityUid.of('User', 'alice'),
parents: [app.uid],
attributes: {
'name': Value.string('Alice'),
},
);
final canCreateTodo = policySet.isAuthorized(
AuthorizationRequest(
principal: user.uid,
action: EntityUid.of('Action', 'CreateList'),
resource: app.uid,
entities: {app.uid: app, user.uid: user},
),
);
switch (canCreateTodo) {
case AuthorizationResponse(decision: Decision.allow):
print('Alice can create the todo list!');
case AuthorizationResponse(
:final errorMessages,
:final reasons,
):
print('Alice cannot create the todo list');
print('Contributing policies: $reasons');
print('Error messages: $errorMessages');
}
}
22 changes: 13 additions & 9 deletions packages/cedar/lib/cedar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
/// native assets of `package:cedar_ffi`.
library;

export 'src/authorization/cedar_authorization_request.dart';
export 'src/authorization/cedar_authorization_response.dart';
export 'src/authorization/cedar_authorizer.dart';
export 'src/eval/errors.dart';
export 'src/model/cedar_entity.dart';
export 'src/model/cedar_schema.dart' hide CedarEntityType;
export 'src/model/types/cedar_value.dart';
export 'src/policy/cedar_policy.dart';
export 'src/policy/cedar_policy_set.dart';
export 'src/authorization/authorization_request.dart';
export 'src/authorization/authorization_response.dart';
export 'src/authorization/authorizer.dart';
export 'src/model/entity.dart';
export 'src/model/entity_id.dart';
export 'src/model/errors.dart';
export 'src/model/policy.dart';
export 'src/model/policy_constraint.dart';
export 'src/model/policy_set.dart';
export 'src/model/schema.dart';
export 'src/model/schema_type.dart';
export 'src/model/value/value.dart';
export 'src/model/variable.dart';
5 changes: 3 additions & 2 deletions packages/cedar/lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'ast/pattern.dart';
export 'ast/value.dart';
export 'ast/variable.dart';
export 'ast/visitor.dart';
export 'model/policy.dart';
export 'model/policy_constraint.dart';
export 'model/value/value.dart';
export 'parser/position.dart';
export 'policy/cedar_policy.dart';
export 'policy/cedar_scope.dart';
8 changes: 4 additions & 4 deletions packages/cedar/lib/src/ast/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ final class Annotations with IterableMixin<Annotation> {
});
}

CedarPolicy permit() {
return CedarPolicy(effect: CedarEffect.permit, annotations: this);
Policy permit() {
return Policy(effect: Effect.permit, annotations: this);
}

CedarPolicy forbid() {
return CedarPolicy(effect: CedarEffect.forbid, annotations: this);
Policy forbid() {
return Policy(effect: Effect.forbid, annotations: this);
}

Iterable<Annotation> get iterable sync* {
Expand Down
Loading

0 comments on commit 806d73a

Please sign in to comment.