@janssenproject/cedarling_wasm 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -0
- package/cedarling_wasm.d.ts +222 -0
- package/cedarling_wasm.js +1385 -0
- package/cedarling_wasm_bg.wasm +0 -0
- package/package.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Cedarling WASM
|
|
2
|
+
|
|
3
|
+
This module is designed to build cedarling for browser wasm.
|
|
4
|
+
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
For building we use [`wasm-pack`](https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_Wasm) for install you can use command `cargo install wasm-pack`
|
|
8
|
+
|
|
9
|
+
Build cedarling in release:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
wasm-pack build --release --target web
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Build cedarling in dev mode
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
wasm-pack build --target web --dev
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Result files will be in `pkg` folder.
|
|
22
|
+
|
|
23
|
+
## Testing
|
|
24
|
+
|
|
25
|
+
For WASM testing we use `wasm-pack` and it allows to make test in `node`, `chrome`, `firefox`, `safari`. You just need specify appropriate flag.
|
|
26
|
+
|
|
27
|
+
Example for firefox.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
wasm-pack test --firefox
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Run browser example
|
|
34
|
+
|
|
35
|
+
To run example using `index.html` you need execute following steps:
|
|
36
|
+
|
|
37
|
+
1. Build wasm cedarling.
|
|
38
|
+
2. Run webserver using `python3 -m http.server` or any other.
|
|
39
|
+
3. Visit example app [localhost](http://localhost:8000/), on this app you will get log in browser console.
|
|
40
|
+
- Also you can try use cedarling with web app using [cedarling_app](http://localhost:8000/cedarling_app.html), using custom bootstrap properties and request.
|
|
41
|
+
|
|
42
|
+
## WASM Usage
|
|
43
|
+
|
|
44
|
+
After building WASM bindings in folder `pkg` you can find where you can find `cedarling_wasm.js` and `cedarling_wasm.d.ts` where is defined interface for application.
|
|
45
|
+
|
|
46
|
+
In `index.html` described simple usage of `cedarling wasm` API:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { BOOTSTRAP_CONFIG, REQUEST } from "/example_data.js" // Import js objects: bootstrap config and request
|
|
50
|
+
import initWasm, { init } from "/pkg/cedarling_wasm.js";
|
|
51
|
+
|
|
52
|
+
async function main() {
|
|
53
|
+
await initWasm(); // Initialize the WebAssembly module
|
|
54
|
+
|
|
55
|
+
let instance = await init(BOOTSTRAP_CONFIG);
|
|
56
|
+
let result = await instance.authorize(REQUEST);
|
|
57
|
+
console.log("result:", result);
|
|
58
|
+
}
|
|
59
|
+
main().catch(console.error);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Before using any function from library you need initialize WASM runtime by calling `initWasm` function.
|
|
63
|
+
|
|
64
|
+
### Defined API
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
/**
|
|
68
|
+
* Create a new instance of the Cedarling application.
|
|
69
|
+
* This function can take as config parameter the eather `Map` other `Object`
|
|
70
|
+
*/
|
|
71
|
+
export function init(config: any): Promise<Cedarling>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The instance of the Cedarling application.
|
|
75
|
+
*/
|
|
76
|
+
export class Cedarling {
|
|
77
|
+
/**
|
|
78
|
+
* Create a new instance of the Cedarling application.
|
|
79
|
+
* Assume that config is `Object`
|
|
80
|
+
*/
|
|
81
|
+
static new(config: object): Promise<Cedarling>;
|
|
82
|
+
/**
|
|
83
|
+
* Create a new instance of the Cedarling application.
|
|
84
|
+
* Assume that config is `Map`
|
|
85
|
+
*/
|
|
86
|
+
static new_from_map(config: Map<any, any>): Promise<Cedarling>;
|
|
87
|
+
/**
|
|
88
|
+
* Authorize request
|
|
89
|
+
* makes authorization decision based on the [`Request`]
|
|
90
|
+
*/
|
|
91
|
+
authorize(request: any): Promise<AuthorizeResult>;
|
|
92
|
+
/**
|
|
93
|
+
* Get logs and remove them from the storage.
|
|
94
|
+
* Returns `Array` of `Map`
|
|
95
|
+
*/
|
|
96
|
+
pop_logs(): Array<any>;
|
|
97
|
+
/**
|
|
98
|
+
* Get specific log entry.
|
|
99
|
+
* Returns `Map` with values or `null`.
|
|
100
|
+
*/
|
|
101
|
+
get_log_by_id(id: string): any;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a list of all log ids.
|
|
104
|
+
* Returns `Array` of `String`
|
|
105
|
+
*/
|
|
106
|
+
get_log_ids(): Array<any>;
|
|
107
|
+
/**
|
|
108
|
+
* Get logs by tag, like `log_kind` or `log level`.
|
|
109
|
+
* Tag can be `log_kind`, `log_level`.
|
|
110
|
+
*/
|
|
111
|
+
get_logs_by_tag(tag: string): any[];
|
|
112
|
+
/**
|
|
113
|
+
* Get logs by request_id.
|
|
114
|
+
* Return log entries that match the given request_id.
|
|
115
|
+
*/
|
|
116
|
+
get_logs_by_request_id(request_id: string): any[];
|
|
117
|
+
/**
|
|
118
|
+
* Get log by request_id and tag, like composite key `request_id` + `log_kind`.
|
|
119
|
+
* Tag can be `log_kind`, `log_level`.
|
|
120
|
+
* Return log entries that match the given request_id and tag.
|
|
121
|
+
*/
|
|
122
|
+
get_logs_by_request_id_and_tag(request_id: string, tag: string): any[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A WASM wrapper for the Rust `cedarling::AuthorizeResult` struct.
|
|
127
|
+
* Represents the result of an authorization request.
|
|
128
|
+
*/
|
|
129
|
+
export class AuthorizeResult {
|
|
130
|
+
/**
|
|
131
|
+
* Convert `AuthorizeResult` to json string value
|
|
132
|
+
*/
|
|
133
|
+
json_string(): string;
|
|
134
|
+
/**
|
|
135
|
+
* Result of authorization where principal is `Jans::Workload`
|
|
136
|
+
*/
|
|
137
|
+
workload?: AuthorizeResultResponse;
|
|
138
|
+
/**
|
|
139
|
+
* Result of authorization where principal is `Jans::User`
|
|
140
|
+
*/
|
|
141
|
+
person?: AuthorizeResultResponse;
|
|
142
|
+
/**
|
|
143
|
+
* Result of authorization
|
|
144
|
+
* true means `ALLOW`
|
|
145
|
+
* false means `Deny`
|
|
146
|
+
*
|
|
147
|
+
* this field is [`bool`] type to be compatible with [authzen Access Evaluation Decision](https://openid.github.io/authzen/#section-6.2.1).
|
|
148
|
+
*/
|
|
149
|
+
decision: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Request ID of the authorization request
|
|
152
|
+
*/
|
|
153
|
+
request_id: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A WASM wrapper for the Rust `cedar_policy::Response` struct.
|
|
158
|
+
* Represents the result of an authorization request.
|
|
159
|
+
*/
|
|
160
|
+
export class AuthorizeResultResponse {
|
|
161
|
+
/**
|
|
162
|
+
* Authorization decision
|
|
163
|
+
*/
|
|
164
|
+
readonly decision: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Diagnostics providing more information on how this decision was reached
|
|
167
|
+
*/
|
|
168
|
+
readonly diagnostics: Diagnostics;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Diagnostics
|
|
173
|
+
* ===========
|
|
174
|
+
*
|
|
175
|
+
* Provides detailed information about how a policy decision was made, including policies that contributed to the decision and any errors encountered during evaluation.
|
|
176
|
+
*/
|
|
177
|
+
export class Diagnostics {
|
|
178
|
+
/**
|
|
179
|
+
* `PolicyId`s of the policies that contributed to the decision.
|
|
180
|
+
* If no policies applied to the request, this set will be empty.
|
|
181
|
+
*
|
|
182
|
+
* The ids should be treated as unordered,
|
|
183
|
+
*/
|
|
184
|
+
readonly reason: (string)[];
|
|
185
|
+
/**
|
|
186
|
+
* Errors that occurred during authorization. The errors should be
|
|
187
|
+
* treated as unordered, since policies may be evaluated in any order.
|
|
188
|
+
*/
|
|
189
|
+
readonly errors: (PolicyEvaluationError)[];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* PolicyEvaluationError
|
|
194
|
+
* =====================
|
|
195
|
+
*
|
|
196
|
+
* Represents an error that occurred when evaluating a Cedar policy.
|
|
197
|
+
*/
|
|
198
|
+
export class PolicyEvaluationError {
|
|
199
|
+
/**
|
|
200
|
+
* Id of the policy with an error
|
|
201
|
+
*/
|
|
202
|
+
readonly id: string;
|
|
203
|
+
/**
|
|
204
|
+
* Underlying evaluation error string representation
|
|
205
|
+
*/
|
|
206
|
+
readonly error: string;
|
|
207
|
+
}
|
|
208
|
+
```
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Create a new instance of the Cedarling application.
|
|
5
|
+
* This function can take as config parameter the eather `Map` other `Object`
|
|
6
|
+
*/
|
|
7
|
+
export function init(config: any): Promise<Cedarling>;
|
|
8
|
+
/**
|
|
9
|
+
* A WASM wrapper for the Rust `cedarling::AuthorizeResult` struct.
|
|
10
|
+
* Represents the result of an authorization request.
|
|
11
|
+
*/
|
|
12
|
+
export class AuthorizeResult {
|
|
13
|
+
private constructor();
|
|
14
|
+
free(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Convert `AuthorizeResult` to json string value
|
|
17
|
+
*/
|
|
18
|
+
json_string(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Result of authorization where principal is `Jans::Workload`
|
|
21
|
+
*/
|
|
22
|
+
get workload(): AuthorizeResultResponse | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Result of authorization where principal is `Jans::Workload`
|
|
25
|
+
*/
|
|
26
|
+
set workload(value: AuthorizeResultResponse | null | undefined);
|
|
27
|
+
/**
|
|
28
|
+
* Result of authorization where principal is `Jans::User`
|
|
29
|
+
*/
|
|
30
|
+
get person(): AuthorizeResultResponse | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Result of authorization where principal is `Jans::User`
|
|
33
|
+
*/
|
|
34
|
+
set person(value: AuthorizeResultResponse | null | undefined);
|
|
35
|
+
/**
|
|
36
|
+
* Result of authorization
|
|
37
|
+
* true means `ALLOW`
|
|
38
|
+
* false means `Deny`
|
|
39
|
+
*
|
|
40
|
+
* this field is [`bool`] type to be compatible with [authzen Access Evaluation Decision](https://openid.github.io/authzen/#section-6.2.1).
|
|
41
|
+
*/
|
|
42
|
+
decision: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Request ID of the authorization request
|
|
45
|
+
*/
|
|
46
|
+
request_id: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A WASM wrapper for the Rust `cedar_policy::Response` struct.
|
|
50
|
+
* Represents the result of an authorization request.
|
|
51
|
+
*/
|
|
52
|
+
export class AuthorizeResultResponse {
|
|
53
|
+
private constructor();
|
|
54
|
+
free(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Authorization decision
|
|
57
|
+
*/
|
|
58
|
+
readonly decision: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Diagnostics providing more information on how this decision was reached
|
|
61
|
+
*/
|
|
62
|
+
readonly diagnostics: Diagnostics;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The instance of the Cedarling application.
|
|
66
|
+
*/
|
|
67
|
+
export class Cedarling {
|
|
68
|
+
private constructor();
|
|
69
|
+
free(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Create a new instance of the Cedarling application.
|
|
72
|
+
* Assume that config is `Object`
|
|
73
|
+
*/
|
|
74
|
+
static new(config: object): Promise<Cedarling>;
|
|
75
|
+
/**
|
|
76
|
+
* Create a new instance of the Cedarling application.
|
|
77
|
+
* Assume that config is `Map`
|
|
78
|
+
*/
|
|
79
|
+
static new_from_map(config: Map<any, any>): Promise<Cedarling>;
|
|
80
|
+
/**
|
|
81
|
+
* Authorize request
|
|
82
|
+
* makes authorization decision based on the [`Request`]
|
|
83
|
+
*/
|
|
84
|
+
authorize(request: any): Promise<AuthorizeResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Get logs and remove them from the storage.
|
|
87
|
+
* Returns `Array` of `Map`
|
|
88
|
+
*/
|
|
89
|
+
pop_logs(): Array<any>;
|
|
90
|
+
/**
|
|
91
|
+
* Get specific log entry.
|
|
92
|
+
* Returns `Map` with values or `null`.
|
|
93
|
+
*/
|
|
94
|
+
get_log_by_id(id: string): any;
|
|
95
|
+
/**
|
|
96
|
+
* Returns a list of all log ids.
|
|
97
|
+
* Returns `Array` of `String`
|
|
98
|
+
*/
|
|
99
|
+
get_log_ids(): Array<any>;
|
|
100
|
+
/**
|
|
101
|
+
* Get logs by tag, like `log_kind` or `log level`.
|
|
102
|
+
* Tag can be `log_kind`, `log_level`.
|
|
103
|
+
*/
|
|
104
|
+
get_logs_by_tag(tag: string): any[];
|
|
105
|
+
/**
|
|
106
|
+
* Get logs by request_id.
|
|
107
|
+
* Return log entries that match the given request_id.
|
|
108
|
+
*/
|
|
109
|
+
get_logs_by_request_id(request_id: string): any[];
|
|
110
|
+
/**
|
|
111
|
+
* Get log by request_id and tag, like composite key `request_id` + `log_kind`.
|
|
112
|
+
* Tag can be `log_kind`, `log_level`.
|
|
113
|
+
* Return log entries that match the given request_id and tag.
|
|
114
|
+
*/
|
|
115
|
+
get_logs_by_request_id_and_tag(request_id: string, tag: string): any[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Diagnostics
|
|
119
|
+
* ===========
|
|
120
|
+
*
|
|
121
|
+
* Provides detailed information about how a policy decision was made, including policies that contributed to the decision and any errors encountered during evaluation.
|
|
122
|
+
*/
|
|
123
|
+
export class Diagnostics {
|
|
124
|
+
private constructor();
|
|
125
|
+
free(): void;
|
|
126
|
+
/**
|
|
127
|
+
* `PolicyId`s of the policies that contributed to the decision.
|
|
128
|
+
* If no policies applied to the request, this set will be empty.
|
|
129
|
+
*
|
|
130
|
+
* The ids should be treated as unordered,
|
|
131
|
+
*/
|
|
132
|
+
readonly reason: string[];
|
|
133
|
+
/**
|
|
134
|
+
* Errors that occurred during authorization. The errors should be
|
|
135
|
+
* treated as unordered, since policies may be evaluated in any order.
|
|
136
|
+
*/
|
|
137
|
+
readonly errors: PolicyEvaluationError[];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* PolicyEvaluationError
|
|
141
|
+
* =====================
|
|
142
|
+
*
|
|
143
|
+
* Represents an error that occurred when evaluating a Cedar policy.
|
|
144
|
+
*/
|
|
145
|
+
export class PolicyEvaluationError {
|
|
146
|
+
private constructor();
|
|
147
|
+
free(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Id of the policy with an error
|
|
150
|
+
*/
|
|
151
|
+
readonly id: string;
|
|
152
|
+
/**
|
|
153
|
+
* Underlying evaluation error string representation
|
|
154
|
+
*/
|
|
155
|
+
readonly error: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
159
|
+
|
|
160
|
+
export interface InitOutput {
|
|
161
|
+
readonly memory: WebAssembly.Memory;
|
|
162
|
+
readonly __wbg_cedarling_free: (a: number, b: number) => void;
|
|
163
|
+
readonly init: (a: number) => number;
|
|
164
|
+
readonly cedarling_new: (a: number) => number;
|
|
165
|
+
readonly cedarling_new_from_map: (a: number) => number;
|
|
166
|
+
readonly cedarling_authorize: (a: number, b: number) => number;
|
|
167
|
+
readonly cedarling_pop_logs: (a: number, b: number) => void;
|
|
168
|
+
readonly cedarling_get_log_by_id: (a: number, b: number, c: number, d: number) => void;
|
|
169
|
+
readonly cedarling_get_log_ids: (a: number) => number;
|
|
170
|
+
readonly cedarling_get_logs_by_tag: (a: number, b: number, c: number, d: number) => void;
|
|
171
|
+
readonly cedarling_get_logs_by_request_id: (a: number, b: number, c: number, d: number) => void;
|
|
172
|
+
readonly cedarling_get_logs_by_request_id_and_tag: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
173
|
+
readonly __wbg_authorizeresult_free: (a: number, b: number) => void;
|
|
174
|
+
readonly __wbg_get_authorizeresult_workload: (a: number) => number;
|
|
175
|
+
readonly __wbg_set_authorizeresult_workload: (a: number, b: number) => void;
|
|
176
|
+
readonly __wbg_get_authorizeresult_person: (a: number) => number;
|
|
177
|
+
readonly __wbg_set_authorizeresult_person: (a: number, b: number) => void;
|
|
178
|
+
readonly __wbg_get_authorizeresult_decision: (a: number) => number;
|
|
179
|
+
readonly __wbg_set_authorizeresult_decision: (a: number, b: number) => void;
|
|
180
|
+
readonly __wbg_get_authorizeresult_request_id: (a: number, b: number) => void;
|
|
181
|
+
readonly __wbg_set_authorizeresult_request_id: (a: number, b: number, c: number) => void;
|
|
182
|
+
readonly authorizeresult_json_string: (a: number, b: number) => void;
|
|
183
|
+
readonly __wbg_authorizeresultresponse_free: (a: number, b: number) => void;
|
|
184
|
+
readonly authorizeresultresponse_decision: (a: number) => number;
|
|
185
|
+
readonly authorizeresultresponse_diagnostics: (a: number) => number;
|
|
186
|
+
readonly __wbg_diagnostics_free: (a: number, b: number) => void;
|
|
187
|
+
readonly diagnostics_reason: (a: number, b: number) => void;
|
|
188
|
+
readonly diagnostics_errors: (a: number, b: number) => void;
|
|
189
|
+
readonly __wbg_policyevaluationerror_free: (a: number, b: number) => void;
|
|
190
|
+
readonly policyevaluationerror_id: (a: number, b: number) => void;
|
|
191
|
+
readonly policyevaluationerror_error: (a: number, b: number) => void;
|
|
192
|
+
readonly ring_core_0_17_8_bn_mul_mont: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
193
|
+
readonly __wbindgen_export_0: (a: number) => void;
|
|
194
|
+
readonly __wbindgen_export_1: (a: number, b: number) => number;
|
|
195
|
+
readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
|
|
196
|
+
readonly __wbindgen_export_3: WebAssembly.Table;
|
|
197
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
198
|
+
readonly __wbindgen_export_4: (a: number, b: number, c: number) => void;
|
|
199
|
+
readonly __wbindgen_export_5: (a: number, b: number, c: number) => void;
|
|
200
|
+
readonly __wbindgen_export_6: (a: number, b: number, c: number, d: number) => void;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
204
|
+
/**
|
|
205
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
206
|
+
* a precompiled `WebAssembly.Module`.
|
|
207
|
+
*
|
|
208
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
209
|
+
*
|
|
210
|
+
* @returns {InitOutput}
|
|
211
|
+
*/
|
|
212
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
216
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
217
|
+
*
|
|
218
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
219
|
+
*
|
|
220
|
+
* @returns {Promise<InitOutput>}
|
|
221
|
+
*/
|
|
222
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|