Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Oct 12, 2021
1 parent 1f12e44 commit 7142dbd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ getRulesCompliance model =
in
send GetRulesComplianceResult req

getNodesList : Model -> Cmd Msg
getNodesList model =
let
req =
request
{ method = "GET"
, headers = []
, url = getUrl model "/nodes"
, body = emptyBody
, expect = expectJson decodeGetNodesList
, timeout = Nothing
, withCredentials = False
}
in
send GetNodesList req


saveRuleDetails : Rule -> Bool -> Model -> Cmd Msg
saveRuleDetails ruleDetails creation model =
let
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ type alias Technique =
, directives : List Directive
}

type alias NodeInfo =
{ id : String
, hostname : String
, description : String
, policyMode : String
}

type alias Category a =
{ id : String
, name : String
Expand Down Expand Up @@ -199,6 +206,7 @@ type alias Model =
, techniquesTree : Category Technique
, rulesCompliance : List RuleCompliance
, directives : List Directive
, nodes : List NodeInfo
, ui : UI
}

Expand All @@ -223,6 +231,7 @@ type Msg
| GetRulesResult (Result Error (Category Rule))
| GetGroupsTreeResult (Result Error (Category Group))
| GetTechniquesTreeResult (Result Error ((Category Technique, List Technique)))
| GetNodesList (Result Error (List NodeInfo))
| DeleteRule (Result Error (RuleId, String))
| DeleteCategory (Result Error (String, String))
| DisableRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ init flags =
initCategory = Category "" "" "" (SubCategories []) []
initFilters = Filters (TableFilters Name True "") (TreeFilters "" [])
initUI = UI initFilters initFilters initFilters NoModal flags.hasWriteRights
initModel = Model flags.contextPath Loading "" initCategory initCategory initCategory [] [] initUI
initModel = Model flags.contextPath Loading "" initCategory initCategory initCategory [] [] [] initUI

listInitActions =
[ getPolicyMode initModel
, getNodesList initModel
, getRulesCompliance initModel
, getGroupsTree initModel
, getTechniquesTree initModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,15 @@ decodeTargets =
string

]

decodeGetNodesList : Decoder (List NodeInfo)
decodeGetNodesList =
D.at ["data", "nodes" ] (D.list decodeNodeInfo)

decodeNodeInfo : Decoder NodeInfo
decodeNodeInfo =
succeed NodeInfo
|> required "id" D.string
|> required "hostname" D.string
|> required "description" D.string
|> required "policyMode" D.string
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ update msg model =
Err err ->
(model, Cmd.none)

GetNodesList res ->
case res of
Ok nodes ->
({model | nodes = nodes}, Cmd.none)
Err err ->
processApiError "Getting Nodes list" err model

OpenRuleDetails rId True ->
(model, Cmd.batch [getRuleDetails model rId, pushUrl ("rule", rId.value)])
OpenRuleDetails rId False ->
Expand Down

0 comments on commit 7142dbd

Please sign in to comment.