Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaadF committed Apr 11, 2021
1 parent 19cda1a commit 55b3ddc
Show file tree
Hide file tree
Showing 8 changed files with 322 additions and 200 deletions.
Expand Up @@ -2,12 +2,12 @@ module ApiCalls exposing (..)

import DataTypes exposing (Model, Msg(..), Secret)
import Http exposing (emptyBody, expectJson, jsonBody, request, send)
import JsonDecoder exposing (decodeDeleteSecret, decodeGetAllSecrets, decodeOneSecret)
import JsonDecoder exposing (decodeSecretsApi)
import JsonEncoder exposing (encodeSecret)

getUrl: DataTypes.Model -> String -> String
getUrl m parameter =
m.contextPath ++ "/secure/api/latest/secret" ++ parameter
getUrl m url =
m.contextPath ++ "/secure/api" ++ url

getSecret : Model -> String -> Cmd Msg
getSecret model secretName =
Expand All @@ -16,9 +16,9 @@ getSecret model secretName =
request
{ method = "GET"
, headers = []
, url = getUrl model secretName
, url = getUrl model ("/secret/" ++ secretName)
, body = emptyBody
, expect = expectJson decodeOneSecret
, expect = expectJson decodeSecretsApi
, timeout = Nothing
, withCredentials = False
}
Expand All @@ -32,9 +32,9 @@ getAllSecrets model =
request
{ method = "GET"
, headers = []
, url = getUrl model ""
, url = getUrl model "/secret"
, body = emptyBody
, expect = expectJson decodeGetAllSecrets
, expect = expectJson decodeSecretsApi
, timeout = Nothing
, withCredentials = False
}
Expand All @@ -48,9 +48,9 @@ deleteSecret secretName model =
request
{ method = "DELETE"
, headers = []
, url = getUrl model secretName
, url = getUrl model ("/secret/" ++ secretName)
, body = emptyBody
, expect = expectJson decodeDeleteSecret
, expect = expectJson decodeSecretsApi
, timeout = Nothing
, withCredentials = False
}
Expand All @@ -64,9 +64,9 @@ addSecret model secret =
request
{ method = "PUT"
, headers = []
, url = getUrl model ""
, url = getUrl model "/secret"
, body = jsonBody (encodeSecret secret)
, expect = expectJson decodeOneSecret
, expect = expectJson decodeSecretsApi
, timeout = Nothing
, withCredentials = False
}
Expand All @@ -80,9 +80,9 @@ updateSecret model secret =
request
{ method = "POST"
, headers = []
, url = getUrl model ""
, url = getUrl model "/secret"
, body = jsonBody (encodeSecret secret)
, expect = expectJson decodeOneSecret
, expect = expectJson decodeSecretsApi
, timeout = Nothing
, withCredentials = False
}
Expand Down
@@ -1,50 +1,63 @@
module DataTypes exposing(..)

import Http exposing (Error)
import Toasty
import Toasty.Defaults

type alias Secret =
{ name : String
{ info : SecretInfo
, value : String
}

type alias SecretInfo =
{ name : String
, description : String
}


type alias Model =
{ contextPath : String
, secrets : List Secret
, focusOn : Maybe Secret
, newSecretInput : Maybe Secret
, isOpenCreateModal : Bool
, isOpenEditModal : Bool
, stateInputs : List StateInput
{ contextPath : String
, secrets : List SecretInfo
, focusOn : Maybe SecretInfo
, newSecretInput : Maybe Secret
, openModalMode : Mode
, stateInputs : List StateInput
, openedDescription : List String
, sortOn : (Sorting, Column)
, filteredSecrets : Maybe (List SecretInfo)
}

type WriteAction
type Mode
= Edit
| Add
| Delete
| Read

type StateInput
= InvalidName
| InvalidValue
| InvalidDescription
= EmptyInputName
| EmptyInputValue
| EmptyInputDescription

type Sorting
= ASC
| DESC
| NONE

type Column
= Name
| Description

type Msg
= GetAllSecrets (Result Error (List Secret))
| GetSecret (Result Error Secret)
| AddSecret (Result Error Secret)
| DeleteSecret (Result Error String)
| UpdateSecret (Result Error Secret)
= GetAllSecrets (Result Error (List SecretInfo))
| GetSecret (Result Error (List SecretInfo))
| AddSecret (Result Error (List SecretInfo))
| DeleteSecret (Result Error (List SecretInfo))
| UpdateSecret (Result Error (List SecretInfo))
| CallApi (Model -> Cmd Msg)
| OpenCreateModal
| OpenEditModal Secret
| OpenModal Mode (Maybe SecretInfo)
| CloseModal
| InputName String
| InputValue String
| InputDescription String
| SubmitSecret WriteAction
| OpenDescription Secret
--
-- -- NOTIFICATIONS
--| ToastyMsg (Toasty.Msg Toasty.Defaults.Toast)
--| Notification (Toasty.Msg Toasty.Defaults.Toast)
| SubmitSecret Mode
| OpenDescription SecretInfo
| ChangeSorting Column
| FilterSecrets String
Expand Up @@ -5,11 +5,8 @@ module Init exposing (..)
------------------------------

import ApiCalls exposing (getAllSecrets)
import DataTypes exposing (Model, Msg(..), StateInput(..))
import Html.Attributes exposing (style)
import DataTypes exposing (Column(..), Mode(..), Model, Msg(..), Sorting(..), StateInput(..))
import Http
import Toasty
import Toasty.Defaults

subscriptions : Model -> Sub Msg
subscriptions model =
Expand All @@ -23,9 +20,7 @@ subscriptions model =
init : { contextPath : String } -> ( Model, Cmd Msg )
init flags =
let
--secrets = [(DataTypes.Secret "toto" "value1"), (DataTypes.Secret "tata" "value2"),( DataTypes.Secret "cqjdiueq" "value2"), (DataTypes.Secret "tv2rv2revwrata" "value2") ]

initModel = Model flags.contextPath [] Nothing Nothing False False [] []
initModel = Model flags.contextPath [] Nothing Nothing Read [] [] (NONE, Name) Nothing
in
( initModel
, getAllSecrets initModel
Expand Down
@@ -1,23 +1,15 @@
module JsonDecoder exposing (..)

import DataTypes exposing (Secret)
import DataTypes exposing (Secret, SecretInfo)
import Json.Decode as D exposing (Decoder)
import Json.Decode.Pipeline exposing (required)
import Json.Decode.Pipeline exposing (hardcoded, optional, required)

decodeGetAllSecrets : Decoder (List Secret)
decodeGetAllSecrets =
D.at [ "data" ] ( D.at [ "secrets" ] (D.list <| decodeSecret) )
decodeSecretsApi : Decoder (List SecretInfo)
decodeSecretsApi =
D.at [ "data" ] ( D.at [ "secrets" ] (D.list <| decodeSecretInfo) )

decodeOneSecret : Decoder Secret
decodeOneSecret =
D.at [ "data" ] ( D.at [ "secret" ] decodeSecret)

decodeDeleteSecret : Decoder String
decodeDeleteSecret =
D.at [ "data" ] ( D.at [ "secretName" ] D.string )

decodeSecret : Decoder Secret
decodeSecret =
D.succeed Secret
decodeSecretInfo : Decoder SecretInfo
decodeSecretInfo =
D.succeed SecretInfo
|> required "name" D.string
|> required "value" D.string
|> required "description" D.string
Expand Up @@ -6,6 +6,7 @@ import Json.Encode exposing (Value, object, string)
encodeSecret: Secret -> Value
encodeSecret secret =
object
[ ("name", string secret.name)
[ ("name", string secret.info.name)
, ("value", string secret.value)
, ("description", string secret.info.description)
]

0 comments on commit 55b3ddc

Please sign in to comment.