on develop help sign in
Minor naming tweaks to make it easier to trace down typlit functions
commitf7399aae77dce72bde88b7eb5943a14d38d0ff50 authorBrendan Hay <brendan.g.hay@gmail.com> dateSun 20 Mar 2016, 17:29 (11 years ago) parent26772c7
5 files changed+25−27
gogol/src/Network/Google.hs+5−6 gogol/src/Network/Google/Auth.hs+2−2 gogol/src/Network/Google/Auth/InstalledApplication.hs+1−1 gogol/src/Network/Google/Auth/Scope.hs+15−16 gogol/src/Network/Google/Env.hs+2−2
gogol/src/Network/Google.hs+5−6
@@ -48,8 +48,8 @@ module Network.Google
4848 , forbid
4949 , (!)
5050
51− , type Authorize
52− , type MatchAnyScope
51+ , type HasScope
52+ , type HasScope'
5353
5454 -- * Sending Requests
5555 , send
@@ -97,7 +97,6 @@ module Network.Google
9797 , tlsManagerSettings
9898
9999 -- * Re-exported Types
100− , Proxy (..)
101100 , OctetStream
102101 , PlainText
103102 , JSON
@@ -208,7 +207,7 @@ instance (Monoid w, MonadGoogle s m) => MonadGoogle s (LRW.RWST r w s' m) where
208207-- | Send a request, returning the associated response if successful.
209208--
210209-- Throws 'Error'.
211−send :: (MonadGoogle s m, Authorize s a, GoogleRequest a) => a -> m (Rs a)
210+send :: (MonadGoogle s m, HasScope s a, GoogleRequest a) => a -> m (Rs a)
212211send x = liftGoogle $ do
213212 e <- ask
214213 r <- perform e x
@@ -222,7 +221,7 @@ send x = liftGoogle $ do
222221--
223222-- Throws 'Error'.
224223download :: ( MonadGoogle s m
225− , Authorize s (MediaDownload a)
224+ , HasScope s (MediaDownload a)
226225 , GoogleRequest (MediaDownload a)
227226 )
228227 => a
@@ -233,7 +232,7 @@ download = send . MediaDownload
233232--
234233-- Throws 'Error'.
235234upload :: ( MonadGoogle s m
236− , Authorize s (MediaUpload a)
235+ , HasScope s (MediaUpload a)
237236 , GoogleRequest (MediaUpload a)
238237 )
239238 => a
gogol/src/Network/Google/Auth.hs+2−2
@@ -153,7 +153,7 @@ exchange c l = fmap (Auth c) . action l
153153 where
154154 action = case c of
155155 FromMetadata s -> metadataToken s
156− FromAccount a -> serviceAccountToken a (getScopes c)
156+ FromAccount a -> serviceAccountToken a (allowScopes c)
157157 FromClient x n -> exchangeCode x n
158158 FromUser u -> authorizedUserToken u Nothing
159159
@@ -167,7 +167,7 @@ refresh (Auth c t) l = fmap (Auth c) . action l
167167 where
168168 action = case c of
169169 FromMetadata s -> metadataToken s
170− FromAccount a -> serviceAccountToken a (getScopes c)
170+ FromAccount a -> serviceAccountToken a (allowScopes c)
171171 FromClient x _ -> refreshToken x t
172172 FromUser u -> authorizedUserToken u (_tokenRefresh t)
173173
gogol/src/Network/Google/Auth/InstalledApplication.hs+1−1
@@ -31,7 +31,7 @@ redirectURI = "urn:ietf:wg:oauth:2.0:oob"
3131--
3232-- /See:/ <https://developers.google.com/accounts/docs/OAuth2InstalledApp#formingtheurl Forming the URL>.
3333formURL :: Allow s => OAuthClient -> proxy s -> Text
34−formURL c = formURLWith c . getScopes
34+formURL c = formURLWith c . allowScopes
3535
3636-- | Form a URL using 'OAuthScope' values.
3737--
gogol/src/Network/Google/Auth/Scope.hs+15−16
@@ -41,13 +41,11 @@ import Network.HTTP.Types (urlEncode)
4141-- with a 'Proxy' type, or explicitly specifying the type annotation without
4242-- having separate functions.
4343--
44−-- This seems sufficiently general, does it already exist?
45−--
4644-- /See:/ '!'.
4745allow :: proxy s -> k s -> k s
4846allow _ = id
4947
50−-- | Type-restrict the supplied credentials etc. to no scopes.
48+-- | Type-restrict the supplied credentials (etc.) to no scopes.
5149forbid :: k '[] -> k '[]
5250forbid = id
5351
@@ -61,16 +59,17 @@ forbid = id
6159-- listed in the scopes the credentials supports.
6260--
6361-- For error message/presentation purposes, this wraps the result of
64−-- the membership checks below.
65−type family Authorize (s :: [Symbol]) a :: Constraint where
66− Authorize s a = MatchAnyScope s (Scopes a) ~ 'True
62+-- the 'HasScope' membership check to show both lists of scopes before
63+-- reduction.
64+type family HasScope (s :: [Symbol]) a :: Constraint where
65+ HasScope s a = (s `HasScope'` Scopes a) ~ 'True
6766
68−-- | Check if any scope exists in both parameters.
69−type family MatchAnyScope a b where
70− MatchAnyScope a '[] = 'True
71− MatchAnyScope (x ': xs) b = x ∈ b || MatchAnyScope xs b
67+-- | Check if any of actual supplied scopes 's' exist in the required set 'a'.
68+type family HasScope' s a where
69+ HasScope' s '[] = 'True -- No scopes are required.
70+ HasScope' (x ': xs) a = x ∈ a || HasScope' xs a
7271
73−-- | Set membership.
72+-- | Membership.
7473type family (∈) a b where
7574 (∈) x '[] = 'False
7675 (∈) x (y ': xs) = x == y || x ∈ xs
@@ -82,19 +81,19 @@ type family (++) xs ys where
8281 (++) (a ': as) bs = a ': (as ++ bs)
8382
8483class Allow a where
85− -- | Obtain a list of supported 'OAuthScope's from a proxy type.
86− getScopes :: proxy a -> [OAuthScope]
84+ -- | Obtain a list of supported 'OAuthScope' values from a proxy.
85+ allowScopes :: proxy a -> [OAuthScope]
8786
8887instance Allow '[] where
89− getScopes _ = []
88+ allowScopes _ = []
9089
9190instance (KnownSymbol x, Allow xs) => Allow (x ': xs) where
92− getScopes _ = scope (Proxy :: Proxy x) : getScopes (Proxy :: Proxy xs)
91+ allowScopes _ = scope (Proxy :: Proxy x) : allowScopes (Proxy :: Proxy xs)
9392 where
9493 scope = OAuthScope . Text.pack . symbolVal
9594
9695instance Allow s => Allow (Credentials s) where
97− getScopes _ = getScopes (Proxy :: Proxy s)
96+ allowScopes _ = allowScopes (Proxy :: Proxy s)
9897
9998concatScopes :: [OAuthScope] -> Text
10099concatScopes = Text.intercalate " " . coerce
gogol/src/Network/Google/Env.hs+2−2
@@ -68,7 +68,7 @@ instance HasEnv s (Env s) where
6868-- To override a specific service, it's suggested you use
6969-- either 'configure' or 'reconfigure' with a modified version of the default
7070-- service, such as @Network.Google.Gmail.gmailService@.
71−override :: HasEnv s a => (Service -> ServiceConfig) -> a -> a
71+override :: HasEnv s a => (ServiceConfig -> ServiceConfig) -> a -> a
7272override f = envOverride <>~ Dual (Endo f)
7373
7474-- | Configure a specific service. All requests belonging to the
@@ -116,7 +116,7 @@ timeout s = local (override (serviceTimeout ?~ s))
116116-- The 'Allow'ed 'OAuthScope's are used to authorize any @service_account@ that is
117117-- found with the appropriate scopes. See the top-level module of each individual
118118-- @gogol-*@ library for a list of available scopes, such as
119−-- @Network.Google.Compute.computeScope@.
119+-- @Network.Google.Compute.authComputeScope@.
120120--
121121-- Lenses from 'HasEnv' can be used to further configure the resulting 'Env'.
122122--