Skip to content

Commit

Permalink
Merge pull request #119 from FleekHQ/hotfix/refactor-temp-hub-ctx-helpr
Browse files Browse the repository at this point in the history
Hotfix: Error on startup due to hub context issue
  • Loading branch information
jsonsivar authored Aug 20, 2020
2 parents c03e145 + eddb5ee commit ae3e280
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
5 changes: 1 addition & 4 deletions core/textile/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,11 @@ func (tc *textileClient) getHubCtx(ctx context.Context) (context.Context, error)
log.Debug("Authenticating with Textile Hub")

// TODO: Use hub.GetHubToken instead
tokStr, err := hub.GetHubTokenUsingTextileKeys(ctx, tc.store, tc.kc, tc.ht)
ctx, err := hub.GetHubTokenUsingTextileKeys(ctx, tc.store, tc.kc, tc.ht)
if err != nil {
return nil, err
}

tok := thread.Token(tokStr)

ctx = thread.NewTokenContext(ctx, tok)
return ctx, nil
}

Expand Down
40 changes: 24 additions & 16 deletions core/textile/hub/hub_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,40 +150,48 @@ func GetHubToken(ctx context.Context, st store.Store, kc keychain.Keychain, cfg

// This method is just for testing purposes. Keys shouldn't be bundled in the daemon.
// Use GetHubToken instead.
func GetHubTokenUsingTextileKeys(ctx context.Context, st store.Store, kc keychain.Keychain, threads *threadsClient.Client) (string, error) {
// Try to avoid redoing challenge if we already have the token
if valFromStore, err := getHubTokenFromStore(st); err != nil {
return "", err
} else if valFromStore != "" {
log.Debug("Got hub token from store: " + valFromStore)
return valFromStore, nil
}
func GetHubTokenUsingTextileKeys(ctx context.Context, st store.Store, kc keychain.Keychain, threads *threadsClient.Client) (context.Context, error) {
var tokStr string

// prebuild context, needs to happen
// whether token is saved or not
key := os.Getenv("TXL_USER_KEY")
secret := os.Getenv("TXL_USER_SECRET")

if key == "" || secret == "" {
return "", errors.New("Couldn't get Textile key or secret from envs")
return nil, errors.New("Couldn't get Textile key or secret from envs")
}
ctx = common.NewAPIKeyContext(ctx, key)

apiSigCtx, err := common.CreateAPISigContext(ctx, time.Now().Add(time.Minute), secret)
if err != nil {
return "", err
return nil, err
}
ctx = apiSigCtx

privateKey, _, err := kc.GetStoredKeyPairInLibP2PFormat()
if err != nil {
return "", err
return nil, err
}

tok, err := threads.GetToken(ctx, thread.NewLibp2pIdentity(privateKey))
tokStr := string(tok)
// Try to avoid redoing challenge if we already have the token
if tokStr, err = getHubTokenFromStore(st); err != nil {
return nil, err
} else if tokStr == "" {

if err := storeHubToken(st, tokStr); err != nil {
return "", err
tok, err := threads.GetToken(ctx, thread.NewLibp2pIdentity(privateKey))
if err != nil {
return nil, err
}

tokStr = string(tok)

if err := storeHubToken(st, tokStr); err != nil {
return nil, err
}
}

return tokStr, err
tok := thread.Token(tokStr)
ctx = thread.NewTokenContext(ctx, tok)
return ctx, nil
}
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
Expand Down Expand Up @@ -514,6 +515,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.14.6 h1:8ERzHx8aj1Sc47mu9n/AksaKCSWrMchFtkdrS4BIj5o=
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
github.com/gxed/go-shellwords v1.0.3/go.mod h1:N7paucT91ByIjmVJHhvoarjoQnmsi3Jd3vH7VqgtMxQ=
github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
Expand Down

0 comments on commit ae3e280

Please sign in to comment.