kubernetes-client 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+183/−79 lines, 4 filesdep ~base64-bytestringdep ~connectiondep ~containers
Dependency ranges changed: base64-bytestring, connection, containers, data-default-class, either, file-embed, filepath, hoauth2, hspec, hspec-attoparsec, http-client-tls, jose-jwt, kubernetes-client-core, mtl, oidc-client, pem, safe-exceptions, stm, time, timerep, tls, typed-process, uri-bytestring, x509, x509-store, x509-system, x509-validation, yaml
Files
- kubernetes-client.cabal +81/−79
- src/Kubernetes/Client/Auth/Basic.hs +45/−0
- src/Kubernetes/Client/Config.hs +2/−0
- test/Kubernetes/Client/Auth/BasicSpec.hs +55/−0
kubernetes-client.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: kubernetes-client-version: 0.2.0.0+version: 0.3.0.0 license: Apache-2.0 license-file: LICENSE maintainer:@@ -26,6 +26,7 @@ library exposed-modules: Kubernetes.Client+ Kubernetes.Client.Auth.Basic Kubernetes.Client.Auth.ClientCert Kubernetes.Client.Auth.GCP Kubernetes.Client.Auth.Internal.Types@@ -46,37 +47,37 @@ aeson >=1.2 && <1.5, attoparsec ==0.13.*, base >=4.7 && <5.0,- base64-bytestring >=1.0.0.2 && <1.1,+ base64-bytestring >=1.0.0.2, bytestring ==0.10.*,- connection >=0.2 && <0.4,- containers >=0.5 && <0.7,- data-default-class ==0.1.*,- either ==5.0.*,- filepath ==1.4.*,- hoauth2 ==1.8.*,+ connection >=0.2,+ containers >=0.5,+ data-default-class >=0.1,+ either >=5.0,+ filepath >=1.4,+ hoauth2 >=1.8, http-client >=0.5 && <0.7,- http-client-tls ==0.3.*,- jose-jwt ==0.8.*,+ http-client-tls >=0.3,+ jose-jwt >=0.8, jsonpath ==0.1.*,- kubernetes-client-core ==0.2.0.0,+ kubernetes-client-core ==0.3.0.0, microlens ==0.4.*,- mtl ==2.2.*,- oidc-client ==0.4.*,- pem ==0.2.*,- safe-exceptions >=0.1.0.0 && <0.2,- stm >=2.4 && <2.6,+ mtl >=2.2,+ oidc-client >=0.4,+ pem >=0.2,+ safe-exceptions >=0.1.0.0,+ stm >=2.4, streaming-bytestring >=0.1 && <0.2.0, text >=0.11 && <1.3,- time ==1.8.*,- timerep ==2.0.*,- tls >=1.4.1 && <1.5,- typed-process ==0.2.*,- uri-bytestring ==0.3.*,- x509 ==1.7.*,- x509-store ==1.6.*,- x509-system ==1.6.*,- x509-validation ==1.6.*,- yaml >=0.8.32 && <0.12+ time >=1.8,+ timerep >=2.0,+ tls >=1.4.1,+ typed-process >=0.2,+ uri-bytestring >=0.3,+ x509 >=1.7,+ x509-store >=1.6,+ x509-system >=1.6,+ x509-validation >=1.6,+ yaml >=0.8.32 test-suite example type: exitcode-stdio-1.0@@ -88,44 +89,45 @@ aeson >=1.2 && <1.5, attoparsec ==0.13.*, base >=4.7 && <5.0,- base64-bytestring >=1.0.0.2 && <1.1,+ base64-bytestring >=1.0.0.2, bytestring ==0.10.*,- connection >=0.2 && <0.4,- containers >=0.5 && <0.7,- data-default-class ==0.1.*,- either ==5.0.*,- filepath ==1.4.*,- hoauth2 ==1.8.*,+ connection >=0.2,+ containers >=0.5,+ data-default-class >=0.1,+ either >=5.0,+ filepath >=1.4,+ hoauth2 >=1.8, http-client >=0.5 && <0.7,- http-client-tls ==0.3.*,- jose-jwt ==0.8.*,+ http-client-tls >=0.3,+ jose-jwt >=0.8, jsonpath ==0.1.*, kubernetes-client -any,- kubernetes-client-core ==0.2.0.0,+ kubernetes-client-core ==0.3.0.0, microlens ==0.4.*,- mtl ==2.2.*,- oidc-client ==0.4.*,- pem ==0.2.*,- safe-exceptions >=0.1.0.0 && <0.2,- stm >=2.4 && <2.6,+ mtl >=2.2,+ oidc-client >=0.4,+ pem >=0.2,+ safe-exceptions >=0.1.0.0,+ stm >=2.4, streaming-bytestring >=0.1 && <0.2.0, text >=0.11 && <1.3,- time ==1.8.*,- timerep ==2.0.*,- tls >=1.4.1 && <1.5,- typed-process ==0.2.*,- uri-bytestring ==0.3.*,- x509 ==1.7.*,- x509-store ==1.6.*,- x509-system ==1.6.*,- x509-validation ==1.6.*,- yaml >=0.8.32 && <0.12+ time >=1.8,+ timerep >=2.0,+ tls >=1.4.1,+ typed-process >=0.2,+ uri-bytestring >=0.3,+ x509 >=1.7,+ x509-store >=1.6,+ x509-system >=1.6,+ x509-validation >=1.6,+ yaml >=0.8.32 test-suite spec type: exitcode-stdio-1.0 main-is: Spec.hs hs-source-dirs: test other-modules:+ Kubernetes.Client.Auth.BasicSpec Kubernetes.Client.Auth.ClientCertSpec Kubernetes.Client.Auth.TokenFileSpec Kubernetes.Client.KubeConfigSpec@@ -137,38 +139,38 @@ aeson >=1.2 && <1.5, attoparsec ==0.13.*, base >=4.7 && <5.0,- base64-bytestring >=1.0.0.2 && <1.1,+ base64-bytestring >=1.0.0.2, bytestring ==0.10.*,- connection >=0.2 && <0.4,- containers >=0.5 && <0.7,- data-default-class ==0.1.*,- either ==5.0.*,- file-embed >=0.0.11 && <0.1,- filepath ==1.4.*,- hoauth2 ==1.8.*,- hspec >=2.7.1 && <2.8,- hspec-attoparsec >=0.1.0.2 && <0.2,+ connection >=0.2,+ containers >=0.5,+ data-default-class >=0.1,+ either >=5.0,+ file-embed >=0.0.11,+ filepath >=1.4,+ hoauth2 >=1.8,+ hspec >=2.7.1,+ hspec-attoparsec >=0.1.0.2, http-client >=0.5 && <0.7,- http-client-tls ==0.3.*,- jose-jwt ==0.8.*,+ http-client-tls >=0.3,+ jose-jwt >=0.8, jsonpath ==0.1.*, kubernetes-client -any,- kubernetes-client-core ==0.2.0.0,+ kubernetes-client-core ==0.3.0.0, microlens ==0.4.*,- mtl ==2.2.*,- oidc-client ==0.4.*,- pem ==0.2.*,- safe-exceptions >=0.1.0.0 && <0.2,- stm >=2.4 && <2.6,+ mtl >=2.2,+ oidc-client >=0.4,+ pem >=0.2,+ safe-exceptions >=0.1.0.0,+ stm >=2.4, streaming-bytestring >=0.1 && <0.2.0, text >=0.11 && <1.3,- time ==1.8.*,- timerep ==2.0.*,- tls >=1.4.1 && <1.5,- typed-process ==0.2.*,- uri-bytestring ==0.3.*,- x509 ==1.7.*,- x509-store ==1.6.*,- x509-system ==1.6.*,- x509-validation ==1.6.*,- yaml >=0.11.1.2 && <0.12+ time >=1.8,+ timerep >=2.0,+ tls >=1.4.1,+ typed-process >=0.2,+ uri-bytestring >=0.3,+ x509 >=1.7,+ x509-store >=1.6,+ x509-system >=1.6,+ x509-validation >=1.6,+ yaml >=0.11.1.2
+ src/Kubernetes/Client/Auth/Basic.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}+module Kubernetes.Client.Auth.Basic where++import Data.ByteString.Base64 ( encode )+import Data.Function ( (&) )+import Data.Monoid ( (<>) )+import Data.Text ( Text )+import Kubernetes.Client.Auth.Internal.Types+import Kubernetes.OpenAPI.Core+import Kubernetes.Client.KubeConfig++import qualified Data.Text.Encoding as T+import qualified Lens.Micro as L+++data BasicAuth = BasicAuth { basicAuthUsername :: Text+ , basicAuthPassword :: Text+ }++instance AuthMethod BasicAuth where+ applyAuthMethod _ BasicAuth{..} req =+ pure+ $ req+ `setHeader` toHeader ("authorization", "Basic " <> encodeBasicAuth)+ & L.set rAuthTypesL []+ where+ encodeBasicAuth = T.decodeUtf8 $ encode $ T.encodeUtf8 $ basicAuthUsername <> ":" <> basicAuthPassword++-- |Detects if username and password is specified in AuthConfig, if it is configures 'KubernetesClientConfig' with 'BasicAuth'+basicAuth :: DetectAuth+basicAuth auth (tlsParams, cfg) = do+ u <- username auth+ p <- password auth+ return $ return (tlsParams, setBasicAuth u p cfg)++-- |Configures the 'KubernetesClientConfig' to use basic authentication.+setBasicAuth+ :: Text -- ^Username+ -> Text -- ^Password+ -> KubernetesClientConfig+ -> KubernetesClientConfig+setBasicAuth u p kcfg = kcfg+ { configAuthMethods = [AnyAuthMethod (BasicAuth u p)]+ }
src/Kubernetes/Client/Config.hs view
@@ -44,6 +44,7 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Yaml+import Kubernetes.Client.Auth.Basic import Kubernetes.Client.Auth.ClientCert import Kubernetes.Client.Auth.GCP import Kubernetes.Client.Auth.OIDC@@ -172,3 +173,4 @@ <|> tokenFileAuth auth input <|> gcpAuth auth input <|> cachedOIDCAuth oidcCache auth input+ <|> basicAuth auth input
+ test/Kubernetes/Client/Auth/BasicSpec.hs view
@@ -0,0 +1,55 @@+{-# LANGUAGE OverloadedStrings #-}+module Kubernetes.Client.Auth.BasicSpec where++import Test.Hspec+import Data.Typeable+import Data.Maybe ( isJust+ , isNothing+ , fromJust+ )+import Kubernetes.Client.Auth.Basic+import Kubernetes.Client.KubeConfig+import Kubernetes.OpenAPI+import Network.TLS ( defaultParamsClient )++emptyAuthInfo :: AuthInfo+emptyAuthInfo = AuthInfo Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing+ Nothing++spec :: Spec+spec = do+ let testTLSParams = defaultParamsClient "" ""+ testUsername = Just "testuser"+ testPassword = Just "testpassword"+ basicAuthInfo = emptyAuthInfo { username = testUsername, password = testPassword}+ describe "Basic Authentication" $ do+ it "should return Nothing if the username an d/or password is not provided" $ do+ testConfig <- newConfig+ isNothing (basicAuth emptyAuthInfo (testTLSParams, testConfig))+ `shouldBe` True+ isNothing (basicAuth emptyAuthInfo { username = testUsername} (testTLSParams, testConfig))+ `shouldBe` True+ isNothing (basicAuth emptyAuthInfo { password = testUsername} (testTLSParams, testConfig))+ `shouldBe` True++ context "when username and password are provided" $ do+ it "should return a configuration provider io" $ do+ testConfig <- newConfig+ isJust (basicAuth basicAuthInfo (testTLSParams, testConfig)) `shouldBe` True+ + it "should configure basic auth" $ do+ testConfig <- newConfig+ (_, (KubernetesClientConfig { configAuthMethods = AnyAuthMethod (a) : as })) <- + fromJust $ basicAuth basicAuthInfo (testTLSParams, testConfig)+ null as `shouldBe` True+ isJust (cast a :: Maybe BasicAuth) `shouldBe` True