on develop help sign in
Minor naming tweaks to make it easier to trace down typlit functions
f7399aaBrendan Hay
gogol/src/Network/Google.hs+5−6
@@ -48,8 +48,8 @@ module Network.Google
48 , forbid
48 , forbid
49 , (!)
49 , (!)
50
50
51− , type Authorize
51+ , type HasScope
52− , type MatchAnyScope
52+ , type HasScope'
53
53
54 -- * Sending Requests
54 -- * Sending Requests
55 , send
55 , send
@@ -97,7 +97,6 @@ module Network.Google
97 , tlsManagerSettings
97 , tlsManagerSettings
98
98
99 -- * Re-exported Types
99 -- * Re-exported Types
100− , Proxy (..)
101 , OctetStream
100 , OctetStream
102 , PlainText
101 , PlainText
103 , JSON
102 , JSON
@@ -208,7 +207,7 @@ instance (Monoid w, MonadGoogle s m) => MonadGoogle s (LRW.RWST r w s' m) where
208-- | Send a request, returning the associated response if successful.
207-- | Send a request, returning the associated response if successful.
209--
208--
210-- Throws 'Error'.
209-- 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)
212send x = liftGoogle $ do
211send x = liftGoogle $ do
213 e <- ask
212 e <- ask
214 r <- perform e x
213 r <- perform e x
@@ -222,7 +221,7 @@ send x = liftGoogle $ do
222--
221--
223-- Throws 'Error'.
222-- Throws 'Error'.
224download :: ( MonadGoogle s m
223download :: ( MonadGoogle s m
225− , Authorize s (MediaDownload a)
224+ , HasScope s (MediaDownload a)
226 , GoogleRequest (MediaDownload a)
225 , GoogleRequest (MediaDownload a)
227 )
226 )
228 => a
227 => a
@@ -233,7 +232,7 @@ download = send . MediaDownload
233--
232--
234-- Throws 'Error'.
233-- Throws 'Error'.
235upload :: ( MonadGoogle s m
234upload :: ( MonadGoogle s m
236− , Authorize s (MediaUpload a)
235+ , HasScope s (MediaUpload a)
237 , GoogleRequest (MediaUpload a)
236 , GoogleRequest (MediaUpload a)
238 )
237 )
239 => a
238 => a
gogol/src/Network/Google/Auth.hs+2−2
@@ -153,7 +153,7 @@ exchange c l = fmap (Auth c) . action l
153 where
153 where
154 action = case c of
154 action = case c of
155 FromMetadata s -> metadataToken s
155 FromMetadata s -> metadataToken s
156− FromAccount a -> serviceAccountToken a (getScopes c)
156+ FromAccount a -> serviceAccountToken a (allowScopes c)
157 FromClient x n -> exchangeCode x n
157 FromClient x n -> exchangeCode x n
158 FromUser u -> authorizedUserToken u Nothing
158 FromUser u -> authorizedUserToken u Nothing
159
159
@@ -167,7 +167,7 @@ refresh (Auth c t) l = fmap (Auth c) . action l
167 where
167 where
168 action = case c of
168 action = case c of
169 FromMetadata s -> metadataToken s
169 FromMetadata s -> metadataToken s
170− FromAccount a -> serviceAccountToken a (getScopes c)
170+ FromAccount a -> serviceAccountToken a (allowScopes c)
171 FromClient x _ -> refreshToken x t
171 FromClient x _ -> refreshToken x t
172 FromUser u -> authorizedUserToken u (_tokenRefresh t)
172 FromUser u -> authorizedUserToken u (_tokenRefresh t)
173
173
gogol/src/Network/Google/Auth/InstalledApplication.hs+1−1
@@ -31,7 +31,7 @@ redirectURI = "urn:ietf:wg:oauth:2.0:oob"
31--
31--
32-- /See:/ <https://developers.google.com/accounts/docs/OAuth2InstalledApp#formingtheurl Forming the URL>.
32-- /See:/ <https://developers.google.com/accounts/docs/OAuth2InstalledApp#formingtheurl Forming the URL>.
33formURL :: Allow s => OAuthClient -> proxy s -> Text
33formURL :: Allow s => OAuthClient -> proxy s -> Text
34−formURL c = formURLWith c . getScopes
34+formURL c = formURLWith c . allowScopes
35
35
36-- | Form a URL using 'OAuthScope' values.
36-- | Form a URL using 'OAuthScope' values.
37--
37--
gogol/src/Network/Google/Auth/Scope.hs+15−16
@@ -41,13 +41,11 @@ import Network.HTTP.Types (urlEncode)
41-- with a 'Proxy' type, or explicitly specifying the type annotation without
41-- with a 'Proxy' type, or explicitly specifying the type annotation without
42-- having separate functions.
42-- having separate functions.
43--
43--
44−-- This seems sufficiently general, does it already exist?
45−--
46-- /See:/ '!'.
44-- /See:/ '!'.
47allow :: proxy s -> k s -> k s
45allow :: proxy s -> k s -> k s
48allow _ = id
46allow _ = id
49
47
50−-- | Type-restrict the supplied credentials etc. to no scopes.
48+-- | Type-restrict the supplied credentials (etc.) to no scopes.
51forbid :: k '[] -> k '[]
49forbid :: k '[] -> k '[]
52forbid = id
50forbid = id
53
51
@@ -61,16 +59,17 @@ forbid = id
61-- listed in the scopes the credentials supports.
59-- listed in the scopes the credentials supports.
62--
60--
63-- For error message/presentation purposes, this wraps the result of
61-- For error message/presentation purposes, this wraps the result of
64−-- the membership checks below.
62+-- the 'HasScope' membership check to show both lists of scopes before
63+-- reduction.
65−type family Authorize (s :: [Symbol]) a :: Constraint where
64+type family HasScope (s :: [Symbol]) a :: Constraint where
66− Authorize s a = MatchAnyScope s (Scopes a) ~ 'True
65+ HasScope s a = (s `HasScope'` Scopes a) ~ 'True
67
66
68−-- | Check if any scope exists in both parameters.
67+-- | Check if any of actual supplied scopes 's' exist in the required set 'a'.
69−type family MatchAnyScope a b where
68+type family HasScope' s a where
70− MatchAnyScope a '[] = 'True
69+ HasScope' s '[] = 'True -- No scopes are required.
71− MatchAnyScope (x ': xs) b = x ∈ b || MatchAnyScope xs b
70+ HasScope' (x ': xs) a = x ∈ a || HasScope' xs a
72
71
73−-- | Set membership.
72+-- | Membership.
74type family (∈) a b where
73type family (∈) a b where
75 (∈) x '[] = 'False
74 (∈) x '[] = 'False
76 (∈) x (y ': xs) = x == y || x ∈ xs
75 (∈) x (y ': xs) = x == y || x ∈ xs
@@ -82,19 +81,19 @@ type family (++) xs ys where
82 (++) (a ': as) bs = a ': (as ++ bs)
81 (++) (a ': as) bs = a ': (as ++ bs)
83
82
84class Allow a where
83class Allow a where
85− -- | Obtain a list of supported 'OAuthScope's from a proxy type.
84+ -- | Obtain a list of supported 'OAuthScope' values from a proxy.
86− getScopes :: proxy a -> [OAuthScope]
85+ allowScopes :: proxy a -> [OAuthScope]
87
86
88instance Allow '[] where
87instance Allow '[] where
89− getScopes _ = []
88+ allowScopes _ = []
90
89
91instance (KnownSymbol x, Allow xs) => Allow (x ': xs) where
90instance (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)
93 where
92 where
94 scope = OAuthScope . Text.pack . symbolVal
93 scope = OAuthScope . Text.pack . symbolVal
95
94
96instance Allow s => Allow (Credentials s) where
95instance Allow s => Allow (Credentials s) where
97− getScopes _ = getScopes (Proxy :: Proxy s)
96+ allowScopes _ = allowScopes (Proxy :: Proxy s)
98
97
99concatScopes :: [OAuthScope] -> Text
98concatScopes :: [OAuthScope] -> Text
100concatScopes = Text.intercalate " " . coerce
99concatScopes = Text.intercalate " " . coerce
gogol/src/Network/Google/Env.hs+2−2
@@ -68,7 +68,7 @@ instance HasEnv s (Env s) where
68-- To override a specific service, it's suggested you use
68-- To override a specific service, it's suggested you use
69-- either 'configure' or 'reconfigure' with a modified version of the default
69-- either 'configure' or 'reconfigure' with a modified version of the default
70-- service, such as @Network.Google.Gmail.gmailService@.
70-- 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
72override f = envOverride <>~ Dual (Endo f)
72override f = envOverride <>~ Dual (Endo f)
73
73
74-- | Configure a specific service. All requests belonging to the
74-- | Configure a specific service. All requests belonging to the
@@ -116,7 +116,7 @@ timeout s = local (override (serviceTimeout ?~ s))
116-- The 'Allow'ed 'OAuthScope's are used to authorize any @service_account@ that is
116-- The 'Allow'ed 'OAuthScope's are used to authorize any @service_account@ that is
117-- found with the appropriate scopes. See the top-level module of each individual
117-- found with the appropriate scopes. See the top-level module of each individual
118-- @gogol-*@ library for a list of available scopes, such as
118-- @gogol-*@ library for a list of available scopes, such as
119−-- @Network.Google.Compute.computeScope@.
119+-- @Network.Google.Compute.authComputeScope@.
120--
120--
121-- Lenses from 'HasEnv' can be used to further configure the resulting 'Env'.
121-- Lenses from 'HasEnv' can be used to further configure the resulting 'Env'.
122--
122--