captplanet: configure api key (#195)

This commit is contained in:
JT Olio 2018-08-02 13:30:57 -06:00 committed by GitHub
parent d934733c4d
commit 30e3b503a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}