2019-06-27 18:36:51 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package uplink_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
|
|
|
"storj.io/storj/lib/uplink"
|
|
|
|
)
|
|
|
|
|
2019-06-28 14:40:37 +01:00
|
|
|
func CreateBucketExample(ctx context.Context,
|
|
|
|
satelliteAddress, apiKey string,
|
|
|
|
cfg *uplink.Config, out io.Writer) (err error) {
|
|
|
|
|
2019-06-27 18:36:51 +01:00
|
|
|
errCatch := func(fn func() error) { err = errs.Combine(err, fn()) }
|
|
|
|
|
|
|
|
// First, create an Uplink handle.
|
|
|
|
ul, err := uplink.NewUplink(ctx, cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer errCatch(ul.Close)
|
|
|
|
|
2019-06-28 14:40:37 +01:00
|
|
|
// Then, parse the API key. API keys are "macaroons" that allow you to create
|
|
|
|
// new, restricted API keys.
|
2019-06-27 18:36:51 +01:00
|
|
|
key, err := uplink.ParseAPIKey(apiKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-28 14:40:37 +01:00
|
|
|
// Next, open the project in question. Projects are identified by a specific
|
|
|
|
// Satellite and API key
|
2019-06-27 18:36:51 +01:00
|
|
|
p, err := ul.OpenProject(ctx, satelliteAddress, key)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer errCatch(p.Close)
|
|
|
|
|
|
|
|
// Last, create the bucket!
|
|
|
|
_, err = p.CreateBucket(ctx, "testbucket", nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(out, "success!")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Example_createBucket() {
|
2019-06-28 14:40:37 +01:00
|
|
|
// The satellite address is the address of the satellite your API key is
|
|
|
|
// valid on
|
2019-06-27 18:36:51 +01:00
|
|
|
satelliteAddress := "us-central-1.tardigrade.io:7777"
|
|
|
|
|
|
|
|
// The API key can be created in the web interface
|
|
|
|
apiKey := "qPSUM3k0bZyOIyil2xrVWiSuc9HuB2yBP3qDrA2Gc"
|
|
|
|
|
2019-08-01 12:14:09 +01:00
|
|
|
err := CreateBucketExample(context.Background(), satelliteAddress, apiKey, &uplink.Config{}, os.Stdout)
|
2019-06-27 18:36:51 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|