Skip to content

Commit

Permalink
Merge pull request #208 from textileio/asutula/pow-1.1.0
Browse files Browse the repository at this point in the history
Update to powergate 1.1.0
  • Loading branch information
asutula authored Nov 11, 2020
2 parents 29110f3 + 2fd0edd commit 015e132
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 298 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const host = "http://0.0.0.0:6002" // or whatever powergate instance you want
const pow = createPow({ host })
```

Most Powergate APIs require authorization in the form of a Storage Profile auth token. Storage Profiles are created using the `admin` API. Powergate's backend may be configured to secure the `admin` API with an auth token, and in that case, you'll neeed to set the admin auth token on the client as shown below.
Most Powergate APIs require authorization in the form of a user auth token. Users are created using the `admin` API. Powergate's backend may be configured to secure the `admin` API with an auth token, and in that case, you'll neeed to set the admin auth token on the client as shown below.

```typescript
import { createPow } from "@textile/powergate-client"
Expand All @@ -62,14 +62,14 @@ const pow = createPow({ host })
pow.setAdminToken("<an admin auth token>")

async function exampleCode () {
const { authEntry } = await pow.admin.profiles.createStorageProfile() // save this token for later use!
return authEntry?.token
const { user } = await pow.admin.users.create() // save this token for later use!
return user?.token
}
```

The returned auth token is the only thing that gives access to the corresponding Storage Profile at a later time, so be sure to save it securely.
The returned auth token is the only thing that gives access to the corresponding user at a later time, so be sure to save it securely.

A Storage Profile auth token can later be set for the Powergate client so that the client authenticates with the Storage Profile associated with the auth token.
A user auth token can later be set for the Powergate client so that the client authenticates with the user associated with the auth token.

```typescript
import { createPow } from "@textile/powergate-client"
Expand All @@ -78,7 +78,7 @@ const host = "http://0.0.0.0:6002" // or whatever powergate instance you want

const pow = createPow({ host })

const token = "<previously generated storage profile auth token>"
const token = "<previously generated user auth token>"

pow.setToken(token)
```
Expand All @@ -94,10 +94,10 @@ const host = "http://0.0.0.0:6002" // or whatever powergate instance you want
const pow = createPow({ host })

async function exampleCode() {
// get wallet addresses associated with your storage profile
// get wallet addresses associated with the user
const { addressesList } = await pow.wallet.addresses()

// create a new address associated with your storage profile
// create a new address associated with the user
const { address } = await pow.wallet.newAddress("my new address")

// get build information about the powergate server
Expand Down Expand Up @@ -130,10 +130,10 @@ async function exampleCode() {
// current storage state, and all related Powegate storage jobs
const { cidInfosList } = await pow.data.cidInfo(cid)

// retrieve data stored in the storage profile by cid
// retrieve data stored in the user by cid
const bytes = await pow.data.get(cid)

// send FIL from an address managed by your storage profile to any other address
// send FIL from an address managed by the user to any other address
await pow.wallet.sendFil(addressesList[0].address, "<some other address>", BigInt(1000))
}
```
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
},
"dependencies": {
"@textile/grpc-powergate-client": "1.0.0",
"@textile/grpc-powergate-client": "1.1.0",
"@textile/grpc-transport": "0.0.3",
"ipfs-http-client": "^47.0.1",
"it-block": "^2.0.0"
Expand Down
10 changes: 5 additions & 5 deletions src/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { grpc } from "@improbable-eng/grpc-web"
import { Config } from "../types"
import { createProfiles, Profiles } from "./profiles"
import { createStorageJobs, StorageJobs } from "./storage-jobs"
import { createUsers, Users } from "./users"
import { createWallet, Wallet } from "./wallet"
export { Profiles, StorageJobs, Wallet }
export { Users, StorageJobs, Wallet }

export interface Admin {
/**
* The admin Profiles API.
* The admin Users API.
*/
profiles: Profiles
users: Users

/**
* The admin Wallet API.
Expand All @@ -27,7 +27,7 @@ export interface Admin {
*/
export const createAdmin = (config: Config, getMeta: () => grpc.Metadata): Admin => {
return {
profiles: createProfiles(config, getMeta),
users: createUsers(config, getMeta),
wallet: createWallet(config, getMeta),
storageJobs: createStorageJobs(config, getMeta),
}
Expand Down
45 changes: 0 additions & 45 deletions src/admin/profiles.ts

This file was deleted.

49 changes: 23 additions & 26 deletions src/admin/storage-jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,112 +10,109 @@ import {
QueuedStorageJobsResponse,
StorageJobsSummaryRequest,
StorageJobsSummaryResponse,
} from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb"
import { PowergateAdminServiceClient } from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb_service"
} from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb"
import { AdminServiceClient } from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb_service"
import { Config } from "../types"
import { promise } from "../util"

export interface StorageJobs {
/**
* List queued storgae jobs.
* @param profileId The storage profile id to query or an empty string for all storage profiles.
* @param userId The user id to query or an empty string for all users.
* @param cids An optional list of data cids to fileter the results with.
* @returns A list of queued storage jobs.
*/
queued: (profileId: string, ...cids: string[]) => Promise<QueuedStorageJobsResponse.AsObject>
queued: (userId: string, ...cids: string[]) => Promise<QueuedStorageJobsResponse.AsObject>

/**
* List executing storgae jobs.
* @param profileId The storage profile id to query or an empty string for all storage profiles.
* @param userId The user id to query or an empty string for all users.
* @param cids An optional list of data cids to fileter the results with.
* @returns A list of executing storage jobs.
*/
executing: (
profileId: string,
...cids: string[]
) => Promise<ExecutingStorageJobsResponse.AsObject>
executing: (userId: string, ...cids: string[]) => Promise<ExecutingStorageJobsResponse.AsObject>

/**
* List the latest final storgae jobs.
* @param profileId The storage profile id to query or an empty string for all storage profiles.
* @param userId The user id to query or an empty string for all users.
* @param cids An optional list of data cids to fileter the results with.
* @returns A list of the latest final storage jobs.
*/
latestFinal: (
profileId: string,
userId: string,
...cids: string[]
) => Promise<LatestFinalStorageJobsResponse.AsObject>

/**
* List the latest successful storgae jobs.
* @param profileId The storage profile id to query or an empty string for all storage profiles.
* @param userId The user id to query or an empty string for all users.
* @param cids An optional list of data cids to fileter the results with.
* @returns A list of the latest successful storage jobs.
*/
latestSuccessful: (
profileId: string,
userId: string,
...cids: string[]
) => Promise<LatestSuccessfulStorageJobsResponse.AsObject>

/**
* Get a summary of all jobs.
* @param profileId The storage profile id to query or an empty string for all storage profiles.
* @param userId The user id to query or an empty string for all users.
* @param cids An optional list of data cids to fileter the results with.
* @returns A summary of all jobs.
*/
summary: (profileId: string, ...cids: string[]) => Promise<StorageJobsSummaryResponse.AsObject>
summary: (userId: string, ...cids: string[]) => Promise<StorageJobsSummaryResponse.AsObject>
}

/**
* @ignore
*/
export const createStorageJobs = (config: Config, getMeta: () => grpc.Metadata): StorageJobs => {
const client = new PowergateAdminServiceClient(config.host, config)
const client = new AdminServiceClient(config.host, config)
return {
queued: (profileId: string, ...cids: string[]) => {
queued: (userId: string, ...cids: string[]) => {
const req = new QueuedStorageJobsRequest()
req.setCidsList(cids)
req.setProfileId(profileId)
req.setUserId(userId)
return promise(
(cb) => client.queuedStorageJobs(req, getMeta(), cb),
(resp: QueuedStorageJobsResponse) => resp.toObject(),
)
},

executing: (profileId: string, ...cids: string[]) => {
executing: (userId: string, ...cids: string[]) => {
const req = new ExecutingStorageJobsRequest()
req.setCidsList(cids)
req.setProfileId(profileId)
req.setUserId(userId)
return promise(
(cb) => client.executingStorageJobs(req, getMeta(), cb),
(resp: ExecutingStorageJobsResponse) => resp.toObject(),
)
},

latestFinal: (profileId: string, ...cids: string[]) => {
latestFinal: (userId: string, ...cids: string[]) => {
const req = new LatestFinalStorageJobsRequest()
req.setCidsList(cids)
req.setProfileId(profileId)
req.setUserId(userId)
return promise(
(cb) => client.latestFinalStorageJobs(req, getMeta(), cb),
(resp: LatestFinalStorageJobsResponse) => resp.toObject(),
)
},

latestSuccessful: (profileId: string, ...cids: string[]) => {
latestSuccessful: (userId: string, ...cids: string[]) => {
const req = new LatestSuccessfulStorageJobsRequest()
req.setCidsList(cids)
req.setProfileId(profileId)
req.setUserId(userId)
return promise(
(cb) => client.latestSuccessfulStorageJobs(req, getMeta(), cb),
(resp: LatestSuccessfulStorageJobsResponse) => resp.toObject(),
)
},

summary: (profileId: string, ...cids: string[]) => {
summary: (userId: string, ...cids: string[]) => {
const req = new StorageJobsSummaryRequest()
req.setCidsList(cids)
req.setProfileId(profileId)
req.setUserId(userId)
return promise(
(cb) => client.storageJobsSummary(req, getMeta(), cb),
(resp: StorageJobsSummaryResponse) => resp.toObject(),
Expand Down
45 changes: 45 additions & 0 deletions src/admin/users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { grpc } from "@improbable-eng/grpc-web"
import {
CreateUserRequest,
CreateUserResponse,
UsersRequest,
UsersResponse,
} from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb"
import { AdminServiceClient } from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb_service"
import { Config } from "../types"
import { promise } from "../util"

export interface Users {
/**
* Create a new user.
* @returns Information about the new user.
*/
create: () => Promise<CreateUserResponse.AsObject>

/**
* List all users.
* @returns A list of all users.
*/
list: () => Promise<UsersResponse.AsObject>
}

/**
* @ignore
*/
export const createUsers = (config: Config, getMeta: () => grpc.Metadata): Users => {
const client = new AdminServiceClient(config.host, config)
return {
create: () => {
return promise(
(cb) => client.createUser(new CreateUserRequest(), getMeta(), cb),
(resp: CreateUserResponse) => resp.toObject(),
)
},

list: () =>
promise(
(cb) => client.users(new UsersRequest(), getMeta(), cb),
(resp: UsersResponse) => resp.toObject(),
),
}
}
6 changes: 3 additions & 3 deletions src/admin/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
NewAddressResponse,
SendFilRequest,
SendFilResponse,
} from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb"
import { PowergateAdminServiceClient } from "@textile/grpc-powergate-client/dist/proto/admin/v1/powergate_admin_pb_service"
} from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb"
import { AdminServiceClient } from "@textile/grpc-powergate-client/dist/powergate/admin/v1/admin_pb_service"
import { Config } from "../types"
import { promise } from "../util"

Expand Down Expand Up @@ -38,7 +38,7 @@ export interface Wallet {
* @ignore
*/
export const createWallet = (config: Config, getMeta: () => grpc.Metadata): Wallet => {
const client = new PowergateAdminServiceClient(config.host, config)
const client = new AdminServiceClient(config.host, config)
return {
newAddress: (type: "bls" | "secp256k1" = "bls") => {
const req = new NewAddressRequest()
Expand Down
Loading

0 comments on commit 015e132

Please sign in to comment.