From 6ffbf171c23596394c6c19918c56cc08679c4899 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 30 Oct 2024 14:59:35 +0100 Subject: [PATCH 1/5] Update dependencies --- go.mod | 18 +++++++++--------- go.sum | 35 ++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index 9491e50d..bc35b16f 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/Masterminds/semver/v3 v3.3.0 // indirect github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect github.com/alecthomas/go-check-sumtype v0.2.0 // indirect - github.com/alexkohler/nakedret/v2 v2.0.4 // indirect + github.com/alexkohler/nakedret/v2 v2.0.5 // indirect github.com/alexkohler/prealloc v1.0.0 // indirect github.com/alingse/asasalint v0.0.11 // indirect github.com/ashanbrown/forbidigo v1.6.0 // indirect @@ -44,7 +44,7 @@ require ( github.com/bkielbasa/cyclop v1.2.3 // indirect github.com/blizzy78/varnamelen v0.8.0 // indirect github.com/bombsimon/wsl/v4 v4.4.1 // indirect - github.com/breml/bidichk v0.3.1 // indirect + github.com/breml/bidichk v0.3.2 // indirect github.com/breml/errchkjson v0.4.0 // indirect github.com/butuzov/ireturn v0.3.0 // indirect github.com/butuzov/mirror v1.2.0 // indirect @@ -100,7 +100,7 @@ require ( github.com/jjti/go-spancheck v0.6.2 // indirect github.com/julz/importas v0.1.0 // indirect github.com/karamaru-alpha/copyloopvar v1.1.0 // indirect - github.com/kisielk/errcheck v1.7.0 // indirect + github.com/kisielk/errcheck v1.8.0 // indirect github.com/kisielk/gotool v1.0.0 // indirect github.com/kkHAIKE/contextcheck v1.1.5 // indirect github.com/kulti/thelper v0.6.3 // indirect @@ -127,7 +127,7 @@ require ( github.com/nakabonne/nestif v0.3.1 // indirect github.com/nishanths/exhaustive v0.12.0 // indirect github.com/nishanths/predeclared v0.2.2 // indirect - github.com/nunnatsa/ginkgolinter v0.16.2 // indirect + github.com/nunnatsa/ginkgolinter v0.17.0 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/patrickcping/pingone-go-sdk-v2/authorize v0.6.0 // indirect github.com/patrickcping/pingone-go-sdk-v2/credentials v0.9.0 // indirect @@ -137,14 +137,14 @@ require ( github.com/polyfloyd/go-errorlint v1.6.0 // indirect github.com/prometheus/client_golang v1.20.5 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.60.0 // indirect + github.com/prometheus/common v0.60.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 // indirect github.com/quasilyte/go-ruleguard/dsl v0.3.22 // indirect github.com/quasilyte/gogrep v0.5.0 // indirect github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect github.com/ryancurrah/gomodguard v1.3.5 // indirect github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect @@ -157,7 +157,7 @@ require ( github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/sivchari/containedctx v1.0.3 // indirect - github.com/sivchari/tenv v1.10.0 // indirect + github.com/sivchari/tenv v1.12.1 // indirect github.com/sonatard/noctx v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/sourcegraph/go-diff v0.7.0 // indirect @@ -170,8 +170,8 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect github.com/tdakkota/asciicheck v0.2.0 // indirect github.com/tetafro/godot v1.4.18 // indirect - github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a // indirect - github.com/timonwong/loggercheck v0.10.0 // indirect + github.com/timakin/bodyclose v0.0.0-20241017074824-adbc21e6bf36 // indirect + github.com/timonwong/loggercheck v0.10.1 // indirect github.com/tomarrell/wrapcheck/v2 v2.9.0 // indirect github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect github.com/ultraware/funlen v0.1.0 // indirect diff --git a/go.sum b/go.sum index d900108f..52895351 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/alecthomas/go-check-sumtype v0.2.0 h1:Bo+e4DFf3rs7ME9w/0SU/g6nmzJaphd github.com/alecthomas/go-check-sumtype v0.2.0/go.mod h1:WyYPfhfkdhyrdaligV6svFopZV8Lqdzn5pyVBaV6jhQ= github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/alexkohler/nakedret/v2 v2.0.4 h1:yZuKmjqGi0pSmjGpOC016LtPJysIL0WEUiaXW5SUnNg= -github.com/alexkohler/nakedret/v2 v2.0.4/go.mod h1:bF5i0zF2Wo2o4X4USt9ntUWve6JbFv02Ff4vlkmS/VU= +github.com/alexkohler/nakedret/v2 v2.0.5 h1:fP5qLgtwbx9EJE8dGEERT02YwS8En4r9nnZ71RK+EVU= +github.com/alexkohler/nakedret/v2 v2.0.5/go.mod h1:bF5i0zF2Wo2o4X4USt9ntUWve6JbFv02Ff4vlkmS/VU= github.com/alexkohler/prealloc v1.0.0 h1:Hbq0/3fJPQhNkN0dR95AVrr6R7tou91y0uHG5pOcUuw= github.com/alexkohler/prealloc v1.0.0/go.mod h1:VetnK3dIgFBBKmg0YnD9F9x6Icjd+9cvfHR56wJVlKE= github.com/alingse/asasalint v0.0.11 h1:SFwnQXJ49Kx/1GghOFz1XGqHYKp21Kq1nHad/0WQRnw= @@ -48,8 +48,8 @@ github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= github.com/bombsimon/wsl/v4 v4.4.1 h1:jfUaCkN+aUpobrMO24zwyAMwMAV5eSziCkOKEauOLdw= github.com/bombsimon/wsl/v4 v4.4.1/go.mod h1:Xu/kDxGZTofQcDGCtQe9KCzhHphIe0fDuyWTxER9Feo= -github.com/breml/bidichk v0.3.1 h1:mm0l1NVE6lhaF4GUI8wX6TRV+e9kyHSvtA1wSG3nDqU= -github.com/breml/bidichk v0.3.1/go.mod h1:Qo0jQtZkQYyArvHxFXxNmaioxJRgfnSo6UirDTaAJL4= +github.com/breml/bidichk v0.3.2 h1:xV4flJ9V5xWTqxL+/PMFF6dtJPvZLPsyixAoPe8BGJs= +github.com/breml/bidichk v0.3.2/go.mod h1:VzFLBxuYtT23z5+iVkamXO386OB+/sVwZOpIj6zXGos= github.com/breml/errchkjson v0.4.0 h1:gftf6uWZMtIa/Is3XJgibewBm2ksAQSY/kABDNFTAdk= github.com/breml/errchkjson v0.4.0/go.mod h1:AuBOSTHyLSaaAFlWsRSuRBIroCh3eh7ZHh5YeelDIk8= github.com/butuzov/ireturn v0.3.0 h1:hTjMqWw3y5JC3kpnC5vXmFJAWI/m31jaCYQqzkS6PL0= @@ -203,8 +203,8 @@ github.com/julz/importas v0.1.0 h1:F78HnrsjY3cR7j0etXy5+TU1Zuy7Xt08X/1aJnH5xXY= github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= github.com/karamaru-alpha/copyloopvar v1.1.0 h1:x7gNyKcC2vRBO1H2Mks5u1VxQtYvFiym7fCjIP8RPos= github.com/karamaru-alpha/copyloopvar v1.1.0/go.mod h1:u7CIfztblY0jZLOQZgH3oYsJzpC2A7S6u/lfgSXHy0k= -github.com/kisielk/errcheck v1.7.0 h1:+SbscKmWJ5mOK/bO1zS60F5I9WwZDWOfRsC4RwfwRV0= -github.com/kisielk/errcheck v1.7.0/go.mod h1:1kLL+jV4e+CFfueBmI1dSK2ADDyQnlrnrY/FqKluHJQ= +github.com/kisielk/errcheck v1.8.0 h1:ZX/URYa7ilESY19ik/vBmCn6zdGQLxACwjAcWbHlYlg= +github.com/kisielk/errcheck v1.8.0/go.mod h1:1kLL+jV4e+CFfueBmI1dSK2ADDyQnlrnrY/FqKluHJQ= github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkHAIKE/contextcheck v1.1.5 h1:CdnJh63tcDe53vG+RebdpdXJTc9atMgGqdx8LXxiilg= @@ -270,8 +270,8 @@ github.com/nishanths/exhaustive v0.12.0 h1:vIY9sALmw6T/yxiASewa4TQcFsVYZQQRUQJhK github.com/nishanths/exhaustive v0.12.0/go.mod h1:mEZ95wPIZW+x8kC4TgC+9YCUgiST7ecevsVDTgc2obs= github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= github.com/nishanths/predeclared v0.2.2/go.mod h1:RROzoN6TnGQupbC+lqggsOlcgysk3LMK/HI84Mp280c= -github.com/nunnatsa/ginkgolinter v0.16.2 h1:8iLqHIZvN4fTLDC0Ke9tbSZVcyVHoBs0HIbnVSxfHJk= -github.com/nunnatsa/ginkgolinter v0.16.2/go.mod h1:4tWRinDN1FeJgU+iJANW/kz7xKN5nYRAOfJDQUS9dOQ= +github.com/nunnatsa/ginkgolinter v0.17.0 h1:9cvAxodbajOdYkszkj/qZTBgWB3/BUyV/PpPoVzwXnE= +github.com/nunnatsa/ginkgolinter v0.17.0/go.mod h1:vPrWafSULmjMGCMsfGA908if95VnHQNAahvSBOjTuWs= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo/v2 v2.20.2 h1:7NVCeyIWROIAheY21RLS+3j2bb52W0W82tkberYytp4= @@ -317,8 +317,8 @@ github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+ github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= -github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc= +github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/quasilyte/go-ruleguard v0.4.3-0.20240823090925-0fe6f58b47b1 h1:+Wl/0aFp0hpuHM3H//KMft64WQ1yX9LdJY64Qm/gFCo= @@ -331,8 +331,9 @@ github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 h1:TCg2WBOl github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0= github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 h1:M8mH9eK4OUR4lu7Gd+PU1fV2/qnDNfzT635KRSObncs= github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567/go.mod h1:DWNGW8A4Y+GyBgPuaQJuWiy0XYftx4Xm/y5Jqk9I6VQ= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -365,8 +366,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sivchari/containedctx v1.0.3 h1:x+etemjbsh2fB5ewm5FeLNi5bUjK0V8n0RB+Wwfd0XE= github.com/sivchari/containedctx v1.0.3/go.mod h1:c1RDvCbnJLtH4lLcYD/GqwiBSSf4F5Qk0xld2rBqzJ4= -github.com/sivchari/tenv v1.10.0 h1:g/hzMA+dBCKqGXgW8AV/1xIWhAvDrx0zFKNR48NFMg0= -github.com/sivchari/tenv v1.10.0/go.mod h1:tdY24masnVoZFxYrHv/nD6Tc8FbkEtAQEEziXpyMgqY= +github.com/sivchari/tenv v1.12.1 h1:+E0QzjktdnExv/wwsnnyk4oqZBUfuh89YMQT1cyuvSY= +github.com/sivchari/tenv v1.12.1/go.mod h1:1LjSOUCc25snIr5n3DtGGrENhX3LuWefcplwVGC24mw= github.com/sonatard/noctx v0.1.0 h1:JjqOc2WN16ISWAjAk8M5ej0RfExEXtkEyExl2hLW+OM= github.com/sonatard/noctx v0.1.0/go.mod h1:0RvBxqY8D4j9cTTTWE8ylt2vqj2EPI8fHmrxHdsaZ2c= github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= @@ -411,10 +412,10 @@ github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpR github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY= github.com/tetafro/godot v1.4.18 h1:ouX3XGiziKDypbpXqShBfnNLTSjR8r3/HVzrtJ+bHlI= github.com/tetafro/godot v1.4.18/go.mod h1:2oVxTBSftRTh4+MVfUaUXR6bn2GDXCaMcOG4Dk3rfio= -github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a h1:A6uKudFIfAEpoPdaal3aSqGxBzLyU8TqyXImLwo6dIo= -github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a/go.mod h1:mkjARE7Yr8qU23YcGMSALbIxTQ9r9QBVahQOBRfU460= -github.com/timonwong/loggercheck v0.10.0 h1:I147kLXbiXRqomF9km8rz0/cgXt4qCLxpYrR8ihupb0= -github.com/timonwong/loggercheck v0.10.0/go.mod h1:EJLx5lF0NvxwjQdUSLqRlsZiXcTHyK2Jspsds8s+Koc= +github.com/timakin/bodyclose v0.0.0-20241017074824-adbc21e6bf36 h1:BLrrwIAzisfgAzwJXJmDV13xxgP8S0ITQtc8vVFPRXY= +github.com/timakin/bodyclose v0.0.0-20241017074824-adbc21e6bf36/go.mod h1:mkjARE7Yr8qU23YcGMSALbIxTQ9r9QBVahQOBRfU460= +github.com/timonwong/loggercheck v0.10.1 h1:uVZYClxQFpw55eh+PIoqM7uAOHMrhVcDoWDery9R8Lg= +github.com/timonwong/loggercheck v0.10.1/go.mod h1:HEAWU8djynujaAVX7QI65Myb8qgfcZ1uKbdpg3ZzKl8= github.com/tomarrell/wrapcheck/v2 v2.9.0 h1:801U2YCAjLhdN8zhZ/7tdjB3EnAoRlJHt/s+9hijLQ4= github.com/tomarrell/wrapcheck/v2 v2.9.0/go.mod h1:g9vNIyhb5/9TQgumxQyOEqDHsmGYcGsVMOx/xGkqdMo= github.com/tommy-muehle/go-mnd/v2 v2.5.1 h1:NowYhSdyE/1zwK9QCLeRb6USWdoif80Ie+v+yU8u1Zw= From bd90535cad2f850619c120249426f5b225256fb7 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 30 Oct 2024 16:15:34 +0100 Subject: [PATCH 2/5] PDI-2056: Require User to Specify Export Output Directory - Remove auto-generated output directory from profile creation - Require output directory from user in export_internal.go - Add examples for both absolute filepaths and relative ones. --- cmd/root.go | 4 +-- internal/commands/platform/export_internal.go | 35 ++++++++++++++----- internal/configuration/platform/export.go | 32 ++++------------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index d2d58dfa..3c0f9ceb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -98,7 +98,7 @@ func initViperProfile() { // Validate the configuration if err := profiles.Validate(); err != nil { - output.UserFatal(fmt.Sprintf("Failed to validate Ping CLI configuration: %v", err), nil) + output.UserFatal(fmt.Sprintf("%v", err), nil) } } @@ -151,7 +151,7 @@ func initMainViper(cfgFile string) { loadMainViperConfig(cfgFile) } - // For each profile, if a viper key from an option doesn't exist, set it to nil + // For each profile, if a viper key from an option doesn't exist, set it to the default value for _, pName := range profiles.GetMainConfig().ProfileNames() { subViper := profiles.GetMainConfig().ViperInstance().Sub(pName) for _, opt := range options.Options() { diff --git a/internal/commands/platform/export_internal.go b/internal/commands/platform/export_internal.go index 1d208677..e9bef70d 100644 --- a/internal/commands/platform/export_internal.go +++ b/internal/commands/platform/export_internal.go @@ -82,7 +82,7 @@ func RunInternalExport(ctx context.Context, commandVersion string) (err error) { if err != nil { return err } - if err := createOrValidateOutputDir(outputDir, overwriteExportBool); err != nil { + if outputDir, err = createOrValidateOutputDir(outputDir, overwriteExportBool); err != nil { return err } @@ -355,22 +355,41 @@ pingone region - %s return nil } -func createOrValidateOutputDir(outputDir string, overwriteExport bool) (err error) { +func createOrValidateOutputDir(outputDir string, overwriteExport bool) (resolvedOutputDir string, err error) { l := logger.Get() + // Check if outputDir is empty + if outputDir == "" { + return "", fmt.Errorf("Failed to export services. The output directory is not set. Specify the output directory "+ + "via the '--%s' flag, '%s' environment variable, or key '%s' in the configuration file.", + options.PlatformExportOutputDirectoryOption.CobraParamName, + options.PlatformExportOutputDirectoryOption.EnvVar, + options.PlatformExportOutputDirectoryOption.ViperKey) + } + + // Check if path is absolute. If not, make it absolute using the present working directory + if !filepath.IsAbs(outputDir) { + pwd, err := os.Getwd() + if err != nil { + return "", fmt.Errorf("failed to get present working directory: %v", err) + } + + outputDir = filepath.Join(pwd, outputDir) + } + // Check if outputDir exists // If not, create the directory l.Debug().Msgf("Validating export output directory '%s'", outputDir) _, err = os.Stat(outputDir) if err != nil { - output.Warn(fmt.Sprintf("failed to find 'platform export' output directory. creating new output directory at filepath '%s'", outputDir), nil) + output.Warn(fmt.Sprintf("Output directory does not exist. Creating the directory at filepath '%s'", outputDir), nil) err = os.MkdirAll(outputDir, os.ModePerm) if err != nil { - return fmt.Errorf("failed to create 'platform export' output directory '%s': %s", outputDir, err.Error()) + return "", fmt.Errorf("failed to create 'platform export' output directory '%s': %s", outputDir, err.Error()) } - output.Success(fmt.Sprintf("new 'platform export' output directory '%s' created", outputDir), nil) + output.Success(fmt.Sprintf("Output directory '%s' created", outputDir), nil) } else { // Check if the output directory is empty // If not, default behavior is to exit and not overwrite. @@ -378,16 +397,16 @@ func createOrValidateOutputDir(outputDir string, overwriteExport bool) (err erro if !overwriteExport { dirEntries, err := os.ReadDir(outputDir) if err != nil { - return fmt.Errorf("failed to read contents of 'platform export' output directory '%s': %s", outputDir, err.Error()) + return "", fmt.Errorf("failed to read contents of output directory '%s': %v", outputDir, err) } if len(dirEntries) > 0 { - return fmt.Errorf("'platform export' output directory '%s' is not empty. Use --overwrite to overwrite existing export data", outputDir) + return "", fmt.Errorf("output directory '%s' is not empty. Use --overwrite to overwrite existing export data", outputDir) } } } - return nil + return outputDir, nil } func getPingOneExportEnvID() (err error) { diff --git a/internal/configuration/platform/export.go b/internal/configuration/platform/export.go index e40a003e..61c50a36 100644 --- a/internal/configuration/platform/export.go +++ b/internal/configuration/platform/export.go @@ -2,12 +2,10 @@ package configuration_platform import ( "fmt" - "os" "strings" "github.com/pingidentity/pingcli/internal/configuration/options" "github.com/pingidentity/pingcli/internal/customtypes" - "github.com/pingidentity/pingcli/internal/logger" "github.com/spf13/pflag" ) @@ -81,20 +79,21 @@ func initServicesOption() { func initOutputDirectoryOption() { cobraParamName := "output-directory" cobraValue := new(customtypes.String) - defaultValue := getDefaultExportDir() + defaultValue := customtypes.String("") envVar := "PINGCLI_EXPORT_OUTPUT_DIRECTORY" options.PlatformExportOutputDirectoryOption = options.Option{ CobraParamName: cobraParamName, CobraParamValue: cobraValue, - DefaultValue: defaultValue, + DefaultValue: &defaultValue, EnvVar: envVar, Flag: &pflag.Flag{ Name: cobraParamName, Shorthand: "d", - Usage: "Specifies the output directory for export. " + - "(default $(pwd)/export)" + - "\nExample: '$HOME/pingcli-export'", + Usage: "Specifies the output directory for export. Can be an absolute filepath or a relative filepath of" + + " the present working directory. " + + "\nExample: '/Users/example/pingcli-export'" + + "\nExample: 'pingcli-export'", Value: cobraValue, }, Type: options.ENUM_STRING, @@ -145,22 +144,3 @@ func initPingOneEnvironmentIDOption() { ViperKey: "export.pingone.environmentID", } } - -func getDefaultExportDir() (defaultExportDir *customtypes.String) { - l := logger.Get() - pwd, err := os.Getwd() - if err != nil { - l.Err(err).Msg("Failed to determine current working directory") - return nil - } - - defaultExportDir = new(customtypes.String) - - err = defaultExportDir.Set(fmt.Sprintf("%s/export", pwd)) - if err != nil { - l.Err(err).Msg("Failed to set default export directory") - return nil - } - - return defaultExportDir -} From baea16ad21d8e329e0cd04dde66e638db52b0b48 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 30 Oct 2024 16:20:56 +0100 Subject: [PATCH 3/5] update error message --- internal/commands/platform/export_internal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/platform/export_internal.go b/internal/commands/platform/export_internal.go index e9bef70d..58ee710d 100644 --- a/internal/commands/platform/export_internal.go +++ b/internal/commands/platform/export_internal.go @@ -386,7 +386,7 @@ func createOrValidateOutputDir(outputDir string, overwriteExport bool) (resolved err = os.MkdirAll(outputDir, os.ModePerm) if err != nil { - return "", fmt.Errorf("failed to create 'platform export' output directory '%s': %s", outputDir, err.Error()) + return "", fmt.Errorf("failed to create output directory '%s': %s", outputDir, err.Error()) } output.Success(fmt.Sprintf("Output directory '%s' created", outputDir), nil) From 42321dd6a97f27caed6f8380b32a9a3ce9b554fb Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 30 Oct 2024 16:23:26 +0100 Subject: [PATCH 4/5] fix test cases --- internal/commands/platform/export_internal_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/commands/platform/export_internal_test.go b/internal/commands/platform/export_internal_test.go index f57943c7..d520930f 100644 --- a/internal/commands/platform/export_internal_test.go +++ b/internal/commands/platform/export_internal_test.go @@ -150,7 +150,7 @@ func TestCreateOrValidateOutputDir(t *testing.T) { outputDir := os.TempDir() + "/nonexistantdir" - err := createOrValidateOutputDir(outputDir, false) + _, err := createOrValidateOutputDir(outputDir, false) testutils.CheckExpectedError(t, err, nil) } @@ -160,7 +160,7 @@ func TestCreateOrValidateOutputDirExistentDir(t *testing.T) { outputDir := t.TempDir() - err := createOrValidateOutputDir(outputDir, false) + _, err := createOrValidateOutputDir(outputDir, false) testutils.CheckExpectedError(t, err, nil) } @@ -177,7 +177,7 @@ func TestCreateOrValidateOutputDirExistentDirWithFile(t *testing.T) { } file.Close() - err = createOrValidateOutputDir(outputDir, true) + _, err = createOrValidateOutputDir(outputDir, true) testutils.CheckExpectedError(t, err, nil) } @@ -195,7 +195,7 @@ func TestCreateOrValidateOutputDirExistentDirWithFileNoOverwrite(t *testing.T) { file.Close() expectedErrorPattern := `^'platform export' output directory '.*' is not empty\. Use --overwrite to overwrite existing export data$` - err = createOrValidateOutputDir(outputDir, false) + _, err = createOrValidateOutputDir(outputDir, false) testutils.CheckExpectedError(t, err, &expectedErrorPattern) } From 6c35e7a17a2cfdb4143f43c3856e85d2398d8b81 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Wed, 30 Oct 2024 16:32:18 +0100 Subject: [PATCH 5/5] fix tests --- cmd/platform/export_test.go | 4 ++-- internal/commands/platform/export_internal_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/platform/export_test.go b/cmd/platform/export_test.go index a16b888c..ce4892c2 100644 --- a/cmd/platform/export_test.go +++ b/cmd/platform/export_test.go @@ -96,7 +96,7 @@ func TestPlatformExportCmd_OutputDirectoryFlag(t *testing.T) { // Test Platform Export Command --output-directory flag with invalid directory func TestPlatformExportCmd_OutputDirectoryFlagInvalidDirectory(t *testing.T) { - expectedErrorPattern := `^failed to create 'platform export' output directory '\/invalid': mkdir \/invalid: .+$` + expectedErrorPattern := `^failed to create output directory '\/invalid': mkdir \/invalid: .+$` err := testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", "/invalid") testutils.CheckExpectedError(t, err, &expectedErrorPattern) } @@ -122,7 +122,7 @@ func TestPlatformExportCmd_OverwriteFlagFalseWithExistingDirectory(t *testing.T) t.Errorf("Error creating file in output directory: %v", err) } - expectedErrorPattern := `^'platform export' output directory '[A-Za-z0-9_\-\/]+' is not empty\. Use --overwrite to overwrite existing export data$` + expectedErrorPattern := `^output directory '[A-Za-z0-9_\-\/]+' is not empty\. Use --overwrite to overwrite existing export data$` err = testutils_cobra.ExecutePingcli(t, "platform", "export", "--output-directory", outputDir, "--services", "pingone-protect", diff --git a/internal/commands/platform/export_internal_test.go b/internal/commands/platform/export_internal_test.go index d520930f..05924eb8 100644 --- a/internal/commands/platform/export_internal_test.go +++ b/internal/commands/platform/export_internal_test.go @@ -194,7 +194,7 @@ func TestCreateOrValidateOutputDirExistentDirWithFileNoOverwrite(t *testing.T) { } file.Close() - expectedErrorPattern := `^'platform export' output directory '.*' is not empty\. Use --overwrite to overwrite existing export data$` + expectedErrorPattern := `^output directory '.*' is not empty\. Use --overwrite to overwrite existing export data$` _, err = createOrValidateOutputDir(outputDir, false) testutils.CheckExpectedError(t, err, &expectedErrorPattern) }