From 841d6163fd6eda871cb9db96c9de7301e2582cc2 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 19 Nov 2024 11:12:07 -0700 Subject: [PATCH 1/9] Upgrade Dependencies --- go.mod | 30 +++++++++++++++--------------- go.sum | 55 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/go.mod b/go.mod index e12a4c3a..a1585554 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ module github.com/pingidentity/pingcli -go 1.23.2 +go 1.23.3 require ( github.com/fatih/color v1.18.0 github.com/golangci/golangci-lint v1.62.0 github.com/hashicorp/go-uuid v1.0.3 github.com/manifoldco/promptui v0.9.0 - github.com/patrickcping/pingone-go-sdk-v2 v0.12.3 - github.com/patrickcping/pingone-go-sdk-v2/management v0.43.0 - github.com/patrickcping/pingone-go-sdk-v2/mfa v0.20.0 - github.com/patrickcping/pingone-go-sdk-v2/risk v0.16.0 + github.com/patrickcping/pingone-go-sdk-v2 v0.12.4 + github.com/patrickcping/pingone-go-sdk-v2/management v0.44.0 + github.com/patrickcping/pingone-go-sdk-v2/mfa v0.21.0 + github.com/patrickcping/pingone-go-sdk-v2/risk v0.17.0 github.com/pavius/impi v0.0.3 github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.3 github.com/rs/zerolog v1.33.0 @@ -27,7 +27,7 @@ require ( github.com/Abirdcfly/dupword v0.1.3 // indirect github.com/Antonboom/errname v1.0.0 // indirect github.com/Antonboom/nilnil v1.0.0 // indirect - github.com/Antonboom/testifylint v1.5.0 // indirect + github.com/Antonboom/testifylint v1.5.2 // indirect github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect github.com/Crocmagnon/fatcontext v0.5.2 // indirect github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect @@ -88,7 +88,7 @@ require ( github.com/google/go-cmp v0.6.0 // indirect github.com/gordonklaus/ineffassign v0.1.0 // indirect github.com/gostaticanalysis/analysisutil v0.7.1 // indirect - github.com/gostaticanalysis/comment v1.4.2 // indirect + github.com/gostaticanalysis/comment v1.5.0 // indirect github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect github.com/gostaticanalysis/nilerr v0.1.1 // indirect github.com/hashicorp/go-version v1.7.0 // indirect @@ -118,7 +118,7 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect - github.com/mgechev/revive v1.5.0 // indirect + github.com/mgechev/revive v1.5.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moricho/tparallel v0.3.2 // indirect @@ -126,14 +126,14 @@ 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.18.2 // indirect + github.com/nunnatsa/ginkgolinter v0.18.3 // 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 - github.com/patrickcping/pingone-go-sdk-v2/verify v0.7.0 // indirect + github.com/patrickcping/pingone-go-sdk-v2/authorize v0.7.0 // indirect + github.com/patrickcping/pingone-go-sdk-v2/credentials v0.10.0 // indirect + github.com/patrickcping/pingone-go-sdk-v2/verify v0.8.0 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/polyfloyd/go-errorlint v1.6.0 // indirect + github.com/polyfloyd/go-errorlint v1.7.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.1 // indirect @@ -173,7 +173,7 @@ require ( github.com/tetafro/godot v1.4.18 // 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/tomarrell/wrapcheck/v2 v2.10.0 // indirect github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect github.com/ultraware/funlen v0.1.0 // indirect github.com/ultraware/whitespace v0.1.1 // indirect @@ -197,7 +197,7 @@ require ( golang.org/x/sys v0.27.0 // indirect golang.org/x/text v0.20.0 // indirect golang.org/x/tools v0.27.0 // indirect - google.golang.org/protobuf v1.35.1 // indirect + google.golang.org/protobuf v1.35.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect honnef.co/go/tools v0.5.1 // indirect diff --git a/go.sum b/go.sum index 0424f265..ec627ca4 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/Antonboom/errname v1.0.0 h1:oJOOWR07vS1kRusl6YRSlat7HFnb3mSfMl6sDMRoT github.com/Antonboom/errname v1.0.0/go.mod h1:gMOBFzK/vrTiXN9Oh+HFs+e6Ndl0eTFbtsRTSRdXyGI= github.com/Antonboom/nilnil v1.0.0 h1:n+v+B12dsE5tbAqRODXmEKfZv9j2KcTBrp+LkoM4HZk= github.com/Antonboom/nilnil v1.0.0/go.mod h1:fDJ1FSFoLN6yoG65ANb1WihItf6qt9PJVTn/s2IrcII= -github.com/Antonboom/testifylint v1.5.0 h1:dlUIsDMtCrZWUnvkaCz3quJCoIjaGi41GzjPBGkkJ8A= -github.com/Antonboom/testifylint v1.5.0/go.mod h1:wqaJbu0Blb5Wag2wv7Z5xt+CIV+eVLxtGZrlK13z3AE= +github.com/Antonboom/testifylint v1.5.2 h1:4s3Xhuv5AvdIgbd8wOOEeo0uZG7PbDKQyKY5lGoQazk= +github.com/Antonboom/testifylint v1.5.2/go.mod h1:vxy8VJ0bc6NavlYqjZfmp6EfqXMtBgQ4+mhCojwC1P8= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/Crocmagnon/fatcontext v0.5.2 h1:vhSEg8Gqng8awhPju2w7MKHqMlg4/NI+gSDHtR3xgwA= @@ -173,8 +173,9 @@ github.com/gordonklaus/ineffassign v0.1.0/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it github.com/gostaticanalysis/analysisutil v0.7.1 h1:ZMCjoue3DtDWQ5WyU16YbjbQEQ3VuzwxALrpYd+HeKk= github.com/gostaticanalysis/analysisutil v0.7.1/go.mod h1:v21E3hY37WKMGSnbsw2S/ojApNWb6C1//mXO48CXbVc= github.com/gostaticanalysis/comment v1.4.1/go.mod h1:ih6ZxzTHLdadaiSnF5WY3dxUoXfXAlTaRzuaNDlSado= -github.com/gostaticanalysis/comment v1.4.2 h1:hlnx5+S2fY9Zo9ePo4AhgYsYHbM2+eAv8m/s1JiCd6Q= github.com/gostaticanalysis/comment v1.4.2/go.mod h1:KLUTGDv6HOCotCH8h2erHKmpci2ZoR8VPu34YA2uzdM= +github.com/gostaticanalysis/comment v1.5.0 h1:X82FLl+TswsUMpMh17srGRuKaaXprTaytmEpgnKIDu8= +github.com/gostaticanalysis/comment v1.5.0/go.mod h1:V6eb3gpCv9GNVqb6amXzEUX3jXLVK/AdA+IrAMSqvEc= github.com/gostaticanalysis/forcetypeassert v0.1.0 h1:6eUflI3DiGusXGK6X7cCcIgVCpZ2CiZ1Q7jl6ZxNV70= github.com/gostaticanalysis/forcetypeassert v0.1.0/go.mod h1:qZEedyP/sY1lTGV1uJ3VhWZ2mqag3IkWsDHVbplHXak= github.com/gostaticanalysis/nilerr v0.1.1 h1:ThE+hJP0fEp4zWLkWHWcRyI2Od0p7DlgYG3Uqrmrcpk= @@ -252,8 +253,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/mgechev/revive v1.5.0 h1:oaSmjA7rP8+HyoRuCgC531VHwnLH1AlJdjj+1AnQceQ= -github.com/mgechev/revive v1.5.0/go.mod h1:L6T3H8EoerRO86c7WuGpvohIUmiploGiyoYbtIWFmV8= +github.com/mgechev/revive v1.5.1 h1:hE+QPeq0/wIzJwOphdVyUJ82njdd8Khp4fUIHGZHW3M= +github.com/mgechev/revive v1.5.1/go.mod h1:lC9AhkJIBs5zwx8wkudyHrU+IJkrEKmpCmGMnIJPk4o= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -268,8 +269,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.18.2 h1:b2yZTU30JabiqGnmcJtFVXLBXyAj2Dmy7ZwPUbYphyc= -github.com/nunnatsa/ginkgolinter v0.18.2/go.mod h1:Mp5o0Yc8+cBJEmcu3QAzk6QxT0HgbWO7Ofb28zrJ/Vs= +github.com/nunnatsa/ginkgolinter v0.18.3 h1:WgS7X3zzmni3vwHSBhvSgqrRgUecN6PQUcfB0j1noDw= +github.com/nunnatsa/ginkgolinter v0.18.3/go.mod h1:BE1xyB/PNtXXG1azrvrqJW5eFH0hSRylNzFy8QHPwzs= 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= @@ -283,20 +284,20 @@ github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJ github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= github.com/otiai10/mint v1.3.1/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= -github.com/patrickcping/pingone-go-sdk-v2 v0.12.3 h1:XE6W6slEcgiWZACXtgpcYaOZobXPQFy23KZxo72+ZdA= -github.com/patrickcping/pingone-go-sdk-v2 v0.12.3/go.mod h1:XxS30BS5T6OktONudZYJkpqDMJZ/ttfhKRr9ysqFqX4= -github.com/patrickcping/pingone-go-sdk-v2/authorize v0.6.0 h1:nWvkKoo8NuQyjggqNQHe0D7agSvVRD4QYowMLUEggBo= -github.com/patrickcping/pingone-go-sdk-v2/authorize v0.6.0/go.mod h1:D+vbECm13P8SkyvcWN9hjw90Qw9sbqdJTUezb+CRt3o= -github.com/patrickcping/pingone-go-sdk-v2/credentials v0.9.0 h1:ZxeY871Y8FN0he3SpHte7voVXjcx5R00K/XOsPvxWsg= -github.com/patrickcping/pingone-go-sdk-v2/credentials v0.9.0/go.mod h1:sUk+JIdeUPPTtbK533QFDYygGcR51QAT9dccHfJEXDI= -github.com/patrickcping/pingone-go-sdk-v2/management v0.43.0 h1:MedfcWEgPJScxQriXORdBMUylJmk0xxSI1ImTnCpFRY= -github.com/patrickcping/pingone-go-sdk-v2/management v0.43.0/go.mod h1:5YMhQOKlAzBKK2y0md7GRj8JcBfTYdyMDidLiMxQCjA= -github.com/patrickcping/pingone-go-sdk-v2/mfa v0.20.0 h1:7u62JJ8nH8jZW79+O7cwrJBsDTMfQ5zllqG7twBeqJk= -github.com/patrickcping/pingone-go-sdk-v2/mfa v0.20.0/go.mod h1:2fA7oR1PNCE+U1mYlLP9P2kRJLDjh98KqOn4eP8OZIE= -github.com/patrickcping/pingone-go-sdk-v2/risk v0.16.0 h1:ZDffATzIhUsVlyEWz91DKwe9YD1VBoE3PsjlKiRMovE= -github.com/patrickcping/pingone-go-sdk-v2/risk v0.16.0/go.mod h1:bOWHYOWkAmJu8KxEsVf3l1XJB2+uFzgEyjk6z6BnjE4= -github.com/patrickcping/pingone-go-sdk-v2/verify v0.7.0 h1:m6aLDyttXySQaUTNMubJMtI0SteWTsi53lAqlcQ0CrI= -github.com/patrickcping/pingone-go-sdk-v2/verify v0.7.0/go.mod h1:CYnq6n5E8YDg3FYieSfldjjT/2EyMyYCgdoNAiqNZFc= +github.com/patrickcping/pingone-go-sdk-v2 v0.12.4 h1:geen+q6junlsLmTG30KC7zdnTCQ11BzKu7GGc22Tj5U= +github.com/patrickcping/pingone-go-sdk-v2 v0.12.4/go.mod h1:I1WQE3pSKTrwOzlUuNSN1Tmm5FFIUJwepnDoILpestw= +github.com/patrickcping/pingone-go-sdk-v2/authorize v0.7.0 h1:e36HmxvHy3zmt9oKHlTTgImSt1Q71RT05i6Kp4EwxWU= +github.com/patrickcping/pingone-go-sdk-v2/authorize v0.7.0/go.mod h1:2PDrgC1ufXk2IDIk4JQHx6r34r2xpkbnzKIpXFv8gYs= +github.com/patrickcping/pingone-go-sdk-v2/credentials v0.10.0 h1:NziAU4J3b18hw/4L+4TpCOBS+kd9srQR2R3xP0aEbNw= +github.com/patrickcping/pingone-go-sdk-v2/credentials v0.10.0/go.mod h1:yRGf7+tsB3/AQYsNjIIs4ScJhR885mvDYMgwHiQeMl0= +github.com/patrickcping/pingone-go-sdk-v2/management v0.44.0 h1:NjEaHbefO6YrvxsRWoNGSpEsQN0WFV/LJHO+rQilNzk= +github.com/patrickcping/pingone-go-sdk-v2/management v0.44.0/go.mod h1:oLB/jjAkn4oEA60nC5/0KAobvcNJbflOWnVaS6lKxv8= +github.com/patrickcping/pingone-go-sdk-v2/mfa v0.21.0 h1:/cfl+PcocLDj2m4ZgE653m3UDdIk7VEB7iVwCQ1YSH4= +github.com/patrickcping/pingone-go-sdk-v2/mfa v0.21.0/go.mod h1:Q+Ym6kktv5Y6VnVhDt//lWoOhmIKfyjo6ejRx5mLttY= +github.com/patrickcping/pingone-go-sdk-v2/risk v0.17.0 h1:sEJSGAFXhTB/Uy/ulxafLUnRqOE4W3PQoaaGMA1YaS4= +github.com/patrickcping/pingone-go-sdk-v2/risk v0.17.0/go.mod h1:ppwkDT/w2/2y2aFH+hFQgziLMsWvz2MEZvwYexREqRk= +github.com/patrickcping/pingone-go-sdk-v2/verify v0.8.0 h1:FsssxnJ/VSIxXtdvZlDn555nY+Yn1ndsg9IITyXYBbM= +github.com/patrickcping/pingone-go-sdk-v2/verify v0.8.0/go.mod h1:bCq5fHv9mSdNsm/XiT5jb3YgYnQb8F824EYfq9eAJl4= github.com/pavius/impi v0.0.3 h1:DND6MzU+BLABhOZXbELR3FU8b+zDgcq4dOCNLhiTYuI= github.com/pavius/impi v0.0.3/go.mod h1:x/hU0bfdWIhuOT1SKwiJg++yvkk6EuOtJk8WtDZqgr8= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= @@ -307,8 +308,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/polyfloyd/go-errorlint v1.6.0 h1:tftWV9DE7txiFzPpztTAwyoRLKNj9gpVm2cg8/OwcYY= -github.com/polyfloyd/go-errorlint v1.6.0/go.mod h1:HR7u8wuP1kb1NeN1zqTd1ZMlqUKPPHF+Id4vIPvDqVw= +github.com/polyfloyd/go-errorlint v1.7.0 h1:Zp6lzCK4hpBDj8y8a237YK4EPrMXQWvOe3nGoH4pFrU= +github.com/polyfloyd/go-errorlint v1.7.0/go.mod h1:dGWKu85mGHnegQ2SWpEybFityCg3j7ZbwsVUxAOk9gY= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= @@ -416,8 +417,8 @@ github.com/timakin/bodyclose v0.0.0-20241017074824-adbc21e6bf36 h1:BLrrwIAzisfgA 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/tomarrell/wrapcheck/v2 v2.10.0 h1:SzRCryzy4IrAH7bVGG4cK40tNUhmVmMDuJujy4XwYDg= +github.com/tomarrell/wrapcheck/v2 v2.10.0/go.mod h1:g9vNIyhb5/9TQgumxQyOEqDHsmGYcGsVMOx/xGkqdMo= github.com/tommy-muehle/go-mnd/v2 v2.5.1 h1:NowYhSdyE/1zwK9QCLeRb6USWdoif80Ie+v+yU8u1Zw= github.com/tommy-muehle/go-mnd/v2 v2.5.1/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw= github.com/ultraware/funlen v0.1.0 h1:BuqclbkY6pO+cvxoq7OsktIXZpgBSkYTQtmwhAK81vI= @@ -589,8 +590,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T 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= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 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= From 266c9e764fe51d0f97d88241de2acc3f7d28076a Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 19 Nov 2024 13:09:12 -0700 Subject: [PATCH 2/9] Update PingOneMFAApplicationPushCredentialResource to use PingOne pagination and only use Native OIDC applications to retrieve MFA push credentials --- internal/connector/common/resources_common.go | 100 ++++++++-------- ...pingone_mfa_application_push_credential.go | 107 +++++++++++------- 2 files changed, 120 insertions(+), 87 deletions(-) diff --git a/internal/connector/common/resources_common.go b/internal/connector/common/resources_common.go index e6289dd8..fdc1725d 100644 --- a/internal/connector/common/resources_common.go +++ b/internal/connector/common/resources_common.go @@ -32,64 +32,72 @@ func HandleClientResponse(response *http.Response, err error, apiFunctionName st return nil } -// Executes the function apiExecuteFunc for the ManagementAPIClient +// Iterates through the pagedIterator // Handles err and response if Client call failed -// Returns embedded data if not nil +// // Returns embedded data if not nil // Treats nil embedded data as an error -func GetManagementEmbedded(apiExecuteFunc func() (*management.EntityArray, *http.Response, error), apiFunctionName string, resourceType string) (*management.EntityArrayEmbedded, error) { - l := logger.Get() - - entityArray, response, err := apiExecuteFunc() - - err = HandleClientResponse(response, err, apiFunctionName, resourceType) - if err != nil { - return nil, err - } - - if entityArray == nil { - l.Error().Msgf("Returned %s() entityArray is nil.", apiFunctionName) - l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) - return nil, fmt.Errorf("failed to fetch %s resources via %s()", resourceType, apiFunctionName) +func GetAllManagementEmbedded(pagedIterator management.EntityArrayPagedIterator, apiFunctionName string, resourceType string) (allEmbedded []management.EntityArrayEmbedded, err error) { + allEmbedded = []management.EntityArrayEmbedded{} + + for pagedCursor, err := range pagedIterator { + err = HandleClientResponse(pagedCursor.HTTPResponse, err, apiFunctionName, resourceType) + if err != nil { + return nil, err + } + + dataNilErr := fmt.Errorf("failed to create resource '%s' import blocks.\n"+ + "PingOne API request for resource '%s' was not successful. response data is nil.\n"+ + "response code: %s\n"+ + "response body: %s", + resourceType, resourceType, pagedCursor.HTTPResponse.Status, pagedCursor.HTTPResponse.Body) + + if pagedCursor.EntityArray == nil { + return nil, dataNilErr + } + + embedded, embeddedOk := pagedCursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return nil, dataNilErr + } + + allEmbedded = append(allEmbedded, *embedded) } - embedded, embeddedOk := entityArray.GetEmbeddedOk() - if !embeddedOk { - l.Error().Msgf("Returned %s() embedded data is nil.", apiFunctionName) - l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) - return nil, fmt.Errorf("failed to fetch %s resources via %s()", resourceType, apiFunctionName) - } - - return embedded, nil + return allEmbedded, nil } // Executes the function apiExecuteFunc for the MFAAPIClient // Handles err and response if Client call failed // Returns embedded data if not nil // Treats nil embedded data as an error -func GetMFAEmbedded(apiExecuteFunc func() (*mfa.EntityArray, *http.Response, error), apiFunctionName string, resourceType string) (*mfa.EntityArrayEmbedded, error) { - l := logger.Get() - - entityArray, response, err := apiExecuteFunc() - - err = HandleClientResponse(response, err, apiFunctionName, resourceType) - if err != nil { - return nil, err +func GetAllMFAEmbedded(pagedIterator mfa.EntityArrayPagedIterator, apiFunctionName string, resourceType string) (allEmbedded []mfa.EntityArrayEmbedded, err error) { + allEmbedded = []mfa.EntityArrayEmbedded{} + + for pagedCursor, err := range pagedIterator { + err = HandleClientResponse(pagedCursor.HTTPResponse, err, apiFunctionName, resourceType) + if err != nil { + return nil, err + } + + dataNilErr := fmt.Errorf("failed to create resource '%s' import blocks.\n"+ + "PingOne API request for resource '%s' was not successful. response data is nil.\n"+ + "response code: %s\n"+ + "response body: %s", + resourceType, resourceType, pagedCursor.HTTPResponse.Status, pagedCursor.HTTPResponse.Body) + + if pagedCursor.EntityArray == nil { + return nil, dataNilErr + } + + embedded, embeddedOk := pagedCursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return nil, dataNilErr + } + + allEmbedded = append(allEmbedded, *embedded) } - if entityArray == nil { - l.Error().Msgf("Returned %s() entityArray is nil.", apiFunctionName) - l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) - return nil, fmt.Errorf("failed to fetch %s resources via %s()", resourceType, apiFunctionName) - } - - embedded, embeddedOk := entityArray.GetEmbeddedOk() - if !embeddedOk { - l.Error().Msgf("Returned %s() embedded data is nil.", apiFunctionName) - l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) - return nil, fmt.Errorf("failed to fetch %s resources via %s()", resourceType, apiFunctionName) - } - - return embedded, nil + return allEmbedded, nil } // Executes the function apiExecuteFunc for the RiskAPIClient diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go index 610aae4b..e75583e5 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go @@ -3,6 +3,8 @@ package resources import ( "fmt" + "github.com/patrickcping/pingone-go-sdk-v2/management" + "github.com/patrickcping/pingone-go-sdk-v2/mfa" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -29,67 +31,43 @@ func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector. l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - // Fetch all pingone_application resources that could have pingone_mfa_application_push_credentials - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + nativeOIDCApplications, err := r.getNativeOIDCApplications() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - } - - if appIdOk && appNameOk { - // Fetch all pingone_mfa_application_push_credentials for each application - apiExecuteFunc := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute - apiFunctionName := "ReadAllMFAPushCredentials" + importBlocks := []connector.ImportBlock{} + for _, nativeOIDCApplication := range nativeOIDCApplications { + nativeOIDCApplicationId, nativeOIDCApplicationIdOk := nativeOIDCApplication.GetIdOk() + nativeOIDCApplicationName, nativeOIDCApplicationNameOk := nativeOIDCApplication.GetNameOk() - embedded, err := common.GetMFAEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + if nativeOIDCApplicationIdOk && nativeOIDCApplicationNameOk { + mfaPushCredentialResponses, err := r.getMFAPushCredentials(nativeOIDCApplicationId) if err != nil { return nil, err } - for _, mfaPushCredentialResponse := range embedded.GetPushCredentials() { + for _, mfaPushCredentialResponse := range mfaPushCredentialResponses { mfaPushCredentialResponseType, mfaPushCredentialResponseTypeOk := mfaPushCredentialResponse.GetTypeOk() mfaPushCredentialResponseId, mfaPushCredentialResponseIdOk := mfaPushCredentialResponse.GetIdOk() if mfaPushCredentialResponseTypeOk && mfaPushCredentialResponseIdOk { commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "MFA Push Credential Type": string(*mfaPushCredentialResponseType), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - "MFA Push Credential ID": *mfaPushCredentialResponseId, + + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Push Credential ID": *mfaPushCredentialResponseId, + "MFA Push Credential Type": string(*mfaPushCredentialResponseType), + "Native Application (OpenID Connect) ID": *nativeOIDCApplicationId, + "Native Application (OpenID Connect) Name": *nativeOIDCApplicationName, + "Resource Type": r.ResourceType(), } importBlocks = append(importBlocks, connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *appName, *mfaPushCredentialResponseType), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *mfaPushCredentialResponseId), + ResourceName: fmt.Sprintf("%s_%s", *nativeOIDCApplicationName, *mfaPushCredentialResponseType), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *nativeOIDCApplicationId, *mfaPushCredentialResponseId), CommentInformation: common.GenerateCommentInformation(commentData), }) } @@ -103,3 +81,50 @@ func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector. func (r *PingOneMFAApplicationPushCredentialResource) ResourceType() string { return "pingone_mfa_application_push_credential" } + +func (r *PingOneMFAApplicationPushCredentialResource) getNativeOIDCApplications() (nativeOIDCApplications []*management.ApplicationOIDC, err error) { + nativeOIDCApplications = []*management.ApplicationOIDC{} + + // Fetch all pingone_application resources that could have pingone_mfa_application_push_credentials + applicationsPagedIterator := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + allEmbedded, err := common.GetAllManagementEmbedded(applicationsPagedIterator, "ReadAllApplications", "pingone_application") + if err != nil { + return nil, err + } + + // pingone_mfa_application_push_credential are for Native applications only + // Native application authenticate with OIDC only + for _, embedded := range allEmbedded { + for _, app := range embedded.GetApplications() { + if app.ApplicationOIDC != nil { + appType, appTypeOk := app.ApplicationOIDC.GetTypeOk() + if appTypeOk && *appType == management.ENUMAPPLICATIONTYPE_NATIVE_APP { + nativeOIDCApplications = append(nativeOIDCApplications, app.ApplicationOIDC) + } + } + } + } + + return nativeOIDCApplications, nil +} + +func (r *PingOneMFAApplicationPushCredentialResource) getMFAPushCredentials(nativeOIDCApplicationId *string) (mfaPushCredentialResponses []mfa.MFAPushCredentialResponse, err error) { + mfaPushCredentialResponses = []mfa.MFAPushCredentialResponse{} + + // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application + mfaApplicationPushCredentialsPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *nativeOIDCApplicationId).Execute() + + allEmbedded, err := common.GetAllMFAEmbedded(mfaApplicationPushCredentialsPagedIterator, "ReadAllMFAPushCredentials", r.ResourceType()) + if err != nil { + return nil, err + } + + for _, embedded := range allEmbedded { + for _, mfaPushCredentialResponse := range embedded.GetPushCredentials() { + mfaPushCredentialResponses = append(mfaPushCredentialResponses, mfaPushCredentialResponse) + } + } + + return mfaPushCredentialResponses, nil +} From 14bc1e444acc76f0355be25d300c3f0f6d509746 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 19 Nov 2024 14:15:40 -0700 Subject: [PATCH 3/9] Update all remaining PingOne MFA resources to use PingOne pagination --- ...pingone_mfa_application_push_credential.go | 149 ++++++++++-------- .../resources/pingone_mfa_device_policy.go | 88 ++++++++--- .../mfa/resources/pingone_mfa_fido2_policy.go | 88 ++++++++--- .../mfa/resources/pingone_mfa_settings.go | 19 ++- 4 files changed, 224 insertions(+), 120 deletions(-) diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go index e75583e5..f9b8f1df 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go @@ -19,6 +19,13 @@ type PingOneMFAApplicationPushCredentialResource struct { clientInfo *connector.PingOneClientInfo } +type mfaApplicationPushCredentialImportBlockData struct { + PushCredentialID string + PushCredentialType string + NativeOIDCApplicationID string + NativeOIDCApplicationName string +} + // Utility method for creating a PingOneMFAApplicationPushCredentialResource func MFAApplicationPushCredential(clientInfo *connector.PingOneClientInfo) *PingOneMFAApplicationPushCredentialResource { return &PingOneMFAApplicationPushCredentialResource{ @@ -26,69 +33,17 @@ func MFAApplicationPushCredential(clientInfo *connector.PingOneClientInfo) *Ping } } -func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() - - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - nativeOIDCApplications, err := r.getNativeOIDCApplications() - if err != nil { - return nil, err - } - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - importBlocks := []connector.ImportBlock{} - for _, nativeOIDCApplication := range nativeOIDCApplications { - nativeOIDCApplicationId, nativeOIDCApplicationIdOk := nativeOIDCApplication.GetIdOk() - nativeOIDCApplicationName, nativeOIDCApplicationNameOk := nativeOIDCApplication.GetNameOk() - - if nativeOIDCApplicationIdOk && nativeOIDCApplicationNameOk { - mfaPushCredentialResponses, err := r.getMFAPushCredentials(nativeOIDCApplicationId) - if err != nil { - return nil, err - } - - for _, mfaPushCredentialResponse := range mfaPushCredentialResponses { - mfaPushCredentialResponseType, mfaPushCredentialResponseTypeOk := mfaPushCredentialResponse.GetTypeOk() - mfaPushCredentialResponseId, mfaPushCredentialResponseIdOk := mfaPushCredentialResponse.GetIdOk() - - if mfaPushCredentialResponseTypeOk && mfaPushCredentialResponseIdOk { - commentData := map[string]string{ - - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "MFA Push Credential ID": *mfaPushCredentialResponseId, - "MFA Push Credential Type": string(*mfaPushCredentialResponseType), - "Native Application (OpenID Connect) ID": *nativeOIDCApplicationId, - "Native Application (OpenID Connect) Name": *nativeOIDCApplicationName, - "Resource Type": r.ResourceType(), - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *nativeOIDCApplicationName, *mfaPushCredentialResponseType), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *nativeOIDCApplicationId, *mfaPushCredentialResponseId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } - } - } - } - - return &importBlocks, nil -} - func (r *PingOneMFAApplicationPushCredentialResource) ResourceType() string { return "pingone_mfa_application_push_credential" } -func (r *PingOneMFAApplicationPushCredentialResource) getNativeOIDCApplications() (nativeOIDCApplications []*management.ApplicationOIDC, err error) { +func (r *PingOneMFAApplicationPushCredentialResource) nativeOIDCApplications() (nativeOIDCApplications []*management.ApplicationOIDC, err error) { nativeOIDCApplications = []*management.ApplicationOIDC{} // Fetch all pingone_application resources that could have pingone_mfa_application_push_credentials - applicationsPagedIterator := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + entityArrayPagedIterator := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - allEmbedded, err := common.GetAllManagementEmbedded(applicationsPagedIterator, "ReadAllApplications", "pingone_application") + allEmbedded, err := common.GetAllManagementEmbedded(entityArrayPagedIterator, "ReadAllApplications", "pingone_application") if err != nil { return nil, err } @@ -96,11 +51,11 @@ func (r *PingOneMFAApplicationPushCredentialResource) getNativeOIDCApplications( // pingone_mfa_application_push_credential are for Native applications only // Native application authenticate with OIDC only for _, embedded := range allEmbedded { - for _, app := range embedded.GetApplications() { - if app.ApplicationOIDC != nil { - appType, appTypeOk := app.ApplicationOIDC.GetTypeOk() + for _, readOneApplication200Response := range embedded.GetApplications() { + if readOneApplication200Response.ApplicationOIDC != nil { + appType, appTypeOk := readOneApplication200Response.ApplicationOIDC.GetTypeOk() if appTypeOk && *appType == management.ENUMAPPLICATIONTYPE_NATIVE_APP { - nativeOIDCApplications = append(nativeOIDCApplications, app.ApplicationOIDC) + nativeOIDCApplications = append(nativeOIDCApplications, readOneApplication200Response.ApplicationOIDC) } } } @@ -109,13 +64,13 @@ func (r *PingOneMFAApplicationPushCredentialResource) getNativeOIDCApplications( return nativeOIDCApplications, nil } -func (r *PingOneMFAApplicationPushCredentialResource) getMFAPushCredentials(nativeOIDCApplicationId *string) (mfaPushCredentialResponses []mfa.MFAPushCredentialResponse, err error) { +func (r *PingOneMFAApplicationPushCredentialResource) pushCredentialResponses(nativeOIDCApplicationId *string) (mfaPushCredentialResponses []mfa.MFAPushCredentialResponse, err error) { mfaPushCredentialResponses = []mfa.MFAPushCredentialResponse{} // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application - mfaApplicationPushCredentialsPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *nativeOIDCApplicationId).Execute() + entityArrayPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *nativeOIDCApplicationId).Execute() - allEmbedded, err := common.GetAllMFAEmbedded(mfaApplicationPushCredentialsPagedIterator, "ReadAllMFAPushCredentials", r.ResourceType()) + allEmbedded, err := common.GetAllMFAEmbedded(entityArrayPagedIterator, "ReadAllMFAPushCredentials", r.ResourceType()) if err != nil { return nil, err } @@ -128,3 +83,73 @@ func (r *PingOneMFAApplicationPushCredentialResource) getMFAPushCredentials(nati return mfaPushCredentialResponses, nil } + +func (r *PingOneMFAApplicationPushCredentialResource) importBlockData() (importBlockData []mfaApplicationPushCredentialImportBlockData, err error) { + importBlockData = []mfaApplicationPushCredentialImportBlockData{} + + nativeOIDCApplications, err := r.nativeOIDCApplications() + if err != nil { + return nil, err + } + + for _, nativeOIDCApplication := range nativeOIDCApplications { + nativeOIDCApplicationId, nativeOIDCApplicationIdOk := nativeOIDCApplication.GetIdOk() + nativeOIDCApplicationName, nativeOIDCApplicationNameOk := nativeOIDCApplication.GetNameOk() + + if nativeOIDCApplicationIdOk && nativeOIDCApplicationNameOk { + mfaPushCredentialResponses, err := r.pushCredentialResponses(nativeOIDCApplicationId) + if err != nil { + return nil, err + } + + for _, mfaPushCredentialResponse := range mfaPushCredentialResponses { + mfaPushCredentialResponseType, mfaPushCredentialResponseTypeOk := mfaPushCredentialResponse.GetTypeOk() + mfaPushCredentialResponseId, mfaPushCredentialResponseIdOk := mfaPushCredentialResponse.GetIdOk() + if mfaPushCredentialResponseTypeOk && mfaPushCredentialResponseIdOk { + importBlockData = append(importBlockData, mfaApplicationPushCredentialImportBlockData{ + PushCredentialID: *mfaPushCredentialResponseId, + PushCredentialType: string(*mfaPushCredentialResponseType), + NativeOIDCApplicationID: *nativeOIDCApplicationId, + NativeOIDCApplicationName: *nativeOIDCApplicationName, + }) + } + } + } + } + + return importBlockData, nil +} + +func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + importBlocks := []connector.ImportBlock{} + + l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + + importBlockData, err := r.importBlockData() + if err != nil { + return nil, err + } + + l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + + for _, data := range importBlockData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Application Push Credential ID": data.PushCredentialID, + "MFA Application Push Credential Type": data.PushCredentialType, + "Native Application (OpenID Connect) ID": data.NativeOIDCApplicationID, + "Native Application (OpenID Connect) Name": data.NativeOIDCApplicationName, + "Resource Type": r.ResourceType(), + } + + importBlocks = append(importBlocks, connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", data.NativeOIDCApplicationName, data.PushCredentialType), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, data.NativeOIDCApplicationID, data.PushCredentialID), + CommentInformation: common.GenerateCommentInformation(commentData), + }) + } + + return &importBlocks, nil +} diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go b/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go index c26a0b5b..8ce8eed4 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go @@ -3,6 +3,7 @@ package resources import ( "fmt" + "github.com/patrickcping/pingone-go-sdk-v2/mfa" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -17,6 +18,11 @@ type PingOneMFADevicePolicyResource struct { clientInfo *connector.PingOneClientInfo } +type mfaDevicePolicyImportBlockData struct { + ID string + Name string +} + // Utility method for creating a PingOneMFADevicePolicyResource func MFADevicePolicy(clientInfo *connector.PingOneClientInfo) *PingOneMFADevicePolicyResource { return &PingOneMFADevicePolicyResource{ @@ -24,47 +30,81 @@ func MFADevicePolicy(clientInfo *connector.PingOneClientInfo) *PingOneMFADeviceP } } -func (r *PingOneMFADevicePolicyResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() +func (r *PingOneMFADevicePolicyResource) ResourceType() string { + return "pingone_mfa_device_policy" +} - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) +func (r *PingOneMFADevicePolicyResource) deviceAuthenticationPolicies() (deviceAuthenticationPolicies []mfa.DeviceAuthenticationPolicy, err error) { + deviceAuthenticationPolicies = []mfa.DeviceAuthenticationPolicy{} - apiExecuteFunc := r.clientInfo.ApiClient.MFAAPIClient.DeviceAuthenticationPolicyApi.ReadDeviceAuthenticationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadDeviceAuthenticationPolicies" + // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application + entityArrayPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.DeviceAuthenticationPolicyApi.ReadDeviceAuthenticationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - embedded, err := common.GetMFAEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + allEmbedded, err := common.GetAllMFAEmbedded(entityArrayPagedIterator, "ReadDeviceAuthenticationPolicies", r.ResourceType()) if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + for _, embedded := range allEmbedded { + for _, deviceAuthenticationPolicy := range embedded.GetDeviceAuthenticationPolicies() { + deviceAuthenticationPolicies = append(deviceAuthenticationPolicies, deviceAuthenticationPolicy) + } + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return deviceAuthenticationPolicies, nil +} - for _, deviceAuthenticationPolicy := range embedded.GetDeviceAuthenticationPolicies() { +func (r *PingOneMFADevicePolicyResource) importBlockData() (importBlockData []mfaDevicePolicyImportBlockData, err error) { + importBlockData = []mfaDevicePolicyImportBlockData{} + + deviceAuthenticationPolicies, err := r.deviceAuthenticationPolicies() + if err != nil { + return nil, err + } + + for _, deviceAuthenticationPolicy := range deviceAuthenticationPolicies { deviceAuthenticationPolicyName, deviceAuthenticationPolicyNameOk := deviceAuthenticationPolicy.GetNameOk() deviceAuthenticationPolicyId, deviceAuthenticationPolicyIdOk := deviceAuthenticationPolicy.GetIdOk() if deviceAuthenticationPolicyNameOk && deviceAuthenticationPolicyIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "MFA Policy Name": *deviceAuthenticationPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "MFA Policy ID": *deviceAuthenticationPolicyId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *deviceAuthenticationPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *deviceAuthenticationPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), + importBlockData = append(importBlockData, mfaDevicePolicyImportBlockData{ + ID: *deviceAuthenticationPolicyId, + Name: *deviceAuthenticationPolicyName, }) } } - return &importBlocks, nil + return importBlockData, nil } -func (r *PingOneMFADevicePolicyResource) ResourceType() string { - return "pingone_mfa_device_policy" +func (r *PingOneMFADevicePolicyResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + importBlocks := []connector.ImportBlock{} + + l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + + importBlockData, err := r.importBlockData() + if err != nil { + return nil, err + } + + l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + + for _, data := range importBlockData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Device Policy ID": data.ID, + "MFA Device Policy Name": data.Name, + "Resource Type": r.ResourceType(), + } + + importBlocks = append(importBlocks, connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: data.Name, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, data.ID), + CommentInformation: common.GenerateCommentInformation(commentData), + }) + } + + return &importBlocks, nil } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go b/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go index baf14c1b..0056ce94 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go @@ -3,6 +3,7 @@ package resources import ( "fmt" + "github.com/patrickcping/pingone-go-sdk-v2/mfa" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -17,6 +18,11 @@ type PingOneMFAFido2PolicyResource struct { clientInfo *connector.PingOneClientInfo } +type mfaFido2PolicyImportBlockData struct { + ID string + Name string +} + // Utility method for creating a PingOneMFAFido2PolicyResource func MFAFido2Policy(clientInfo *connector.PingOneClientInfo) *PingOneMFAFido2PolicyResource { return &PingOneMFAFido2PolicyResource{ @@ -24,47 +30,81 @@ func MFAFido2Policy(clientInfo *connector.PingOneClientInfo) *PingOneMFAFido2Pol } } -func (r *PingOneMFAFido2PolicyResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() +func (r *PingOneMFAFido2PolicyResource) ResourceType() string { + return "pingone_mfa_fido2_policy" +} - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) +func (r *PingOneMFAFido2PolicyResource) fido2Policies() (fido2Policies []mfa.FIDO2Policy, err error) { + fido2Policies = []mfa.FIDO2Policy{} - apiExecuteFunc := r.clientInfo.ApiClient.MFAAPIClient.FIDO2PolicyApi.ReadFIDO2Policies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadFIDO2Policies" + // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application + entityArrayPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.FIDO2PolicyApi.ReadFIDO2Policies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - embedded, err := common.GetMFAEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + allEmbedded, err := common.GetAllMFAEmbedded(entityArrayPagedIterator, "ReadFIDO2Policies", r.ResourceType()) if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + for _, embedded := range allEmbedded { + for _, fido2Policy := range embedded.GetFido2Policies() { + fido2Policies = append(fido2Policies, fido2Policy) + } + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return fido2Policies, nil +} - for _, fido2Policy := range embedded.GetFido2Policies() { +func (r *PingOneMFAFido2PolicyResource) importBlockData() (importBlockData []mfaFido2PolicyImportBlockData, err error) { + importBlockData = []mfaFido2PolicyImportBlockData{} + + fido2Policies, err := r.fido2Policies() + if err != nil { + return nil, err + } + + for _, fido2Policy := range fido2Policies { fido2PolicyName, fido2PolicyNameOk := fido2Policy.GetNameOk() fido2PolicyId, fido2PolicyIdOk := fido2Policy.GetIdOk() if fido2PolicyNameOk && fido2PolicyIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "FIDO2 Policy Name": *fido2PolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "FIDO2 Policy ID": *fido2PolicyId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *fido2PolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *fido2PolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), + importBlockData = append(importBlockData, mfaFido2PolicyImportBlockData{ + ID: *fido2PolicyId, + Name: *fido2PolicyName, }) } } - return &importBlocks, nil + return importBlockData, nil } -func (r *PingOneMFAFido2PolicyResource) ResourceType() string { - return "pingone_mfa_fido2_policy" +func (r *PingOneMFAFido2PolicyResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + importBlocks := []connector.ImportBlock{} + + l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + + importBlockData, err := r.importBlockData() + if err != nil { + return nil, err + } + + l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + + for _, data := range importBlockData { + commentData := map[string]string{ + "Resource Type": r.ResourceType(), + "FIDO2 Policy Name": data.Name, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "FIDO2 Policy ID": data.ID, + } + + importBlocks = append(importBlocks, connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: data.Name, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, data.ID), + CommentInformation: common.GenerateCommentInformation(commentData), + }) + } + + return &importBlocks, nil } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go b/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go index 4979858a..b047e212 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go @@ -22,8 +22,13 @@ func MFASettings(clientInfo *connector.PingOneClientInfo) *PingOneMFASettingsRes } } +func (r *PingOneMFASettingsResource) ResourceType() string { + return "pingone_mfa_settings" +} + func (r *PingOneMFASettingsResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + importBlocks := []connector.ImportBlock{} l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) @@ -33,30 +38,24 @@ func (r *PingOneMFASettingsResource) ExportAll() (*[]connector.ImportBlock, erro return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - if response.StatusCode == 204 { l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) return &importBlocks, nil } + l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + commentData := map[string]string{ - "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), } importBlocks = append(importBlocks, connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: "mfa_settings", + ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), }) return &importBlocks, nil } - -func (r *PingOneMFASettingsResource) ResourceType() string { - return "pingone_mfa_settings" -} From ae26e5ee09e8f464f8d863a1605c9ecc57ec4518 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 26 Nov 2024 10:17:19 -0700 Subject: [PATCH 4/9] Update MFA and Platform resource exports to iter info extraction design --- internal/commands/request/request_internal.go | 1 + internal/connector/common/resources_common.go | 107 +--------- ...pingone_mfa_application_push_credential.go | 173 +++++++--------- .../resources/pingone_mfa_device_policy.go | 106 ++++------ .../mfa/resources/pingone_mfa_fido2_policy.go | 106 ++++------ .../mfa/resources/pingone_mfa_settings.go | 34 ++- .../platform/resources/pingone_agreement.go | 79 ++++--- .../resources/pingone_agreement_enable.go | 36 ++-- .../pingone_agreement_localization.go | 131 +++++++----- .../pingone_agreement_localization_enable.go | 38 ++-- ...pingone_agreement_localization_revision.go | 179 ++++++++++------ .../resources/pingone_branding_settings.go | 47 +++-- .../resources/pingone_branding_theme.go | 87 +++++--- .../pingone_branding_theme_default.go | 101 ++++----- .../platform/resources/pingone_certificate.go | 74 ++++--- .../resources/pingone_custom_domain.go | 80 ++++--- .../platform/resources/pingone_environment.go | 45 ++-- .../platform/resources/pingone_form.go | 80 ++++--- .../resources/pingone_forms_recaptcha_v2.go | 51 +++-- .../platform/resources/pingone_gateway.go | 116 ++++++----- .../resources/pingone_gateway_credential.go | 159 ++++++++------ .../pingone_gateway_role_assignment.go | 171 +++++++++------ .../pingone_identity_propagation_plan.go | 80 ++++--- .../pingone/platform/resources/pingone_key.go | 73 ++++--- .../resources/pingone_key_rotation_policy.go | 80 ++++--- .../platform/resources/pingone_language.go | 90 ++++---- .../resources/pingone_language_update.go | 101 +++++---- .../resources/pingone_notification_policy.go | 80 ++++--- .../pingone_notification_settings.go | 49 +++-- .../pingone_notification_settings_email.go | 63 +++--- .../pingone_notification_template_content.go | 195 ++++++++---------- .../pingone_phone_delivery_settings.go | 134 +++++++----- .../resources/pingone_system_application.go | 110 ++++++---- .../pingone_trusted_email_address.go | 127 ++++++++---- .../resources/pingone_trusted_email_domain.go | 80 ++++--- .../platform/resources/pingone_webhook.go | 80 ++++--- 36 files changed, 1916 insertions(+), 1427 deletions(-) diff --git a/internal/commands/request/request_internal.go b/internal/commands/request/request_internal.go index b39662c5..94d16510 100644 --- a/internal/commands/request/request_internal.go +++ b/internal/commands/request/request_internal.go @@ -105,6 +105,7 @@ func runInternalPingOneRequest(uri string) (err error) { // Note we don't os.Exit(1) here because pingcli has executed // without issue, despite a failed response to the custom request output.UserError("Failed Custom Request", fields) + } else { output.Success("Custom request successful", fields) } diff --git a/internal/connector/common/resources_common.go b/internal/connector/common/resources_common.go index fdc1725d..6dde40fe 100644 --- a/internal/connector/common/resources_common.go +++ b/internal/connector/common/resources_common.go @@ -4,9 +4,6 @@ import ( "fmt" "net/http" - "github.com/patrickcping/pingone-go-sdk-v2/management" - "github.com/patrickcping/pingone-go-sdk-v2/mfa" - "github.com/patrickcping/pingone-go-sdk-v2/risk" "github.com/pingidentity/pingcli/internal/logger" ) @@ -24,7 +21,7 @@ func HandleClientResponse(response *http.Response, err error, apiFunctionName st defer response.Body.Close() - if err != nil || response.StatusCode == 404 || response.StatusCode >= 300 { + if err != nil || response.StatusCode >= 300 || response.StatusCode < 200 { l.Error().Err(err).Msgf("%s Request for resource '%s' was not successful. \nResponse Code: %s\nResponse Body: %s", apiFunctionName, resourceType, response.Status, response.Body) return fmt.Errorf("%s Request for resource '%s' was not successful. \nResponse Code: %s\nResponse Body: %s\n Error: %v", apiFunctionName, resourceType, response.Status, response.Body, err) } @@ -32,102 +29,12 @@ func HandleClientResponse(response *http.Response, err error, apiFunctionName st return nil } -// Iterates through the pagedIterator -// Handles err and response if Client call failed -// // Returns embedded data if not nil -// Treats nil embedded data as an error -func GetAllManagementEmbedded(pagedIterator management.EntityArrayPagedIterator, apiFunctionName string, resourceType string) (allEmbedded []management.EntityArrayEmbedded, err error) { - allEmbedded = []management.EntityArrayEmbedded{} - - for pagedCursor, err := range pagedIterator { - err = HandleClientResponse(pagedCursor.HTTPResponse, err, apiFunctionName, resourceType) - if err != nil { - return nil, err - } - - dataNilErr := fmt.Errorf("failed to create resource '%s' import blocks.\n"+ - "PingOne API request for resource '%s' was not successful. response data is nil.\n"+ - "response code: %s\n"+ - "response body: %s", - resourceType, resourceType, pagedCursor.HTTPResponse.Status, pagedCursor.HTTPResponse.Body) - - if pagedCursor.EntityArray == nil { - return nil, dataNilErr - } - - embedded, embeddedOk := pagedCursor.EntityArray.GetEmbeddedOk() - if !embeddedOk { - return nil, dataNilErr - } - - allEmbedded = append(allEmbedded, *embedded) - } - - return allEmbedded, nil -} - -// Executes the function apiExecuteFunc for the MFAAPIClient -// Handles err and response if Client call failed -// Returns embedded data if not nil -// Treats nil embedded data as an error -func GetAllMFAEmbedded(pagedIterator mfa.EntityArrayPagedIterator, apiFunctionName string, resourceType string) (allEmbedded []mfa.EntityArrayEmbedded, err error) { - allEmbedded = []mfa.EntityArrayEmbedded{} - - for pagedCursor, err := range pagedIterator { - err = HandleClientResponse(pagedCursor.HTTPResponse, err, apiFunctionName, resourceType) - if err != nil { - return nil, err - } - - dataNilErr := fmt.Errorf("failed to create resource '%s' import blocks.\n"+ - "PingOne API request for resource '%s' was not successful. response data is nil.\n"+ - "response code: %s\n"+ - "response body: %s", - resourceType, resourceType, pagedCursor.HTTPResponse.Status, pagedCursor.HTTPResponse.Body) - - if pagedCursor.EntityArray == nil { - return nil, dataNilErr - } - - embedded, embeddedOk := pagedCursor.EntityArray.GetEmbeddedOk() - if !embeddedOk { - return nil, dataNilErr - } - - allEmbedded = append(allEmbedded, *embedded) - } - - return allEmbedded, nil -} - -// Executes the function apiExecuteFunc for the RiskAPIClient -// Handles err and response if Client call failed -// Returns embedded data if not nil -// Treats nil embedded data as an error -func GetProtectEmbedded(apiExecuteFunc func() (*risk.EntityArray, *http.Response, error), apiFunctionName string, resourceType string) (*risk.EntityArrayEmbedded, error) { - l := logger.Get() - - entityArray, response, err := apiExecuteFunc() - - err = HandleClientResponse(response, err, apiFunctionName, resourceType) - if err != nil { - return nil, err - } - - if entityArray == nil { - l.Error().Msgf("Returned %s() entityArray is nil.", apiFunctionName) - l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) - return nil, fmt.Errorf("failed to fetch %s resources via %s()", resourceType, apiFunctionName) - } - - embedded, embeddedOk := entityArray.GetEmbeddedOk() - if !embeddedOk { - l.Error().Msgf("Returned %s() embedded data is nil.", apiFunctionName) - l.Error().Msgf("%s Response Code: %s\nResponse Body: %s", apiFunctionName, response.Status, response.Body) - return nil, fmt.Errorf("failed to fetch %s resources via %s()", resourceType, apiFunctionName) - } - - return embedded, nil +func DataNilError(resourceType string, response *http.Response) error { + return fmt.Errorf("failed to export resource '%s'.\n"+ + "PingOne API request for resource '%s' was not successful. response data is nil.\n"+ + "response code: %s\n"+ + "response body: %s", + resourceType, resourceType, response.Status, response.Body) } func GenerateCommentInformation(data map[string]string) string { diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go index f9b8f1df..b4744b64 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/patrickcping/pingone-go-sdk-v2/management" - "github.com/patrickcping/pingone-go-sdk-v2/mfa" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -16,20 +15,15 @@ var ( ) type PingOneMFAApplicationPushCredentialResource struct { - clientInfo *connector.PingOneClientInfo -} - -type mfaApplicationPushCredentialImportBlockData struct { - PushCredentialID string - PushCredentialType string - NativeOIDCApplicationID string - NativeOIDCApplicationName string + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneMFAApplicationPushCredentialResource func MFAApplicationPushCredential(clientInfo *connector.PingOneClientInfo) *PingOneMFAApplicationPushCredentialResource { return &PingOneMFAApplicationPushCredentialResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } @@ -37,119 +31,106 @@ func (r *PingOneMFAApplicationPushCredentialResource) ResourceType() string { return "pingone_mfa_application_push_credential" } -func (r *PingOneMFAApplicationPushCredentialResource) nativeOIDCApplications() (nativeOIDCApplications []*management.ApplicationOIDC, err error) { - nativeOIDCApplications = []*management.ApplicationOIDC{} - - // Fetch all pingone_application resources that could have pingone_mfa_application_push_credentials - entityArrayPagedIterator := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() +func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - allEmbedded, err := common.GetAllManagementEmbedded(entityArrayPagedIterator, "ReadAllApplications", "pingone_application") + err := r.exportPushCreds() if err != nil { return nil, err } - // pingone_mfa_application_push_credential are for Native applications only - // Native application authenticate with OIDC only - for _, embedded := range allEmbedded { - for _, readOneApplication200Response := range embedded.GetApplications() { - if readOneApplication200Response.ApplicationOIDC != nil { - appType, appTypeOk := readOneApplication200Response.ApplicationOIDC.GetTypeOk() - if appTypeOk && *appType == management.ENUMAPPLICATIONTYPE_NATIVE_APP { - nativeOIDCApplications = append(nativeOIDCApplications, readOneApplication200Response.ApplicationOIDC) - } - } - } - } - - return nativeOIDCApplications, nil + return r.importBlocks, nil } -func (r *PingOneMFAApplicationPushCredentialResource) pushCredentialResponses(nativeOIDCApplicationId *string) (mfaPushCredentialResponses []mfa.MFAPushCredentialResponse, err error) { - mfaPushCredentialResponses = []mfa.MFAPushCredentialResponse{} +func (r *PingOneMFAApplicationPushCredentialResource) exportPushCreds() error { + // Fetch all pingone_application resources that could have pingone_mfa_application_push_credentials + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application - entityArrayPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *nativeOIDCApplicationId).Execute() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", "pingone_application") + if err != nil { + return err + } - allEmbedded, err := common.GetAllMFAEmbedded(entityArrayPagedIterator, "ReadAllMFAPushCredentials", r.ResourceType()) - if err != nil { - return nil, err - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, embedded := range allEmbedded { - for _, mfaPushCredentialResponse := range embedded.GetPushCredentials() { - mfaPushCredentialResponses = append(mfaPushCredentialResponses, mfaPushCredentialResponse) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, app := range embedded.GetApplications() { + // MFa application push credentials are only for OIDC Native Apps + if app.ApplicationOIDC != nil { + appId, appIdOk := app.ApplicationOIDC.GetIdOk() + appName, appNameOk := app.ApplicationOIDC.GetNameOk() + appType, appTypeOk := app.ApplicationOIDC.GetTypeOk() + + if appIdOk && appNameOk && appTypeOk { + if *appType == management.ENUMAPPLICATIONTYPE_NATIVE_APP { + err := r.exportPushCredsByApp(*appId, *appName) + if err != nil { + return err + } + } + } + } } } - return mfaPushCredentialResponses, nil + return nil } -func (r *PingOneMFAApplicationPushCredentialResource) importBlockData() (importBlockData []mfaApplicationPushCredentialImportBlockData, err error) { - importBlockData = []mfaApplicationPushCredentialImportBlockData{} +func (r *PingOneMFAApplicationPushCredentialResource) exportPushCredsByApp(appId, appName string) error { + iter := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() - nativeOIDCApplications, err := r.nativeOIDCApplications() - if err != nil { - return nil, err - } + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllMFAPushCredentials", r.ResourceType()) + if err != nil { + return err + } - for _, nativeOIDCApplication := range nativeOIDCApplications { - nativeOIDCApplicationId, nativeOIDCApplicationIdOk := nativeOIDCApplication.GetIdOk() - nativeOIDCApplicationName, nativeOIDCApplicationNameOk := nativeOIDCApplication.GetNameOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if nativeOIDCApplicationIdOk && nativeOIDCApplicationNameOk { - mfaPushCredentialResponses, err := r.pushCredentialResponses(nativeOIDCApplicationId) - if err != nil { - return nil, err - } + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, mfaPushCredentialResponse := range mfaPushCredentialResponses { - mfaPushCredentialResponseType, mfaPushCredentialResponseTypeOk := mfaPushCredentialResponse.GetTypeOk() - mfaPushCredentialResponseId, mfaPushCredentialResponseIdOk := mfaPushCredentialResponse.GetIdOk() - if mfaPushCredentialResponseTypeOk && mfaPushCredentialResponseIdOk { - importBlockData = append(importBlockData, mfaApplicationPushCredentialImportBlockData{ - PushCredentialID: *mfaPushCredentialResponseId, - PushCredentialType: string(*mfaPushCredentialResponseType), - NativeOIDCApplicationID: *nativeOIDCApplicationId, - NativeOIDCApplicationName: *nativeOIDCApplicationName, - }) - } + for _, pushCred := range embedded.GetPushCredentials() { + pushCredId, pushCredIdOk := pushCred.GetIdOk() + pushCredType, pushCredTypeOk := pushCred.GetTypeOk() + + if pushCredIdOk && pushCredTypeOk { + r.addImportBlock(appId, appName, *pushCredId, string(*pushCredType)) } } } - return importBlockData, nil + return nil } -func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - importBlockData, err := r.importBlockData() - if err != nil { - return nil, err +func (r *PingOneMFAApplicationPushCredentialResource) addImportBlock(appId, appName, pushCredId, pushCredType string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Application Push Credential ID": pushCredId, + "MFA Application Push Credential Type": pushCredType, + "Native OIDC Application ID": appId, + "Native OIDC Application Name": appName, + "Resource Type": r.ResourceType(), } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, data := range importBlockData { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "MFA Application Push Credential ID": data.PushCredentialID, - "MFA Application Push Credential Type": data.PushCredentialType, - "Native Application (OpenID Connect) ID": data.NativeOIDCApplicationID, - "Native Application (OpenID Connect) Name": data.NativeOIDCApplicationName, - "Resource Type": r.ResourceType(), - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", data.NativeOIDCApplicationName, data.PushCredentialType), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, data.NativeOIDCApplicationID, data.PushCredentialID), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, pushCredType), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, pushCredId), + CommentInformation: common.GenerateCommentInformation(commentData), } - return &importBlocks, nil + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go b/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go index 8ce8eed4..35bf0578 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go @@ -3,7 +3,6 @@ package resources import ( "fmt" - "github.com/patrickcping/pingone-go-sdk-v2/mfa" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -15,18 +14,15 @@ var ( ) type PingOneMFADevicePolicyResource struct { - clientInfo *connector.PingOneClientInfo -} - -type mfaDevicePolicyImportBlockData struct { - ID string - Name string + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneMFADevicePolicyResource func MFADevicePolicy(clientInfo *connector.PingOneClientInfo) *PingOneMFADevicePolicyResource { return &PingOneMFADevicePolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } @@ -34,77 +30,63 @@ func (r *PingOneMFADevicePolicyResource) ResourceType() string { return "pingone_mfa_device_policy" } -func (r *PingOneMFADevicePolicyResource) deviceAuthenticationPolicies() (deviceAuthenticationPolicies []mfa.DeviceAuthenticationPolicy, err error) { - deviceAuthenticationPolicies = []mfa.DeviceAuthenticationPolicy{} - - // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application - entityArrayPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.DeviceAuthenticationPolicyApi.ReadDeviceAuthenticationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() +func (r *PingOneMFADevicePolicyResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - allEmbedded, err := common.GetAllMFAEmbedded(entityArrayPagedIterator, "ReadDeviceAuthenticationPolicies", r.ResourceType()) + err := r.exportDevicePolicies() if err != nil { return nil, err } - for _, embedded := range allEmbedded { - for _, deviceAuthenticationPolicy := range embedded.GetDeviceAuthenticationPolicies() { - deviceAuthenticationPolicies = append(deviceAuthenticationPolicies, deviceAuthenticationPolicy) - } - } - - return deviceAuthenticationPolicies, nil + return r.importBlocks, nil } -func (r *PingOneMFADevicePolicyResource) importBlockData() (importBlockData []mfaDevicePolicyImportBlockData, err error) { - importBlockData = []mfaDevicePolicyImportBlockData{} - - deviceAuthenticationPolicies, err := r.deviceAuthenticationPolicies() - if err != nil { - return nil, err - } - - for _, deviceAuthenticationPolicy := range deviceAuthenticationPolicies { - deviceAuthenticationPolicyName, deviceAuthenticationPolicyNameOk := deviceAuthenticationPolicy.GetNameOk() - deviceAuthenticationPolicyId, deviceAuthenticationPolicyIdOk := deviceAuthenticationPolicy.GetIdOk() +func (r *PingOneMFADevicePolicyResource) exportDevicePolicies() error { + iter := r.clientInfo.ApiClient.MFAAPIClient.DeviceAuthenticationPolicyApi.ReadDeviceAuthenticationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - if deviceAuthenticationPolicyNameOk && deviceAuthenticationPolicyIdOk { - importBlockData = append(importBlockData, mfaDevicePolicyImportBlockData{ - ID: *deviceAuthenticationPolicyId, - Name: *deviceAuthenticationPolicyName, - }) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadDeviceAuthenticationPolicies", r.ResourceType()) + if err != nil { + return err } - } - return importBlockData, nil -} + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } -func (r *PingOneMFADevicePolicyResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() - importBlocks := []connector.ImportBlock{} + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + for _, devicePolicy := range embedded.GetDeviceAuthenticationPolicies() { + devicePolicyId, devicePolicyIdOk := devicePolicy.GetIdOk() + devicePolicyName, devicePolicyNameOk := devicePolicy.GetNameOk() - importBlockData, err := r.importBlockData() - if err != nil { - return nil, err + if devicePolicyIdOk && devicePolicyNameOk { + r.addImportBlock(*devicePolicyId, *devicePolicyName) + } + } } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return nil +} - for _, data := range importBlockData { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "MFA Device Policy ID": data.ID, - "MFA Device Policy Name": data.Name, - "Resource Type": r.ResourceType(), - } +func (r *PingOneMFADevicePolicyResource) addImportBlock(devicePolicyId, devicePolicyName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Device Policy ID": devicePolicyId, + "MFA Device Policy Name": devicePolicyName, + "Resource Type": r.ResourceType(), + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: data.Name, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, data.ID), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: devicePolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, devicePolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), } - return &importBlocks, nil + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go b/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go index 0056ce94..747cb744 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go @@ -3,7 +3,6 @@ package resources import ( "fmt" - "github.com/patrickcping/pingone-go-sdk-v2/mfa" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -15,18 +14,15 @@ var ( ) type PingOneMFAFido2PolicyResource struct { - clientInfo *connector.PingOneClientInfo -} - -type mfaFido2PolicyImportBlockData struct { - ID string - Name string + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneMFAFido2PolicyResource func MFAFido2Policy(clientInfo *connector.PingOneClientInfo) *PingOneMFAFido2PolicyResource { return &PingOneMFAFido2PolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } @@ -34,77 +30,63 @@ func (r *PingOneMFAFido2PolicyResource) ResourceType() string { return "pingone_mfa_fido2_policy" } -func (r *PingOneMFAFido2PolicyResource) fido2Policies() (fido2Policies []mfa.FIDO2Policy, err error) { - fido2Policies = []mfa.FIDO2Policy{} - - // Fetch all pingone_mfa_application_push_credentials resources for the given pingone_application - entityArrayPagedIterator := r.clientInfo.ApiClient.MFAAPIClient.FIDO2PolicyApi.ReadFIDO2Policies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() +func (r *PingOneMFAFido2PolicyResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - allEmbedded, err := common.GetAllMFAEmbedded(entityArrayPagedIterator, "ReadFIDO2Policies", r.ResourceType()) + err := r.exportFido2Policies() if err != nil { return nil, err } - for _, embedded := range allEmbedded { - for _, fido2Policy := range embedded.GetFido2Policies() { - fido2Policies = append(fido2Policies, fido2Policy) - } - } - - return fido2Policies, nil + return r.importBlocks, nil } -func (r *PingOneMFAFido2PolicyResource) importBlockData() (importBlockData []mfaFido2PolicyImportBlockData, err error) { - importBlockData = []mfaFido2PolicyImportBlockData{} - - fido2Policies, err := r.fido2Policies() - if err != nil { - return nil, err - } - - for _, fido2Policy := range fido2Policies { - fido2PolicyName, fido2PolicyNameOk := fido2Policy.GetNameOk() - fido2PolicyId, fido2PolicyIdOk := fido2Policy.GetIdOk() +func (r *PingOneMFAFido2PolicyResource) exportFido2Policies() error { + iter := r.clientInfo.ApiClient.MFAAPIClient.FIDO2PolicyApi.ReadFIDO2Policies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - if fido2PolicyNameOk && fido2PolicyIdOk { - importBlockData = append(importBlockData, mfaFido2PolicyImportBlockData{ - ID: *fido2PolicyId, - Name: *fido2PolicyName, - }) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadFIDO2Policies", r.ResourceType()) + if err != nil { + return err } - } - return importBlockData, nil -} + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } -func (r *PingOneMFAFido2PolicyResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() - importBlocks := []connector.ImportBlock{} + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + for _, fido2Policy := range embedded.GetFido2Policies() { + fido2PolicyId, fido2PolicyIdOk := fido2Policy.GetIdOk() + fido2PolicyName, fido2PolicyNameOk := fido2Policy.GetNameOk() - importBlockData, err := r.importBlockData() - if err != nil { - return nil, err + if fido2PolicyIdOk && fido2PolicyNameOk { + r.addImportBlock(*fido2PolicyId, *fido2PolicyName) + } + } } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return nil +} - for _, data := range importBlockData { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "FIDO2 Policy Name": data.Name, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "FIDO2 Policy ID": data.ID, - } +func (r *PingOneMFAFido2PolicyResource) addImportBlock(fido2PolicyId, fido2PolicyName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "FIDO2 Policy ID": fido2PolicyId, + "FIDO2 Policy Name": fido2PolicyName, + "Resource Type": r.ResourceType(), + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: data.Name, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, data.ID), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fido2PolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, fido2PolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), } - return &importBlocks, nil + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go b/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go index b047e212..e372873d 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go @@ -12,13 +12,15 @@ var ( ) type PingOneMFASettingsResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneMFASettingsResource func MFASettings(clientInfo *connector.PingOneClientInfo) *PingOneMFASettingsResource { return &PingOneMFASettingsResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } @@ -28,34 +30,44 @@ func (r *PingOneMFASettingsResource) ResourceType() string { func (r *PingOneMFASettingsResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() - importBlocks := []connector.ImportBlock{} + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + err := r.exportMFASettings() + if err != nil { + return nil, err + } + + return r.importBlocks, nil +} +func (r *PingOneMFASettingsResource) exportMFASettings() error { _, response, err := r.clientInfo.ApiClient.MFAAPIClient.MFASettingsApi.ReadMFASettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "ReadMFASettings", r.ResourceType()) if err != nil { - return nil, err + return err } if response.StatusCode == 204 { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil + return common.DataNilError(r.ResourceType(), response) } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + r.addImportBlock() + + return nil +} +func (r *PingOneMFASettingsResource) addImportBlock() { commentData := map[string]string{ "Export Environment ID": r.clientInfo.ExportEnvironmentID, "Resource Type": r.ResourceType(), } - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), - }) + } - return &importBlocks, nil + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement.go b/internal/connector/pingone/platform/resources/pingone_agreement.go index 4066b37f..86f76c53 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement.go @@ -14,56 +14,79 @@ var ( ) type PingOneAgreementResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneAgreementResource func Agreement(clientInfo *connector.PingOneClientInfo) *PingOneAgreementResource { return &PingOneAgreementResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneAgreementResource) ResourceType() string { + return "pingone_agreement" +} + func (r *PingOneAgreementResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllAgreements" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportAgreements() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneAgreementResource) exportAgreements() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreements", r.ResourceType()) + if err != nil { + return err + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - for _, agreement := range embedded.GetAgreements() { - agreementId, agreementIdOk := agreement.GetIdOk() - agreementName, agreementNameOk := agreement.GetNameOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Agreement Resource Name": *agreementName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Agreement Resource ID": *agreementId, + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if agreementIdOk && agreementNameOk { - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *agreementName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *agreementId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + for _, agreement := range embedded.GetAgreements() { + agreementId, agreementIdOk := agreement.GetIdOk() + agreementName, agreementNameOk := agreement.GetNameOk() + + if agreementIdOk && agreementNameOk { + r.addImportBlock(*agreementId, *agreementName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneAgreementResource) ResourceType() string { - return "pingone_agreement" +func (r *PingOneAgreementResource) addImportBlock(agreementId, agreementName string) { + commentData := map[string]string{ + "Agreement ID": agreementId, + "Agreement Name": agreementName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: agreementName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, agreementId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_enable.go b/internal/connector/pingone/platform/resources/pingone_agreement_enable.go index c72db9a2..880e1263 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_enable.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_enable.go @@ -13,42 +13,50 @@ var ( ) type PingOneAgreementEnableResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneAgreementEnableResource func AgreementEnable(clientInfo *connector.PingOneClientInfo) *PingOneAgreementEnableResource { return &PingOneAgreementEnableResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneAgreementEnableResource) ResourceType() string { + return "pingone_agreement_enable" +} + func (r *PingOneAgreementEnableResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all pingone_agreement_enable resources...") - - agreementImportBlocks, err := Agreement(r.clientInfo).ExportAll() + err := r.exportAgreementEnables() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all pingone_agreement_enable resources...") +func (r *PingOneAgreementEnableResource) exportAgreementEnables() error { + agreementImportBlocks, err := Agreement(r.clientInfo).ExportAll() + if err != nil { + return err + } for _, importBlock := range *agreementImportBlocks { - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock = connector.ImportBlock{ ResourceType: r.ResourceType(), ResourceName: fmt.Sprintf("%s_enable", importBlock.ResourceName), ResourceID: importBlock.ResourceID, CommentInformation: importBlock.CommentInformation, - }) - } + } - return &importBlocks, nil -} + *r.importBlocks = append(*r.importBlocks, importBlock) + } -func (r *PingOneAgreementEnableResource) ResourceType() string { - return "pingone_agreement_enable" + return nil } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization.go index cfbfd7d1..91db92f7 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization.go @@ -14,78 +14,117 @@ var ( ) type PingOneAgreementLocalizationResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneAgreementLocalizationResource func AgreementLocalization(clientInfo *connector.PingOneClientInfo) *PingOneAgreementLocalizationResource { return &PingOneAgreementLocalizationResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneAgreementLocalizationResource) ResourceType() string { + return "pingone_agreement_localization" +} + func (r *PingOneAgreementLocalizationResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllAgreements" - - agreementEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportAgreementLocalizations() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizations() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreements", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, agreement := range agreementEmbedded.GetAgreements() { - agreementId, agreementIdOk := agreement.GetIdOk() - agreementName, agreementNameOk := agreement.GetNameOk() + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if agreementIdOk && agreementNameOk { - apiExecuteFunc = r.clientInfo.ApiClient.ManagementAPIClient.AgreementLanguagesResourcesApi.ReadAllAgreementLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *agreement.Id).Execute - apiFunctionName = "ReadAllAgreementLanguages" + for _, agreement := range embedded.GetAgreements() { + agreementId, agreementIdOk := agreement.GetIdOk() + agreementName, agreementNameOk := agreement.GetNameOk() - agreementLanguageEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err + if agreementIdOk && agreementNameOk { + err := r.exportAgreementLocalizationsByAgreement(*agreementId, *agreementName) + if err != nil { + return err + } } + } + } - for _, languageWrapper := range agreementLanguageEmbedded.GetLanguages() { - if languageWrapper.AgreementLanguage != nil { - agreementLanguage := languageWrapper.AgreementLanguage - - agreementLanguageLocale, agreementLanguageLocaleOk := agreementLanguage.GetLocaleOk() - agreementLanguageId, agreementLanguageIdOk := agreementLanguage.GetIdOk() - - if agreementLanguageLocaleOk && agreementLanguageIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Agreement Name": *agreementName, - "Agreement Language Locale": *agreementLanguageLocale, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Agreement ID": *agreementId, - "Agreement Language ID": *agreementLanguageId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *agreementName, *agreementLanguageLocale), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *agreementId, *agreementLanguageId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } + return nil +} + +func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizationsByAgreement(agreementId, agreementName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementLanguagesResourcesApi.ReadAllAgreementLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, agreementId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreementLanguages", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, languageInner := range embedded.GetLanguages() { + if languageInner.AgreementLanguage == nil { + agreementLanguageId, agreementLanguageIdOk := languageInner.AgreementLanguage.GetIdOk() + agreementLanguageLocale, agreementLanguageLocaleOk := languageInner.AgreementLanguage.GetLocaleOk() + + if agreementLanguageIdOk && agreementLanguageLocaleOk { + r.addImportBlock(agreementId, agreementName, *agreementLanguageId, *agreementLanguageLocale) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneAgreementLocalizationResource) ResourceType() string { - return "pingone_agreement_localization" +func (r *PingOneAgreementLocalizationResource) addImportBlock(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale string) { + commentData := map[string]string{ + "Agreement ID": agreementId, + "Agreement Language ID": agreementLanguageId, + "Agreement Language Locale": agreementLanguageLocale, + "Agreement Name": agreementName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", agreementName, agreementLanguageLocale), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go index bb97939e..04501064 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go @@ -13,42 +13,50 @@ var ( ) type PingOneAgreementLocalizationEnableResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneAgreementLocalizationEnableResource func AgreementLocalizationEnable(clientInfo *connector.PingOneClientInfo) *PingOneAgreementLocalizationEnableResource { return &PingOneAgreementLocalizationEnableResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneAgreementLocalizationEnableResource) ResourceType() string { + return "pingone_agreement_localization_enable" +} + func (r *PingOneAgreementLocalizationEnableResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all pingone_agreement_localization_enable resources...") - - localizationImportBlocks, err := AgreementLocalization(r.clientInfo).ExportAll() + err := r.exportAgreementLocalizationEnables() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all pingone_agreement_localization_enable resources...") +func (r *PingOneAgreementLocalizationEnableResource) exportAgreementLocalizationEnables() error { + agreementLocalizationImportBlocks, err := AgreementLocalization(r.clientInfo).ExportAll() + if err != nil { + return err + } - for _, importBlock := range *localizationImportBlocks { - importBlocks = append(importBlocks, connector.ImportBlock{ + for _, importBlock := range *agreementLocalizationImportBlocks { + importBlock = connector.ImportBlock{ ResourceType: r.ResourceType(), ResourceName: fmt.Sprintf("%s_enable", importBlock.ResourceName), ResourceID: importBlock.ResourceID, CommentInformation: importBlock.CommentInformation, - }) - } + } - return &importBlocks, nil -} + *r.importBlocks = append(*r.importBlocks, importBlock) + } -func (r *PingOneAgreementLocalizationEnableResource) ResourceType() string { - return "pingone_agreement_localization_enable" + return nil } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go index 82093bcd..8e1fd7a6 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go @@ -14,92 +14,151 @@ var ( ) type PingOneAgreementLocalizationRevisionResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneAgreementLocalizationRevisionResource func AgreementLocalizationRevision(clientInfo *connector.PingOneClientInfo) *PingOneAgreementLocalizationRevisionResource { return &PingOneAgreementLocalizationRevisionResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneAgreementLocalizationRevisionResource) ResourceType() string { + return "pingone_agreement_localization_revision" +} + func (r *PingOneAgreementLocalizationRevisionResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllAgreements" - - agreementEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportAgreementLocalizationRevisions() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizationRevisions() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreements", r.ResourceType()) + if err != nil { + return err + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - for _, agreement := range agreementEmbedded.GetAgreements() { - agreementId, agreementIdOk := agreement.GetIdOk() - agreementName, agreementNameOk := agreement.GetNameOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if agreementIdOk && agreementNameOk { - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.AgreementLanguagesResourcesApi.ReadAllAgreementLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *agreement.Id).Execute - apiFunctionName := "ReadAllAgreementLanguages" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - agreementLanguageEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, agreement := range embedded.GetAgreements() { + agreementId, agreementIdOk := agreement.GetIdOk() + agreementName, agreementNameOk := agreement.GetNameOk() + + if agreementIdOk && agreementNameOk { + err := r.exportAgreementLocalizationRevisionsByAgreement(*agreementId, *agreementName) + if err != nil { + return err + } } + } + } + + return nil +} + +func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizationRevisionsByAgreement(agreementId, agreementName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementLanguagesResourcesApi.ReadAllAgreementLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, agreementId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreementLanguages", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, languageWrapper := range agreementLanguageEmbedded.GetLanguages() { - if languageWrapper.AgreementLanguage != nil { - agreementLanguage := languageWrapper.AgreementLanguage - - agreementLanguageLocale, agreementLanguageLocaleOk := agreementLanguage.GetLocaleOk() - agreementLanguageId, agreementLanguageIdOk := agreementLanguage.GetIdOk() - - if agreementLanguageLocaleOk && agreementLanguageIdOk { - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.AgreementRevisionsResourcesApi.ReadAllAgreementLanguageRevisions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *agreementId, *agreementLanguageId).Execute - apiFunctionName := "ReadAllAgreementLanguageRevisions" - - agreementLanguageRevisionEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } - - for revisionIndex, revision := range agreementLanguageRevisionEmbedded.GetRevisions() { - revisionId, revisionIdOk := revision.GetIdOk() - - if revisionIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Agreement Name": *agreementName, - "Agreement Language Locale": *agreementLanguageLocale, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Agreement ID": *agreementId, - "Agreement Language ID": *agreementLanguageId, - "Agreement Localization Revision ID": *revisionId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%d", *agreementName, *agreementLanguageLocale, (revisionIndex + 1)), - ResourceID: fmt.Sprintf("%s/%s/%s/%s", r.clientInfo.ExportEnvironmentID, *agreementId, *agreementLanguageId, *revisionId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } - } + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, languageInner := range embedded.GetLanguages() { + if languageInner.AgreementLanguage != nil { + agreementLanguageLocale, agreementLanguageLocaleOk := languageInner.AgreementLanguage.GetLocaleOk() + agreementLanguageId, agreementLanguageIdOk := languageInner.AgreementLanguage.GetIdOk() + + if agreementLanguageLocaleOk && agreementLanguageIdOk { + err := r.exportAgreementLocalizationRevisionsByAgreementLanguage(agreementId, agreementName, *agreementLanguageId, *agreementLanguageLocale) + if err != nil { + return err } } } } } - return &importBlocks, nil + return nil } -func (r *PingOneAgreementLocalizationRevisionResource) ResourceType() string { - return "pingone_agreement_localization_revision" +func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizationRevisionsByAgreementLanguage(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementRevisionsResourcesApi.ReadAllAgreementLanguageRevisions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreementLanguageRevisions", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, revision := range embedded.GetRevisions() { + agreementLanguageRevisionId, agreementLanguageRevisionIdOk := revision.GetIdOk() + + if agreementLanguageRevisionIdOk { + r.addImportBlock(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale, *agreementLanguageRevisionId) + } + } + } + + return nil +} + +func (r *PingOneAgreementLocalizationRevisionResource) addImportBlock(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale, agreementLanguageRevisionId string) { + commentData := map[string]string{ + "Agreement ID": agreementId, + "Agreement Language ID": agreementLanguageId, + "Agreement Language Locale": agreementLanguageLocale, + "Agreement Localization Revision ID": agreementLanguageRevisionId, + "Agreement Name": agreementName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", agreementName, agreementLanguageLocale, agreementLanguageRevisionId), + ResourceID: fmt.Sprintf("%s/%s/%s/%s", r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId, agreementLanguageRevisionId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_settings.go b/internal/connector/pingone/platform/resources/pingone_branding_settings.go index cc2cf214..62c5bc62 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_settings.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_settings.go @@ -12,51 +12,62 @@ var ( ) type PingOneBrandingSettingsResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneBrandingSettingsResource func BrandingSettings(clientInfo *connector.PingOneClientInfo) *PingOneBrandingSettingsResource { return &PingOneBrandingSettingsResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneBrandingSettingsResource) ResourceType() string { + return "pingone_branding_settings" +} + func (r *PingOneBrandingSettingsResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.BrandingSettingsApi.ReadBrandingSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - err = common.HandleClientResponse(response, err, "ReadBrandingSettings", r.ResourceType()) + err := r.exportBrandingSettings() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneBrandingSettingsResource) exportBrandingSettings() error { + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.BrandingSettingsApi.ReadBrandingSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + err = common.HandleClientResponse(response, err, "ReadBrandingSettings", r.ResourceType()) + if err != nil { + return err + } if response.StatusCode == 204 { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil + return common.DataNilError(r.ResourceType(), response) } + r.addImportBlock() + + return nil +} + +func (r *PingOneBrandingSettingsResource) addImportBlock() { commentData := map[string]string{ "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, } - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: "branding_settings", + ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), - }) - - return &importBlocks, nil -} + } -func (r *PingOneBrandingSettingsResource) ResourceType() string { - return "pingone_branding_settings" + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_theme.go b/internal/connector/pingone/platform/resources/pingone_branding_theme.go index 147cd2ae..b366dca1 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_theme.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_theme.go @@ -14,62 +14,83 @@ var ( ) type PingOneBrandingThemeResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneBrandingThemeResource func BrandingTheme(clientInfo *connector.PingOneClientInfo) *PingOneBrandingThemeResource { return &PingOneBrandingThemeResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneBrandingThemeResource) ResourceType() string { + return "pingone_branding_theme" +} + func (r *PingOneBrandingThemeResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.BrandingThemesApi.ReadBrandingThemes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadBrandingThemes" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportBrandingThemes() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneBrandingThemeResource) exportBrandingThemes() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.BrandingThemesApi.ReadBrandingThemes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, theme := range embedded.GetThemes() { - themeId, themeIdOk := theme.GetIdOk() - themeConfiguration, themeConfigurationOk := theme.GetConfigurationOk() - var themeName *string - var themeNameOk = false - if themeConfigurationOk { - themeName, themeNameOk = themeConfiguration.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadBrandingThemes", r.ResourceType()) + if err != nil { + return err } - if themeIdOk && themeConfigurationOk && themeNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Branding Theme Name": *themeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Branding Theme ID": *themeId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, brandingTheme := range embedded.GetThemes() { + brandingThemeId, brandingThemeIdOk := brandingTheme.GetIdOk() + brandingThemeConfiguration, brandingThemeConfigurationOk := brandingTheme.GetConfigurationOk() + + if brandingThemeIdOk && brandingThemeConfigurationOk { + brandingThemeName, brandingThemeNameOk := brandingThemeConfiguration.GetNameOk() - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *themeName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *themeId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if brandingThemeNameOk { + r.addImportBlock(*brandingThemeId, *brandingThemeName) + } + } } } - return &importBlocks, nil + return nil } -func (r *PingOneBrandingThemeResource) ResourceType() string { - return "pingone_branding_theme" +func (r *PingOneBrandingThemeResource) addImportBlock(brandingThemeId, brandingThemeName string) { + commentData := map[string]string{ + "Branding Theme ID": brandingThemeId, + "Branding Theme Name": brandingThemeName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: brandingThemeName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, brandingThemeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go b/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go index c3763087..87b7751a 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go @@ -1,9 +1,6 @@ package resources import ( - "fmt" - - "github.com/patrickcping/pingone-go-sdk-v2/management" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -15,75 +12,85 @@ var ( ) type PingOneBrandingThemeDefaultResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneBrandingThemeDefaultResource func BrandingThemeDefault(clientInfo *connector.PingOneClientInfo) *PingOneBrandingThemeDefaultResource { return &PingOneBrandingThemeDefaultResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneBrandingThemeDefaultResource) ResourceType() string { + return "pingone_branding_theme_default" +} + func (r *PingOneBrandingThemeDefaultResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.BrandingThemesApi.ReadBrandingThemes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadBrandingThemes" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportBrandingThemeDefault() if err != nil { return nil, err } - foundDefault := false - var defaultBrandingTheme management.BrandingTheme + return r.importBlocks, nil +} + +func (r *PingOneBrandingThemeDefaultResource) exportBrandingThemeDefault() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.BrandingThemesApi.ReadBrandingThemes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, brandingTheme := range embedded.GetThemes() { - if brandingTheme.GetDefault() { - foundDefault = true - defaultBrandingTheme = brandingTheme - break + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadBrandingThemes", r.ResourceType()) + if err != nil { + return err } - } - if !foundDefault { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &[]connector.ImportBlock{}, nil - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks := []connector.ImportBlock{} + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for _, brandingTheme := range embedded.GetThemes() { + brandingThemeDefault, brandingThemeDefaultOk := brandingTheme.GetDefaultOk() - defaultBrandingThemeConfiguration, defaultBrandingThemeConfigurationOk := defaultBrandingTheme.GetConfigurationOk() - var ( - defaultBrandingThemeName *string - defaultBrandingThemeNameOk = false - ) - if defaultBrandingThemeConfigurationOk { - defaultBrandingThemeName, defaultBrandingThemeNameOk = defaultBrandingThemeConfiguration.GetNameOk() - } + if brandingThemeDefaultOk && *brandingThemeDefault { + brandingThemeConfiguration, brandingThemeConfigurationOk := brandingTheme.GetConfigurationOk() - if defaultBrandingThemeConfigurationOk && defaultBrandingThemeNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - } + if brandingThemeConfigurationOk { + brandingThemeName, brandingThemeNameOk := brandingThemeConfiguration.GetNameOk() - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_default_theme", *defaultBrandingThemeName), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if brandingThemeNameOk { + r.addImportBlock(*brandingThemeName) + } + } + } + } } - return &importBlocks, nil + return nil } -func (r *PingOneBrandingThemeDefaultResource) ResourceType() string { - return "pingone_branding_theme_default" +func (r *PingOneBrandingThemeDefaultResource) addImportBlock(brandingThemeName string) { + commentData := map[string]string{ + "Default Branding Theme Name": brandingThemeName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: brandingThemeName, + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_certificate.go b/internal/connector/pingone/platform/resources/pingone_certificate.go index a6022acb..c6046910 100644 --- a/internal/connector/pingone/platform/resources/pingone_certificate.go +++ b/internal/connector/pingone/platform/resources/pingone_certificate.go @@ -14,57 +14,77 @@ var ( ) type PingOneCertificateResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneCertificateResource func Certificate(clientInfo *connector.PingOneClientInfo) *PingOneCertificateResource { return &PingOneCertificateResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneCertificateResource) ResourceType() string { + return "pingone_certificate" +} + func (r *PingOneCertificateResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + err := r.exportCertificates() + if err != nil { + return nil, err + } - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.CertificateManagementApi.GetCertificates(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "GetCertificates" + return r.importBlocks, nil +} - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) +func (r *PingOneCertificateResource) exportCertificates() error { + // TODO: Implement pagination once supported in the PingOne Go Client SDK + entityArray, response, err := r.clientInfo.ApiClient.ManagementAPIClient.CertificateManagementApi.GetCertificates(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + err = common.HandleClientResponse(response, err, "GetCertificates", r.ResourceType()) if err != nil { - return nil, err + return err } - importBlocks := []connector.ImportBlock{} + if entityArray == nil { + return common.DataNilError(r.ResourceType(), response) + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + embedded, embeddedOk := entityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), response) + } for _, certificate := range embedded.GetCertificates() { - certificateName, certificateNameOk := certificate.GetNameOk() certificateId, certificateIdOk := certificate.GetIdOk() + certificateName, certificateNameOk := certificate.GetNameOk() - if certificateNameOk && certificateIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Certificate Name": *certificateName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Certificate ID": *certificateId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *certificateName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *certificateId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if certificateIdOk && certificateNameOk { + r.addImportBlock(*certificateId, *certificateName) } } - return &importBlocks, nil + return nil } -func (r *PingOneCertificateResource) ResourceType() string { - return "pingone_certificate" +func (r *PingOneCertificateResource) addImportBlock(certificateId string, certificateName string) { + commentData := map[string]string{ + "Certificate ID": certificateId, + "Certificate Name": certificateName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: certificateName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, certificateId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_custom_domain.go b/internal/connector/pingone/platform/resources/pingone_custom_domain.go index 2a7b98ad..a62d9e6f 100644 --- a/internal/connector/pingone/platform/resources/pingone_custom_domain.go +++ b/internal/connector/pingone/platform/resources/pingone_custom_domain.go @@ -14,57 +14,79 @@ var ( ) type PingOneCustomDomainResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneCustomDomainResource func CustomDomain(clientInfo *connector.PingOneClientInfo) *PingOneCustomDomainResource { return &PingOneCustomDomainResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneCustomDomainResource) ResourceType() string { + return "pingone_custom_domain" +} + func (r *PingOneCustomDomainResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.CustomDomainsApi.ReadAllDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllDomains" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportCustomDomains() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneCustomDomainResource) exportCustomDomains() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.CustomDomainsApi.ReadAllDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, customDomain := range embedded.GetCustomDomains() { - customDomainName, customDomainNameOk := customDomain.GetDomainNameOk() - customDomainId, customDomainIdOk := customDomain.GetIdOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllDomains", r.ResourceType()) + if err != nil { + return err + } - if customDomainIdOk && customDomainNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Custom Domain Name": *customDomainName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Custom Domain ID": *customDomainId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *customDomainName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *customDomainId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, customDomain := range embedded.GetCustomDomains() { + customDomainName, customDomainNameOk := customDomain.GetDomainNameOk() + customDomainId, customDomainIdOk := customDomain.GetIdOk() + + if customDomainIdOk && customDomainNameOk { + r.addImportBlock(*customDomainId, *customDomainName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneCustomDomainResource) ResourceType() string { - return "pingone_custom_domain" +func (r *PingOneCustomDomainResource) addImportBlock(customDomainId, customDomainName string) { + commentData := map[string]string{ + "Custom Domain ID": customDomainId, + "Custom Domain Name": customDomainName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: customDomainName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, customDomainId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_environment.go b/internal/connector/pingone/platform/resources/pingone_environment.go index c5ad3e9f..8ea68b80 100644 --- a/internal/connector/pingone/platform/resources/pingone_environment.go +++ b/internal/connector/pingone/platform/resources/pingone_environment.go @@ -12,40 +12,59 @@ var ( ) type PingOneEnvironmentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneEnvironmentResource func Environment(clientInfo *connector.PingOneClientInfo) *PingOneEnvironmentResource { return &PingOneEnvironmentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneEnvironmentResource) ResourceType() string { + return "pingone_environment" +} + func (r *PingOneEnvironmentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) + + err := r.exportEnvironments() + if err != nil { + return nil, err + } + + return r.importBlocks, nil +} - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) +func (r *PingOneEnvironmentResource) exportEnvironments() error { + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.EnvironmentsApi.ReadOneEnvironment(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - importBlocks := []connector.ImportBlock{} + err = common.HandleClientResponse(response, err, "ReadOneEnvironment", r.ResourceType()) + if err != nil { + return err + } + + r.addImportBlock() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return nil +} +func (r *PingOneEnvironmentResource) addImportBlock() { commentData := map[string]string{ "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, } - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: "export_environment", + ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), - }) - - return &importBlocks, nil -} + } -func (r *PingOneEnvironmentResource) ResourceType() string { - return "pingone_environment" + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_form.go b/internal/connector/pingone/platform/resources/pingone_form.go index 5abeb800..46ea34e2 100644 --- a/internal/connector/pingone/platform/resources/pingone_form.go +++ b/internal/connector/pingone/platform/resources/pingone_form.go @@ -14,57 +14,79 @@ var ( ) type PingOneFormResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneFormResource func Form(clientInfo *connector.PingOneClientInfo) *PingOneFormResource { return &PingOneFormResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneFormResource) ResourceType() string { + return "pingone_form" +} + func (r *PingOneFormResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.FormManagementApi.ReadAllForms(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllForms" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportForms() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneFormResource) exportForms() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.FormManagementApi.ReadAllForms(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, form := range embedded.GetForms() { - formId, formIdOk := form.GetIdOk() - formName, formNameOk := form.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllForms", r.ResourceType()) + if err != nil { + return err + } - if formIdOk && formNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Form Name": *formName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Form ID": *formId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *formName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *formId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, form := range embedded.GetForms() { + formId, formIdOk := form.GetIdOk() + formName, formNameOk := form.GetNameOk() + + if formIdOk && formNameOk { + r.addImportBlock(*formId, *formName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneFormResource) ResourceType() string { - return "pingone_form" +func (r *PingOneFormResource) addImportBlock(formId, formName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Form ID": formId, + "Form Name": formName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: formName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, formId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go b/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go index febb58a1..9a94bc10 100644 --- a/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go +++ b/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go @@ -12,53 +12,62 @@ var ( ) type PingOneFormRecaptchaV2Resource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneFormRecaptchaV2Resource func FormRecaptchaV2(clientInfo *connector.PingOneClientInfo) *PingOneFormRecaptchaV2Resource { return &PingOneFormRecaptchaV2Resource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneFormRecaptchaV2Resource) ResourceType() string { + return "pingone_forms_recaptcha_v2" +} + func (r *PingOneFormRecaptchaV2Resource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - // Fetch FormRecaptchaV2 Resource from API. - // If response is 204 No Content, then return empty import blocks. - _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.RecaptchaConfigurationApi.ReadRecaptchaConfiguration(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - err = common.HandleClientResponse(response, err, "ReadRecaptchaConfiguration", r.ResourceType()) + err := r.exportFormRecaptchaV2() if err != nil { return nil, err } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return r.importBlocks, nil +} - importBlocks := []connector.ImportBlock{} +func (r *PingOneFormRecaptchaV2Resource) exportFormRecaptchaV2() error { + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.RecaptchaConfigurationApi.ReadRecaptchaConfiguration(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + err = common.HandleClientResponse(response, err, "ReadRecaptchaConfiguration", r.ResourceType()) + if err != nil { + return err + } if response.StatusCode == 204 { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil + return common.DataNilError(r.ResourceType(), response) } + r.addImportBlock() + + return nil +} + +func (r *PingOneFormRecaptchaV2Resource) addImportBlock() { commentData := map[string]string{ - "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), } - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: "recaptcha_configuration", + ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), - }) - - return &importBlocks, nil -} + } -func (r *PingOneFormRecaptchaV2Resource) ResourceType() string { - return "pingone_forms_recaptcha_v2" + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_gateway.go b/internal/connector/pingone/platform/resources/pingone_gateway.go index c6ad38f3..dce534dc 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway.go @@ -14,75 +14,97 @@ var ( ) type PingOneGatewayResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneGatewayResource func Gateway(clientInfo *connector.PingOneClientInfo) *PingOneGatewayResource { return &PingOneGatewayResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneGatewayResource) ResourceType() string { + return "pingone_gateway" +} + func (r *PingOneGatewayResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllGateways" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportGateways() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, gatewayInner := range embedded.GetGateways() { - var ( - gatewayId *string - gatewayName *string - gatewayIdOk bool - gatewayNameOk bool - ) - - switch { - case gatewayInner.Gateway != nil: - gatewayId, gatewayIdOk = gatewayInner.Gateway.GetIdOk() - gatewayName, gatewayNameOk = gatewayInner.Gateway.GetNameOk() - case gatewayInner.GatewayTypeLDAP != nil: - gatewayId, gatewayIdOk = gatewayInner.GatewayTypeLDAP.GetIdOk() - gatewayName, gatewayNameOk = gatewayInner.GatewayTypeLDAP.GetNameOk() - case gatewayInner.GatewayTypeRADIUS != nil: - gatewayId, gatewayIdOk = gatewayInner.GatewayTypeRADIUS.GetIdOk() - gatewayName, gatewayNameOk = gatewayInner.GatewayTypeRADIUS.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneGatewayResource) exportGateways() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGateways", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if gatewayIdOk && gatewayNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Gateway Name": *gatewayName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Gateway ID": *gatewayId, + for _, gatewayInner := range embedded.GetGateways() { + var ( + gatewayId *string + gatewayName *string + gatewayIdOk bool + gatewayNameOk bool + ) + + switch { + case gatewayInner.Gateway != nil: + gatewayId, gatewayIdOk = gatewayInner.Gateway.GetIdOk() + gatewayName, gatewayNameOk = gatewayInner.Gateway.GetNameOk() + case gatewayInner.GatewayTypeLDAP != nil: + gatewayId, gatewayIdOk = gatewayInner.GatewayTypeLDAP.GetIdOk() + gatewayName, gatewayNameOk = gatewayInner.GatewayTypeLDAP.GetNameOk() + case gatewayInner.GatewayTypeRADIUS != nil: + gatewayId, gatewayIdOk = gatewayInner.GatewayTypeRADIUS.GetIdOk() + gatewayName, gatewayNameOk = gatewayInner.GatewayTypeRADIUS.GetNameOk() + default: + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *gatewayName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *gatewayId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if gatewayIdOk && gatewayNameOk { + r.addImportBlock(*gatewayId, *gatewayName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneGatewayResource) ResourceType() string { - return "pingone_gateway" +func (r *PingOneGatewayResource) addImportBlock(gatewayId, gatewayName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Gateway ID": gatewayId, + "Gateway Name": gatewayName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: gatewayName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_gateway_credential.go b/internal/connector/pingone/platform/resources/pingone_gateway_credential.go index 7fe3548c..91d82e46 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway_credential.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway_credential.go @@ -14,90 +14,131 @@ var ( ) type PingOneGatewayCredentialResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneGatewayCredentialResource func GatewayCredential(clientInfo *connector.PingOneClientInfo) *PingOneGatewayCredentialResource { return &PingOneGatewayCredentialResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneGatewayCredentialResource) ResourceType() string { + return "pingone_gateway_credential" +} + func (r *PingOneGatewayCredentialResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllGateways" - - gatewaysEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportGatewayCredentials() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, gatewayInner := range gatewaysEmbedded.GetGateways() { - var ( - gatewayId *string - gatewayName *string - gatewayIdOk bool - gatewayNameOk bool - ) - - switch { - case gatewayInner.Gateway != nil: - gatewayId, gatewayIdOk = gatewayInner.Gateway.GetIdOk() - gatewayName, gatewayNameOk = gatewayInner.Gateway.GetNameOk() - case gatewayInner.GatewayTypeLDAP != nil: - gatewayId, gatewayIdOk = gatewayInner.GatewayTypeLDAP.GetIdOk() - gatewayName, gatewayNameOk = gatewayInner.GatewayTypeLDAP.GetNameOk() - case gatewayInner.GatewayTypeRADIUS != nil: - gatewayId, gatewayIdOk = gatewayInner.GatewayTypeRADIUS.GetIdOk() - gatewayName, gatewayNameOk = gatewayInner.GatewayTypeRADIUS.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneGatewayCredentialResource) exportGatewayCredentials() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGateways", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if gatewayIdOk && gatewayNameOk { - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GatewayCredentialsApi.ReadAllGatewayCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *gatewayId).Execute - apiFunctionName := "ReadAllGatewayCredentials" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - gatewayCredentialsEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, gatewayInner := range embedded.GetGateways() { + var ( + gatewayId *string + gatewayIdOk bool + gatewayName *string + gatewayNameOk bool + ) + + switch { + case gatewayInner.Gateway != nil: + gatewayId, gatewayIdOk = gatewayInner.Gateway.GetIdOk() + gatewayName, gatewayNameOk = gatewayInner.Gateway.GetNameOk() + case gatewayInner.GatewayTypeLDAP != nil: + gatewayId, gatewayIdOk = gatewayInner.GatewayTypeLDAP.GetIdOk() + gatewayName, gatewayNameOk = gatewayInner.GatewayTypeLDAP.GetNameOk() + case gatewayInner.GatewayTypeRADIUS != nil: + gatewayId, gatewayIdOk = gatewayInner.GatewayTypeRADIUS.GetIdOk() + gatewayName, gatewayNameOk = gatewayInner.GatewayTypeRADIUS.GetNameOk() + default: + continue } - for gatewayCredentialIndex, gatewayCredential := range gatewayCredentialsEmbedded.GetCredentials() { - gatewayCredentialId, gatewayCredentialIdOk := gatewayCredential.GetIdOk() - - if gatewayCredentialIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Gateway Name": *gatewayName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Gateway ID": *gatewayId, - "Gateway Credential ID": *gatewayCredentialId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_credential_%d", *gatewayName, (gatewayCredentialIndex + 1)), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *gatewayId, *gatewayCredentialId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if gatewayIdOk && gatewayNameOk { + err := r.exportGatewayCredentialsByGateway(*gatewayId, *gatewayName) + if err != nil { + return err } } } } - return &importBlocks, nil + return nil } -func (r *PingOneGatewayCredentialResource) ResourceType() string { - return "pingone_gateway_credential" +func (r *PingOneGatewayCredentialResource) exportGatewayCredentialsByGateway(gatewayId, gatewayName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewayCredentialsApi.ReadAllGatewayCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, gatewayId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGatewayCredentials", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, gatewayCredential := range embedded.GetCredentials() { + gatewayCredentialId, gatewayCredentialIdOk := gatewayCredential.GetIdOk() + + if gatewayCredentialIdOk { + r.addImportBlock(gatewayId, gatewayName, *gatewayCredentialId) + } + } + } + + return nil +} + +func (r *PingOneGatewayCredentialResource) addImportBlock(gatewayId, gatewayName, gatewayCredentialId string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Gateway Credential ID": gatewayCredentialId, + "Gateway ID": gatewayId, + "Gateway Name": gatewayName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_credential_%s", gatewayName, gatewayCredentialId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId, gatewayCredentialId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go b/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go index 623baebf..5b120813 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go @@ -15,82 +15,65 @@ var ( ) type PingOneGatewayRoleAssignmentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneGatewayRoleAssignmentResource func GatewayRoleAssignment(clientInfo *connector.PingOneClientInfo) *PingOneGatewayRoleAssignmentResource { return &PingOneGatewayRoleAssignmentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneGatewayRoleAssignmentResource) ResourceType() string { + return "pingone_gateway_role_assignment" +} + func (r *PingOneGatewayRoleAssignmentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllGateways" - - gatewaysEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportGatewayRoleAssignments() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignments() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, gatewayInner := range gatewaysEmbedded.GetGateways() { - // Only PingFederate Connections have role assignments - if gatewayInner.Gateway != nil { - gatewayType, gatewayTypeOk := gatewayInner.Gateway.GetTypeOk() - if gatewayTypeOk && *gatewayType == management.ENUMGATEWAYTYPE_PING_FEDERATE { - gatewayId, gatewayIdOk := gatewayInner.Gateway.GetIdOk() - gatewayName, gatewayNameOk := gatewayInner.Gateway.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGateways", r.ResourceType()) + if err != nil { + return err + } - if gatewayIdOk && gatewayNameOk { - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GatewayRoleAssignmentsApi.ReadGatewayRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *gatewayId).Execute - apiFunctionName := "ReadGatewayRoleAssignments" + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - gatewayRoleAssignmentsEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, roleAssignment := range gatewayRoleAssignmentsEmbedded.GetRoleAssignments() { - roleAssignmentId, roleAssignmentIdOk := roleAssignment.GetIdOk() - roleAssignmentRole, roleAssignmentRoleOk := roleAssignment.GetRoleOk() - if roleAssignmentIdOk && roleAssignmentRoleOk { - roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk() - if roleAssignmentRoleIdOk { - role, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, *roleAssignmentRoleId).Execute() - err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) - if err != nil { - return nil, err - } - if role != nil { - roleName, roleNameOk := role.GetNameOk() - if roleNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Gateway Name": *gatewayName, - "Role Name": string(*roleName), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Gateway ID": *gatewayId, - "Role Assignment ID": *roleAssignmentId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s", *gatewayName, *roleName, *roleAssignmentId), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *gatewayId, *roleAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } - } - } + for _, gatewayInner := range embedded.GetGateways() { + // Only PingFederate Connections have role assignments + if gatewayInner.Gateway != nil { + gatewayType, gatewayTypeOk := gatewayInner.Gateway.GetTypeOk() + + if gatewayTypeOk && *gatewayType == management.ENUMGATEWAYTYPE_PING_FEDERATE { + gatewayId, gatewayIdOk := gatewayInner.Gateway.GetIdOk() + gatewayName, gatewayNameOk := gatewayInner.Gateway.GetNameOk() + + if gatewayIdOk && gatewayNameOk { + err := r.exportGatewayRoleAssignmentsByGateway(*gatewayId, *gatewayName) + if err != nil { + return err } } } @@ -98,9 +81,79 @@ func (r *PingOneGatewayRoleAssignmentResource) ExportAll() (*[]connector.ImportB } } - return &importBlocks, nil + return nil } -func (r *PingOneGatewayRoleAssignmentResource) ResourceType() string { - return "pingone_gateway_role_assignment" +func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignmentsByGateway(gatewayId, gatewayName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewayRoleAssignmentsApi.ReadGatewayRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, gatewayId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadGatewayRoleAssignments", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, roleAssignment := range embedded.GetRoleAssignments() { + roleAssignmentId, roleAssignmentIdOk := roleAssignment.GetIdOk() + roleAssignmentRole, roleAssignmentRoleOk := roleAssignment.GetRoleOk() + + if roleAssignmentIdOk && roleAssignmentRoleOk { + roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk() + if roleAssignmentRoleIdOk { + err := r.exportGatewayRoleAssignmentsByRole(gatewayId, gatewayName, *roleAssignmentId, *roleAssignmentRoleId) + if err != nil { + return err + } + } + } + } + } + + return nil +} + +func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignmentsByRole(gatewayId, gatewayName, roleAssignmentId, roleId string) error { + role, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, roleId).Execute() + err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) + if err != nil { + return err + } + + if role != nil { + roleName, roleNameOk := role.GetNameOk() + if roleNameOk { + r.addImportBlock(gatewayId, gatewayName, roleAssignmentId, string(*roleName)) + } + } + + return nil +} + +func (r *PingOneGatewayRoleAssignmentResource) addImportBlock(gatewayId, gatewayName, roleAssignmentId, roleName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Gateway ID": gatewayId, + "Gateway Name": gatewayName, + "Resource Type": r.ResourceType(), + "Role Assignment ID": roleAssignmentId, + "Role Name": roleName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", gatewayName, roleName, roleAssignmentId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId, roleAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go b/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go index 164b910c..f7ec92d6 100644 --- a/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go +++ b/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go @@ -14,57 +14,79 @@ var ( ) type PingOneIdentityPropagationPlanResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneIdentityPropagationPlanResource func IdentityPropagationPlan(clientInfo *connector.PingOneClientInfo) *PingOneIdentityPropagationPlanResource { return &PingOneIdentityPropagationPlanResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneIdentityPropagationPlanResource) ResourceType() string { + return "pingone_identity_propagation_plan" +} + func (r *PingOneIdentityPropagationPlanResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.IdentityPropagationPlansApi.ReadAllPlans(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllPlans" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportIdentityPropagationPlans() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneIdentityPropagationPlanResource) exportIdentityPropagationPlans() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityPropagationPlansApi.ReadAllPlans(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, identityPropagationPlan := range embedded.GetPlans() { - identityPropagationPlanId, identityPropagationPlanIdOk := identityPropagationPlan.GetIdOk() - identityPropagationPlanName, identityPropagationPlanNameOk := identityPropagationPlan.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPlans", r.ResourceType()) + if err != nil { + return err + } - if identityPropagationPlanIdOk && identityPropagationPlanNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Identity Propagation Plan Name": *identityPropagationPlanName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Identity Propagation Plan ID": *identityPropagationPlanId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *identityPropagationPlanName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *identityPropagationPlanId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, identityPropagationPlan := range embedded.GetPlans() { + identityPropagationPlanId, identityPropagationPlanIdOk := identityPropagationPlan.GetIdOk() + identityPropagationPlanName, identityPropagationPlanNameOk := identityPropagationPlan.GetNameOk() + + if identityPropagationPlanIdOk && identityPropagationPlanNameOk { + r.addImportBlock(*identityPropagationPlanId, *identityPropagationPlanName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneIdentityPropagationPlanResource) ResourceType() string { - return "pingone_identity_propagation_plan" +func (r *PingOneIdentityPropagationPlanResource) addImportBlock(identityPropagationPlanId, identityPropagationPlanName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Identity Propagation Plan ID": identityPropagationPlanId, + "Identity Propagation Plan Name": identityPropagationPlanName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: identityPropagationPlanName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, identityPropagationPlanId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_key.go b/internal/connector/pingone/platform/resources/pingone_key.go index 00018427..16762cd0 100644 --- a/internal/connector/pingone/platform/resources/pingone_key.go +++ b/internal/connector/pingone/platform/resources/pingone_key.go @@ -14,32 +14,51 @@ var ( ) type PingOneKeyResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneKeyResource func Key(clientInfo *connector.PingOneClientInfo) *PingOneKeyResource { return &PingOneKeyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneKeyResource) ResourceType() string { + return "pingone_key" +} + func (r *PingOneKeyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + err := r.exportKeys() + if err != nil { + return nil, err + } + + return r.importBlocks, nil +} - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.CertificateManagementApi.GetKeys(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "GetKeys" +func (r *PingOneKeyResource) exportKeys() error { + // TODO: Implement pagination once supported in the PingOne Go Client SDK + entityArray, response, err := r.clientInfo.ApiClient.ManagementAPIClient.CertificateManagementApi.GetKeys(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err = common.HandleClientResponse(response, err, "GetKeys", r.ResourceType()) if err != nil { - return nil, err + return err } - importBlocks := []connector.ImportBlock{} + if entityArray == nil { + return common.DataNilError(r.ResourceType(), response) + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + embedded, embeddedOk := entityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), response) + } for _, key := range embedded.GetKeys() { keyId, keyIdOk := key.GetIdOk() @@ -47,26 +66,28 @@ func (r *PingOneKeyResource) ExportAll() (*[]connector.ImportBlock, error) { keyUsageType, keyUsageTypeOk := key.GetUsageTypeOk() if keyIdOk && keyNameOk && keyUsageTypeOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Key Name": *keyName, - "Key Usage Type": string(*keyUsageType), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Key ID": *keyId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *keyName, *keyUsageType), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *keyId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + r.addImportBlock(*keyId, *keyName, string(*keyUsageType)) } } - return &importBlocks, nil + return nil } -func (r *PingOneKeyResource) ResourceType() string { - return "pingone_key" +func (r *PingOneKeyResource) addImportBlock(keyId, keyName, keyUsageType string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Key ID": keyId, + "Key Name": keyName, + "Key Usage Type": keyUsageType, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", keyName, keyUsageType), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, keyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go b/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go index f88ecb4e..f9a2be46 100644 --- a/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go +++ b/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go @@ -14,57 +14,79 @@ var ( ) type PingOneKeyRotationPolicyResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneKeyRotationPolicyResource func KeyRotationPolicy(clientInfo *connector.PingOneClientInfo) *PingOneKeyRotationPolicyResource { return &PingOneKeyRotationPolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneKeyRotationPolicyResource) ResourceType() string { + return "pingone_key_rotation_policy" +} + func (r *PingOneKeyRotationPolicyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.KeyRotationPoliciesApi.GetKeyRotationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "GetKeyRotationPolicies" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportKeyRotationPolicies() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneKeyRotationPolicyResource) exportKeyRotationPolicies() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.KeyRotationPoliciesApi.GetKeyRotationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, keyRotationPolicy := range embedded.GetKeyRotationPolicies() { - keyRotationPolicyId, keyRotationPolicyIdOk := keyRotationPolicy.GetIdOk() - keyRotationPolicyName, keyRotationPolicyNameOk := keyRotationPolicy.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "GetKeyRotationPolicies", r.ResourceType()) + if err != nil { + return err + } - if keyRotationPolicyIdOk && keyRotationPolicyNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Key Rotation Policy Name": *keyRotationPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Key Rotation Policy ID": *keyRotationPolicyId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *keyRotationPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *keyRotationPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, keyRotationPolicy := range embedded.GetKeyRotationPolicies() { + keyRotationPolicyId, keyRotationPolicyIdOk := keyRotationPolicy.GetIdOk() + keyRotationPolicyName, keyRotationPolicyNameOk := keyRotationPolicy.GetNameOk() + + if keyRotationPolicyIdOk && keyRotationPolicyNameOk { + r.addImportBlock(*keyRotationPolicyId, *keyRotationPolicyName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneKeyRotationPolicyResource) ResourceType() string { - return "pingone_key_rotation_policy" +func (r *PingOneKeyRotationPolicyResource) addImportBlock(keyRotationPolicyId, keyRotationPolicyName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Key Rotation Policy ID": keyRotationPolicyId, + "Key Rotation Policy Name": keyRotationPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: keyRotationPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, keyRotationPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_language.go b/internal/connector/pingone/platform/resources/pingone_language.go index 78adc546..5848b122 100644 --- a/internal/connector/pingone/platform/resources/pingone_language.go +++ b/internal/connector/pingone/platform/resources/pingone_language.go @@ -14,67 +14,87 @@ var ( ) type PingOneLanguageResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneLanguageResource func Language(clientInfo *connector.PingOneClientInfo) *PingOneLanguageResource { return &PingOneLanguageResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneLanguageResource) ResourceType() string { + return "pingone_language" +} + func (r *PingOneLanguageResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadLanguages" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportLanguages() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneLanguageResource) exportLanguages() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, languageInner := range embedded.GetLanguages() { - if languageInner.Language != nil { - language := languageInner.Language + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadLanguages", r.ResourceType()) + if err != nil { + return err + } - // If language is not customer added, skip it - languageCustomerAdded, languageCustomerAddedOk := language.GetCustomerAddedOk() - if languageCustomerAddedOk && !*languageCustomerAdded { - continue - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - languageId, languageIdOk := language.GetIdOk() - languageName, languageNameOk := language.GetNameOk() + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if languageIdOk && languageNameOk && languageCustomerAddedOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Language Name": *languageName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Language ID": *languageId, + for _, languageInner := range embedded.GetLanguages() { + if languageInner.Language != nil { + // If language is not customer added, skip it + languageCustomerAdded, languageCustomerAddedOk := languageInner.Language.GetCustomerAddedOk() + if !languageCustomerAddedOk || !*languageCustomerAdded { + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *languageName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *languageId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + languageId, languageIdOk := languageInner.Language.GetIdOk() + languageName, languageNameOk := languageInner.Language.GetNameOk() + + if languageIdOk && languageNameOk { + r.addImportBlock(*languageId, *languageName) + } } } } - return &importBlocks, nil + return nil } -func (r *PingOneLanguageResource) ResourceType() string { - return "pingone_language" +func (r *PingOneLanguageResource) addImportBlock(languageId, languageName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Language ID": languageId, + "Language Name": languageName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: languageName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, languageId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_language_update.go b/internal/connector/pingone/platform/resources/pingone_language_update.go index 1007e6b2..9c2db127 100644 --- a/internal/connector/pingone/platform/resources/pingone_language_update.go +++ b/internal/connector/pingone/platform/resources/pingone_language_update.go @@ -14,69 +14,94 @@ var ( ) type PingOneLanguageUpdateResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneLanguageUpdateResource func LanguageUpdate(clientInfo *connector.PingOneClientInfo) *PingOneLanguageUpdateResource { return &PingOneLanguageUpdateResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneLanguageUpdateResource) ResourceType() string { + return "pingone_language_update" +} + func (r *PingOneLanguageUpdateResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadLanguages" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportLanguageUpdates() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return r.importBlocks, nil +} - for _, languageInner := range embedded.GetLanguages() { - if languageInner.Language != nil { - language := languageInner.Language +func (r *PingOneLanguageUpdateResource) exportLanguageUpdates() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - languageCreatedAt, languageCreatedAtOk := language.GetCreatedAtOk() - languageUpdatedAt, languageUpdatedAtOk := language.GetUpdatedAtOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadLanguages", r.ResourceType()) + if err != nil { + return err + } - // if language update time is equal to creation time, skip it as it has not been updated - if languageCreatedAtOk && languageUpdatedAtOk && (*languageCreatedAt).Equal(*languageUpdatedAt) { - continue - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - languageId, languageIdOk := language.GetIdOk() - languageName, languageNameOk := language.GetNameOk() + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if languageIdOk && languageNameOk && languageCreatedAtOk && languageUpdatedAtOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Language Name": *languageName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Language ID": *languageId, + for _, languageInner := range embedded.GetLanguages() { + if languageInner.Language != nil { + languageEnabled, languageEnabledOk := languageInner.Language.GetEnabledOk() + languageLocale, languageLocaleOk := languageInner.Language.GetLocaleOk() + languageDefault, languageDefaultOk := languageInner.Language.GetDefaultOk() + + if languageEnabledOk && languageLocaleOk && languageDefaultOk { + // Export the language if it meets any of the criteria of the following 3 conditions: + // 1) Any language enabled + // 2) The 'en' language disabled + // 3) If any language other than 'en' is the default + + if *languageEnabled || (*languageLocale == "en" && !*languageEnabled) || (*languageLocale != "en" && *languageDefault) { + languageId, languageIdOk := languageInner.Language.GetIdOk() + languageName, languageNameOk := languageInner.Language.GetNameOk() + + if languageIdOk && languageNameOk { + r.addImportBlock(*languageId, *languageName) + } + } } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_update", *languageName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *languageId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) } } } - return &importBlocks, nil + return nil } -func (r *PingOneLanguageUpdateResource) ResourceType() string { - return "pingone_language_update" +func (r *PingOneLanguageUpdateResource) addImportBlock(languageId, languageName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Language ID": languageId, + "Language Name": languageName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_update", languageName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, languageId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_policy.go b/internal/connector/pingone/platform/resources/pingone_notification_policy.go index a305e141..30e73723 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_policy.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_policy.go @@ -14,57 +14,79 @@ var ( ) type PingOneNotificationPolicyResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneNotificationPolicyResource func NotificationPolicy(clientInfo *connector.PingOneClientInfo) *PingOneNotificationPolicyResource { return &PingOneNotificationPolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneNotificationPolicyResource) ResourceType() string { + return "pingone_notification_policy" +} + func (r *PingOneNotificationPolicyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsPoliciesApi.ReadAllNotificationsPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllNotificationsPolicies" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportNotificationPolicies() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneNotificationPolicyResource) exportNotificationPolicies() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsPoliciesApi.ReadAllNotificationsPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, notificationPolicy := range embedded.GetNotificationsPolicies() { - notificationPolicyId, notificationPolicyIdOk := notificationPolicy.GetIdOk() - notificationPolicyName, notificationPolicyNameOk := notificationPolicy.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllNotificationsPolicies", r.ResourceType()) + if err != nil { + return err + } - if notificationPolicyIdOk && notificationPolicyNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Notification Policy Name": *notificationPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Notification Policy ID": *notificationPolicyId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *notificationPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *notificationPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, notificationPolicy := range embedded.GetNotificationsPolicies() { + notificationPolicyId, notificationPolicyIdOk := notificationPolicy.GetIdOk() + notificationPolicyName, notificationPolicyNameOk := notificationPolicy.GetNameOk() + + if notificationPolicyIdOk && notificationPolicyNameOk { + r.addImportBlock(*notificationPolicyId, *notificationPolicyName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneNotificationPolicyResource) ResourceType() string { - return "pingone_notification_policy" +func (r *PingOneNotificationPolicyResource) addImportBlock(notificationPolicyId, notificationPolicyName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Notification Policy ID": notificationPolicyId, + "Notification Policy Name": notificationPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: notificationPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, notificationPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_settings.go b/internal/connector/pingone/platform/resources/pingone_notification_settings.go index bfe2242f..3fbfc07d 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_settings.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_settings.go @@ -12,51 +12,62 @@ var ( ) type PingOneNotificationSettingsResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneNotificationSettingsResource func NotificationSettings(clientInfo *connector.PingOneClientInfo) *PingOneNotificationSettingsResource { return &PingOneNotificationSettingsResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneNotificationSettingsResource) ResourceType() string { + return "pingone_notification_settings" +} + func (r *PingOneNotificationSettingsResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsSettingsApi.ReadNotificationsSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - err = common.HandleClientResponse(response, err, "ReadNotificationsSettings", r.ResourceType()) + err := r.exportNotificationSettings() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneNotificationSettingsResource) exportNotificationSettings() error { + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsSettingsApi.ReadNotificationsSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + err = common.HandleClientResponse(response, err, "ReadNotificationsSettings", r.ResourceType()) + if err != nil { + return err + } if response.StatusCode == 204 { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil + return common.DataNilError(r.ResourceType(), response) } + r.addImportBlock() + + return nil +} + +func (r *PingOneNotificationSettingsResource) addImportBlock() { commentData := map[string]string{ - "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), } - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: "notification_settings", + ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), - }) - - return &importBlocks, nil -} + } -func (r *PingOneNotificationSettingsResource) ResourceType() string { - return "pingone_notification_settings" + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go b/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go index 3bd0e2dd..adfdf86e 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go @@ -12,71 +12,62 @@ var ( ) type PingOneNotificationSettingsEmailResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneNotificationSettingsEmailResource func NotificationSettingsEmail(clientInfo *connector.PingOneClientInfo) *PingOneNotificationSettingsEmailResource { return &PingOneNotificationSettingsEmailResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneNotificationSettingsEmailResource) ResourceType() string { + return "pingone_notification_settings_email" +} + func (r *PingOneNotificationSettingsEmailResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - emailNotificationSettings, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsSettingsSMTPApi.ReadEmailNotificationsSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - err = common.HandleClientResponse(response, err, "ReadEmailNotificationsSettings", r.ResourceType()) + err := r.exportNotificationSettingsEmails() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + return r.importBlocks, nil +} - if emailNotificationSettings == nil { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil +func (r *PingOneNotificationSettingsEmailResource) exportNotificationSettingsEmails() error { + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsSettingsSMTPApi.ReadEmailNotificationsSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + err = common.HandleClientResponse(response, err, "ReadEmailNotificationsSettings", r.ResourceType()) + if err != nil { + return err } if response.StatusCode == 204 { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil + return common.DataNilError(r.ResourceType(), response) } - emailNotificationSettingsEnv, emailNotificationSettingsEnvOk := emailNotificationSettings.GetEnvironmentOk() - var ( - emailNotificationSettingsEnvID *string - emailNotificationSettingsEnvIDOk bool - ) + r.addImportBlock() - if emailNotificationSettingsEnvOk { - emailNotificationSettingsEnvID, emailNotificationSettingsEnvIDOk = emailNotificationSettingsEnv.GetIdOk() - } - - if !emailNotificationSettingsEnvOk || !emailNotificationSettingsEnvIDOk || emailNotificationSettingsEnvID == nil { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &importBlocks, nil - } + return nil +} +func (r *PingOneNotificationSettingsEmailResource) addImportBlock() { commentData := map[string]string{ - "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), } - importBlocks = append(importBlocks, connector.ImportBlock{ + importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: "pingone_notification_settings_email", + ResourceName: r.ResourceType(), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), - }) - - return &importBlocks, nil -} + } -func (r *PingOneNotificationSettingsEmailResource) ResourceType() string { - return "pingone_notification_settings_email" + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_template_content.go b/internal/connector/pingone/platform/resources/pingone_notification_template_content.go index 8bd6c12c..12324f5e 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_template_content.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_template_content.go @@ -15,152 +15,129 @@ var ( ) type PingOneNotificationTemplateContentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneNotificationTemplateContentResource func NotificationTemplateContent(clientInfo *connector.PingOneClientInfo) *PingOneNotificationTemplateContentResource { return &PingOneNotificationTemplateContentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneNotificationTemplateContentResource) ResourceType() string { + return "pingone_notification_template_content" +} + func (r *PingOneNotificationTemplateContentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - // Get all enabled language locales - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadLanguages" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportNotificationTemplateContents() if err != nil { return nil, err } - enabledLocales := map[string]bool{} - for _, languageInner := range embedded.GetLanguages() { - if languageInner.Language != nil { - language := languageInner.Language - - languageEnabled, languageEnabledOk := language.GetEnabledOk() - languageLocale, languageLocaleOk := language.GetLocaleOk() + return r.importBlocks, nil +} - if languageEnabledOk && languageLocaleOk && *languageEnabled { - enabledLocales[*languageLocale] = true - } +func (r *PingOneNotificationTemplateContentResource) exportNotificationTemplateContents() error { + for _, templateName := range management.AllowedEnumTemplateNameEnumValues { + err := r.exportNotificationTemplateContentsByTemplate(templateName) + if err != nil { + return err } } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - // This is weird... the provider mentions many possible template types, - // but pingone console and the API only support the following types: - validTemplateNames := []management.EnumTemplateName{ - management.ENUMTEMPLATENAME_DEVICE_PAIRING, - management.ENUMTEMPLATENAME_EMAIL_VERIFICATION_ADMIN, - management.ENUMTEMPLATENAME_EMAIL_VERIFICATION_USER, - management.ENUMTEMPLATENAME_GENERAL, - management.ENUMTEMPLATENAME_NEW_DEVICE_PAIRED, - management.ENUMTEMPLATENAME_STRONG_AUTHENTICATION, - management.ENUMTEMPLATENAME_TRANSACTION, - management.ENUMTEMPLATENAME_VERIFICATION_CODE_TEMPLATE, - } + return nil +} - // TODO: When the above hard-coded values are fixed, use the following - // for _, templateNameEnum := range management.AllowedEnumTemplateNameEnumValues { - for _, templateNameEnum := range validTemplateNames { - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsTemplatesApi.ReadAllTemplateContents(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, templateNameEnum).Execute - apiFunctionName := "ReadAllTemplateContents" +func (r *PingOneNotificationTemplateContentResource) exportNotificationTemplateContentsByTemplate(templateName management.EnumTemplateName) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsTemplatesApi.ReadAllTemplateContents(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, templateName).Execute() - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTemplateContents", r.ResourceType()) if err != nil { - return nil, err + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - for _, templateContents := range embedded.GetContents() { + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, templateContent := range embedded.GetContents() { var ( - templateContentsId *string - templateContentsIdOk bool - templateDeliveryMethod *management.EnumTemplateContentDeliveryMethod - templateDeliveryMethodOk bool - templateLocale *string - templateLocaleOk bool - templateVariant *string - templateVariantOk bool + templateContentId *string + templateContentIdOk bool + templateContentDeliveryMethod *management.EnumTemplateContentDeliveryMethod + templateContentDeliveryMethodOk bool + templateContentLocale *string + templateContentLocaleOk bool + templateContentVariant string ) switch { - case templateContents.TemplateContentEmail != nil: - templateContentsId, templateContentsIdOk = templateContents.TemplateContentEmail.GetIdOk() - templateDeliveryMethod, templateDeliveryMethodOk = templateContents.TemplateContentEmail.GetDeliveryMethodOk() - templateLocale, templateLocaleOk = templateContents.TemplateContentEmail.GetLocaleOk() - templateVariant, templateVariantOk = templateContents.TemplateContentEmail.GetVariantOk() - case templateContents.TemplateContentPush != nil: - templateContentsId, templateContentsIdOk = templateContents.TemplateContentPush.GetIdOk() - templateDeliveryMethod, templateDeliveryMethodOk = templateContents.TemplateContentPush.GetDeliveryMethodOk() - templateLocale, templateLocaleOk = templateContents.TemplateContentPush.GetLocaleOk() - templateVariant, templateVariantOk = templateContents.TemplateContentPush.GetVariantOk() - case templateContents.TemplateContentSMS != nil: - templateContentsId, templateContentsIdOk = templateContents.TemplateContentSMS.GetIdOk() - templateDeliveryMethod, templateDeliveryMethodOk = templateContents.TemplateContentSMS.GetDeliveryMethodOk() - templateLocale, templateLocaleOk = templateContents.TemplateContentSMS.GetLocaleOk() - templateVariant, templateVariantOk = templateContents.TemplateContentSMS.GetVariantOk() - case templateContents.TemplateContentVoice != nil: - templateContentsId, templateContentsIdOk = templateContents.TemplateContentVoice.GetIdOk() - templateDeliveryMethod, templateDeliveryMethodOk = templateContents.TemplateContentVoice.GetDeliveryMethodOk() - templateLocale, templateLocaleOk = templateContents.TemplateContentVoice.GetLocaleOk() - templateVariant, templateVariantOk = templateContents.TemplateContentVoice.GetVariantOk() + case templateContent.TemplateContentPush != nil: + templateContentId, templateContentIdOk = templateContent.TemplateContentPush.GetIdOk() + templateContentDeliveryMethod, templateContentDeliveryMethodOk = templateContent.TemplateContentPush.GetDeliveryMethodOk() + templateContentLocale, templateContentLocaleOk = templateContent.TemplateContentPush.GetLocaleOk() + templateContentVariant = templateContent.TemplateContentPush.GetVariant() + case templateContent.TemplateContentSMS != nil: + templateContentId, templateContentIdOk = templateContent.TemplateContentSMS.GetIdOk() + templateContentDeliveryMethod, templateContentDeliveryMethodOk = templateContent.TemplateContentSMS.GetDeliveryMethodOk() + templateContentLocale, templateContentLocaleOk = templateContent.TemplateContentSMS.GetLocaleOk() + templateContentVariant = templateContent.TemplateContentSMS.GetVariant() + case templateContent.TemplateContentEmail != nil: + templateContentId, templateContentIdOk = templateContent.TemplateContentEmail.GetIdOk() + templateContentDeliveryMethod, templateContentDeliveryMethodOk = templateContent.TemplateContentEmail.GetDeliveryMethodOk() + templateContentLocale, templateContentLocaleOk = templateContent.TemplateContentEmail.GetLocaleOk() + templateContentVariant = templateContent.TemplateContentEmail.GetVariant() + case templateContent.TemplateContentVoice != nil: + templateContentId, templateContentIdOk = templateContent.TemplateContentVoice.GetIdOk() + templateContentDeliveryMethod, templateContentDeliveryMethodOk = templateContent.TemplateContentVoice.GetDeliveryMethodOk() + templateContentLocale, templateContentLocaleOk = templateContent.TemplateContentVoice.GetLocaleOk() + templateContentVariant = templateContent.TemplateContentVoice.GetVariant() default: continue } - // If the template content locale is not enabled, skip it - if templateLocaleOk && !enabledLocales[*templateLocale] { - continue + if templateContentIdOk && templateContentDeliveryMethodOk && templateContentLocaleOk { + r.addImportBlock(string(templateName), *templateContentId, string(*templateContentDeliveryMethod), *templateContentLocale, templateContentVariant) } + } + } - // This variable handles the case where template type, locale, - // and delivery method are the same across two content instances - // Append it to the ResourceName if present from SDK - if templateVariantOk { - *templateVariant = "_" + *templateVariant - } else { - emptyString := "" - templateVariant = &emptyString - } + return nil +} - if templateContentsIdOk && templateDeliveryMethodOk && templateLocaleOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Template Name": string(templateNameEnum), - "Template Delivery Method": string(*templateDeliveryMethod), - "Template Locale": string(*templateLocale), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Template Contents ID": string(*templateContentsId), - } - - if templateVariantOk { - commentData["Template Variant"] = *templateVariant - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s%s", templateNameEnum, *templateDeliveryMethod, *templateLocale, *templateVariant), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, templateNameEnum, *templateContentsId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } - } +func (r *PingOneNotificationTemplateContentResource) addImportBlock(templateName, templateContentId, templateContentDeliveryMethod, templateContentLocale, templateContentVariant string) { + commentData := map[string]string{ + "Resource Type": r.ResourceType(), + "Template Name": templateName, + "Template Content Delivery Method": templateContentDeliveryMethod, + "Template Content Locale": templateContentLocale, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Template Content ID": templateContentId, + } + if templateContentVariant != "" { + commentData["Template Content Variant"] = templateContentVariant + templateContentVariant = "_" + templateContentVariant } - return &importBlocks, nil -} + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s%s", templateName, templateContentDeliveryMethod, templateContentLocale, templateContentVariant), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, templateName, templateContentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } -func (r *PingOneNotificationTemplateContentResource) ResourceType() string { - return "pingone_notification_template_content" + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go b/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go index bb8fd405..686e82ef 100644 --- a/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go +++ b/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go @@ -15,84 +15,106 @@ var ( ) type PingOnePhoneDeliverySettingsResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOnePhoneDeliverySettingsResource func PhoneDeliverySettings(clientInfo *connector.PingOneClientInfo) *PingOnePhoneDeliverySettingsResource { return &PingOnePhoneDeliverySettingsResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOnePhoneDeliverySettingsResource) ResourceType() string { + return "pingone_phone_delivery_settings" +} + func (r *PingOnePhoneDeliverySettingsResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.PhoneDeliverySettingsApi.ReadAllPhoneDeliverySettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllPhoneDeliverySettings" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportPhoneDeliverySettings() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for index, phoneDeliverySettings := range embedded.GetPhoneDeliverySettings() { - var ( - phoneDeliverySettingsId *string - phoneDeliverySettingsName *string - phoneDeliverySettingsIdOk bool - phoneDeliverySettingsNameOk bool - ) - - switch { - case phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsCustom != nil: - phoneDeliverySettingsId, phoneDeliverySettingsIdOk = phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsCustom.GetIdOk() - phoneDeliverySettingsName, phoneDeliverySettingsNameOk = phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsCustom.GetNameOk() - case phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse != nil: - phoneDeliverySettingsId, phoneDeliverySettingsIdOk = phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse.GetIdOk() - phoneDeliverySettingsProvider, phoneDeliverySettingProviderOk := phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse.GetProviderOk() - if phoneDeliverySettingProviderOk { - switch *phoneDeliverySettingsProvider { - case management.ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_TWILIO: - twilioName := fmt.Sprintf("CUSTOM_TWILIO_%d", index) - phoneDeliverySettingsName, phoneDeliverySettingsNameOk = &twilioName, true - case management.ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_SYNIVERSE: - syniverseName := fmt.Sprintf("CUSTOM_SYNIVERSE_%d", index) - phoneDeliverySettingsName, phoneDeliverySettingsNameOk = &syniverseName, true - default: - continue - } - } - default: - continue + return r.importBlocks, nil +} + +func (r *PingOnePhoneDeliverySettingsResource) exportPhoneDeliverySettings() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.PhoneDeliverySettingsApi.ReadAllPhoneDeliverySettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPhoneDeliverySettings", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if phoneDeliverySettingsIdOk && phoneDeliverySettingsNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Phone Delivery Settings Name": *phoneDeliverySettingsName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Phone Delivery Settings ID": *phoneDeliverySettingsId, + for _, phoneDeliverySettings := range embedded.GetPhoneDeliverySettings() { + var ( + phoneDeliverySettingsId *string + phoneDeliverySettingsIdOk bool + phoneDeliverySettingsName string + phoneDeliverySettingsNameOk bool + ) + + switch { + case phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsCustom != nil: + phoneDeliverySettingsId, phoneDeliverySettingsIdOk = phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsCustom.GetIdOk() + if phoneDeliverySettingsIdOk { + phoneDeliverySettingsName, phoneDeliverySettingsNameOk = fmt.Sprintf("provider_custom_%s", *phoneDeliverySettingsId), true + } + case phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse != nil: + phoneDeliverySettingsId, phoneDeliverySettingsIdOk = phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse.GetIdOk() + phoneDeliverySettingsProvider, phoneDeliverySettingProviderOk := phoneDeliverySettings.NotificationsSettingsPhoneDeliverySettingsTwilioSyniverse.GetProviderOk() + if phoneDeliverySettingsIdOk && phoneDeliverySettingProviderOk { + switch *phoneDeliverySettingsProvider { + case management.ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_TWILIO: + phoneDeliverySettingsName, phoneDeliverySettingsNameOk = fmt.Sprintf("provider_twilio_%s", *phoneDeliverySettingsId), true + case management.ENUMNOTIFICATIONSSETTINGSPHONEDELIVERYSETTINGSPROVIDER_SYNIVERSE: + phoneDeliverySettingsName, phoneDeliverySettingsNameOk = fmt.Sprintf("provider_syniverse_%s", *phoneDeliverySettingsId), true + default: + continue + } + } + default: + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *phoneDeliverySettingsName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *phoneDeliverySettingsId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if phoneDeliverySettingsIdOk && phoneDeliverySettingsNameOk { + r.addImportBlock(*phoneDeliverySettingsId, phoneDeliverySettingsName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOnePhoneDeliverySettingsResource) ResourceType() string { - return "pingone_phone_delivery_settings" +func (r *PingOnePhoneDeliverySettingsResource) addImportBlock(phoneDeliverySettingsId, phoneDeliverySettingsName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Phone Delivery Settings ID": phoneDeliverySettingsId, + "Phone Delivery Settings Name": phoneDeliverySettingsName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: phoneDeliverySettingsName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, phoneDeliverySettingsId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_system_application.go b/internal/connector/pingone/platform/resources/pingone_system_application.go index 9bda3eaf..370eb069 100644 --- a/internal/connector/pingone/platform/resources/pingone_system_application.go +++ b/internal/connector/pingone/platform/resources/pingone_system_application.go @@ -14,72 +14,94 @@ var ( ) type PingOneSystemApplicationResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneSystemApplicationResource func SystemApplication(clientInfo *connector.PingOneClientInfo) *PingOneSystemApplicationResource { return &PingOneSystemApplicationResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneSystemApplicationResource) ResourceType() string { + return "pingone_system_application" +} + func (r *PingOneSystemApplicationResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportSystemApplications() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationPingOnePortal != nil: - appId, appIdOk = app.ApplicationPingOnePortal.GetIdOk() - appName, appNameOk = app.ApplicationPingOnePortal.GetNameOk() - case app.ApplicationPingOneSelfService != nil: - appId, appIdOk = app.ApplicationPingOneSelfService.GetIdOk() - appName, appNameOk = app.ApplicationPingOneSelfService.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneSystemApplicationResource) exportSystemApplications() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if appIdOk && appNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "System Application Name": *appName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "System Application ID": *appId, + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationPingOnePortal != nil: + appId, appIdOk = app.ApplicationPingOnePortal.GetIdOk() + appName, appNameOk = app.ApplicationPingOnePortal.GetNameOk() + case app.ApplicationPingOneSelfService != nil: + appId, appIdOk = app.ApplicationPingOneSelfService.GetIdOk() + appName, appNameOk = app.ApplicationPingOneSelfService.GetNameOk() + default: + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *appName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *appId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if appIdOk && appNameOk { + r.addImportBlock(*appId, *appName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneSystemApplicationResource) ResourceType() string { - return "pingone_system_application" +func (r *PingOneSystemApplicationResource) addImportBlock(appId, appName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "System Application ID": appId, + "System Application Name": appName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: appName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go b/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go index 27274fa2..b61c1755 100644 --- a/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go +++ b/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go @@ -14,74 +14,115 @@ var ( ) type PingOneTrustedEmailAddressResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneTrustedEmailAddressResource func TrustedEmailAddress(clientInfo *connector.PingOneClientInfo) *PingOneTrustedEmailAddressResource { return &PingOneTrustedEmailAddressResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneTrustedEmailAddressResource) ResourceType() string { + return "pingone_trusted_email_address" +} + func (r *PingOneTrustedEmailAddressResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailDomainsApi.ReadAllTrustedEmailDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllTrustedEmailDomains" - - emailDomainEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportTrustedEmailAddresses() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneTrustedEmailAddressResource) exportTrustedEmailAddresses() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailDomainsApi.ReadAllTrustedEmailDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTrustedEmailDomains", r.ResourceType()) + if err != nil { + return err + } - for _, trustedEmailDomain := range emailDomainEmbedded.GetEmailDomains() { - trustedEmailDomainId, trustedEmailDomainIdOk := trustedEmailDomain.GetIdOk() - trustedEmailDomainName, trustedEmailDomainNameOk := trustedEmailDomain.GetDomainNameOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if trustedEmailDomainIdOk && trustedEmailDomainNameOk { - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailAddressesApi.ReadAllTrustedEmailAddresses(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *trustedEmailDomainId).Execute - apiFunctionName := "ReadAllTrustedEmailAddresses" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - trustedEmailAddressEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + for _, trustedEmailDomain := range embedded.GetEmailDomains() { + trustedEmailDomainId, trustedEmailDomainIdOk := trustedEmailDomain.GetIdOk() + trustedEmailDomainName, trustedEmailDomainNameOk := trustedEmailDomain.GetDomainNameOk() - for _, trustedEmail := range trustedEmailAddressEmbedded.GetTrustedEmails() { - trustedEmailAddress, trustedEmailAddressOk := trustedEmail.GetEmailAddressOk() - trustedEmailId, trustedEmailIdOk := trustedEmail.GetIdOk() - - if trustedEmailAddressOk && trustedEmailIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Trusted Email Domain Name": *trustedEmailDomainName, - "Trusted Email Address": *trustedEmailAddress, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Trusted Email Domain ID": *trustedEmailDomainId, - "Trusted Email Address ID": *trustedEmailId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *trustedEmailDomainName, *trustedEmailAddress), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *trustedEmailDomainId, *trustedEmailId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if trustedEmailDomainIdOk && trustedEmailDomainNameOk { + err := r.exportTrustedEmailAddressesByDomain(*trustedEmailDomainId, *trustedEmailDomainName) + if err != nil { + return err } } } } - return &importBlocks, nil + return nil } -func (r *PingOneTrustedEmailAddressResource) ResourceType() string { - return "pingone_trusted_email_address" +func (r *PingOneTrustedEmailAddressResource) exportTrustedEmailAddressesByDomain(trustedEmailDomainId, trustedEmailDomainName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailAddressesApi.ReadAllTrustedEmailAddresses(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, trustedEmailDomainId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTrustedEmailAddresses", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, trustedEmail := range embedded.GetTrustedEmails() { + trustedEmailAddress, trustedEmailAddressOk := trustedEmail.GetEmailAddressOk() + trustedEmailId, trustedEmailIdOk := trustedEmail.GetIdOk() + + if trustedEmailAddressOk && trustedEmailIdOk { + r.addImportBlock(trustedEmailDomainId, trustedEmailDomainName, *trustedEmailId, *trustedEmailAddress) + } + } + } + + return nil +} + +func (r *PingOneTrustedEmailAddressResource) addImportBlock(trustedEmailDomainId, trustedEmailDomainName, trustedEmailId, trustedEmailAddress string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Trusted Email Address": trustedEmailAddress, + "Trusted Email Address ID": trustedEmailId, + "Trusted Email Domain ID": trustedEmailDomainId, + "Trusted Email Domain Name": trustedEmailDomainName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", trustedEmailDomainName, trustedEmailAddress), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, trustedEmailDomainId, trustedEmailId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go b/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go index 9f55d1fc..7b2cf478 100644 --- a/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go +++ b/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go @@ -14,57 +14,79 @@ var ( ) type PingOneTrustedEmailDomainResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOne Trusted Email Domain Resource func TrustedEmailDomain(clientInfo *connector.PingOneClientInfo) *PingOneTrustedEmailDomainResource { return &PingOneTrustedEmailDomainResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneTrustedEmailDomainResource) ResourceType() string { + return "pingone_trusted_email_domain" +} + func (r *PingOneTrustedEmailDomainResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailDomainsApi.ReadAllTrustedEmailDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllTrustedEmailDomains" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportTrustedEmailDomains() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneTrustedEmailDomainResource) exportTrustedEmailDomains() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailDomainsApi.ReadAllTrustedEmailDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, emailDomain := range embedded.GetEmailDomains() { - emailDomainId, emailDomainIdOk := emailDomain.GetIdOk() - emailDomainName, emailDomainNameOk := emailDomain.GetDomainNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTrustedEmailDomains", r.ResourceType()) + if err != nil { + return err + } - if emailDomainIdOk && emailDomainNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Trusted Email Domain Name": *emailDomainName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Trusted Email Domain ID": *emailDomainId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *emailDomainName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *emailDomainId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, emailDomain := range embedded.GetEmailDomains() { + emailDomainId, emailDomainIdOk := emailDomain.GetIdOk() + emailDomainName, emailDomainNameOk := emailDomain.GetDomainNameOk() + + if emailDomainIdOk && emailDomainNameOk { + r.addImportBlock(*emailDomainId, *emailDomainName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneTrustedEmailDomainResource) ResourceType() string { - return "pingone_trusted_email_domain" +func (r *PingOneTrustedEmailDomainResource) addImportBlock(emailDomainId, emailDomainName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Trusted Email Domain ID": emailDomainId, + "Trusted Email Domain Name": emailDomainName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: emailDomainName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, emailDomainId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/platform/resources/pingone_webhook.go b/internal/connector/pingone/platform/resources/pingone_webhook.go index b154cbfb..bd4f702d 100644 --- a/internal/connector/pingone/platform/resources/pingone_webhook.go +++ b/internal/connector/pingone/platform/resources/pingone_webhook.go @@ -14,57 +14,79 @@ var ( ) type PingOneWebhookResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneWebhookResource func Webhook(clientInfo *connector.PingOneClientInfo) *PingOneWebhookResource { return &PingOneWebhookResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneWebhookResource) ResourceType() string { + return "pingone_webhook" +} + func (r *PingOneWebhookResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.SubscriptionsWebhooksApi.ReadAllSubscriptions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllSubscriptions" - - usersEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportWebhooks() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneWebhookResource) exportWebhooks() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.SubscriptionsWebhooksApi.ReadAllSubscriptions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, subscription := range usersEmbedded.GetSubscriptions() { - subscriptionId, subscriptionIdOk := subscription.GetIdOk() - subscriptionName, subscriptionNameOk := subscription.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSubscriptions", r.ResourceType()) + if err != nil { + return err + } - if subscriptionIdOk && subscriptionNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Webhook Name": *subscriptionName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Webhook ID": *subscriptionId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *subscriptionName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *subscriptionId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, subscription := range embedded.GetSubscriptions() { + subscriptionId, subscriptionIdOk := subscription.GetIdOk() + subscriptionName, subscriptionNameOk := subscription.GetNameOk() + + if subscriptionIdOk && subscriptionNameOk { + r.addImportBlock(*subscriptionId, *subscriptionName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneWebhookResource) ResourceType() string { - return "pingone_webhook" +func (r *PingOneWebhookResource) addImportBlock(subscriptionId, subscriptionName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Webhook ID": subscriptionId, + "Webhook Name": subscriptionName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: subscriptionName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, subscriptionId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } From fcb2312245ba031447053eec3f0b4e6947cc70f2 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 26 Nov 2024 11:12:27 -0700 Subject: [PATCH 5/9] Update Protect resource exports to iter info extraction design --- .../protect/resources/pingone_risk_policy.go | 79 ++++--- .../resources/pingone_risk_predictor.go | 210 ++++++++++-------- 2 files changed, 165 insertions(+), 124 deletions(-) diff --git a/internal/connector/pingone/protect/resources/pingone_risk_policy.go b/internal/connector/pingone/protect/resources/pingone_risk_policy.go index a6c114dc..6006a9e1 100644 --- a/internal/connector/pingone/protect/resources/pingone_risk_policy.go +++ b/internal/connector/pingone/protect/resources/pingone_risk_policy.go @@ -14,58 +14,79 @@ var ( ) type PingOneRiskPolicyResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneRiskPolicyResource func RiskPolicy(clientInfo *connector.PingOneClientInfo) *PingOneRiskPolicyResource { return &PingOneRiskPolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneRiskPolicyResource) ResourceType() string { + return "pingone_risk_policy" +} + func (r *PingOneRiskPolicyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.RiskAPIClient.RiskPoliciesApi.ReadRiskPolicySets(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadRiskPolicySets" - - embedded, err := common.GetProtectEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportPolicies() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneRiskPolicyResource) exportPolicies() error { + iter := r.clientInfo.ApiClient.RiskAPIClient.RiskPoliciesApi.ReadRiskPolicySets(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, riskPolicySet := range embedded.GetRiskPolicySets() { - riskPolicySetName, riskPolicySetNameOk := riskPolicySet.GetNameOk() - riskPolicySetId, riskPolicySetIdOk := riskPolicySet.GetIdOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadRiskPolicySets", r.ResourceType()) + if err != nil { + return err + } - if riskPolicySetNameOk && riskPolicySetIdOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Risk Policy Name": *riskPolicySetName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Risk Policy ID": *riskPolicySetId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *riskPolicySetName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *riskPolicySetId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, riskPolicySet := range embedded.GetRiskPolicySets() { + riskPolicySetName, riskPolicySetNameOk := riskPolicySet.GetNameOk() + riskPolicySetId, riskPolicySetIdOk := riskPolicySet.GetIdOk() + if riskPolicySetIdOk && riskPolicySetNameOk { + r.addImportBlock(*riskPolicySetId, *riskPolicySetName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneRiskPolicyResource) ResourceType() string { - return "pingone_risk_policy" +func (r *PingOneRiskPolicyResource) addImportBlock(riskPolicySetId, riskPolicySetName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Risk Policy ID": riskPolicySetId, + "Risk Policy Name": riskPolicySetName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: riskPolicySetName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, riskPolicySetId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/protect/resources/pingone_risk_predictor.go b/internal/connector/pingone/protect/resources/pingone_risk_predictor.go index c27c4501..7a6905ba 100644 --- a/internal/connector/pingone/protect/resources/pingone_risk_predictor.go +++ b/internal/connector/pingone/protect/resources/pingone_risk_predictor.go @@ -15,123 +15,143 @@ var ( ) type PingOneRiskPredictorResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneRiskPredictorResource func RiskPredictor(clientInfo *connector.PingOneClientInfo) *PingOneRiskPredictorResource { return &PingOneRiskPredictorResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneRiskPredictorResource) ResourceType() string { + return "pingone_risk_predictor" +} + func (r *PingOneRiskPredictorResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.RiskAPIClient.RiskAdvancedPredictorsApi.ReadAllRiskPredictors(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllRiskPredictors" - - embedded, err := common.GetProtectEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportRiskPredictors() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, riskPredictor := range embedded.GetRiskPredictors() { - var ( - riskPredictorId *string - riskPredictorIdOk bool - - riskPredictorName *string - riskPredictorNameOk bool - - riskPredictorType *risk.EnumPredictorType - riskPredictorTypeOk bool - ) - - switch { - case riskPredictor.RiskPredictorAdversaryInTheMiddle != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorAdversaryInTheMiddle.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorAdversaryInTheMiddle.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorAdversaryInTheMiddle.GetTypeOk() - case riskPredictor.RiskPredictorAnonymousNetwork != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorAnonymousNetwork.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorAnonymousNetwork.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorAnonymousNetwork.GetTypeOk() - case riskPredictor.RiskPredictorBotDetection != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorBotDetection.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorBotDetection.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorBotDetection.GetTypeOk() - case riskPredictor.RiskPredictorCommon != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorCommon.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorCommon.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorCommon.GetTypeOk() - case riskPredictor.RiskPredictorComposite != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorComposite.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorComposite.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorComposite.GetTypeOk() - case riskPredictor.RiskPredictorCustom != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorCustom.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorCustom.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorCustom.GetTypeOk() - case riskPredictor.RiskPredictorDevice != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorDevice.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorDevice.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorDevice.GetTypeOk() - case riskPredictor.RiskPredictorEmailReputation != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorEmailReputation.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorEmailReputation.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorEmailReputation.GetTypeOk() - case riskPredictor.RiskPredictorGeovelocity != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorGeovelocity.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorGeovelocity.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorGeovelocity.GetTypeOk() - case riskPredictor.RiskPredictorIPReputation != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorIPReputation.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorIPReputation.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorIPReputation.GetTypeOk() - case riskPredictor.RiskPredictorUserLocationAnomaly != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorUserLocationAnomaly.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorUserLocationAnomaly.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorUserLocationAnomaly.GetTypeOk() - case riskPredictor.RiskPredictorUserRiskBehavior != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorUserRiskBehavior.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorUserRiskBehavior.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorUserRiskBehavior.GetTypeOk() - case riskPredictor.RiskPredictorVelocity != nil: - riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorVelocity.GetIdOk() - riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorVelocity.GetNameOk() - riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorVelocity.GetTypeOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneRiskPredictorResource) exportRiskPredictors() error { + iter := r.clientInfo.ApiClient.RiskAPIClient.RiskAdvancedPredictorsApi.ReadAllRiskPredictors(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllRiskPredictors", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if riskPredictorIdOk && riskPredictorNameOk && riskPredictorTypeOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Risk Predictor Type": string(*riskPredictorType), - "Risk Predictor Name": *riskPredictorName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Risk Predictor ID": *riskPredictorId, + for _, riskPredictor := range embedded.GetRiskPredictors() { + var ( + riskPredictorId *string + riskPredictorIdOk bool + riskPredictorName *string + riskPredictorNameOk bool + riskPredictorType *risk.EnumPredictorType + riskPredictorTypeOk bool + ) + + switch { + case riskPredictor.RiskPredictorAdversaryInTheMiddle != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorAdversaryInTheMiddle.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorAdversaryInTheMiddle.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorAdversaryInTheMiddle.GetTypeOk() + case riskPredictor.RiskPredictorAnonymousNetwork != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorAnonymousNetwork.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorAnonymousNetwork.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorAnonymousNetwork.GetTypeOk() + case riskPredictor.RiskPredictorBotDetection != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorBotDetection.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorBotDetection.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorBotDetection.GetTypeOk() + case riskPredictor.RiskPredictorCommon != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorCommon.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorCommon.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorCommon.GetTypeOk() + case riskPredictor.RiskPredictorComposite != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorComposite.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorComposite.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorComposite.GetTypeOk() + case riskPredictor.RiskPredictorCustom != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorCustom.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorCustom.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorCustom.GetTypeOk() + case riskPredictor.RiskPredictorDevice != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorDevice.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorDevice.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorDevice.GetTypeOk() + case riskPredictor.RiskPredictorEmailReputation != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorEmailReputation.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorEmailReputation.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorEmailReputation.GetTypeOk() + case riskPredictor.RiskPredictorGeovelocity != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorGeovelocity.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorGeovelocity.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorGeovelocity.GetTypeOk() + case riskPredictor.RiskPredictorIPReputation != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorIPReputation.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorIPReputation.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorIPReputation.GetTypeOk() + case riskPredictor.RiskPredictorUserLocationAnomaly != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorUserLocationAnomaly.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorUserLocationAnomaly.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorUserLocationAnomaly.GetTypeOk() + case riskPredictor.RiskPredictorUserRiskBehavior != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorUserRiskBehavior.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorUserRiskBehavior.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorUserRiskBehavior.GetTypeOk() + case riskPredictor.RiskPredictorVelocity != nil: + riskPredictorId, riskPredictorIdOk = riskPredictor.RiskPredictorVelocity.GetIdOk() + riskPredictorName, riskPredictorNameOk = riskPredictor.RiskPredictorVelocity.GetNameOk() + riskPredictorType, riskPredictorTypeOk = riskPredictor.RiskPredictorVelocity.GetTypeOk() + default: + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *riskPredictorType, *riskPredictorName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *riskPredictorId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if riskPredictorIdOk && riskPredictorNameOk && riskPredictorTypeOk { + r.addImportBlock(*riskPredictorId, *riskPredictorName, string(*riskPredictorType)) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneRiskPredictorResource) ResourceType() string { - return "pingone_risk_predictor" +func (r *PingOneRiskPredictorResource) addImportBlock(riskPredictorId, riskPredictorName, riskPredictorType string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Risk Predictor ID": riskPredictorId, + "Risk Predictor Name": riskPredictorName, + "Risk Predictor Type": riskPredictorType, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", riskPredictorType, riskPredictorName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, riskPredictorId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } From 6fafcec3b2f60b5cb63b72d080b37e5974e725b1 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 3 Dec 2024 16:38:45 -0600 Subject: [PATCH 6/9] Update SSO resource exports to iter iter info extraction design --- .../sso/resources/pingone_application.go | 116 ++++++---- .../pingone_application_attribute_mapping.go | 151 +++++++----- ...gone_application_flow_policy_assignment.go | 199 ++++++++++------ .../pingone_application_resource_grant.go | 198 +++++++++------- .../pingone_application_role_assignment.go | 219 +++++++++++------- .../resources/pingone_application_secret.go | 169 ++++++++------ ...e_application_sign_on_policy_assignment.go | 199 ++++++++++------ .../pingone/sso/resources/pingone_group.go | 80 ++++--- .../sso/resources/pingone_group_nesting.go | 126 ++++++---- .../pingone_group_role_assignment.go | 159 ++++++++----- .../resources/pingone_identity_provider.go | 135 ++++++----- .../pingone_identity_provider_attribute.go | 179 ++++++++------ .../sso/resources/pingone_password_policy.go | 80 ++++--- .../sso/resources/pingone_population.go | 80 ++++--- .../resources/pingone_population_default.go | 102 ++++---- .../pingone/sso/resources/pingone_resource.go | 83 ++++--- .../resources/pingone_resource_attribute.go | 154 +++++++----- .../sso/resources/pingone_resource_scope.go | 128 ++++++---- .../pingone_resource_scope_openid.go | 126 ++++++---- .../pingone_resource_scope_pingone_api.go | 134 +++++++---- .../sso/resources/pingone_schema_attribute.go | 125 ++++++---- .../sso/resources/pingone_sign_on_policy.go | 80 ++++--- .../pingone_sign_on_policy_action.go | 173 ++++++++------ 23 files changed, 1996 insertions(+), 1199 deletions(-) diff --git a/internal/connector/pingone/sso/resources/pingone_application.go b/internal/connector/pingone/sso/resources/pingone_application.go index 8d0cebba..b0010e35 100644 --- a/internal/connector/pingone/sso/resources/pingone_application.go +++ b/internal/connector/pingone/sso/resources/pingone_application.go @@ -14,75 +14,97 @@ var ( ) type PingOneApplicationResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationResource func Application(clientInfo *connector.PingOneClientInfo) *PingOneApplicationResource { return &PingOneApplicationResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationResource) ResourceType() string { + return "pingone_application" +} + func (r *PingOneApplicationResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + err := r.exportApplications() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneApplicationResource) exportApplications() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if appIdOk && appNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationOIDC != nil: + appId, appIdOk = app.ApplicationOIDC.GetIdOk() + appName, appNameOk = app.ApplicationOIDC.GetNameOk() + case app.ApplicationSAML != nil: + appId, appIdOk = app.ApplicationSAML.GetIdOk() + appName, appNameOk = app.ApplicationSAML.GetNameOk() + case app.ApplicationExternalLink != nil: + appId, appIdOk = app.ApplicationExternalLink.GetIdOk() + appName, appNameOk = app.ApplicationExternalLink.GetNameOk() + default: + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *appName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *appId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if appIdOk && appNameOk { + r.addImportBlock(*appId, *appName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneApplicationResource) ResourceType() string { - return "pingone_application" +func (r *PingOneApplicationResource) addImportBlock(appId, appName string) { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: appName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go b/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go index 05494786..3043cf9a 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go +++ b/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go @@ -14,93 +14,132 @@ var ( ) type PingOneApplicationAttributeMappingResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationAttributeMappingResource func ApplicationAttributeMapping(clientInfo *connector.PingOneClientInfo) *PingOneApplicationAttributeMappingResource { return &PingOneApplicationAttributeMappingResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationAttributeMappingResource) ResourceType() string { + return "pingone_application_attribute_mapping" +} + func (r *PingOneApplicationAttributeMappingResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + err := r.exportApplicationAttributeMappings() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneApplicationAttributeMappingResource) exportApplicationAttributeMappings() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if appIdOk && appNameOk { - apiExecuteAttributeMappingFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationAttributeMappingApi.ReadAllApplicationAttributeMappings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute - apiAttributeMappingFunctionName := "ReadAllApplicationAttributeMappings" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - attributeMappingsEmbedded, err := common.GetManagementEmbedded(apiExecuteAttributeMappingFunc, apiAttributeMappingFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationOIDC != nil: + appId, appIdOk = app.ApplicationOIDC.GetIdOk() + appName, appNameOk = app.ApplicationOIDC.GetNameOk() + case app.ApplicationSAML != nil: + appId, appIdOk = app.ApplicationSAML.GetIdOk() + appName, appNameOk = app.ApplicationSAML.GetNameOk() + default: + continue } - for _, attributeMapping := range attributeMappingsEmbedded.GetAttributes() { - if attributeMapping.ApplicationAttributeMapping == nil { - continue + if appIdOk && appNameOk { + err := r.exportApplicationAttributeMappingsByApplication(*appId, *appName) + if err != nil { + return err } + } + } + } + return nil +} + +func (r *PingOneApplicationAttributeMappingResource) exportApplicationAttributeMappingsByApplication(appId, appName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationAttributeMappingApi.ReadAllApplicationAttributeMappings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplicationAttributeMappings", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, attributeMapping := range embedded.GetAttributes() { + if attributeMapping.ApplicationAttributeMapping != nil { attributeMappingId, attributeMappingIdOk := attributeMapping.ApplicationAttributeMapping.GetIdOk() attributeMappingName, attributeMappingNameOk := attributeMapping.ApplicationAttributeMapping.GetNameOk() if attributeMappingIdOk && attributeMappingNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Attribute Mapping Name": *attributeMappingName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - "Attribute Mapping ID": *attributeMappingId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *appName, *attributeMappingName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *attributeMappingId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + r.addImportBlock(appId, appName, *attributeMappingId, *attributeMappingName) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneApplicationAttributeMappingResource) ResourceType() string { - return "pingone_application_attribute_mapping" +func (r *PingOneApplicationAttributeMappingResource) addImportBlock(appId, appName, attributeMappingId, attributeMappingName string) { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Attribute Mapping ID": attributeMappingId, + "Attribute Mapping Name": attributeMappingName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, attributeMappingName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, attributeMappingId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go b/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go index 83eb1e95..54ea9171 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go @@ -14,112 +14,159 @@ var ( ) type PingOneApplicationFlowPolicyAssignmentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationFlowPolicyAssignmentResource func ApplicationFlowPolicyAssignment(clientInfo *connector.PingOneClientInfo) *PingOneApplicationFlowPolicyAssignmentResource { return &PingOneApplicationFlowPolicyAssignmentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationFlowPolicyAssignmentResource) ResourceType() string { + return "pingone_application_flow_policy_assignment" +} + func (r *PingOneApplicationFlowPolicyAssignmentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + err := r.exportApplicationFlowPolicyAssignments() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPolicyAssignments() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if appIdOk && appNameOk { - apiExecutePoliciesFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationFlowPolicyAssignmentsApi.ReadAllFlowPolicyAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute - apiPolicyFunctionName := "ReadAllFlowPolicyAssignments" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - policyEmbedded, err := common.GetManagementEmbedded(apiExecutePoliciesFunc, apiPolicyFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationOIDC != nil: + appId, appIdOk = app.ApplicationOIDC.GetIdOk() + appName, appNameOk = app.ApplicationOIDC.GetNameOk() + case app.ApplicationSAML != nil: + appId, appIdOk = app.ApplicationSAML.GetIdOk() + appName, appNameOk = app.ApplicationSAML.GetNameOk() + case app.ApplicationExternalLink != nil: + appId, appIdOk = app.ApplicationExternalLink.GetIdOk() + appName, appNameOk = app.ApplicationExternalLink.GetNameOk() + default: + continue } - for _, flowPolicyAssignment := range policyEmbedded.GetFlowPolicyAssignments() { - flowPolicyAssignmentId, flowPolicyAssignmentIdOk := flowPolicyAssignment.GetIdOk() - flowPolicyAssignmentFlowPolicy, flowPolicyAssignmentFlowPolicyOk := flowPolicyAssignment.GetFlowPolicyOk() + if appIdOk && appNameOk { + err := r.exportApplicationFlowPolicyAssignmentsByApplication(*appId, *appName) + if err != nil { + return err + } + } + } + } - var ( - flowPolicyId *string - flowPolicyIdOk bool - ) + return nil +} - if flowPolicyAssignmentFlowPolicyOk { - flowPolicyId, flowPolicyIdOk = flowPolicyAssignmentFlowPolicy.GetIdOk() - } +func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPolicyAssignmentsByApplication(appId, appName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationFlowPolicyAssignmentsApi.ReadAllFlowPolicyAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() - if flowPolicyAssignmentIdOk && flowPolicyAssignmentFlowPolicyOk && flowPolicyIdOk { - flowPolicy, response, err := r.clientInfo.ApiClient.ManagementAPIClient.FlowPoliciesApi.ReadOneFlowPolicy(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *flowPolicyId).Execute() - err = common.HandleClientResponse(response, err, "ReadOneFlowPolicy", r.ResourceType()) - if err != nil { - return nil, err - } + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllFlowPolicyAssignments", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if flowPolicy != nil { - flowPolicyName, flowPolicyNameOk := flowPolicy.GetNameOk() - if flowPolicyNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Flow Policy Name": *flowPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - "Flow Policy Assignment ID": *flowPolicyAssignmentId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *appName, *flowPolicyName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *flowPolicyAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } + for _, flowPolicyAssignment := range embedded.GetFlowPolicyAssignments() { + flowPolicyAssignmentId, flowPolicyAssignmentIdOk := flowPolicyAssignment.GetIdOk() + flowPolicyAssignmentFlowPolicy, flowPolicyAssignmentFlowPolicyOk := flowPolicyAssignment.GetFlowPolicyOk() + + if flowPolicyAssignmentIdOk && flowPolicyAssignmentFlowPolicyOk { + flowPolicyId, flowPolicyIdOk := flowPolicyAssignmentFlowPolicy.GetIdOk() + + if flowPolicyIdOk { + err := r.exportApplicationFlowPolicyAssignmentsByFlowPolicy(appId, appName, *flowPolicyId, *flowPolicyAssignmentId) + if err != nil { + return err } } } } } - return &importBlocks, nil + return nil } -func (r *PingOneApplicationFlowPolicyAssignmentResource) ResourceType() string { - return "pingone_application_flow_policy_assignment" +func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPolicyAssignmentsByFlowPolicy(appId, appName, flowPolicyId, flowPolicyAssignmentId string) error { + flowPolicy, response, err := r.clientInfo.ApiClient.ManagementAPIClient.FlowPoliciesApi.ReadOneFlowPolicy(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, flowPolicyId).Execute() + + err = common.HandleClientResponse(response, err, "ReadOneFlowPolicy", r.ResourceType()) + if err != nil { + return err + } + + if flowPolicy != nil { + flowPolicyName, flowPolicyNameOk := flowPolicy.GetNameOk() + + if flowPolicyNameOk { + r.addImportBlock(appId, appName, flowPolicyAssignmentId, *flowPolicyName) + } + } + + return nil +} + +func (r *PingOneApplicationFlowPolicyAssignmentResource) addImportBlock(appId, appName, flowPolicyAssignmentId, flowPolicyName string) { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Flow Policy Assignment ID": flowPolicyAssignmentId, + "Flow Policy Name": flowPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, flowPolicyName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, flowPolicyAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go b/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go index f5fb8b72..009b9050 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go +++ b/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go @@ -14,112 +14,154 @@ var ( ) type PingOneApplicationResourceGrantResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationResourceGrantResource func ApplicationResourceGrant(clientInfo *connector.PingOneClientInfo) *PingOneApplicationResourceGrantResource { return &PingOneApplicationResourceGrantResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationResourceGrantResource) ResourceType() string { + return "pingone_application_resource_grant" +} + func (r *PingOneApplicationResourceGrantResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + err := r.exportApplicationResourceGrants() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationPingOnePortal != nil: - appId, appIdOk = app.ApplicationPingOnePortal.GetIdOk() - appName, appNameOk = app.ApplicationPingOnePortal.GetNameOk() - case app.ApplicationPingOneSelfService != nil: - appId, appIdOk = app.ApplicationPingOneSelfService.GetIdOk() - appName, appNameOk = app.ApplicationPingOneSelfService.GetNameOk() - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrants() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if appIdOk && appNameOk { - apiExecutePoliciesFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationResourceGrantsApi.ReadAllApplicationGrants(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute - apiApplicationGrantFunctionName := "ReadAllApplicationGrants" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - applicationEmbedded, err := common.GetManagementEmbedded(apiExecutePoliciesFunc, apiApplicationGrantFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationPingOnePortal != nil: + appId, appIdOk = app.ApplicationPingOnePortal.GetIdOk() + appName, appNameOk = app.ApplicationPingOnePortal.GetNameOk() + case app.ApplicationPingOneSelfService != nil: + appId, appIdOk = app.ApplicationPingOneSelfService.GetIdOk() + appName, appNameOk = app.ApplicationPingOneSelfService.GetNameOk() + case app.ApplicationExternalLink != nil: + appId, appIdOk = app.ApplicationExternalLink.GetIdOk() + appName, appNameOk = app.ApplicationExternalLink.GetNameOk() + default: + continue + } + + if appIdOk && appNameOk { + err := r.exportApplicationResourceGrantsByApplication(*appId, *appName) + if err != nil { + return err + } } + } + } - for _, grant := range applicationEmbedded.GetGrants() { - grantId, grantIdOk := grant.GetIdOk() - grantResource, grantResourceOk := grant.GetResourceOk() + return nil +} - var ( - grantResourceId *string - grantResourceIdOk bool - ) +func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrantsByApplication(appId, appName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationResourceGrantsApi.ReadAllApplicationGrants(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() - if grantResourceOk { - grantResourceId, grantResourceIdOk = grantResource.GetIdOk() - } + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplicationGrants", r.ResourceType()) + if err != nil { + return err + } - if grantIdOk && grantResourceOk && grantResourceIdOk { - resource, response, err := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadOneResource(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *grantResourceId).Execute() - err = common.HandleClientResponse(response, err, "ReadOneResource", r.ResourceType()) - if err != nil { - return nil, err - } - - if resource != nil { - resourceName, resourceNameOk := resource.GetNameOk() - if resourceNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Resource Name": *resourceName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - "Resource Grant ID": *grantId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *appName, *resourceName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *grantId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, grant := range embedded.GetGrants() { + grantId, grantIdOk := grant.GetIdOk() + grantResource, grantResourceOk := grant.GetResourceOk() + + if grantIdOk && grantResourceOk { + grantResourceId, grantResourceIdOk := grantResource.GetIdOk() + + if grantResourceIdOk { + r.exportApplicationResourceGrantsByResource(appId, appName, *grantId, *grantResourceId) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneApplicationResourceGrantResource) ResourceType() string { - return "pingone_application_resource_grant" +func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrantsByResource(appId, appName, grantId, grantResourceId string) error { + resource, response, err := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadOneResource(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, grantResourceId).Execute() + err = common.HandleClientResponse(response, err, "ReadOneResource", r.ResourceType()) + if err != nil { + return err + } + + if resource != nil { + resourceName, resourceNameOk := resource.GetNameOk() + if resourceNameOk { + r.addImportBlock(appId, appName, grantId, *resourceName) + } + } + + return nil +} + +func (r *PingOneApplicationResourceGrantResource) addImportBlock(appId, appName, grantId, resourceName string) { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Application Resource Grant ID": grantId, + "Application Resource Name": resourceName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, resourceName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, grantId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go b/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go index 2622cf95..178a3c89 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go @@ -15,115 +15,170 @@ var ( ) type PingOneApplicationRoleAssignmentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationRoleAssignmentResource func ApplicationRoleAssignment(clientInfo *connector.PingOneClientInfo) *PingOneApplicationRoleAssignmentResource { return &PingOneApplicationRoleAssignmentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationRoleAssignmentResource) ResourceType() string { + return "pingone_application_role_assignment" +} + func (r *PingOneApplicationRoleAssignmentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + err := r.exportApplicationRoleAssignments() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - appAccessControlRole *management.ApplicationAccessControlRole - appAccessControlRoleOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - if app.ApplicationOIDC.AccessControl != nil { - appAccessControlRole, appAccessControlRoleOk = app.ApplicationOIDC.AccessControl.GetRoleOk() - } - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - if app.ApplicationSAML.AccessControl != nil { - appAccessControlRole, appAccessControlRoleOk = app.ApplicationSAML.AccessControl.GetRoleOk() + return r.importBlocks, nil +} + +func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignments() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + appAccessControlRole *management.ApplicationAccessControlRole + appAccessControlRoleOk bool + ) + + switch { + case app.ApplicationOIDC != nil: + appId, appIdOk = app.ApplicationOIDC.GetIdOk() + appName, appNameOk = app.ApplicationOIDC.GetNameOk() + if app.ApplicationOIDC.AccessControl != nil { + appAccessControlRole, appAccessControlRoleOk = app.ApplicationOIDC.AccessControl.GetRoleOk() + } + case app.ApplicationSAML != nil: + appId, appIdOk = app.ApplicationSAML.GetIdOk() + appName, appNameOk = app.ApplicationSAML.GetNameOk() + if app.ApplicationSAML.AccessControl != nil { + appAccessControlRole, appAccessControlRoleOk = app.ApplicationSAML.AccessControl.GetRoleOk() + } + case app.ApplicationExternalLink != nil: + appId, appIdOk = app.ApplicationExternalLink.GetIdOk() + appName, appNameOk = app.ApplicationExternalLink.GetNameOk() + if app.ApplicationExternalLink.AccessControl != nil { + appAccessControlRole, appAccessControlRoleOk = app.ApplicationExternalLink.AccessControl.GetRoleOk() + } + default: + continue } - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - if app.ApplicationExternalLink.AccessControl != nil { - appAccessControlRole, appAccessControlRoleOk = app.ApplicationExternalLink.AccessControl.GetRoleOk() + + if appIdOk && appNameOk && appAccessControlRoleOk { + if appAccessControlRole.GetType() != management.ENUMAPPLICATIONACCESSCONTROLTYPE_ADMIN_USERS_ONLY { + continue + } + + err := r.exportApplicationRoleAssignmentsByApplication(*appId, *appName) + if err != nil { + return err + } } - default: - continue } + } - if appIdOk && appNameOk && appAccessControlRoleOk && appAccessControlRole.GetType() == management.ENUMAPPLICATIONACCESSCONTROLTYPE_ADMIN_USERS_ONLY { - apiExecutePoliciesFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationRoleAssignmentsApi.ReadApplicationRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute - apiApplicationRoleAssignmentsFunctionName := "ReadApplicationRoleAssignments" + return nil +} - appRoleAssignmentsEmbedded, err := common.GetManagementEmbedded(apiExecutePoliciesFunc, apiApplicationRoleAssignmentsFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } +func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignmentsByApplication(appId, appName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationRoleAssignmentsApi.ReadApplicationRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadApplicationRoleAssignments", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for roleAssignmentIndex, roleAssignment := range appRoleAssignmentsEmbedded.GetRoleAssignments() { - roleAssignmentId, roleAssignmentIdOk := roleAssignment.GetIdOk() - roleAssignmentRole, roleAssignmentRoleOk := roleAssignment.GetRoleOk() - if roleAssignmentIdOk && roleAssignmentRoleOk { - roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk() - if roleAssignmentRoleIdOk { - apiRole, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, *roleAssignmentRoleId).Execute() - err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) - if err != nil { - return nil, err - } - if apiRole != nil { - apiRoleName, apiRoleNameOk := apiRole.GetNameOk() - if apiRoleNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Role Name": string(*apiRoleName), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - "Role Assignment ID": *roleAssignmentId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%d", *appName, *apiRoleName, (roleAssignmentIndex + 1)), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *roleAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } - } + for _, roleAssignment := range embedded.GetRoleAssignments() { + roleAssignmentId, roleAssignmentIdOk := roleAssignment.GetIdOk() + roleAssignmentRole, roleAssignmentRoleOk := roleAssignment.GetRoleOk() + if roleAssignmentIdOk && roleAssignmentRoleOk { + roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk() + if roleAssignmentRoleIdOk { + err := r.exportApplicationRoleAssignmentsByRole(appId, appName, *roleAssignmentId, *roleAssignmentRoleId) + if err != nil { + return err } } } } } - return &importBlocks, nil + return nil } -func (r *PingOneApplicationRoleAssignmentResource) ResourceType() string { - return "pingone_application_role_assignment" +func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignmentsByRole(appId, appName, roleAssignmentId, roleId string) error { + apiRole, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, roleId).Execute() + err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) + if err != nil { + return err + } + + if apiRole != nil { + apiRoleName, apiRoleNameOk := apiRole.GetNameOk() + if apiRoleNameOk { + r.addImportBlock(appId, appName, roleAssignmentId, string(*apiRoleName)) + } + } + + return nil +} + +func (r *PingOneApplicationRoleAssignmentResource) addImportBlock(appId, appName, roleAssignmentId, roleName string) { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Application Role Assignment ID": roleAssignmentId, + "Application Role Name": roleName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", appName, roleName, roleAssignmentId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, roleAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_secret.go b/internal/connector/pingone/sso/resources/pingone_application_secret.go index 37742089..8204b50c 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_secret.go +++ b/internal/connector/pingone/sso/resources/pingone_application_secret.go @@ -14,102 +14,135 @@ var ( ) type PingOneApplicationSecretResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationSecretResource func ApplicationSecret(clientInfo *connector.PingOneClientInfo) *PingOneApplicationSecretResource { return &PingOneApplicationSecretResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationSecretResource) ResourceType() string { + return "pingone_application_secret" +} + func (r *PingOneApplicationSecretResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportApplicationSecrets() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneApplicationSecretResource) exportApplicationSecrets() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err } - if appIdOk && appNameOk { - // The platform enforces that worker apps cannot read their own secret - // Make sure we can read the secret before adding it to the import blocks - _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationSecretApi.ReadApplicationSecret(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute() - - // If the appId is the same as the worker ID, make sure the API response is a 403 and ignore the error - if *appId == *r.clientInfo.ApiClientId { - if response.StatusCode == 403 { - continue - } else { - return nil, fmt.Errorf("ReadApplicationSecret: Expected response code 403 - worker apps cannot read their own secret, actual response code: %d", response.StatusCode) - } - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - // Use output package to warn the user of any errors or non-200 response codes - // Expected behavior in this case is to skip the resource, and continue exporting the other resources - defer response.Body.Close() + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if err != nil { - l.Warn().Err(err).Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", *appName, apiFunctionName, response.Status, response.Body) + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationOIDC != nil: + appId, appIdOk = app.ApplicationOIDC.GetIdOk() + appName, appNameOk = app.ApplicationOIDC.GetNameOk() + case app.ApplicationSAML != nil: + appId, appIdOk = app.ApplicationSAML.GetIdOk() + appName, appNameOk = app.ApplicationSAML.GetNameOk() + case app.ApplicationExternalLink != nil: + appId, appIdOk = app.ApplicationExternalLink.GetIdOk() + appName, appNameOk = app.ApplicationExternalLink.GetNameOk() + default: continue } - if response.StatusCode >= 300 { - l.Warn().Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", *appName, apiFunctionName, response.Status, response.Body) - continue + if appIdOk && appNameOk { + err := r.exportApplicationSecretsByApplication(*appId, *appName) + if err != nil { + return err + } } + } + } - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - } + return nil +} + +func (r *PingOneApplicationSecretResource) exportApplicationSecretsByApplication(appId, appName string) error { + l := logger.Get() - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_secret", *appName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *appId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + // The platform enforces that worker apps cannot read their own secret + // Make sure we can read the secret before adding it to the import blocks + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationSecretApi.ReadApplicationSecret(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() + + // If the appId is the same as the worker ID, make sure the API response is a 403 and ignore the error + if appId == *r.clientInfo.ApiClientId { + if response.StatusCode == 403 { + return nil + } else { + return fmt.Errorf("ReadApplicationSecret: Expected response code 403 - worker apps cannot read their own secret, actual response code: %d", response.StatusCode) } } - return &importBlocks, nil + // Use output package to warn the user of any errors or non-200 response codes + // Expected behavior in this case is to skip the resource, and continue exporting the other resources + defer response.Body.Close() + + if err != nil { + l.Warn().Err(err).Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", appName, "ReadApplicationSecret", response.Status, response.Body) + return nil + } + + if response.StatusCode >= 300 { + l.Warn().Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", appName, "ReadApplicationSecret", response.Status, response.Body) + return nil + } + + r.addImportBlock(appId, appName) + + return nil } -func (r *PingOneApplicationSecretResource) ResourceType() string { - return "pingone_application_secret" +func (r *PingOneApplicationSecretResource) addImportBlock(appId, appName string) { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_secret", appName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go b/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go index 5c04d18d..2b3861a0 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go @@ -14,113 +14,158 @@ var ( ) type PingOneApplicationSignOnPolicyAssignmentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneApplicationSignOnPolicyAssignmentResource func ApplicationSignOnPolicyAssignment(clientInfo *connector.PingOneClientInfo) *PingOneApplicationSignOnPolicyAssignmentResource { return &PingOneApplicationSignOnPolicyAssignmentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneApplicationSignOnPolicyAssignmentResource) ResourceType() string { + return "pingone_application_sign_on_policy_assignment" +} + func (r *PingOneApplicationSignOnPolicyAssignmentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteApplicationsFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiApplicationFunctionName := "ReadAllApplications" - - embedded, err := common.GetManagementEmbedded(apiExecuteApplicationsFunc, apiApplicationFunctionName, r.ResourceType()) + err := r.exportApplicationSignOnPolicyAssignments() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, app := range embedded.GetApplications() { - var ( - appId *string - appIdOk bool - appName *string - appNameOk bool - ) - - switch { - case app.ApplicationOIDC != nil: - appId, appIdOk = app.ApplicationOIDC.GetIdOk() - appName, appNameOk = app.ApplicationOIDC.GetNameOk() - case app.ApplicationSAML != nil: - appId, appIdOk = app.ApplicationSAML.GetIdOk() - appName, appNameOk = app.ApplicationSAML.GetNameOk() - case app.ApplicationExternalLink != nil: - appId, appIdOk = app.ApplicationExternalLink.GetIdOk() - appName, appNameOk = app.ApplicationExternalLink.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSignOnPolicyAssignments() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if appIdOk && appNameOk { - apiExecutePoliciesFunc := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationSignOnPolicyAssignmentsApi.ReadAllSignOnPolicyAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *appId).Execute - apiPolicyFunctionName := "ReadAllSignOnPolicyAssignments" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - signOnPolicyEmbedded, err := common.GetManagementEmbedded(apiExecutePoliciesFunc, apiPolicyFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, app := range embedded.GetApplications() { + var ( + appId *string + appIdOk bool + appName *string + appNameOk bool + ) + + switch { + case app.ApplicationOIDC != nil: + appId, appIdOk = app.ApplicationOIDC.GetIdOk() + appName, appNameOk = app.ApplicationOIDC.GetNameOk() + case app.ApplicationSAML != nil: + appId, appIdOk = app.ApplicationSAML.GetIdOk() + appName, appNameOk = app.ApplicationSAML.GetNameOk() + case app.ApplicationExternalLink != nil: + appId, appIdOk = app.ApplicationExternalLink.GetIdOk() + appName, appNameOk = app.ApplicationExternalLink.GetNameOk() + default: + continue } - for _, signOnPolicyAssignment := range signOnPolicyEmbedded.GetSignOnPolicyAssignments() { - signOnPolicyAssignmentId, signOnPolicyAssignmentIdOk := signOnPolicyAssignment.GetIdOk() - signOnPolicyAssignmentSignOnPolicy, signOnPolicyAssignmentSignOnPolicyOk := signOnPolicyAssignment.GetSignOnPolicyOk() + if appIdOk && appNameOk { + err := r.exportApplicationSignOnPolicyAssignmentsByApplication(*appId, *appName) + if err != nil { + return err + } + } + } + } - var ( - signOnPolicyAssignmentSignOnPolicyId *string - signOnPolicyAssignmentSignOnPolicyIdOk bool - ) + return nil +} - if signOnPolicyAssignmentSignOnPolicyOk { - signOnPolicyAssignmentSignOnPolicyId, signOnPolicyAssignmentSignOnPolicyIdOk = signOnPolicyAssignmentSignOnPolicy.GetIdOk() - } +func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSignOnPolicyAssignmentsByApplication(appId, appName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationSignOnPolicyAssignmentsApi.ReadAllSignOnPolicyAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() - if signOnPolicyAssignmentIdOk && signOnPolicyAssignmentSignOnPolicyOk && signOnPolicyAssignmentSignOnPolicyIdOk { - signOnPolicy, response, err := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadOneSignOnPolicy(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *signOnPolicyAssignmentSignOnPolicyId).Execute() - err = common.HandleClientResponse(response, err, "ReadOneSignOnPolicy", r.ResourceType()) - if err != nil { - return nil, err - } + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicyAssignments", r.ResourceType()) + if err != nil { + return err + } - if signOnPolicy != nil { - signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() - - if signOnPolicyNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application Name": *appName, - "Sign On Policy Name": *signOnPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Application ID": *appId, - "Sign On Policy Assignment ID": *signOnPolicyAssignmentId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *appName, *signOnPolicyName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *appId, *signOnPolicyAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, signOnPolicyAssignment := range embedded.GetSignOnPolicyAssignments() { + signOnPolicyAssignmentId, signOnPolicyAssignmentIdOk := signOnPolicyAssignment.GetIdOk() + signOnPolicyAssignmentSignOnPolicy, signOnPolicyAssignmentSignOnPolicyOk := signOnPolicyAssignment.GetSignOnPolicyOk() + + if signOnPolicyAssignmentIdOk && signOnPolicyAssignmentSignOnPolicyOk { + signOnPolicyAssignmentSignOnPolicyId, signOnPolicyAssignmentSignOnPolicyIdOk := signOnPolicyAssignmentSignOnPolicy.GetIdOk() + + if signOnPolicyAssignmentSignOnPolicyIdOk { + err := r.exportApplicationSignOnPolicyAssignmentsBySignOnPolicy(appId, appName, *signOnPolicyAssignmentId, *signOnPolicyAssignmentSignOnPolicyId) + if err != nil { + return err } } } } } - return &importBlocks, nil + return nil } -func (r *PingOneApplicationSignOnPolicyAssignmentResource) ResourceType() string { - return "pingone_application_sign_on_policy_assignment" +func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSignOnPolicyAssignmentsBySignOnPolicy(appId, appName, signOnPolicyAssignmentId, signOnPolicyId string) error { + signOnPolicy, response, err := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadOneSignOnPolicy(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, signOnPolicyId).Execute() + err = common.HandleClientResponse(response, err, "ReadOneSignOnPolicy", r.ResourceType()) + if err != nil { + return err + } + + if signOnPolicy != nil { + signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() + + if signOnPolicyNameOk { + r.addImportBlock(appId, appName, signOnPolicyAssignmentId, *signOnPolicyName) + } + } + + return nil +} + +func (r *PingOneApplicationSignOnPolicyAssignmentResource) addImportBlock(appId, appName, signOnPolicyAssignmentId, signOnPolicyName string) { + commentData := map[string]string{ + "Resource Type": r.ResourceType(), + "Application ID": appId, + "Application Name": appName, + "Application Sign-On Policy Assignment ID": signOnPolicyAssignmentId, + "Application Sign-On Policy Name": signOnPolicyName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, signOnPolicyName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, signOnPolicyAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_group.go b/internal/connector/pingone/sso/resources/pingone_group.go index 12def755..55478878 100644 --- a/internal/connector/pingone/sso/resources/pingone_group.go +++ b/internal/connector/pingone/sso/resources/pingone_group.go @@ -14,57 +14,79 @@ var ( ) type PingOneGroupResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneGroupResource func Group(clientInfo *connector.PingOneClientInfo) *PingOneGroupResource { return &PingOneGroupResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneGroupResource) ResourceType() string { + return "pingone_group" +} + func (r *PingOneGroupResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllGroups" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportGroups() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneGroupResource) exportGroups() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, group := range embedded.GetGroups() { - groupId, groupIdOk := group.GetIdOk() - groupName, groupNameOk := group.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGroups", r.ResourceType()) + if err != nil { + return err + } - if groupIdOk && groupNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Group Name": *groupName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Group ID": *groupId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *groupName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *groupId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, group := range embedded.GetGroups() { + groupId, groupIdOk := group.GetIdOk() + groupName, groupNameOk := group.GetNameOk() + + if groupIdOk && groupNameOk { + r.addImportBlock(*groupId, *groupName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneGroupResource) ResourceType() string { - return "pingone_group" +func (r *PingOneGroupResource) addImportBlock(groupId, groupName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Group ID": groupId, + "Group Name": groupName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: groupName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, groupId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_group_nesting.go b/internal/connector/pingone/sso/resources/pingone_group_nesting.go index 88703517..25b2d860 100644 --- a/internal/connector/pingone/sso/resources/pingone_group_nesting.go +++ b/internal/connector/pingone/sso/resources/pingone_group_nesting.go @@ -14,73 +14,115 @@ var ( ) type PingOneGroupNestingResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneGroupNestingResource func GroupNesting(clientInfo *connector.PingOneClientInfo) *PingOneGroupNestingResource { return &PingOneGroupNestingResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneGroupNestingResource) ResourceType() string { + return "pingone_group_nesting" +} + func (r *PingOneGroupNestingResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllGroups" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportGroupNesting() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneGroupNestingResource) exportGroupNesting() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGroups", r.ResourceType()) + if err != nil { + return err + } - for _, parentGroup := range embedded.GetGroups() { - parentGroupId, parentGroupIdOk := parentGroup.GetIdOk() - parentGroupName, parentGroupNameOk := parentGroup.GetNameOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if parentGroupIdOk && parentGroupNameOk { - apiGroupNestingExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadGroupNesting(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *parentGroupId).Execute - apiGroupNestingFunctionName := "ReadGroupNesting" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - embeddedGroupNesting, err := common.GetManagementEmbedded(apiGroupNestingExecuteFunc, apiGroupNestingFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + for _, parentGroup := range embedded.GetGroups() { + parentGroupId, parentGroupIdOk := parentGroup.GetIdOk() + parentGroupName, parentGroupNameOk := parentGroup.GetNameOk() - for _, nestedGroup := range embeddedGroupNesting.GetGroupMemberships() { - nestedGroupId, nestedGroupIdOk := nestedGroup.GetIdOk() - nestedGroupName, nestedGroupNameOk := nestedGroup.GetNameOk() - if nestedGroupIdOk && nestedGroupNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Parent Group Name": *parentGroupName, - "Nested Group Name": *nestedGroupName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Parent Group ID": *parentGroupId, - "Nested Group ID": *nestedGroupId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *parentGroupName, *nestedGroupName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *parentGroupId, *nestedGroupId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if parentGroupIdOk && parentGroupNameOk { + err := r.exportGroupNestingByParentGroup(*parentGroupId, *parentGroupName) + if err != nil { + return err } } } } - return &importBlocks, nil + return nil } -func (r *PingOneGroupNestingResource) ResourceType() string { - return "pingone_group_nesting" +func (r *PingOneGroupNestingResource) exportGroupNestingByParentGroup(parentGroupId, parentGroupName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadGroupNesting(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, parentGroupId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadGroupNesting", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, nestedGroup := range embedded.GetGroupMemberships() { + nestedGroupId, nestedGroupIdOk := nestedGroup.GetIdOk() + nestedGroupName, nestedGroupNameOk := nestedGroup.GetNameOk() + + if nestedGroupIdOk && nestedGroupNameOk { + r.addImportBlock(parentGroupId, parentGroupName, *nestedGroupId, *nestedGroupName) + } + } + } + + return nil +} + +func (r *PingOneGroupNestingResource) addImportBlock(parentGroupId, parentGroupName, nestedGroupId, nestedGroupName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Nested Group ID": nestedGroupId, + "Nested Group Name": nestedGroupName, + "Parent Group ID": parentGroupId, + "Parent Group Name": parentGroupName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", parentGroupName, nestedGroupName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, parentGroupId, nestedGroupId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go b/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go index a275beae..b17c9f20 100644 --- a/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go @@ -14,95 +14,138 @@ var ( ) type PingOneGroupRoleAssignmentResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneGroupRoleAssignmentResource func GroupRoleAssignment(clientInfo *connector.PingOneClientInfo) *PingOneGroupRoleAssignmentResource { return &PingOneGroupRoleAssignmentResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneGroupRoleAssignmentResource) ResourceType() string { + return "pingone_group_role_assignment" +} + func (r *PingOneGroupRoleAssignmentResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllGroups" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportGroupRoleAssignments() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignments() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGroups", r.ResourceType()) + if err != nil { + return err + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, group := range embedded.GetGroups() { - groupId, groupIdOk := group.GetIdOk() - groupName, groupNameOk := group.GetNameOk() + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if groupIdOk && groupNameOk { - apiGroupRoleAssignmentExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.GroupRoleAssignmentsApi.ReadGroupRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *groupId).Execute - apiGroupRoleAssignmentFunctionName := "ReadGroupRoleAssignments" + for _, group := range embedded.GetGroups() { + groupId, groupIdOk := group.GetIdOk() + groupName, groupNameOk := group.GetNameOk() - embeddedGroupRoleAssignments, err := common.GetManagementEmbedded(apiGroupRoleAssignmentExecuteFunc, apiGroupRoleAssignmentFunctionName, r.ResourceType()) - if err != nil { - return nil, err + if groupIdOk && groupNameOk { + err := r.exportGroupRoleAssignmentsByGroup(*groupId, *groupName) + if err != nil { + return err + } } + } + } - for groupRoleAssignmentIndex, groupRoleAssignment := range embeddedGroupRoleAssignments.GetRoleAssignments() { - groupRoleAssignmentId, groupRoleAssignmentIdOk := groupRoleAssignment.GetIdOk() - groupRoleAssignmentRole, groupRoleAssignmentRoleOk := groupRoleAssignment.GetRoleOk() + return nil +} - var ( - groupRoleAssignmentRoleId *string - groupRoleAssignmentRoleIdOk bool - ) +func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignmentsByGroup(groupId string, groupName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupRoleAssignmentsApi.ReadGroupRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, groupId).Execute() - if groupRoleAssignmentRoleOk { - groupRoleAssignmentRoleId, groupRoleAssignmentRoleIdOk = groupRoleAssignmentRole.GetIdOk() - } + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadGroupRoleAssignments", r.ResourceType()) + if err != nil { + return err + } - if groupRoleAssignmentIdOk && groupRoleAssignmentRoleOk && groupRoleAssignmentRoleIdOk { - role, response, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, *groupRoleAssignmentRoleId).Execute() - err = common.HandleClientResponse(response, err, "ReadOneRole", r.ResourceType()) - if err != nil { - return nil, err - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if role != nil { - roleName, roleNameOk := role.GetNameOk() - - if roleNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Group Name": *groupName, - "Role Name": string(*roleName), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Group ID": *groupId, - "Group Role Assignment ID": *groupRoleAssignmentId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%d", *groupName, *roleName, (groupRoleAssignmentIndex + 1)), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *groupId, *groupRoleAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } + for _, groupRoleAssignment := range embedded.GetRoleAssignments() { + groupRoleAssignmentId, groupRoleAssignmentIdOk := groupRoleAssignment.GetIdOk() + groupRoleAssignmentRole, groupRoleAssignmentRoleOk := groupRoleAssignment.GetRoleOk() + + if groupRoleAssignmentIdOk && groupRoleAssignmentRoleOk { + groupRoleAssignmentRoleId, groupRoleAssignmentRoleIdOk := groupRoleAssignmentRole.GetIdOk() + if groupRoleAssignmentRoleIdOk { + err := r.exportGroupRoleAssignmentsByRole(groupId, groupName, *groupRoleAssignmentId, *groupRoleAssignmentRoleId) + if err != nil { + return err } } } } } - return &importBlocks, nil + return nil } -func (r *PingOneGroupRoleAssignmentResource) ResourceType() string { - return "pingone_group_role_assignment" +func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignmentsByRole(groupId, groupName, groupRoleAssignmentId, roleId string) error { + apiRole, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, roleId).Execute() + err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) + if err != nil { + return err + } + + if apiRole != nil { + apiRoleName, apiRoleNameOk := apiRole.GetNameOk() + if apiRoleNameOk { + r.addImportBlock(groupId, groupName, groupRoleAssignmentId, string(*apiRoleName)) + } + } + + return nil +} + +func (r *PingOneGroupRoleAssignmentResource) addImportBlock(groupId, groupName, groupRoleAssignmentId, roleName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Group ID": groupId, + "Group Name": groupName, + "Group Role Assignment ID": groupRoleAssignmentId, + "Group Role Name": roleName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", groupName, roleName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, groupId, groupRoleAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_identity_provider.go b/internal/connector/pingone/sso/resources/pingone_identity_provider.go index 6469e0d1..df527871 100644 --- a/internal/connector/pingone/sso/resources/pingone_identity_provider.go +++ b/internal/connector/pingone/sso/resources/pingone_identity_provider.go @@ -1,8 +1,6 @@ package resources import ( - "fmt" - "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -14,84 +12,107 @@ var ( ) type PingOneIdentityProviderResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneIdentityProviderResource func IdentityProvider(clientInfo *connector.PingOneClientInfo) *PingOneIdentityProviderResource { return &PingOneIdentityProviderResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneIdentityProviderResource) ResourceType() string { + return "pingone_identity_provider" +} + func (r *PingOneIdentityProviderResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - apiExecuteIdentityProvidersFunc := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiIdentityProviderFunctionName := "ReadAllIdentityProviders" - - embedded, err := common.GetManagementEmbedded(apiExecuteIdentityProvidersFunc, apiIdentityProviderFunctionName, r.ResourceType()) + err := r.exportIdentityProviders() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, idp := range embedded.GetIdentityProviders() { - var ( - idpId *string - idpIdOk bool - idpName *string - idpNameOk bool - ) - - switch { - case idp.IdentityProviderApple != nil: - idpId, idpIdOk = idp.IdentityProviderApple.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderApple.GetNameOk() - case idp.IdentityProviderClientIDClientSecret != nil: - idpId, idpIdOk = idp.IdentityProviderClientIDClientSecret.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderClientIDClientSecret.GetNameOk() - case idp.IdentityProviderFacebook != nil: - idpId, idpIdOk = idp.IdentityProviderFacebook.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderFacebook.GetNameOk() - case idp.IdentityProviderOIDC != nil: - idpId, idpIdOk = idp.IdentityProviderOIDC.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderOIDC.GetNameOk() - case idp.IdentityProviderPaypal != nil: - idpId, idpIdOk = idp.IdentityProviderPaypal.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderPaypal.GetNameOk() - case idp.IdentityProviderSAML != nil: - idpId, idpIdOk = idp.IdentityProviderSAML.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderSAML.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneIdentityProviderResource) exportIdentityProviders() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllIdentityProviders", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } - if idpIdOk && idpNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Identity Provider Name": *idpName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Identity Provider ID": *idpId, + for _, idp := range embedded.GetIdentityProviders() { + var ( + idpId *string + idpIdOk bool + idpName *string + idpNameOk bool + ) + + switch { + case idp.IdentityProviderApple != nil: + idpId, idpIdOk = idp.IdentityProviderApple.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderApple.GetNameOk() + case idp.IdentityProviderClientIDClientSecret != nil: + idpId, idpIdOk = idp.IdentityProviderClientIDClientSecret.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderClientIDClientSecret.GetNameOk() + case idp.IdentityProviderFacebook != nil: + idpId, idpIdOk = idp.IdentityProviderFacebook.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderFacebook.GetNameOk() + case idp.IdentityProviderOIDC != nil: + idpId, idpIdOk = idp.IdentityProviderOIDC.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderOIDC.GetNameOk() + case idp.IdentityProviderPaypal != nil: + idpId, idpIdOk = idp.IdentityProviderPaypal.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderPaypal.GetNameOk() + case idp.IdentityProviderSAML != nil: + idpId, idpIdOk = idp.IdentityProviderSAML.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderSAML.GetNameOk() + default: + continue } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *idpName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *idpId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if idpIdOk && idpNameOk { + r.addImportBlock(*idpId, *idpName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneIdentityProviderResource) ResourceType() string { - return "pingone_identity_provider" +func (r *PingOneIdentityProviderResource) addImportBlock(idpId, idpName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Identity Provider ID": idpId, + "Identity Provider Name": idpName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: idpName, + ResourceID: idpId, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go b/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go index 9f6b7ad6..e94fefb8 100644 --- a/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go @@ -14,100 +14,143 @@ var ( ) type PingOneIdentityProviderAttributeResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneIdentityProviderAttributeResource func IdentityProviderAttribute(clientInfo *connector.PingOneClientInfo) *PingOneIdentityProviderAttributeResource { return &PingOneIdentityProviderAttributeResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneIdentityProviderAttributeResource) ResourceType() string { + return "pingone_identity_provider_attribute" +} + func (r *PingOneIdentityProviderAttributeResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - idpsApiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - idpsApiFunctionName := "ReadAllIdentityProviders" - - embedded, err := common.GetManagementEmbedded(idpsApiExecuteFunc, idpsApiFunctionName, r.ResourceType()) + err := r.exportIdentityProviderAttributes() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} - - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) - - for _, idp := range embedded.GetIdentityProviders() { - var ( - idpId *string - idpIdOk bool - idpName *string - idpNameOk bool - ) - - switch { - case idp.IdentityProviderApple != nil: - idpId, idpIdOk = idp.IdentityProviderApple.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderApple.GetNameOk() - case idp.IdentityProviderClientIDClientSecret != nil: - idpId, idpIdOk = idp.IdentityProviderClientIDClientSecret.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderClientIDClientSecret.GetNameOk() - case idp.IdentityProviderFacebook != nil: - idpId, idpIdOk = idp.IdentityProviderFacebook.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderFacebook.GetNameOk() - case idp.IdentityProviderOIDC != nil: - idpId, idpIdOk = idp.IdentityProviderOIDC.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderOIDC.GetNameOk() - case idp.IdentityProviderPaypal != nil: - idpId, idpIdOk = idp.IdentityProviderPaypal.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderPaypal.GetNameOk() - case idp.IdentityProviderSAML != nil: - idpId, idpIdOk = idp.IdentityProviderSAML.GetIdOk() - idpName, idpNameOk = idp.IdentityProviderSAML.GetNameOk() - default: - continue + return r.importBlocks, nil +} + +func (r *PingOneIdentityProviderAttributeResource) exportIdentityProviderAttributes() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllIdentityProviders", r.ResourceType()) + if err != nil { + return err } - if idpIdOk && idpNameOk { - apiExecuteIdpAttributesFunc := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProviderAttributesApi.ReadAllIdentityProviderAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *idpId).Execute - apiIdpAttributesFunctionName := "ReadAllIdentityProviderAttributes" + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - idpAttributesEmbedded, err := common.GetManagementEmbedded(apiExecuteIdpAttributesFunc, apiIdpAttributesFunctionName, r.ResourceType()) - if err != nil { - return nil, err + for _, idp := range embedded.GetIdentityProviders() { + var ( + idpId *string + idpIdOk bool + idpName *string + idpNameOk bool + ) + + switch { + case idp.IdentityProviderApple != nil: + idpId, idpIdOk = idp.IdentityProviderApple.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderApple.GetNameOk() + case idp.IdentityProviderClientIDClientSecret != nil: + idpId, idpIdOk = idp.IdentityProviderClientIDClientSecret.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderClientIDClientSecret.GetNameOk() + case idp.IdentityProviderFacebook != nil: + idpId, idpIdOk = idp.IdentityProviderFacebook.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderFacebook.GetNameOk() + case idp.IdentityProviderOIDC != nil: + idpId, idpIdOk = idp.IdentityProviderOIDC.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderOIDC.GetNameOk() + case idp.IdentityProviderPaypal != nil: + idpId, idpIdOk = idp.IdentityProviderPaypal.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderPaypal.GetNameOk() + case idp.IdentityProviderSAML != nil: + idpId, idpIdOk = idp.IdentityProviderSAML.GetIdOk() + idpName, idpNameOk = idp.IdentityProviderSAML.GetNameOk() + default: + continue } - for _, idpAttribute := range idpAttributesEmbedded.GetAttributes() { - idpAttributeId, idpAttributeIdOk := idpAttribute.IdentityProviderAttribute.GetIdOk() - idpAttributeName, idpAttributeNameOk := idpAttribute.IdentityProviderAttribute.GetNameOk() - if idpAttributeIdOk && idpAttributeNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Identity Provider Name": *idpName, - "Identity Provider Attribute Name": *idpAttributeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Identity Provider ID": *idpId, - "Identity Provider Attribute ID": *idpAttributeId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *idpName, *idpAttributeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *idpId, *idpAttributeId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if idpIdOk && idpNameOk { + err := r.exportIdentityProviderAttributesByIdentityProvider(*idpId, *idpName) + if err != nil { + return err } } } } - return &importBlocks, nil + return nil } -func (r *PingOneIdentityProviderAttributeResource) ResourceType() string { - return "pingone_identity_provider_attribute" +func (r *PingOneIdentityProviderAttributeResource) exportIdentityProviderAttributesByIdentityProvider(idpId, idpName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProviderAttributesApi.ReadAllIdentityProviderAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, idpId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllIdentityProviderAttributes", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, idpAttribute := range embedded.GetAttributes() { + idpAttributeId, idpAttributeIdOk := idpAttribute.IdentityProviderAttribute.GetIdOk() + idpAttributeName, idpAttributeNameOk := idpAttribute.IdentityProviderAttribute.GetNameOk() + + if idpAttributeIdOk && idpAttributeNameOk { + r.addImportBlock(idpId, idpName, *idpAttributeName, *idpAttributeId) + } + } + } + + return nil +} + +func (r *PingOneIdentityProviderAttributeResource) addImportBlock(idpId, idpName, idpAttributeName, idpAttributeId string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Identity Provider Attribute ID": idpAttributeId, + "Identity Provider Attribute Name": idpAttributeName, + "Identity Provider ID": idpId, + "Identity Provider Name": idpName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", idpName, idpAttributeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, idpId, idpAttributeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_password_policy.go b/internal/connector/pingone/sso/resources/pingone_password_policy.go index e4daf906..8c3c6395 100644 --- a/internal/connector/pingone/sso/resources/pingone_password_policy.go +++ b/internal/connector/pingone/sso/resources/pingone_password_policy.go @@ -14,57 +14,79 @@ var ( ) type PingOnePasswordPolicyResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOnePasswordPolicyResource func PasswordPolicy(clientInfo *connector.PingOneClientInfo) *PingOnePasswordPolicyResource { return &PingOnePasswordPolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOnePasswordPolicyResource) ResourceType() string { + return "pingone_password_policy" +} + func (r *PingOnePasswordPolicyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.PasswordPoliciesApi.ReadAllPasswordPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllPasswordPolicies" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportPasswordPolicies() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOnePasswordPolicyResource) exportPasswordPolicies() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.PasswordPoliciesApi.ReadAllPasswordPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, passwordPolicy := range embedded.GetPasswordPolicies() { - passwordPolicyId, passwordPolicyIdOk := passwordPolicy.GetIdOk() - passwordPolicyName, passwordPolicyNameOk := passwordPolicy.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPasswordPolicies", r.ResourceType()) + if err != nil { + return err + } - if passwordPolicyIdOk && passwordPolicyNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Password Policy Name": *passwordPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Password Policy ID": *passwordPolicyId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *passwordPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *passwordPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, passwordPolicy := range embedded.GetPasswordPolicies() { + passwordPolicyId, passwordPolicyIdOk := passwordPolicy.GetIdOk() + passwordPolicyName, passwordPolicyNameOk := passwordPolicy.GetNameOk() + + if passwordPolicyIdOk && passwordPolicyNameOk { + r.addImportBlock(*passwordPolicyId, *passwordPolicyName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOnePasswordPolicyResource) ResourceType() string { - return "pingone_password_policy" +func (r *PingOnePasswordPolicyResource) addImportBlock(passwordPolicyId, passwordPolicyName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Password Policy ID": passwordPolicyId, + "Password Policy Name": passwordPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: passwordPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, passwordPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_population.go b/internal/connector/pingone/sso/resources/pingone_population.go index afc0298c..1e6fe5e2 100644 --- a/internal/connector/pingone/sso/resources/pingone_population.go +++ b/internal/connector/pingone/sso/resources/pingone_population.go @@ -14,57 +14,79 @@ var ( ) type PingOnePopulationResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOnePopulationResource func Population(clientInfo *connector.PingOneClientInfo) *PingOnePopulationResource { return &PingOnePopulationResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOnePopulationResource) ResourceType() string { + return "pingone_population" +} + func (r *PingOnePopulationResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllPopulations" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportPopulations() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOnePopulationResource) exportPopulations() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, population := range embedded.GetPopulations() { - populationId, populationIdOk := population.GetIdOk() - populationName, populationNameOk := population.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPopulations", r.ResourceType()) + if err != nil { + return err + } - if populationIdOk && populationNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Population Name": *populationName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Population ID": *populationId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *populationName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *populationId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, population := range embedded.GetPopulations() { + populationId, populationIdOk := population.GetIdOk() + populationName, populationNameOk := population.GetNameOk() + + if populationIdOk && populationNameOk { + r.addImportBlock(*populationId, *populationName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOnePopulationResource) ResourceType() string { - return "pingone_population" +func (r *PingOnePopulationResource) addImportBlock(populationId, populationName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Population ID": populationId, + "Population Name": populationName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: populationName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, populationId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_population_default.go b/internal/connector/pingone/sso/resources/pingone_population_default.go index 53c01a63..9403fe51 100644 --- a/internal/connector/pingone/sso/resources/pingone_population_default.go +++ b/internal/connector/pingone/sso/resources/pingone_population_default.go @@ -3,7 +3,6 @@ package resources import ( "fmt" - "github.com/patrickcping/pingone-go-sdk-v2/management" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -11,72 +10,85 @@ import ( // Verify that the resource satisfies the exportable resource interface var ( - _ connector.ExportableResource = &PingOnePopulationDefaultDefaultResource{} + _ connector.ExportableResource = &PingOnePopulationDefaultResource{} ) -type PingOnePopulationDefaultDefaultResource struct { - clientInfo *connector.PingOneClientInfo +type PingOnePopulationDefaultResource struct { + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } -// Utility method for creating a PingOnePopulationDefaultDefaultResource -func PopulationDefault(clientInfo *connector.PingOneClientInfo) *PingOnePopulationDefaultDefaultResource { - return &PingOnePopulationDefaultDefaultResource{ - clientInfo: clientInfo, +// Utility method for creating a PingOnePopulationDefaultResource +func PopulationDefault(clientInfo *connector.PingOneClientInfo) *PingOnePopulationDefaultResource { + return &PingOnePopulationDefaultResource{ + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } -func (r *PingOnePopulationDefaultDefaultResource) ExportAll() (*[]connector.ImportBlock, error) { - l := logger.Get() - - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) +func (r *PingOnePopulationDefaultResource) ResourceType() string { + return "pingone_population_default" +} - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllPopulations" +func (r *PingOnePopulationDefaultResource) ExportAll() (*[]connector.ImportBlock, error) { + l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportPopulationDefault() if err != nil { return nil, err } - foundDefault := false - var defaultPopulation management.Population - for _, population := range embedded.GetPopulations() { - if population.GetDefault() { - foundDefault = true - defaultPopulation = population - break + return r.importBlocks, nil +} + +func (r *PingOnePopulationDefaultResource) exportPopulationDefault() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPopulations", r.ResourceType()) + if err != nil { + return err } - } - if !foundDefault { - l.Debug().Msgf("No exportable %s resource found", r.ResourceType()) - return &[]connector.ImportBlock{}, nil - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks := []connector.ImportBlock{} + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for _, population := range embedded.GetPopulations() { + populationDefault, populationDefaultOk := population.GetDefaultOk() - defaultPopulationName, defaultPopulationNameOk := defaultPopulation.GetNameOk() + if populationDefaultOk && *populationDefault { + populationName, populationNameOk := population.GetNameOk() - if defaultPopulationNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Default Population Name": *defaultPopulationName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, + if populationNameOk { + r.addImportBlock(*populationName) + } + } } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_population_default", *defaultPopulationName), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - }) } - return &importBlocks, nil + return nil } -func (r *PingOnePopulationDefaultDefaultResource) ResourceType() string { - return "pingone_population_default" +func (r *PingOnePopulationDefaultResource) addImportBlock(populationName string) { + commentData := map[string]string{ + "Default Population Name": populationName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_population_default", populationName), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_resource.go b/internal/connector/pingone/sso/resources/pingone_resource.go index 644ea0d0..85c8964e 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource.go +++ b/internal/connector/pingone/sso/resources/pingone_resource.go @@ -14,58 +14,81 @@ var ( ) type PingOneResourceResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneResourceResource func Resource(clientInfo *connector.PingOneClientInfo) *PingOneResourceResource { return &PingOneResourceResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneResourceResource) ResourceType() string { + return "pingone_resource" +} + func (r *PingOneResourceResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllResources" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportResources() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneResourceResource) exportResources() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, resourceInner := range embedded.GetResources() { - resource := resourceInner.Resource - resourceId, resourceIdOk := resource.GetIdOk() - resourceName, resourceNameOk := resource.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) + if err != nil { + return err + } - if resourceIdOk && resourceNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Resource Name": *resourceName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource ID": *resourceId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *resourceName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *resourceId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, resourceInner := range embedded.GetResources() { + if resourceInner.Resource != nil { + resourceId, resourceIdOk := resourceInner.Resource.GetIdOk() + resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() + + if resourceIdOk && resourceNameOk { + r.addImportBlock(*resourceId, *resourceName) + } + } } } - return &importBlocks, nil + return nil } -func (r *PingOneResourceResource) ResourceType() string { - return "pingone_resource" +func (r *PingOneResourceResource) addImportBlock(resourceId, resourceName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource ID": resourceId, + "Resource Name": resourceName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: resourceName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_attribute.go b/internal/connector/pingone/sso/resources/pingone_resource_attribute.go index 2ab6d805..ac7bc09e 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_attribute.go @@ -15,96 +15,136 @@ var ( ) type PingOneResourceAttributeResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneResourceAttributeResource func ResourceAttribute(clientInfo *connector.PingOneClientInfo) *PingOneResourceAttributeResource { return &PingOneResourceAttributeResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneResourceAttributeResource) ResourceType() string { + return "pingone_resource_attribute" +} + func (r *PingOneResourceAttributeResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllResources" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportResourceAttributes() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneResourceAttributeResource) exportResourceAttributes() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, resourceInner := range embedded.GetResources() { - resource := resourceInner.Resource - resourceId, resourceIdOk := resource.GetIdOk() - resourceName, resourceNameOk := resource.GetNameOk() - resourceType, resourceTypeOk := resource.GetTypeOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) + if err != nil { + return err + } - if resourceIdOk && resourceNameOk && resourceTypeOk { - apiExecuteFunc = r.clientInfo.ApiClient.ManagementAPIClient.ResourceAttributesApi.ReadAllResourceAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *resourceId).Execute - apiFunctionName = "ReadAllResourceAttributes" + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - embedded, err = common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, resourceInner := range embedded.GetResources() { + if resourceInner.Resource != nil { + resourceId, resourceIdOk := resourceInner.Resource.GetIdOk() + resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() + resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() - for _, attributeInner := range embedded.GetAttributes() { - if attributeInner.ResourceAttribute == nil { - continue + if resourceIdOk && resourceNameOk && resourceTypeOk { + err := r.exportResourceAttributeByResource(*resourceId, *resourceName, *resourceType) + if err != nil { + return err + } } - resourceAttribute := attributeInner.ResourceAttribute + } + } + } + + return nil +} + +func (r *PingOneResourceAttributeResource) exportResourceAttributeByResource(resourceId, resourceName string, resourceType management.EnumResourceType) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceAttributesApi.ReadAllResourceAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() - resourceAttributeId, resourceAttributeIdOk := resourceAttribute.GetIdOk() - resourceAttributeName, resourceAttributeNameOk := resourceAttribute.GetNameOk() - resourceAttributeType, resourceAttributeTypeOk := resourceAttribute.GetTypeOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceAttributes", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if resourceAttributeTypeOk { - switch { + for _, attributeInner := range embedded.GetAttributes() { + if attributeInner.ResourceAttribute != nil { + resourceAttributeId, resourceAttributeIdOk := attributeInner.ResourceAttribute.GetIdOk() + resourceAttributeName, resourceAttributeNameOk := attributeInner.ResourceAttribute.GetNameOk() + resourceAttributeType, resourceAttributeTypeOk := attributeInner.ResourceAttribute.GetTypeOk() + + if resourceAttributeIdOk && resourceAttributeNameOk && resourceAttributeTypeOk { // Any CORE attribute is required and cannot be overridden - case *resourceAttributeType == management.ENUMRESOURCEATTRIBUTETYPE_CORE: - // Handle the special case where a CUSTOM resource can override the sub attribute - if *resourceType != management.ENUMRESOURCETYPE_CUSTOM { - continue - } - if *resourceAttributeName != "sub" { + // Do not export CORE attributes + // There is one exception where a CUSTOM resource can override the sub CORE attribute + if *resourceAttributeType == management.ENUMRESOURCEATTRIBUTETYPE_CORE { + if resourceType == management.ENUMRESOURCETYPE_CUSTOM { + // Skip export of all CORE attributes except for the sub attribute for CUSTOM resources + if *resourceAttributeName != "sub" { + continue + } + } else { + // Skip export of all CORE attributes for non-CUSTOM resources continue } } - } - if resourceAttributeIdOk && resourceAttributeNameOk && resourceAttributeTypeOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Resource Name": *resourceName, - "Resource Attribute Name": *resourceAttributeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource ID": *resourceId, - "Resource Attribute ID": *resourceAttributeId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *resourceName, *resourceAttributeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *resourceId, *resourceAttributeId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + r.addImportBlock(resourceId, resourceName, *resourceAttributeId, *resourceAttributeName) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneResourceAttributeResource) ResourceType() string { - return "pingone_resource_attribute" +func (r *PingOneResourceAttributeResource) addImportBlock(resourceId, resourceName, resourceAttributeId, resourceAttributeName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Attribute ID": resourceAttributeId, + "Resource Attribute Name": resourceAttributeName, + "Resource ID": resourceId, + "Resource Name": resourceName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: resourceName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceAttributeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_scope.go b/internal/connector/pingone/sso/resources/pingone_resource_scope.go index d9dc27c2..fdcc3883 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_scope.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_scope.go @@ -15,75 +15,117 @@ var ( ) type PingOneResourceScopeResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneResourceScopeResource func ResourceScope(clientInfo *connector.PingOneClientInfo) *PingOneResourceScopeResource { return &PingOneResourceScopeResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneResourceScopeResource) ResourceType() string { + return "pingone_resource_scope" +} + func (r *PingOneResourceScopeResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllResources" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportResourceScopes() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneResourceScopeResource) exportResourceScopes() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) + if err != nil { + return err + } - for _, resourceInner := range embedded.GetResources() { - resource := resourceInner.Resource - resourceId, resourceIdOk := resource.GetIdOk() - resourceName, resourceNameOk := resource.GetNameOk() - resourceType, resourceTypeOk := resource.GetTypeOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_CUSTOM { - apiResourceScopesExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *resourceId).Execute - apiResourceScopesFunctionName := "ReadAllResourceScopes" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - embeddedResourceScopes, err := common.GetManagementEmbedded(apiResourceScopesExecuteFunc, apiResourceScopesFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + for _, resourceInner := range embedded.GetResources() { + if resourceInner.Resource != nil { + resourceId, resourceIdOk := resourceInner.Resource.GetIdOk() + resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() + resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() - for _, scope := range embeddedResourceScopes.GetScopes() { - scopeId, scopeIdOk := scope.GetIdOk() - scopeName, scopeNameOk := scope.GetNameOk() - if scopeIdOk && scopeNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Resource Name": *resourceName, - "Scope Name": *scopeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource ID": *resourceId, - "Scope ID": *scopeId, + if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_CUSTOM { + err := r.exportResourceScopesByResource(*resourceId, *resourceName) + if err != nil { + return err } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *resourceName, *scopeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *resourceId, *scopeId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneResourceScopeResource) ResourceType() string { - return "pingone_resource_scope" +func (r *PingOneResourceScopeResource) exportResourceScopesByResource(resourceId, resourceName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceScopes", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, scope := range embedded.GetScopes() { + scopeId, scopeIdOk := scope.GetIdOk() + scopeName, scopeNameOk := scope.GetNameOk() + if scopeIdOk && scopeNameOk { + r.addImportBlock(resourceId, resourceName, *scopeId, *scopeName) + } + } + } + + return nil +} + +func (r *PingOneResourceScopeResource) addImportBlock(resourceId, resourceName, scopeId, scopeName string) { + commentData := map[string]string{ + "Custom Resource ID": resourceId, + "Custom Resource Name": resourceName, + "Custom Resource Scope ID": scopeId, + "Custom Resource Scope Name": scopeName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, scopeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, resourceId, scopeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go b/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go index eb9ec217..b9fec723 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go @@ -15,74 +15,116 @@ var ( ) type PingOneResourceScopeOpenIdResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneResourceScopeOpenIdResource func ResourceScopeOpenId(clientInfo *connector.PingOneClientInfo) *PingOneResourceScopeOpenIdResource { return &PingOneResourceScopeOpenIdResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneResourceScopeOpenIdResource) ResourceType() string { + return "pingone_resource_scope_openid" +} + func (r *PingOneResourceScopeOpenIdResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllResources" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportResourceScopeOpenIds() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneResourceScopeOpenIdResource) exportResourceScopeOpenIds() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) + if err != nil { + return err + } - for _, resourceInner := range embedded.GetResources() { - resource := resourceInner.Resource - resourceId, resourceIdOk := resource.GetIdOk() - resourceName, resourceNameOk := resource.GetNameOk() - resourceType, resourceTypeOk := resource.GetTypeOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_OPENID_CONNECT { - apiResourceScopeOpenIdsExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *resourceId).Execute - apiResourceScopeOpenIdsFunctionName := "ReadAllResourceScopes" + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - embeddedResourceScopeOpenIds, err := common.GetManagementEmbedded(apiResourceScopeOpenIdsExecuteFunc, apiResourceScopeOpenIdsFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + for _, resourceInner := range embedded.GetResources() { + if resourceInner.Resource != nil { + resourceId, resourceIdOk := resourceInner.Resource.GetIdOk() + resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() + resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() - for _, scopeOpenId := range embeddedResourceScopeOpenIds.GetScopes() { - scopeOpenIdId, scopeOpenIdIdOk := scopeOpenId.GetIdOk() - scopeOpenIdName, scopeOpenIdNameOk := scopeOpenId.GetNameOk() - if scopeOpenIdIdOk && scopeOpenIdNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Resource Name": *resourceName, - "Scope OpenID Name": *scopeOpenIdName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Scope OpenID ID": *scopeOpenIdId, + if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_OPENID_CONNECT { + err := r.exportResourceScopeOpenIdByResource(*resourceId, *resourceName) + if err != nil { + return err } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *resourceName, *scopeOpenIdName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *scopeOpenIdId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneResourceScopeOpenIdResource) ResourceType() string { - return "pingone_resource_scope_openid" +func (r *PingOneResourceScopeOpenIdResource) exportResourceScopeOpenIdByResource(resourceId, resourceName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceScopes", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, scopeOpenId := range embedded.GetScopes() { + scopeOpenIdId, scopeOpenIdIdOk := scopeOpenId.GetIdOk() + scopeOpenIdName, scopeOpenIdNameOk := scopeOpenId.GetNameOk() + if scopeOpenIdIdOk && scopeOpenIdNameOk { + r.addImportBlock(resourceName, *scopeOpenIdId, *scopeOpenIdName) + } + } + } + + return nil +} + +func (r *PingOneResourceScopeOpenIdResource) addImportBlock(resourceName, scopeOpenIdId, scopeOpenIdName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "OpenID Connect Resource Name": resourceName, + "OpenID Connect Resource Scope ID": scopeOpenIdId, + "OpenID Connect Resource Scope Name": scopeOpenIdName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, scopeOpenIdName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, scopeOpenIdId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go b/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go index 173e26e0..b58f8629 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go @@ -16,84 +16,124 @@ var ( ) type PingOneResourceScopePingOneApiResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneResourceScopePingOneApiResource func ResourceScopePingOneApi(clientInfo *connector.PingOneClientInfo) *PingOneResourceScopePingOneApiResource { return &PingOneResourceScopePingOneApiResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneResourceScopePingOneApiResource) ResourceType() string { + return "pingone_resource_scope_pingone_api" +} + func (r *PingOneResourceScopePingOneApiResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllResources" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportResourceScopePingOneApis() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneResourceScopePingOneApiResource) exportResourceScopePingOneApis() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, resourceInner := range embedded.GetResources() { - resource := resourceInner.Resource - resourceId, resourceIdOk := resource.GetIdOk() - resourceName, resourceNameOk := resource.GetNameOk() - resourceType, resourceTypeOk := resource.GetTypeOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) + if err != nil { + return err + } - if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_PINGONE_API { - apiResourceScopePingOneApisExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *resourceId).Execute - apiResourceScopePingOneApisFunctionName := "ReadAllResourceScopes" + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - embeddedResourceScopePingOneApis, err := common.GetManagementEmbedded(apiResourceScopePingOneApisExecuteFunc, apiResourceScopePingOneApisFunctionName, r.ResourceType()) - if err != nil { - return nil, err + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, resourceInner := range embedded.GetResources() { + if resourceInner.Resource != nil { + resourceId, resourceIdOk := resourceInner.Resource.GetIdOk() + resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() + resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() + + if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_PINGONE_API { + err := r.exportResourceScopePingOneApiByResource(*resourceId, *resourceName) + if err != nil { + return err + } + } } + } + } + + return nil +} + +func (r *PingOneResourceScopePingOneApiResource) exportResourceScopePingOneApiByResource(resourceId, resourceName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() - for _, scopePingOneApi := range embeddedResourceScopePingOneApis.GetScopes() { - scopePingOneApiId, scopePingOneApiIdOk := scopePingOneApi.GetIdOk() - scopePingOneApiName, scopePingOneApiNameOk := scopePingOneApi.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceScopes", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, scopePingOneApi := range embedded.GetScopes() { + scopePingOneApiId, scopePingOneApiIdOk := scopePingOneApi.GetIdOk() + scopePingOneApiName, scopePingOneApiNameOk := scopePingOneApi.GetNameOk() + + if scopePingOneApiIdOk && scopePingOneApiNameOk { // Make sure the scope name is in the form of one of the following four patterns // p1:read:user, p1:update:user, p1:read:user:{suffix}, or p1:update:user:{suffix} // as supported by https://registry.terraform.io/providers/pingidentity/pingone/latest/docs/resources/resource_scope_pingone_api - var scopeMatch bool - if scopePingOneApiNameOk { - re := regexp.MustCompile(`p1:(read|update):user($|(:.+))`) - scopeMatch = re.MatchString(*scopePingOneApiName) - } + re := regexp.MustCompile(`^p1:(read|update):user(|:.+)$`) - if scopeMatch && scopePingOneApiIdOk && scopePingOneApiNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Resource Name": *resourceName, - "Scope PingOneApi Name": *scopePingOneApiName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Scope PingOneApi ID": *scopePingOneApiId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *resourceName, *scopePingOneApiName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *scopePingOneApiId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + if re.MatchString(*scopePingOneApiName) { + r.addImportBlock(resourceName, *scopePingOneApiId, *scopePingOneApiName) } } } } - return &importBlocks, nil + return nil } -func (r *PingOneResourceScopePingOneApiResource) ResourceType() string { - return "pingone_resource_scope_pingone_api" +func (r *PingOneResourceScopePingOneApiResource) addImportBlock(resourceName, scopePingOneApiId, scopePingOneApiName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "PingOne API Resource Name": resourceName, + "PingOne API Resource Scope ID": scopePingOneApiId, + "PingOne API Resource Scope Name": scopePingOneApiName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, scopePingOneApiName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, scopePingOneApiId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_schema_attribute.go b/internal/connector/pingone/sso/resources/pingone_schema_attribute.go index 0b455f5b..def09608 100644 --- a/internal/connector/pingone/sso/resources/pingone_schema_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_schema_attribute.go @@ -14,72 +14,113 @@ var ( ) type PingOneSchemaAttributeResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneSchemaAttributeResource func SchemaAttribute(clientInfo *connector.PingOneClientInfo) *PingOneSchemaAttributeResource { return &PingOneSchemaAttributeResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneSchemaAttributeResource) ResourceType() string { + return "pingone_schema_attribute" +} + func (r *PingOneSchemaAttributeResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteSchemaFunc := r.clientInfo.ApiClient.ManagementAPIClient.SchemasApi.ReadAllSchemas(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiSchemaFunctionName := "ReadAllSchemas" - - embedded, err := common.GetManagementEmbedded(apiExecuteSchemaFunc, apiSchemaFunctionName, r.ResourceType()) + err := r.exportSchemaAttributes() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneSchemaAttributeResource) exportSchemaAttributes() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.SchemasApi.ReadAllSchemas(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSchemas", r.ResourceType()) + if err != nil { + return err + } - for _, schema := range embedded.GetSchemas() { - schemaId, schemaIdOk := schema.GetIdOk() - schemaName, schemaNameOk := schema.GetNameOk() - if schemaIdOk && schemaNameOk { - apiExecuteSchemaAttributeFunc := r.clientInfo.ApiClient.ManagementAPIClient.SchemasApi.ReadAllSchemaAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *schemaId).Execute - apiSchemaAttributeFunctionName := "ReadAllSchemaAttributes" + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - schemaEmbedded, err := common.GetManagementEmbedded(apiExecuteSchemaAttributeFunc, apiSchemaAttributeFunctionName, r.ResourceType()) - if err != nil { - return nil, err - } + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - for _, schemaAttribute := range schemaEmbedded.GetAttributes() { - schemaAttributeId, schemaAttributeIdOk := schemaAttribute.SchemaAttribute.GetIdOk() - schemaAttributeName, schemaAttributeNameOk := schemaAttribute.SchemaAttribute.GetNameOk() - if schemaAttributeIdOk && schemaAttributeNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Schema Name": *schemaName, - "Schema Attribute Name": *schemaAttributeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Schema ID": *schemaId, - "Schema Attribute ID": *schemaAttributeId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *schemaName, *schemaAttributeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *schemaId, *schemaAttributeId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + for _, schema := range embedded.GetSchemas() { + schemaId, schemaIdOk := schema.GetIdOk() + schemaName, schemaNameOk := schema.GetNameOk() + if schemaIdOk && schemaNameOk { + err := r.exportSchemaAttributesBySchema(*schemaId, *schemaName) + if err != nil { + return err } } } } - return &importBlocks, nil + return nil } -func (r *PingOneSchemaAttributeResource) ResourceType() string { - return "pingone_schema_attribute" +func (r *PingOneSchemaAttributeResource) exportSchemaAttributesBySchema(schemaId, schemaName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.SchemasApi.ReadAllSchemaAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, schemaId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSchemaAttributes", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, schemaAttribute := range embedded.GetAttributes() { + schemaAttributeId, schemaAttributeIdOk := schemaAttribute.SchemaAttribute.GetIdOk() + schemaAttributeName, schemaAttributeNameOk := schemaAttribute.SchemaAttribute.GetNameOk() + if schemaAttributeIdOk && schemaAttributeNameOk { + r.addImportBlock(schemaId, schemaName, *schemaAttributeId, *schemaAttributeName) + } + } + } + + return nil +} + +func (r *PingOneSchemaAttributeResource) addImportBlock(schemaId, schemaName, schemaAttributeId, schemaAttributeName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Schema Attribute ID": schemaAttributeId, + "Schema Attribute Name": schemaAttributeName, + "Schema ID": schemaId, + "Schema Name": schemaName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", schemaName, schemaAttributeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, schemaId, schemaAttributeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go b/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go index 27bcfbe8..7bc1773b 100644 --- a/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go +++ b/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go @@ -14,57 +14,79 @@ var ( ) type PingOneSignOnPolicyResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneSignOnPolicyResource func SignOnPolicy(clientInfo *connector.PingOneClientInfo) *PingOneSignOnPolicyResource { return &PingOneSignOnPolicyResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneSignOnPolicyResource) ResourceType() string { + return "pingone_sign_on_policy" +} + func (r *PingOneSignOnPolicyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadAllSignOnPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllSignOnPolicies" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportSignOnPolicies() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) +func (r *PingOneSignOnPolicyResource) exportSignOnPolicies() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadAllSignOnPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - for _, signOnPolicy := range embedded.GetSignOnPolicies() { - signOnPolicyId, signOnPolicyIdOk := signOnPolicy.GetIdOk() - signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicies", r.ResourceType()) + if err != nil { + return err + } - if signOnPolicyIdOk && signOnPolicyNameOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Sign On Policy Name": *signOnPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Sign On Policy ID": *signOnPolicyId, - } + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: *signOnPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, *signOnPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, signOnPolicy := range embedded.GetSignOnPolicies() { + signOnPolicyId, signOnPolicyIdOk := signOnPolicy.GetIdOk() + signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() + + if signOnPolicyIdOk && signOnPolicyNameOk { + r.addImportBlock(*signOnPolicyId, *signOnPolicyName) + } } } - return &importBlocks, nil + return nil } -func (r *PingOneSignOnPolicyResource) ResourceType() string { - return "pingone_sign_on_policy" +func (r *PingOneSignOnPolicyResource) addImportBlock(signOnPolicyId, signOnPolicyName string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Sign-On Policy ID": signOnPolicyId, + "Sign-On Policy Name": signOnPolicyName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: signOnPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, signOnPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } diff --git a/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go b/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go index e731fbe5..268b0e02 100644 --- a/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go +++ b/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go @@ -15,47 +15,87 @@ var ( ) type PingOneSignOnPolicyActionResource struct { - clientInfo *connector.PingOneClientInfo + clientInfo *connector.PingOneClientInfo + importBlocks *[]connector.ImportBlock } // Utility method for creating a PingOneSignOnPolicyActionResource func SignOnPolicyAction(clientInfo *connector.PingOneClientInfo) *PingOneSignOnPolicyActionResource { return &PingOneSignOnPolicyActionResource{ - clientInfo: clientInfo, + clientInfo: clientInfo, + importBlocks: &[]connector.ImportBlock{}, } } +func (r *PingOneSignOnPolicyActionResource) ResourceType() string { + return "pingone_sign_on_policy_action" +} + func (r *PingOneSignOnPolicyActionResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() + l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - l.Debug().Msgf("Fetching all %s resources...", r.ResourceType()) - - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadAllSignOnPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute - apiFunctionName := "ReadAllSignOnPolicies" - - embedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) + err := r.exportSignOnPolicyActions() if err != nil { return nil, err } - importBlocks := []connector.ImportBlock{} + return r.importBlocks, nil +} + +func (r *PingOneSignOnPolicyActionResource) exportSignOnPolicyActions() error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadAllSignOnPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() - l.Debug().Msgf("Generating Import Blocks for all %s resources...", r.ResourceType()) + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicies", r.ResourceType()) + if err != nil { + return err + } - for _, signOnPolicy := range embedded.GetSignOnPolicies() { - signOnPolicyId, signOnPolicyIdOk := signOnPolicy.GetIdOk() - signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - if signOnPolicyIdOk && signOnPolicyNameOk { + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } - apiExecuteFunc := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPolicyActionsApi.ReadAllSignOnPolicyActions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, *signOnPolicyId).Execute - apiFunctionName := "ReadAllSignOnPolicyActions" + for _, signOnPolicy := range embedded.GetSignOnPolicies() { + signOnPolicyId, signOnPolicyIdOk := signOnPolicy.GetIdOk() + signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() - actionEmbedded, err := common.GetManagementEmbedded(apiExecuteFunc, apiFunctionName, r.ResourceType()) - if err != nil { - return nil, err + if signOnPolicyIdOk && signOnPolicyNameOk { + err := r.exportSignOnPolicyActionsBySignOnPolicy(*signOnPolicyId, *signOnPolicyName) + if err != nil { + return err + } } + } + } + + return nil +} +func (r *PingOneSignOnPolicyActionResource) exportSignOnPolicyActionsBySignOnPolicy(signOnPolicyId, signOnPolicyName string) error { + iter := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPolicyActionsApi.ReadAllSignOnPolicyActions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, signOnPolicyId).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicyActions", r.ResourceType()) + if err != nil { + return err + } + + if cursor.EntityArray == nil { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, action := range embedded.GetActions() { var ( actionId *string actionIdOk bool @@ -63,60 +103,57 @@ func (r *PingOneSignOnPolicyActionResource) ExportAll() (*[]connector.ImportBloc actionTypeOk bool ) - for _, action := range actionEmbedded.GetActions() { - switch { - case action.SignOnPolicyActionAgreement != nil: - actionId, actionIdOk = action.SignOnPolicyActionAgreement.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionAgreement.GetTypeOk() - case action.SignOnPolicyActionCommon != nil: - actionId, actionIdOk = action.SignOnPolicyActionCommon.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionCommon.GetTypeOk() - case action.SignOnPolicyActionIDFirst != nil: - actionId, actionIdOk = action.SignOnPolicyActionIDFirst.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionIDFirst.GetTypeOk() - case action.SignOnPolicyActionIDP != nil: - actionId, actionIdOk = action.SignOnPolicyActionIDP.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionIDP.GetTypeOk() - case action.SignOnPolicyActionLogin != nil: - actionId, actionIdOk = action.SignOnPolicyActionLogin.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionLogin.GetTypeOk() - case action.SignOnPolicyActionMFA != nil: - actionId, actionIdOk = action.SignOnPolicyActionMFA.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionMFA.GetTypeOk() - case action.SignOnPolicyActionPingIDWinLoginPasswordless != nil: - actionId, actionIdOk = action.SignOnPolicyActionPingIDWinLoginPasswordless.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionPingIDWinLoginPasswordless.GetTypeOk() - case action.SignOnPolicyActionProgressiveProfiling != nil: - actionId, actionIdOk = action.SignOnPolicyActionProgressiveProfiling.GetIdOk() - actionType, actionTypeOk = action.SignOnPolicyActionProgressiveProfiling.GetTypeOk() - default: - continue - } + switch { + case action.SignOnPolicyActionAgreement != nil: + actionId, actionIdOk = action.SignOnPolicyActionAgreement.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionAgreement.GetTypeOk() + case action.SignOnPolicyActionCommon != nil: + actionId, actionIdOk = action.SignOnPolicyActionCommon.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionCommon.GetTypeOk() + case action.SignOnPolicyActionIDFirst != nil: + actionId, actionIdOk = action.SignOnPolicyActionIDFirst.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionIDFirst.GetTypeOk() + case action.SignOnPolicyActionIDP != nil: + actionId, actionIdOk = action.SignOnPolicyActionIDP.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionIDP.GetTypeOk() + case action.SignOnPolicyActionLogin != nil: + actionId, actionIdOk = action.SignOnPolicyActionLogin.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionLogin.GetTypeOk() + case action.SignOnPolicyActionMFA != nil: + actionId, actionIdOk = action.SignOnPolicyActionMFA.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionMFA.GetTypeOk() + case action.SignOnPolicyActionPingIDWinLoginPasswordless != nil: + actionId, actionIdOk = action.SignOnPolicyActionPingIDWinLoginPasswordless.GetIdOk() + actionType, actionTypeOk = action.SignOnPolicyActionPingIDWinLoginPasswordless.GetTypeOk() + default: + continue + } - if actionIdOk && actionTypeOk { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Sign On Policy Name": *signOnPolicyName, - "Action Type": string(*actionType), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Sign On Policy ID": *signOnPolicyId, - "Sign On Policy Action ID": *actionId, - } - - importBlocks = append(importBlocks, connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", *signOnPolicyName, *actionType), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *signOnPolicyId, *actionId), - CommentInformation: common.GenerateCommentInformation(commentData), - }) - } + if actionIdOk && actionTypeOk { + r.addImportBlock(signOnPolicyId, signOnPolicyName, *actionId, string(*actionType)) } } } - return &importBlocks, nil + return nil } -func (r *PingOneSignOnPolicyActionResource) ResourceType() string { - return "pingone_sign_on_policy_action" +func (r *PingOneSignOnPolicyActionResource) addImportBlock(signOnPolicyId, signOnPolicyName, actionId, actionType string) { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Sign-On Policy Action ID": actionId, + "Sign-On Policy Action Type": actionType, + "Sign-On Policy ID": signOnPolicyId, + "Sign-On Policy Name": signOnPolicyName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", signOnPolicyName, actionType), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, signOnPolicyId, actionId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + *r.importBlocks = append(*r.importBlocks, importBlock) } From 47701a200b263e2e6cd7837b64906ab794fe526c Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Tue, 3 Dec 2024 17:24:51 -0600 Subject: [PATCH 7/9] testing fixes for various changes in import block names and bugs caught by testing. Update dependencies --- go.mod | 41 ++++----- go.sum | 85 ++++++++++--------- .../resources/pingone_mfa_settings_test.go | 2 +- .../pingone_agreement_localization.go | 2 +- ...ne_agreement_localization_revision_test.go | 6 +- .../pingone_branding_settings_test.go | 2 +- .../pingone_branding_theme_default.go | 4 +- .../resources/pingone_environment_test.go | 2 +- .../pingone_forms_recaptcha_v2_test.go | 2 +- .../pingone_gateway_credential_test.go | 16 ++-- .../resources/pingone_language_update_test.go | 5 ++ .../pingone_notification_settings_test.go | 2 +- .../pingone_phone_delivery_settings_test.go | 2 +- .../pingone_application_resource_grant.go | 5 +- ...ingone_application_role_assignment_test.go | 52 ++++++------ .../pingone_group_role_assignment.go | 2 +- .../pingone_group_role_assignment_test.go | 4 +- .../resources/pingone_identity_provider.go | 4 +- .../resources/pingone_resource_attribute.go | 4 +- 19 files changed, 133 insertions(+), 109 deletions(-) diff --git a/go.mod b/go.mod index a1585554..48b9dd84 100644 --- a/go.mod +++ b/go.mod @@ -4,15 +4,14 @@ go 1.23.3 require ( github.com/fatih/color v1.18.0 - github.com/golangci/golangci-lint v1.62.0 + github.com/golangci/golangci-lint v1.62.2 github.com/hashicorp/go-uuid v1.0.3 github.com/manifoldco/promptui v0.9.0 github.com/patrickcping/pingone-go-sdk-v2 v0.12.4 github.com/patrickcping/pingone-go-sdk-v2/management v0.44.0 - github.com/patrickcping/pingone-go-sdk-v2/mfa v0.21.0 github.com/patrickcping/pingone-go-sdk-v2/risk v0.17.0 github.com/pavius/impi v0.0.3 - github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.3 + github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.5 github.com/rs/zerolog v1.33.0 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 @@ -29,25 +28,25 @@ require ( github.com/Antonboom/nilnil v1.0.0 // indirect github.com/Antonboom/testifylint v1.5.2 // indirect github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect - github.com/Crocmagnon/fatcontext v0.5.2 // indirect + github.com/Crocmagnon/fatcontext v0.5.3 // indirect github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 // indirect github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 // indirect - github.com/Masterminds/semver/v3 v3.3.0 // indirect + github.com/Masterminds/semver/v3 v3.3.1 // 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.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 - github.com/ashanbrown/makezero v1.1.1 // indirect + github.com/ashanbrown/makezero v1.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect 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.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 + github.com/butuzov/ireturn v0.3.1 // indirect + github.com/butuzov/mirror v1.3.0 // indirect github.com/catenacyber/perfsprint v0.7.1 // indirect github.com/ccojocar/zxcvbn-go v1.0.2 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -55,7 +54,7 @@ require ( github.com/chavacava/garif v0.1.0 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/ckaznocha/intrange v0.2.1 // indirect - github.com/curioswitch/go-reassign v0.2.0 // indirect + github.com/curioswitch/go-reassign v0.3.0 // indirect github.com/daixiang0/gci v0.13.5 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/denis-tingaikin/go-header v0.5.0 // indirect @@ -74,7 +73,7 @@ require ( github.com/go-toolsmith/strparse v1.1.0 // indirect github.com/go-toolsmith/typep v1.1.0 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect - github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect + github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gofrs/flock v0.12.1 // indirect github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect @@ -91,13 +90,15 @@ require ( github.com/gostaticanalysis/comment v1.5.0 // indirect github.com/gostaticanalysis/forcetypeassert v0.1.0 // indirect github.com/gostaticanalysis/nilerr v0.1.1 // indirect + github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect github.com/hashicorp/go-version v1.7.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/hexops/gotextdiff v1.0.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jgautheron/goconst v1.7.1 // indirect github.com/jingyugao/rowserrcheck v1.1.1 // indirect - github.com/jjti/go-spancheck v0.6.2 // indirect + github.com/jjti/go-spancheck v0.6.4 // indirect github.com/julz/importas v0.1.0 // indirect github.com/karamaru-alpha/copyloopvar v1.1.0 // indirect github.com/kisielk/errcheck v1.8.0 // indirect @@ -107,14 +108,15 @@ require ( github.com/kunwardeep/paralleltest v1.0.10 // indirect github.com/kyoh86/exportloopref v0.1.11 // indirect github.com/lasiar/canonicalheader v1.1.2 // indirect - github.com/ldez/gomoddirectives v0.2.4 // indirect - github.com/ldez/tagliatelle v0.5.0 // indirect + github.com/ldez/gomoddirectives v0.6.0 // indirect + github.com/ldez/grignotin v0.6.0 // indirect + github.com/ldez/tagliatelle v0.6.0 // indirect github.com/leonklingele/grouper v1.1.2 // indirect github.com/macabu/inamedparam v0.1.3 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/maratori/testableexamples v1.0.0 // indirect github.com/maratori/testpackage v1.1.1 // indirect - github.com/matoous/godox v0.0.0-20240105082147-c5b5e0e7c0c0 // indirect + github.com/matoous/godox v0.0.0-20241202171805-94d1edd68ebb // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect @@ -130,6 +132,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/patrickcping/pingone-go-sdk-v2/authorize v0.7.0 // indirect github.com/patrickcping/pingone-go-sdk-v2/credentials v0.10.0 // indirect + github.com/patrickcping/pingone-go-sdk-v2/mfa v0.21.0 // indirect github.com/patrickcping/pingone-go-sdk-v2/verify v0.8.0 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect @@ -150,7 +153,7 @@ require ( github.com/ryanrolds/sqlclosecheck v0.5.1 // indirect github.com/sagikazarmark/locafero v0.6.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect - github.com/sanposhiho/wastedassign/v2 v2.0.7 // indirect + github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect github.com/sashamelentyev/interfacebloat v1.1.0 // indirect github.com/sashamelentyev/usestdlibvars v1.27.0 // indirect @@ -165,11 +168,11 @@ require ( github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect - github.com/stbenjam/no-sprintf-host-port v0.1.1 // indirect + github.com/stbenjam/no-sprintf-host-port v0.2.0 // indirect github.com/stretchr/objx v0.5.2 // indirect - github.com/stretchr/testify v1.9.0 // indirect + github.com/stretchr/testify v1.10.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect - github.com/tdakkota/asciicheck v0.2.0 // indirect + github.com/tdakkota/asciicheck v0.3.0 // indirect github.com/tetafro/godot v1.4.18 // indirect github.com/timakin/bodyclose v0.0.0-20241017074824-adbc21e6bf36 // indirect github.com/timonwong/loggercheck v0.10.1 // indirect @@ -178,7 +181,7 @@ require ( github.com/ultraware/funlen v0.1.0 // indirect github.com/ultraware/whitespace v0.1.1 // indirect github.com/uudashr/gocognit v1.1.3 // indirect - github.com/uudashr/iface v1.2.0 // indirect + github.com/uudashr/iface v1.3.0 // indirect github.com/xen0n/gosmopolitan v1.2.2 // indirect github.com/yagipy/maintidx v1.0.0 // indirect github.com/yeya24/promlinter v0.3.0 // indirect diff --git a/go.sum b/go.sum index ec627ca4..a1205d16 100644 --- a/go.sum +++ b/go.sum @@ -14,14 +14,14 @@ github.com/Antonboom/testifylint v1.5.2 h1:4s3Xhuv5AvdIgbd8wOOEeo0uZG7PbDKQyKY5l github.com/Antonboom/testifylint v1.5.2/go.mod h1:vxy8VJ0bc6NavlYqjZfmp6EfqXMtBgQ4+mhCojwC1P8= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/Crocmagnon/fatcontext v0.5.2 h1:vhSEg8Gqng8awhPju2w7MKHqMlg4/NI+gSDHtR3xgwA= -github.com/Crocmagnon/fatcontext v0.5.2/go.mod h1:87XhRMaInHP44Q7Tlc7jkgKKB7kZAOPiDkFMdKCC+74= +github.com/Crocmagnon/fatcontext v0.5.3 h1:zCh/wjc9oyeF+Gmp+V60wetm8ph2tlsxocgg/J0hOps= +github.com/Crocmagnon/fatcontext v0.5.3/go.mod h1:XoCQYY1J+XTfyv74qLXvNw4xFunr3L1wkopIIKG7wGM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 h1:/fTUt5vmbkAcMBt4YQiuC23cV0kEsN1MVMNqeOW43cU= github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0/go.mod h1:ONJg5sxcbsdQQ4pOW8TGdTidT2TMAUy/2Xhr8mrYaao= -github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= -github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4= +github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJPdp74zmpA= github.com/OpenPeeDeeP/depguard/v2 v2.2.0/go.mod h1:CIzddKRvLBC4Au5aYP/i3nyaWQ+ClszLIuVocRiCYFQ= github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= @@ -38,8 +38,8 @@ github.com/alingse/asasalint v0.0.11 h1:SFwnQXJ49Kx/1GghOFz1XGqHYKp21Kq1nHad/0WQ github.com/alingse/asasalint v0.0.11/go.mod h1:nCaoMhw7a9kSJObvQyVzNTPBDbNpdocqrSP7t/cW5+I= github.com/ashanbrown/forbidigo v1.6.0 h1:D3aewfM37Yb3pxHujIPSpTf6oQk9sc9WZi8gerOIVIY= github.com/ashanbrown/forbidigo v1.6.0/go.mod h1:Y8j9jy9ZYAEHXdu723cUlraTqbzjKF1MUyfOKL+AjcU= -github.com/ashanbrown/makezero v1.1.1 h1:iCQ87C0V0vSyO+M9E/FZYbu65auqH0lnsOkf5FcB28s= -github.com/ashanbrown/makezero v1.1.1/go.mod h1:i1bJLCRSCHOcOa9Y6MyF2FTfMZMFdHvxKHxgO5Z1axI= +github.com/ashanbrown/makezero v1.2.0 h1:/2Lp1bypdmK9wDIq7uWBlDF1iMUpIIS4A+pF6C9IEUU= +github.com/ashanbrown/makezero v1.2.0/go.mod h1:dxlPhHbDMC6N6xICzFBSK+4njQDdK8euNO0qjQMtGY4= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bkielbasa/cyclop v1.2.3 h1:faIVMIGDIANuGPWH031CZJTi2ymOQBULs9H21HSMa5w= @@ -52,10 +52,10 @@ 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= -github.com/butuzov/ireturn v0.3.0/go.mod h1:A09nIiwiqzN/IoVo9ogpa0Hzi9fex1kd9PSD6edP5ZA= -github.com/butuzov/mirror v1.2.0 h1:9YVK1qIjNspaqWutSv8gsge2e/Xpq1eqEkslEUHy5cs= -github.com/butuzov/mirror v1.2.0/go.mod h1:DqZZDtzm42wIAIyHXeN8W/qb1EPlb9Qn/if9icBOpdQ= +github.com/butuzov/ireturn v0.3.1 h1:mFgbEI6m+9W8oP/oDdfA34dLisRFCj2G6o/yiI1yZrY= +github.com/butuzov/ireturn v0.3.1/go.mod h1:ZfRp+E7eJLC0NQmk1Nrm1LOrn/gQlOykv+cVPdiXH5M= +github.com/butuzov/mirror v1.3.0 h1:HdWCXzmwlQHdVhwvsfBb2Au0r3HyINry3bDWLYXiKoc= +github.com/butuzov/mirror v1.3.0/go.mod h1:AEij0Z8YMALaq4yQj9CPPVYOyJQyiexpQEQgihajRfI= github.com/catenacyber/perfsprint v0.7.1 h1:PGW5G/Kxn+YrN04cRAZKC+ZuvlVwolYMrIyyTJ/rMmc= github.com/catenacyber/perfsprint v0.7.1/go.mod h1:/wclWYompEyjUD2FuIIDVKNkqz7IgBIWXIH3V0Zol50= github.com/ccojocar/zxcvbn-go v1.0.2 h1:na/czXU8RrhXO4EZme6eQJLR4PzcGsahsBOAwU6I3Vg= @@ -79,8 +79,8 @@ github.com/ckaznocha/intrange v0.2.1 h1:M07spnNEQoALOJhwrImSrJLaxwuiQK+hA2DeajBl github.com/ckaznocha/intrange v0.2.1/go.mod h1:7NEhVyf8fzZO5Ds7CRaqPEm52Ut83hsTiL5zbER/HYk= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/curioswitch/go-reassign v0.2.0 h1:G9UZyOcpk/d7Gd6mqYgd8XYWFMw/znxwGDUstnC9DIo= -github.com/curioswitch/go-reassign v0.2.0/go.mod h1:x6OpXuWvgfQaMGks2BZybTngWjT84hqJfKoO8Tt/Roc= +github.com/curioswitch/go-reassign v0.3.0 h1:dh3kpQHuADL3cobV/sSGETA8DOv457dwl+fbBAhrQPs= +github.com/curioswitch/go-reassign v0.3.0/go.mod h1:nApPCCTtqLJN/s8HfItCcKV0jIPwluBOvZP+dsJGA88= github.com/daixiang0/gci v0.13.5 h1:kThgmH1yBmZSBCh1EJVxQ7JsHpm5Oms0AMed/0LaH4c= github.com/daixiang0/gci v0.13.5/go.mod h1:12etP2OniiIdP4q+kjUGrC/rUagga7ODbqsom5Eo5Yk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -134,8 +134,8 @@ github.com/go-toolsmith/typep v1.1.0 h1:fIRYDyF+JywLfqzyhdiHzRop/GQDxxNhLGQ6gFUN github.com/go-toolsmith/typep v1.1.0/go.mod h1:fVIw+7zjdsMxDA3ITWnH1yOiw1rnTQKCsF/sk2H/qig= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= -github.com/go-xmlfmt/xmlfmt v1.1.2 h1:Nea7b4icn8s57fTx1M5AI4qQT5HEM3rVUO8MuE6g80U= -github.com/go-xmlfmt/xmlfmt v1.1.2/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= +github.com/go-xmlfmt/xmlfmt v1.1.3 h1:t8Ey3Uy7jDSEisW2K3somuMKIpzktkWptA0iFCnRUWY= +github.com/go-xmlfmt/xmlfmt v1.1.3/go.mod h1:aUCEOzzezBEjDBbFBoSiya/gduyIiWYRP6CnSFIV8AM= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -147,8 +147,8 @@ github.com/golangci/go-printf-func-name v0.1.0 h1:dVokQP+NMTO7jwO4bwsRwLWeudOVUP github.com/golangci/go-printf-func-name v0.1.0/go.mod h1:wqhWFH5mUdJQhweRnldEywnR5021wTdZSNgwYceV14s= github.com/golangci/gofmt v0.0.0-20240816233607-d8596aa466a9 h1:/1322Qns6BtQxUZDTAT4SdcoxknUki7IAoK4SAXr8ME= github.com/golangci/gofmt v0.0.0-20240816233607-d8596aa466a9/go.mod h1:Oesb/0uFAyWoaw1U1qS5zyjCg5NP9C9iwjnI4tIsXEE= -github.com/golangci/golangci-lint v1.62.0 h1:/G0g+bi1BhmGJqLdNQkKBWjcim8HjOPc4tsKuHDOhcI= -github.com/golangci/golangci-lint v1.62.0/go.mod h1:jtoOhQcKTz8B6dGNFyfQV3WZkQk+YvBDewDtNpiAJts= +github.com/golangci/golangci-lint v1.62.2 h1:b8K5K9PN+rZN1+mKLtsZHz2XXS9aYKzQ9i25x3Qnxxw= +github.com/golangci/golangci-lint v1.62.2/go.mod h1:ILWWyeFUrctpHVGMa1dg2xZPKoMUTc5OIMgW7HZr34g= github.com/golangci/misspell v0.6.0 h1:JCle2HUTNWirNlDIAUO44hUsKhOFqGPoC4LZxlaSXDs= github.com/golangci/misspell v0.6.0/go.mod h1:keMNyY6R9isGaSAu+4Q8NMBwMPkh15Gtc8UCVoDtAWo= github.com/golangci/modinfo v0.3.4 h1:oU5huX3fbxqQXdfspamej74DFX0kyGLkw1ppvXoJ8GA= @@ -183,11 +183,15 @@ github.com/gostaticanalysis/nilerr v0.1.1/go.mod h1:wZYb6YI5YAxxq0i1+VJbY0s2YONW github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M= github.com/gostaticanalysis/testutil v0.4.0 h1:nhdCmubdmDF6VEatUNjgUZBJKWRqugoISdUv3PPQgHY= github.com/gostaticanalysis/testutil v0.4.0/go.mod h1:bLIoPefWXrRi/ssLFWX1dx7Repi5x3CuviD3dgAZaBU= +github.com/hashicorp/go-immutable-radix/v2 v2.1.0 h1:CUW5RYIcysz+D3B+l1mDeXrQ7fUvGGCwJfdASSzbrfo= +github.com/hashicorp/go-immutable-radix/v2 v2.1.0/go.mod h1:hgdqLXA4f6NIjRVisM1TJ9aOJVNRqKZj+xDGF6m7PBw= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= @@ -198,8 +202,8 @@ github.com/jgautheron/goconst v1.7.1 h1:VpdAG7Ca7yvvJk5n8dMwQhfEZJh95kl/Hl9S1OI5 github.com/jgautheron/goconst v1.7.1/go.mod h1:aAosetZ5zaeC/2EfMeRswtxUFBpe2Hr7HzkgX4fanO4= github.com/jingyugao/rowserrcheck v1.1.1 h1:zibz55j/MJtLsjP1OF4bSdgXxwL1b+Vn7Tjzq7gFzUs= github.com/jingyugao/rowserrcheck v1.1.1/go.mod h1:4yvlZSDb3IyDTUZJUmpZfm2Hwok+Dtp+nu2qOq+er9c= -github.com/jjti/go-spancheck v0.6.2 h1:iYtoxqPMzHUPp7St+5yA8+cONdyXD3ug6KK15n7Pklk= -github.com/jjti/go-spancheck v0.6.2/go.mod h1:+X7lvIrR5ZdUTkxFYqzJ0abr8Sb5LOo80uOhWNqIrYA= +github.com/jjti/go-spancheck v0.6.4 h1:Tl7gQpYf4/TMU7AT84MN83/6PutY21Nb9fuQjFTpRRc= +github.com/jjti/go-spancheck v0.6.4/go.mod h1:yAEYdKJ2lRkDA8g7X+oKUHXOWVAXSBJRv04OhF+QUjk= 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= @@ -224,10 +228,12 @@ github.com/kyoh86/exportloopref v0.1.11 h1:1Z0bcmTypkL3Q4k+IDHMWTcnCliEZcaPiIe0/ github.com/kyoh86/exportloopref v0.1.11/go.mod h1:qkV4UF1zGl6EkF1ox8L5t9SwyeBAZ3qLMd6up458uqA= github.com/lasiar/canonicalheader v1.1.2 h1:vZ5uqwvDbyJCnMhmFYimgMZnJMjwljN5VGY0VKbMXb4= github.com/lasiar/canonicalheader v1.1.2/go.mod h1:qJCeLFS0G/QlLQ506T+Fk/fWMa2VmBUiEI2cuMK4djI= -github.com/ldez/gomoddirectives v0.2.4 h1:j3YjBIjEBbqZ0NKtBNzr8rtMHTOrLPeiwTkfUJZ3alg= -github.com/ldez/gomoddirectives v0.2.4/go.mod h1:oWu9i62VcQDYp9EQ0ONTfqLNh+mDLWWDO+SO0qSQw5g= -github.com/ldez/tagliatelle v0.5.0 h1:epgfuYt9v0CG3fms0pEgIMNPuFf/LpPIfjk4kyqSioo= -github.com/ldez/tagliatelle v0.5.0/go.mod h1:rj1HmWiL1MiKQuOONhd09iySTEkUuE/8+5jtPYz9xa4= +github.com/ldez/gomoddirectives v0.6.0 h1:Jyf1ZdTeiIB4dd+2n4qw+g4aI9IJ6JyfOZ8BityWvnA= +github.com/ldez/gomoddirectives v0.6.0/go.mod h1:TuwOGYoPAoENDWQpe8DMqEm5nIfjrxZXmxX/CExWyZ4= +github.com/ldez/grignotin v0.6.0 h1:i++3002hxD5TpVto0iLjLrfz1V+yEJ+BBk4glb3aqC8= +github.com/ldez/grignotin v0.6.0/go.mod h1:uaVTr0SoZ1KBii33c47O1M8Jp3OP3YDwhZCmzT9GHEk= +github.com/ldez/tagliatelle v0.6.0 h1:1Muumft/shmQ0x96vA6a/OUgTjamRt8jUlZPLm1ruwA= +github.com/ldez/tagliatelle v0.6.0/go.mod h1:WeZ7TgEqq7fw/0Zj8BuQhh4+4KX1/+g0O11eygvClRA= github.com/leonklingele/grouper v1.1.2 h1:o1ARBDLOmmasUaNDesWqWCIFH3u7hoFlM84YrjT3mIY= github.com/leonklingele/grouper v1.1.2/go.mod h1:6D0M/HVkhs2yRKRFZUoGjeDy7EZTfFBE9gl4kjmIGkA= github.com/macabu/inamedparam v0.1.3 h1:2tk/phHkMlEL/1GNe/Yf6kkR/hkcUdAEY3L0hjYV1Mk= @@ -240,8 +246,8 @@ github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s github.com/maratori/testableexamples v1.0.0/go.mod h1:4rhjL1n20TUTT4vdh3RDqSizKLyXp7K2u6HgraZCGzE= github.com/maratori/testpackage v1.1.1 h1:S58XVV5AD7HADMmD0fNnziNHqKvSdDuEKdPD1rNTU04= github.com/maratori/testpackage v1.1.1/go.mod h1:s4gRK/ym6AMrqpOa/kEbQTV4Q4jb7WeLZzVhVVVOQMc= -github.com/matoous/godox v0.0.0-20240105082147-c5b5e0e7c0c0 h1:Ny7cm4KSWceJLYyI1sm+aFIVDWSGXLcOJ0O0UaS5wdU= -github.com/matoous/godox v0.0.0-20240105082147-c5b5e0e7c0c0/go.mod h1:jgE/3fUXiTurkdHOLT5WEkThTSuE7yxHv5iWPa80afs= +github.com/matoous/godox v0.0.0-20241202171805-94d1edd68ebb h1:16vJua1jlCfNLTCcMREK9/rX6SYkD22pD2UnUBTi0jU= +github.com/matoous/godox v0.0.0-20241202171805-94d1edd68ebb/go.mod h1:jgE/3fUXiTurkdHOLT5WEkThTSuE7yxHv5iWPa80afs= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -302,8 +308,8 @@ github.com/pavius/impi v0.0.3 h1:DND6MzU+BLABhOZXbELR3FU8b+zDgcq4dOCNLhiTYuI= github.com/pavius/impi v0.0.3/go.mod h1:x/hU0bfdWIhuOT1SKwiJg++yvkk6EuOtJk8WtDZqgr8= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= -github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.3 h1:KY6GmIfOJB5Nc3fX/f66fsWnPt1Fc0+QqQIbvAsyYkM= -github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.3/go.mod h1:6FV76bV3LF98Rn1Q62RRxcPk1XqRzRNcI6PeFe9MNbk= +github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.5 h1:Hem1TdVF0CZivFKwCMLUYwL978MaeyPL2WWE3eM6qjQ= +github.com/pingidentity/pingfederate-go-client/v1210 v1210.0.5/go.mod h1:UeqdbbpFTqN4llGpjQJqHWu73is6F9CZCBShEEffSa8= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -349,8 +355,8 @@ github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3 github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/sanposhiho/wastedassign/v2 v2.0.7 h1:J+6nrY4VW+gC9xFzUc+XjPD3g3wF3je/NsJFwFK7Uxc= -github.com/sanposhiho/wastedassign/v2 v2.0.7/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= +github.com/sanposhiho/wastedassign/v2 v2.1.0 h1:crurBF7fJKIORrV85u9UUpePDYGWnwvv3+A96WvwXT0= +github.com/sanposhiho/wastedassign/v2 v2.1.0/go.mod h1:+oSmSC+9bQ+VUAxA66nBb0Z7N8CK7mscKTDYC6aIek4= github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tMEOsumirXcOJqAw= @@ -387,8 +393,8 @@ github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= github.com/ssgreg/nlreturn/v2 v2.2.1 h1:X4XDI7jstt3ySqGU86YGAURbxw3oTDPK9sPEi6YEwQ0= github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRkkxBiELzh2I= -github.com/stbenjam/no-sprintf-host-port v0.1.1 h1:tYugd/yrm1O0dV+ThCbaKZh195Dfm07ysF0U6JQXczc= -github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8LHsN9N74I+PhRquPsxpL0I= +github.com/stbenjam/no-sprintf-host-port v0.2.0 h1:i8pxvGrt1+4G0czLr/WnmyH7zbZ8Bg8etvARQ1rpyl4= +github.com/stbenjam/no-sprintf-host-port v0.2.0/go.mod h1:eL0bQ9PasS0hsyTyfTjjG+E80QIyPnBVQbYZyv20Jfk= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -401,12 +407,12 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/tdakkota/asciicheck v0.2.0 h1:o8jvnUANo0qXtnslk2d3nMKTFNlOnJjRrNcj0j9qkHM= -github.com/tdakkota/asciicheck v0.2.0/go.mod h1:Qb7Y9EgjCLJGup51gDHFzbI08/gbGhL/UVhYIPWG2rg= +github.com/tdakkota/asciicheck v0.3.0 h1:LqDGgZdholxZMaJgpM6b0U9CFIjDCbFdUF00bDnBKOQ= +github.com/tdakkota/asciicheck v0.3.0/go.mod h1:KoJKXuX/Z/lt6XzLo8WMBfQGzak0SrAKZlvRr4tg8Ac= github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA= github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0= github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag= @@ -427,8 +433,8 @@ github.com/ultraware/whitespace v0.1.1 h1:bTPOGejYFulW3PkcrqkeQwOd6NKOOXvmGD9bo/ github.com/ultraware/whitespace v0.1.1/go.mod h1:XcP1RLD81eV4BW8UhQlpaR+SDc2givTvyI8a586WjW8= github.com/uudashr/gocognit v1.1.3 h1:l+a111VcDbKfynh+airAy/DJQKaXh2m9vkoysMPSZyM= github.com/uudashr/gocognit v1.1.3/go.mod h1:aKH8/e8xbTRBwjbCkwZ8qt4l2EpKXl31KMHgSS+lZ2U= -github.com/uudashr/iface v1.2.0 h1:ECJjh5q/1Zmnv/2yFpWV6H3oMg5+Mo+vL0aqw9Gjazo= -github.com/uudashr/iface v1.2.0/go.mod h1:Ux/7d/rAF3owK4m53cTVXL4YoVHKNqnoOeQHn2xrlp0= +github.com/uudashr/iface v1.3.0 h1:zwPch0fs9tdh9BmL5kcgSpvnObV+yHjO4JjVBl8IA10= +github.com/uudashr/iface v1.3.0/go.mod h1:4QvspiRd3JLPAEXBQ9AiZpLbJlrWWgRChOKDJEuQTdg= github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU= github.com/xen0n/gosmopolitan v1.2.2/go.mod h1:7XX7Mj61uLYrj0qmeN0zi7XDon9JRAEhYQqAPLVNTeg= github.com/yagipy/maintidx v1.0.0 h1:h5NvIsCz+nRDapQ0exNv4aJ0yXSI0420omVANTv3GJM= @@ -475,11 +481,11 @@ 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.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= @@ -497,6 +503,7 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= @@ -548,6 +555,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= @@ -559,6 +567,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= @@ -576,12 +585,12 @@ golang.org/x/tools v0.1.1-0.20210205202024-ef80cdb6ec6d/go.mod h1:9bzcO0MWcOuT0t golang.org/x/tools v0.1.1-0.20210302220138-2ac05c832e1a/go.mod h1:9bzcO0MWcOuT0tm1iBGzDVPshzfwoVvREIui8C+MHqU= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o= diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_settings_test.go b/internal/connector/pingone/mfa/resources/pingone_mfa_settings_test.go index 5387a5ce..4708b31c 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_settings_test.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_settings_test.go @@ -17,7 +17,7 @@ func TestMFASettingsExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_mfa_settings", - ResourceName: "mfa_settings", + ResourceName: "pingone_mfa_settings", ResourceID: testutils.GetEnvironmentID(), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization.go index 91db92f7..2429116b 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization.go @@ -95,7 +95,7 @@ func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizationsByAgr } for _, languageInner := range embedded.GetLanguages() { - if languageInner.AgreementLanguage == nil { + if languageInner.AgreementLanguage != nil { agreementLanguageId, agreementLanguageIdOk := languageInner.AgreementLanguage.GetIdOk() agreementLanguageLocale, agreementLanguageLocaleOk := languageInner.AgreementLanguage.GetLocaleOk() diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision_test.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision_test.go index 29c8f512..d928a17f 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision_test.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision_test.go @@ -18,17 +18,17 @@ func TestAgreementLocalizationRevisionExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_agreement_localization_revision", - ResourceName: "Test_fr_1", + ResourceName: "Test_fr_08c49433-b84b-4aeb-860b-02d58336e309", ResourceID: fmt.Sprintf("%s/37ab76b8-8eff-43ae-b499-a7dce9fe0e75/03cd7e69-2836-4bad-b69f-249684c42fd9/08c49433-b84b-4aeb-860b-02d58336e309", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_agreement_localization_revision", - ResourceName: "Test_en_1", + ResourceName: "Test_en_2c2a98d7-8c11-4887-b35b-7f5358f75ec1", ResourceID: fmt.Sprintf("%s/37ab76b8-8eff-43ae-b499-a7dce9fe0e75/b5ceb6b5-025c-4896-951d-dd676c96d3c6/2c2a98d7-8c11-4887-b35b-7f5358f75ec1", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_agreement_localization_revision", - ResourceName: "Test_en_2", + ResourceName: "Test_en_82cff258-1af7-4f2d-94f0-a0ebbbc84a5e", ResourceID: fmt.Sprintf("%s/37ab76b8-8eff-43ae-b499-a7dce9fe0e75/b5ceb6b5-025c-4896-951d-dd676c96d3c6/82cff258-1af7-4f2d-94f0-a0ebbbc84a5e", testutils.GetEnvironmentID()), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_settings_test.go b/internal/connector/pingone/platform/resources/pingone_branding_settings_test.go index 37211710..63074315 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_settings_test.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_settings_test.go @@ -17,7 +17,7 @@ func TestBrandingSettingsExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_branding_settings", - ResourceName: "branding_settings", + ResourceName: "pingone_branding_settings", ResourceID: testutils.GetEnvironmentID(), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go b/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go index 87b7751a..45fc2483 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go @@ -1,6 +1,8 @@ package resources import ( + "fmt" + "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -87,7 +89,7 @@ func (r *PingOneBrandingThemeDefaultResource) addImportBlock(brandingThemeName s importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: brandingThemeName, + ResourceName: fmt.Sprintf("%s_default_theme", brandingThemeName), ResourceID: r.clientInfo.ExportEnvironmentID, CommentInformation: common.GenerateCommentInformation(commentData), } diff --git a/internal/connector/pingone/platform/resources/pingone_environment_test.go b/internal/connector/pingone/platform/resources/pingone_environment_test.go index ceb86f1a..ebc34e9e 100644 --- a/internal/connector/pingone/platform/resources/pingone_environment_test.go +++ b/internal/connector/pingone/platform/resources/pingone_environment_test.go @@ -17,7 +17,7 @@ func TestEnvironmentExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_environment", - ResourceName: "export_environment", + ResourceName: "pingone_environment", ResourceID: testutils.GetEnvironmentID(), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2_test.go b/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2_test.go index 30d413ac..ca277d56 100644 --- a/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2_test.go +++ b/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2_test.go @@ -17,7 +17,7 @@ func TestFormRecaptchaV2Export(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_forms_recaptcha_v2", - ResourceName: "recaptcha_configuration", + ResourceName: "pingone_forms_recaptcha_v2", ResourceID: testutils.GetEnvironmentID(), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_gateway_credential_test.go b/internal/connector/pingone/platform/resources/pingone_gateway_credential_test.go index fea3a203..ae24b50f 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway_credential_test.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway_credential_test.go @@ -18,42 +18,42 @@ func TestGatewayCredentialExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_gateway_credential", - ResourceName: "random_credential_1", + ResourceName: "random_credential_932c1ca6-da29-4a0e-b19c-d012f5b6014f", ResourceID: fmt.Sprintf("%s/0b1d882c-5c71-4600-a9fb-befdad921df2/932c1ca6-da29-4a0e-b19c-d012f5b6014f", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "PingFederate LDAP Gateway_credential_1", + ResourceName: "PingFederate LDAP Gateway_credential_fa809636-4796-4a25-8693-2b786eed4f71", ResourceID: fmt.Sprintf("%s/3b7b5d9d-1820-4b21-bb29-a5336af65352/fa809636-4796-4a25-8693-2b786eed4f71", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "PF TF Provider_credential_1", + ResourceName: "PF TF Provider_credential_971b5d20-0955-4030-b49b-7e349b3b9b1e", ResourceID: fmt.Sprintf("%s/554257ac-76ca-447a-a210-722343328312/971b5d20-0955-4030-b49b-7e349b3b9b1e", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "Local Test_credential_1", + ResourceName: "Local Test_credential_bd2307d8-2a5e-4c11-a397-cfb991179f3f", ResourceID: fmt.Sprintf("%s/5cd3f6b7-35f0-4873-ac64-f32118bf3102/bd2307d8-2a5e-4c11-a397-cfb991179f3f", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "TestGateway_credential_1", + ResourceName: "TestGateway_credential_2e2ab72c-6dcf-4ec2-96be-1a5ba2e66f4a", ResourceID: fmt.Sprintf("%s/bc37814f-b3a9-4149-b880-0ed457bbb5c5/2e2ab72c-6dcf-4ec2-96be-1a5ba2e66f4a", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "TestGateway_credential_2", + ResourceName: "TestGateway_credential_5aa73594-66a3-4175-ad69-67fa38b5e307", ResourceID: fmt.Sprintf("%s/bc37814f-b3a9-4149-b880-0ed457bbb5c5/5aa73594-66a3-4175-ad69-67fa38b5e307", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "TestGateway_credential_3", + ResourceName: "TestGateway_credential_ed648842-d109-4a40-97ba-ef4f8ce8eabe", ResourceID: fmt.Sprintf("%s/bc37814f-b3a9-4149-b880-0ed457bbb5c5/ed648842-d109-4a40-97ba-ef4f8ce8eabe", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_gateway_credential", - ResourceName: "another connection for testing_credential_1", + ResourceName: "another connection for testing_credential_98f9946c-3a78-4b4b-8645-a425f89c7ab5", ResourceID: fmt.Sprintf("%s/8773b833-ade0-4883-9cad-05fe82b23135/98f9946c-3a78-4b4b-8645-a425f89c7ab5", testutils.GetEnvironmentID()), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_language_update_test.go b/internal/connector/pingone/platform/resources/pingone_language_update_test.go index b38a778f..5462624f 100644 --- a/internal/connector/pingone/platform/resources/pingone_language_update_test.go +++ b/internal/connector/pingone/platform/resources/pingone_language_update_test.go @@ -21,6 +21,11 @@ func TestLanguageUpdateExport(t *testing.T) { ResourceName: "French_update", ResourceID: fmt.Sprintf("%s/3f8a2e14-0ace-41db-a92d-74b3b7913ffe", testutils.GetEnvironmentID()), }, + { + ResourceType: "pingone_language_update", + ResourceName: "English_update", + ResourceID: fmt.Sprintf("%s/88c78fb2-9d74-41e3-a1d8-a9f729a2b463", testutils.GetEnvironmentID()), + }, } testutils.ValidateImportBlocks(t, resource, &expectedImportBlocks) diff --git a/internal/connector/pingone/platform/resources/pingone_notification_settings_test.go b/internal/connector/pingone/platform/resources/pingone_notification_settings_test.go index 4ff98a11..dca2f02f 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_settings_test.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_settings_test.go @@ -17,7 +17,7 @@ func TestNotificationSettingsExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_notification_settings", - ResourceName: "notification_settings", + ResourceName: "pingone_notification_settings", ResourceID: testutils.GetEnvironmentID(), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings_test.go b/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings_test.go index 07ab6bfd..aafcb226 100644 --- a/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings_test.go +++ b/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings_test.go @@ -18,7 +18,7 @@ func TestPhoneDeliverySettingsExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_phone_delivery_settings", - ResourceName: "Test Provider", + ResourceName: "provider_custom_eb90b2a5-a801-45b3-8bf4-7d06cb6a5374", ResourceID: fmt.Sprintf("%s/eb90b2a5-a801-45b3-8bf4-7d06cb6a5374", testutils.GetEnvironmentID()), }, } diff --git a/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go b/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go index 009b9050..96f4ee46 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go +++ b/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go @@ -120,7 +120,10 @@ func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrant grantResourceId, grantResourceIdOk := grantResource.GetIdOk() if grantResourceIdOk { - r.exportApplicationResourceGrantsByResource(appId, appName, *grantId, *grantResourceId) + err := r.exportApplicationResourceGrantsByResource(appId, appName, *grantId, *grantResourceId) + if err != nil { + return err + } } } } diff --git a/internal/connector/pingone/sso/resources/pingone_application_role_assignment_test.go b/internal/connector/pingone/sso/resources/pingone_application_role_assignment_test.go index ea1ed3eb..ebead167 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_role_assignment_test.go +++ b/internal/connector/pingone/sso/resources/pingone_application_role_assignment_test.go @@ -18,132 +18,132 @@ func TestApplicationRoleAssignmentExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_application_role_assignment", - ResourceName: "OAuth Worker App_PingFederate Crypto Administrator_1", + ResourceName: "OAuth Worker App_PingFederate Crypto Administrator_d4aa4aec-c521-4538-ab76-8776355d2b22", ResourceID: fmt.Sprintf("%s/9d6c443b-6329-4d3c-949e-880eda3b9599/d4aa4aec-c521-4538-ab76-8776355d2b22", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "OAuth Worker App_PingFederate User Administrator_2", + ResourceName: "OAuth Worker App_PingFederate User Administrator_9f431f95-8df7-43cb-8419-e2b3898ca8c4", ResourceID: fmt.Sprintf("%s/9d6c443b-6329-4d3c-949e-880eda3b9599/9f431f95-8df7-43cb-8419-e2b3898ca8c4", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "OAuth Worker App_PingFederate Administrator_3", + ResourceName: "OAuth Worker App_PingFederate Administrator_28607a1f-b0b3-4c43-8807-4bf8a93c8d07", ResourceID: fmt.Sprintf("%s/9d6c443b-6329-4d3c-949e-880eda3b9599/28607a1f-b0b3-4c43-8807-4bf8a93c8d07", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "OAuth Worker App_PingFederate Expression Administrator_4", + ResourceName: "OAuth Worker App_PingFederate Expression Administrator_cbd5b6a0-1748-4ca6-b252-e02fd843897e", ResourceID: fmt.Sprintf("%s/9d6c443b-6329-4d3c-949e-880eda3b9599/cbd5b6a0-1748-4ca6-b252-e02fd843897e", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "PingOne DaVinci Connection_Identity Data Admin_1", + ResourceName: "PingOne DaVinci Connection_Identity Data Admin_4331fc1a-434c-4cee-ba2a-ceb57974550c", ResourceID: fmt.Sprintf("%s/7b621870-7124-4426-b432-6c675642afcb/4331fc1a-434c-4cee-ba2a-ceb57974550c", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "PingOne DaVinci Connection_DaVinci Admin_2", + ResourceName: "PingOne DaVinci Connection_DaVinci Admin_ebcdd4c7-0014-4eb5-9aa9-15af45795c15", ResourceID: fmt.Sprintf("%s/7b621870-7124-4426-b432-6c675642afcb/ebcdd4c7-0014-4eb5-9aa9-15af45795c15", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "PingOne DaVinci Connection_Environment Admin_3", + ResourceName: "PingOne DaVinci Connection_Environment Admin_9e1d7f96-c4a9-49d3-bb2d-d2b1fef197dd", ResourceID: fmt.Sprintf("%s/7b621870-7124-4426-b432-6c675642afcb/9e1d7f96-c4a9-49d3-bb2d-d2b1fef197dd", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Identity Data Admin_1", + ResourceName: "Worker App_Identity Data Admin_9225c10f-b902-4107-8aba-b15b219d6c0e", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/9225c10f-b902-4107-8aba-b15b219d6c0e", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Client Application Developer_2", + ResourceName: "Worker App_Client Application Developer_0081f0ab-d02c-4718-b10c-35fd48b82f47", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/0081f0ab-d02c-4718-b10c-35fd48b82f47", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Identity Data Read Only_3", + ResourceName: "Worker App_Identity Data Read Only_a0f34409-4d1b-4b22-911a-7b4a61ac68b1", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/a0f34409-4d1b-4b22-911a-7b4a61ac68b1", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Identity Data Admin_4", + ResourceName: "Worker App_Identity Data Admin_970667f1-26d5-4021-809f-e5d17fe44a7d", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/970667f1-26d5-4021-809f-e5d17fe44a7d", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Client Application Developer_5", + ResourceName: "Worker App_Client Application Developer_785b582f-eaf2-4a0b-ac8e-b7c7f9665762", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/785b582f-eaf2-4a0b-ac8e-b7c7f9665762", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Identity Data Read Only_6", + ResourceName: "Worker App_Identity Data Read Only_91562725-239b-4854-8cef-c4efe35ea77f", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/91562725-239b-4854-8cef-c4efe35ea77f", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Identity Data Admin_7", + ResourceName: "Worker App_Identity Data Admin_ed54c262-38ab-4874-a206-2d13e34f21fd", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/ed54c262-38ab-4874-a206-2d13e34f21fd", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Client Application Developer_8", + ResourceName: "Worker App_Client Application Developer_3f112aa9-b712-4388-821d-8f37a429b071", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/3f112aa9-b712-4388-821d-8f37a429b071", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Identity Data Read Only_9", + ResourceName: "Worker App_Identity Data Read Only_1395d969-6527-45f4-b356-4ef36a5d6349", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/1395d969-6527-45f4-b356-4ef36a5d6349", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_PingFederate Crypto Administrator_10", + ResourceName: "Worker App_PingFederate Crypto Administrator_c01ef5c4-74c4-4074-8929-b0836aa9a783", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/c01ef5c4-74c4-4074-8929-b0836aa9a783", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_DaVinci Admin_11", + ResourceName: "Worker App_DaVinci Admin_9bdbe295-e199-4952-8717-3405112eccad", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/9bdbe295-e199-4952-8717-3405112eccad", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Organization Admin_12", + ResourceName: "Worker App_Organization Admin_b57756a8-d9c6-4fbc-95d4-9d2aabf801e0", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/b57756a8-d9c6-4fbc-95d4-9d2aabf801e0", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Environment Admin_13", + ResourceName: "Worker App_Environment Admin_3e77cca6-8820-4eb6-bcfd-761cf4e74ad1", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/3e77cca6-8820-4eb6-bcfd-761cf4e74ad1", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_PingFederate User Administrator_14", + ResourceName: "Worker App_PingFederate User Administrator_6600fad1-82c4-412f-aa2c-22e8668d8c3a", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/6600fad1-82c4-412f-aa2c-22e8668d8c3a", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_Configuration Read Only_15", + ResourceName: "Worker App_Configuration Read Only_6f01ea75-5e04-45a5-8614-186b58f9eb4e", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/6f01ea75-5e04-45a5-8614-186b58f9eb4e", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_PingFederate Auditor_16", + ResourceName: "Worker App_PingFederate Auditor_cf1edf79-fd13-4d72-a049-7bdc4377ee0c", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/cf1edf79-fd13-4d72-a049-7bdc4377ee0c", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_PingFederate Administrator_17", + ResourceName: "Worker App_PingFederate Administrator_530824c1-675f-4282-8a61-6567fc3afee6", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/530824c1-675f-4282-8a61-6567fc3afee6", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_DaVinci Admin Read Only_18", + ResourceName: "Worker App_DaVinci Admin Read Only_e82d85ed-8687-4724-87ad-7f138cdbe673", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/e82d85ed-8687-4724-87ad-7f138cdbe673", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_application_role_assignment", - ResourceName: "Worker App_PingFederate Expression Administrator_19", + ResourceName: "Worker App_PingFederate Expression Administrator_c090f7c9-4419-447b-8316-baf3e70030bc", ResourceID: fmt.Sprintf("%s/c45c2f8c-dee0-4a12-b169-bae693a13d57/c090f7c9-4419-447b-8316-baf3e70030bc", testutils.GetEnvironmentID()), }, } diff --git a/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go b/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go index b17c9f20..34621ceb 100644 --- a/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go @@ -142,7 +142,7 @@ func (r *PingOneGroupRoleAssignmentResource) addImportBlock(groupId, groupName, importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", groupName, roleName), + ResourceName: fmt.Sprintf("%s_%s_%s", groupName, roleName, groupRoleAssignmentId), ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, groupId, groupRoleAssignmentId), CommentInformation: common.GenerateCommentInformation(commentData), } diff --git a/internal/connector/pingone/sso/resources/pingone_group_role_assignment_test.go b/internal/connector/pingone/sso/resources/pingone_group_role_assignment_test.go index e6ad74d0..9e76a060 100644 --- a/internal/connector/pingone/sso/resources/pingone_group_role_assignment_test.go +++ b/internal/connector/pingone/sso/resources/pingone_group_role_assignment_test.go @@ -18,12 +18,12 @@ func TestGroupRoleAssignmentExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_group_role_assignment", - ResourceName: "testing_Client Application Developer_1", + ResourceName: "testing_Client Application Developer_1db1accc-f63f-4f03-ab62-c767398fa730", ResourceID: fmt.Sprintf("%s/b6924f30-73ca-4d3c-964b-90c77adce6a7/1db1accc-f63f-4f03-ab62-c767398fa730", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_group_role_assignment", - ResourceName: "testing_Identity Data Read Only_2", + ResourceName: "testing_Identity Data Read Only_53a88921-2a9f-44f1-958e-3db9be3f8c69", ResourceID: fmt.Sprintf("%s/b6924f30-73ca-4d3c-964b-90c77adce6a7/53a88921-2a9f-44f1-958e-3db9be3f8c69", testutils.GetEnvironmentID()), }, } diff --git a/internal/connector/pingone/sso/resources/pingone_identity_provider.go b/internal/connector/pingone/sso/resources/pingone_identity_provider.go index df527871..3ae9eb53 100644 --- a/internal/connector/pingone/sso/resources/pingone_identity_provider.go +++ b/internal/connector/pingone/sso/resources/pingone_identity_provider.go @@ -1,6 +1,8 @@ package resources import ( + "fmt" + "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -110,7 +112,7 @@ func (r *PingOneIdentityProviderResource) addImportBlock(idpId, idpName string) importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), ResourceName: idpName, - ResourceID: idpId, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, idpId), CommentInformation: common.GenerateCommentInformation(commentData), } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_attribute.go b/internal/connector/pingone/sso/resources/pingone_resource_attribute.go index ac7bc09e..b8829643 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_attribute.go @@ -141,8 +141,8 @@ func (r *PingOneResourceAttributeResource) addImportBlock(resourceId, resourceNa importBlock := connector.ImportBlock{ ResourceType: r.ResourceType(), - ResourceName: resourceName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceAttributeId), + ResourceName: fmt.Sprintf("%s_%s", resourceName, resourceAttributeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, resourceId, resourceAttributeId), CommentInformation: common.GenerateCommentInformation(commentData), } From 5c88cb70eecb6aba16208e5de07d55e83e9cd642 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Thu, 12 Dec 2024 11:13:57 -0700 Subject: [PATCH 8/9] PR review changes --- ...pingone_mfa_application_push_credential.go | 90 ++++---- .../resources/pingone_mfa_device_policy.go | 62 +++--- .../mfa/resources/pingone_mfa_fido2_policy.go | 62 +++--- .../mfa/resources/pingone_mfa_settings.go | 46 ++--- .../pingone_platform_connector_test.go | 11 +- .../platform/resources/pingone_agreement.go | 62 +++--- .../resources/pingone_agreement_enable.go | 21 +- .../pingone_agreement_localization.go | 89 ++++---- .../pingone_agreement_localization_enable.go | 21 +- ...pingone_agreement_localization_revision.go | 116 ++++++----- .../resources/pingone_branding_settings.go | 46 ++--- .../resources/pingone_branding_theme.go | 62 +++--- .../pingone_branding_theme_default.go | 56 +++-- .../platform/resources/pingone_certificate.go | 62 +++--- .../resources/pingone_custom_domain.go | 62 +++--- .../platform/resources/pingone_environment.go | 42 ++-- .../platform/resources/pingone_form.go | 62 +++--- .../resources/pingone_forms_recaptcha_v2.go | 46 ++--- .../platform/resources/pingone_gateway.go | 62 +++--- .../resources/pingone_gateway_credential.go | 88 ++++---- .../pingone_gateway_role_assignment.go | 106 +++++----- .../pingone_identity_propagation_plan.go | 62 +++--- .../pingone/platform/resources/pingone_key.go | 67 +++--- .../resources/pingone_key_rotation_policy.go | 62 +++--- .../platform/resources/pingone_language.go | 62 +++--- .../resources/pingone_language_update.go | 62 +++--- .../resources/pingone_notification_policy.go | 62 +++--- .../pingone_notification_settings.go | 46 ++--- .../pingone_notification_settings_email.go | 46 ++--- .../pingone_notification_template_content.go | 180 ++++++++++++---- ...gone_notification_template_content_test.go | 192 ++++++++++++++---- .../pingone_phone_delivery_settings.go | 62 +++--- .../resources/pingone_system_application.go | 62 +++--- .../pingone_trusted_email_address.go | 90 ++++---- .../resources/pingone_trusted_email_domain.go | 62 +++--- .../platform/resources/pingone_webhook.go | 62 +++--- .../protect/resources/pingone_risk_policy.go | 62 +++--- .../resources/pingone_risk_predictor.go | 67 +++--- .../sso/resources/pingone_application.go | 62 +++--- .../pingone_application_attribute_mapping.go | 90 ++++---- ...gone_application_flow_policy_assignment.go | 106 +++++----- .../pingone_application_resource_grant.go | 106 +++++----- .../pingone_application_role_assignment.go | 108 +++++----- .../resources/pingone_application_secret.go | 94 ++++----- ...e_application_sign_on_policy_assignment.go | 106 +++++----- .../pingone/sso/resources/pingone_group.go | 62 +++--- .../sso/resources/pingone_group_nesting.go | 90 ++++---- .../pingone_group_role_assignment.go | 108 +++++----- .../resources/pingone_identity_provider.go | 63 +++--- .../pingone_identity_provider_attribute.go | 91 +++++---- .../sso/resources/pingone_password_policy.go | 62 +++--- .../sso/resources/pingone_population.go | 62 +++--- .../resources/pingone_population_default.go | 56 +++-- .../pingone/sso/resources/pingone_resource.go | 62 +++--- .../resources/pingone_resource_attribute.go | 95 +++++---- .../sso/resources/pingone_resource_scope.go | 90 ++++---- .../pingone_resource_scope_openid.go | 89 ++++---- .../pingone_resource_scope_pingone_api.go | 88 ++++---- .../sso/resources/pingone_schema_attribute.go | 90 ++++---- .../sso/resources/pingone_sign_on_policy.go | 62 +++--- .../pingone_sign_on_policy_action.go | 90 ++++---- 61 files changed, 2465 insertions(+), 2049 deletions(-) diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go index b4744b64..0e39440e 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_application_push_credential.go @@ -15,15 +15,13 @@ var ( ) type PingOneMFAApplicationPushCredentialResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneMFAApplicationPushCredentialResource func MFAApplicationPushCredential(clientInfo *connector.PingOneClientInfo) *PingOneMFAApplicationPushCredentialResource { return &PingOneMFAApplicationPushCredentialResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,31 +33,62 @@ func (r *PingOneMFAApplicationPushCredentialResource) ExportAll() (*[]connector. l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportPushCreds() + importBlocks := []connector.ImportBlock{} + + appData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *appData { + pushCredData, err := r.getPushCredentialData(appId) + if err != nil { + return nil, err + } + + for pushCredId, pushCredType := range *pushCredData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Application Push Credential ID": pushCredId, + "MFA Application Push Credential Type": pushCredType, + "Native OIDC Application ID": appId, + "Native OIDC Application Name": appName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, pushCredType), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, pushCredId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneMFAApplicationPushCredentialResource) exportPushCreds() error { +func (r *PingOneMFAApplicationPushCredentialResource) getApplicationData() (*map[string]string, error) { + appData := make(map[string]string) + // Fetch all pingone_application resources that could have pingone_mfa_application_push_credentials iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", "pingone_application") if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -71,35 +100,34 @@ func (r *PingOneMFAApplicationPushCredentialResource) exportPushCreds() error { if appIdOk && appNameOk && appTypeOk { if *appType == management.ENUMAPPLICATIONTYPE_NATIVE_APP { - err := r.exportPushCredsByApp(*appId, *appName) - if err != nil { - return err - } + appData[*appId] = *appName } } } } } - return nil + return &appData, nil } -func (r *PingOneMFAApplicationPushCredentialResource) exportPushCredsByApp(appId, appName string) error { +func (r *PingOneMFAApplicationPushCredentialResource) getPushCredentialData(appId string) (*map[string]string, error) { + pushCredData := make(map[string]string) + iter := r.clientInfo.ApiClient.MFAAPIClient.ApplicationsApplicationMFAPushCredentialsApi.ReadAllMFAPushCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllMFAPushCredentials", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, pushCred := range embedded.GetPushCredentials() { @@ -107,30 +135,10 @@ func (r *PingOneMFAApplicationPushCredentialResource) exportPushCredsByApp(appId pushCredType, pushCredTypeOk := pushCred.GetTypeOk() if pushCredIdOk && pushCredTypeOk { - r.addImportBlock(appId, appName, *pushCredId, string(*pushCredType)) + pushCredData[*pushCredId] = string(*pushCredType) } } } - return nil -} - -func (r *PingOneMFAApplicationPushCredentialResource) addImportBlock(appId, appName, pushCredId, pushCredType string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "MFA Application Push Credential ID": pushCredId, - "MFA Application Push Credential Type": pushCredType, - "Native OIDC Application ID": appId, - "Native OIDC Application Name": appName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", appName, pushCredType), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, pushCredId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &pushCredData, nil } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go b/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go index 35bf0578..19088299 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_device_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOneMFADevicePolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneMFADevicePolicyResource func MFADevicePolicy(clientInfo *connector.PingOneClientInfo) *PingOneMFADevicePolicyResource { return &PingOneMFADevicePolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneMFADevicePolicyResource) ExportAll() (*[]connector.ImportBlock, l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportDevicePolicies() + importBlocks := []connector.ImportBlock{} + + deviceAuthPolicyData, err := r.getDeviceAuthPolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for devicePolicyId, devicePolicyName := range *deviceAuthPolicyData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "MFA Device Policy ID": devicePolicyId, + "MFA Device Policy Name": devicePolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: devicePolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, devicePolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneMFADevicePolicyResource) exportDevicePolicies() error { +func (r *PingOneMFADevicePolicyResource) getDeviceAuthPolicyData() (*map[string]string, error) { + deviceAuthPolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.MFAAPIClient.DeviceAuthenticationPolicyApi.ReadDeviceAuthenticationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadDeviceAuthenticationPolicies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, devicePolicy := range embedded.GetDeviceAuthenticationPolicies() { @@ -65,28 +85,10 @@ func (r *PingOneMFADevicePolicyResource) exportDevicePolicies() error { devicePolicyName, devicePolicyNameOk := devicePolicy.GetNameOk() if devicePolicyIdOk && devicePolicyNameOk { - r.addImportBlock(*devicePolicyId, *devicePolicyName) + deviceAuthPolicyData[*devicePolicyId] = *devicePolicyName } } } - return nil -} - -func (r *PingOneMFADevicePolicyResource) addImportBlock(devicePolicyId, devicePolicyName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "MFA Device Policy ID": devicePolicyId, - "MFA Device Policy Name": devicePolicyName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: devicePolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, devicePolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &deviceAuthPolicyData, nil } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go b/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go index 747cb744..2b0b47b2 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_fido2_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOneMFAFido2PolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneMFAFido2PolicyResource func MFAFido2Policy(clientInfo *connector.PingOneClientInfo) *PingOneMFAFido2PolicyResource { return &PingOneMFAFido2PolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneMFAFido2PolicyResource) ExportAll() (*[]connector.ImportBlock, e l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportFido2Policies() + importBlocks := []connector.ImportBlock{} + + fido2PolicyData, err := r.getFido2PolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for fido2PolicyId, fido2PolicyName := range *fido2PolicyData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "FIDO2 Policy ID": fido2PolicyId, + "FIDO2 Policy Name": fido2PolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fido2PolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, fido2PolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneMFAFido2PolicyResource) exportFido2Policies() error { +func (r *PingOneMFAFido2PolicyResource) getFido2PolicyData() (*map[string]string, error) { + fido2PolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.MFAAPIClient.FIDO2PolicyApi.ReadFIDO2Policies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadFIDO2Policies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, fido2Policy := range embedded.GetFido2Policies() { @@ -65,28 +85,10 @@ func (r *PingOneMFAFido2PolicyResource) exportFido2Policies() error { fido2PolicyName, fido2PolicyNameOk := fido2Policy.GetNameOk() if fido2PolicyIdOk && fido2PolicyNameOk { - r.addImportBlock(*fido2PolicyId, *fido2PolicyName) + fido2PolicyData[*fido2PolicyId] = *fido2PolicyName } } } - return nil -} - -func (r *PingOneMFAFido2PolicyResource) addImportBlock(fido2PolicyId, fido2PolicyName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "FIDO2 Policy ID": fido2PolicyId, - "FIDO2 Policy Name": fido2PolicyName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fido2PolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, fido2PolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &fido2PolicyData, nil } diff --git a/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go b/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go index e372873d..7218c35d 100644 --- a/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go +++ b/internal/connector/pingone/mfa/resources/pingone_mfa_settings.go @@ -12,15 +12,13 @@ var ( ) type PingOneMFASettingsResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneMFASettingsResource func MFASettings(clientInfo *connector.PingOneClientInfo) *PingOneMFASettingsResource { return &PingOneMFASettingsResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,15 +30,31 @@ func (r *PingOneMFASettingsResource) ExportAll() (*[]connector.ImportBlock, erro l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportMFASettings() + importBlocks := []connector.ImportBlock{} + + err := r.checkMFASettingsData() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: r.ResourceType(), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOneMFASettingsResource) exportMFASettings() error { +func (r *PingOneMFASettingsResource) checkMFASettingsData() error { _, response, err := r.clientInfo.ApiClient.MFAAPIClient.MFASettingsApi.ReadMFASettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "ReadMFASettings", r.ResourceType()) if err != nil { @@ -51,23 +65,5 @@ func (r *PingOneMFASettingsResource) exportMFASettings() error { return common.DataNilError(r.ResourceType(), response) } - r.addImportBlock() - return nil } - -func (r *PingOneMFASettingsResource) addImportBlock() { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: r.ResourceType(), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) -} diff --git a/internal/connector/pingone/platform/pingone_platform_connector_test.go b/internal/connector/pingone/platform/pingone_platform_connector_test.go index cba53a05..d206beb0 100644 --- a/internal/connector/pingone/platform/pingone_platform_connector_test.go +++ b/internal/connector/pingone/platform/pingone_platform_connector_test.go @@ -150,11 +150,12 @@ func TestPlatformTerraformPlan(t *testing.T) { "Error: Missing Configuration for Required Attribute", }, }, - { - name: "NotificationTemplateContent", - resource: resources.NotificationTemplateContent(PingOneClientInfo), - ignoredErrors: nil, - }, + // TODO remove this skip dependent upon STAGING-25369 + // { + // name: "NotificationTemplateContent", + // resource: resources.NotificationTemplateContent(PingOneClientInfo), + // ignoredErrors: nil, + // }, { name: "PhoneDeliverySettings", resource: resources.PhoneDeliverySettings(PingOneClientInfo), diff --git a/internal/connector/pingone/platform/resources/pingone_agreement.go b/internal/connector/pingone/platform/resources/pingone_agreement.go index 86f76c53..bee948ef 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement.go @@ -14,15 +14,13 @@ var ( ) type PingOneAgreementResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneAgreementResource func Agreement(clientInfo *connector.PingOneClientInfo) *PingOneAgreementResource { return &PingOneAgreementResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneAgreementResource) ExportAll() (*[]connector.ImportBlock, error) l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportAgreements() + importBlocks := []connector.ImportBlock{} + + agreementData, err := r.getAgreementData() if err != nil { return nil, err } - return r.importBlocks, nil + for agreementId, agreementName := range *agreementData { + commentData := map[string]string{ + "Agreement ID": agreementId, + "Agreement Name": agreementName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: agreementName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, agreementId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneAgreementResource) exportAgreements() error { +func (r *PingOneAgreementResource) getAgreementData() (*map[string]string, error) { + agreementData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreements", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, agreement := range embedded.GetAgreements() { @@ -65,28 +85,10 @@ func (r *PingOneAgreementResource) exportAgreements() error { agreementName, agreementNameOk := agreement.GetNameOk() if agreementIdOk && agreementNameOk { - r.addImportBlock(*agreementId, *agreementName) + agreementData[*agreementId] = *agreementName } } } - return nil -} - -func (r *PingOneAgreementResource) addImportBlock(agreementId, agreementName string) { - commentData := map[string]string{ - "Agreement ID": agreementId, - "Agreement Name": agreementName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: agreementName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, agreementId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &agreementData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_enable.go b/internal/connector/pingone/platform/resources/pingone_agreement_enable.go index 880e1263..4e84bb93 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_enable.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_enable.go @@ -13,15 +13,13 @@ var ( ) type PingOneAgreementEnableResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneAgreementEnableResource func AgreementEnable(clientInfo *connector.PingOneClientInfo) *PingOneAgreementEnableResource { return &PingOneAgreementEnableResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -33,18 +31,11 @@ func (r *PingOneAgreementEnableResource) ExportAll() (*[]connector.ImportBlock, l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportAgreementEnables() - if err != nil { - return nil, err - } + importBlocks := []connector.ImportBlock{} - return r.importBlocks, nil -} - -func (r *PingOneAgreementEnableResource) exportAgreementEnables() error { agreementImportBlocks, err := Agreement(r.clientInfo).ExportAll() if err != nil { - return err + return nil, err } for _, importBlock := range *agreementImportBlocks { @@ -55,8 +46,8 @@ func (r *PingOneAgreementEnableResource) exportAgreementEnables() error { CommentInformation: importBlock.CommentInformation, } - *r.importBlocks = append(*r.importBlocks, importBlock) + importBlocks = append(importBlocks, importBlock) } - return nil + return &importBlocks, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization.go index 2429116b..7c5ae9f7 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization.go @@ -14,15 +14,13 @@ var ( ) type PingOneAgreementLocalizationResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneAgreementLocalizationResource func AgreementLocalization(clientInfo *connector.PingOneClientInfo) *PingOneAgreementLocalizationResource { return &PingOneAgreementLocalizationResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,60 @@ func (r *PingOneAgreementLocalizationResource) ExportAll() (*[]connector.ImportB l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportAgreementLocalizations() + importBlocks := []connector.ImportBlock{} + + agreementData, err := r.getAgreementData() if err != nil { return nil, err } - return r.importBlocks, nil + for agreementId, agreementName := range *agreementData { + agreementLanguageData, err := r.getAgreementLanguageData(agreementId) + if err != nil { + return nil, err + } + + for agreementLanguageId, agreementLanguageLocale := range *agreementLanguageData { + commentData := map[string]string{ + "Agreement ID": agreementId, + "Agreement Language ID": agreementLanguageId, + "Agreement Language Locale": agreementLanguageLocale, + "Agreement Name": agreementName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", agreementName, agreementLanguageLocale), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizations() error { +func (r *PingOneAgreementLocalizationResource) getAgreementData() (*map[string]string, error) { + agreementData := make(map[string]string) iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreements", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, agreement := range embedded.GetAgreements() { @@ -65,33 +93,32 @@ func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizations() er agreementName, agreementNameOk := agreement.GetNameOk() if agreementIdOk && agreementNameOk { - err := r.exportAgreementLocalizationsByAgreement(*agreementId, *agreementName) - if err != nil { - return err - } + agreementData[*agreementId] = *agreementName } } } - return nil + return &agreementData, nil } -func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizationsByAgreement(agreementId, agreementName string) error { +func (r *PingOneAgreementLocalizationResource) getAgreementLanguageData(agreementId string) (*map[string]string, error) { + agreementLanguageData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementLanguagesResourcesApi.ReadAllAgreementLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, agreementId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreementLanguages", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, languageInner := range embedded.GetLanguages() { @@ -100,31 +127,11 @@ func (r *PingOneAgreementLocalizationResource) exportAgreementLocalizationsByAgr agreementLanguageLocale, agreementLanguageLocaleOk := languageInner.AgreementLanguage.GetLocaleOk() if agreementLanguageIdOk && agreementLanguageLocaleOk { - r.addImportBlock(agreementId, agreementName, *agreementLanguageId, *agreementLanguageLocale) + agreementLanguageData[*agreementLanguageId] = *agreementLanguageLocale } } } } - return nil -} - -func (r *PingOneAgreementLocalizationResource) addImportBlock(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale string) { - commentData := map[string]string{ - "Agreement ID": agreementId, - "Agreement Language ID": agreementLanguageId, - "Agreement Language Locale": agreementLanguageLocale, - "Agreement Name": agreementName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", agreementName, agreementLanguageLocale), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &agreementLanguageData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go index 04501064..e99eb197 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization_enable.go @@ -13,15 +13,13 @@ var ( ) type PingOneAgreementLocalizationEnableResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneAgreementLocalizationEnableResource func AgreementLocalizationEnable(clientInfo *connector.PingOneClientInfo) *PingOneAgreementLocalizationEnableResource { return &PingOneAgreementLocalizationEnableResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -33,18 +31,11 @@ func (r *PingOneAgreementLocalizationEnableResource) ExportAll() (*[]connector.I l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportAgreementLocalizationEnables() - if err != nil { - return nil, err - } + importBlocks := []connector.ImportBlock{} - return r.importBlocks, nil -} - -func (r *PingOneAgreementLocalizationEnableResource) exportAgreementLocalizationEnables() error { agreementLocalizationImportBlocks, err := AgreementLocalization(r.clientInfo).ExportAll() if err != nil { - return err + return nil, err } for _, importBlock := range *agreementLocalizationImportBlocks { @@ -55,8 +46,8 @@ func (r *PingOneAgreementLocalizationEnableResource) exportAgreementLocalization CommentInformation: importBlock.CommentInformation, } - *r.importBlocks = append(*r.importBlocks, importBlock) + importBlocks = append(importBlocks, importBlock) } - return nil + return &importBlocks, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go b/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go index 8e1fd7a6..b16e83f3 100644 --- a/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go +++ b/internal/connector/pingone/platform/resources/pingone_agreement_localization_revision.go @@ -14,15 +14,13 @@ var ( ) type PingOneAgreementLocalizationRevisionResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneAgreementLocalizationRevisionResource func AgreementLocalizationRevision(clientInfo *connector.PingOneClientInfo) *PingOneAgreementLocalizationRevisionResource { return &PingOneAgreementLocalizationRevisionResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,69 @@ func (r *PingOneAgreementLocalizationRevisionResource) ExportAll() (*[]connector l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportAgreementLocalizationRevisions() + importBlocks := []connector.ImportBlock{} + + agreementData, err := r.getAgreementData() if err != nil { return nil, err } - return r.importBlocks, nil + for agreementId, agreementName := range *agreementData { + agreementLanguageData, err := r.getAgreementLanguageData(agreementId) + if err != nil { + return nil, err + } + + for agreementLanguageId, agreementLanguageLocale := range *agreementLanguageData { + agreementLanguageRevisionData, err := r.getAgreementLanguageRevisionData(agreementId, agreementLanguageId) + if err != nil { + return nil, err + } + + for _, agreementLanguageRevisionId := range *agreementLanguageRevisionData { + commentData := map[string]string{ + "Agreement ID": agreementId, + "Agreement Language ID": agreementLanguageId, + "Agreement Language Locale": agreementLanguageLocale, + "Agreement Localization Revision ID": agreementLanguageRevisionId, + "Agreement Name": agreementName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", agreementName, agreementLanguageLocale, agreementLanguageRevisionId), + ResourceID: fmt.Sprintf("%s/%s/%s/%s", r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId, agreementLanguageRevisionId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + } + + return &importBlocks, nil } -func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizationRevisions() error { +func (r *PingOneAgreementLocalizationRevisionResource) getAgreementData() (*map[string]string, error) { + agreementData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementsResourcesApi.ReadAllAgreements(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreements", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, agreement := range embedded.GetAgreements() { @@ -65,33 +102,32 @@ func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizati agreementName, agreementNameOk := agreement.GetNameOk() if agreementIdOk && agreementNameOk { - err := r.exportAgreementLocalizationRevisionsByAgreement(*agreementId, *agreementName) - if err != nil { - return err - } + agreementData[*agreementId] = *agreementName } } } - return nil + return &agreementData, nil } -func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizationRevisionsByAgreement(agreementId, agreementName string) error { +func (r *PingOneAgreementLocalizationRevisionResource) getAgreementLanguageData(agreementId string) (*map[string]string, error) { + agreementLanguageData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementLanguagesResourcesApi.ReadAllAgreementLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, agreementId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreementLanguages", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, languageInner := range embedded.GetLanguages() { @@ -100,65 +136,43 @@ func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizati agreementLanguageId, agreementLanguageIdOk := languageInner.AgreementLanguage.GetIdOk() if agreementLanguageLocaleOk && agreementLanguageIdOk { - err := r.exportAgreementLocalizationRevisionsByAgreementLanguage(agreementId, agreementName, *agreementLanguageId, *agreementLanguageLocale) - if err != nil { - return err - } + agreementLanguageData[*agreementLanguageId] = *agreementLanguageLocale } } } } - return nil + return &agreementLanguageData, nil } -func (r *PingOneAgreementLocalizationRevisionResource) exportAgreementLocalizationRevisionsByAgreementLanguage(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale string) error { +func (r *PingOneAgreementLocalizationRevisionResource) getAgreementLanguageRevisionData(agreementId, agreementLanguageId string) (*[]string, error) { + agreementLanguageRevisionData := []string{} + iter := r.clientInfo.ApiClient.ManagementAPIClient.AgreementRevisionsResourcesApi.ReadAllAgreementLanguageRevisions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllAgreementLanguageRevisions", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, revision := range embedded.GetRevisions() { agreementLanguageRevisionId, agreementLanguageRevisionIdOk := revision.GetIdOk() if agreementLanguageRevisionIdOk { - r.addImportBlock(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale, *agreementLanguageRevisionId) + agreementLanguageRevisionData = append(agreementLanguageRevisionData, *agreementLanguageRevisionId) } } } - return nil -} - -func (r *PingOneAgreementLocalizationRevisionResource) addImportBlock(agreementId, agreementName, agreementLanguageId, agreementLanguageLocale, agreementLanguageRevisionId string) { - commentData := map[string]string{ - "Agreement ID": agreementId, - "Agreement Language ID": agreementLanguageId, - "Agreement Language Locale": agreementLanguageLocale, - "Agreement Localization Revision ID": agreementLanguageRevisionId, - "Agreement Name": agreementName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s", agreementName, agreementLanguageLocale, agreementLanguageRevisionId), - ResourceID: fmt.Sprintf("%s/%s/%s/%s", r.clientInfo.ExportEnvironmentID, agreementId, agreementLanguageId, agreementLanguageRevisionId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &agreementLanguageRevisionData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_settings.go b/internal/connector/pingone/platform/resources/pingone_branding_settings.go index 62c5bc62..9ae6e031 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_settings.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_settings.go @@ -12,15 +12,13 @@ var ( ) type PingOneBrandingSettingsResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneBrandingSettingsResource func BrandingSettings(clientInfo *connector.PingOneClientInfo) *PingOneBrandingSettingsResource { return &PingOneBrandingSettingsResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,15 +30,31 @@ func (r *PingOneBrandingSettingsResource) ExportAll() (*[]connector.ImportBlock, l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportBrandingSettings() + importBlocks := []connector.ImportBlock{} + + err := r.checkBrandingSettingsData() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Resource Type": r.ResourceType(), + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: r.ResourceType(), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOneBrandingSettingsResource) exportBrandingSettings() error { +func (r *PingOneBrandingSettingsResource) checkBrandingSettingsData() error { _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.BrandingSettingsApi.ReadBrandingSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "ReadBrandingSettings", r.ResourceType()) if err != nil { @@ -51,23 +65,5 @@ func (r *PingOneBrandingSettingsResource) exportBrandingSettings() error { return common.DataNilError(r.ResourceType(), response) } - r.addImportBlock() - return nil } - -func (r *PingOneBrandingSettingsResource) addImportBlock() { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: r.ResourceType(), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) -} diff --git a/internal/connector/pingone/platform/resources/pingone_branding_theme.go b/internal/connector/pingone/platform/resources/pingone_branding_theme.go index b366dca1..4d3d7e04 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_theme.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_theme.go @@ -14,15 +14,13 @@ var ( ) type PingOneBrandingThemeResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneBrandingThemeResource func BrandingTheme(clientInfo *connector.PingOneClientInfo) *PingOneBrandingThemeResource { return &PingOneBrandingThemeResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneBrandingThemeResource) ExportAll() (*[]connector.ImportBlock, er l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportBrandingThemes() + importBlocks := []connector.ImportBlock{} + + brandingThemeData, err := r.getBrandingThemeData() if err != nil { return nil, err } - return r.importBlocks, nil + for brandingThemeId, brandingThemeName := range *brandingThemeData { + commentData := map[string]string{ + "Branding Theme ID": brandingThemeId, + "Branding Theme Name": brandingThemeName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: brandingThemeName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, brandingThemeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneBrandingThemeResource) exportBrandingThemes() error { +func (r *PingOneBrandingThemeResource) getBrandingThemeData() (*map[string]string, error) { + brandingThemeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.BrandingThemesApi.ReadBrandingThemes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadBrandingThemes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, brandingTheme := range embedded.GetThemes() { @@ -68,29 +88,11 @@ func (r *PingOneBrandingThemeResource) exportBrandingThemes() error { brandingThemeName, brandingThemeNameOk := brandingThemeConfiguration.GetNameOk() if brandingThemeNameOk { - r.addImportBlock(*brandingThemeId, *brandingThemeName) + brandingThemeData[*brandingThemeId] = *brandingThemeName } } } } - return nil -} - -func (r *PingOneBrandingThemeResource) addImportBlock(brandingThemeId, brandingThemeName string) { - commentData := map[string]string{ - "Branding Theme ID": brandingThemeId, - "Branding Theme Name": brandingThemeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: brandingThemeName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, brandingThemeId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &brandingThemeData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go b/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go index 45fc2483..3264c912 100644 --- a/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go +++ b/internal/connector/pingone/platform/resources/pingone_branding_theme_default.go @@ -14,15 +14,13 @@ var ( ) type PingOneBrandingThemeDefaultResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneBrandingThemeDefaultResource func BrandingThemeDefault(clientInfo *connector.PingOneClientInfo) *PingOneBrandingThemeDefaultResource { return &PingOneBrandingThemeDefaultResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,47 @@ func (r *PingOneBrandingThemeDefaultResource) ExportAll() (*[]connector.ImportBl l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportBrandingThemeDefault() + importBlocks := []connector.ImportBlock{} + + defaultBrandingThemeName, err := r.getDefaultBrandingThemeName() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Default Branding Theme Name": *defaultBrandingThemeName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_default_theme", *defaultBrandingThemeName), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOneBrandingThemeDefaultResource) exportBrandingThemeDefault() error { +func (r *PingOneBrandingThemeDefaultResource) getDefaultBrandingThemeName() (*string, error) { iter := r.clientInfo.ApiClient.ManagementAPIClient.BrandingThemesApi.ReadBrandingThemes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadBrandingThemes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, brandingTheme := range embedded.GetThemes() { @@ -70,29 +85,12 @@ func (r *PingOneBrandingThemeDefaultResource) exportBrandingThemeDefault() error brandingThemeName, brandingThemeNameOk := brandingThemeConfiguration.GetNameOk() if brandingThemeNameOk { - r.addImportBlock(*brandingThemeName) + return brandingThemeName, nil } } } } } - return nil -} - -func (r *PingOneBrandingThemeDefaultResource) addImportBlock(brandingThemeName string) { - commentData := map[string]string{ - "Default Branding Theme Name": brandingThemeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_default_theme", brandingThemeName), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("failed to export resource '%s'. No default branding theme found.", r.ResourceType()) } diff --git a/internal/connector/pingone/platform/resources/pingone_certificate.go b/internal/connector/pingone/platform/resources/pingone_certificate.go index c6046910..b86499ff 100644 --- a/internal/connector/pingone/platform/resources/pingone_certificate.go +++ b/internal/connector/pingone/platform/resources/pingone_certificate.go @@ -14,15 +14,13 @@ var ( ) type PingOneCertificateResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneCertificateResource func Certificate(clientInfo *connector.PingOneClientInfo) *PingOneCertificateResource { return &PingOneCertificateResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,29 +32,51 @@ func (r *PingOneCertificateResource) ExportAll() (*[]connector.ImportBlock, erro l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportCertificates() + importBlocks := []connector.ImportBlock{} + + certificateData, err := r.getCertificateData() if err != nil { return nil, err } - return r.importBlocks, nil + for certificateId, certificateName := range *certificateData { + commentData := map[string]string{ + "Certificate ID": certificateId, + "Certificate Name": certificateName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: certificateName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, certificateId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneCertificateResource) exportCertificates() error { +func (r *PingOneCertificateResource) getCertificateData() (*map[string]string, error) { + certificateData := make(map[string]string) + // TODO: Implement pagination once supported in the PingOne Go Client SDK entityArray, response, err := r.clientInfo.ApiClient.ManagementAPIClient.CertificateManagementApi.GetCertificates(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "GetCertificates", r.ResourceType()) if err != nil { - return err + return nil, err } if entityArray == nil { - return common.DataNilError(r.ResourceType(), response) + return nil, common.DataNilError(r.ResourceType(), response) } embedded, embeddedOk := entityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), response) + return nil, common.DataNilError(r.ResourceType(), response) } for _, certificate := range embedded.GetCertificates() { @@ -64,27 +84,9 @@ func (r *PingOneCertificateResource) exportCertificates() error { certificateName, certificateNameOk := certificate.GetNameOk() if certificateIdOk && certificateNameOk { - r.addImportBlock(*certificateId, *certificateName) + certificateData[*certificateId] = *certificateName } } - return nil -} - -func (r *PingOneCertificateResource) addImportBlock(certificateId string, certificateName string) { - commentData := map[string]string{ - "Certificate ID": certificateId, - "Certificate Name": certificateName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: certificateName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, certificateId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &certificateData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_custom_domain.go b/internal/connector/pingone/platform/resources/pingone_custom_domain.go index a62d9e6f..871ddce0 100644 --- a/internal/connector/pingone/platform/resources/pingone_custom_domain.go +++ b/internal/connector/pingone/platform/resources/pingone_custom_domain.go @@ -14,15 +14,13 @@ var ( ) type PingOneCustomDomainResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneCustomDomainResource func CustomDomain(clientInfo *connector.PingOneClientInfo) *PingOneCustomDomainResource { return &PingOneCustomDomainResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneCustomDomainResource) ExportAll() (*[]connector.ImportBlock, err l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportCustomDomains() + importBlocks := []connector.ImportBlock{} + + domainData, err := r.getCustomDomainData() if err != nil { return nil, err } - return r.importBlocks, nil + for domainId, domainName := range *domainData { + commentData := map[string]string{ + "Custom Domain ID": domainId, + "Custom Domain Name": domainName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: domainName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, domainId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneCustomDomainResource) exportCustomDomains() error { +func (r *PingOneCustomDomainResource) getCustomDomainData() (*map[string]string, error) { + domainData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.CustomDomainsApi.ReadAllDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllDomains", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, customDomain := range embedded.GetCustomDomains() { @@ -65,28 +85,10 @@ func (r *PingOneCustomDomainResource) exportCustomDomains() error { customDomainId, customDomainIdOk := customDomain.GetIdOk() if customDomainIdOk && customDomainNameOk { - r.addImportBlock(*customDomainId, *customDomainName) + domainData[*customDomainId] = *customDomainName } } } - return nil -} - -func (r *PingOneCustomDomainResource) addImportBlock(customDomainId, customDomainName string) { - commentData := map[string]string{ - "Custom Domain ID": customDomainId, - "Custom Domain Name": customDomainName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: customDomainName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, customDomainId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &domainData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_environment.go b/internal/connector/pingone/platform/resources/pingone_environment.go index 8ea68b80..f1520170 100644 --- a/internal/connector/pingone/platform/resources/pingone_environment.go +++ b/internal/connector/pingone/platform/resources/pingone_environment.go @@ -12,15 +12,13 @@ var ( ) type PingOneEnvironmentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneEnvironmentResource func Environment(clientInfo *connector.PingOneClientInfo) *PingOneEnvironmentResource { return &PingOneEnvironmentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,28 +30,13 @@ func (r *PingOneEnvironmentResource) ExportAll() (*[]connector.ImportBlock, erro l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportEnvironments() - if err != nil { - return nil, err - } - - return r.importBlocks, nil -} - -func (r *PingOneEnvironmentResource) exportEnvironments() error { - _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.EnvironmentsApi.ReadOneEnvironment(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + importBlocks := []connector.ImportBlock{} - err = common.HandleClientResponse(response, err, "ReadOneEnvironment", r.ResourceType()) + err := r.checkEnvironmentData() if err != nil { - return err + return nil, err } - r.addImportBlock() - - return nil -} - -func (r *PingOneEnvironmentResource) addImportBlock() { commentData := map[string]string{ "Resource Type": r.ResourceType(), "Export Environment ID": r.clientInfo.ExportEnvironmentID, @@ -66,5 +49,18 @@ func (r *PingOneEnvironmentResource) addImportBlock() { CommentInformation: common.GenerateCommentInformation(commentData), } - *r.importBlocks = append(*r.importBlocks, importBlock) + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil +} + +func (r *PingOneEnvironmentResource) checkEnvironmentData() error { + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.EnvironmentsApi.ReadOneEnvironment(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + err = common.HandleClientResponse(response, err, "ReadOneEnvironment", r.ResourceType()) + if err != nil { + return err + } + + return nil } diff --git a/internal/connector/pingone/platform/resources/pingone_form.go b/internal/connector/pingone/platform/resources/pingone_form.go index 46ea34e2..7ac724b1 100644 --- a/internal/connector/pingone/platform/resources/pingone_form.go +++ b/internal/connector/pingone/platform/resources/pingone_form.go @@ -14,15 +14,13 @@ var ( ) type PingOneFormResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneFormResource func Form(clientInfo *connector.PingOneClientInfo) *PingOneFormResource { return &PingOneFormResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneFormResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportForms() + importBlocks := []connector.ImportBlock{} + + formData, err := r.getFormData() if err != nil { return nil, err } - return r.importBlocks, nil + for formId, formName := range *formData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Form ID": formId, + "Form Name": formName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: formName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, formId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneFormResource) exportForms() error { +func (r *PingOneFormResource) getFormData() (*map[string]string, error) { + formData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.FormManagementApi.ReadAllForms(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllForms", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, form := range embedded.GetForms() { @@ -65,28 +85,10 @@ func (r *PingOneFormResource) exportForms() error { formName, formNameOk := form.GetNameOk() if formIdOk && formNameOk { - r.addImportBlock(*formId, *formName) + formData[*formId] = *formName } } } - return nil -} - -func (r *PingOneFormResource) addImportBlock(formId, formName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Form ID": formId, - "Form Name": formName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: formName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, formId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &formData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go b/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go index 9a94bc10..3b2a15f1 100644 --- a/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go +++ b/internal/connector/pingone/platform/resources/pingone_forms_recaptcha_v2.go @@ -12,15 +12,13 @@ var ( ) type PingOneFormRecaptchaV2Resource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneFormRecaptchaV2Resource func FormRecaptchaV2(clientInfo *connector.PingOneClientInfo) *PingOneFormRecaptchaV2Resource { return &PingOneFormRecaptchaV2Resource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,15 +30,31 @@ func (r *PingOneFormRecaptchaV2Resource) ExportAll() (*[]connector.ImportBlock, l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportFormRecaptchaV2() + importBlocks := []connector.ImportBlock{} + + err := r.checkFormRecaptchaV2Data() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: r.ResourceType(), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOneFormRecaptchaV2Resource) exportFormRecaptchaV2() error { +func (r *PingOneFormRecaptchaV2Resource) checkFormRecaptchaV2Data() error { _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.RecaptchaConfigurationApi.ReadRecaptchaConfiguration(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "ReadRecaptchaConfiguration", r.ResourceType()) if err != nil { @@ -51,23 +65,5 @@ func (r *PingOneFormRecaptchaV2Resource) exportFormRecaptchaV2() error { return common.DataNilError(r.ResourceType(), response) } - r.addImportBlock() - return nil } - -func (r *PingOneFormRecaptchaV2Resource) addImportBlock() { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: r.ResourceType(), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) -} diff --git a/internal/connector/pingone/platform/resources/pingone_gateway.go b/internal/connector/pingone/platform/resources/pingone_gateway.go index dce534dc..2eb41423 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway.go @@ -14,15 +14,13 @@ var ( ) type PingOneGatewayResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneGatewayResource func Gateway(clientInfo *connector.PingOneClientInfo) *PingOneGatewayResource { return &PingOneGatewayResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneGatewayResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportGateways() + importBlocks := []connector.ImportBlock{} + + gatewayData, err := r.getGatewayData() if err != nil { return nil, err } - return r.importBlocks, nil + for gatewayId, gatewayName := range *gatewayData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Gateway ID": gatewayId, + "Gateway Name": gatewayName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: gatewayName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneGatewayResource) exportGateways() error { +func (r *PingOneGatewayResource) getGatewayData() (*map[string]string, error) { + gatewayData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGateways", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, gatewayInner := range embedded.GetGateways() { @@ -83,28 +103,10 @@ func (r *PingOneGatewayResource) exportGateways() error { } if gatewayIdOk && gatewayNameOk { - r.addImportBlock(*gatewayId, *gatewayName) + gatewayData[*gatewayId] = *gatewayName } } } - return nil -} - -func (r *PingOneGatewayResource) addImportBlock(gatewayId, gatewayName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Gateway ID": gatewayId, - "Gateway Name": gatewayName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: gatewayName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &gatewayData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_gateway_credential.go b/internal/connector/pingone/platform/resources/pingone_gateway_credential.go index 91d82e46..ca10a779 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway_credential.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway_credential.go @@ -14,15 +14,13 @@ var ( ) type PingOneGatewayCredentialResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneGatewayCredentialResource func GatewayCredential(clientInfo *connector.PingOneClientInfo) *PingOneGatewayCredentialResource { return &PingOneGatewayCredentialResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,60 @@ func (r *PingOneGatewayCredentialResource) ExportAll() (*[]connector.ImportBlock l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportGatewayCredentials() + importBlocks := []connector.ImportBlock{} + + gatewayData, err := r.getGatewayData() if err != nil { return nil, err } - return r.importBlocks, nil + for gatewayId, gatewayName := range *gatewayData { + gatewayCredentialData, err := r.getGatewayCredentialData(gatewayId) + if err != nil { + return nil, err + } + + for _, gatewayCredentialId := range *gatewayCredentialData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Gateway Credential ID": gatewayCredentialId, + "Gateway ID": gatewayId, + "Gateway Name": gatewayName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_credential_%s", gatewayName, gatewayCredentialId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId, gatewayCredentialId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneGatewayCredentialResource) exportGatewayCredentials() error { +func (r *PingOneGatewayCredentialResource) getGatewayData() (*map[string]string, error) { + gatewayData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGateways", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, gatewayInner := range embedded.GetGateways() { @@ -83,62 +111,42 @@ func (r *PingOneGatewayCredentialResource) exportGatewayCredentials() error { } if gatewayIdOk && gatewayNameOk { - err := r.exportGatewayCredentialsByGateway(*gatewayId, *gatewayName) - if err != nil { - return err - } + gatewayData[*gatewayId] = *gatewayName } } } - return nil + return &gatewayData, nil } -func (r *PingOneGatewayCredentialResource) exportGatewayCredentialsByGateway(gatewayId, gatewayName string) error { +func (r *PingOneGatewayCredentialResource) getGatewayCredentialData(gatewayId string) (*[]string, error) { + gatewayCredentialData := []string{} + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewayCredentialsApi.ReadAllGatewayCredentials(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, gatewayId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGatewayCredentials", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, gatewayCredential := range embedded.GetCredentials() { gatewayCredentialId, gatewayCredentialIdOk := gatewayCredential.GetIdOk() if gatewayCredentialIdOk { - r.addImportBlock(gatewayId, gatewayName, *gatewayCredentialId) + gatewayCredentialData = append(gatewayCredentialData, *gatewayCredentialId) } } } - return nil -} - -func (r *PingOneGatewayCredentialResource) addImportBlock(gatewayId, gatewayName, gatewayCredentialId string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Gateway Credential ID": gatewayCredentialId, - "Gateway ID": gatewayId, - "Gateway Name": gatewayName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_credential_%s", gatewayName, gatewayCredentialId), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId, gatewayCredentialId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &gatewayCredentialData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go b/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go index 5b120813..3b8fac4f 100644 --- a/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go +++ b/internal/connector/pingone/platform/resources/pingone_gateway_role_assignment.go @@ -15,15 +15,13 @@ var ( ) type PingOneGatewayRoleAssignmentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneGatewayRoleAssignmentResource func GatewayRoleAssignment(clientInfo *connector.PingOneClientInfo) *PingOneGatewayRoleAssignmentResource { return &PingOneGatewayRoleAssignmentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,66 @@ func (r *PingOneGatewayRoleAssignmentResource) ExportAll() (*[]connector.ImportB l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportGatewayRoleAssignments() + importBlocks := []connector.ImportBlock{} + + gatewayData, err := r.getGatewayData() if err != nil { return nil, err } - return r.importBlocks, nil + for gatewayId, gatewayName := range *gatewayData { + gatewayRoleAssignmentData, err := r.getGatewayRoleAssignmentData(gatewayId) + if err != nil { + return nil, err + } + + for roleAssignmentId, roleId := range *gatewayRoleAssignmentData { + roleName, err := r.getRoleAssignmentRoleName(roleId) + if err != nil { + return nil, err + } + + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Gateway ID": gatewayId, + "Gateway Name": gatewayName, + "Resource Type": r.ResourceType(), + "Role Assignment ID": roleAssignmentId, + "Role Name": string(*roleName), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", gatewayName, string(*roleName), roleAssignmentId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId, roleAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignments() error { +func (r *PingOneGatewayRoleAssignmentResource) getGatewayData() (*map[string]string, error) { + gatewayData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewaysApi.ReadAllGateways(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGateways", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, gatewayInner := range embedded.GetGateways() { @@ -71,35 +105,34 @@ func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignments() er gatewayName, gatewayNameOk := gatewayInner.Gateway.GetNameOk() if gatewayIdOk && gatewayNameOk { - err := r.exportGatewayRoleAssignmentsByGateway(*gatewayId, *gatewayName) - if err != nil { - return err - } + gatewayData[*gatewayId] = *gatewayName } } } } } - return nil + return &gatewayData, nil } -func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignmentsByGateway(gatewayId, gatewayName string) error { +func (r *PingOneGatewayRoleAssignmentResource) getGatewayRoleAssignmentData(gatewayId string) (*map[string]string, error) { + gatewayRoleAssignmentData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GatewayRoleAssignmentsApi.ReadGatewayRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, gatewayId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadGatewayRoleAssignments", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, roleAssignment := range embedded.GetRoleAssignments() { @@ -109,51 +142,28 @@ func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignmentsByGat if roleAssignmentIdOk && roleAssignmentRoleOk { roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk() if roleAssignmentRoleIdOk { - err := r.exportGatewayRoleAssignmentsByRole(gatewayId, gatewayName, *roleAssignmentId, *roleAssignmentRoleId) - if err != nil { - return err - } + gatewayRoleAssignmentData[*roleAssignmentId] = *roleAssignmentRoleId } } } } - return nil + return &gatewayRoleAssignmentData, nil } -func (r *PingOneGatewayRoleAssignmentResource) exportGatewayRoleAssignmentsByRole(gatewayId, gatewayName, roleAssignmentId, roleId string) error { +func (r *PingOneGatewayRoleAssignmentResource) getRoleAssignmentRoleName(roleId string) (*management.EnumRoleName, error) { role, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, roleId).Execute() err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) if err != nil { - return err + return nil, err } if role != nil { roleName, roleNameOk := role.GetNameOk() if roleNameOk { - r.addImportBlock(gatewayId, gatewayName, roleAssignmentId, string(*roleName)) + return roleName, nil } } - return nil -} - -func (r *PingOneGatewayRoleAssignmentResource) addImportBlock(gatewayId, gatewayName, roleAssignmentId, roleName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Gateway ID": gatewayId, - "Gateway Name": gatewayName, - "Resource Type": r.ResourceType(), - "Role Assignment ID": roleAssignmentId, - "Role Name": roleName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s", gatewayName, roleName, roleAssignmentId), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, gatewayId, roleAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("failed to export resource '%s'. No role name found for Role ID '%s'.", r.ResourceType(), roleId) } diff --git a/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go b/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go index f7ec92d6..a711a535 100644 --- a/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go +++ b/internal/connector/pingone/platform/resources/pingone_identity_propagation_plan.go @@ -14,15 +14,13 @@ var ( ) type PingOneIdentityPropagationPlanResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneIdentityPropagationPlanResource func IdentityPropagationPlan(clientInfo *connector.PingOneClientInfo) *PingOneIdentityPropagationPlanResource { return &PingOneIdentityPropagationPlanResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneIdentityPropagationPlanResource) ExportAll() (*[]connector.Impor l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportIdentityPropagationPlans() + importBlocks := []connector.ImportBlock{} + + planData, err := r.getIdentityPropagationPlanData() if err != nil { return nil, err } - return r.importBlocks, nil + for planId, planName := range *planData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Identity Propagation Plan ID": planId, + "Identity Propagation Plan Name": planName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: planName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, planId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneIdentityPropagationPlanResource) exportIdentityPropagationPlans() error { +func (r *PingOneIdentityPropagationPlanResource) getIdentityPropagationPlanData() (*map[string]string, error) { + identityPropagationPlanData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityPropagationPlansApi.ReadAllPlans(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPlans", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, identityPropagationPlan := range embedded.GetPlans() { @@ -65,28 +85,10 @@ func (r *PingOneIdentityPropagationPlanResource) exportIdentityPropagationPlans( identityPropagationPlanName, identityPropagationPlanNameOk := identityPropagationPlan.GetNameOk() if identityPropagationPlanIdOk && identityPropagationPlanNameOk { - r.addImportBlock(*identityPropagationPlanId, *identityPropagationPlanName) + identityPropagationPlanData[*identityPropagationPlanId] = *identityPropagationPlanName } } } - return nil -} - -func (r *PingOneIdentityPropagationPlanResource) addImportBlock(identityPropagationPlanId, identityPropagationPlanName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Identity Propagation Plan ID": identityPropagationPlanId, - "Identity Propagation Plan Name": identityPropagationPlanName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: identityPropagationPlanName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, identityPropagationPlanId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &identityPropagationPlanData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_key.go b/internal/connector/pingone/platform/resources/pingone_key.go index 16762cd0..8bc78252 100644 --- a/internal/connector/pingone/platform/resources/pingone_key.go +++ b/internal/connector/pingone/platform/resources/pingone_key.go @@ -14,15 +14,13 @@ var ( ) type PingOneKeyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneKeyResource func Key(clientInfo *connector.PingOneClientInfo) *PingOneKeyResource { return &PingOneKeyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,56 @@ func (r *PingOneKeyResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportKeys() + importBlocks := []connector.ImportBlock{} + + keyData, err := r.getKeyData() if err != nil { return nil, err } - return r.importBlocks, nil + for keyId, keyNameAndType := range *keyData { + keyName := keyNameAndType[0] + keyType := keyNameAndType[1] + + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Key ID": keyId, + "Key Name": keyName, + "Key Type": keyType, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", keyName, keyType), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, keyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneKeyResource) exportKeys() error { +func (r *PingOneKeyResource) getKeyData() (*map[string][]string, error) { + keyData := make(map[string][]string) + // TODO: Implement pagination once supported in the PingOne Go Client SDK entityArray, response, err := r.clientInfo.ApiClient.ManagementAPIClient.CertificateManagementApi.GetKeys(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "GetKeys", r.ResourceType()) if err != nil { - return err + return nil, err } if entityArray == nil { - return common.DataNilError(r.ResourceType(), response) + return nil, common.DataNilError(r.ResourceType(), response) } embedded, embeddedOk := entityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), response) + return nil, common.DataNilError(r.ResourceType(), response) } for _, key := range embedded.GetKeys() { @@ -66,28 +90,9 @@ func (r *PingOneKeyResource) exportKeys() error { keyUsageType, keyUsageTypeOk := key.GetUsageTypeOk() if keyIdOk && keyNameOk && keyUsageTypeOk { - r.addImportBlock(*keyId, *keyName, string(*keyUsageType)) + keyData[*keyId] = []string{*keyName, string(*keyUsageType)} } } - return nil -} - -func (r *PingOneKeyResource) addImportBlock(keyId, keyName, keyUsageType string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Key ID": keyId, - "Key Name": keyName, - "Key Usage Type": keyUsageType, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", keyName, keyUsageType), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, keyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &keyData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go b/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go index f9a2be46..05272f6e 100644 --- a/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go +++ b/internal/connector/pingone/platform/resources/pingone_key_rotation_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOneKeyRotationPolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneKeyRotationPolicyResource func KeyRotationPolicy(clientInfo *connector.PingOneClientInfo) *PingOneKeyRotationPolicyResource { return &PingOneKeyRotationPolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneKeyRotationPolicyResource) ExportAll() (*[]connector.ImportBlock l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportKeyRotationPolicies() + importBlocks := []connector.ImportBlock{} + + keyRotationPolicyData, err := r.getKeyRotationPolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for keyRotationPolicyId, keyRotationPolicyName := range *keyRotationPolicyData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Key Rotation Policy ID": keyRotationPolicyId, + "Key Rotation Policy Name": keyRotationPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: keyRotationPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, keyRotationPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneKeyRotationPolicyResource) exportKeyRotationPolicies() error { +func (r *PingOneKeyRotationPolicyResource) getKeyRotationPolicyData() (*map[string]string, error) { + keyRotationPolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.KeyRotationPoliciesApi.GetKeyRotationPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "GetKeyRotationPolicies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, keyRotationPolicy := range embedded.GetKeyRotationPolicies() { @@ -65,28 +85,10 @@ func (r *PingOneKeyRotationPolicyResource) exportKeyRotationPolicies() error { keyRotationPolicyName, keyRotationPolicyNameOk := keyRotationPolicy.GetNameOk() if keyRotationPolicyIdOk && keyRotationPolicyNameOk { - r.addImportBlock(*keyRotationPolicyId, *keyRotationPolicyName) + keyRotationPolicyData[*keyRotationPolicyId] = *keyRotationPolicyName } } } - return nil -} - -func (r *PingOneKeyRotationPolicyResource) addImportBlock(keyRotationPolicyId, keyRotationPolicyName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Key Rotation Policy ID": keyRotationPolicyId, - "Key Rotation Policy Name": keyRotationPolicyName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: keyRotationPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, keyRotationPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &keyRotationPolicyData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_language.go b/internal/connector/pingone/platform/resources/pingone_language.go index 5848b122..a15d90b8 100644 --- a/internal/connector/pingone/platform/resources/pingone_language.go +++ b/internal/connector/pingone/platform/resources/pingone_language.go @@ -14,15 +14,13 @@ var ( ) type PingOneLanguageResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneLanguageResource func Language(clientInfo *connector.PingOneClientInfo) *PingOneLanguageResource { return &PingOneLanguageResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneLanguageResource) ExportAll() (*[]connector.ImportBlock, error) l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportLanguages() + importBlocks := []connector.ImportBlock{} + + languageData, err := r.getLanguageData() if err != nil { return nil, err } - return r.importBlocks, nil + for languageId, languageName := range *languageData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Language ID": languageId, + "Language Name": languageName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: languageName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, languageId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneLanguageResource) exportLanguages() error { +func (r *PingOneLanguageResource) getLanguageData() (*map[string]string, error) { + languageData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadLanguages", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, languageInner := range embedded.GetLanguages() { @@ -72,29 +92,11 @@ func (r *PingOneLanguageResource) exportLanguages() error { languageName, languageNameOk := languageInner.Language.GetNameOk() if languageIdOk && languageNameOk { - r.addImportBlock(*languageId, *languageName) + languageData[*languageId] = *languageName } } } } - return nil -} - -func (r *PingOneLanguageResource) addImportBlock(languageId, languageName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Language ID": languageId, - "Language Name": languageName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: languageName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, languageId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &languageData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_language_update.go b/internal/connector/pingone/platform/resources/pingone_language_update.go index 9c2db127..fac44ead 100644 --- a/internal/connector/pingone/platform/resources/pingone_language_update.go +++ b/internal/connector/pingone/platform/resources/pingone_language_update.go @@ -14,15 +14,13 @@ var ( ) type PingOneLanguageUpdateResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneLanguageUpdateResource func LanguageUpdate(clientInfo *connector.PingOneClientInfo) *PingOneLanguageUpdateResource { return &PingOneLanguageUpdateResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneLanguageUpdateResource) ExportAll() (*[]connector.ImportBlock, e l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportLanguageUpdates() + importBlocks := []connector.ImportBlock{} + + languageData, err := r.getLanguageData() if err != nil { return nil, err } - return r.importBlocks, nil + for languageId, languageName := range *languageData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Language ID": languageId, + "Language Name": languageName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_update", languageName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, languageId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneLanguageUpdateResource) exportLanguageUpdates() error { +func (r *PingOneLanguageUpdateResource) getLanguageData() (*map[string]string, error) { + languageData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadLanguages", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, languageInner := range embedded.GetLanguages() { @@ -77,7 +97,7 @@ func (r *PingOneLanguageUpdateResource) exportLanguageUpdates() error { languageName, languageNameOk := languageInner.Language.GetNameOk() if languageIdOk && languageNameOk { - r.addImportBlock(*languageId, *languageName) + languageData[*languageId] = *languageName } } } @@ -85,23 +105,5 @@ func (r *PingOneLanguageUpdateResource) exportLanguageUpdates() error { } } - return nil -} - -func (r *PingOneLanguageUpdateResource) addImportBlock(languageId, languageName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Language ID": languageId, - "Language Name": languageName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_update", languageName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, languageId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &languageData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_policy.go b/internal/connector/pingone/platform/resources/pingone_notification_policy.go index 30e73723..08bdb071 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_policy.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOneNotificationPolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneNotificationPolicyResource func NotificationPolicy(clientInfo *connector.PingOneClientInfo) *PingOneNotificationPolicyResource { return &PingOneNotificationPolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneNotificationPolicyResource) ExportAll() (*[]connector.ImportBloc l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportNotificationPolicies() + importBlocks := []connector.ImportBlock{} + + notificationPolicyData, err := r.getNotificationPolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for notificationPolicyId, notificationPolicyName := range *notificationPolicyData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Notification Policy ID": notificationPolicyId, + "Notification Policy Name": notificationPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: notificationPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, notificationPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneNotificationPolicyResource) exportNotificationPolicies() error { +func (r *PingOneNotificationPolicyResource) getNotificationPolicyData() (*map[string]string, error) { + notificationPolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsPoliciesApi.ReadAllNotificationsPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllNotificationsPolicies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, notificationPolicy := range embedded.GetNotificationsPolicies() { @@ -65,28 +85,10 @@ func (r *PingOneNotificationPolicyResource) exportNotificationPolicies() error { notificationPolicyName, notificationPolicyNameOk := notificationPolicy.GetNameOk() if notificationPolicyIdOk && notificationPolicyNameOk { - r.addImportBlock(*notificationPolicyId, *notificationPolicyName) + notificationPolicyData[*notificationPolicyId] = *notificationPolicyName } } } - return nil -} - -func (r *PingOneNotificationPolicyResource) addImportBlock(notificationPolicyId, notificationPolicyName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Notification Policy ID": notificationPolicyId, - "Notification Policy Name": notificationPolicyName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: notificationPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, notificationPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return ¬ificationPolicyData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_settings.go b/internal/connector/pingone/platform/resources/pingone_notification_settings.go index 3fbfc07d..001b8885 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_settings.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_settings.go @@ -12,15 +12,13 @@ var ( ) type PingOneNotificationSettingsResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneNotificationSettingsResource func NotificationSettings(clientInfo *connector.PingOneClientInfo) *PingOneNotificationSettingsResource { return &PingOneNotificationSettingsResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,15 +30,31 @@ func (r *PingOneNotificationSettingsResource) ExportAll() (*[]connector.ImportBl l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportNotificationSettings() + importBlocks := []connector.ImportBlock{} + + err := r.checkNotificationSettingsData() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: r.ResourceType(), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOneNotificationSettingsResource) exportNotificationSettings() error { +func (r *PingOneNotificationSettingsResource) checkNotificationSettingsData() error { _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsSettingsApi.ReadNotificationsSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "ReadNotificationsSettings", r.ResourceType()) if err != nil { @@ -51,23 +65,5 @@ func (r *PingOneNotificationSettingsResource) exportNotificationSettings() error return common.DataNilError(r.ResourceType(), response) } - r.addImportBlock() - return nil } - -func (r *PingOneNotificationSettingsResource) addImportBlock() { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: r.ResourceType(), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) -} diff --git a/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go b/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go index adfdf86e..f1c36b70 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_settings_email.go @@ -12,15 +12,13 @@ var ( ) type PingOneNotificationSettingsEmailResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneNotificationSettingsEmailResource func NotificationSettingsEmail(clientInfo *connector.PingOneClientInfo) *PingOneNotificationSettingsEmailResource { return &PingOneNotificationSettingsEmailResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,15 +30,31 @@ func (r *PingOneNotificationSettingsEmailResource) ExportAll() (*[]connector.Imp l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportNotificationSettingsEmails() + importBlocks := []connector.ImportBlock{} + + err := r.checkNotificationSettingsEmailData() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: r.ResourceType(), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOneNotificationSettingsEmailResource) exportNotificationSettingsEmails() error { +func (r *PingOneNotificationSettingsEmailResource) checkNotificationSettingsEmailData() error { _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsSettingsSMTPApi.ReadEmailNotificationsSettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() err = common.HandleClientResponse(response, err, "ReadEmailNotificationsSettings", r.ResourceType()) if err != nil { @@ -51,23 +65,5 @@ func (r *PingOneNotificationSettingsEmailResource) exportNotificationSettingsEma return common.DataNilError(r.ResourceType(), response) } - r.addImportBlock() - return nil } - -func (r *PingOneNotificationSettingsEmailResource) addImportBlock() { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: r.ResourceType(), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) -} diff --git a/internal/connector/pingone/platform/resources/pingone_notification_template_content.go b/internal/connector/pingone/platform/resources/pingone_notification_template_content.go index 12324f5e..6ab702b7 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_template_content.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_template_content.go @@ -2,6 +2,8 @@ package resources import ( "fmt" + "io" + "strings" "github.com/patrickcping/pingone-go-sdk-v2/management" "github.com/pingidentity/pingcli/internal/connector" @@ -9,21 +11,26 @@ import ( "github.com/pingidentity/pingcli/internal/logger" ) +type NotificationTemplateContentData struct { + TemplateContentId string + TemplateContentDeliveryMethod string + TemplateContentLocale string + TemplateContentVariant string +} + // Verify that the resource satisfies the exportable resource interface var ( _ connector.ExportableResource = &PingOneNotificationTemplateContentResource{} ) type PingOneNotificationTemplateContentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneNotificationTemplateContentResource func NotificationTemplateContent(clientInfo *connector.PingOneClientInfo) *PingOneNotificationTemplateContentResource { return &PingOneNotificationTemplateContentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,41 +42,151 @@ func (r *PingOneNotificationTemplateContentResource) ExportAll() (*[]connector.I l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportNotificationTemplateContents() + importBlocks := []connector.ImportBlock{} + + enabledLocales, err := r.getEnabledLocales() + if err != nil { + return nil, err + } + + templateNames, err := r.getTemplateNames() if err != nil { return nil, err } - return r.importBlocks, nil + for _, templateName := range *templateNames { + templateContentData, err := r.getTemplateContentData(templateName) + if err != nil { + return nil, err + } + + for _, templateContentInfo := range *templateContentData { + templateContentId := templateContentInfo.TemplateContentId + templateContentDeliveryMethod := templateContentInfo.TemplateContentDeliveryMethod + templateContentLocale := templateContentInfo.TemplateContentLocale + templateContentVariant := templateContentInfo.TemplateContentVariant + + // Only export template content if the locale is enabled + if (*enabledLocales)[templateContentLocale] { + commentData := map[string]string{ + "Resource Type": r.ResourceType(), + "Template Name": string(templateName), + "Template Content Delivery Method": templateContentDeliveryMethod, + "Template Content Locale": templateContentLocale, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Template Content ID": templateContentId, + } + + if templateContentVariant != "" { + commentData["Template Content Variant"] = templateContentVariant + templateContentVariant = fmt.Sprintf("_%s", templateContentVariant) + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s%s", string(templateName), templateContentDeliveryMethod, templateContentLocale, templateContentVariant), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, string(templateName), templateContentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + } + + return &importBlocks, nil +} + +func (r *PingOneNotificationTemplateContentResource) getEnabledLocales() (*map[string]bool, error) { + enabledLocales := make(map[string]bool) + + iter := r.clientInfo.ApiClient.ManagementAPIClient.LanguagesApi.ReadLanguages(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() + + for cursor, err := range iter { + err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadLanguages", r.ResourceType()) + if err != nil { + return nil, err + } + + if cursor.EntityArray == nil { + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() + if !embeddedOk { + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + for _, languageInner := range embedded.GetLanguages() { + if languageInner.Language != nil { + languageLocale, languageLocaleOk := languageInner.Language.GetLocaleOk() + languageEnabled, languageEnabledOk := languageInner.Language.GetEnabledOk() + + if languageLocaleOk && languageEnabledOk && *languageEnabled { + enabledLocales[*languageLocale] = true + } + } + } + } + + return &enabledLocales, nil } -func (r *PingOneNotificationTemplateContentResource) exportNotificationTemplateContents() error { +func (r *PingOneNotificationTemplateContentResource) getTemplateNames() (*[]management.EnumTemplateName, error) { + templateNames := []management.EnumTemplateName{} + for _, templateName := range management.AllowedEnumTemplateNameEnumValues { - err := r.exportNotificationTemplateContentsByTemplate(templateName) + _, response, err := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsTemplatesApi.ReadOneTemplate(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, templateName).Execute() + // When PingOne services are not enabled in an environment, + // the response code for the templates related to that service is + // 400 Bad Request - "CONSTRAINT_VIOLATION" + if err != nil && response.StatusCode == 400 && response.Status == "400 Bad Request" { + defer response.Body.Close() + body, err := io.ReadAll(response.Body) + if err != nil { + return nil, err + } + + if strings.Contains(string(body), "CONSTRAINT_VIOLATION") { + continue + } + } + + // Handle all other errors or bad responses + err = common.HandleClientResponse(response, err, "ReadOneTemplate", r.ResourceType()) if err != nil { - return err + return nil, err } + + templateNames = append(templateNames, templateName) } - return nil + return &templateNames, nil } -func (r *PingOneNotificationTemplateContentResource) exportNotificationTemplateContentsByTemplate(templateName management.EnumTemplateName) error { +func (r *PingOneNotificationTemplateContentResource) getTemplateContentData(templateName management.EnumTemplateName) (*[]NotificationTemplateContentData, error) { + l := logger.Get() + templateContentData := []NotificationTemplateContentData{} + iter := r.clientInfo.ApiClient.ManagementAPIClient.NotificationsTemplatesApi.ReadAllTemplateContents(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, templateName).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTemplateContents", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + } + + if templateName == management.ENUMTEMPLATENAME_STRONG_AUTHENTICATION { + fmt.Printf("Page data length %d\n", len(embedded.GetContents())) } for _, templateContent := range embedded.GetContents() { @@ -105,39 +222,20 @@ func (r *PingOneNotificationTemplateContentResource) exportNotificationTemplateC templateContentLocale, templateContentLocaleOk = templateContent.TemplateContentVoice.GetLocaleOk() templateContentVariant = templateContent.TemplateContentVoice.GetVariant() default: + l.Warn().Msgf("Template content '%s' for template '%s' is not one of: Push, SMS, Email, or Voice. Skipping export.", *templateContentId, templateName) continue } if templateContentIdOk && templateContentDeliveryMethodOk && templateContentLocaleOk { - r.addImportBlock(string(templateName), *templateContentId, string(*templateContentDeliveryMethod), *templateContentLocale, templateContentVariant) + templateContentData = append(templateContentData, NotificationTemplateContentData{ + TemplateContentId: *templateContentId, + TemplateContentDeliveryMethod: string(*templateContentDeliveryMethod), + TemplateContentLocale: *templateContentLocale, + TemplateContentVariant: templateContentVariant, + }) } } } - return nil -} - -func (r *PingOneNotificationTemplateContentResource) addImportBlock(templateName, templateContentId, templateContentDeliveryMethod, templateContentLocale, templateContentVariant string) { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Template Name": templateName, - "Template Content Delivery Method": templateContentDeliveryMethod, - "Template Content Locale": templateContentLocale, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Template Content ID": templateContentId, - } - - if templateContentVariant != "" { - commentData["Template Content Variant"] = templateContentVariant - templateContentVariant = "_" + templateContentVariant - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s%s", templateName, templateContentDeliveryMethod, templateContentLocale, templateContentVariant), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, templateName, templateContentId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &templateContentData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_notification_template_content_test.go b/internal/connector/pingone/platform/resources/pingone_notification_template_content_test.go index 16b3befb..3cee9cfb 100644 --- a/internal/connector/pingone/platform/resources/pingone_notification_template_content_test.go +++ b/internal/connector/pingone/platform/resources/pingone_notification_template_content_test.go @@ -10,7 +10,7 @@ import ( ) func TestNotificationTemplateContentExport(t *testing.T) { - // TODO: Remove the skipNow following completion of https://github.com/pingidentity/pingcli/issues/29 + // TODO remove this skip dependent upon STAGING-25369 t.SkipNow() // Get initialized apiClient and resource @@ -21,117 +21,237 @@ func TestNotificationTemplateContentExport(t *testing.T) { expectedImportBlocks := []connector.ImportBlock{ { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_Voice_en_Test Duplication on Device Pairing", + ResourceName: "device_pairing_email_en_625d98de_9f2d_4e1b_8417_d0ba139d36b2", + ResourceID: fmt.Sprintf("%s/device_pairing/625d98de-9f2d-4e1b-8417-d0ba139d36b2", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "device_pairing_sms_en_d4ca6154_bf87_4201_825b_6a1fecbd66ac", + ResourceID: fmt.Sprintf("%s/device_pairing/d4ca6154-bf87-4201-825b-6a1fecbd66ac", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "device_pairing_voice_en_d4ed6d8d_1b54_4903_970f_1c9896eed55d", ResourceID: fmt.Sprintf("%s/device_pairing/d4ed6d8d-1b54-4903-970f-1c9896eed55d", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_Email_en_Test Duplication on Device Pairing", + ResourceName: "device_pairing_email_en_2acfe36d_065c_465e_be21_cb95e46cee45", ResourceID: fmt.Sprintf("%s/device_pairing/2acfe36d-065c-465e-be21-cb95e46cee45", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_SMS_en_Test Duplication on Device Pairing", - ResourceID: fmt.Sprintf("%s/device_pairing/f67b076d-bb78-4cbd-b945-f721be9c88f6", testutils.GetEnvironmentID()), + ResourceName: "device_pairing_voice_fr_f50e80bc_e84d_7124_0db5_4fd4cf72d7c9", + ResourceID: fmt.Sprintf("%s/device_pairing/f50e80bc-e84d-7124-0db5-4fd4cf72d7c9", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_Voice_en", - ResourceID: fmt.Sprintf("%s/device_pairing/d02693ae-8809-4a7f-a7f9-da9f272c8096", testutils.GetEnvironmentID()), + ResourceName: "device_pairing_email_fr_a0a13d00_a249_7ad1_3f7e_b6ba77a55955", + ResourceID: fmt.Sprintf("%s/device_pairing/a0a13d00-a249-7ad1-3f7e-b6ba77a55955", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_Email_en", - ResourceID: fmt.Sprintf("%s/device_pairing/625d98de-9f2d-4e1b-8417-d0ba139d36b2", testutils.GetEnvironmentID()), + ResourceName: "device_pairing_sms_fr_c21bda2c_64b4_7025_2c83_d04d0f72077f", + ResourceID: fmt.Sprintf("%s/device_pairing/c21bda2c-64b4-7025-2c83-d04d0f72077f", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_SMS_en", - ResourceID: fmt.Sprintf("%s/device_pairing/d4ca6154-bf87-4201-825b-6a1fecbd66ac", testutils.GetEnvironmentID()), + ResourceName: "device_pairing_email_en_14651a6a_945b_725b_321f_e13cbe0fd9c6", + ResourceID: fmt.Sprintf("%s/device_pairing/14651a6a-945b-725b-321f-e13cbe0fd9c6", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "device_pairing_SMS_fr", - ResourceID: fmt.Sprintf("%s/device_pairing/c21bda2c-64b4-7025-2c83-d04d0f72077f", testutils.GetEnvironmentID()), + ResourceName: "device_pairing_sms_en_f67b076d_bb78_4cbd_b945_f721be9c88f6", + ResourceID: fmt.Sprintf("%s/device_pairing/f67b076d-bb78-4cbd-b945-f721be9c88f6", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "device_pairing_voice_en_56b27d33_0110_7670_2c16_f0fca48b6340", + ResourceID: fmt.Sprintf("%s/device_pairing/56b27d33-0110-7670-2c16-f0fca48b6340", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "email_verification_admin_Email_en", + ResourceName: "device_pairing_voice_en_d02693ae_8809_4a7f_a7f9_da9f272c8096", + ResourceID: fmt.Sprintf("%s/device_pairing/d02693ae-8809-4a7f-a7f9-da9f272c8096", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "device_pairing_sms_en_2512b56d_e14d_7cbd_3667_e1663d44fa41", + ResourceID: fmt.Sprintf("%s/device_pairing/2512b56d-e14d-7cbd-3667-e1663d44fa41", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "email_verification_admin_email_en_b130f9a6_a422_72c0_3afa_105d5f8fbb88", ResourceID: fmt.Sprintf("%s/email_verification_admin/b130f9a6-a422-72c0-3afa-105d5f8fbb88", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "email_verification_user_Email_en", + ResourceName: "email_verification_user_email_en_5eda6f7b_59c6_7c22_3348_9821179c2b37", ResourceID: fmt.Sprintf("%s/email_verification_user/5eda6f7b-59c6-7c22-3348-9821179c2b37", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "general_Voice_fr", - ResourceID: fmt.Sprintf("%s/general/831e9b77-5a05-7ed1-0fa6-c8cb637b5904", testutils.GetEnvironmentID()), + ResourceName: "general_sms_fr_63501c32_723c_7d4c_1f93_4e3c8c0cb292", + ResourceID: fmt.Sprintf("%s/general/63501c32-723c-7d4c-1f93-4e3c8c0cb292", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "general_SMS_fr", - ResourceID: fmt.Sprintf("%s/general/63501c32-723c-7d4c-1f93-4e3c8c0cb292", testutils.GetEnvironmentID()), + ResourceName: "general_email_en_92adace7_5056_7d40_1c7e_adc71e57cc3f", + ResourceID: fmt.Sprintf("%s/general/92adace7-5056-7d40-1c7e-adc71e57cc3f", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "general_SMS_en", + ResourceName: "general_sms_en_1dd4c1a3_802b_70c0_3d10_5524eb9defc7", ResourceID: fmt.Sprintf("%s/general/1dd4c1a3-802b-70c0-3d10-5524eb9defc7", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "new_device_paired_SMS_fr", - ResourceID: fmt.Sprintf("%s/new_device_paired/a5dacd1c-c395-74ab-216f-a17037b22cf6", testutils.GetEnvironmentID()), + ResourceName: "general_voice_en_72618f82_18ed_7b7c_19ac_0b5899d92f0c", + ResourceID: fmt.Sprintf("%s/general/72618f82-18ed-7b7c-19ac-0b5899d92f0c", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "general_email_fr_28524b17_b60b_7fa2_131d_59816ac19864", + ResourceID: fmt.Sprintf("%s/general/28524b17-b60b-7fa2-131d-59816ac19864", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "general_voice_fr_831e9b77_5a05_7ed1_0fa6_c8cb637b5904", + ResourceID: fmt.Sprintf("%s/general/831e9b77-5a05-7ed1-0fa6-c8cb637b5904", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "new_device_paired_Email_en", + ResourceName: "new_device_paired_email_fr_a7c11013_ca70_7071_3955_d647568f95d2", + ResourceID: fmt.Sprintf("%s/new_device_paired/a7c11013-ca70-7071-3955-d647568f95d2", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "new_device_paired_email_en_995558d3_39a9_72bf_32a6_e3c1e395aa1f", ResourceID: fmt.Sprintf("%s/new_device_paired/995558d3-39a9-72bf-32a6-e3c1e395aa1f", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "strong_authentication_Voice_en", - ResourceID: fmt.Sprintf("%s/strong_authentication/b5664ec8-a329-4ced-92ce-bbab388e7329", testutils.GetEnvironmentID()), + ResourceName: "new_device_paired_sms_fr_a5dacd1c_c395_74ab_216f_a17037b22cf6", + ResourceID: fmt.Sprintf("%s/new_device_paired/a5dacd1c-c395-74ab-216f-a17037b22cf6", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "strong_authentication_Email_en", - ResourceID: fmt.Sprintf("%s/strong_authentication/d1235c66-48c6-46ae-ae6d-599513ab26d7", testutils.GetEnvironmentID()), + ResourceName: "new_device_paired_sms_en_daef917c_3695_7347_1ed0_bb03d80198c2", + ResourceID: fmt.Sprintf("%s/new_device_paired/daef917c-3695-7347-1ed0-bb03d80198c2", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "strong_authentication_SMS_en", - ResourceID: fmt.Sprintf("%s/strong_authentication/41054e31-dacd-4591-a8c8-f44cbec6313f", testutils.GetEnvironmentID()), + ResourceName: "recovery_code_template_email_fr_c558cd3c_eb16_7158_38c3_d87fb2e320f0", + ResourceID: fmt.Sprintf("%s/recovery_code_template/c558cd3c-eb16-7158-38c3-d87fb2e320f0", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "strong_authentication_Push_en", + ResourceName: "recovery_code_template_email_en_dc6755cd_123b_71f6_2fe0_5b74d3789001", + ResourceID: fmt.Sprintf("%s/recovery_code_template/dc6755cd-123b-71f6-2fe0-5b74d3789001", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_push_en_c6b2f1e9_fcde_4b64_b473_f5370219da76", ResourceID: fmt.Sprintf("%s/strong_authentication/c6b2f1e9-fcde-4b64-b473-f5370219da76", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "strong_authentication_SMS_fr", - ResourceID: fmt.Sprintf("%s/strong_authentication/807cd1a1-f3f8-7440-10f5-5f9cf944abb3", testutils.GetEnvironmentID()), + ResourceName: "strong_authentication_voice_fr_c6de3d50_d766_7533_25cf_bd28f72e2f86", + ResourceID: fmt.Sprintf("%s/strong_authentication/c6de3d50-d766-7533-25cf-bd28f72e2f86", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_sms_en_5d2b94bc_d264_7f79_048f_a0f062f66d98", + ResourceID: fmt.Sprintf("%s/strong_authentication/5d2b94bc-d264-7f79-048f-a0f062f66d98", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_push_en_b368bc5e_0815_7d16_178c_2631a620e00c", + ResourceID: fmt.Sprintf("%s/strong_authentication/b368bc5e-0815-7d16-178c-2631a620e00c", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_email_fr_2e103d6d_af8e_70fa_282f_91821ed778fd", + ResourceID: fmt.Sprintf("%s/strong_authentication/2e103d6d-af8e-70fa-282f-91821ed778fd", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "strong_authentication_Push_fr", + ResourceName: "strong_authentication_push_fr_d3d66f1b_b748_7afc_2d4b_a1daffd50a77", ResourceID: fmt.Sprintf("%s/strong_authentication/d3d66f1b-b748-7afc-2d4b-a1daffd50a77", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "transaction_SMS_fr", + ResourceName: "strong_authentication_voice_en_8a888c96_4cb9_7941_0c07_0a4e99a54a04", + ResourceID: fmt.Sprintf("%s/strong_authentication/8a888c96-4cb9-7941-0c07-0a4e99a54a04", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_sms_en_41054e31_dacd_4591_a8c8_f44cbec6313f", + ResourceID: fmt.Sprintf("%s/strong_authentication/41054e31-dacd-4591-a8c8-f44cbec6313f", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_sms_fr_807cd1a1_f3f8_7440_10f5_5f9cf944abb3", + ResourceID: fmt.Sprintf("%s/strong_authentication/807cd1a1-f3f8-7440-10f5-5f9cf944abb3", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_email_en_e8539132_48c6_7061_1309_f33e99599a3e", + ResourceID: fmt.Sprintf("%s/strong_authentication/e8539132-48c6-7061-1309-f33e99599a3e", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "strong_authentication_email_en_d1235c66_48c6_46ae_ae6d_599513ab26d7", + ResourceID: fmt.Sprintf("%s/strong_authentication/d1235c66-48c6-46ae-ae6d-599513ab26d7", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_push_fr_453937a6_e95b_78b9_0d13_be9e17cdda89", + ResourceID: fmt.Sprintf("%s/transaction/453937a6-e95b-78b9-0d13-be9e17cdda89", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_sms_fr_10458132_7361_7d6b_3e42_04128ae31625", ResourceID: fmt.Sprintf("%s/transaction/10458132-7361-7d6b-3e42-04128ae31625", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "verification_code_template_Email_fr", + ResourceName: "transaction_voice_en_b2509f63_c86c_7f76_0fea_52472af67df2", + ResourceID: fmt.Sprintf("%s/transaction/b2509f63-c86c-7f76-0fea-52472af67df2", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_email_fr_1953c10e_53a9_7c44_13eb_560823acacf6", + ResourceID: fmt.Sprintf("%s/transaction/1953c10e-53a9-7c44-13eb-560823acacf6", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_push_en_926802db_4abb_7369_249a_ff3c63c6a7d1", + ResourceID: fmt.Sprintf("%s/transaction/926802db-4abb-7369-249a-ff3c63c6a7d1", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_email_en_996806a7_0c4e_744c_117b_6312e08225d3", + ResourceID: fmt.Sprintf("%s/transaction/996806a7-0c4e-744c-117b-6312e08225d3", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_sms_en_d9751d12_2f37_7d6e_3cc4_33368770f6da", + ResourceID: fmt.Sprintf("%s/transaction/d9751d12-2f37-7d6e-3cc4-33368770f6da", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "transaction_voice_fr_0db4c9f4_c1d6_7adf_1870_22f70f5e95a1", + ResourceID: fmt.Sprintf("%s/transaction/0db4c9f4-c1d6-7adf-1870-22f70f5e95a1", testutils.GetEnvironmentID()), + }, + { + ResourceType: "pingone_notification_template_content", + ResourceName: "verification_code_template_email_fr_03bdf108_c71d_74fb_28e8_143f22b98125", ResourceID: fmt.Sprintf("%s/verification_code_template/03bdf108-c71d-74fb-28e8-143f22b98125", testutils.GetEnvironmentID()), }, { ResourceType: "pingone_notification_template_content", - ResourceName: "verification_code_template_Email_en", + ResourceName: "verification_code_template_email_en_93688f61_e554_736d_227d_ac8ee610c254", ResourceID: fmt.Sprintf("%s/verification_code_template/93688f61-e554-736d-227d-ac8ee610c254", testutils.GetEnvironmentID()), }, } diff --git a/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go b/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go index 686e82ef..f2ee8262 100644 --- a/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go +++ b/internal/connector/pingone/platform/resources/pingone_phone_delivery_settings.go @@ -15,15 +15,13 @@ var ( ) type PingOnePhoneDeliverySettingsResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOnePhoneDeliverySettingsResource func PhoneDeliverySettings(clientInfo *connector.PingOneClientInfo) *PingOnePhoneDeliverySettingsResource { return &PingOnePhoneDeliverySettingsResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,52 @@ func (r *PingOnePhoneDeliverySettingsResource) ExportAll() (*[]connector.ImportB l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportPhoneDeliverySettings() + importBlocks := []connector.ImportBlock{} + + phoneDeliverySettingsData, err := r.getPhoneDeliverySettingsData() if err != nil { return nil, err } - return r.importBlocks, nil + for phoneDeliverySettingsId, phoneDeliverySettingsName := range *phoneDeliverySettingsData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Phone Delivery Settings ID": phoneDeliverySettingsId, + "Phone Delivery Settings Name": phoneDeliverySettingsName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: phoneDeliverySettingsName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, phoneDeliverySettingsId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOnePhoneDeliverySettingsResource) exportPhoneDeliverySettings() error { +func (r *PingOnePhoneDeliverySettingsResource) getPhoneDeliverySettingsData() (*map[string]string, error) { + phoneDeliverySettingsData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.PhoneDeliverySettingsApi.ReadAllPhoneDeliverySettings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPhoneDeliverySettings", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, phoneDeliverySettings := range embedded.GetPhoneDeliverySettings() { @@ -93,28 +113,10 @@ func (r *PingOnePhoneDeliverySettingsResource) exportPhoneDeliverySettings() err } if phoneDeliverySettingsIdOk && phoneDeliverySettingsNameOk { - r.addImportBlock(*phoneDeliverySettingsId, phoneDeliverySettingsName) + phoneDeliverySettingsData[*phoneDeliverySettingsId] = phoneDeliverySettingsName } } } - return nil -} - -func (r *PingOnePhoneDeliverySettingsResource) addImportBlock(phoneDeliverySettingsId, phoneDeliverySettingsName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Phone Delivery Settings ID": phoneDeliverySettingsId, - "Phone Delivery Settings Name": phoneDeliverySettingsName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: phoneDeliverySettingsName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, phoneDeliverySettingsId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &phoneDeliverySettingsData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_system_application.go b/internal/connector/pingone/platform/resources/pingone_system_application.go index 370eb069..a9901a5b 100644 --- a/internal/connector/pingone/platform/resources/pingone_system_application.go +++ b/internal/connector/pingone/platform/resources/pingone_system_application.go @@ -14,15 +14,13 @@ var ( ) type PingOneSystemApplicationResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneSystemApplicationResource func SystemApplication(clientInfo *connector.PingOneClientInfo) *PingOneSystemApplicationResource { return &PingOneSystemApplicationResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneSystemApplicationResource) ExportAll() (*[]connector.ImportBlock l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportSystemApplications() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getSystemApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "System Application ID": appId, + "System Application Name": appName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: appName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneSystemApplicationResource) exportSystemApplications() error { +func (r *PingOneSystemApplicationResource) getSystemApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -80,28 +100,10 @@ func (r *PingOneSystemApplicationResource) exportSystemApplications() error { } if appIdOk && appNameOk { - r.addImportBlock(*appId, *appName) + applicationData[*appId] = *appName } } } - return nil -} - -func (r *PingOneSystemApplicationResource) addImportBlock(appId, appName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "System Application ID": appId, - "System Application Name": appName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: appName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &applicationData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go b/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go index b61c1755..0f115b49 100644 --- a/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go +++ b/internal/connector/pingone/platform/resources/pingone_trusted_email_address.go @@ -14,15 +14,13 @@ var ( ) type PingOneTrustedEmailAddressResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneTrustedEmailAddressResource func TrustedEmailAddress(clientInfo *connector.PingOneClientInfo) *PingOneTrustedEmailAddressResource { return &PingOneTrustedEmailAddressResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,61 @@ func (r *PingOneTrustedEmailAddressResource) ExportAll() (*[]connector.ImportBlo l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportTrustedEmailAddresses() + importBlocks := []connector.ImportBlock{} + + trustedEmailDomainData, err := r.getTrustedEmailDomainData() if err != nil { return nil, err } - return r.importBlocks, nil + for trustedEmailDomainId, trustedEmailDomainName := range *trustedEmailDomainData { + trustedEmailAddressData, err := r.getTrustedEmailAddressData(trustedEmailDomainId) + if err != nil { + return nil, err + } + + for trustedEmailId, trustedEmailAddress := range *trustedEmailAddressData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Trusted Email Address": trustedEmailAddress, + "Trusted Email Address ID": trustedEmailId, + "Trusted Email Domain ID": trustedEmailDomainId, + "Trusted Email Domain Name": trustedEmailDomainName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", trustedEmailDomainName, trustedEmailAddress), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, trustedEmailDomainId, trustedEmailId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneTrustedEmailAddressResource) exportTrustedEmailAddresses() error { +func (r *PingOneTrustedEmailAddressResource) getTrustedEmailDomainData() (*map[string]string, error) { + trustedEmailDomainData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailDomainsApi.ReadAllTrustedEmailDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTrustedEmailDomains", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, trustedEmailDomain := range embedded.GetEmailDomains() { @@ -65,33 +94,32 @@ func (r *PingOneTrustedEmailAddressResource) exportTrustedEmailAddresses() error trustedEmailDomainName, trustedEmailDomainNameOk := trustedEmailDomain.GetDomainNameOk() if trustedEmailDomainIdOk && trustedEmailDomainNameOk { - err := r.exportTrustedEmailAddressesByDomain(*trustedEmailDomainId, *trustedEmailDomainName) - if err != nil { - return err - } + trustedEmailDomainData[*trustedEmailDomainId] = *trustedEmailDomainName } } } - return nil + return &trustedEmailDomainData, nil } -func (r *PingOneTrustedEmailAddressResource) exportTrustedEmailAddressesByDomain(trustedEmailDomainId, trustedEmailDomainName string) error { +func (r *PingOneTrustedEmailAddressResource) getTrustedEmailAddressData(trustedEmailDomainId string) (*map[string]string, error) { + trustedEmailAddressData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailAddressesApi.ReadAllTrustedEmailAddresses(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, trustedEmailDomainId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTrustedEmailAddresses", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, trustedEmail := range embedded.GetTrustedEmails() { @@ -99,30 +127,10 @@ func (r *PingOneTrustedEmailAddressResource) exportTrustedEmailAddressesByDomain trustedEmailId, trustedEmailIdOk := trustedEmail.GetIdOk() if trustedEmailAddressOk && trustedEmailIdOk { - r.addImportBlock(trustedEmailDomainId, trustedEmailDomainName, *trustedEmailId, *trustedEmailAddress) + trustedEmailAddressData[*trustedEmailId] = *trustedEmailAddress } } } - return nil -} - -func (r *PingOneTrustedEmailAddressResource) addImportBlock(trustedEmailDomainId, trustedEmailDomainName, trustedEmailId, trustedEmailAddress string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Trusted Email Address": trustedEmailAddress, - "Trusted Email Address ID": trustedEmailId, - "Trusted Email Domain ID": trustedEmailDomainId, - "Trusted Email Domain Name": trustedEmailDomainName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", trustedEmailDomainName, trustedEmailAddress), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, trustedEmailDomainId, trustedEmailId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &trustedEmailAddressData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go b/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go index 7b2cf478..f0debf8b 100644 --- a/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go +++ b/internal/connector/pingone/platform/resources/pingone_trusted_email_domain.go @@ -14,15 +14,13 @@ var ( ) type PingOneTrustedEmailDomainResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOne Trusted Email Domain Resource func TrustedEmailDomain(clientInfo *connector.PingOneClientInfo) *PingOneTrustedEmailDomainResource { return &PingOneTrustedEmailDomainResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneTrustedEmailDomainResource) ExportAll() (*[]connector.ImportBloc l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportTrustedEmailDomains() + importBlocks := []connector.ImportBlock{} + + trustedEmailDomainData, err := r.getTrustedEmailDomainData() if err != nil { return nil, err } - return r.importBlocks, nil + for trustedEmailDomainId, trustedEmailDomainName := range *trustedEmailDomainData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Trusted Email Domain ID": trustedEmailDomainId, + "Trusted Email Domain Name": trustedEmailDomainName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: trustedEmailDomainName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, trustedEmailDomainId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneTrustedEmailDomainResource) exportTrustedEmailDomains() error { +func (r *PingOneTrustedEmailDomainResource) getTrustedEmailDomainData() (*map[string]string, error) { + trustedEmailDomainData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.TrustedEmailDomainsApi.ReadAllTrustedEmailDomains(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllTrustedEmailDomains", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, emailDomain := range embedded.GetEmailDomains() { @@ -65,28 +85,10 @@ func (r *PingOneTrustedEmailDomainResource) exportTrustedEmailDomains() error { emailDomainName, emailDomainNameOk := emailDomain.GetDomainNameOk() if emailDomainIdOk && emailDomainNameOk { - r.addImportBlock(*emailDomainId, *emailDomainName) + trustedEmailDomainData[*emailDomainId] = *emailDomainName } } } - return nil -} - -func (r *PingOneTrustedEmailDomainResource) addImportBlock(emailDomainId, emailDomainName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Trusted Email Domain ID": emailDomainId, - "Trusted Email Domain Name": emailDomainName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: emailDomainName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, emailDomainId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &trustedEmailDomainData, nil } diff --git a/internal/connector/pingone/platform/resources/pingone_webhook.go b/internal/connector/pingone/platform/resources/pingone_webhook.go index bd4f702d..e3b94815 100644 --- a/internal/connector/pingone/platform/resources/pingone_webhook.go +++ b/internal/connector/pingone/platform/resources/pingone_webhook.go @@ -14,15 +14,13 @@ var ( ) type PingOneWebhookResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneWebhookResource func Webhook(clientInfo *connector.PingOneClientInfo) *PingOneWebhookResource { return &PingOneWebhookResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneWebhookResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportWebhooks() + importBlocks := []connector.ImportBlock{} + + subscriptionData, err := r.getSubscriptionData() if err != nil { return nil, err } - return r.importBlocks, nil + for subscriptionId, subscriptionName := range *subscriptionData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Webhook ID": subscriptionId, + "Webhook Name": subscriptionName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: subscriptionName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, subscriptionId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneWebhookResource) exportWebhooks() error { +func (r *PingOneWebhookResource) getSubscriptionData() (*map[string]string, error) { + subscriptionData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.SubscriptionsWebhooksApi.ReadAllSubscriptions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSubscriptions", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, subscription := range embedded.GetSubscriptions() { @@ -65,28 +85,10 @@ func (r *PingOneWebhookResource) exportWebhooks() error { subscriptionName, subscriptionNameOk := subscription.GetNameOk() if subscriptionIdOk && subscriptionNameOk { - r.addImportBlock(*subscriptionId, *subscriptionName) + subscriptionData[*subscriptionId] = *subscriptionName } } } - return nil -} - -func (r *PingOneWebhookResource) addImportBlock(subscriptionId, subscriptionName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Webhook ID": subscriptionId, - "Webhook Name": subscriptionName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: subscriptionName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, subscriptionId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &subscriptionData, nil } diff --git a/internal/connector/pingone/protect/resources/pingone_risk_policy.go b/internal/connector/pingone/protect/resources/pingone_risk_policy.go index 6006a9e1..14327882 100644 --- a/internal/connector/pingone/protect/resources/pingone_risk_policy.go +++ b/internal/connector/pingone/protect/resources/pingone_risk_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOneRiskPolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneRiskPolicyResource func RiskPolicy(clientInfo *connector.PingOneClientInfo) *PingOneRiskPolicyResource { return &PingOneRiskPolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneRiskPolicyResource) ExportAll() (*[]connector.ImportBlock, error l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportPolicies() + importBlocks := []connector.ImportBlock{} + + ristPolicySetData, err := r.getRiskPolicySetData() if err != nil { return nil, err } - return r.importBlocks, nil + for riskPolicySetId, riskPolicySetName := range *ristPolicySetData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Risk Policy ID": riskPolicySetId, + "Risk Policy Name": riskPolicySetName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: riskPolicySetName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, riskPolicySetId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneRiskPolicyResource) exportPolicies() error { +func (r *PingOneRiskPolicyResource) getRiskPolicySetData() (*map[string]string, error) { + riskPolicySetData := make(map[string]string) + iter := r.clientInfo.ApiClient.RiskAPIClient.RiskPoliciesApi.ReadRiskPolicySets(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadRiskPolicySets", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, riskPolicySet := range embedded.GetRiskPolicySets() { @@ -65,28 +85,10 @@ func (r *PingOneRiskPolicyResource) exportPolicies() error { riskPolicySetId, riskPolicySetIdOk := riskPolicySet.GetIdOk() if riskPolicySetIdOk && riskPolicySetNameOk { - r.addImportBlock(*riskPolicySetId, *riskPolicySetName) + riskPolicySetData[*riskPolicySetId] = *riskPolicySetName } } } - return nil -} - -func (r *PingOneRiskPolicyResource) addImportBlock(riskPolicySetId, riskPolicySetName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Risk Policy ID": riskPolicySetId, - "Risk Policy Name": riskPolicySetName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: riskPolicySetName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, riskPolicySetId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &riskPolicySetData, nil } diff --git a/internal/connector/pingone/protect/resources/pingone_risk_predictor.go b/internal/connector/pingone/protect/resources/pingone_risk_predictor.go index 7a6905ba..9eb7f85f 100644 --- a/internal/connector/pingone/protect/resources/pingone_risk_predictor.go +++ b/internal/connector/pingone/protect/resources/pingone_risk_predictor.go @@ -15,15 +15,13 @@ var ( ) type PingOneRiskPredictorResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneRiskPredictorResource func RiskPredictor(clientInfo *connector.PingOneClientInfo) *PingOneRiskPredictorResource { return &PingOneRiskPredictorResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,56 @@ func (r *PingOneRiskPredictorResource) ExportAll() (*[]connector.ImportBlock, er l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportRiskPredictors() + importBlocks := []connector.ImportBlock{} + + riskPredictorData, err := r.getRiskPredictorData() if err != nil { return nil, err } - return r.importBlocks, nil + for riskPredictorId, riskPredictorInfo := range *riskPredictorData { + riskPredictorName := riskPredictorInfo[0] + riskPredictorType := riskPredictorInfo[1] + + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Risk Predictor ID": riskPredictorId, + "Risk Predictor Name": riskPredictorName, + "Risk Predictor Type": riskPredictorType, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", riskPredictorType, riskPredictorName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, riskPredictorId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneRiskPredictorResource) exportRiskPredictors() error { +func (r *PingOneRiskPredictorResource) getRiskPredictorData() (*map[string][]string, error) { + riskPredictorData := make(map[string][]string) + iter := r.clientInfo.ApiClient.RiskAPIClient.RiskAdvancedPredictorsApi.ReadAllRiskPredictors(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllRiskPredictors", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, riskPredictor := range embedded.GetRiskPredictors() { @@ -129,29 +153,10 @@ func (r *PingOneRiskPredictorResource) exportRiskPredictors() error { } if riskPredictorIdOk && riskPredictorNameOk && riskPredictorTypeOk { - r.addImportBlock(*riskPredictorId, *riskPredictorName, string(*riskPredictorType)) + riskPredictorData[*riskPredictorId] = []string{*riskPredictorName, string(*riskPredictorType)} } } } - return nil -} - -func (r *PingOneRiskPredictorResource) addImportBlock(riskPredictorId, riskPredictorName, riskPredictorType string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Risk Predictor ID": riskPredictorId, - "Risk Predictor Name": riskPredictorName, - "Risk Predictor Type": riskPredictorType, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", riskPredictorType, riskPredictorName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, riskPredictorId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &riskPredictorData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_application.go b/internal/connector/pingone/sso/resources/pingone_application.go index b0010e35..1b94f1e9 100644 --- a/internal/connector/pingone/sso/resources/pingone_application.go +++ b/internal/connector/pingone/sso/resources/pingone_application.go @@ -14,15 +14,13 @@ var ( ) type PingOneApplicationResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationResource func Application(clientInfo *connector.PingOneClientInfo) *PingOneApplicationResource { return &PingOneApplicationResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneApplicationResource) ExportAll() (*[]connector.ImportBlock, erro l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplications() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: appName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneApplicationResource) exportApplications() error { +func (r *PingOneApplicationResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -83,28 +103,10 @@ func (r *PingOneApplicationResource) exportApplications() error { } if appIdOk && appNameOk { - r.addImportBlock(*appId, *appName) + applicationData[*appId] = *appName } } } - return nil -} - -func (r *PingOneApplicationResource) addImportBlock(appId, appName string) { - commentData := map[string]string{ - "Application ID": appId, - "Application Name": appName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: appName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &applicationData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go b/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go index 3043cf9a..deb5050b 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go +++ b/internal/connector/pingone/sso/resources/pingone_application_attribute_mapping.go @@ -14,15 +14,13 @@ var ( ) type PingOneApplicationAttributeMappingResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationAttributeMappingResource func ApplicationAttributeMapping(clientInfo *connector.PingOneClientInfo) *PingOneApplicationAttributeMappingResource { return &PingOneApplicationAttributeMappingResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,61 @@ func (r *PingOneApplicationAttributeMappingResource) ExportAll() (*[]connector.I l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplicationAttributeMappings() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + applicationAttributeMappingData, err := r.getApplicationAttributeMappingData(appId) + if err != nil { + return nil, err + } + + for attributeMappingId, attributeMappingName := range *applicationAttributeMappingData { + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Attribute Mapping ID": attributeMappingId, + "Attribute Mapping Name": attributeMappingName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, attributeMappingName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, attributeMappingId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneApplicationAttributeMappingResource) exportApplicationAttributeMappings() error { +func (r *PingOneApplicationAttributeMappingResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -80,33 +109,32 @@ func (r *PingOneApplicationAttributeMappingResource) exportApplicationAttributeM } if appIdOk && appNameOk { - err := r.exportApplicationAttributeMappingsByApplication(*appId, *appName) - if err != nil { - return err - } + applicationData[*appId] = *appName } } } - return nil + return &applicationData, nil } -func (r *PingOneApplicationAttributeMappingResource) exportApplicationAttributeMappingsByApplication(appId, appName string) error { +func (r *PingOneApplicationAttributeMappingResource) getApplicationAttributeMappingData(appId string) (*map[string]string, error) { + applicationAttributeMappingData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationAttributeMappingApi.ReadAllApplicationAttributeMappings(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplicationAttributeMappings", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, attributeMapping := range embedded.GetAttributes() { @@ -115,31 +143,11 @@ func (r *PingOneApplicationAttributeMappingResource) exportApplicationAttributeM attributeMappingName, attributeMappingNameOk := attributeMapping.ApplicationAttributeMapping.GetNameOk() if attributeMappingIdOk && attributeMappingNameOk { - r.addImportBlock(appId, appName, *attributeMappingId, *attributeMappingName) + applicationAttributeMappingData[*attributeMappingId] = *attributeMappingName } } } } - return nil -} - -func (r *PingOneApplicationAttributeMappingResource) addImportBlock(appId, appName, attributeMappingId, attributeMappingName string) { - commentData := map[string]string{ - "Application ID": appId, - "Application Name": appName, - "Attribute Mapping ID": attributeMappingId, - "Attribute Mapping Name": attributeMappingName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", appName, attributeMappingName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, attributeMappingId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &applicationAttributeMappingData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go b/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go index 54ea9171..280dd9f6 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_application_flow_policy_assignment.go @@ -14,15 +14,13 @@ var ( ) type PingOneApplicationFlowPolicyAssignmentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationFlowPolicyAssignmentResource func ApplicationFlowPolicyAssignment(clientInfo *connector.PingOneClientInfo) *PingOneApplicationFlowPolicyAssignmentResource { return &PingOneApplicationFlowPolicyAssignmentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,66 @@ func (r *PingOneApplicationFlowPolicyAssignmentResource) ExportAll() (*[]connect l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplicationFlowPolicyAssignments() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + flowPolicyAssignmentData, err := r.getFlowPolicyAssignmentData(appId) + if err != nil { + return nil, err + } + + for flowPolicyAssignmentId, flowPolicyId := range *flowPolicyAssignmentData { + flowPolicyName, err := r.getFlowPolicyName(flowPolicyId) + if err != nil { + return nil, err + } + + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Flow Policy Assignment ID": flowPolicyAssignmentId, + "Flow Policy Name": *flowPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, *flowPolicyName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, flowPolicyAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPolicyAssignments() error { +func (r *PingOneApplicationFlowPolicyAssignmentResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -83,33 +117,32 @@ func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPo } if appIdOk && appNameOk { - err := r.exportApplicationFlowPolicyAssignmentsByApplication(*appId, *appName) - if err != nil { - return err - } + applicationData[*appId] = *appName } } } - return nil + return &applicationData, nil } -func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPolicyAssignmentsByApplication(appId, appName string) error { +func (r *PingOneApplicationFlowPolicyAssignmentResource) getFlowPolicyAssignmentData(appId string) (*map[string]string, error) { + flowPolicyAssignmentData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationFlowPolicyAssignmentsApi.ReadAllFlowPolicyAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllFlowPolicyAssignments", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, flowPolicyAssignment := range embedded.GetFlowPolicyAssignments() { @@ -120,53 +153,30 @@ func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPo flowPolicyId, flowPolicyIdOk := flowPolicyAssignmentFlowPolicy.GetIdOk() if flowPolicyIdOk { - err := r.exportApplicationFlowPolicyAssignmentsByFlowPolicy(appId, appName, *flowPolicyId, *flowPolicyAssignmentId) - if err != nil { - return err - } + flowPolicyAssignmentData[*flowPolicyAssignmentId] = *flowPolicyId } } } } - return nil + return &flowPolicyAssignmentData, nil } -func (r *PingOneApplicationFlowPolicyAssignmentResource) exportApplicationFlowPolicyAssignmentsByFlowPolicy(appId, appName, flowPolicyId, flowPolicyAssignmentId string) error { +func (r *PingOneApplicationFlowPolicyAssignmentResource) getFlowPolicyName(flowPolicyId string) (*string, error) { flowPolicy, response, err := r.clientInfo.ApiClient.ManagementAPIClient.FlowPoliciesApi.ReadOneFlowPolicy(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, flowPolicyId).Execute() err = common.HandleClientResponse(response, err, "ReadOneFlowPolicy", r.ResourceType()) if err != nil { - return err + return nil, err } if flowPolicy != nil { flowPolicyName, flowPolicyNameOk := flowPolicy.GetNameOk() if flowPolicyNameOk { - r.addImportBlock(appId, appName, flowPolicyAssignmentId, *flowPolicyName) + return flowPolicyName, nil } } - return nil -} - -func (r *PingOneApplicationFlowPolicyAssignmentResource) addImportBlock(appId, appName, flowPolicyAssignmentId, flowPolicyName string) { - commentData := map[string]string{ - "Application ID": appId, - "Application Name": appName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Flow Policy Assignment ID": flowPolicyAssignmentId, - "Flow Policy Name": flowPolicyName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", appName, flowPolicyName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, flowPolicyAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("Unable to get Flow Policy Name for Flow Policy ID: %s", flowPolicyId) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go b/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go index 96f4ee46..9a3b77d8 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go +++ b/internal/connector/pingone/sso/resources/pingone_application_resource_grant.go @@ -14,15 +14,13 @@ var ( ) type PingOneApplicationResourceGrantResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationResourceGrantResource func ApplicationResourceGrant(clientInfo *connector.PingOneClientInfo) *PingOneApplicationResourceGrantResource { return &PingOneApplicationResourceGrantResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,66 @@ func (r *PingOneApplicationResourceGrantResource) ExportAll() (*[]connector.Impo l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplicationResourceGrants() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + applicationGrantData, err := r.getApplicationGrantData(appId) + if err != nil { + return nil, err + } + + for grantId, grantResourceId := range *applicationGrantData { + resourceName, err := r.getGrantResourceName(grantResourceId) + if err != nil { + return nil, err + } + + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Application Resource Grant ID": grantId, + "Application Resource Name": *resourceName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, *resourceName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, grantId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrants() error { +func (r *PingOneApplicationResourceGrantResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -83,33 +117,32 @@ func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrant } if appIdOk && appNameOk { - err := r.exportApplicationResourceGrantsByApplication(*appId, *appName) - if err != nil { - return err - } + applicationData[*appId] = *appName } } } - return nil + return &applicationData, nil } -func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrantsByApplication(appId, appName string) error { +func (r *PingOneApplicationResourceGrantResource) getApplicationGrantData(appId string) (*map[string]string, error) { + applicationGrantData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationResourceGrantsApi.ReadAllApplicationGrants(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplicationGrants", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, grant := range embedded.GetGrants() { @@ -120,51 +153,28 @@ func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrant grantResourceId, grantResourceIdOk := grantResource.GetIdOk() if grantResourceIdOk { - err := r.exportApplicationResourceGrantsByResource(appId, appName, *grantId, *grantResourceId) - if err != nil { - return err - } + applicationGrantData[*grantId] = *grantResourceId } } } } - return nil + return &applicationGrantData, nil } -func (r *PingOneApplicationResourceGrantResource) exportApplicationResourceGrantsByResource(appId, appName, grantId, grantResourceId string) error { +func (r *PingOneApplicationResourceGrantResource) getGrantResourceName(grantResourceId string) (*string, error) { resource, response, err := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadOneResource(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, grantResourceId).Execute() err = common.HandleClientResponse(response, err, "ReadOneResource", r.ResourceType()) if err != nil { - return err + return nil, err } if resource != nil { resourceName, resourceNameOk := resource.GetNameOk() if resourceNameOk { - r.addImportBlock(appId, appName, grantId, *resourceName) + return resourceName, nil } } - return nil -} - -func (r *PingOneApplicationResourceGrantResource) addImportBlock(appId, appName, grantId, resourceName string) { - commentData := map[string]string{ - "Application ID": appId, - "Application Name": appName, - "Application Resource Grant ID": grantId, - "Application Resource Name": resourceName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", appName, resourceName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, grantId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("Unable to get resource name for grant resource ID: %s", grantResourceId) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go b/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go index 178a3c89..3e6fd0a2 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_application_role_assignment.go @@ -15,15 +15,13 @@ var ( ) type PingOneApplicationRoleAssignmentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationRoleAssignmentResource func ApplicationRoleAssignment(clientInfo *connector.PingOneClientInfo) *PingOneApplicationRoleAssignmentResource { return &PingOneApplicationRoleAssignmentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,66 @@ func (r *PingOneApplicationRoleAssignmentResource) ExportAll() (*[]connector.Imp l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplicationRoleAssignments() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + applicationRoleAssignmentData, err := r.getApplicationRoleAssignmentData(appId) + if err != nil { + return nil, err + } + + for roleAssignmentId, roleId := range *applicationRoleAssignmentData { + roleName, err := r.getRoleName(roleId) + if err != nil { + return nil, err + } + + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Application Role Assignment ID": roleAssignmentId, + "Application Role Name": string(*roleName), + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", appName, string(*roleName), roleAssignmentId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, roleAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignments() error { +func (r *PingOneApplicationRoleAssignmentResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -99,86 +133,64 @@ func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignme continue } - err := r.exportApplicationRoleAssignmentsByApplication(*appId, *appName) - if err != nil { - return err - } + applicationData[*appId] = *appName } } } - return nil + return &applicationData, nil } -func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignmentsByApplication(appId, appName string) error { +func (r *PingOneApplicationRoleAssignmentResource) getApplicationRoleAssignmentData(appId string) (*map[string]string, error) { + applicationRoleAssignmentData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationRoleAssignmentsApi.ReadApplicationRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadApplicationRoleAssignments", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, roleAssignment := range embedded.GetRoleAssignments() { roleAssignmentId, roleAssignmentIdOk := roleAssignment.GetIdOk() roleAssignmentRole, roleAssignmentRoleOk := roleAssignment.GetRoleOk() + if roleAssignmentIdOk && roleAssignmentRoleOk { roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk() + if roleAssignmentRoleIdOk { - err := r.exportApplicationRoleAssignmentsByRole(appId, appName, *roleAssignmentId, *roleAssignmentRoleId) - if err != nil { - return err - } + applicationRoleAssignmentData[*roleAssignmentId] = *roleAssignmentRoleId } } } } - return nil + return &applicationRoleAssignmentData, nil } -func (r *PingOneApplicationRoleAssignmentResource) exportApplicationRoleAssignmentsByRole(appId, appName, roleAssignmentId, roleId string) error { +func (r *PingOneApplicationRoleAssignmentResource) getRoleName(roleId string) (*management.EnumRoleName, error) { apiRole, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, roleId).Execute() err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) if err != nil { - return err + return nil, err } if apiRole != nil { apiRoleName, apiRoleNameOk := apiRole.GetNameOk() if apiRoleNameOk { - r.addImportBlock(appId, appName, roleAssignmentId, string(*apiRoleName)) + return apiRoleName, nil } } - return nil -} - -func (r *PingOneApplicationRoleAssignmentResource) addImportBlock(appId, appName, roleAssignmentId, roleName string) { - commentData := map[string]string{ - "Application ID": appId, - "Application Name": appName, - "Application Role Assignment ID": roleAssignmentId, - "Application Role Name": roleName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s", appName, roleName, roleAssignmentId), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, roleAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("Unable to get role name for role ID: %s", roleId) } diff --git a/internal/connector/pingone/sso/resources/pingone_application_secret.go b/internal/connector/pingone/sso/resources/pingone_application_secret.go index 8204b50c..6b7ee911 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_secret.go +++ b/internal/connector/pingone/sso/resources/pingone_application_secret.go @@ -14,15 +14,13 @@ var ( ) type PingOneApplicationSecretResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationSecretResource func ApplicationSecret(clientInfo *connector.PingOneClientInfo) *PingOneApplicationSecretResource { return &PingOneApplicationSecretResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,61 @@ func (r *PingOneApplicationSecretResource) ExportAll() (*[]connector.ImportBlock l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplicationSecrets() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + ok, err := r.checkApplicationSecretData(appId) + if err != nil { + return nil, err + } + + if !ok { + continue + } + + commentData := map[string]string{ + "Application ID": appId, + "Application Name": appName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_secret", appName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneApplicationSecretResource) exportApplicationSecrets() error { +func (r *PingOneApplicationSecretResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -83,18 +112,15 @@ func (r *PingOneApplicationSecretResource) exportApplicationSecrets() error { } if appIdOk && appNameOk { - err := r.exportApplicationSecretsByApplication(*appId, *appName) - if err != nil { - return err - } + applicationData[*appId] = *appName } } } - return nil + return &applicationData, nil } -func (r *PingOneApplicationSecretResource) exportApplicationSecretsByApplication(appId, appName string) error { +func (r *PingOneApplicationSecretResource) checkApplicationSecretData(appId string) (bool, error) { l := logger.Get() // The platform enforces that worker apps cannot read their own secret @@ -104,9 +130,9 @@ func (r *PingOneApplicationSecretResource) exportApplicationSecretsByApplication // If the appId is the same as the worker ID, make sure the API response is a 403 and ignore the error if appId == *r.clientInfo.ApiClientId { if response.StatusCode == 403 { - return nil + return false, nil } else { - return fmt.Errorf("ReadApplicationSecret: Expected response code 403 - worker apps cannot read their own secret, actual response code: %d", response.StatusCode) + return false, fmt.Errorf("ReadApplicationSecret: Expected response code 403 - worker apps cannot read their own secret, actual response code: %d", response.StatusCode) } } @@ -114,35 +140,9 @@ func (r *PingOneApplicationSecretResource) exportApplicationSecretsByApplication // Expected behavior in this case is to skip the resource, and continue exporting the other resources defer response.Body.Close() - if err != nil { - l.Warn().Err(err).Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", appName, "ReadApplicationSecret", response.Status, response.Body) - return nil - } - - if response.StatusCode >= 300 { - l.Warn().Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", appName, "ReadApplicationSecret", response.Status, response.Body) - return nil - } - - r.addImportBlock(appId, appName) - - return nil -} - -func (r *PingOneApplicationSecretResource) addImportBlock(appId, appName string) { - commentData := map[string]string{ - "Application ID": appId, - "Application Name": appName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_secret", appName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, appId), - CommentInformation: common.GenerateCommentInformation(commentData), + if err != nil || response.StatusCode >= 300 || response.StatusCode < 200 { + l.Warn().Msgf("Failed to read secret for application %s. %s Response Code: %s\nResponse Body: %s", appId, "ReadApplicationSecret", response.Status, response.Body) } - *r.importBlocks = append(*r.importBlocks, importBlock) + return true, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go b/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go index 2b3861a0..aa25d523 100644 --- a/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_application_sign_on_policy_assignment.go @@ -14,15 +14,13 @@ var ( ) type PingOneApplicationSignOnPolicyAssignmentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneApplicationSignOnPolicyAssignmentResource func ApplicationSignOnPolicyAssignment(clientInfo *connector.PingOneClientInfo) *PingOneApplicationSignOnPolicyAssignmentResource { return &PingOneApplicationSignOnPolicyAssignmentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,66 @@ func (r *PingOneApplicationSignOnPolicyAssignmentResource) ExportAll() (*[]conne l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportApplicationSignOnPolicyAssignments() + importBlocks := []connector.ImportBlock{} + + applicationData, err := r.getApplicationData() if err != nil { return nil, err } - return r.importBlocks, nil + for appId, appName := range *applicationData { + signOnPolicyAssignmentData, err := r.getApplicationSignOnPolicyAssignmentData(appId) + if err != nil { + return nil, err + } + + for signOnPolicyAssignmentId, signOnPolicyId := range *signOnPolicyAssignmentData { + signOnPolicyName, err := r.getSignOnPolicyName(signOnPolicyId) + if err != nil { + return nil, err + } + + commentData := map[string]string{ + "Resource Type": r.ResourceType(), + "Application ID": appId, + "Application Name": appName, + "Application Sign-On Policy Assignment ID": signOnPolicyAssignmentId, + "Application Sign-On Policy Name": *signOnPolicyName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", appName, *signOnPolicyName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, signOnPolicyAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSignOnPolicyAssignments() error { +func (r *PingOneApplicationSignOnPolicyAssignmentResource) getApplicationData() (*map[string]string, error) { + applicationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationsApi.ReadAllApplications(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllApplications", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, app := range embedded.GetApplications() { @@ -83,33 +117,32 @@ func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSign } if appIdOk && appNameOk { - err := r.exportApplicationSignOnPolicyAssignmentsByApplication(*appId, *appName) - if err != nil { - return err - } + applicationData[*appId] = *appName } } } - return nil + return &applicationData, nil } -func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSignOnPolicyAssignmentsByApplication(appId, appName string) error { +func (r *PingOneApplicationSignOnPolicyAssignmentResource) getApplicationSignOnPolicyAssignmentData(appId string) (*map[string]string, error) { + signOnPolicyAssignmentData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ApplicationSignOnPolicyAssignmentsApi.ReadAllSignOnPolicyAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, appId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicyAssignments", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, signOnPolicyAssignment := range embedded.GetSignOnPolicyAssignments() { @@ -120,52 +153,29 @@ func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSign signOnPolicyAssignmentSignOnPolicyId, signOnPolicyAssignmentSignOnPolicyIdOk := signOnPolicyAssignmentSignOnPolicy.GetIdOk() if signOnPolicyAssignmentSignOnPolicyIdOk { - err := r.exportApplicationSignOnPolicyAssignmentsBySignOnPolicy(appId, appName, *signOnPolicyAssignmentId, *signOnPolicyAssignmentSignOnPolicyId) - if err != nil { - return err - } + signOnPolicyAssignmentData[*signOnPolicyAssignmentId] = *signOnPolicyAssignmentSignOnPolicyId } } } } - return nil + return &signOnPolicyAssignmentData, nil } -func (r *PingOneApplicationSignOnPolicyAssignmentResource) exportApplicationSignOnPolicyAssignmentsBySignOnPolicy(appId, appName, signOnPolicyAssignmentId, signOnPolicyId string) error { +func (r *PingOneApplicationSignOnPolicyAssignmentResource) getSignOnPolicyName(signOnPolicyId string) (*string, error) { signOnPolicy, response, err := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadOneSignOnPolicy(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, signOnPolicyId).Execute() err = common.HandleClientResponse(response, err, "ReadOneSignOnPolicy", r.ResourceType()) if err != nil { - return err + return nil, err } if signOnPolicy != nil { signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() if signOnPolicyNameOk { - r.addImportBlock(appId, appName, signOnPolicyAssignmentId, *signOnPolicyName) + return signOnPolicyName, nil } } - return nil -} - -func (r *PingOneApplicationSignOnPolicyAssignmentResource) addImportBlock(appId, appName, signOnPolicyAssignmentId, signOnPolicyName string) { - commentData := map[string]string{ - "Resource Type": r.ResourceType(), - "Application ID": appId, - "Application Name": appName, - "Application Sign-On Policy Assignment ID": signOnPolicyAssignmentId, - "Application Sign-On Policy Name": signOnPolicyName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", appName, signOnPolicyName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, appId, signOnPolicyAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("Unable to get sign-on policy name for sign-on policy ID: %s", signOnPolicyId) } diff --git a/internal/connector/pingone/sso/resources/pingone_group.go b/internal/connector/pingone/sso/resources/pingone_group.go index 55478878..04fb7527 100644 --- a/internal/connector/pingone/sso/resources/pingone_group.go +++ b/internal/connector/pingone/sso/resources/pingone_group.go @@ -14,15 +14,13 @@ var ( ) type PingOneGroupResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneGroupResource func Group(clientInfo *connector.PingOneClientInfo) *PingOneGroupResource { return &PingOneGroupResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneGroupResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportGroups() + importBlocks := []connector.ImportBlock{} + + groupData, err := r.getGroupData() if err != nil { return nil, err } - return r.importBlocks, nil + for groupId, groupName := range *groupData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Group ID": groupId, + "Group Name": groupName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: groupName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, groupId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneGroupResource) exportGroups() error { +func (r *PingOneGroupResource) getGroupData() (*map[string]string, error) { + groupData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGroups", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, group := range embedded.GetGroups() { @@ -65,28 +85,10 @@ func (r *PingOneGroupResource) exportGroups() error { groupName, groupNameOk := group.GetNameOk() if groupIdOk && groupNameOk { - r.addImportBlock(*groupId, *groupName) + groupData[*groupId] = *groupName } } } - return nil -} - -func (r *PingOneGroupResource) addImportBlock(groupId, groupName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Group ID": groupId, - "Group Name": groupName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: groupName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, groupId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &groupData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_group_nesting.go b/internal/connector/pingone/sso/resources/pingone_group_nesting.go index 25b2d860..97d463ab 100644 --- a/internal/connector/pingone/sso/resources/pingone_group_nesting.go +++ b/internal/connector/pingone/sso/resources/pingone_group_nesting.go @@ -14,15 +14,13 @@ var ( ) type PingOneGroupNestingResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneGroupNestingResource func GroupNesting(clientInfo *connector.PingOneClientInfo) *PingOneGroupNestingResource { return &PingOneGroupNestingResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,61 @@ func (r *PingOneGroupNestingResource) ExportAll() (*[]connector.ImportBlock, err l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportGroupNesting() + importBlocks := []connector.ImportBlock{} + + groupData, err := r.getGroupData() if err != nil { return nil, err } - return r.importBlocks, nil + for parentGroupId, parentGroupName := range *groupData { + groupNestingData, err := r.getGroupNestingData(parentGroupId) + if err != nil { + return nil, err + } + + for nestedGroupId, nestedGroupName := range *groupNestingData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Nested Group ID": nestedGroupId, + "Nested Group Name": nestedGroupName, + "Parent Group ID": parentGroupId, + "Parent Group Name": parentGroupName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", parentGroupName, nestedGroupName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, parentGroupId, nestedGroupId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneGroupNestingResource) exportGroupNesting() error { +func (r *PingOneGroupNestingResource) getGroupData() (*map[string]string, error) { + groupData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGroups", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, parentGroup := range embedded.GetGroups() { @@ -65,33 +94,32 @@ func (r *PingOneGroupNestingResource) exportGroupNesting() error { parentGroupName, parentGroupNameOk := parentGroup.GetNameOk() if parentGroupIdOk && parentGroupNameOk { - err := r.exportGroupNestingByParentGroup(*parentGroupId, *parentGroupName) - if err != nil { - return err - } + groupData[*parentGroupId] = *parentGroupName } } } - return nil + return &groupData, nil } -func (r *PingOneGroupNestingResource) exportGroupNestingByParentGroup(parentGroupId, parentGroupName string) error { +func (r *PingOneGroupNestingResource) getGroupNestingData(parentGroupId string) (*map[string]string, error) { + groupNestingData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadGroupNesting(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, parentGroupId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadGroupNesting", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, nestedGroup := range embedded.GetGroupMemberships() { @@ -99,30 +127,10 @@ func (r *PingOneGroupNestingResource) exportGroupNestingByParentGroup(parentGrou nestedGroupName, nestedGroupNameOk := nestedGroup.GetNameOk() if nestedGroupIdOk && nestedGroupNameOk { - r.addImportBlock(parentGroupId, parentGroupName, *nestedGroupId, *nestedGroupName) + groupNestingData[*nestedGroupId] = *nestedGroupName } } } - return nil -} - -func (r *PingOneGroupNestingResource) addImportBlock(parentGroupId, parentGroupName, nestedGroupId, nestedGroupName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Nested Group ID": nestedGroupId, - "Nested Group Name": nestedGroupName, - "Parent Group ID": parentGroupId, - "Parent Group Name": parentGroupName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", parentGroupName, nestedGroupName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, parentGroupId, nestedGroupId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &groupNestingData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go b/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go index 34621ceb..c51b1475 100644 --- a/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go +++ b/internal/connector/pingone/sso/resources/pingone_group_role_assignment.go @@ -3,6 +3,7 @@ package resources import ( "fmt" + "github.com/patrickcping/pingone-go-sdk-v2/management" "github.com/pingidentity/pingcli/internal/connector" "github.com/pingidentity/pingcli/internal/connector/common" "github.com/pingidentity/pingcli/internal/logger" @@ -14,15 +15,13 @@ var ( ) type PingOneGroupRoleAssignmentResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneGroupRoleAssignmentResource func GroupRoleAssignment(clientInfo *connector.PingOneClientInfo) *PingOneGroupRoleAssignmentResource { return &PingOneGroupRoleAssignmentResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +33,66 @@ func (r *PingOneGroupRoleAssignmentResource) ExportAll() (*[]connector.ImportBlo l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportGroupRoleAssignments() + importBlocks := []connector.ImportBlock{} + + groupData, err := r.getGroupData() if err != nil { return nil, err } - return r.importBlocks, nil + for groupId, groupName := range *groupData { + groupRoleAssignmentData, err := r.getGroupRoleAssignmentData(groupId) + if err != nil { + return nil, err + } + + for groupRoleAssignmentId, roleId := range *groupRoleAssignmentData { + roleName, err := r.getRoleName(roleId) + if err != nil { + return nil, err + } + + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Group ID": groupId, + "Group Name": groupName, + "Group Role Assignment ID": groupRoleAssignmentId, + "Group Role Name": string(*roleName), + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s_%s", groupName, string(*roleName), groupRoleAssignmentId), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, groupId, groupRoleAssignmentId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignments() error { +func (r *PingOneGroupRoleAssignmentResource) getGroupData() (*map[string]string, error) { + groupData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupsApi.ReadAllGroups(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllGroups", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, group := range embedded.GetGroups() { @@ -65,33 +100,32 @@ func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignments() error groupName, groupNameOk := group.GetNameOk() if groupIdOk && groupNameOk { - err := r.exportGroupRoleAssignmentsByGroup(*groupId, *groupName) - if err != nil { - return err - } + groupData[*groupId] = *groupName } } } - return nil + return &groupData, nil } -func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignmentsByGroup(groupId string, groupName string) error { +func (r *PingOneGroupRoleAssignmentResource) getGroupRoleAssignmentData(groupId string) (*map[string]string, error) { + groupRoleAssignmentData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.GroupRoleAssignmentsApi.ReadGroupRoleAssignments(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, groupId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadGroupRoleAssignments", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, groupRoleAssignment := range embedded.GetRoleAssignments() { @@ -100,52 +134,30 @@ func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignmentsByGroup(g if groupRoleAssignmentIdOk && groupRoleAssignmentRoleOk { groupRoleAssignmentRoleId, groupRoleAssignmentRoleIdOk := groupRoleAssignmentRole.GetIdOk() + if groupRoleAssignmentRoleIdOk { - err := r.exportGroupRoleAssignmentsByRole(groupId, groupName, *groupRoleAssignmentId, *groupRoleAssignmentRoleId) - if err != nil { - return err - } + groupRoleAssignmentData[*groupRoleAssignmentId] = *groupRoleAssignmentRoleId } } } } - return nil + return &groupRoleAssignmentData, nil } -func (r *PingOneGroupRoleAssignmentResource) exportGroupRoleAssignmentsByRole(groupId, groupName, groupRoleAssignmentId, roleId string) error { +func (r *PingOneGroupRoleAssignmentResource) getRoleName(roleId string) (*management.EnumRoleName, error) { apiRole, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, roleId).Execute() err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType()) if err != nil { - return err + return nil, err } if apiRole != nil { apiRoleName, apiRoleNameOk := apiRole.GetNameOk() if apiRoleNameOk { - r.addImportBlock(groupId, groupName, groupRoleAssignmentId, string(*apiRoleName)) + return apiRoleName, nil } } - return nil -} - -func (r *PingOneGroupRoleAssignmentResource) addImportBlock(groupId, groupName, groupRoleAssignmentId, roleName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Group ID": groupId, - "Group Name": groupName, - "Group Role Assignment ID": groupRoleAssignmentId, - "Group Role Name": roleName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s_%s", groupName, roleName, groupRoleAssignmentId), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, groupId, groupRoleAssignmentId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("unable to get role name for role ID: %s", roleId) } diff --git a/internal/connector/pingone/sso/resources/pingone_identity_provider.go b/internal/connector/pingone/sso/resources/pingone_identity_provider.go index 3ae9eb53..0bbe0782 100644 --- a/internal/connector/pingone/sso/resources/pingone_identity_provider.go +++ b/internal/connector/pingone/sso/resources/pingone_identity_provider.go @@ -14,15 +14,13 @@ var ( ) type PingOneIdentityProviderResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneIdentityProviderResource func IdentityProvider(clientInfo *connector.PingOneClientInfo) *PingOneIdentityProviderResource { return &PingOneIdentityProviderResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,33 +30,54 @@ func (r *PingOneIdentityProviderResource) ResourceType() string { func (r *PingOneIdentityProviderResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() - l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportIdentityProviders() + importBlocks := []connector.ImportBlock{} + + identityProviderData, err := r.getIdentityProviderData() if err != nil { return nil, err } - return r.importBlocks, nil + for idpId, idpName := range *identityProviderData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Identity Provider ID": idpId, + "Identity Provider Name": idpName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: idpName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, idpId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneIdentityProviderResource) exportIdentityProviders() error { +func (r *PingOneIdentityProviderResource) getIdentityProviderData() (*map[string]string, error) { + identityProviderData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllIdentityProviders", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, idp := range embedded.GetIdentityProviders() { @@ -93,28 +112,10 @@ func (r *PingOneIdentityProviderResource) exportIdentityProviders() error { } if idpIdOk && idpNameOk { - r.addImportBlock(*idpId, *idpName) + identityProviderData[*idpId] = *idpName } } } - return nil -} - -func (r *PingOneIdentityProviderResource) addImportBlock(idpId, idpName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Identity Provider ID": idpId, - "Identity Provider Name": idpName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: idpName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, idpId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &identityProviderData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go b/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go index e94fefb8..92f6342a 100644 --- a/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_identity_provider_attribute.go @@ -14,15 +14,13 @@ var ( ) type PingOneIdentityProviderAttributeResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneIdentityProviderAttributeResource func IdentityProviderAttribute(clientInfo *connector.PingOneClientInfo) *PingOneIdentityProviderAttributeResource { return &PingOneIdentityProviderAttributeResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -32,33 +30,63 @@ func (r *PingOneIdentityProviderAttributeResource) ResourceType() string { func (r *PingOneIdentityProviderAttributeResource) ExportAll() (*[]connector.ImportBlock, error) { l := logger.Get() - l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportIdentityProviderAttributes() + importBlocks := []connector.ImportBlock{} + + identityProviderData, err := r.getIdentityProviderData() if err != nil { return nil, err } - return r.importBlocks, nil + for idpId, idpName := range *identityProviderData { + identityProviderAttributeData, err := r.getIdentityProviderAttributeData(idpId) + if err != nil { + return nil, err + } + + for idpAttributeId, idpAttributeName := range *identityProviderAttributeData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Identity Provider Attribute ID": idpAttributeId, + "Identity Provider Attribute Name": idpAttributeName, + "Identity Provider ID": idpId, + "Identity Provider Name": idpName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", idpName, idpAttributeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, idpId, idpAttributeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneIdentityProviderAttributeResource) exportIdentityProviderAttributes() error { +func (r *PingOneIdentityProviderAttributeResource) getIdentityProviderData() (*map[string]string, error) { + identityProviderData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProvidersApi.ReadAllIdentityProviders(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllIdentityProviders", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, idp := range embedded.GetIdentityProviders() { @@ -93,33 +121,32 @@ func (r *PingOneIdentityProviderAttributeResource) exportIdentityProviderAttribu } if idpIdOk && idpNameOk { - err := r.exportIdentityProviderAttributesByIdentityProvider(*idpId, *idpName) - if err != nil { - return err - } + identityProviderData[*idpId] = *idpName } } } - return nil + return &identityProviderData, nil } -func (r *PingOneIdentityProviderAttributeResource) exportIdentityProviderAttributesByIdentityProvider(idpId, idpName string) error { +func (r *PingOneIdentityProviderAttributeResource) getIdentityProviderAttributeData(idpId string) (*map[string]string, error) { + identityProviderAttributeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.IdentityProviderAttributesApi.ReadAllIdentityProviderAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, idpId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllIdentityProviderAttributes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, idpAttribute := range embedded.GetAttributes() { @@ -127,30 +154,10 @@ func (r *PingOneIdentityProviderAttributeResource) exportIdentityProviderAttribu idpAttributeName, idpAttributeNameOk := idpAttribute.IdentityProviderAttribute.GetNameOk() if idpAttributeIdOk && idpAttributeNameOk { - r.addImportBlock(idpId, idpName, *idpAttributeName, *idpAttributeId) + identityProviderAttributeData[*idpAttributeId] = *idpAttributeName } } } - return nil -} - -func (r *PingOneIdentityProviderAttributeResource) addImportBlock(idpId, idpName, idpAttributeName, idpAttributeId string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Identity Provider Attribute ID": idpAttributeId, - "Identity Provider Attribute Name": idpAttributeName, - "Identity Provider ID": idpId, - "Identity Provider Name": idpName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", idpName, idpAttributeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, idpId, idpAttributeId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &identityProviderAttributeData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_password_policy.go b/internal/connector/pingone/sso/resources/pingone_password_policy.go index 8c3c6395..7cb74291 100644 --- a/internal/connector/pingone/sso/resources/pingone_password_policy.go +++ b/internal/connector/pingone/sso/resources/pingone_password_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOnePasswordPolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOnePasswordPolicyResource func PasswordPolicy(clientInfo *connector.PingOneClientInfo) *PingOnePasswordPolicyResource { return &PingOnePasswordPolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOnePasswordPolicyResource) ExportAll() (*[]connector.ImportBlock, e l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportPasswordPolicies() + importBlocks := []connector.ImportBlock{} + + passwordPolicyData, err := r.getPasswordPolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for passwordPolicyId, passwordPolicyName := range *passwordPolicyData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Password Policy ID": passwordPolicyId, + "Password Policy Name": passwordPolicyName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: passwordPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, passwordPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOnePasswordPolicyResource) exportPasswordPolicies() error { +func (r *PingOnePasswordPolicyResource) getPasswordPolicyData() (*map[string]string, error) { + passwordPolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.PasswordPoliciesApi.ReadAllPasswordPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPasswordPolicies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, passwordPolicy := range embedded.GetPasswordPolicies() { @@ -65,28 +85,10 @@ func (r *PingOnePasswordPolicyResource) exportPasswordPolicies() error { passwordPolicyName, passwordPolicyNameOk := passwordPolicy.GetNameOk() if passwordPolicyIdOk && passwordPolicyNameOk { - r.addImportBlock(*passwordPolicyId, *passwordPolicyName) + passwordPolicyData[*passwordPolicyId] = *passwordPolicyName } } } - return nil -} - -func (r *PingOnePasswordPolicyResource) addImportBlock(passwordPolicyId, passwordPolicyName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Password Policy ID": passwordPolicyId, - "Password Policy Name": passwordPolicyName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: passwordPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, passwordPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &passwordPolicyData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_population.go b/internal/connector/pingone/sso/resources/pingone_population.go index 1e6fe5e2..ce8f5728 100644 --- a/internal/connector/pingone/sso/resources/pingone_population.go +++ b/internal/connector/pingone/sso/resources/pingone_population.go @@ -14,15 +14,13 @@ var ( ) type PingOnePopulationResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOnePopulationResource func Population(clientInfo *connector.PingOneClientInfo) *PingOnePopulationResource { return &PingOnePopulationResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOnePopulationResource) ExportAll() (*[]connector.ImportBlock, error l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportPopulations() + importBlocks := []connector.ImportBlock{} + + populationData, err := r.getPopulationData() if err != nil { return nil, err } - return r.importBlocks, nil + for populationId, populationName := range *populationData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Population ID": populationId, + "Population Name": populationName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: populationName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, populationId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOnePopulationResource) exportPopulations() error { +func (r *PingOnePopulationResource) getPopulationData() (*map[string]string, error) { + populationData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPopulations", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, population := range embedded.GetPopulations() { @@ -65,28 +85,10 @@ func (r *PingOnePopulationResource) exportPopulations() error { populationName, populationNameOk := population.GetNameOk() if populationIdOk && populationNameOk { - r.addImportBlock(*populationId, *populationName) + populationData[*populationId] = *populationName } } } - return nil -} - -func (r *PingOnePopulationResource) addImportBlock(populationId, populationName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Population ID": populationId, - "Population Name": populationName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: populationName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, populationId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &populationData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_population_default.go b/internal/connector/pingone/sso/resources/pingone_population_default.go index 9403fe51..d995637b 100644 --- a/internal/connector/pingone/sso/resources/pingone_population_default.go +++ b/internal/connector/pingone/sso/resources/pingone_population_default.go @@ -14,15 +14,13 @@ var ( ) type PingOnePopulationDefaultResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOnePopulationDefaultResource func PopulationDefault(clientInfo *connector.PingOneClientInfo) *PingOnePopulationDefaultResource { return &PingOnePopulationDefaultResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,47 @@ func (r *PingOnePopulationDefaultResource) ExportAll() (*[]connector.ImportBlock l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportPopulationDefault() + importBlocks := []connector.ImportBlock{} + + defaultPopulationName, err := r.getDefaultPopulationName() if err != nil { return nil, err } - return r.importBlocks, nil + commentData := map[string]string{ + "Default Population Name": *defaultPopulationName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_population_default", *defaultPopulationName), + ResourceID: r.clientInfo.ExportEnvironmentID, + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + + return &importBlocks, nil } -func (r *PingOnePopulationDefaultResource) exportPopulationDefault() error { +func (r *PingOnePopulationDefaultResource) getDefaultPopulationName() (*string, error) { iter := r.clientInfo.ApiClient.ManagementAPIClient.PopulationsApi.ReadAllPopulations(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllPopulations", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, population := range embedded.GetPopulations() { @@ -67,28 +82,11 @@ func (r *PingOnePopulationDefaultResource) exportPopulationDefault() error { populationName, populationNameOk := population.GetNameOk() if populationNameOk { - r.addImportBlock(*populationName) + return populationName, nil } } } } - return nil -} - -func (r *PingOnePopulationDefaultResource) addImportBlock(populationName string) { - commentData := map[string]string{ - "Default Population Name": populationName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_population_default", populationName), - ResourceID: r.clientInfo.ExportEnvironmentID, - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return nil, fmt.Errorf("Unable to find the name of the default population") } diff --git a/internal/connector/pingone/sso/resources/pingone_resource.go b/internal/connector/pingone/sso/resources/pingone_resource.go index 85c8964e..6ea34150 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource.go +++ b/internal/connector/pingone/sso/resources/pingone_resource.go @@ -14,15 +14,13 @@ var ( ) type PingOneResourceResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneResourceResource func Resource(clientInfo *connector.PingOneClientInfo) *PingOneResourceResource { return &PingOneResourceResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneResourceResource) ExportAll() (*[]connector.ImportBlock, error) l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportResources() + importBlocks := []connector.ImportBlock{} + + resourceData, err := r.getResourceData() if err != nil { return nil, err } - return r.importBlocks, nil + for resourceId, resourceName := range *resourceData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource ID": resourceId, + "Resource Name": resourceName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: resourceName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneResourceResource) exportResources() error { +func (r *PingOneResourceResource) getResourceData() (*map[string]string, error) { + resourceData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, resourceInner := range embedded.GetResources() { @@ -66,29 +86,11 @@ func (r *PingOneResourceResource) exportResources() error { resourceName, resourceNameOk := resourceInner.Resource.GetNameOk() if resourceIdOk && resourceNameOk { - r.addImportBlock(*resourceId, *resourceName) + resourceData[*resourceId] = *resourceName } } } } - return nil -} - -func (r *PingOneResourceResource) addImportBlock(resourceId, resourceName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource ID": resourceId, - "Resource Name": resourceName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: resourceName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &resourceData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_attribute.go b/internal/connector/pingone/sso/resources/pingone_resource_attribute.go index b8829643..c0d29da3 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_attribute.go @@ -15,15 +15,13 @@ var ( ) type PingOneResourceAttributeResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneResourceAttributeResource func ResourceAttribute(clientInfo *connector.PingOneClientInfo) *PingOneResourceAttributeResource { return &PingOneResourceAttributeResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,64 @@ func (r *PingOneResourceAttributeResource) ExportAll() (*[]connector.ImportBlock l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportResourceAttributes() + importBlocks := []connector.ImportBlock{} + + resourceData, err := r.getResourceData() if err != nil { return nil, err } - return r.importBlocks, nil + for resourceId, resourceNameAndType := range *resourceData { + resourceName := resourceNameAndType[0] + resourceType := resourceNameAndType[1] + + resourceAttributeData, err := r.getResourceAttributeData(resourceId, resourceType) + if err != nil { + return nil, err + } + + for resourceAttributeId, resourceAttributeName := range *resourceAttributeData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Attribute ID": resourceAttributeId, + "Resource Attribute Name": resourceAttributeName, + "Resource ID": resourceId, + "Resource Name": resourceName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, resourceAttributeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, resourceId, resourceAttributeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneResourceAttributeResource) exportResourceAttributes() error { +func (r *PingOneResourceAttributeResource) getResourceData() (*map[string][]string, error) { + resourceData := make(map[string][]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, resourceInner := range embedded.GetResources() { @@ -68,34 +100,33 @@ func (r *PingOneResourceAttributeResource) exportResourceAttributes() error { resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() if resourceIdOk && resourceNameOk && resourceTypeOk { - err := r.exportResourceAttributeByResource(*resourceId, *resourceName, *resourceType) - if err != nil { - return err - } + resourceData[*resourceId] = []string{*resourceName, string(*resourceType)} } } } } - return nil + return &resourceData, nil } -func (r *PingOneResourceAttributeResource) exportResourceAttributeByResource(resourceId, resourceName string, resourceType management.EnumResourceType) error { +func (r *PingOneResourceAttributeResource) getResourceAttributeData(resourceId string, resourceType string) (*map[string]string, error) { + resourceAttributeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceAttributesApi.ReadAllResourceAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceAttributes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, attributeInner := range embedded.GetAttributes() { @@ -109,7 +140,7 @@ func (r *PingOneResourceAttributeResource) exportResourceAttributeByResource(res // Do not export CORE attributes // There is one exception where a CUSTOM resource can override the sub CORE attribute if *resourceAttributeType == management.ENUMRESOURCEATTRIBUTETYPE_CORE { - if resourceType == management.ENUMRESOURCETYPE_CUSTOM { + if resourceType == string(management.ENUMRESOURCETYPE_CUSTOM) { // Skip export of all CORE attributes except for the sub attribute for CUSTOM resources if *resourceAttributeName != "sub" { continue @@ -120,31 +151,11 @@ func (r *PingOneResourceAttributeResource) exportResourceAttributeByResource(res } } - r.addImportBlock(resourceId, resourceName, *resourceAttributeId, *resourceAttributeName) + resourceAttributeData[*resourceAttributeId] = *resourceAttributeName } } } } - return nil -} - -func (r *PingOneResourceAttributeResource) addImportBlock(resourceId, resourceName, resourceAttributeId, resourceAttributeName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Attribute ID": resourceAttributeId, - "Resource Attribute Name": resourceAttributeName, - "Resource ID": resourceId, - "Resource Name": resourceName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", resourceName, resourceAttributeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, resourceId, resourceAttributeId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &resourceAttributeData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_scope.go b/internal/connector/pingone/sso/resources/pingone_resource_scope.go index fdcc3883..d9753841 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_scope.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_scope.go @@ -15,15 +15,13 @@ var ( ) type PingOneResourceScopeResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneResourceScopeResource func ResourceScope(clientInfo *connector.PingOneClientInfo) *PingOneResourceScopeResource { return &PingOneResourceScopeResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,61 @@ func (r *PingOneResourceScopeResource) ExportAll() (*[]connector.ImportBlock, er l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportResourceScopes() + importBlocks := []connector.ImportBlock{} + + resourceData, err := r.getResourceData() if err != nil { return nil, err } - return r.importBlocks, nil + for resourceId, resourceName := range *resourceData { + resourceScopeData, err := r.getResourceScopeData(resourceId) + if err != nil { + return nil, err + } + + for resourceScopeId, resourceScopeName := range *resourceScopeData { + commentData := map[string]string{ + "Custom Resource ID": resourceId, + "Custom Resource Name": resourceName, + "Custom Resource Scope ID": resourceScopeId, + "Custom Resource Scope Name": resourceScopeName, + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, resourceScopeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, resourceId, resourceScopeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneResourceScopeResource) exportResourceScopes() error { +func (r *PingOneResourceScopeResource) getResourceData() (*map[string]string, error) { + resourceData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, resourceInner := range embedded.GetResources() { @@ -68,64 +97,43 @@ func (r *PingOneResourceScopeResource) exportResourceScopes() error { resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_CUSTOM { - err := r.exportResourceScopesByResource(*resourceId, *resourceName) - if err != nil { - return err - } + resourceData[*resourceId] = *resourceName } } } } - return nil + return &resourceData, nil } -func (r *PingOneResourceScopeResource) exportResourceScopesByResource(resourceId, resourceName string) error { +func (r *PingOneResourceScopeResource) getResourceScopeData(resourceId string) (*map[string]string, error) { + resourceScopeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceScopes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, scope := range embedded.GetScopes() { scopeId, scopeIdOk := scope.GetIdOk() scopeName, scopeNameOk := scope.GetNameOk() if scopeIdOk && scopeNameOk { - r.addImportBlock(resourceId, resourceName, *scopeId, *scopeName) + resourceScopeData[*scopeId] = *scopeName } } } - return nil -} - -func (r *PingOneResourceScopeResource) addImportBlock(resourceId, resourceName, scopeId, scopeName string) { - commentData := map[string]string{ - "Custom Resource ID": resourceId, - "Custom Resource Name": resourceName, - "Custom Resource Scope ID": scopeId, - "Custom Resource Scope Name": scopeName, - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", resourceName, scopeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, resourceId, scopeId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &resourceScopeData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go b/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go index b9fec723..ff04507a 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_scope_openid.go @@ -15,15 +15,13 @@ var ( ) type PingOneResourceScopeOpenIdResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneResourceScopeOpenIdResource func ResourceScopeOpenId(clientInfo *connector.PingOneClientInfo) *PingOneResourceScopeOpenIdResource { return &PingOneResourceScopeOpenIdResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,60 @@ func (r *PingOneResourceScopeOpenIdResource) ExportAll() (*[]connector.ImportBlo l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportResourceScopeOpenIds() + importBlocks := []connector.ImportBlock{} + + resourceData, err := r.getResourceData() if err != nil { return nil, err } - return r.importBlocks, nil + for resourceId, resourceName := range *resourceData { + resourceScopeData, err := r.getResourceScopeData(resourceId) + if err != nil { + return nil, err + } + + for resourceScopeId, resourceScopeName := range *resourceScopeData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "OpenID Connect Resource Name": resourceName, + "OpenID Connect Resource Scope ID": resourceScopeId, + "OpenID Connect Resource Scope Name": resourceScopeName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, resourceScopeName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceScopeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneResourceScopeOpenIdResource) exportResourceScopeOpenIds() error { +func (r *PingOneResourceScopeOpenIdResource) getResourceData() (*map[string]string, error) { + resourceData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, resourceInner := range embedded.GetResources() { @@ -68,63 +96,44 @@ func (r *PingOneResourceScopeOpenIdResource) exportResourceScopeOpenIds() error resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_OPENID_CONNECT { - err := r.exportResourceScopeOpenIdByResource(*resourceId, *resourceName) - if err != nil { - return err - } + resourceData[*resourceId] = *resourceName } } } } - return nil + return &resourceData, nil } -func (r *PingOneResourceScopeOpenIdResource) exportResourceScopeOpenIdByResource(resourceId, resourceName string) error { +func (r *PingOneResourceScopeOpenIdResource) getResourceScopeData(resourceId string) (*map[string]string, error) { + resourceScopeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceScopes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, scopeOpenId := range embedded.GetScopes() { scopeOpenIdId, scopeOpenIdIdOk := scopeOpenId.GetIdOk() scopeOpenIdName, scopeOpenIdNameOk := scopeOpenId.GetNameOk() + if scopeOpenIdIdOk && scopeOpenIdNameOk { - r.addImportBlock(resourceName, *scopeOpenIdId, *scopeOpenIdName) + resourceScopeData[*scopeOpenIdId] = *scopeOpenIdName } } } - return nil -} - -func (r *PingOneResourceScopeOpenIdResource) addImportBlock(resourceName, scopeOpenIdId, scopeOpenIdName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "OpenID Connect Resource Name": resourceName, - "OpenID Connect Resource Scope ID": scopeOpenIdId, - "OpenID Connect Resource Scope Name": scopeOpenIdName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", resourceName, scopeOpenIdName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, scopeOpenIdId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &resourceScopeData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go b/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go index b58f8629..8226a7fa 100644 --- a/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go +++ b/internal/connector/pingone/sso/resources/pingone_resource_scope_pingone_api.go @@ -16,15 +16,13 @@ var ( ) type PingOneResourceScopePingOneApiResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneResourceScopePingOneApiResource func ResourceScopePingOneApi(clientInfo *connector.PingOneClientInfo) *PingOneResourceScopePingOneApiResource { return &PingOneResourceScopePingOneApiResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -36,30 +34,60 @@ func (r *PingOneResourceScopePingOneApiResource) ExportAll() (*[]connector.Impor l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportResourceScopePingOneApis() + importBlocks := []connector.ImportBlock{} + + resourceData, err := r.getResourceData() if err != nil { return nil, err } - return r.importBlocks, nil + for resourceId, resourceName := range *resourceData { + resourceScopeData, err := r.getResourceScopeData(resourceId) + if err != nil { + return nil, err + } + + for resourceScopeId, resourceScopeName := range *resourceScopeData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "PingOne API Resource Name": resourceName, + "PingOne API Resource Scope ID": resourceScopeId, + "PingOne API Resource Scope Name": resourceScopeName, + "Resource Type": r.ResourceType(), + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", resourceName, resourceScopeName), + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, resourceScopeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneResourceScopePingOneApiResource) exportResourceScopePingOneApis() error { +func (r *PingOneResourceScopePingOneApiResource) getResourceData() (*map[string]string, error) { + resourceData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourcesApi.ReadAllResources(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResources", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, resourceInner := range embedded.GetResources() { @@ -69,34 +97,33 @@ func (r *PingOneResourceScopePingOneApiResource) exportResourceScopePingOneApis( resourceType, resourceTypeOk := resourceInner.Resource.GetTypeOk() if resourceIdOk && resourceNameOk && resourceTypeOk && *resourceType == management.ENUMRESOURCETYPE_PINGONE_API { - err := r.exportResourceScopePingOneApiByResource(*resourceId, *resourceName) - if err != nil { - return err - } + resourceData[*resourceId] = *resourceName } } } } - return nil + return &resourceData, nil } -func (r *PingOneResourceScopePingOneApiResource) exportResourceScopePingOneApiByResource(resourceId, resourceName string) error { +func (r *PingOneResourceScopePingOneApiResource) getResourceScopeData(resourceId string) (*map[string]string, error) { + resourceScopeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.ResourceScopesApi.ReadAllResourceScopes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, resourceId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllResourceScopes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, scopePingOneApi := range embedded.GetScopes() { @@ -110,30 +137,11 @@ func (r *PingOneResourceScopePingOneApiResource) exportResourceScopePingOneApiBy re := regexp.MustCompile(`^p1:(read|update):user(|:.+)$`) if re.MatchString(*scopePingOneApiName) { - r.addImportBlock(resourceName, *scopePingOneApiId, *scopePingOneApiName) + resourceScopeData[*scopePingOneApiId] = *scopePingOneApiName } } } } - return nil -} - -func (r *PingOneResourceScopePingOneApiResource) addImportBlock(resourceName, scopePingOneApiId, scopePingOneApiName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "PingOne API Resource Name": resourceName, - "PingOne API Resource Scope ID": scopePingOneApiId, - "PingOne API Resource Scope Name": scopePingOneApiName, - "Resource Type": r.ResourceType(), - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", resourceName, scopePingOneApiName), - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, scopePingOneApiId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &resourceScopeData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_schema_attribute.go b/internal/connector/pingone/sso/resources/pingone_schema_attribute.go index def09608..9c7de31a 100644 --- a/internal/connector/pingone/sso/resources/pingone_schema_attribute.go +++ b/internal/connector/pingone/sso/resources/pingone_schema_attribute.go @@ -14,15 +14,13 @@ var ( ) type PingOneSchemaAttributeResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneSchemaAttributeResource func SchemaAttribute(clientInfo *connector.PingOneClientInfo) *PingOneSchemaAttributeResource { return &PingOneSchemaAttributeResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,93 +32,103 @@ func (r *PingOneSchemaAttributeResource) ExportAll() (*[]connector.ImportBlock, l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportSchemaAttributes() + importBlocks := []connector.ImportBlock{} + + schemaData, err := r.getSchemaData() if err != nil { return nil, err } - return r.importBlocks, nil + for schemaId, schemaName := range *schemaData { + schemaAttributeData, err := r.getSchemaAttributeData(schemaId) + if err != nil { + return nil, err + } + + for schemaAttributeId, schemaAttributeName := range *schemaAttributeData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Schema Attribute ID": schemaAttributeId, + "Schema Attribute Name": schemaAttributeName, + "Schema ID": schemaId, + "Schema Name": schemaName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", schemaName, schemaAttributeName), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, schemaId, schemaAttributeId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneSchemaAttributeResource) exportSchemaAttributes() error { +func (r *PingOneSchemaAttributeResource) getSchemaData() (*map[string]string, error) { + schemaData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.SchemasApi.ReadAllSchemas(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSchemas", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, schema := range embedded.GetSchemas() { schemaId, schemaIdOk := schema.GetIdOk() schemaName, schemaNameOk := schema.GetNameOk() if schemaIdOk && schemaNameOk { - err := r.exportSchemaAttributesBySchema(*schemaId, *schemaName) - if err != nil { - return err - } + schemaData[*schemaId] = *schemaName } } } - return nil + return &schemaData, nil } -func (r *PingOneSchemaAttributeResource) exportSchemaAttributesBySchema(schemaId, schemaName string) error { +func (r *PingOneSchemaAttributeResource) getSchemaAttributeData(schemaId string) (*map[string]string, error) { + schemaAttributeData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.SchemasApi.ReadAllSchemaAttributes(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, schemaId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSchemaAttributes", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, schemaAttribute := range embedded.GetAttributes() { schemaAttributeId, schemaAttributeIdOk := schemaAttribute.SchemaAttribute.GetIdOk() schemaAttributeName, schemaAttributeNameOk := schemaAttribute.SchemaAttribute.GetNameOk() if schemaAttributeIdOk && schemaAttributeNameOk { - r.addImportBlock(schemaId, schemaName, *schemaAttributeId, *schemaAttributeName) + schemaAttributeData[*schemaAttributeId] = *schemaAttributeName } } } - return nil -} - -func (r *PingOneSchemaAttributeResource) addImportBlock(schemaId, schemaName, schemaAttributeId, schemaAttributeName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Schema Attribute ID": schemaAttributeId, - "Schema Attribute Name": schemaAttributeName, - "Schema ID": schemaId, - "Schema Name": schemaName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", schemaName, schemaAttributeName), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, schemaId, schemaAttributeId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &schemaAttributeData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go b/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go index 7bc1773b..eaa7e9e0 100644 --- a/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go +++ b/internal/connector/pingone/sso/resources/pingone_sign_on_policy.go @@ -14,15 +14,13 @@ var ( ) type PingOneSignOnPolicyResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneSignOnPolicyResource func SignOnPolicy(clientInfo *connector.PingOneClientInfo) *PingOneSignOnPolicyResource { return &PingOneSignOnPolicyResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -34,30 +32,52 @@ func (r *PingOneSignOnPolicyResource) ExportAll() (*[]connector.ImportBlock, err l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportSignOnPolicies() + importBlocks := []connector.ImportBlock{} + + signOnPolicyData, err := r.getSignOnPolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for signOnPolicyId, signOnPolicyName := range *signOnPolicyData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Sign-On Policy ID": signOnPolicyId, + "Sign-On Policy Name": signOnPolicyName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: signOnPolicyName, + ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, signOnPolicyId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + + return &importBlocks, nil } -func (r *PingOneSignOnPolicyResource) exportSignOnPolicies() error { +func (r *PingOneSignOnPolicyResource) getSignOnPolicyData() (*map[string]string, error) { + signOnPolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadAllSignOnPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, signOnPolicy := range embedded.GetSignOnPolicies() { @@ -65,28 +85,10 @@ func (r *PingOneSignOnPolicyResource) exportSignOnPolicies() error { signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() if signOnPolicyIdOk && signOnPolicyNameOk { - r.addImportBlock(*signOnPolicyId, *signOnPolicyName) + signOnPolicyData[*signOnPolicyId] = *signOnPolicyName } } } - return nil -} - -func (r *PingOneSignOnPolicyResource) addImportBlock(signOnPolicyId, signOnPolicyName string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Sign-On Policy ID": signOnPolicyId, - "Sign-On Policy Name": signOnPolicyName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: signOnPolicyName, - ResourceID: fmt.Sprintf("%s/%s", r.clientInfo.ExportEnvironmentID, signOnPolicyId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &signOnPolicyData, nil } diff --git a/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go b/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go index 268b0e02..82cbffb7 100644 --- a/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go +++ b/internal/connector/pingone/sso/resources/pingone_sign_on_policy_action.go @@ -15,15 +15,13 @@ var ( ) type PingOneSignOnPolicyActionResource struct { - clientInfo *connector.PingOneClientInfo - importBlocks *[]connector.ImportBlock + clientInfo *connector.PingOneClientInfo } // Utility method for creating a PingOneSignOnPolicyActionResource func SignOnPolicyAction(clientInfo *connector.PingOneClientInfo) *PingOneSignOnPolicyActionResource { return &PingOneSignOnPolicyActionResource{ - clientInfo: clientInfo, - importBlocks: &[]connector.ImportBlock{}, + clientInfo: clientInfo, } } @@ -35,30 +33,61 @@ func (r *PingOneSignOnPolicyActionResource) ExportAll() (*[]connector.ImportBloc l := logger.Get() l.Debug().Msgf("Exporting all '%s' Resources...", r.ResourceType()) - err := r.exportSignOnPolicyActions() + importBlocks := []connector.ImportBlock{} + + signOnPolicyData, err := r.getSignOnPolicyData() if err != nil { return nil, err } - return r.importBlocks, nil + for signOnPolicyId, signOnPolicyName := range *signOnPolicyData { + signOnPolicyActionData, err := r.getSignOnPolicyActionData(signOnPolicyId) + if err != nil { + return nil, err + } + + for actionId, actionType := range *signOnPolicyActionData { + commentData := map[string]string{ + "Export Environment ID": r.clientInfo.ExportEnvironmentID, + "Resource Type": r.ResourceType(), + "Sign-On Policy Action ID": actionId, + "Sign-On Policy Action Type": actionType, + "Sign-On Policy ID": signOnPolicyId, + "Sign-On Policy Name": signOnPolicyName, + } + + importBlock := connector.ImportBlock{ + ResourceType: r.ResourceType(), + ResourceName: fmt.Sprintf("%s_%s", signOnPolicyName, actionType), + ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, signOnPolicyId, actionId), + CommentInformation: common.GenerateCommentInformation(commentData), + } + + importBlocks = append(importBlocks, importBlock) + } + } + + return &importBlocks, nil } -func (r *PingOneSignOnPolicyActionResource) exportSignOnPolicyActions() error { +func (r *PingOneSignOnPolicyActionResource) getSignOnPolicyData() (*map[string]string, error) { + signOnPolicyData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPoliciesApi.ReadAllSignOnPolicies(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicies", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, signOnPolicy := range embedded.GetSignOnPolicies() { @@ -66,33 +95,32 @@ func (r *PingOneSignOnPolicyActionResource) exportSignOnPolicyActions() error { signOnPolicyName, signOnPolicyNameOk := signOnPolicy.GetNameOk() if signOnPolicyIdOk && signOnPolicyNameOk { - err := r.exportSignOnPolicyActionsBySignOnPolicy(*signOnPolicyId, *signOnPolicyName) - if err != nil { - return err - } + signOnPolicyData[*signOnPolicyId] = *signOnPolicyName } } } - return nil + return &signOnPolicyData, nil } -func (r *PingOneSignOnPolicyActionResource) exportSignOnPolicyActionsBySignOnPolicy(signOnPolicyId, signOnPolicyName string) error { +func (r *PingOneSignOnPolicyActionResource) getSignOnPolicyActionData(signOnPolicyId string) (*map[string]string, error) { + signOnPolicyActionData := make(map[string]string) + iter := r.clientInfo.ApiClient.ManagementAPIClient.SignOnPolicyActionsApi.ReadAllSignOnPolicyActions(r.clientInfo.Context, r.clientInfo.ExportEnvironmentID, signOnPolicyId).Execute() for cursor, err := range iter { err = common.HandleClientResponse(cursor.HTTPResponse, err, "ReadAllSignOnPolicyActions", r.ResourceType()) if err != nil { - return err + return nil, err } if cursor.EntityArray == nil { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } embedded, embeddedOk := cursor.EntityArray.GetEmbeddedOk() if !embeddedOk { - return common.DataNilError(r.ResourceType(), cursor.HTTPResponse) + return nil, common.DataNilError(r.ResourceType(), cursor.HTTPResponse) } for _, action := range embedded.GetActions() { @@ -130,30 +158,10 @@ func (r *PingOneSignOnPolicyActionResource) exportSignOnPolicyActionsBySignOnPol } if actionIdOk && actionTypeOk { - r.addImportBlock(signOnPolicyId, signOnPolicyName, *actionId, string(*actionType)) + signOnPolicyActionData[*actionId] = string(*actionType) } } } - return nil -} - -func (r *PingOneSignOnPolicyActionResource) addImportBlock(signOnPolicyId, signOnPolicyName, actionId, actionType string) { - commentData := map[string]string{ - "Export Environment ID": r.clientInfo.ExportEnvironmentID, - "Resource Type": r.ResourceType(), - "Sign-On Policy Action ID": actionId, - "Sign-On Policy Action Type": actionType, - "Sign-On Policy ID": signOnPolicyId, - "Sign-On Policy Name": signOnPolicyName, - } - - importBlock := connector.ImportBlock{ - ResourceType: r.ResourceType(), - ResourceName: fmt.Sprintf("%s_%s", signOnPolicyName, actionType), - ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, signOnPolicyId, actionId), - CommentInformation: common.GenerateCommentInformation(commentData), - } - - *r.importBlocks = append(*r.importBlocks, importBlock) + return &signOnPolicyActionData, nil } From e8ffa33121854b3a17e70471da20c1cc0c0da3d5 Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Thu, 12 Dec 2024 11:19:00 -0700 Subject: [PATCH 9/9] Upgrade dependencies --- go.mod | 26 +++++++++++----------- go.sum | 68 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/go.mod b/go.mod index 48b9dd84..0a1264db 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/GaijinEntertainment/go-exhaustruct/v3 v3.3.0 // indirect github.com/Masterminds/semver/v3 v3.3.1 // indirect github.com/OpenPeeDeeP/depguard/v2 v2.2.0 // indirect - github.com/alecthomas/go-check-sumtype v0.2.0 // indirect + github.com/alecthomas/go-check-sumtype v0.3.0 // 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 @@ -53,7 +53,7 @@ require ( github.com/charithe/durationcheck v0.0.10 // indirect github.com/chavacava/garif v0.1.0 // indirect github.com/chzyer/readline v1.5.1 // indirect - github.com/ckaznocha/intrange v0.2.1 // indirect + github.com/ckaznocha/intrange v0.3.0 // indirect github.com/curioswitch/go-reassign v0.3.0 // indirect github.com/daixiang0/gci v0.13.5 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -110,10 +110,10 @@ require ( github.com/lasiar/canonicalheader v1.1.2 // indirect github.com/ldez/gomoddirectives v0.6.0 // indirect github.com/ldez/grignotin v0.6.0 // indirect - github.com/ldez/tagliatelle v0.6.0 // indirect + github.com/ldez/tagliatelle v0.7.1 // indirect github.com/leonklingele/grouper v1.1.2 // indirect github.com/macabu/inamedparam v0.1.3 // indirect - github.com/magiconair/properties v1.8.7 // indirect + github.com/magiconair/properties v1.8.9 // indirect github.com/maratori/testableexamples v1.0.0 // indirect github.com/maratori/testpackage v1.1.1 // indirect github.com/matoous/godox v0.0.0-20241202171805-94d1edd68ebb // indirect @@ -128,7 +128,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.18.3 // indirect + github.com/nunnatsa/ginkgolinter v0.18.4 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/patrickcping/pingone-go-sdk-v2/authorize v0.7.0 // indirect github.com/patrickcping/pingone-go-sdk-v2/credentials v0.10.0 // indirect @@ -139,7 +139,7 @@ require ( github.com/polyfloyd/go-errorlint v1.7.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.1 // indirect + github.com/prometheus/common v0.61.0 // 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 @@ -180,7 +180,7 @@ require ( github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect github.com/ultraware/funlen v0.1.0 // indirect github.com/ultraware/whitespace v0.1.1 // indirect - github.com/uudashr/gocognit v1.1.3 // indirect + github.com/uudashr/gocognit v1.2.0 // indirect github.com/uudashr/iface v1.3.0 // indirect github.com/xen0n/gosmopolitan v1.2.2 // indirect github.com/yagipy/maintidx v1.0.0 // indirect @@ -192,14 +192,14 @@ require ( go.uber.org/automaxprocs v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect - golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect + golang.org/x/exp v0.0.0-20241210194714-1829a127f884 // indirect + golang.org/x/exp/typeparams v0.0.0-20241210194714-1829a127f884 // indirect golang.org/x/mod v0.22.0 // indirect golang.org/x/oauth2 v0.24.0 // indirect - golang.org/x/sync v0.9.0 // indirect - golang.org/x/sys v0.27.0 // indirect - golang.org/x/text v0.20.0 // indirect - golang.org/x/tools v0.27.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + golang.org/x/tools v0.28.0 // indirect google.golang.org/protobuf v1.35.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index a1205d16..2be5e676 100644 --- a/go.sum +++ b/go.sum @@ -24,12 +24,12 @@ github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7r github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJPdp74zmpA= github.com/OpenPeeDeeP/depguard/v2 v2.2.0/go.mod h1:CIzddKRvLBC4Au5aYP/i3nyaWQ+ClszLIuVocRiCYFQ= -github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk= -github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= -github.com/alecthomas/go-check-sumtype v0.2.0 h1:Bo+e4DFf3rs7ME9w/0SU/g6nmzJaphduP8Cjiz0gbwY= -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/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= +github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/go-check-sumtype v0.3.0 h1:yOw5oYjpa5eyKNztSfUr2xk2nvUrx7cUjFMbm6puybc= +github.com/alecthomas/go-check-sumtype v0.3.0/go.mod h1:I5AdgQAzhonsD7Bu2UYq8cjS8pzVML1gb3q8mcg/rpQ= +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= 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= @@ -75,8 +75,8 @@ github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObk github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= -github.com/ckaznocha/intrange v0.2.1 h1:M07spnNEQoALOJhwrImSrJLaxwuiQK+hA2DeajBlwYk= -github.com/ckaznocha/intrange v0.2.1/go.mod h1:7NEhVyf8fzZO5Ds7CRaqPEm52Ut83hsTiL5zbER/HYk= +github.com/ckaznocha/intrange v0.3.0 h1:VqnxtK32pxgkhJgYQEeOArVidIPg+ahLP7WBOXZd5ZY= +github.com/ckaznocha/intrange v0.3.0/go.mod h1:+I/o2d2A1FBHgGELbGxzIcyd3/9l9DuwjM8FsbSS3Lo= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/curioswitch/go-reassign v0.3.0 h1:dh3kpQHuADL3cobV/sSGETA8DOv457dwl+fbBAhrQPs= @@ -181,8 +181,8 @@ github.com/gostaticanalysis/forcetypeassert v0.1.0/go.mod h1:qZEedyP/sY1lTGV1uJ3 github.com/gostaticanalysis/nilerr v0.1.1 h1:ThE+hJP0fEp4zWLkWHWcRyI2Od0p7DlgYG3Uqrmrcpk= github.com/gostaticanalysis/nilerr v0.1.1/go.mod h1:wZYb6YI5YAxxq0i1+VJbY0s2YONW0HU0GPE3+5PWN4A= github.com/gostaticanalysis/testutil v0.3.1-0.20210208050101-bfb5c8eec0e4/go.mod h1:D+FIZ+7OahH3ePw/izIEeH5I06eKs1IKI4Xr64/Am3M= -github.com/gostaticanalysis/testutil v0.4.0 h1:nhdCmubdmDF6VEatUNjgUZBJKWRqugoISdUv3PPQgHY= -github.com/gostaticanalysis/testutil v0.4.0/go.mod h1:bLIoPefWXrRi/ssLFWX1dx7Repi5x3CuviD3dgAZaBU= +github.com/gostaticanalysis/testutil v0.5.0 h1:Dq4wT1DdTwTGCQQv3rl3IvD5Ld0E6HiY+3Zh0sUGqw8= +github.com/gostaticanalysis/testutil v0.5.0/go.mod h1:OLQSbuM6zw2EvCcXTz1lVq5unyoNft372msDY0nY5Hs= github.com/hashicorp/go-immutable-radix/v2 v2.1.0 h1:CUW5RYIcysz+D3B+l1mDeXrQ7fUvGGCwJfdASSzbrfo= github.com/hashicorp/go-immutable-radix/v2 v2.1.0/go.mod h1:hgdqLXA4f6NIjRVisM1TJ9aOJVNRqKZj+xDGF6m7PBw= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= @@ -232,14 +232,14 @@ github.com/ldez/gomoddirectives v0.6.0 h1:Jyf1ZdTeiIB4dd+2n4qw+g4aI9IJ6JyfOZ8Bit github.com/ldez/gomoddirectives v0.6.0/go.mod h1:TuwOGYoPAoENDWQpe8DMqEm5nIfjrxZXmxX/CExWyZ4= github.com/ldez/grignotin v0.6.0 h1:i++3002hxD5TpVto0iLjLrfz1V+yEJ+BBk4glb3aqC8= github.com/ldez/grignotin v0.6.0/go.mod h1:uaVTr0SoZ1KBii33c47O1M8Jp3OP3YDwhZCmzT9GHEk= -github.com/ldez/tagliatelle v0.6.0 h1:1Muumft/shmQ0x96vA6a/OUgTjamRt8jUlZPLm1ruwA= -github.com/ldez/tagliatelle v0.6.0/go.mod h1:WeZ7TgEqq7fw/0Zj8BuQhh4+4KX1/+g0O11eygvClRA= +github.com/ldez/tagliatelle v0.7.1 h1:bTgKjjc2sQcsgPiT902+aadvMjCeMHrY7ly2XKFORIk= +github.com/ldez/tagliatelle v0.7.1/go.mod h1:3zjxUpsNB2aEZScWiZTHrAXOl1x25t3cRmzfK1mlo2I= github.com/leonklingele/grouper v1.1.2 h1:o1ARBDLOmmasUaNDesWqWCIFH3u7hoFlM84YrjT3mIY= github.com/leonklingele/grouper v1.1.2/go.mod h1:6D0M/HVkhs2yRKRFZUoGjeDy7EZTfFBE9gl4kjmIGkA= github.com/macabu/inamedparam v0.1.3 h1:2tk/phHkMlEL/1GNe/Yf6kkR/hkcUdAEY3L0hjYV1Mk= github.com/macabu/inamedparam v0.1.3/go.mod h1:93FLICAIk/quk7eaPPQvbzihUdn/QkGDwIZEoLtpH6I= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= +github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= @@ -275,8 +275,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.18.3 h1:WgS7X3zzmni3vwHSBhvSgqrRgUecN6PQUcfB0j1noDw= -github.com/nunnatsa/ginkgolinter v0.18.3/go.mod h1:BE1xyB/PNtXXG1azrvrqJW5eFH0hSRylNzFy8QHPwzs= +github.com/nunnatsa/ginkgolinter v0.18.4 h1:zmX4KUR+6fk/vhUFt8DOP6KwznekhkmVSzzVJve2vyM= +github.com/nunnatsa/ginkgolinter v0.18.4/go.mod h1:AMEane4QQ6JwFz5GgjI5xLUM9S/CylO+UyM97fN2iBI= 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= @@ -322,8 +322,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.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc= -github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/common v0.61.0 h1:3gv/GThfX0cV2lpO7gkTUwZru38mxevy90Bj8YFSRQQ= +github.com/prometheus/common v0.61.0/go.mod h1:zr29OCN/2BsJRaFwG8QOBr41D6kkchKbpeNH7pAjb/s= 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= @@ -431,8 +431,8 @@ github.com/ultraware/funlen v0.1.0 h1:BuqclbkY6pO+cvxoq7OsktIXZpgBSkYTQtmwhAK81v github.com/ultraware/funlen v0.1.0/go.mod h1:XJqmOQja6DpxarLj6Jj1U7JuoS8PvL4nEqDaQhy22p4= github.com/ultraware/whitespace v0.1.1 h1:bTPOGejYFulW3PkcrqkeQwOd6NKOOXvmGD9bo/Gk8VQ= github.com/ultraware/whitespace v0.1.1/go.mod h1:XcP1RLD81eV4BW8UhQlpaR+SDc2givTvyI8a586WjW8= -github.com/uudashr/gocognit v1.1.3 h1:l+a111VcDbKfynh+airAy/DJQKaXh2m9vkoysMPSZyM= -github.com/uudashr/gocognit v1.1.3/go.mod h1:aKH8/e8xbTRBwjbCkwZ8qt4l2EpKXl31KMHgSS+lZ2U= +github.com/uudashr/gocognit v1.2.0 h1:3BU9aMr1xbhPlvJLSydKwdLN3tEUUrzPSSM8S4hDYRA= +github.com/uudashr/gocognit v1.2.0/go.mod h1:k/DdKPI6XBZO1q7HgoV2juESI2/Ofj9AcHPZhBBdrTU= github.com/uudashr/iface v1.3.0 h1:zwPch0fs9tdh9BmL5kcgSpvnObV+yHjO4JjVBl8IA10= github.com/uudashr/iface v1.3.0/go.mod h1:4QvspiRd3JLPAEXBQ9AiZpLbJlrWWgRChOKDJEuQTdg= github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU= @@ -471,12 +471,12 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo= -golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak= +golang.org/x/exp v0.0.0-20241210194714-1829a127f884 h1:Y/Mj/94zIQQGHVSv1tTtQBDaQaJe62U9bkDZKKyhPCU= +golang.org/x/exp v0.0.0-20241210194714-1829a127f884/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= -golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f h1:WTyX8eCCyfdqiPYkRGm0MqElSfYFH3yR1+rl/mct9sA= -golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/exp/typeparams v0.0.0-20241210194714-1829a127f884 h1:1xaZTydL5Gsg78QharTwKfA9FY9CZ1VQj6D/AZEvHR0= +golang.org/x/exp/typeparams v0.0.0-20241210194714-1829a127f884/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= 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.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= @@ -507,8 +507,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= -golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -520,8 +520,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -548,8 +548,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -570,8 +570,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190321232350-e250d351ecad/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -593,8 +593,8 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= -golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o= -golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q= +golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= +golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= 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=