1
0
Fork 0

mvp in 90 uloc

This commit is contained in:
setop 2024-11-26 19:03:44 +01:00
commit 72071df374
4 changed files with 174 additions and 0 deletions

19
README.md Normal file
View File

@ -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)

24
elm.json Normal file
View File

@ -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": {}
}
}

127
src/Main.elm Normal file
View File

@ -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))
]

4
uloc.sh Executable file
View File

@ -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