Skip to content

Instantly share code, notes, and snippets.

@MaxDaten
Last active March 20, 2017 22:50
Show Gist options
  • Save MaxDaten/962088e28d5250c8b25a745beb097316 to your computer and use it in GitHub Desktop.
Save MaxDaten/962088e28d5250c8b25a745beb097316 to your computer and use it in GitHub Desktop.
gogol datastore 0.1.1 auth bug

gogol datastore 0.1.1 auth bug

Minimal example for brendanhay/gogol#50

  1. start emulator gcloud beta emulators datastore start --host-port=localhost:8398
  2. Not working with gogol-0.1.1 (lts-8.5).
stack --stack-yaml=stack-lts-8.5-not-working.yaml build --exec gogol-datastore-exe
# Fails with:
# gogol-datastore-exe: TokenRefreshError (Status {statusCode = 400, statusMessage = "Bad Request"}) "Failure refreshing token from accounts.google.com/o/oauth2/v2/auth" Nothing
# Note: No Request is traced but logging is set to `Trace`
  1. Working with gogol-0.2.0 (Forced as extra-deps in yaml)
stack --stack-yaml=stack-lts-8.5-working.yaml build --exec gogol-datastore-exe
name: gogol-datastore-bug
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/MaxDaten/gogol-datastore#readme
license: BSD3
license-file: LICENSE
author: Jan-Philip Loos
maintainer: maxdaten@gmail.com
copyright: 2017 Jan-Philip Loos
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10
executable gogol-datastore-exe
hs-source-dirs: ./
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends: base
, gogol
, gogol-datastore
, lens
, mtl
default-language: Haskell2010
source-repository head
type: git
location: https://github.com/MaxDaten/gogol-datastore
Copyright 2063 Jan-Philip Loos
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Network.Google as Google
import Network.Google.Datastore as DS
import Control.Monad.Reader
import Control.Lens
import System.IO (stdout)
main = do
let papegoPartition = partitionId & piProjectId ?~ "example" & piNamespaceId ?~ "example"
entityKey = key
& kPartitionId ?~ papegoPartition
& kPath .~ [pathElement & peKind ?~ "ExampleEntity" & peName ?~ "entity name"]
theEntity = DS.entity & eKey ?~ entityKey
putStrLn "Create entity"
print theEntity
let upsertEntity = commitRequest
& crMutations .~ [mutation & mUpsert ?~ theEntity]
& crMode ?~ NonTransactional
print upsertEntity
logger <- Google.newLogger Google.Trace stdout
env <- Google.newEnv <&> (Google.envLogger .~ logger) . Google.allow datastoreScope
let cfg = datastoreService
& serviceHost .~ "localhost"
& servicePort .~ 8398
& serviceSecure .~ False
resp <- runResourceT . runGoogle env $ local (override cfg) $
Google.send $ projectsCommit upsertEntity "example"
print resp
putStrLn "Done!"
import Distribution.Simple
main = defaultMain
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-8.5
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.4"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
# This file was automatically generated by 'stack init'
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/
# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
# resolver: ghcjs-0.1.0_ghc-7.10.2
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-8.5
# User packages to be built.
# Various formats can be used as shown in the example below.
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
# - location:
# git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# extra-dep: true
# subdirs:
# - auto-update
# - wai
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps:
- gogol-0.2.0
- gogol-core-0.2.0
- gogol-datastore-0.2.0
# Override default flag values for local packages and extra-deps
flags: {}
# Extra package databases containing global packages
extra-package-dbs: []
# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.4"
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment