commit 72071df3742fa84981d167dd9b43a4cec3b95cb5 Author: setop Date: Tue Nov 26 19:03:44 2024 +0100 mvp in 90 uloc diff --git a/README.md b/README.md new file mode 100644 index 0000000..b9189dd --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ + +Implements naming convention based on resource properies, such as type, location, role, application code + +Requirement : name must update in real time when properties are edited (no stale result). + +# TODO + +- [x] virtual machines + - [x] code + - [x] region + - [x] environment + - [x] role + - [x] increment +- [ ] other resource type + - [ ] resource group + - [ ] storage account +- [ ] some styling +- [ ] propose some links (azure web console, datadog, leanix) +- [ ] lookup code from app name with fuzzy search (try native component at first) diff --git a/elm.json b/elm.json new file mode 100644 index 0000000..ce2a08d --- /dev/null +++ b/elm.json @@ -0,0 +1,24 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/src/Main.elm b/src/Main.elm new file mode 100644 index 0000000..dbd3e01 --- /dev/null +++ b/src/Main.elm @@ -0,0 +1,127 @@ +module Main exposing (..) + +import Browser +import Html exposing (..) +import Html.Attributes exposing (..) +import Html.Events exposing (..) + + +main = + Browser.sandbox + { init = init + , view = view + , update = update + } + + +init = + { reg = "EW", code = "zz", env = "P", role = "APP", incr = 1 } + + +regions = + [ ( "EW", "West Europe, Amsterdam" ) + , ( "EN", "North Europe, Dublin" ) + ] + + +roles = + [ ( "APP", "Application Server" ) + , ( "WEB", "Web Server" ) + , ( "DBA", "Database" ) + , ( "RDS", "Remote Desktop Server" ) + ] + + +envs = + [ ( "P", "Production" ) + , ( "E", "Préproduction" ) + , ( "U", "UAT" ) + , ( "T", "Test" ) + , ( "I", "Integration" ) + ] + + +type Msg + = InputCode String + | InputReg String + | InputRole String + | InputEnv String + | InputIncr String + + +update msg model = + case msg of + InputCode s -> + { model | code = s } + + InputReg s -> + { model | reg = s } + + InputRole s -> + { model | role = s } + + InputEnv s -> + { model | env = s } + + InputIncr s -> + { model | incr = String.toInt s |> Maybe.withDefault 1 } + + +formatName r = + "AL" + ++ r.reg + ++ "1" + -- AZ is hard coded :( + ++ r.code + ++ r.env + ++ r.role + ++ (if r.incr < 10 then + "0" + + else + "" + ) + ++ String.fromInt r.incr + + +br_ = + br [] [] + + +renderSelect : (String -> Msg) -> List ( String, String ) -> Html Msg +renderSelect msg options = + select [ onInput msg ] (options |> List.map renderOption) + + +renderOption : ( String, String ) -> Html Msg +renderOption opt = + option [ opt |> Tuple.first |> value ] [ opt |> Tuple.second |> text ] + + +view model = + div [] + [ h1 [] [ text "Name Generator 😎" ] + , br_ + , text (formatName model) + , br_ + , br_ + , br_ + , text "code" + , input [ onInput InputCode, value model.code ] [] + , br_ + , br_ + , text "region" + , renderSelect InputReg regions + , br_ + , br_ + , text "environment" + , renderSelect InputEnv envs + , br_ + , br_ + , text "role" + , renderSelect InputRole roles + , br_ + , br_ + , text "increment" + , select [ onInput InputIncr ] (List.range 1 20 |> List.map (String.fromInt >> (\s -> ( s, s )) >> renderOption)) + ] diff --git a/uloc.sh b/uloc.sh new file mode 100755 index 0000000..db9c733 --- /dev/null +++ b/uloc.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +find . \( -name "*.sh" -or -name "*.elm" \) -and -not \( -path "./elm-stuff/*" -or -path "./.vscode/*" \) -print0 | \ +xargs -0 cat | countuniq0 # sort -u | wc -l