captplanet: configure api key (#195)
This commit is contained in:
parent
d934733c4d
commit
30e3b503a4
@ -4,11 +4,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
base58 "github.com/jbenet/go-base58"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"storj.io/storj/pkg/cfgstruct"
|
||||
@ -77,6 +79,11 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
|
||||
startingPort := setupCfg.StartingPort
|
||||
|
||||
apiKey, err := newAPIKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
overrides := map[string]interface{}{
|
||||
"heavy-client.identity.cert-path": filepath.Join(
|
||||
setupCfg.BasePath, "hc", "ident.leaf.cert"),
|
||||
@ -104,7 +111,8 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
setupCfg.ListenHost, startingPort+1),
|
||||
"gateway.minio-dir": filepath.Join(
|
||||
setupCfg.BasePath, "gw", "minio"),
|
||||
"pointer-db.auth.api-key": "abc123",
|
||||
"gateway.api-key": apiKey,
|
||||
"pointer-db.auth.api-key": apiKey,
|
||||
}
|
||||
|
||||
for i := 0; i < len(runCfg.Farmers); i++ {
|
||||
@ -130,3 +138,12 @@ func cmdSetup(cmd *cobra.Command, args []string) (err error) {
|
||||
func joinHostPort(host string, port int) string {
|
||||
return net.JoinHostPort(host, fmt.Sprint(port))
|
||||
}
|
||||
|
||||
func newAPIKey() (string, error) {
|
||||
var buf [20]byte
|
||||
_, err := rand.Read(buf[:])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return base58.Encode(buf[:]), nil
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ type ClientConfig struct {
|
||||
// TODO(jt): these should probably be the same
|
||||
OverlayAddr string `help:"Address to contact overlay server through"`
|
||||
PointerDBAddr string `help:"Address to contact pointerdb server through"`
|
||||
|
||||
APIKey string `help:"API Key (TODO: this needs to change to macaroons somehow)"`
|
||||
}
|
||||
|
||||
// Config is a general miniogw configuration struct. This should be everything
|
||||
@ -124,7 +126,7 @@ func (c Config) action(ctx context.Context, cliCtx *cli.Context,
|
||||
// TODO(jt): pointerdb.NewClient should dial the pointerdb server with the
|
||||
// transport client. probably should use the same connection as the
|
||||
// overlay client
|
||||
pdb, err := pointerdb.NewClient(c.PointerDBAddr, nil)
|
||||
pdb, err := pointerdb.NewClient(c.PointerDBAddr, []byte(c.APIKey))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user