Skip to content

Commit

Permalink
feat: allow permissions read_attach on token (#21)
Browse files Browse the repository at this point in the history
* feat: allow permissions read_attach on token

* docs(readme): attach read_attach example
  • Loading branch information
notrab authored Jun 16, 2024
1 parent 88420d5 commit 5d8691e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const token = await turso.groups.createToken("default", {
expiration: "1w2d6h3m",
authorization: "full-access",
});
const token = await turso.groups.createToken("default", {
permissions: {
read_attach: {
databases: ["db1", "db2"]
}
}
});
const token = await turso.groups.rotateTokens("default");
```

Expand Down Expand Up @@ -102,6 +109,13 @@ const token = await turso.databases.createToken("my-db", {
expiration: "1w2d6h3n",
authorization: "full-access",
});
const token = await turso.databases.createToken("my-db", {
permissions: {
read_attach: {
databases: ["db1", "db2"]
}
}
});
const token = await turso.databases.rotateTokens("my-db");

const usageStatsWithDate = await turso.databases.usage("my-db");
Expand Down
10 changes: 10 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ export class DatabaseClient {
options?: {
expiration: string;
authorization: "read-only" | "full-access";
permissions?: {
read_attach: { databases: Database["name"][] };
};
}
): Promise<DatabaseToken> {
const queryParams = new URLSearchParams();
Expand All @@ -229,6 +232,13 @@ export class DatabaseClient {
this.config,
{
method: "POST",
body: JSON.stringify({
permissions: {
read_attach: {
databases: options?.permissions?.read_attach?.databases ?? [],
},
},
}),
}
);

Expand Down
11 changes: 11 additions & 0 deletions src/group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TursoConfig } from "./config";
import { LocationKeys } from "./location";
import { TursoClient } from "./client";
import type { Database } from "./database";

export interface Group {
locations: Array<keyof LocationKeys>;
Expand Down Expand Up @@ -116,6 +117,9 @@ export class GroupClient {
options?: {
expiration: string;
authorization: "read-only" | "full-access";
permissions?: {
read_attach: { databases: Database["name"][] };
};
}
): Promise<GroupToken> {
const queryParams = new URLSearchParams();
Expand All @@ -133,6 +137,13 @@ export class GroupClient {
this.config,
{
method: "POST",
body: JSON.stringify({
permissions: {
read_attach: {
databases: options?.permissions?.read_attach?.databases ?? [],
},
},
}),
}
);

Expand Down

0 comments on commit 5d8691e

Please sign in to comment.