e228d090e8
* working on put request for nsclient * working on put request for nsclient * netstate put * netstate put * wip testing client * wip - testing client and working through some errors * wip - testing client and working through some errors * put request works * put request works for client * get request working * get request working * get request working-minor edit * get request working-minor edit * list request works * list request works * working through delete error * working through delete error * fixed exp client, still working through delete error * fixed exp client, still working through delete error * delete works; fixed formatting issues * delete works; fixed formatting issues * deleted comment * deleted comment * resolving merge conflicts * resolving merge conflict * fixing merge conflict * implemented and modified kayloyans paths file * working on testing * added test for path_test.go * fixed string, read through netstate test * deleted env variables * initial commit for mocking out grpc client- got it working * mocked grpc client * mock put passed test * 2 tests pass for PUT with mock * put requests test pass, wip- want mini review * get tests pass mock * list test working * initial commit for list test * all list req. working, starting on delete tests * delete tests passed * cleaned up tests * resolved merge conflicts * resolved merge conflicts * fixed linter errors * fixed error found in travis * initial commit for fixes from PR comments * fixed pr comments and linting * added error handling for api creds, and rebased * fixes from dennis comments * fixed pr with dennis suggestioon * added copyrights to files * fixed casing per dennis great comment * fixed travis complaint on sprintf
109 lines
2.5 KiB
Go
109 lines
2.5 KiB
Go
// Copyright (C) 2018 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"strings"
|
|
"os"
|
|
|
|
"go.uber.org/zap"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
p "storj.io/storj/pkg/paths"
|
|
client "storj.io/storj/pkg/pointerdb"
|
|
proto "storj.io/storj/protos/pointerdb"
|
|
)
|
|
|
|
var (
|
|
pointerdbClientPort string
|
|
)
|
|
|
|
func initializeFlags() {
|
|
flag.StringVar(&pointerdbClientPort, "pointerdbPort", ":8080", "this is your port")
|
|
flag.Parse()
|
|
}
|
|
|
|
func main() {
|
|
initializeFlags()
|
|
|
|
logger, _ := zap.NewDevelopment()
|
|
defer logger.Sync()
|
|
|
|
pdbclient, err := client.NewClient(pointerdbClientPort)
|
|
|
|
if err != nil {
|
|
logger.Error("Failed to dial: ", zap.Error(err))
|
|
os.Exit(1)
|
|
}
|
|
|
|
logger.Debug(fmt.Sprintf("client dialed port %s", pointerdbClientPort))
|
|
ctx := context.Background()
|
|
|
|
// Example parameters to pass into API calls
|
|
var path = p.New("fold1/fold2/fold3/file.txt")
|
|
pointer := &proto.Pointer{
|
|
Type: proto.Pointer_INLINE,
|
|
InlineSegment: []byte("popcorn"),
|
|
}
|
|
APIKey := []byte("abc123")
|
|
|
|
// Example Put1
|
|
err = pdbclient.Put(ctx, path, pointer, APIKey)
|
|
|
|
if err != nil || status.Code(err) == codes.Internal {
|
|
logger.Error("couldn't put pointer in db", zap.Error(err))
|
|
} else {
|
|
logger.Debug("Success: put pointer in db")
|
|
}
|
|
|
|
// Example Put2
|
|
err = pdbclient.Put(ctx, p.New("fold1/fold2"), pointer, APIKey)
|
|
|
|
if err != nil || status.Code(err) == codes.Internal {
|
|
logger.Error("couldn't put pointer in db", zap.Error(err))
|
|
} else {
|
|
logger.Debug("Success: put pointer in db")
|
|
}
|
|
|
|
// Example Get
|
|
getRes, err := pdbclient.Get(ctx, path, APIKey)
|
|
|
|
if err != nil {
|
|
logger.Error("couldn't GET pointer from db", zap.Error(err))
|
|
} else {
|
|
logger.Info("Success: got Pointer from db",
|
|
zap.String("pointer", getRes.String()),
|
|
)
|
|
}
|
|
|
|
// Example List with pagination
|
|
startingPathKey := p.New("fold1/")
|
|
var limit int64 = 1
|
|
|
|
paths, trunc, err := pdbclient.List(ctx, startingPathKey, limit, APIKey)
|
|
|
|
if err != nil || status.Code(err) == codes.Internal {
|
|
logger.Error("failed to list file paths", zap.Error(err))
|
|
} else {
|
|
var stringList []string
|
|
for _, pathByte := range paths {
|
|
stringList = append(stringList, string(pathByte))
|
|
}
|
|
logger.Debug("Success: listed paths: " + strings.Join(stringList, ", ") + "; truncated: " + fmt.Sprintf("%t", trunc))
|
|
}
|
|
|
|
// Example Delete
|
|
err = pdbclient.Delete(ctx, path, APIKey)
|
|
|
|
if err != nil || status.Code(err) == codes.Internal {
|
|
logger.Error("Error in deleteing file from db", zap.Error(err))
|
|
} else {
|
|
logger.Debug("Success: file is deleted from db")
|
|
}
|
|
}
|