mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-29 09:32:57 +03:00
Move over internal functions from Secrets module to a new internal module.
This commit is contained in:
parent
bcf33a86da
commit
8bc59a3d59
@ -28,6 +28,7 @@ import Mark
|
||||
import Pages.ContentCache as ContentCache exposing (ContentCache)
|
||||
import Pages.Document
|
||||
import Pages.ImagePath as ImagePath
|
||||
import Pages.Internal.Secrets
|
||||
import Pages.Manifest as Manifest
|
||||
import Pages.PagePath as PagePath exposing (PagePath)
|
||||
import Pages.StaticHttpRequest as StaticHttpRequest
|
||||
@ -267,7 +268,7 @@ init :
|
||||
-> Decode.Value
|
||||
-> ( model, Effect pathKey )
|
||||
init toModel contentCache siteMetadata config cliMsgConstructor flags =
|
||||
case Decode.decodeValue (Decode.field "secrets" Secrets.decoder) flags of
|
||||
case Decode.decodeValue (Decode.field "secrets" Pages.Internal.Secrets.decoder) flags of
|
||||
Ok secrets ->
|
||||
case contentCache of
|
||||
Ok _ ->
|
||||
@ -361,7 +362,7 @@ init toModel contentCache siteMetadata config cliMsgConstructor flags =
|
||||
|
||||
Err error ->
|
||||
( Model Dict.empty
|
||||
Secrets.empty
|
||||
Pages.Internal.Secrets.empty
|
||||
[ InternalError <| { message = [ Terminal.text <| "Failed to parse flags: " ++ Decode.errorToString error ] }
|
||||
]
|
||||
|> toModel
|
||||
@ -494,7 +495,7 @@ performStaticHttpRequests secrets staticRequests =
|
||||
urlBuilder secrets
|
||||
|> Result.map
|
||||
(\unmasked ->
|
||||
FetchHttp unmasked (Secrets.useFakeSecrets urlBuilder)
|
||||
FetchHttp unmasked (Pages.Internal.Secrets.useFakeSecrets urlBuilder)
|
||||
)
|
||||
|> Result.mapError MissingSecret
|
||||
)
|
||||
@ -556,7 +557,7 @@ staticResponsesUpdate newEntry staticResponses =
|
||||
urls
|
||||
|> List.map
|
||||
(\urlBuilder ->
|
||||
Secrets.useFakeSecrets urlBuilder
|
||||
Pages.Internal.Secrets.useFakeSecrets urlBuilder
|
||||
)
|
||||
|
||||
includesUrl =
|
||||
|
35
src/Pages/Internal/Secrets.elm
Normal file
35
src/Pages/Internal/Secrets.elm
Normal file
@ -0,0 +1,35 @@
|
||||
module Pages.Internal.Secrets exposing (Secrets(..), decoder, empty, useFakeSecrets)
|
||||
|
||||
import BuildError exposing (BuildError)
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
|
||||
|
||||
type alias UrlWithSecrets =
|
||||
Secrets -> Result BuildError String
|
||||
|
||||
|
||||
type Secrets
|
||||
= Secrets (Dict String String)
|
||||
| Protected
|
||||
|
||||
|
||||
protected : Secrets
|
||||
protected =
|
||||
Protected
|
||||
|
||||
|
||||
useFakeSecrets : (Secrets -> Result BuildError String) -> String
|
||||
useFakeSecrets urlWithSecrets =
|
||||
urlWithSecrets protected
|
||||
|> Result.withDefault ""
|
||||
|
||||
|
||||
empty =
|
||||
Secrets Dict.empty
|
||||
|
||||
|
||||
decoder : Decoder Secrets
|
||||
decoder =
|
||||
Decode.dict Decode.string
|
||||
|> Decode.map Secrets
|
@ -1,34 +1,14 @@
|
||||
module Secrets exposing (..)
|
||||
module Secrets exposing (Secrets, get)
|
||||
|
||||
import BuildError exposing (BuildError)
|
||||
import Dict exposing (Dict)
|
||||
import Fuzzy
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Pages.Internal.Secrets exposing (Secrets(..))
|
||||
import TerminalText as Terminal
|
||||
|
||||
|
||||
type alias UrlWithSecrets =
|
||||
Secrets -> Result BuildError String
|
||||
|
||||
|
||||
type Secrets
|
||||
= Secrets (Dict String String)
|
||||
| Protected
|
||||
|
||||
|
||||
protected : Secrets
|
||||
protected =
|
||||
Protected
|
||||
|
||||
|
||||
useFakeSecrets : (Secrets -> Result BuildError String) -> String
|
||||
useFakeSecrets urlWithSecrets =
|
||||
urlWithSecrets protected
|
||||
|> Result.withDefault ""
|
||||
|
||||
|
||||
empty =
|
||||
Secrets Dict.empty
|
||||
type alias Secrets =
|
||||
Pages.Internal.Secrets.Secrets
|
||||
|
||||
|
||||
get : String -> Secrets -> Result BuildError String
|
||||
@ -76,9 +56,3 @@ sortMatches missingSecret availableSecrets =
|
||||
Fuzzy.match config separators needle hay |> .score
|
||||
in
|
||||
List.sortBy (simpleMatch [] [] missingSecret) availableSecrets
|
||||
|
||||
|
||||
decoder : Decoder Secrets
|
||||
decoder =
|
||||
Decode.dict Decode.string
|
||||
|> Decode.map Secrets
|
||||
|
@ -5,6 +5,7 @@ import Dict exposing (Dict)
|
||||
import Head
|
||||
import Html exposing (Html)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Pages.Internal.Secrets
|
||||
import Pages.StaticHttpRequest exposing (Request(..))
|
||||
import Secrets exposing (Secrets)
|
||||
|
||||
@ -83,14 +84,14 @@ jsonRequestWithSecrets urlWithSecrets decoder =
|
||||
( [ urlWithSecrets ]
|
||||
, \rawResponseDict ->
|
||||
rawResponseDict
|
||||
|> Dict.get (Secrets.useFakeSecrets urlWithSecrets)
|
||||
|> Dict.get (Pages.Internal.Secrets.useFakeSecrets urlWithSecrets)
|
||||
|> (\maybeResponse ->
|
||||
case maybeResponse of
|
||||
Just rawResponse ->
|
||||
Ok rawResponse
|
||||
|
||||
Nothing ->
|
||||
Err <| "Couldn't find response for url `" ++ Secrets.useFakeSecrets urlWithSecrets ++ "`"
|
||||
Err <| "Couldn't find response for url `" ++ Pages.Internal.Secrets.useFakeSecrets urlWithSecrets ++ "`"
|
||||
)
|
||||
|> Result.andThen
|
||||
(\rawResponse ->
|
||||
|
Loading…
Reference in New Issue
Block a user