-
Notifications
You must be signed in to change notification settings - Fork 93
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
API nits + refactor #704
Changes from all commits
2c1c0d0
c399023
ec613ef
8285c9e
58a831d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
- name: Publish JS gRPC bindings | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)}]}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Comment on lines
-85
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, the |
||
.PHONY: protos | ||
|
||
# local is what we run when testing locally. | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New "user" wording in the client. Feels much easier and makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}, | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, the |
||
) | ||
|
||
// 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 | ||
} | ||
} | ||
|
||
|
@@ -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) | ||
} |
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{}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protoc-gen-go
andprotoc-gen-go-grpc
now managed by and accessed throughbingo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice