Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API nits + refactor #704

Merged
merged 5 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ GO ?= $(shell which go)
# @echo "Running buf"
# @$(BUF) <flags/args..>
#
BUF := $(GOBIN)/buf-v0.20.5
BUF := $(GOBIN)/buf-v0.30.0
$(BUF): .bingo/buf.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/buf-v0.20.5"
@cd .bingo && $(GO) build -modfile=buf.mod -o=$(GOBIN)/buf-v0.20.5 "github.com/bufbuild/buf/cmd/buf"
@echo "(re)installing $(GOBIN)/buf-v0.30.0"
@cd .bingo && $(GO) build -modfile=buf.mod -o=$(GOBIN)/buf-v0.30.0 "github.com/bufbuild/buf/cmd/buf"

GOMPLATE := $(GOBIN)/gomplate-v3.8.0
$(GOMPLATE): .bingo/gomplate.mod
Expand Down Expand Up @@ -52,3 +52,15 @@ $(PROTOC_GEN_BUF_CHECK_LINT): .bingo/protoc-gen-buf-check-lint.mod
@echo "(re)installing $(GOBIN)/protoc-gen-buf-check-lint-v0.20.5"
@cd .bingo && $(GO) build -modfile=protoc-gen-buf-check-lint.mod -o=$(GOBIN)/protoc-gen-buf-check-lint-v0.20.5 "github.com/bufbuild/buf/cmd/protoc-gen-buf-check-lint"

PROTOC_GEN_GO_GRPC := $(GOBIN)/protoc-gen-go-grpc-v1.0.1
$(PROTOC_GEN_GO_GRPC): .bingo/protoc-gen-go-grpc.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/protoc-gen-go-grpc-v1.0.1"
@cd .bingo && $(GO) build -modfile=protoc-gen-go-grpc.mod -o=$(GOBIN)/protoc-gen-go-grpc-v1.0.1 "google.golang.org/grpc/cmd/protoc-gen-go-grpc"

PROTOC_GEN_GO := $(GOBIN)/protoc-gen-go-v1.25.0
$(PROTOC_GEN_GO): .bingo/protoc-gen-go.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/protoc-gen-go-v1.25.0"
@cd .bingo && $(GO) build -modfile=protoc-gen-go.mod -o=$(GOBIN)/protoc-gen-go-v1.25.0 "google.golang.org/protobuf/cmd/protoc-gen-go"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protoc-gen-go and protoc-gen-go-grpc now managed by and accessed through bingo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

2 changes: 1 addition & 1 deletion .bingo/buf.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.14

require github.com/bufbuild/buf v0.20.5 // cmd/buf
require github.com/bufbuild/buf v0.30.0 // cmd/buf
5 changes: 5 additions & 0 deletions .bingo/protoc-gen-go-grpc.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.14

require google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.0.1
5 changes: 5 additions & 0 deletions .bingo/protoc-gen-go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.14

require google.golang.org/protobuf v1.25.0 // cmd/protoc-gen-go
6 changes: 5 additions & 1 deletion .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if [ -z "$gobin" ]; then
fi


BUF="${gobin}/buf-v0.20.5"
BUF="${gobin}/buf-v0.30.0"

GOMPLATE="${gobin}/gomplate-v3.8.0"

Expand All @@ -20,3 +20,7 @@ PROTOC_GEN_BUF_CHECK_BREAKING="${gobin}/protoc-gen-buf-check-breaking-v0.20.5"

PROTOC_GEN_BUF_CHECK_LINT="${gobin}/protoc-gen-buf-check-lint-v0.20.5"

PROTOC_GEN_GO_GRPC="${gobin}/protoc-gen-go-grpc-v1.0.1"

PROTOC_GEN_GO="${gobin}/protoc-gen-go-v1.25.0"

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
replace-with: ""
- name: Generate JS gRPC bindings
run: |
./scripts/gen-js-protos.sh ${{steps.makeversion.outputs.replaced}} . ./js-grpc
./scripts/gen-js-protos.sh ${{steps.makeversion.outputs.replaced}} ./proto ./js-grpc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./proto/ is now the "root" of our proto files... ./proto/ itself is not part of the proto path, it's just the container for all protos and the actual proto paths are relative to this root.

- name: Publish JS gRPC bindings
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
# vscode config folder
.vscode/

buildtools/protoc
buildtools/protoc-gen-go

# File names that can be used for testing.
new
myfile
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ clean-protos:
find . -type f -name '*pb_test.go' -delete
.PHONY: clean-protos

install-protoc:
cd buildtools && ./protocInstall.sh

PROTOCGENGO=$(shell pwd)/buildtools/protoc-gen-go
protos: install-protoc clean-protos
PATH=$(PROTOCGENGO):$(PATH) ./scripts/protoc_gen_plugin.bash --proto_path=. --plugin_name=go --plugin_out=. --plugin_opt=plugins=grpc,paths=source_relative
protos: $(BUF) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) clean-protos
$(BUF) generate --template '{"version":"v1beta1","plugins":[{"name":"go","out":"api/gen","opt":"paths=source_relative","path":$(PROTOC_GEN_GO)},{"name":"go-grpc","out":"api/gen","opt":"paths=source_relative","path":$(PROTOC_GEN_GO_GRPC)}]}'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using buf to generate the Go protos. buf actually supports configuring this via a config file, which is really nice, but I needed to pass the location of the buf, protoc-gen-go, and protoc-gen-go-grpc binaries managed by Bingo in dynamically, so I instead used buf's flag for passing the config in as json on the command line.

Comment on lines -85 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the protocInstall.sh was a stretch, this looks more maintainable.

.PHONY: protos

# local is what we run when testing locally.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ Available Commands:
data Provides commands to interact with general data APIs
deals Provides commands to view Filecoin deal information
help Help about any command
id Returns the storage profile id
id Returns the user id
storage-jobs Provides commands to query for storage jobs in various states
version Display version information for pow and the connected server
wallet Provides commands about filecoin wallets

Flags:
-h, --help help for pow
--serverAddress string address of the powergate service api (default "127.0.0.1:5002")
-t, --token string storage profile auth token
-t, --token string user auth token
-v, --version display version information for pow and the connected server

Use "pow [command] --help" for more information about a command.
Expand Down Expand Up @@ -203,9 +203,9 @@ Terminal 2:
```bash
make build
❯ head -c 700 </dev/urandom > myfile
❯ pow admin profile create
❯ pow admin user create
{
"authEntry": {
"user": {
"id": "c06382e0-2021-4234-be53-6e07a8d40065",
"token": "883f57b1-4e66-47f8-b291-7cf8b10f6370"
}
Expand Down
8 changes: 4 additions & 4 deletions api/client/admin/admin.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package admin

import (
proto "github.com/textileio/powergate/proto/admin/v1"
adminPb "github.com/textileio/powergate/api/gen/powergate/admin/v1"
)

// Admin provides access to Powergate admin APIs.
type Admin struct {
StorageJobs *StorageJobs
Profiles *Profiles
Users *Users
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New "user" wording in the client. Feels much easier and makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that user feels weird, but I definitely prefer it over storage profile.

Wallet *Wallet
}

// NewAdmin creates a new admin API.
func NewAdmin(client proto.PowergateAdminServiceClient) *Admin {
func NewAdmin(client adminPb.AdminServiceClient) *Admin {
return &Admin{
StorageJobs: &StorageJobs{client: client},
Profiles: &Profiles{client: client},
Users: &Users{client: client},
Wallet: &Wallet{client: client},
}
}
22 changes: 0 additions & 22 deletions api/client/admin/profiles.go

This file was deleted.

54 changes: 27 additions & 27 deletions api/client/admin/storagejobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ package admin
import (
"context"

proto "github.com/textileio/powergate/proto/admin/v1"
adminPb "github.com/textileio/powergate/api/gen/powergate/admin/v1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the /gen subpath makes clear is gRPC releated.

)

// StorageJobs provides access to Powergate jobs admin APIs.
type StorageJobs struct {
client proto.PowergateAdminServiceClient
client adminPb.AdminServiceClient
}

type storageJobsConfig struct {
ProfileID string
Cids []string
UserID string
Cids []string
}

// StorageJobsOption configures a storageJobsConfig.
type StorageJobsOption = func(*storageJobsConfig)

// WithProfileID filters the results to the specified profile.
func WithProfileID(profileID string) StorageJobsOption {
// WithUserID filters the results to the specified user.
func WithUserID(userID string) StorageJobsOption {
return func(conf *storageJobsConfig) {
conf.ProfileID = profileID
conf.UserID = userID
}
}

Expand All @@ -34,66 +34,66 @@ func WithCids(cids ...string) StorageJobsOption {
}

// Queued returns a list of queued storage jobs.
func (j *StorageJobs) Queued(ctx context.Context, opts ...StorageJobsOption) (*proto.QueuedStorageJobsResponse, error) {
func (j *StorageJobs) Queued(ctx context.Context, opts ...StorageJobsOption) (*adminPb.QueuedStorageJobsResponse, error) {
conf := &storageJobsConfig{}
for _, opt := range opts {
opt(conf)
}
req := &proto.QueuedStorageJobsRequest{
ProfileId: conf.ProfileID,
Cids: conf.Cids,
req := &adminPb.QueuedStorageJobsRequest{
UserId: conf.UserID,
Cids: conf.Cids,
}
return j.client.QueuedStorageJobs(ctx, req)
}

// Executing returns a list of executing storage jobs.
func (j *StorageJobs) Executing(ctx context.Context, opts ...StorageJobsOption) (*proto.ExecutingStorageJobsResponse, error) {
func (j *StorageJobs) Executing(ctx context.Context, opts ...StorageJobsOption) (*adminPb.ExecutingStorageJobsResponse, error) {
conf := &storageJobsConfig{}
for _, opt := range opts {
opt(conf)
}
req := &proto.ExecutingStorageJobsRequest{
ProfileId: conf.ProfileID,
Cids: conf.Cids,
req := &adminPb.ExecutingStorageJobsRequest{
UserId: conf.UserID,
Cids: conf.Cids,
}
return j.client.ExecutingStorageJobs(ctx, req)
}

// LatestFinal returns a list of latest final storage jobs.
func (j *StorageJobs) LatestFinal(ctx context.Context, opts ...StorageJobsOption) (*proto.LatestFinalStorageJobsResponse, error) {
func (j *StorageJobs) LatestFinal(ctx context.Context, opts ...StorageJobsOption) (*adminPb.LatestFinalStorageJobsResponse, error) {
conf := &storageJobsConfig{}
for _, opt := range opts {
opt(conf)
}
req := &proto.LatestFinalStorageJobsRequest{
ProfileId: conf.ProfileID,
Cids: conf.Cids,
req := &adminPb.LatestFinalStorageJobsRequest{
UserId: conf.UserID,
Cids: conf.Cids,
}
return j.client.LatestFinalStorageJobs(ctx, req)
}

// LatestSuccessful returns a list of latest successful storage jobs.
func (j *StorageJobs) LatestSuccessful(ctx context.Context, opts ...StorageJobsOption) (*proto.LatestSuccessfulStorageJobsResponse, error) {
func (j *StorageJobs) LatestSuccessful(ctx context.Context, opts ...StorageJobsOption) (*adminPb.LatestSuccessfulStorageJobsResponse, error) {
conf := &storageJobsConfig{}
for _, opt := range opts {
opt(conf)
}
req := &proto.LatestSuccessfulStorageJobsRequest{
ProfileId: conf.ProfileID,
Cids: conf.Cids,
req := &adminPb.LatestSuccessfulStorageJobsRequest{
UserId: conf.UserID,
Cids: conf.Cids,
}
return j.client.LatestSuccessfulStorageJobs(ctx, req)
}

// Summary returns a summary of storage jobs.
func (j *StorageJobs) Summary(ctx context.Context, opts ...StorageJobsOption) (*proto.StorageJobsSummaryResponse, error) {
func (j *StorageJobs) Summary(ctx context.Context, opts ...StorageJobsOption) (*adminPb.StorageJobsSummaryResponse, error) {
conf := &storageJobsConfig{}
for _, opt := range opts {
opt(conf)
}
req := &proto.StorageJobsSummaryRequest{
ProfileId: conf.ProfileID,
Cids: conf.Cids,
req := &adminPb.StorageJobsSummaryRequest{
UserId: conf.UserID,
Cids: conf.Cids,
}
return j.client.StorageJobsSummary(ctx, req)
}
22 changes: 22 additions & 0 deletions api/client/admin/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package admin

import (
"context"

adminPb "github.com/textileio/powergate/api/gen/powergate/admin/v1"
)

// Users provides access to Powergate admin users APIs.
type Users struct {
client adminPb.AdminServiceClient
}

// Create creates a new Powergate user, returning the user ID and auth token.
func (p *Users) Create(ctx context.Context) (*adminPb.CreateUserResponse, error) {
return p.client.CreateUser(ctx, &adminPb.CreateUserRequest{})
}

// List returns a list of existing users.
func (p *Users) List(ctx context.Context) (*adminPb.UsersResponse, error) {
return p.client.Users(ctx, &adminPb.UsersRequest{})
}
16 changes: 8 additions & 8 deletions api/client/admin/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import (
"context"
"math/big"

proto "github.com/textileio/powergate/proto/admin/v1"
adminPb "github.com/textileio/powergate/api/gen/powergate/admin/v1"
)

// Wallet provides access to Powergate wallet admin APIs.
type Wallet struct {
client proto.PowergateAdminServiceClient
client adminPb.AdminServiceClient
}

// NewAddress creates a new address.
func (w *Wallet) NewAddress(ctx context.Context, addrType string) (*proto.NewAddressResponse, error) {
req := &proto.NewAddressRequest{
func (w *Wallet) NewAddress(ctx context.Context, addrType string) (*adminPb.NewAddressResponse, error) {
req := &adminPb.NewAddressRequest{
AddressType: addrType,
}
return w.client.NewAddress(ctx, req)
}

// Addresses lists all addresses associated with this Powergate.
func (w *Wallet) Addresses(ctx context.Context) (*proto.AddressesResponse, error) {
return w.client.Addresses(ctx, &proto.AddressesRequest{})
func (w *Wallet) Addresses(ctx context.Context) (*adminPb.AddressesResponse, error) {
return w.client.Addresses(ctx, &adminPb.AddressesRequest{})
}

// SendFil sends FIL from an address associated with this Powergate to any other address.
func (w *Wallet) SendFil(ctx context.Context, from, to string, amount *big.Int) (*proto.SendFilResponse, error) {
req := &proto.SendFilRequest{
func (w *Wallet) SendFil(ctx context.Context, from, to string, amount *big.Int) (*adminPb.SendFilResponse, error) {
req := &adminPb.SendFilRequest{
From: from,
To: to,
Amount: amount.String(),
Expand Down
Loading