From 9e7a3a2e518fd24a020eeb386c916f9c40d0f308 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 15:48:43 -0300 Subject: [PATCH 01/23] chore: update deps --- go.mod | 22 +++++++++++----------- go.sum | 58 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/go.mod b/go.mod index 5eb9af79b..1fe854e4b 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,12 @@ require ( github.com/joho/godotenv v1.5.1 github.com/labstack/echo/v4 v4.12.0 github.com/shirou/gopsutil v3.21.11+incompatible - github.com/spf13/cobra v1.8.0 + github.com/spf13/cobra v1.8.1 github.com/swaggo/echo-swagger v1.4.1 github.com/swaggo/swag v1.16.3 - golang.org/x/crypto v0.23.0 - golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f - golang.org/x/net v0.24.0 + golang.org/x/crypto v0.24.0 + golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 + golang.org/x/net v0.26.0 gopkg.in/yaml.v3 v3.0.1 gorm.io/gorm v1.25.10 ) @@ -43,7 +43,7 @@ require ( github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/josharian/intern v1.0.0 // indirect - github.com/klauspost/compress v1.17.8 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -59,14 +59,14 @@ require ( github.com/valyala/fasttemplate v1.2.2 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect go.opencensus.io v0.24.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect - golang.org/x/tools v0.20.0 // indirect - google.golang.org/protobuf v1.34.1 // indirect + golang.org/x/tools v0.22.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - modernc.org/libc v1.50.5 // indirect + modernc.org/libc v1.54.2 // indirect modernc.org/mathutil v1.6.0 // indirect modernc.org/memory v1.8.0 // indirect - modernc.org/sqlite v1.29.9 // indirect + modernc.org/sqlite v1.30.1 // indirect ) diff --git a/go.sum b/go.sum index 4f7a40220..be61b46e9 100644 --- a/go.sum +++ b/go.sum @@ -10,7 +10,7 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -95,8 +95,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= -github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -126,8 +126,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -162,18 +162,18 @@ go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= +golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY= -golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= +golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= +golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= +golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -183,8 +183,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -202,12 +202,12 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -218,8 +218,8 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= -golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= +golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= +golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -243,8 +243,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -258,16 +258,16 @@ gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -modernc.org/cc/v4 v4.21.0 h1:D/gLKtcztomvWbsbvBKo3leKQv+86f+DdqEZBBXhnag= -modernc.org/cc/v4 v4.21.0/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= -modernc.org/ccgo/v4 v4.17.3 h1:t2CQci84jnxKw3GGnHvjGKjiNZeZqyQx/023spkk4hU= -modernc.org/ccgo/v4 v4.17.3/go.mod h1:1FCbAtWYJoKuc+AviS+dH+vGNtYmFJqBeRWjmnDWsIg= +modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ= +modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= +modernc.org/ccgo/v4 v4.19.0 h1:f9K5VdC0nVhHKTFMvhjtZ8TbRgFQbASvE5yO1zs8eC0= +modernc.org/ccgo/v4 v4.19.0/go.mod h1:CfpAl+673iXNwMG/aqcQn+vDcu4Es/YLya7+9RHjTa4= modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= -modernc.org/libc v1.50.5 h1:ZzeUd0dIc/sUtoPTCYIrgypkuzoGzNu6kbEWj2VuEmk= -modernc.org/libc v1.50.5/go.mod h1:rhzrUx5oePTSTIzBgM0mTftwWHK8tiT9aNFUt1mldl0= +modernc.org/libc v1.54.2 h1:9ymAodb+3v85YfBIZqn62BGgO4L9zF2Hx4LNb6dSU/Q= +modernc.org/libc v1.54.2/go.mod h1:B0D6klDmSmnq26T1iocn9kzyX6NtbzjuI3+oX/xfvng= modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= @@ -276,8 +276,8 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= -modernc.org/sqlite v1.29.9 h1:9RhNMklxJs+1596GNuAX+O/6040bvOwacTxuFcRuQow= -modernc.org/sqlite v1.29.9/go.mod h1:ItX2a1OVGgNsFh6Dv60JQvGfJfTPHPVpV6DF59akYOA= +modernc.org/sqlite v1.30.1 h1:YFhPVfu2iIgUf9kuA1CR7iiHdcEEsI2i+yjRYHscyxk= +modernc.org/sqlite v1.30.1/go.mod h1:DUmsiWQDaAvU4abhc/N+djlom/L2o8f7gZ95RCvyoLU= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= From f1a7c7c7c5ff6f6f4085456f068e657d45fe3a0a Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 16:42:03 -0300 Subject: [PATCH 02/23] fix: improve uninstall files delete readability --- src/infra/marketplace/marketplaceCmdRepo.go | 110 ++++++++++---------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/src/infra/marketplace/marketplaceCmdRepo.go b/src/infra/marketplace/marketplaceCmdRepo.go index ef43cab54..29f165ccb 100644 --- a/src/infra/marketplace/marketplaceCmdRepo.go +++ b/src/infra/marketplace/marketplaceCmdRepo.go @@ -82,13 +82,13 @@ func (repo *MarketplaceCmdRepo) parseSystemDataFields( installDir valueObject.UnixFilePath, installUrlPath valueObject.UrlPath, installHostname valueObject.Fqdn, - installUuid string, + installUuid valueObject.MarketplaceInstalledItemUuid, ) (systemDataFields []valueObject.MarketplaceInstallableItemDataField) { dataMap := map[string]string{ "installDirectory": installDir.String(), "installUrlPath": installUrlPath.String(), "installHostname": installHostname.String(), - "installUuid": installUuid, + "installUuid": installUuid.String(), "installTempDir": installTempDirPath, "installRandomPassword": infraHelper.GenPass(16), } @@ -301,7 +301,7 @@ func (repo *MarketplaceCmdRepo) persistInstalledItem( hostname valueObject.Fqdn, urlPath valueObject.UrlPath, installDir valueObject.UnixFilePath, - installUuid string, + installUuid valueObject.MarketplaceInstalledItemUuid, mappingsId []valueObject.MappingId, ) error { servicesList := []string{} @@ -323,7 +323,7 @@ func (repo *MarketplaceCmdRepo) persistInstalledItem( Type: catalogItem.Type.String(), UrlPath: urlPath.String(), InstallDirectory: installDir.String(), - InstallUuid: installUuid, + InstallUuid: installUuid.String(), Services: servicesListStr, Mappings: mappingModels, AvatarUrl: catalogItem.AvatarUrl.String(), @@ -364,12 +364,15 @@ func (repo *MarketplaceCmdRepo) InstallItem( } installDirStr = installDir.String() - installUuid := uuid.New().String()[:16] - installUuidWithoutHyphens := strings.Replace(installUuid, "-", "", -1) + rawInstallUuid := uuid.New().String()[:16] + rawInstallUuidNoHyphens := strings.Replace(rawInstallUuid, "-", "", -1) + installUuid, err := valueObject.NewMarketplaceInstalledItemUuid(rawInstallUuidNoHyphens) + if err != nil { + return err + } systemDataFields := repo.parseSystemDataFields( - installDir, installUrlPath, installDto.Hostname, - installUuidWithoutHyphens, + installDir, installUrlPath, installDto.Hostname, installUuid, ) receivedDataFields := slices.Concat(installDto.DataFields, systemDataFields) @@ -398,7 +401,7 @@ func (repo *MarketplaceCmdRepo) InstallItem( _, err = infraHelper.RunCmd("rm", "-rf", installTempDirPath) if err != nil { - return errors.New("RemoveTmpDirectoryError: " + err.Error()) + return errors.New("DeleteTmpDirectoryError: " + err.Error()) } err = repo.updateFilesPrivileges(installDir) @@ -423,7 +426,7 @@ func (repo *MarketplaceCmdRepo) InstallItem( installDto.Hostname, installUrlPath, installDir, - installUuidWithoutHyphens, + installUuid, mappingIds, ) } @@ -432,7 +435,7 @@ func (repo *MarketplaceCmdRepo) moveSelectedFiles( sourceDir valueObject.UnixFilePath, targetDir valueObject.UnixFilePath, fileNames []valueObject.UnixFileName, - shouldKeepInstead bool, + keepOnlySelectedInstead bool, ) error { fileNamesFilterParams := "-name \"" + fileNames[0].String() + "\"" for _, fileToIgnore := range fileNames[1:] { @@ -440,7 +443,7 @@ func (repo *MarketplaceCmdRepo) moveSelectedFiles( } findCmdFlags := []string{"-mindepth 1", "-maxdepth 1"} - if shouldKeepInstead { + if keepOnlySelectedInstead { findCmdFlags = append(findCmdFlags, "-not") } findCmdFlagsStr := strings.Join(findCmdFlags, " ") @@ -456,84 +459,85 @@ func (repo *MarketplaceCmdRepo) moveSelectedFiles( return err } -func (repo *MarketplaceCmdRepo) uninstallSymlinkFilesRemoval( +func (repo *MarketplaceCmdRepo) uninstallSymlinkFilesDelete( installedItem entity.MarketplaceInstalledItem, catalogItem entity.MarketplaceCatalogItem, - removalDestinationPath valueObject.UnixFilePath, + softDeleteDestDirPath valueObject.UnixFilePath, ) error { itemHostnameStr := installedItem.Hostname.String() - itemRootDirBackup, err := valueObject.NewUnixFilePath( - "/app/" + itemHostnameStr + "-backup", + unfamiliarFilesBackupDir, err := valueObject.NewUnixFilePath( + "/app/" + itemHostnameStr + "-unfamiliar-files-backup", ) if err != nil { return err } - itemRootDirBackupStr := itemRootDirBackup.String() - err = infraHelper.MakeDir(itemRootDirBackupStr) + unfamiliarFilesBackupDirStr := unfamiliarFilesBackupDir.String() + err = infraHelper.MakeDir(unfamiliarFilesBackupDirStr) if err != nil { - return errors.New("CreateRootDirBackupError: " + err.Error()) + return errors.New("CreateUnfamiliarFilesBackupDirError: " + err.Error()) } - shouldKeepInstead := true + keepOnlySelectedInstead := true err = repo.moveSelectedFiles( - installedItem.InstallDirectory, itemRootDirBackup, - catalogItem.UninstallFileNames, shouldKeepInstead, + installedItem.InstallDirectory, unfamiliarFilesBackupDir, + catalogItem.UninstallFileNames, keepOnlySelectedInstead, ) if err != nil { - return errors.New("MoveKeptFilesDuringUninstallError: " + err.Error()) + return errors.New("TemporarilyMoveUnfamiliarFilesError: " + err.Error()) } - itemSrcRootDirPath := fmt.Sprintf( + installedItemRealRootDirPath := fmt.Sprintf( "/app/%s-%s-%s", installedItem.Slug.String(), itemHostnameStr, installedItem.InstallUuid.String(), ) _, err = infraHelper.RunCmdWithSubShell( - "mv " + itemSrcRootDirPath + "/* " + removalDestinationPath.String(), + "mv " + installedItemRealRootDirPath + "/* " + softDeleteDestDirPath.String(), ) if err != nil { - return errors.New("MoveUninstallFilesToTrashError: " + err.Error()) + return errors.New("SoftDeleteItemFilesError: " + err.Error()) } _, err = infraHelper.RunCmdWithSubShell( - "rm -rf " + itemSrcRootDirPath, + "rm -rf " + installedItemRealRootDirPath, ) if err != nil { - return errors.New("DeleteItemSourceRootDirError: " + err.Error()) + return errors.New("DeleteItemRealRootPathError: " + err.Error()) } - itemRootDirStr := installedItem.InstallDirectory.String() + itemAliasesRootDirStr := installedItem.InstallDirectory.String() _, err = infraHelper.RunCmdWithSubShell( - "rm -rf " + itemRootDirStr, + "rm -rf " + itemAliasesRootDirStr, ) if err != nil { - return errors.New("DeleteItemSymlinkRootDirError: " + err.Error()) + return errors.New("DeleteItemAliasesRootDirError: " + err.Error()) } - err = infraHelper.MakeDir(itemRootDirStr) + err = infraHelper.MakeDir(itemAliasesRootDirStr) if err != nil { - return errors.New("RecreateItemRootDirError: " + err.Error()) + return errors.New("RecreateItemAliasesRootDirAsRealDirError: " + err.Error()) } - _, err = infraHelper.RunCmdWithSubShell( - "find " + itemRootDirBackupStr + "/ -mindepth 1 -maxdepth 1 -exec mv -t " + - itemRootDirStr + " {} +", + keepOnlySelectedInstead = true + err = repo.moveSelectedFiles( + unfamiliarFilesBackupDir, installedItem.InstallDirectory, + catalogItem.UninstallFileNames, keepOnlySelectedInstead, ) if err != nil { - return errors.New("RestoreKeptFilesDuringUninstallError: " + err.Error()) + return errors.New("RestoreUnfamiliarFilesError: " + err.Error()) } - _, err = infraHelper.RunCmdWithSubShell("rm -rf " + itemRootDirBackupStr) + _, err = infraHelper.RunCmdWithSubShell("rm -rf " + unfamiliarFilesBackupDirStr) if err != nil { - return errors.New("DeleteRootDirBackupError: " + err.Error()) + return errors.New("DeleteUnfamiliarFilesBackupDirError: " + err.Error()) } return nil } -func (repo *MarketplaceCmdRepo) uninstallFilesRemoval( +func (repo *MarketplaceCmdRepo) uninstallFilesDelete( installedItem entity.MarketplaceInstalledItem, catalogItem entity.MarketplaceCatalogItem, ) error { @@ -541,36 +545,36 @@ func (repo *MarketplaceCmdRepo) uninstallFilesRemoval( return nil } - removalDestinationPathStr := fmt.Sprintf( + softDeleteDestDirPathStr := fmt.Sprintf( "%s/%s-%s-%s", useCase.TrashDirPath, installedItem.Slug.String(), installedItem.Hostname.String(), installedItem.InstallUuid.String(), ) - removalDestinationPath, err := valueObject.NewUnixFilePath(removalDestinationPathStr) + softDeleteDestDirPath, err := valueObject.NewUnixFilePath(softDeleteDestDirPathStr) if err != nil { return err } - err = infraHelper.MakeDir(removalDestinationPathStr) + err = infraHelper.MakeDir(softDeleteDestDirPathStr) if err != nil { - return errors.New("CreateTrashDirectoryError: " + err.Error()) + return errors.New("CreateSoftDeleteDirError: " + err.Error()) } if infraHelper.IsSymlink(installedItem.InstallDirectory.String()) { - return repo.uninstallSymlinkFilesRemoval( - installedItem, catalogItem, removalDestinationPath, + return repo.uninstallSymlinkFilesDelete( + installedItem, catalogItem, softDeleteDestDirPath, ) } - shouldKeepInstead := false + keepOnlySelectedInstead := false err = repo.moveSelectedFiles( - installedItem.InstallDirectory, removalDestinationPath, - catalogItem.UninstallFileNames, shouldKeepInstead, + installedItem.InstallDirectory, softDeleteDestDirPath, + catalogItem.UninstallFileNames, keepOnlySelectedInstead, ) if err != nil { - return errors.New("RemoveFilesDuringUninstallError: " + err.Error()) + return errors.New("DeleteItemFilesError: " + err.Error()) } return nil @@ -646,14 +650,14 @@ func (repo *MarketplaceCmdRepo) UninstallItem( return err } - err = repo.uninstallFilesRemoval(installedItem, catalogItem) + err = repo.uninstallFilesDelete(installedItem, catalogItem) if err != nil { return err } systemDataFields := repo.parseSystemDataFields( - installedItem.InstallDirectory, installedItem.UrlPath, installedItem.Hostname, - installedItem.InstallUuid.String(), + installedItem.InstallDirectory, installedItem.UrlPath, + installedItem.Hostname, installedItem.InstallUuid, ) err = repo.runCmdSteps(catalogItem.UninstallCmdSteps, systemDataFields) if err != nil { From 0f374e7c5692f331ee65e7c8b822e9e45d4e8627 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 17:25:21 -0300 Subject: [PATCH 03/23] fix: adjust perms of soft delete dir --- src/infra/marketplace/marketplaceCmdRepo.go | 26 ++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/infra/marketplace/marketplaceCmdRepo.go b/src/infra/marketplace/marketplaceCmdRepo.go index 29f165ccb..c0c4f356c 100644 --- a/src/infra/marketplace/marketplaceCmdRepo.go +++ b/src/infra/marketplace/marketplaceCmdRepo.go @@ -192,25 +192,25 @@ func (repo *MarketplaceCmdRepo) runCmdSteps( } func (repo *MarketplaceCmdRepo) updateFilesPrivileges( - installDir valueObject.UnixFilePath, + targetDir valueObject.UnixFilePath, ) error { - installDirStr := installDir.String() + targetDirStr := targetDir.String() chownRecursively := true chownSymlinksToo := true err := infraHelper.UpdatePermissionsForWebServerUse( - installDirStr, chownRecursively, chownSymlinksToo, + targetDirStr, chownRecursively, chownSymlinksToo, ) if err != nil { - return errors.New("ChownError (" + installDirStr + "): " + err.Error()) + return errors.New("ChownError (" + targetDirStr + "): " + err.Error()) } _, err = infraHelper.RunCmdWithSubShell( - `find ` + installDirStr + ` -type d -exec chmod 755 {} \; && find ` + - installDirStr + ` -type f -exec chmod 644 {} \;`, + `find ` + targetDirStr + ` -type d -exec chmod 755 {} \; && find ` + + targetDirStr + ` -type f -exec chmod 644 {} \;`, ) if err != nil { - return errors.New("ChmodError (" + installDirStr + "): " + err.Error()) + return errors.New("ChmodError (" + targetDirStr + "): " + err.Error()) } return nil @@ -500,6 +500,11 @@ func (repo *MarketplaceCmdRepo) uninstallSymlinkFilesDelete( return errors.New("SoftDeleteItemFilesError: " + err.Error()) } + err = repo.updateFilesPrivileges(softDeleteDestDirPath) + if err != nil { + return errors.New("UpdateSoftDeleteDirPrivilegesError: " + err.Error()) + } + _, err = infraHelper.RunCmdWithSubShell( "rm -rf " + installedItemRealRootDirPath, ) @@ -574,7 +579,12 @@ func (repo *MarketplaceCmdRepo) uninstallFilesDelete( catalogItem.UninstallFileNames, keepOnlySelectedInstead, ) if err != nil { - return errors.New("DeleteItemFilesError: " + err.Error()) + return errors.New("SoftDeleteItemFilesError: " + err.Error()) + } + + err = repo.updateFilesPrivileges(softDeleteDestDirPath) + if err != nil { + return errors.New("UpdateSoftDeleteDirPrivilegesError: " + err.Error()) } return nil From 767bafc0e73b8670ed716d66badaf06671ff106d Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 17:25:36 -0300 Subject: [PATCH 04/23] fix: add mariadb client to pkgs --- src/infra/services/createInstallable.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/infra/services/createInstallable.go b/src/infra/services/createInstallable.go index 5b5a85029..f1f3c9aaf 100644 --- a/src/infra/services/createInstallable.go +++ b/src/infra/services/createInstallable.go @@ -56,6 +56,7 @@ var PhpPackages = []string{ var MariaDbPackages = []string{ "mariadb-server", + "mariadb-client", } var RedisPackages = []string{ From 82f7519638ed41d2c23c7c4ad9b98f92f0afa4c7 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:11:28 -0300 Subject: [PATCH 05/23] chore: update cspell --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 865e4b055..7a10d0aeb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,7 @@ "bitnami", "Bitnami", "Bsize", + "certbot", "clientid", "cpuacct", "CQRS", From 3161ccce36e51c9a7d0b08271a5ac5dbb124b0f2 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:11:41 -0300 Subject: [PATCH 06/23] feat: add dns lookup helper --- src/infra/helper/dnsLookup.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/infra/helper/dnsLookup.go diff --git a/src/infra/helper/dnsLookup.go b/src/infra/helper/dnsLookup.go new file mode 100644 index 000000000..54a581632 --- /dev/null +++ b/src/infra/helper/dnsLookup.go @@ -0,0 +1,33 @@ +package infraHelper + +import "strings" + +func DnsLookup(recordName string, recordType *string) ([]string, error) { + resourceRecords := []string{} + + recordTypeStr := "A" + if recordType != nil { + recordTypeStr = *recordType + } + + digCmd := "dig +short " + recordTypeStr + " " + recordName + + rawRecords, err := RunCmdWithSubShell(digCmd + " @dns.google") + if err != nil || rawRecords == "" { + rawRecords, err = RunCmdWithSubShell(digCmd + " @security-filter-dns.cleanbrowsing.org") + if err != nil { + return resourceRecords, err + } + } + + if rawRecords == "" { + return resourceRecords, nil + } + + rawRecordsParts := strings.Split(rawRecords, "\n") + for _, rawRecord := range rawRecordsParts { + resourceRecords = append(resourceRecords, strings.TrimSpace(rawRecord)) + } + + return resourceRecords, nil +} From a99af5d9fae561544f259a2cd62c56890eea03ca Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:11:53 -0300 Subject: [PATCH 07/23] feat: add read server public ip addr helper --- src/infra/helper/readServerPublicIpAddress.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/infra/helper/readServerPublicIpAddress.go diff --git a/src/infra/helper/readServerPublicIpAddress.go b/src/infra/helper/readServerPublicIpAddress.go new file mode 100644 index 000000000..b3d098f92 --- /dev/null +++ b/src/infra/helper/readServerPublicIpAddress.go @@ -0,0 +1,36 @@ +package infraHelper + +import ( + "errors" + "strings" + + "github.com/speedianet/os/src/domain/valueObject" +) + +func ReadServerPublicIpAddress() (ipAddress valueObject.IpAddress, err error) { + digCmd := "dig +short TXT" + rawRecord, err := RunCmdWithSubShell( + digCmd + " o-o.myaddr.l.google.com @ns1.google.com", + ) + if err != nil || rawRecord == "" { + rawRecord, err = RunCmdWithSubShell( + digCmd + "CH whoami.cloudflare @1.1.1.1", + ) + if err != nil { + return ipAddress, err + } + } + + rawRecord = strings.Trim(rawRecord, `"`) + rawRecord = strings.TrimSpace(rawRecord) + if rawRecord == "" { + return ipAddress, errors.New("PublicIpAddressNotFound") + } + + ipAddress, err = valueObject.NewIpAddress(rawRecord) + if err != nil { + return ipAddress, err + } + + return ipAddress, nil +} From aad595316cbfc1ab88af3ddd09989e95cbf2979d Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:12:07 -0300 Subject: [PATCH 08/23] fix: use read server ip helper --- src/infra/o11y/o11yQueryRepo.go | 40 +++++++++------------------------ 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/src/infra/o11y/o11yQueryRepo.go b/src/infra/o11y/o11yQueryRepo.go index 07abe308a..3c93e27b7 100644 --- a/src/infra/o11y/o11yQueryRepo.go +++ b/src/infra/o11y/o11yQueryRepo.go @@ -25,9 +25,7 @@ type O11yQueryRepo struct { func NewO11yQueryRepo( transientDbSvc *internalDbInfra.TransientDatabaseService, ) *O11yQueryRepo { - return &O11yQueryRepo{ - transientDbSvc: transientDbSvc, - } + return &O11yQueryRepo{transientDbSvc: transientDbSvc} } func (repo *O11yQueryRepo) getUptime() (uint64, error) { @@ -39,9 +37,10 @@ func (repo *O11yQueryRepo) getUptime() (uint64, error) { return uint64(sysinfo.Uptime), nil } -func (repo *O11yQueryRepo) getPublicIpAddress() (valueObject.IpAddress, error) { - var ipAddress valueObject.IpAddress - +func (repo *O11yQueryRepo) ReadServerPublicIpAddress() ( + ipAddress valueObject.IpAddress, + err error, +) { cachedIpAddressStr, err := repo.transientDbSvc.Get( infraData.GlobalConfigs.PublicIpTransientKey, ) @@ -49,37 +48,20 @@ func (repo *O11yQueryRepo) getPublicIpAddress() (valueObject.IpAddress, error) { return valueObject.NewIpAddress(cachedIpAddressStr) } - rawIpEntry, err := infraHelper.RunCmd( - "dig", "+short", "TXT", "o-o.myaddr.l.google.com", "@ns1.google.com", - ) - if err != nil { - rawIpEntry, err = infraHelper.RunCmd( - "dig", "+short", "TXT", "CH", "whoami.cloudflare", "@1.1.1.1", - ) - if err != nil { - return ipAddress, errors.New("GetPublicIpFailed: " + err.Error()) - } - } - - rawIpEntry = strings.Trim(rawIpEntry, `"`) - if rawIpEntry == "" { - return ipAddress, errors.New("GetPublicIpFailed: NoIpEntry") - } - - ipAddress, err = valueObject.NewIpAddress(rawIpEntry) + serverPublicIpAddress, err := infraHelper.ReadServerPublicIpAddress() if err != nil { - return ipAddress, err + return ipAddress, errors.New("ReadServerPublicIpAddressError: " + err.Error()) } err = repo.transientDbSvc.Set( infraData.GlobalConfigs.PublicIpTransientKey, - ipAddress.String(), + serverPublicIpAddress.String(), ) if err != nil { return ipAddress, errors.New("PersistPublicIpFailed: " + err.Error()) } - return ipAddress, nil + return serverPublicIpAddress, nil } func (repo *O11yQueryRepo) isCgroupV2() bool { @@ -390,9 +372,9 @@ func (repo *O11yQueryRepo) GetOverview() (entity.O11yOverview, error) { uptime = 0 } - publicIpAddress, err := repo.getPublicIpAddress() + publicIpAddress, err := repo.ReadServerPublicIpAddress() if err != nil { - log.Printf("GetPublicIpAddressError: %s", err.Error()) + log.Printf("ReadServerPublicIpAddressError: %s", err.Error()) publicIpAddress, _ = valueObject.NewIpAddress("0.0.0.0") } From 49fcd2f2692624bc6571f09a4ef170a909bafa4c Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:12:54 -0300 Subject: [PATCH 09/23] refactor: replace with valid ssl method and auxiliaries --- src/infra/ssl/sslCmdRepo.go | 303 ++++++++++++++---------------------- 1 file changed, 121 insertions(+), 182 deletions(-) diff --git a/src/infra/ssl/sslCmdRepo.go b/src/infra/ssl/sslCmdRepo.go index f3d83fe87..ac204b8da 100644 --- a/src/infra/ssl/sslCmdRepo.go +++ b/src/infra/ssl/sslCmdRepo.go @@ -3,7 +3,6 @@ package sslInfra import ( "errors" "log" - "net" "os" "github.com/speedianet/os/src/domain/dto" @@ -12,20 +11,24 @@ import ( infraHelper "github.com/speedianet/os/src/infra/helper" infraData "github.com/speedianet/os/src/infra/infraData" internalDbInfra "github.com/speedianet/os/src/infra/internalDatabase" + o11yInfra "github.com/speedianet/os/src/infra/o11y" vhostInfra "github.com/speedianet/os/src/infra/vhost" mappingInfra "github.com/speedianet/os/src/infra/vhost/mapping" ) type SslCmdRepo struct { persistentDbSvc *internalDbInfra.PersistentDatabaseService + transientDbSvc *internalDbInfra.TransientDatabaseService sslQueryRepo SslQueryRepo } func NewSslCmdRepo( persistentDbSvc *internalDbInfra.PersistentDatabaseService, + transientDbSvc *internalDbInfra.TransientDatabaseService, ) *SslCmdRepo { return &SslCmdRepo{ persistentDbSvc: persistentDbSvc, + transientDbSvc: transientDbSvc, sslQueryRepo: SslQueryRepo{}, } } @@ -78,7 +81,44 @@ func (repo *SslCmdRepo) ReplaceWithSelfSigned(vhostName valueObject.Fqdn) error ) } +func (repo *SslCmdRepo) dnsFilterFunctionalHostnames( + vhostNames []valueObject.Fqdn, + serverPublicIpAddress valueObject.IpAddress, +) []valueObject.Fqdn { + functionalHostnames := []valueObject.Fqdn{} + + for _, vhostName := range vhostNames { + wwwVhostName, err := valueObject.NewFqdn("www." + vhostName.String()) + if err != nil { + continue + } + + vhostNames = append(vhostNames, wwwVhostName) + } + + serverPublicIpAddressStr := serverPublicIpAddress.String() + for _, vhostName := range vhostNames { + vhostNameStr := vhostName.String() + + hostnameRecords, err := infraHelper.DnsLookup(vhostNameStr, nil) + if err != nil || len(hostnameRecords) == 0 { + continue + } + + for _, record := range hostnameRecords { + if record != serverPublicIpAddressStr { + continue + } + + functionalHostnames = append(functionalHostnames, vhostName) + } + } + + return functionalHostnames +} + func (repo *SslCmdRepo) createOwnershipValidationMapping( + mappingCmdRepo *mappingInfra.MappingCmdRepo, targetVhostName valueObject.Fqdn, expectedOwnershipHash valueObject.Hash, ) (mappingId valueObject.MappingId, err error) { @@ -93,124 +133,32 @@ func (repo *SslCmdRepo) createOwnershipValidationMapping( ) inlineHtmlMapping := dto.NewCreateMapping( - targetVhostName, - path, - matchPattern, - targetType, - &targetValue, - &httpResponseCode, + targetVhostName, path, matchPattern, targetType, &targetValue, &httpResponseCode, ) - mappingCmdRepo := mappingInfra.NewMappingCmdRepo(repo.persistentDbSvc) mappingId, err = mappingCmdRepo.Create(inlineHtmlMapping) if err != nil { - return mappingId, errors.New( - "CreateOwnershipValidationMappingError (" + - targetVhostName.String() + "): " + err.Error(), - ) + return mappingId, err } return mappingId, nil } -func (repo *SslCmdRepo) filterDomainsMappedToSomewhere( - vhostNames []valueObject.Fqdn, -) []valueObject.Fqdn { - domainsMappedToSomewhere := []valueObject.Fqdn{} - for _, vhostName := range vhostNames { - vhostNameStr := vhostName.String() - - googleDnsServerIp := "8.8.8.8" - rawVhostIps, err := infraHelper.RunCmdWithSubShell( - "dig +short " + vhostNameStr + " @" + googleDnsServerIp, - ) - if err != nil || rawVhostIps == "" { - cleanbrowsingSecurityFilterDnsServerIp := "185.228.168.9" - rawVhostIps, err := infraHelper.RunCmdWithSubShell( - "dig +short " + vhostNameStr + " @" + cleanbrowsingSecurityFilterDnsServerIp, - ) - if err != nil || rawVhostIps == "" { - continue - } - } - - domainsMappedToSomewhere = append(domainsMappedToSomewhere, vhostName) - } - - return domainsMappedToSomewhere -} - -func (repo *SslCmdRepo) shouldIncludeWww(vhost valueObject.Fqdn) bool { - rootDomain, err := infraHelper.GetRootDomain(vhost) - if err != nil { - return false - } - - vhostStr := vhost.String() - isSubdomain := rootDomain.String() != vhostStr - if isSubdomain { - return false - } - - wwwDnsEntry := "www." + vhostStr - wwwDnsEntryIps, err := net.LookupIP(wwwDnsEntry) - if err != nil { - return false - } - - wwwDnsEntryExists := len(wwwDnsEntryIps) > 0 - if !wwwDnsEntryExists { - return false - } - - vhostIps, err := net.LookupIP(vhostStr) - if err != nil { - return false - } - - firstVhostIp := vhostIps[0] - for _, wwwDnsEntryIp := range wwwDnsEntryIps { - if !firstVhostIp.Equal(wwwDnsEntryIp) { - continue - } - - return true - } - - return false -} - -func (repo *SslCmdRepo) filterDomainsMappedToServer( +func (repo *SslCmdRepo) httpFilterFunctionalHostnames( vhostNames []valueObject.Fqdn, expectedOwnershipHash valueObject.Hash, + serverPublicIpAddress valueObject.IpAddress, ) []valueObject.Fqdn { - domainsMappedToServer := []valueObject.Fqdn{} + functionalHostnames := []valueObject.Fqdn{} + + serverPublicIpAddressStr := serverPublicIpAddress.String() + expectedHashStr := expectedOwnershipHash.String() + mappingCmdRepo := mappingInfra.NewMappingCmdRepo(repo.persistentDbSvc) for _, vhostName := range vhostNames { vhostNameStr := vhostName.String() - vhostNameIps, err := net.LookupIP(vhostNameStr) - if err != nil || len(vhostNameIps) == 0 { - continue - } - - var serverIpAddress *valueObject.IpAddress - for _, vhostNameIp := range vhostNameIps { - ipAddress, err := valueObject.NewIpAddress(vhostNameIp.String()) - if err != nil { - continue - } - - serverIpAddress = &ipAddress - break - } - - if serverIpAddress == nil { - continue - } - ownershipValidationMappingId, err := repo.createOwnershipValidationMapping( - vhostName, - expectedOwnershipHash, + mappingCmdRepo, vhostName, expectedOwnershipHash, ) if err != nil { continue @@ -218,109 +166,74 @@ func (repo *SslCmdRepo) filterDomainsMappedToServer( hashUrlPath := infraData.GlobalConfigs.DomainOwnershipValidationUrlPath hashUrlFull := "https://" + vhostNameStr + hashUrlPath - serverIpStr := serverIpAddress.String() - - ownershipHashFound, err := infraHelper.RunCmd( - "curl", "-skLm", "10", "--resolve", vhostNameStr+":443:"+serverIpStr, hashUrlFull, + curlBaseCmd := "curl -skLm 10 " + sniFlag := "--resolve " + vhostNameStr + ":443:" + serverPublicIpAddressStr + ownershipHashFound, err := infraHelper.RunCmdWithSubShell( + curlBaseCmd + sniFlag + " " + hashUrlFull, ) if err != nil { - hashUrlFull = "https://" + serverIpStr + hashUrlPath - ownershipHashFound, err = infraHelper.RunCmd( - "curl", "-skLm", "10", "-H", "Host: "+vhostNameStr, hashUrlFull, + hashUrlFull = "https://" + serverPublicIpAddressStr + hashUrlPath + ownershipHashFound, err = infraHelper.RunCmdWithSubShell( + curlBaseCmd + "-H \"Host: " + vhostNameStr + "\" " + hashUrlFull, ) if err != nil { continue } } - if ownershipHashFound != expectedOwnershipHash.String() { + if ownershipHashFound != expectedHashStr { continue } - domainsMappedToServer = append(domainsMappedToServer, vhostName) + functionalHostnames = append(functionalHostnames, vhostName) - if repo.shouldIncludeWww(vhostName) { - vhostNameWithWww, err := valueObject.NewFqdn("www." + vhostNameStr) - if err != nil { - continue - } - - domainsMappedToServer = append(domainsMappedToServer, vhostNameWithWww) - } - - mappingCmdRepo := mappingInfra.NewMappingCmdRepo(repo.persistentDbSvc) err = mappingCmdRepo.Delete(ownershipValidationMappingId) if err != nil { log.Printf("DeleteOwnershipValidationMappingError: %s", err.Error()) } } - return domainsMappedToServer + return functionalHostnames } -func (repo *SslCmdRepo) ReplaceWithValidSsl(sslPair entity.SslPair) error { - validPairVhostNames := repo.filterDomainsMappedToSomewhere( - sslPair.VirtualHostsHostnames, - ) - if len(validPairVhostNames) == 0 { - return errors.New("NoDomainsMappedToSomewhere") - } - - expectedOwnershipHash, err := repo.sslQueryRepo.GetOwnershipValidationHash( - sslPair.Certificate.CertificateContent, - ) - if err != nil { - return errors.New( - "CreateOwnershipValidationHashError: " + err.Error(), - ) - } - pairVhostNamesMappedToServer := repo.filterDomainsMappedToServer( - validPairVhostNames, expectedOwnershipHash, - ) - if len(pairVhostNamesMappedToServer) == 0 { - return errors.New("NoDomainsMappedToServer") +func (repo *SslCmdRepo) issueValidSsl( + mainHostname valueObject.Fqdn, + functionalHostnames []valueObject.Fqdn, +) error { + mainPairHostnameStr := mainHostname.String() + vhostRootDir := infraData.GlobalConfigs.PrimaryPublicDir + if !infraHelper.IsPrimaryVirtualHost(mainHostname) { + vhostRootDir += "/" + mainPairHostnameStr } - firstVhostName := pairVhostNamesMappedToServer[0] - firstVhostNameStr := firstVhostName.String() - vhostRootDir := infraData.GlobalConfigs.PrimaryPublicDir - if !infraHelper.IsPrimaryVirtualHost(firstVhostName) { - vhostRootDir += "/" + firstVhostNameStr + if !infraHelper.FileExists(vhostRootDir) { + return errors.New("VirtualHostRootDirNotFound") } certbotCmd := "certbot certonly --webroot --webroot-path " + vhostRootDir + - " --agree-tos --register-unsafely-without-email --cert-name " + firstVhostNameStr - - for _, pairVhostName := range pairVhostNamesMappedToServer { - certbotCmd += " -d " + pairVhostName.String() + " --agree-tos --register-unsafely-without-email --cert-name " + mainPairHostnameStr + for _, functionalHostname := range functionalHostnames { + certbotCmd += " -d " + functionalHostname.String() } - _, err = infraHelper.RunCmdWithSubShell(certbotCmd) + _, err := infraHelper.RunCmdWithSubShell(certbotCmd) if err != nil { - return errors.New("CreateValidSslError: " + err.Error()) + return errors.New("GenerateValidSslCertError: " + err.Error()) } certbotDirPath := "/etc/letsencrypt/live" shouldOverwrite := true - certbotCrtFilePath := certbotDirPath + "/" + firstVhostNameStr + "/fullchain.pem" - vhostCrtFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + firstVhostNameStr + ".crt" - err = infraHelper.CreateSymlink( - certbotCrtFilePath, - vhostCrtFilePath, - shouldOverwrite, - ) + certbotCrtFilePath := certbotDirPath + "/" + mainPairHostnameStr + "/fullchain.pem" + vhostCrtFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + mainPairHostnameStr + ".crt" + err = infraHelper.CreateSymlink(certbotCrtFilePath, vhostCrtFilePath, shouldOverwrite) if err != nil { - return errors.New("CreateSslCrtSymlinkError: " + err.Error()) + return errors.New("CreateSslCertSymlinkError: " + err.Error()) } - certbotKeyFilePath := certbotDirPath + "/" + firstVhostNameStr + "/privkey.pem" - vhostKeyFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + firstVhostNameStr + ".key" - err = infraHelper.CreateSymlink( - certbotKeyFilePath, - vhostKeyFilePath, - shouldOverwrite, - ) + certbotKeyFilePath := certbotDirPath + "/" + mainPairHostnameStr + "/privkey.pem" + vhostKeyFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + mainPairHostnameStr + ".key" + err = infraHelper.CreateSymlink(certbotKeyFilePath, vhostKeyFilePath, shouldOverwrite) if err != nil { return errors.New("CreateSslKeySymlinkError: " + err.Error()) } @@ -328,6 +241,40 @@ func (repo *SslCmdRepo) ReplaceWithValidSsl(sslPair entity.SslPair) error { return nil } +func (repo *SslCmdRepo) ReplaceWithValidSsl(sslPair entity.SslPair) error { + o11yQueryRepo := o11yInfra.NewO11yQueryRepo(repo.transientDbSvc) + serverPublicIpAddress, err := o11yQueryRepo.ReadServerPublicIpAddress() + if err != nil { + return err + } + + dnsFunctionalHostnames := repo.dnsFilterFunctionalHostnames( + sslPair.VirtualHostsHostnames, serverPublicIpAddress, + ) + if len(dnsFunctionalHostnames) == 0 { + return errors.New("NoDnsFunctionalHostnames") + } + + expectedOwnershipHash, err := repo.sslQueryRepo.GetOwnershipValidationHash( + sslPair.Certificate.CertificateContent, + ) + if err != nil { + return errors.New( + "CreateOwnershipValidationHashError: " + err.Error(), + ) + } + httpFunctionalHostnames := repo.httpFilterFunctionalHostnames( + dnsFunctionalHostnames, expectedOwnershipHash, serverPublicIpAddress, + ) + if len(httpFunctionalHostnames) == 0 { + return errors.New("NoHttpFunctionalHostnames") + } + + return repo.issueValidSsl( + sslPair.VirtualHostsHostnames[0], httpFunctionalHostnames, + ) +} + func (repo *SslCmdRepo) Create(createSslPair dto.CreateSslPair) error { if len(createSslPair.VirtualHostsHostnames) == 0 { return errors.New("EmptyVirtualHosts") @@ -346,9 +293,7 @@ func (repo *SslCmdRepo) Create(createSslPair dto.CreateSslPair) error { if shouldBeSymlink { shouldOverwrite := true err := infraHelper.CreateSymlink( - firstVhostCertFilePath, - vhostCertFilePath, - shouldOverwrite, + firstVhostCertFilePath, vhostCertFilePath, shouldOverwrite, ) if err != nil { log.Printf( @@ -358,9 +303,7 @@ func (repo *SslCmdRepo) Create(createSslPair dto.CreateSslPair) error { } err = infraHelper.CreateSymlink( - firstVhostCertKeyFilePath, - vhostCertKeyFilePath, - shouldOverwrite, + firstVhostCertKeyFilePath, vhostCertKeyFilePath, shouldOverwrite, ) if err != nil { log.Printf( @@ -383,9 +326,7 @@ func (repo *SslCmdRepo) Create(createSslPair dto.CreateSslPair) error { } err = infraHelper.UpdateFile( - vhostCertKeyFilePath, - createSslPair.Key.String(), - shouldOverwrite, + vhostCertKeyFilePath, createSslPair.Key.String(), shouldOverwrite, ) if err != nil { return err @@ -425,9 +366,7 @@ func (repo *SslCmdRepo) DeleteSslPairVhosts( err = repo.ReplaceWithSelfSigned(vhostName) if err != nil { log.Printf( - "DeleteSslPairVhostsError (%s): %s", - vhostName.String(), - err.Error(), + "DeleteSslPairVhostsError (%s): %s", vhostName.String(), err.Error(), ) } } From 2f697780942415a9c1eaf8d0c54cf2600ce00963 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:13:10 -0300 Subject: [PATCH 10/23] fix: inject transient to ssl cmd repo infra --- .../api/controller/sslController.go | 19 +++++++++++++++---- src/presentation/api/router.go | 2 +- .../cli/controller/sslController.go | 19 ++++++++++++++----- src/presentation/cli/router.go | 2 +- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/presentation/api/controller/sslController.go b/src/presentation/api/controller/sslController.go index 5659474ea..29ee55064 100644 --- a/src/presentation/api/controller/sslController.go +++ b/src/presentation/api/controller/sslController.go @@ -17,13 +17,16 @@ import ( type SslController struct { persistentDbSvc *internalDbInfra.PersistentDatabaseService + transientDbSvc *internalDbInfra.TransientDatabaseService } func NewSslController( persistentDbSvc *internalDbInfra.PersistentDatabaseService, + transientDbSvc *internalDbInfra.TransientDatabaseService, ) *SslController { return &SslController{ persistentDbSvc: persistentDbSvc, + transientDbSvc: transientDbSvc, } } @@ -105,7 +108,9 @@ func (controller *SslController) Create(c echo.Context) error { sslPrivateKey, ) - sslCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + sslCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) vhostQueryRepo := vhostInfra.NewVirtualHostQueryRepo(controller.persistentDbSvc) err := useCase.CreateSslPair( @@ -134,7 +139,9 @@ func (controller *SslController) Delete(c echo.Context) error { sslSerialNumber := valueObject.NewSslIdPanic(c.Param("sslPairId")) sslQueryRepo := sslInfra.SslQueryRepo{} - sslCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + sslCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) err := useCase.DeleteSslPair( sslQueryRepo, @@ -156,7 +163,9 @@ func (controller *SslController) SslCertificateWatchdog() { defer timer.Stop() sslQueryRepo := sslInfra.SslQueryRepo{} - sslCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + sslCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) vhostQueryRepo := vhostInfra.NewVirtualHostQueryRepo(controller.persistentDbSvc) vhostCmdRepo := vhostInfra.NewVirtualHostCmdRepo(controller.persistentDbSvc) @@ -193,7 +202,9 @@ func (controller *SslController) DeleteVhosts(c echo.Context) error { dto := dto.NewDeleteSslPairVhosts(sslPairId, virtualHosts) sslQueryRepo := sslInfra.SslQueryRepo{} - sslCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + sslCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) err := useCase.DeleteSslPairVhosts( sslQueryRepo, diff --git a/src/presentation/api/router.go b/src/presentation/api/router.go index 2d95c38cd..6c7542887 100644 --- a/src/presentation/api/router.go +++ b/src/presentation/api/router.go @@ -137,7 +137,7 @@ func (router Router) servicesRoutes() { func (router Router) sslRoutes() { sslGroup := router.baseRoute.Group("/v1/ssl") sslController := apiController.NewSslController( - router.persistentDbSvc, + router.persistentDbSvc, router.transientDbSvc, ) sslGroup.GET("/", sslController.Read) diff --git a/src/presentation/cli/controller/sslController.go b/src/presentation/cli/controller/sslController.go index c44ee9dc9..f6160689c 100644 --- a/src/presentation/cli/controller/sslController.go +++ b/src/presentation/cli/controller/sslController.go @@ -15,13 +15,16 @@ import ( type SslController struct { persistentDbSvc *internalDbInfra.PersistentDatabaseService + transientDbSvc *internalDbInfra.TransientDatabaseService } func NewSslController( persistentDbSvc *internalDbInfra.PersistentDatabaseService, + transientDbSvc *internalDbInfra.TransientDatabaseService, ) *SslController { return &SslController{ persistentDbSvc: persistentDbSvc, + transientDbSvc: transientDbSvc, } } @@ -62,13 +65,13 @@ func (controller *SslController) Create() *cobra.Command { certificateFilePath.String(), ) if err != nil { - cliHelper.ResponseWrapper(false, "FailedToOpenSslCertificateFile") + cliHelper.ResponseWrapper(false, "OpenSslCertificateFileError") } sslCertificateContent := valueObject.NewSslCertificateContentPanic(certificateContentStr) privateKeyContentStr, err := infraHelper.GetFileContent(keyFilePathStr) if err != nil { - cliHelper.ResponseWrapper(false, "FailedToOpenPrivateKeyFile") + cliHelper.ResponseWrapper(false, "OpenPrivateKeyFileError") } sslCertificate := entity.NewSslCertificatePanic(sslCertificateContent) @@ -80,7 +83,9 @@ func (controller *SslController) Create() *cobra.Command { sslPrivateKey, ) - sslCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + sslCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) vhostQueryRepo := vhostInfra.NewVirtualHostQueryRepo(controller.persistentDbSvc) err = useCase.CreateSslPair( @@ -115,7 +120,9 @@ func (controller *SslController) Delete() *cobra.Command { sslId := valueObject.NewSslIdPanic(sslPairIdStr) cronQueryRepo := sslInfra.SslQueryRepo{} - cronCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + cronCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) err := useCase.DeleteSslPair( cronQueryRepo, @@ -153,7 +160,9 @@ func (controller *SslController) DeleteVhosts() *cobra.Command { dto := dto.NewDeleteSslPairVhosts(sslPairId, virtualHosts) sslQueryRepo := sslInfra.SslQueryRepo{} - sslCmdRepo := sslInfra.NewSslCmdRepo(controller.persistentDbSvc) + sslCmdRepo := sslInfra.NewSslCmdRepo( + controller.persistentDbSvc, controller.transientDbSvc, + ) err := useCase.DeleteSslPairVhosts( sslQueryRepo, diff --git a/src/presentation/cli/router.go b/src/presentation/cli/router.go index fbd75ca2b..31e03c10e 100644 --- a/src/presentation/cli/router.go +++ b/src/presentation/cli/router.go @@ -173,7 +173,7 @@ func (router Router) sslRoutes() { rootCmd.AddCommand(sslCmd) sslController := cliController.NewSslController( - router.persistentDbSvc, + router.persistentDbSvc, router.transientDbSvc, ) sslCmd.AddCommand(sslController.Read()) sslCmd.AddCommand(sslController.Create()) From 4dda90b46600b91eafb3d967de61ca8751c80edc Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:23:10 -0300 Subject: [PATCH 11/23] fix: minor variables renaming --- src/infra/ssl/sslCmdRepo.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/infra/ssl/sslCmdRepo.go b/src/infra/ssl/sslCmdRepo.go index ac204b8da..e6ab3eaba 100644 --- a/src/infra/ssl/sslCmdRepo.go +++ b/src/infra/ssl/sslCmdRepo.go @@ -111,6 +111,7 @@ func (repo *SslCmdRepo) dnsFilterFunctionalHostnames( } functionalHostnames = append(functionalHostnames, vhostName) + break } } @@ -200,10 +201,10 @@ func (repo *SslCmdRepo) issueValidSsl( mainHostname valueObject.Fqdn, functionalHostnames []valueObject.Fqdn, ) error { - mainPairHostnameStr := mainHostname.String() + mainHostnameStr := mainHostname.String() vhostRootDir := infraData.GlobalConfigs.PrimaryPublicDir if !infraHelper.IsPrimaryVirtualHost(mainHostname) { - vhostRootDir += "/" + mainPairHostnameStr + vhostRootDir += "/" + mainHostnameStr } if !infraHelper.FileExists(vhostRootDir) { @@ -211,7 +212,7 @@ func (repo *SslCmdRepo) issueValidSsl( } certbotCmd := "certbot certonly --webroot --webroot-path " + vhostRootDir + - " --agree-tos --register-unsafely-without-email --cert-name " + mainPairHostnameStr + " --agree-tos --register-unsafely-without-email --cert-name " + mainHostnameStr for _, functionalHostname := range functionalHostnames { certbotCmd += " -d " + functionalHostname.String() } @@ -224,15 +225,15 @@ func (repo *SslCmdRepo) issueValidSsl( certbotDirPath := "/etc/letsencrypt/live" shouldOverwrite := true - certbotCrtFilePath := certbotDirPath + "/" + mainPairHostnameStr + "/fullchain.pem" - vhostCrtFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + mainPairHostnameStr + ".crt" + certbotCrtFilePath := certbotDirPath + "/" + mainHostnameStr + "/fullchain.pem" + vhostCrtFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + mainHostnameStr + ".crt" err = infraHelper.CreateSymlink(certbotCrtFilePath, vhostCrtFilePath, shouldOverwrite) if err != nil { return errors.New("CreateSslCertSymlinkError: " + err.Error()) } - certbotKeyFilePath := certbotDirPath + "/" + mainPairHostnameStr + "/privkey.pem" - vhostKeyFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + mainPairHostnameStr + ".key" + certbotKeyFilePath := certbotDirPath + "/" + mainHostnameStr + "/privkey.pem" + vhostKeyFilePath := infraData.GlobalConfigs.PkiConfDir + "/" + mainHostnameStr + ".key" err = infraHelper.CreateSymlink(certbotKeyFilePath, vhostKeyFilePath, shouldOverwrite) if err != nil { return errors.New("CreateSslKeySymlinkError: " + err.Error()) From 74be66728332b6eaceabf8a4fca2fc28e1c4ad9d Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:23:29 -0300 Subject: [PATCH 12/23] fix: remove struct from ssl watchdog --- src/domain/useCase/sslCertificateWatchdog.go | 32 +++++-------------- .../api/controller/sslController.go | 10 +----- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/domain/useCase/sslCertificateWatchdog.go b/src/domain/useCase/sslCertificateWatchdog.go index 73f9746d4..fdee0613a 100644 --- a/src/domain/useCase/sslCertificateWatchdog.go +++ b/src/domain/useCase/sslCertificateWatchdog.go @@ -8,29 +8,11 @@ import ( const SslValidationsPerHour int = 4 -type SslCertificateWatchdog struct { - sslQueryRepo repository.SslQueryRepo - sslCmdRepo repository.SslCmdRepo - vhostQueryRepo repository.VirtualHostQueryRepo - vhostCmdRepo repository.VirtualHostCmdRepo -} - -func NewSslCertificateWatchdog( +func SslCertificateWatchdog( sslQueryRepo repository.SslQueryRepo, sslCmdRepo repository.SslCmdRepo, - vhostQueryRepo repository.VirtualHostQueryRepo, - vhostCmdRepo repository.VirtualHostCmdRepo, -) SslCertificateWatchdog { - return SslCertificateWatchdog{ - sslQueryRepo: sslQueryRepo, - sslCmdRepo: sslCmdRepo, - vhostQueryRepo: vhostQueryRepo, - vhostCmdRepo: vhostCmdRepo, - } -} - -func (uc SslCertificateWatchdog) Execute() { - sslPairs, err := uc.sslQueryRepo.Read() +) { + sslPairs, err := sslQueryRepo.Read() if err != nil { log.Printf("ReadSslPairsError: %s", err.Error()) return @@ -41,10 +23,12 @@ func (uc SslCertificateWatchdog) Execute() { continue } - err = uc.sslCmdRepo.ReplaceWithValidSsl(sslPair) + err = sslCmdRepo.ReplaceWithValidSsl(sslPair) if err != nil { - firstVhostName := sslPair.VirtualHostsHostnames[0] - log.Printf("ReplaceWithValidSslError (%s): %s", firstVhostName.String(), err.Error()) + mainSslPairHostname := sslPair.VirtualHostsHostnames[0] + log.Printf( + "ReplaceWithValidSslError (%s): %s", mainSslPairHostname.String(), err.Error(), + ) } } } diff --git a/src/presentation/api/controller/sslController.go b/src/presentation/api/controller/sslController.go index 29ee55064..9bbcd6528 100644 --- a/src/presentation/api/controller/sslController.go +++ b/src/presentation/api/controller/sslController.go @@ -166,17 +166,9 @@ func (controller *SslController) SslCertificateWatchdog() { sslCmdRepo := sslInfra.NewSslCmdRepo( controller.persistentDbSvc, controller.transientDbSvc, ) - vhostQueryRepo := vhostInfra.NewVirtualHostQueryRepo(controller.persistentDbSvc) - vhostCmdRepo := vhostInfra.NewVirtualHostCmdRepo(controller.persistentDbSvc) for range timer.C { - sslCertificateWatchdog := useCase.NewSslCertificateWatchdog( - sslQueryRepo, - sslCmdRepo, - vhostQueryRepo, - vhostCmdRepo, - ) - sslCertificateWatchdog.Execute() + useCase.SslCertificateWatchdog(sslQueryRepo, sslCmdRepo) } } From 62bf9d7d66df5e5cc93a48c6598318975917cb97 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:28:44 -0300 Subject: [PATCH 13/23] fix: use raw for unparsed strings --- src/infra/marketplace/marketplaceCmdRepo.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/infra/marketplace/marketplaceCmdRepo.go b/src/infra/marketplace/marketplaceCmdRepo.go index c0c4f356c..3c7b93e68 100644 --- a/src/infra/marketplace/marketplaceCmdRepo.go +++ b/src/infra/marketplace/marketplaceCmdRepo.go @@ -487,14 +487,20 @@ func (repo *MarketplaceCmdRepo) uninstallSymlinkFilesDelete( return errors.New("TemporarilyMoveUnfamiliarFilesError: " + err.Error()) } - installedItemRealRootDirPath := fmt.Sprintf( + rawInstalledItemRealRootDirPath := fmt.Sprintf( "/app/%s-%s-%s", installedItem.Slug.String(), itemHostnameStr, installedItem.InstallUuid.String(), ) + installedItemRealRootDirPath, err := valueObject.NewUnixFilePath(rawInstalledItemRealRootDirPath) + if err != nil { + return err + } + installedItemRealRootDirPathStr := installedItemRealRootDirPath.String() + _, err = infraHelper.RunCmdWithSubShell( - "mv " + installedItemRealRootDirPath + "/* " + softDeleteDestDirPath.String(), + "mv " + installedItemRealRootDirPathStr + "/* " + softDeleteDestDirPath.String(), ) if err != nil { return errors.New("SoftDeleteItemFilesError: " + err.Error()) @@ -506,7 +512,7 @@ func (repo *MarketplaceCmdRepo) uninstallSymlinkFilesDelete( } _, err = infraHelper.RunCmdWithSubShell( - "rm -rf " + installedItemRealRootDirPath, + "rm -rf " + installedItemRealRootDirPathStr, ) if err != nil { return errors.New("DeleteItemRealRootPathError: " + err.Error()) @@ -550,19 +556,19 @@ func (repo *MarketplaceCmdRepo) uninstallFilesDelete( return nil } - softDeleteDestDirPathStr := fmt.Sprintf( + rawSoftDeleteDestDirPath := fmt.Sprintf( "%s/%s-%s-%s", useCase.TrashDirPath, installedItem.Slug.String(), installedItem.Hostname.String(), installedItem.InstallUuid.String(), ) - softDeleteDestDirPath, err := valueObject.NewUnixFilePath(softDeleteDestDirPathStr) + softDeleteDestDirPath, err := valueObject.NewUnixFilePath(rawSoftDeleteDestDirPath) if err != nil { return err } - err = infraHelper.MakeDir(softDeleteDestDirPathStr) + err = infraHelper.MakeDir(softDeleteDestDirPath.String()) if err != nil { return errors.New("CreateSoftDeleteDirError: " + err.Error()) } From 8eb4c6a8e0888ace8004551e29adee5b4704175f Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 19:45:51 -0300 Subject: [PATCH 14/23] fix: add ws suffix to restart --- src/infra/runtime/runtimeCmdRepo.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/infra/runtime/runtimeCmdRepo.go b/src/infra/runtime/runtimeCmdRepo.go index 3880d9093..03efe9300 100644 --- a/src/infra/runtime/runtimeCmdRepo.go +++ b/src/infra/runtime/runtimeCmdRepo.go @@ -21,7 +21,7 @@ func NewRuntimeCmdRepo() *RuntimeCmdRepo { return &RuntimeCmdRepo{runtimeQueryRepo: RuntimeQueryRepo{}} } -func (repo *RuntimeCmdRepo) restartPhp() error { +func (repo *RuntimeCmdRepo) restartPhpWebserver() error { phpSvcName, _ := valueObject.NewServiceName("php-webserver") servicesCmdRepo := servicesInfra.ServicesCmdRepo{} err := servicesCmdRepo.Restart(phpSvcName) @@ -58,7 +58,7 @@ func (repo *RuntimeCmdRepo) UpdatePhpVersion( return errors.New("UpdatePhpVersionFailed: " + err.Error()) } - return repo.restartPhp() + return repo.restartPhpWebserver() } func (repo *RuntimeCmdRepo) UpdatePhpSettings( @@ -86,7 +86,7 @@ func (repo *RuntimeCmdRepo) UpdatePhpSettings( } } - return repo.restartPhp() + return repo.restartPhpWebserver() } func (repo *RuntimeCmdRepo) EnablePhpModule( @@ -240,7 +240,7 @@ func (repo *RuntimeCmdRepo) UpdatePhpModules( } } - return repo.restartPhp() + return repo.restartPhpWebserver() } func (repo *RuntimeCmdRepo) CreatePhpVirtualHost(hostname valueObject.Fqdn) error { From 9e0e61e95f1a71cbae60e8c9b21a4bf84b975cf9 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 20:27:28 -0300 Subject: [PATCH 15/23] fix: improve non functional error msgs --- src/infra/ssl/sslCmdRepo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/infra/ssl/sslCmdRepo.go b/src/infra/ssl/sslCmdRepo.go index e6ab3eaba..891b51f15 100644 --- a/src/infra/ssl/sslCmdRepo.go +++ b/src/infra/ssl/sslCmdRepo.go @@ -253,7 +253,7 @@ func (repo *SslCmdRepo) ReplaceWithValidSsl(sslPair entity.SslPair) error { sslPair.VirtualHostsHostnames, serverPublicIpAddress, ) if len(dnsFunctionalHostnames) == 0 { - return errors.New("NoDnsFunctionalHostnames") + return errors.New("NoSslHostnamePointingToServerIpAddress") } expectedOwnershipHash, err := repo.sslQueryRepo.GetOwnershipValidationHash( @@ -268,7 +268,7 @@ func (repo *SslCmdRepo) ReplaceWithValidSsl(sslPair entity.SslPair) error { dnsFunctionalHostnames, expectedOwnershipHash, serverPublicIpAddress, ) if len(httpFunctionalHostnames) == 0 { - return errors.New("NoHttpFunctionalHostnames") + return errors.New("NoSslHostnamePassingHttpOwnershipValidation") } return repo.issueValidSsl( From fad1419e37ed77de57035525148b55beca344524 Mon Sep 17 00:00:00 2001 From: ntorga Date: Wed, 3 Jul 2024 20:31:56 -0300 Subject: [PATCH 16/23] feat: use cron to auto reload after .htaccess change --- src/infra/services/createInstallable.go | 32 ++++++++++++++--- src/infra/services/uninstall.go | 48 +++++++++++++++++++------ 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/infra/services/createInstallable.go b/src/infra/services/createInstallable.go index f1f3c9aaf..c5e0a5fec 100644 --- a/src/infra/services/createInstallable.go +++ b/src/infra/services/createInstallable.go @@ -12,6 +12,7 @@ import ( "github.com/speedianet/os/src/domain/dto" "github.com/speedianet/os/src/domain/valueObject" + cronInfra "github.com/speedianet/os/src/infra/cron" infraHelper "github.com/speedianet/os/src/infra/helper" "github.com/speedianet/os/src/infra/infraData" ) @@ -27,6 +28,8 @@ var OlsPackages = []string{ "openlitespeed", } +const PhpWebserverAutoReloadCronComment string = "AutoReloadPhpWebServerAfterHtaccessChange" + var PhpPackages = []string{ "lsphp74", "lsphp74-common", @@ -122,7 +125,7 @@ func installGpgKey(serviceName string, url string) error { return nil } -func addPhp() error { +func installPhpWebserver() error { repoFilePath := "/speedia/repo.litespeed.sh" err := infraHelper.DownloadFile("https://repo.litespeed.sh", repoFilePath) if err != nil { @@ -249,6 +252,27 @@ func addPhp() error { return errors.New("CreateSupervisorConfError: " + err.Error()) } + // @see https://openlitespeed.org/kb/reload-openlitespeed-automatically-with-directadmin/ + findFreshHtaccessCmd := "find " + infraData.GlobalConfigs.PrimaryPublicDir + + " -maxdepth 7 -type f -name '.htaccess' -newer /usr/local/lsws/cgid -exec false {} +" + autoReloadWebserverCmd := "if ! " + findFreshHtaccessCmd + "; then " + + "/speedia/os services update -n php-webserver -s restart; fi" + + cronCmdRepo, err := cronInfra.NewCronCmdRepo() + if err != nil { + return errors.New("CreateCronCmdRepoError: " + err.Error()) + } + + cronCmd, _ := valueObject.NewUnixCommand(autoReloadWebserverCmd) + cronSchedule, _ := valueObject.NewCronSchedule("*/2 * * * *") + cronComment, _ := valueObject.NewCronComment(PhpWebserverAutoReloadCronComment) + createCronDto := dto.NewCreateCron(cronSchedule, cronCmd, &cronComment) + + err = cronCmdRepo.Create(createCronDto) + if err != nil { + return errors.New("CreateAutoReloadCronError: " + err.Error()) + } + return nil } @@ -458,7 +482,7 @@ func addMariaDb(createDto dto.CreateInstallableService) error { return nil } -func addPostgresqlDb(createDto dto.CreateInstallableService) error { +func installPostgreSql(createDto dto.CreateInstallableService) error { versionStr := "16" if createDto.Version != nil { versionStr = createDto.Version.String() @@ -748,13 +772,13 @@ func CreateInstallable( switch svcNameStr { case "php-webserver", "php": - return addPhp() + return installPhpWebserver() case "node": return addNode(createDto) case "mariadb": return addMariaDb(createDto) case "postgresql": - return addPostgresqlDb(createDto) + return installPostgreSql(createDto) case "redis": return addRedis(createDto) default: diff --git a/src/infra/services/uninstall.go b/src/infra/services/uninstall.go index 71ebee2e3..515bc2e48 100644 --- a/src/infra/services/uninstall.go +++ b/src/infra/services/uninstall.go @@ -1,9 +1,11 @@ package servicesInfra import ( + "errors" "os" "github.com/speedianet/os/src/domain/valueObject" + cronInfra "github.com/speedianet/os/src/infra/cron" infraHelper "github.com/speedianet/os/src/infra/helper" ) @@ -17,7 +19,34 @@ func purgePkgs(packages []string) error { return nil } -func removeMariaDb() error { +func uninstallPhpWebserver() error { + cronQueryRepo := cronInfra.CronQueryRepo{} + crons, err := cronQueryRepo.Get() + if err != nil { + return errors.New("ReadCronsError") + } + + cronCmdRepo, err := cronInfra.NewCronCmdRepo() + if err != nil { + return errors.New("CreateCronCmdRepoError: " + err.Error()) + } + + for _, cron := range crons { + if cron.Comment.String() != PhpWebserverAutoReloadCronComment { + continue + } + + err = cronCmdRepo.Delete(cron.Id) + if err != nil { + return errors.New("DeleteAutoReloadCronError") + } + } + + packages := append(OlsPackages, "lsphp*") + return purgePkgs(packages) +} + +func uninstallMariaDb() error { pathsToRemove := []string{ "/etc/mysql", "/var/lib/mysql", @@ -36,7 +65,7 @@ func removeMariaDb() error { return purgePkgs(MariaDbPackages) } -func removeRedis() error { +func uninstallRedis() error { pathsToRemove := []string{ "/etc/redis", "/var/lib/redis", @@ -54,7 +83,7 @@ func removeRedis() error { return purgePkgs(RedisPackages) } -func removePostgres() error { +func uninstallPostgreSql() error { pathsToRemove := []string{ "/etc/postgresql", "/var/lib/postgresql", @@ -81,15 +110,14 @@ func Uninstall(name valueObject.ServiceName) error { } switch name.String() { - case "php", "php-webserver": - packages := append(OlsPackages, "lsphp*") - return purgePkgs(packages) + case "php-webserver", "php": + return uninstallPhpWebserver() case "mariadb": - return removeMariaDb() + return uninstallMariaDb() case "redis": - return removeRedis() - case "postgresql": - return removePostgres() + return uninstallRedis() + case "postgresql", "postgres": + return uninstallPostgreSql() default: return nil } From a0fb9e440d2e1727803fb51d0cfaaa022c63e434 Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:52:04 -0300 Subject: [PATCH 17/23] fix: set primary vhost var if identifiable --- src/presentation/shared/middleware/checkEnvs.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/presentation/shared/middleware/checkEnvs.go b/src/presentation/shared/middleware/checkEnvs.go index c78534690..38f253eb4 100644 --- a/src/presentation/shared/middleware/checkEnvs.go +++ b/src/presentation/shared/middleware/checkEnvs.go @@ -35,6 +35,11 @@ func genSecret() (string, error) { } func CheckEnvs() { + primaryHostname, err := infraHelper.GetPrimaryVirtualHost() + if err != nil { + log.Fatalf("PrimaryHostnameUnidentifiable") + } + envFilePath := "/speedia/.env" envFile, err := os.OpenFile(envFilePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0400) @@ -54,6 +59,12 @@ func CheckEnvs() { continue } + if key == "PRIMARY_VHOST" { + value = primaryHostname.String() + os.Setenv(key, value) + continue + } + if !slices.Contains(envVarsToGenerateIfEmpty, key) { log.Fatalf("MissingEnvVar: %s", key) } @@ -70,9 +81,4 @@ func CheckEnvs() { os.Setenv(key, value) } - - _, err = infraHelper.GetPrimaryVirtualHost() - if err != nil { - log.Fatalf("PrimaryVirtualHostNotFound") - } } From 90c463dde5c7de64eea6bad113abb7675e3c0338 Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:52:17 -0300 Subject: [PATCH 18/23] fix: touch crontab file for root --- Containerfile | 1 - Containerfile.test | 1 - 2 files changed, 2 deletions(-) diff --git a/Containerfile b/Containerfile index dfdf24944..ce01e5cfd 100644 --- a/Containerfile +++ b/Containerfile @@ -7,7 +7,6 @@ RUN apt-get update && apt-get upgrade -y \ && curl -skL "https://nginx.org/keys/nginx_signing.key" | gpg --dearmor > "/usr/share/keyrings/nginx-archive-keyring.gpg" \ && echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(lsb_release -cs) nginx" > "/etc/apt/sources.list.d/nginx.list" \ && install_packages nginx cron \ - && touch /var/spool/cron/crontabs/root \ && mkdir -p /app/logs/nginx /app/conf/pki /app/html \ && chown -R nobody:nogroup /app diff --git a/Containerfile.test b/Containerfile.test index 546d3bddb..e5069876a 100644 --- a/Containerfile.test +++ b/Containerfile.test @@ -7,7 +7,6 @@ RUN apt-get update && apt-get upgrade -y \ && curl -skL "https://nginx.org/keys/nginx_signing.key" | gpg --dearmor > "/usr/share/keyrings/nginx-archive-keyring.gpg" \ && echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/debian $(lsb_release -cs) nginx" > "/etc/apt/sources.list.d/nginx.list" \ && install_packages nginx cron \ - && touch /var/spool/cron/crontabs/root \ && mkdir -p /app/logs/nginx /app/conf/pki /app/html \ && chown -R nobody:nogroup /app From d395b7047c66f290e0a353e2700627a570d4b802 Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:52:29 -0300 Subject: [PATCH 19/23] fix: remove new line from String() --- src/domain/entity/cron.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/domain/entity/cron.go b/src/domain/entity/cron.go index 575afdaba..7953f5b71 100644 --- a/src/domain/entity/cron.go +++ b/src/domain/entity/cron.go @@ -25,9 +25,8 @@ func NewCron( func (cron Cron) String() string { cronLineStr := cron.Schedule.String() + " " + cron.Command.String() - if cron.Comment != nil { - cronLineStr += " # " + cron.Comment.String() + "\n" + cronLineStr += " # " + cron.Comment.String() } return cronLineStr From 2c9c9673477b4165c11c8a34beb6331f1b60d25f Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:52:43 -0300 Subject: [PATCH 20/23] fix: ignore no crontab error --- src/infra/cron/cronQueryRepo.go | 35 ++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/infra/cron/cronQueryRepo.go b/src/infra/cron/cronQueryRepo.go index 849bb8430..5c12e5b10 100644 --- a/src/infra/cron/cronQueryRepo.go +++ b/src/infra/cron/cronQueryRepo.go @@ -13,7 +13,7 @@ import ( type CronQueryRepo struct { } -func (repo CronQueryRepo) cronFactory( +func (repo *CronQueryRepo) cronFactory( cronIndex int, cronLine string, ) (entity.Cron, error) { @@ -61,18 +61,22 @@ func (repo CronQueryRepo) cronFactory( return entity.NewCron(id, schedule, cmd, cronCommentPtr), nil } -func (repo CronQueryRepo) Get() ([]entity.Cron, error) { +func (repo *CronQueryRepo) Get() ([]entity.Cron, error) { + crons := []entity.Cron{} + cronOut, err := infraHelper.RunCmd("crontab", "-l") if err != nil { - return []entity.Cron{}, errors.New("CrontabReadError") + if strings.Contains(err.Error(), "no crontab") { + return crons, nil + } + return crons, errors.New("CrontabReadError: " + err.Error()) } cronLines := strings.Split(cronOut, "\n") if len(cronLines) == 0 { - return []entity.Cron{}, nil + return crons, nil } - crons := []entity.Cron{} for cronIndex, cronLine := range cronLines { if cronLine == "" { continue @@ -92,23 +96,26 @@ func (repo CronQueryRepo) Get() ([]entity.Cron, error) { return crons, nil } -func (repo CronQueryRepo) GetById(cronId valueObject.CronId) (entity.Cron, error) { - cronjobs, err := repo.Get() +func (repo *CronQueryRepo) GetById( + cronId valueObject.CronId, +) (cronEntity entity.Cron, err error) { + crons, err := repo.Get() if err != nil { - return entity.Cron{}, err + return cronEntity, err } - if len(cronjobs) < 1 { - return entity.Cron{}, errors.New("CronNotFound") + if len(crons) == 0 { + return cronEntity, errors.New("CronNotFound") } - for _, cronjob := range cronjobs { - if cronjob.Id.String() != cronId.String() { + cronIdStr := cronId.String() + for _, cron := range crons { + if cron.Id.String() != cronIdStr { continue } - return cronjob, nil + return cron, nil } - return entity.Cron{}, errors.New("CronNotFound") + return cronEntity, errors.New("CronNotFound") } From c8880225a710c30b24110897141efe79da5af495 Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:53:05 -0300 Subject: [PATCH 21/23] feat: add new line on install and delete by comment --- src/infra/cron/cronCmdRepo.go | 59 ++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/infra/cron/cronCmdRepo.go b/src/infra/cron/cronCmdRepo.go index 13146c93a..d13dc9eac 100644 --- a/src/infra/cron/cronCmdRepo.go +++ b/src/infra/cron/cronCmdRepo.go @@ -31,7 +31,7 @@ func NewCronCmdRepo() (*CronCmdRepo, error) { }, nil } -func (repo CronCmdRepo) createCrontabTmpFile() error { +func (repo *CronCmdRepo) createCrontabTmpFile() error { tmpCrontabFile, err := os.Create(repo.tmpCrontabFilename) if err != nil { return err @@ -41,7 +41,7 @@ func (repo CronCmdRepo) createCrontabTmpFile() error { return nil } -func (repo CronCmdRepo) installNewCrontab() error { +func (repo *CronCmdRepo) installNewCrontab() error { err := repo.createCrontabTmpFile() if err != nil { return nil @@ -49,7 +49,7 @@ func (repo CronCmdRepo) installNewCrontab() error { var crontabContent string for _, cron := range repo.currentCrontab { - crontabContent += cron.String() + crontabContent += cron.String() + "\n" } err = infraHelper.UpdateFile(repo.tmpCrontabFilename, crontabContent, true) @@ -57,10 +57,7 @@ func (repo CronCmdRepo) installNewCrontab() error { return err } - _, err = infraHelper.RunCmd( - "crontab", - repo.tmpCrontabFilename, - ) + _, err = infraHelper.RunCmd("crontab", repo.tmpCrontabFilename) if err != nil { return err } @@ -68,7 +65,7 @@ func (repo CronCmdRepo) installNewCrontab() error { return os.Remove(repo.tmpCrontabFilename) } -func (repo CronCmdRepo) Create(createCron dto.CreateCron) error { +func (repo *CronCmdRepo) Create(createCron dto.CreateCron) error { cronsCount := len(repo.currentCrontab) newCronIndex := cronsCount + 1 @@ -78,10 +75,7 @@ func (repo CronCmdRepo) Create(createCron dto.CreateCron) error { } newCron := entity.NewCron( - cronId, - createCron.Schedule, - createCron.Command, - createCron.Comment, + cronId, createCron.Schedule, createCron.Command, createCron.Comment, ) repo.currentCrontab = append(repo.currentCrontab, newCron) @@ -89,50 +83,57 @@ func (repo CronCmdRepo) Create(createCron dto.CreateCron) error { return repo.installNewCrontab() } -func (repo CronCmdRepo) Update(updateCron dto.UpdateCron) error { +func (repo *CronCmdRepo) Update(updateCron dto.UpdateCron) error { cronToUpdateId := updateCron.Id cronToUpdateListIndex := cronToUpdateId.Get() - 1 - var newCronSchedule valueObject.CronSchedule - var newCronCommand valueObject.UnixCommand - var newCronComment *valueObject.CronComment - - newCronSchedule = repo.currentCrontab[cronToUpdateListIndex].Schedule + newCronSchedule := repo.currentCrontab[cronToUpdateListIndex].Schedule if updateCron.Schedule != nil { newCronSchedule = *updateCron.Schedule } - newCronCommand = repo.currentCrontab[cronToUpdateListIndex].Command + newCronCommand := repo.currentCrontab[cronToUpdateListIndex].Command if updateCron.Command != nil { newCronCommand = *updateCron.Command } - newCronComment = repo.currentCrontab[cronToUpdateListIndex].Comment + newCronComment := repo.currentCrontab[cronToUpdateListIndex].Comment if updateCron.Comment != nil { newCronComment = updateCron.Comment } newCron := entity.NewCron( - cronToUpdateId, - newCronSchedule, - newCronCommand, - newCronComment, + cronToUpdateId, newCronSchedule, newCronCommand, newCronComment, ) - repo.currentCrontab[cronToUpdateListIndex] = newCron return repo.installNewCrontab() } -func (repo CronCmdRepo) Delete(cronId valueObject.CronId) error { - var cronsUpdated []entity.Cron +func (repo *CronCmdRepo) Delete(cronId valueObject.CronId) error { + var cronsToKeep []entity.Cron for _, currentCron := range repo.currentCrontab { if cronId.Get() == currentCron.Id.Get() { continue } - cronsUpdated = append(cronsUpdated, currentCron) + cronsToKeep = append(cronsToKeep, currentCron) + } + repo.currentCrontab = cronsToKeep + + return repo.installNewCrontab() +} + +func (repo *CronCmdRepo) DeleteByComment(comment valueObject.CronComment) error { + commentStr := comment.String() + + var cronsToKeep []entity.Cron + for _, currentCron := range repo.currentCrontab { + if commentStr == currentCron.Comment.String() { + continue + } + cronsToKeep = append(cronsToKeep, currentCron) } - repo.currentCrontab = cronsUpdated + repo.currentCrontab = cronsToKeep return repo.installNewCrontab() } From 215088ff97d72e0e93714d4a1d8375a658da305e Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:53:21 -0300 Subject: [PATCH 22/23] fix: use cron delete by comment --- src/infra/services/uninstall.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/infra/services/uninstall.go b/src/infra/services/uninstall.go index 515bc2e48..925f15c16 100644 --- a/src/infra/services/uninstall.go +++ b/src/infra/services/uninstall.go @@ -20,26 +20,16 @@ func purgePkgs(packages []string) error { } func uninstallPhpWebserver() error { - cronQueryRepo := cronInfra.CronQueryRepo{} - crons, err := cronQueryRepo.Get() - if err != nil { - return errors.New("ReadCronsError") - } - cronCmdRepo, err := cronInfra.NewCronCmdRepo() if err != nil { return errors.New("CreateCronCmdRepoError: " + err.Error()) } - for _, cron := range crons { - if cron.Comment.String() != PhpWebserverAutoReloadCronComment { - continue - } + cronComment, _ := valueObject.NewCronComment(PhpWebserverAutoReloadCronComment) - err = cronCmdRepo.Delete(cron.Id) - if err != nil { - return errors.New("DeleteAutoReloadCronError") - } + err = cronCmdRepo.DeleteByComment(cronComment) + if err != nil { + return errors.New("DeleteAutoReloadCronError: " + err.Error()) } packages := append(OlsPackages, "lsphp*") From 6a5f75dc2c40b717265bab29f810cb40690b1f75 Mon Sep 17 00:00:00 2001 From: ntorga Date: Thu, 4 Jul 2024 20:55:05 -0300 Subject: [PATCH 23/23] fix: remove ptr from methods as there is no new --- src/infra/cron/cronQueryRepo.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/infra/cron/cronQueryRepo.go b/src/infra/cron/cronQueryRepo.go index 5c12e5b10..4d7f004b3 100644 --- a/src/infra/cron/cronQueryRepo.go +++ b/src/infra/cron/cronQueryRepo.go @@ -13,7 +13,7 @@ import ( type CronQueryRepo struct { } -func (repo *CronQueryRepo) cronFactory( +func (repo CronQueryRepo) cronFactory( cronIndex int, cronLine string, ) (entity.Cron, error) { @@ -61,7 +61,7 @@ func (repo *CronQueryRepo) cronFactory( return entity.NewCron(id, schedule, cmd, cronCommentPtr), nil } -func (repo *CronQueryRepo) Get() ([]entity.Cron, error) { +func (repo CronQueryRepo) Get() ([]entity.Cron, error) { crons := []entity.Cron{} cronOut, err := infraHelper.RunCmd("crontab", "-l") @@ -96,7 +96,7 @@ func (repo *CronQueryRepo) Get() ([]entity.Cron, error) { return crons, nil } -func (repo *CronQueryRepo) GetById( +func (repo CronQueryRepo) GetById( cronId valueObject.CronId, ) (cronEntity entity.Cron, err error) { crons, err := repo.Get()