Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help/Advice needed] base64: input: invalid encoding at offset: 1 #47

Closed
denibertovic opened this issue Nov 11, 2016 · 7 comments
Closed
Labels

Comments

@denibertovic
Copy link

denibertovic commented Nov 11, 2016

Hi there. Thanks for this awesome library!

I'm trying out gogol-compute and I'm getting a somewhat weird error when I try to run the example below. I'm trying to get a list of instances for a particular project.
From what I can tell from the debug output I successfully connect to the google compute api, get a bearer token and make a request but then when the debug output would normally print the body (with I assume, the instances json in there) I get the following error:

Main.hs: base64: input: invalid encoding at offset: 1

I tried setting the logger to Info and Error with no luck. I also tried ignoring the result of the api call
but the same error happens.

{-# LANGUAGE OverloadedStrings #-}

module Main where

import           Control.Lens                           ((&), (.~), (<&>), (?~))
import qualified Data.Aeson                             as JSON
import qualified Data.ByteString.Lazy                   as BS
import           Data.Maybe                             (fromJust)
import           Data.Text                              (Text)
import           Network.Google
import           Network.Google.Auth
import           Network.Google.Auth.ApplicationDefault
import           Network.Google.Auth.ServiceAccount
import           Network.Google.Compute
import           System.IO                              (stdout)

import qualified Data.Text                              as Text

main = do
    lgr  <- newLogger Debug stdout
    bs <- BS.readFile "service_account.json"
    manager <- newManager tlsManagerSettings
    let creds = fromJSONCredentials bs
    case creds of
        Left s -> error s
        Right c -> do
            env  <- (newEnvWith c lgr manager) <&> (envScopes .~ computeReadOnlyScope)
            r <- runResourceT . runGoogle env $ do
                send $ (instancesList "testing" "us-east1-c")
            print r
@brendanhay
Copy link
Owner

brendanhay commented Nov 29, 2016

Hi @denibertovic, it seems this error is coming from convertFromBase in the memory package during Base64 deserialisation.

The InstanceList type that is being returned contains a list of type [Instance], which in turn has Metadata and Tags that both contain (supposedly) Base64 encoded fingerprints.

Since the deserialisation is failing I assume that means the fields themselves are not in fact encoded as the spec claims - I'll need to review this for compute specifically and then will try to provide a fix or workaround.

Apologies for the delay.

@brendanhay brendanhay added the bug label Nov 29, 2016
@denibertovic
Copy link
Author

@brendanhay thanks for the reply. If you can't reproduce this locally it might have something to do with my environment. There is a lot of talk here: commercialhaskell/stack#2712 about how the memory package can't be built...for me it built just fine but I wonder if it built correctly, and if that could be causing such errors.

@denibertovic
Copy link
Author

@brendanhay The latest documentation seems to indicate that Tags and Metadata have a fingeprint field which is "bytes".

"fingerprint": bytes

Specifies a fingerprint for this request, which is essentially a hash of the metadata's contents and used for optimistic locking. The fingerprint is initially generated by Compute Engine and changes after every request to modify or update metadata. You must always provide an up-to-date fingerprint hash in order to update or change metadata.

@denibertovic
Copy link
Author

@brendanhay did you manage to figure out what the issue was here and how to fix it? I'd be happy to submit a PR but I'd need more guidance.

@denibertovic
Copy link
Author

denibertovic commented Feb 11, 2017

Hey @brendanhay thanks for fixing this! 🍰 I've tried pulling in the latest changes from github but I'm getting a compilation error about a missing Base64 constructor.

I've added the following in my stack yaml:

- '.'
- location:
    git: [email protected]:brendanhay/gogol.git
    commit: e5b42bbdc7826406e811c06e54282401a27d8fae
  subdirs:
    - core
    - gogol-compute
    - gogol
    - gen
  extra-dep: true

And I'm getting the following error:

    [  2 of 226] Compiling Network.Google.Compute.Types.Product ( gen/Network/Google/Compute/Types/Product.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Network/Google/Compute/Types/Product.

.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:1510:37: error:
        Not in scope: type constructor or class ‘Base64’
    
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:2237:39: error:
        Not in scope: type constructor or class ‘Base64’
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:5648:40: error:
        Not in scope: type constructor or class ‘Base64’
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:13832:32: error:
        Not in scope: type constructor or class ‘Base64’
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:16045:38: error:
        Not in scope: type constructor or class ‘Base64’
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:17131:39: error:
        Not in scope: type constructor or class ‘Base64’
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:18177:42: error:
        Not in scope: type constructor or class ‘Base64’
.stack-work/downloaded/G2yG9i20lkYn/gogol-compute/gen/Network/Google/Compute/Types/Product.hs:18826:32: error:
        Not in scope: type constructor or class ‘Base64’

Did I miss adding something to my stack.yml? Or?

@brendanhay
Copy link
Owner

Hey @denibertovic, the regeneration of the services to match the new underlying base primitives was in #59, apologies for the confusion! HEAD of develop has those changes merged now.

@denibertovic
Copy link
Author

Thanks @brendanhay it works now! 🍰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants