Skip to content

Commit

Permalink
feat(identity-based-policy): add whyCannot method (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Nov 17, 2021
1 parent 5405ef7 commit 47f21f1
Show file tree
Hide file tree
Showing 65 changed files with 844 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ Supports these glob features:
Please click on the language that you prefer

- Translations:

- [Chinese docs](https://roggervalf.github.io/iam-policies/zh-CN/) by [@mickymao1110](https://github.com/mickymao1110) (< v3.5.0 )
- [English docs](https://roggervalf.github.io/iam-policies/en/) by [@roggervalf](https://github.com/roggervalf)

- [Api documentation](https://github.com/roggervalf/iam-policies/blob/master/docs/gitbook/api/index.md)

## Article

[How to build a Deno module](https://medium.com/@rogger.valverde/how-to-build-a-deno-module-dc383eee8edb)
Expand Down
24 changes: 23 additions & 1 deletion dist/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,23 @@ interface OptionalResourceBlock {
interface OptionalNotResourceBlock {
notResource?: Patterns;
}
declare type ConditionKey = string | number | boolean;
interface ConditionMap {
[key: string]: ConditionKey[] | ConditionKey;
}
declare type ConditionBlock = Record<string, Record<string, unknown>>;
interface StatementInterface {
sid?: string;
effect?: EffectBlock;
condition?: ConditionBlock;
}
interface DecomposeString {
start: number;
end: number;
pre: string;
body: string;
post: string;
}
declare type Resolver = (data: any, expected: any) => boolean;
interface ConditionResolver {
[key: string]: Resolver;
Expand All @@ -89,6 +100,13 @@ interface MatchConditionInterface<T extends object> {
context?: T;
conditionResolver?: ConditionResolver;
}
interface MatchConditionResolverInterface<T extends object> {
context: T;
conditionResolver?: ConditionResolver;
path: string;
condition: string;
value: any;
}
interface MatchActionBasedInterface<T extends object> extends MatchConditionInterface<T> {
action: string;
}
Expand All @@ -112,6 +130,9 @@ interface EvaluateResourceBasedInterface<T extends object> extends EvaluateActio
principalType?: string;
resource?: string;
}
interface MemoizeInterface extends Function {
cache: Map<any, any>;
}
declare type ActionBasedType = StatementInterface & (ActionBlock | NotActionBlock);
declare type IdentityBasedType = StatementInterface & (ActionBlock | NotActionBlock) & (ResourceBlock | NotResourceBlock);
declare type ResourceBasedType = StatementInterface & (OptionalPrincipalBlock | OptionalNotPrincipalBlock) & (ActionBlock | NotActionBlock) & (OptionalResourceBlock | OptionalNotResourceBlock);
Expand Down Expand Up @@ -237,6 +258,7 @@ declare class IdentityBasedPolicy<T extends object> extends Policy<T, IdentityBa
can(this: IdentityBasedPolicy<T>, { action, resource, context }: EvaluateIdentityBasedInterface<T>): boolean;
whyCan(this: IdentityBasedPolicy<T>, { action, resource, context }: EvaluateIdentityBasedInterface<T>): IdentityBasedType[];
cannot(this: IdentityBasedPolicy<T>, { action, resource, context }: EvaluateIdentityBasedInterface<T>): boolean;
whyCannot(this: IdentityBasedPolicy<T>, { action, resource, context }: EvaluateIdentityBasedInterface<T>): IdentityBasedType[];
}

interface ResourceBasedPolicyInterface<T extends object> {
Expand All @@ -256,4 +278,4 @@ declare class ResourceBasedPolicy<T extends object> extends Policy<T, ResourceBa
cannot(this: ResourceBasedPolicy<T>, { principal, action, resource, principalType, context }: EvaluateResourceBasedInterface<T>): boolean;
}

export { ActionBased, ActionBasedPolicy, ActionBasedPolicyInterface, IdentityBased, IdentityBasedPolicy, ResourceBased, ResourceBasedPolicy, applyContext, getValueFromPath };
export { ActionBased, ActionBasedPolicy, ActionBasedPolicyInterface, ActionBasedType, ConditionBlock, ConditionKey, ConditionMap, ConditionResolver, DecomposeString, EffectBlock, EvaluateActionBasedInterface, EvaluateIdentityBasedInterface, EvaluateResourceBasedInterface, IdentityBased, IdentityBasedPolicy, IdentityBasedType, MatchActionBasedInterface, MatchConditionInterface, MatchConditionResolverInterface, MatchIdentityBasedInterface, MatchResourceBasedInterface, MemoizeInterface, Patterns, PrincipalMap, ProxyOptions, ResourceBased, ResourceBasedPolicy, ResourceBasedType, StatementInterface, applyContext, getValueFromPath };
14 changes: 14 additions & 0 deletions dist/main.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.es.js.map

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.actionbasedtype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [ActionBasedType](./iam-policies.actionbasedtype.md)

## ActionBasedType type

<b>Signature:</b>

```typescript
declare type ActionBasedType = StatementInterface & (ActionBlock | NotActionBlock);
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.conditionblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [ConditionBlock](./iam-policies.conditionblock.md)

## ConditionBlock type

<b>Signature:</b>

```typescript
declare type ConditionBlock = Record<string, Record<string, unknown>>;
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.conditionkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [ConditionKey](./iam-policies.conditionkey.md)

## ConditionKey type

<b>Signature:</b>

```typescript
declare type ConditionKey = string | number | boolean;
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.conditionmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [ConditionMap](./iam-policies.conditionmap.md)

## ConditionMap interface

<b>Signature:</b>

```typescript
interface ConditionMap
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.conditionresolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [ConditionResolver](./iam-policies.conditionresolver.md)

## ConditionResolver interface

<b>Signature:</b>

```typescript
interface ConditionResolver
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.decomposestring.body.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [DecomposeString](./iam-policies.decomposestring.md) &gt; [body](./iam-policies.decomposestring.body.md)

## DecomposeString.body property

<b>Signature:</b>

```typescript
body: string;
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.decomposestring.end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [DecomposeString](./iam-policies.decomposestring.md) &gt; [end](./iam-policies.decomposestring.end.md)

## DecomposeString.end property

<b>Signature:</b>

```typescript
end: number;
```
22 changes: 22 additions & 0 deletions docs/gitbook/api/iam-policies.decomposestring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [DecomposeString](./iam-policies.decomposestring.md)

## DecomposeString interface

<b>Signature:</b>

```typescript
interface DecomposeString
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [body](./iam-policies.decomposestring.body.md) | string | |
| [end](./iam-policies.decomposestring.end.md) | number | |
| [post](./iam-policies.decomposestring.post.md) | string | |
| [pre](./iam-policies.decomposestring.pre.md) | string | |
| [start](./iam-policies.decomposestring.start.md) | number | |

11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.decomposestring.post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [DecomposeString](./iam-policies.decomposestring.md) &gt; [post](./iam-policies.decomposestring.post.md)

## DecomposeString.post property

<b>Signature:</b>

```typescript
post: string;
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.decomposestring.pre.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [DecomposeString](./iam-policies.decomposestring.md) &gt; [pre](./iam-policies.decomposestring.pre.md)

## DecomposeString.pre property

<b>Signature:</b>

```typescript
pre: string;
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.decomposestring.start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [DecomposeString](./iam-policies.decomposestring.md) &gt; [start](./iam-policies.decomposestring.start.md)

## DecomposeString.start property

<b>Signature:</b>

```typescript
start: number;
```
11 changes: 11 additions & 0 deletions docs/gitbook/api/iam-policies.effectblock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EffectBlock](./iam-policies.effectblock.md)

## EffectBlock type

<b>Signature:</b>

```typescript
declare type EffectBlock = 'allow' | 'deny';
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateActionBasedInterface](./iam-policies.evaluateactionbasedinterface.md) &gt; [action](./iam-policies.evaluateactionbasedinterface.action.md)

## EvaluateActionBasedInterface.action property

<b>Signature:</b>

```typescript
action: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateActionBasedInterface](./iam-policies.evaluateactionbasedinterface.md) &gt; [context](./iam-policies.evaluateactionbasedinterface.context.md)

## EvaluateActionBasedInterface.context property

<b>Signature:</b>

```typescript
context?: T;
```
19 changes: 19 additions & 0 deletions docs/gitbook/api/iam-policies.evaluateactionbasedinterface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateActionBasedInterface](./iam-policies.evaluateactionbasedinterface.md)

## EvaluateActionBasedInterface interface

<b>Signature:</b>

```typescript
interface EvaluateActionBasedInterface<T extends object>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [action](./iam-policies.evaluateactionbasedinterface.action.md) | string | |
| [context?](./iam-policies.evaluateactionbasedinterface.context.md) | T | <i>(Optional)</i> |

19 changes: 19 additions & 0 deletions docs/gitbook/api/iam-policies.evaluateidentitybasedinterface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateIdentityBasedInterface](./iam-policies.evaluateidentitybasedinterface.md)

## EvaluateIdentityBasedInterface interface

<b>Signature:</b>

```typescript
interface EvaluateIdentityBasedInterface<T extends object> extends EvaluateActionBasedInterface<T>
```
<b>Extends:</b> EvaluateActionBasedInterface&lt;T&gt;
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [resource](./iam-policies.evaluateidentitybasedinterface.resource.md) | string | |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateIdentityBasedInterface](./iam-policies.evaluateidentitybasedinterface.md) &gt; [resource](./iam-policies.evaluateidentitybasedinterface.resource.md)

## EvaluateIdentityBasedInterface.resource property

<b>Signature:</b>

```typescript
resource: string;
```
21 changes: 21 additions & 0 deletions docs/gitbook/api/iam-policies.evaluateresourcebasedinterface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateResourceBasedInterface](./iam-policies.evaluateresourcebasedinterface.md)

## EvaluateResourceBasedInterface interface

<b>Signature:</b>

```typescript
interface EvaluateResourceBasedInterface<T extends object> extends EvaluateActionBasedInterface<T>
```
<b>Extends:</b> EvaluateActionBasedInterface&lt;T&gt;
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [principal?](./iam-policies.evaluateresourcebasedinterface.principal.md) | string | <i>(Optional)</i> |
| [principalType?](./iam-policies.evaluateresourcebasedinterface.principaltype.md) | string | <i>(Optional)</i> |
| [resource?](./iam-policies.evaluateresourcebasedinterface.resource.md) | string | <i>(Optional)</i> |
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateResourceBasedInterface](./iam-policies.evaluateresourcebasedinterface.md) &gt; [principal](./iam-policies.evaluateresourcebasedinterface.principal.md)

## EvaluateResourceBasedInterface.principal property

<b>Signature:</b>

```typescript
principal?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [iam-policies](./iam-policies.md) &gt; [EvaluateResourceBasedInterface](./iam-policies.evaluateresourcebasedinterface.md) &gt; [principalType](./iam-policies.evaluateresourcebasedinterface.principaltype.md)

## EvaluateResourceBasedInterface.principalType property

<b>Signature:</b>

```typescript
principalType?: string;
```
Loading

0 comments on commit 47f21f1

Please sign in to comment.