mirror of
https://github.com/denoland/deno.git
synced 2024-11-29 16:30:56 -05:00
parent
54d897c140
commit
1437838ea1
1 changed files with 19 additions and 19 deletions
|
@ -16,26 +16,26 @@ On the CLI, read permission for `/foo/bar` is represented as
|
||||||
`--allow-read=/foo/bar`. In runtime JS, it is represented as the following:
|
`--allow-read=/foo/bar`. In runtime JS, it is represented as the following:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const desc = { name: "read", path: "/foo/bar" };
|
const desc = { name: "read", path: "/foo/bar" } as const;
|
||||||
```
|
```
|
||||||
|
|
||||||
Other examples:
|
Other examples:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// Global write permission.
|
// Global write permission.
|
||||||
const desc1 = { name: "write" };
|
const desc1 = { name: "write" } as const;
|
||||||
|
|
||||||
// Write permission to `$PWD/foo/bar`.
|
// Write permission to `$PWD/foo/bar`.
|
||||||
const desc2 = { name: "write", path: "foo/bar" };
|
const desc2 = { name: "write", path: "foo/bar" } as const;
|
||||||
|
|
||||||
// Global net permission.
|
// Global net permission.
|
||||||
const desc3 = { name: "net" };
|
const desc3 = { name: "net" } as const;
|
||||||
|
|
||||||
// Net permission to 127.0.0.1:8000.
|
// Net permission to 127.0.0.1:8000.
|
||||||
const desc4 = { name: "net", url: "127.0.0.1:8000" };
|
const desc4 = { name: "net", url: "127.0.0.1:8000" } as const;
|
||||||
|
|
||||||
// High-resolution time permission.
|
// High-resolution time permission.
|
||||||
const desc5 = { name: "hrtime" };
|
const desc5 = { name: "hrtime" } as const;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Query permissions
|
### Query permissions
|
||||||
|
@ -45,15 +45,15 @@ Check, by descriptor, if a permission is granted or not.
|
||||||
```ts
|
```ts
|
||||||
// deno run --unstable --allow-read=/foo main.ts
|
// deno run --unstable --allow-read=/foo main.ts
|
||||||
|
|
||||||
const desc1 = { name: "read", path: "/foo" };
|
const desc1 = { name: "read", path: "/foo" } as const;
|
||||||
console.log(await Deno.permissions.query(desc1));
|
console.log(await Deno.permissions.query(desc1));
|
||||||
// PermissionStatus { state: "granted" }
|
// PermissionStatus { state: "granted" }
|
||||||
|
|
||||||
const desc2 = { name: "read", path: "/foo/bar" };
|
const desc2 = { name: "read", path: "/foo/bar" } as const;
|
||||||
console.log(await Deno.permissions.query(desc2));
|
console.log(await Deno.permissions.query(desc2));
|
||||||
// PermissionStatus { state: "granted" }
|
// PermissionStatus { state: "granted" }
|
||||||
|
|
||||||
const desc3 = { name: "read", path: "/bar" };
|
const desc3 = { name: "read", path: "/bar" } as const;
|
||||||
console.log(await Deno.permissions.query(desc3));
|
console.log(await Deno.permissions.query(desc3));
|
||||||
// PermissionStatus { state: "prompt" }
|
// PermissionStatus { state: "prompt" }
|
||||||
```
|
```
|
||||||
|
@ -82,13 +82,13 @@ _[stronger than](https://www.w3.org/TR/permissions/#ref-for-permissiondescriptor
|
||||||
More examples:
|
More examples:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const desc1 = { name: "write" };
|
const desc1 = { name: "write" } as const;
|
||||||
// is stronger than
|
// is stronger than
|
||||||
const desc2 = { name: "write", path: "/foo" };
|
const desc2 = { name: "write", path: "/foo" } as const;
|
||||||
|
|
||||||
const desc3 = { name: "net" };
|
const desc3 = { name: "net" } as const;
|
||||||
// is stronger than
|
// is stronger than
|
||||||
const desc4 = { name: "net", url: "127.0.0.1:8000" };
|
const desc4 = { name: "net", url: "127.0.0.1:8000" } as const;
|
||||||
```
|
```
|
||||||
|
|
||||||
### Request permissions
|
### Request permissions
|
||||||
|
@ -98,13 +98,13 @@ Request an ungranted permission from the user via CLI prompt.
|
||||||
```ts
|
```ts
|
||||||
// deno run --unstable main.ts
|
// deno run --unstable main.ts
|
||||||
|
|
||||||
const desc1 = { name: "read", path: "/foo" };
|
const desc1 = { name: "read", path: "/foo" } as const;
|
||||||
const status1 = await Deno.permissions.request(desc1);
|
const status1 = await Deno.permissions.request(desc1);
|
||||||
// ⚠️ Deno requests read access to "/foo". Grant? [g/d (g = grant, d = deny)] g
|
// ⚠️ Deno requests read access to "/foo". Grant? [g/d (g = grant, d = deny)] g
|
||||||
console.log(status1);
|
console.log(status1);
|
||||||
// PermissionStatus { state: "granted" }
|
// PermissionStatus { state: "granted" }
|
||||||
|
|
||||||
const desc2 = { name: "read", path: "/bar" };
|
const desc2 = { name: "read", path: "/bar" } as const;
|
||||||
const status2 = await Deno.permissions.request(desc2);
|
const status2 = await Deno.permissions.request(desc2);
|
||||||
// ⚠️ Deno requests read access to "/bar". Grant? [g/d (g = grant, d = deny)] d
|
// ⚠️ Deno requests read access to "/bar". Grant? [g/d (g = grant, d = deny)] d
|
||||||
console.log(status2);
|
console.log(status2);
|
||||||
|
@ -129,7 +129,7 @@ Downgrade a permission from "granted" to "prompt".
|
||||||
```ts
|
```ts
|
||||||
// deno run --unstable --allow-read=/foo main.ts
|
// deno run --unstable --allow-read=/foo main.ts
|
||||||
|
|
||||||
const desc = { name: "read", path: "/foo" };
|
const desc = { name: "read", path: "/foo" } as const;
|
||||||
console.log(await Deno.permissions.revoke(desc));
|
console.log(await Deno.permissions.revoke(desc));
|
||||||
// PermissionStatus { state: "prompt" }
|
// PermissionStatus { state: "prompt" }
|
||||||
```
|
```
|
||||||
|
@ -140,7 +140,7 @@ one granted on the CLI?
|
||||||
```ts
|
```ts
|
||||||
// deno run --unstable --allow-read=/foo main.ts
|
// deno run --unstable --allow-read=/foo main.ts
|
||||||
|
|
||||||
const desc = { name: "read", path: "/foo/bar" };
|
const desc = { name: "read", path: "/foo/bar" } as const;
|
||||||
console.log(await Deno.permissions.revoke(desc));
|
console.log(await Deno.permissions.revoke(desc));
|
||||||
// PermissionStatus { state: "granted" }
|
// PermissionStatus { state: "granted" }
|
||||||
```
|
```
|
||||||
|
@ -177,11 +177,11 @@ whichever _explicitly granted permission descriptor_ is _stronger than_ `desc`.
|
||||||
```ts
|
```ts
|
||||||
// deno run --unstable --allow-read=/foo main.ts
|
// deno run --unstable --allow-read=/foo main.ts
|
||||||
|
|
||||||
const desc = { name: "read", path: "/foo/bar" };
|
const desc = { name: "read", path: "/foo/bar" } as const;
|
||||||
console.log(await Deno.permissions.revoke(desc)); // Insufficient.
|
console.log(await Deno.permissions.revoke(desc)); // Insufficient.
|
||||||
// PermissionStatus { state: "granted" }
|
// PermissionStatus { state: "granted" }
|
||||||
|
|
||||||
const strongDesc = { name: "read", path: "/foo" };
|
const strongDesc = { name: "read", path: "/foo" } as const;
|
||||||
await Deno.permissions.revoke(strongDesc); // Good.
|
await Deno.permissions.revoke(strongDesc); // Good.
|
||||||
|
|
||||||
console.log(await Deno.permissions.query(desc));
|
console.log(await Deno.permissions.query(desc));
|
||||||
|
|
Loading…
Reference in a new issue