forked from Normation/rudder
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
416 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 40 additions & 27 deletions
67
webapp/sources/rudder/rudder-web/src/main/elm/secret/sources/DataTypes.elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
111 changes: 8 additions & 103 deletions
111
webapp/sources/rudder/rudder-web/src/main/elm/secret/sources/Init.elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,17 @@ | ||
module Init exposing (..) | ||
|
||
------------------------------ | ||
-- SUBSCRIPTIONS | ||
------------------------------ | ||
|
||
import ApiCalls exposing (getAllSecrets) | ||
import DataTypes exposing (Model, Msg(..), StateInput(..)) | ||
import Html.Attributes exposing (style) | ||
import Http | ||
import Toasty | ||
import Toasty.Defaults | ||
import DataTypes exposing (Column(..), Mode(..), Model, Msg(..), Sorting(..), StateInput(..)) | ||
|
||
subscriptions : Model -> Sub Msg | ||
subscriptions model = | ||
Sub.none | ||
|
||
------------------------------ | ||
-- Init and main -- | ||
------------------------------ | ||
|
||
Sub.none | ||
|
||
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 [] [] | ||
in | ||
( initModel | ||
, getAllSecrets initModel | ||
) | ||
|
||
------------------------------ | ||
-- NOTIFICATIONS -- | ||
------------------------------ | ||
|
||
getErrorMessage : Http.Error -> String | ||
getErrorMessage e = | ||
let | ||
errMessage = | ||
case e of | ||
Http.BadStatus b -> | ||
let | ||
status = | ||
b.status | ||
|
||
message = | ||
status.message | ||
in | ||
"Code " ++ String.fromInt status.code ++ " : " ++ message | ||
|
||
Http.BadUrl str -> | ||
"Invalid API url" | ||
|
||
Http.Timeout -> | ||
"It took too long to get a response" | ||
|
||
Http.NetworkError -> | ||
"Network error" | ||
|
||
Http.BadPayload str rstr -> | ||
str | ||
in | ||
errMessage | ||
|
||
-- | ||
--defaultConfig : Toasty.Config Msg | ||
--defaultConfig = | ||
-- Toasty.Defaults.config | ||
-- |> Toasty.delay 999999999 | ||
-- |> Toasty.containerAttrs | ||
-- [ style "position" "fixed" | ||
-- , style "top" "50px" | ||
-- , style "right" "30px" | ||
-- , style "width" "100%" | ||
-- , style "max-width" "500px" | ||
-- , style "list-style-type" "none" | ||
-- , style "padding" "0" | ||
-- , style "margin" "0" | ||
-- , style "z-index" "9999" | ||
-- ] | ||
-- | ||
-- | ||
--tempConfig : Toasty.Config Msg | ||
--tempConfig = | ||
-- defaultConfig |> Toasty.delay 3000 | ||
-- | ||
-- | ||
--addTempToast : Toasty.Defaults.Toast -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg ) | ||
--addTempToast toast ( model, cmd ) = | ||
-- Toasty.addToast tempConfig ToastyMsg toast ( model, cmd ) | ||
-- | ||
-- | ||
--addToast : Toasty.Defaults.Toast -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg ) | ||
--addToast toast ( model, cmd ) = | ||
-- Toasty.addToast defaultConfig ToastyMsg toast ( model, cmd ) | ||
-- | ||
-- | ||
--createSuccessNotification : String -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg ) | ||
--createSuccessNotification message = | ||
-- addTempToast (Toasty.Defaults.Success "Success!" message) | ||
-- | ||
-- | ||
--createErrorNotification : String -> Http.Error -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg ) | ||
--createErrorNotification message e = | ||
-- addToast (Toasty.Defaults.Error "Error..." (message ++ " (" ++ getErrorMessage e ++ ")")) | ||
-- | ||
-- | ||
--createDecodeErrorNotification : String -> String -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg ) | ||
--createDecodeErrorNotification message e = | ||
-- addToast (Toasty.Defaults.Error "Error..." (message ++ " (" ++ e ++ ")")) | ||
let | ||
initModel = Model flags.contextPath [] Nothing Nothing Read [] [] (NONE, Name) Nothing | ||
in | ||
( initModel | ||
, getAllSecrets initModel | ||
) |
26 changes: 9 additions & 17 deletions
26
webapp/sources/rudder/rudder-web/src/main/elm/secret/sources/JsonDecoder.elm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.