diff --git a/go.mod b/go.mod index dac9dd7b..1920f858 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/golang/mock v1.6.0 github.com/google/go-cmp v0.6.0 github.com/guptarohit/asciigraph v0.5.6 - github.com/hetznercloud/hcloud-go/v2 v2.4.0 + github.com/hetznercloud/hcloud-go/v2 v2.4.1-0.20231130153218-701f3810de06 github.com/pelletier/go-toml/v2 v2.1.0 github.com/rjeczalik/interfaces v0.3.0 github.com/spf13/cobra v1.8.0 @@ -24,10 +24,13 @@ require ( github.com/VividCortex/ewma v1.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/dave/jennifer v1.6.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.15.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20 // indirect + github.com/jmattheis/goverter v1.2.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect @@ -38,8 +41,9 @@ require ( github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.11.1 // indirect github.com/rivo/uniseg v0.2.0 // indirect + github.com/vburenin/ifacemaker v1.2.1 // indirect golang.org/x/mod v0.9.0 // indirect - golang.org/x/net v0.17.0 // indirect + golang.org/x/net v0.18.0 // indirect golang.org/x/sys v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.6.0 // indirect diff --git a/go.sum b/go.sum index 76a3b960..ddf3add6 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,15 @@ github.com/cheggaaa/pb/v3 v3.1.4 h1:DN8j4TVVdKu3WxVwcRKu0sG00IIU6FewoABZzXbRQeo= github.com/cheggaaa/pb/v3 v3.1.4/go.mod h1:6wVjILNBaXMs8c21qRiaUM8BR82erfgau1DQ4iUXmSA= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/dave/astrid v0.0.0-20170323122508-8c2895878b14/go.mod h1:Sth2QfxfATb/nW4EsrSi2KyJmbcniZ8TgTaji17D6ms= +github.com/dave/brenda v1.1.0/go.mod h1:4wCUr6gSlu5/1Tk7akE5X7UorwiQ8Rij0SKH3/BGMOM= +github.com/dave/courtney v0.3.0/go.mod h1:BAv3hA06AYfNUjfjQr+5gc6vxeBVOupLqrColj+QSD8= +github.com/dave/gopackages v0.0.0-20170318123100-46e7023ec56e/go.mod h1:i00+b/gKdIDIxuLDFob7ustLAVqhsZRk2qVZrArELGQ= +github.com/dave/jennifer v1.6.0 h1:MQ/6emI2xM7wt0tJzJzyUik2Q3Tcn2eE0vtYgh4GPVI= +github.com/dave/jennifer v1.6.0/go.mod h1:AxTG893FiZKqxy3FP1kL80VMshSMuz2G+EgvszgGRnk= +github.com/dave/kerr v0.0.0-20170318121727-bc25dd6abe8e/go.mod h1:qZqlPyPvfsDJt+3wHJ1EvSXDuVjFTK0j2p/ca+gtsb8= +github.com/dave/patsy v0.0.0-20210517141501-957256f50cba/go.mod h1:qfR88CgEGLoiqDaE+xxDCi5QA5v4vUoW0UCX2Nd5Tlc= +github.com/dave/rebecca v0.9.1/go.mod h1:N6XYdMD/OKw3lkF3ywh8Z6wPGuwNFDNtWYEMFWEmXBA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -32,8 +41,14 @@ github.com/guptarohit/asciigraph v0.5.6 h1:0tra3HEhfdj1sP/9IedrCpfSiXYTtHdCgBhBL github.com/guptarohit/asciigraph v0.5.6/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag= github.com/hetznercloud/hcloud-go/v2 v2.4.0 h1:MqlAE+w125PLvJRCpAJmEwrIxoVdUdOyuFUhE/Ukbok= github.com/hetznercloud/hcloud-go/v2 v2.4.0/go.mod h1:l7fA5xsncFBzQTyw29/dw5Yr88yEGKKdc6BHf24ONS0= +github.com/hetznercloud/hcloud-go/v2 v2.4.1-0.20231130153218-701f3810de06 h1:iXLUR7pwlVlUawda7bNS3yWGqV6yi9QJs5CBE+cF72k= +github.com/hetznercloud/hcloud-go/v2 v2.4.1-0.20231130153218-701f3810de06/go.mod h1:4rkGyyVFBWx+/LFiPoGgdE8LD/JfSqVpmSyi+7hOQ1s= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20 h1:dAOsPLhnBzIyxu0VvmnKjlNcIlgMK+erD6VRHDtweMI= +github.com/jessevdk/go-flags v1.4.1-0.20181029123624-5de817a9aa20/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jmattheis/goverter v1.2.0 h1:hespXDXi19SWVZKWJyWn0/SSJigEBg4Mjl8BpR2MaHE= +github.com/jmattheis/goverter v1.2.0/go.mod h1:Il/E+0riIfIgRBUpM+Fnh2s8/sJhMp5NeDZZenTd6S4= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -49,6 +64,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= @@ -78,50 +94,78 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/vburenin/ifacemaker v1.2.1 h1:3Vq8B/bfBgjWTkv+jDg4dVL1KHt3k1K4lO7XRxYA2sk= +github.com/vburenin/ifacemaker v1.2.1/go.mod h1:5WqrzX2aD7/hi+okBjcaEQJMg4lDGrpuEX3B8L4Wgrs= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= golang.org/x/mod v0.2.0/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.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= 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= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= golang.org/x/sys v0.14.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.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8= golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= @@ -130,6 +174,9 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.5.0/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/cmd/certificate/list.go b/internal/cmd/certificate/list.go index cd834214..150e92a4 100644 --- a/internal/cmd/certificate/list.go +++ b/internal/cmd/certificate/list.go @@ -83,28 +83,7 @@ var ListCmd = base.ListCmd{ certSchemas := make([]schema.Certificate, 0, len(resources)) for _, resource := range resources { cert := resource.(*hcloud.Certificate) - certSchema := schema.Certificate{ - ID: cert.ID, - Certificate: cert.Certificate, - Created: cert.Created, - DomainNames: cert.DomainNames, - Fingerprint: cert.Fingerprint, - Labels: cert.Labels, - Name: cert.Name, - Type: string(cert.Type), - NotValidAfter: cert.NotValidAfter, - NotValidBefore: cert.NotValidBefore, - } - if len(cert.UsedBy) > 0 { - certSchema.UsedBy = make([]schema.CertificateUsedByRef, len(cert.UsedBy)) - for i, ub := range cert.UsedBy { - certSchema.UsedBy[i] = schema.CertificateUsedByRef{ - ID: ub.ID, - Type: string(ub.Type), - } - } - } - certSchemas = append(certSchemas, certSchema) + certSchemas = append(certSchemas, hcloud.SchemaFromCertificate(cert)) } return certSchemas diff --git a/internal/cmd/datacenter/list.go b/internal/cmd/datacenter/list.go index 4b3bc7ed..e3907590 100644 --- a/internal/cmd/datacenter/list.go +++ b/internal/cmd/datacenter/list.go @@ -7,7 +7,6 @@ import ( "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/output" - "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" @@ -44,7 +43,7 @@ var ListCmd = base.ListCmd{ dcSchemas := make([]schema.Datacenter, 0, len(resources)) for _, resource := range resources { dc := resource.(*hcloud.Datacenter) - dcSchemas = append(dcSchemas, util.DatacenterToSchema(*dc)) + dcSchemas = append(dcSchemas, hcloud.SchemaFromDatacenter(dc)) } return dcSchemas diff --git a/internal/cmd/firewall/list.go b/internal/cmd/firewall/list.go index 1a20cd6e..25ea624f 100644 --- a/internal/cmd/firewall/list.go +++ b/internal/cmd/firewall/list.go @@ -69,46 +69,8 @@ var ListCmd = base.ListCmd{ JSONSchema: func(resources []interface{}) interface{} { firewallSchemas := make([]schema.Firewall, 0, len(resources)) for _, resource := range resources { - firewall := resource.(*hcloud.Firewall) - firewallSchema := schema.Firewall{ - ID: firewall.ID, - Name: firewall.Name, - Labels: firewall.Labels, - Created: firewall.Created, - } - for _, rule := range firewall.Rules { - var sourceNets []string - for _, sourceIP := range rule.SourceIPs { - sourceNets = append(sourceNets, sourceIP.Network()) - } - var destinationNets []string - for _, destinationIP := range rule.DestinationIPs { - destinationNets = append(destinationNets, destinationIP.Network()) - } - firewallSchema.Rules = append(firewallSchema.Rules, schema.FirewallRule{ - Direction: string(rule.Direction), - SourceIPs: sourceNets, - DestinationIPs: destinationNets, - Protocol: string(rule.Protocol), - Port: rule.Port, - Description: rule.Description, - }) - } - for _, AppliedTo := range firewall.AppliedTo { - s := schema.FirewallResource{ - Type: string(AppliedTo.Type), - } - switch AppliedTo.Type { - case hcloud.FirewallResourceTypeServer: - s.Server = &schema.FirewallResourceServer{ID: AppliedTo.Server.ID} - case hcloud.FirewallResourceTypeLabelSelector: - s.LabelSelector = &schema.FirewallResourceLabelSelector{Selector: AppliedTo.LabelSelector.Selector} - } - - firewallSchema.AppliedTo = append(firewallSchema.AppliedTo, s) - } - - firewallSchemas = append(firewallSchemas, firewallSchema) + fw := resource.(*hcloud.Firewall) + firewallSchemas = append(firewallSchemas, hcloud.SchemaFromFirewall(fw)) } return firewallSchemas }, diff --git a/internal/cmd/floatingip/list.go b/internal/cmd/floatingip/list.go index 5d379cee..dd414f46 100644 --- a/internal/cmd/floatingip/list.go +++ b/internal/cmd/floatingip/list.go @@ -97,28 +97,7 @@ var ListCmd = base.ListCmd{ floatingIPSchemas := make([]schema.FloatingIP, 0, len(resources)) for _, resource := range resources { floatingIP := resource.(*hcloud.FloatingIP) - floatingIPSchema := schema.FloatingIP{ - ID: floatingIP.ID, - Name: floatingIP.Name, - Description: hcloud.String(floatingIP.Description), - IP: floatingIP.IP.String(), - Created: floatingIP.Created, - Type: string(floatingIP.Type), - HomeLocation: util.LocationToSchema(*floatingIP.HomeLocation), - Blocked: floatingIP.Blocked, - Protection: schema.FloatingIPProtection{Delete: floatingIP.Protection.Delete}, - Labels: floatingIP.Labels, - } - for ip, dnsPtr := range floatingIP.DNSPtr { - floatingIPSchema.DNSPtr = append(floatingIPSchema.DNSPtr, schema.FloatingIPDNSPtr{ - IP: ip, - DNSPtr: dnsPtr, - }) - } - if floatingIP.Server != nil { - floatingIPSchema.Server = hcloud.Ptr(floatingIP.Server.ID) - } - floatingIPSchemas = append(floatingIPSchemas, floatingIPSchema) + floatingIPSchemas = append(floatingIPSchemas, hcloud.SchemaFromFloatingIP(floatingIP)) } return floatingIPSchemas }, diff --git a/internal/cmd/image/list.go b/internal/cmd/image/list.go index c01ad949..e614cb95 100644 --- a/internal/cmd/image/list.go +++ b/internal/cmd/image/list.go @@ -145,7 +145,7 @@ var ListCmd = base.ListCmd{ imageSchemas := make([]schema.Image, 0, len(resources)) for _, resource := range resources { image := resource.(*hcloud.Image) - imageSchemas = append(imageSchemas, util.ImageToSchema(*image)) + imageSchemas = append(imageSchemas, hcloud.SchemaFromImage(image)) } return imageSchemas }, diff --git a/internal/cmd/iso/list.go b/internal/cmd/iso/list.go index 5d8f5514..075e2f87 100644 --- a/internal/cmd/iso/list.go +++ b/internal/cmd/iso/list.go @@ -12,7 +12,6 @@ import ( "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/cmpl" "github.com/hetznercloud/cli/internal/cmd/output" - "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" @@ -94,7 +93,7 @@ var ListCmd = base.ListCmd{ isoSchemas := make([]schema.ISO, 0, len(resources)) for _, resource := range resources { iso := resource.(*hcloud.ISO) - isoSchemas = append(isoSchemas, util.ISOToSchema(*iso)) + isoSchemas = append(isoSchemas, hcloud.SchemaFromISO(iso)) } return isoSchemas }, diff --git a/internal/cmd/loadbalancer/list.go b/internal/cmd/loadbalancer/list.go index e85994d0..f8fd3efa 100644 --- a/internal/cmd/loadbalancer/list.go +++ b/internal/cmd/loadbalancer/list.go @@ -86,87 +86,7 @@ var ListCmd = base.ListCmd{ loadBalancerSchemas := make([]schema.LoadBalancer, 0, len(resources)) for _, resource := range resources { loadBalancer := resource.(*hcloud.LoadBalancer) - loadBalancerSchema := schema.LoadBalancer{ - ID: loadBalancer.ID, - Name: loadBalancer.Name, - PublicNet: schema.LoadBalancerPublicNet{ - Enabled: loadBalancer.PublicNet.Enabled, - IPv4: schema.LoadBalancerPublicNetIPv4{ - IP: loadBalancer.PublicNet.IPv4.IP.String(), - }, - IPv6: schema.LoadBalancerPublicNetIPv6{ - IP: loadBalancer.PublicNet.IPv6.IP.String(), - }, - }, - Created: loadBalancer.Created, - Labels: loadBalancer.Labels, - LoadBalancerType: util.LoadBalancerTypeToSchema(*loadBalancer.LoadBalancerType), - Location: util.LocationToSchema(*loadBalancer.Location), - IncludedTraffic: loadBalancer.IncludedTraffic, - OutgoingTraffic: &loadBalancer.OutgoingTraffic, - IngoingTraffic: &loadBalancer.IngoingTraffic, - Protection: schema.LoadBalancerProtection{ - Delete: loadBalancer.Protection.Delete, - }, - Algorithm: schema.LoadBalancerAlgorithm{Type: string(loadBalancer.Algorithm.Type)}, - } - for _, service := range loadBalancer.Services { - serviceSchema := schema.LoadBalancerService{ - Protocol: string(service.Protocol), - ListenPort: service.ListenPort, - DestinationPort: service.DestinationPort, - Proxyprotocol: service.Proxyprotocol, - HealthCheck: &schema.LoadBalancerServiceHealthCheck{ - Protocol: string(service.HealthCheck.Protocol), - Port: service.HealthCheck.Port, - Interval: int(service.HealthCheck.Interval.Seconds()), - Timeout: int(service.HealthCheck.Timeout.Seconds()), - Retries: service.HealthCheck.Retries, - }, - } - if service.Protocol != hcloud.LoadBalancerServiceProtocolTCP { - serviceSchema.HTTP = &schema.LoadBalancerServiceHTTP{ - StickySessions: service.HTTP.StickySessions, - CookieName: service.HTTP.CookieName, - CookieLifetime: int(service.HTTP.CookieLifetime.Seconds()), - RedirectHTTP: service.HTTP.RedirectHTTP, - } - } - if service.HealthCheck.HTTP != nil { - serviceSchema.HealthCheck.HTTP = &schema.LoadBalancerServiceHealthCheckHTTP{ - Domain: service.HealthCheck.HTTP.Domain, - Path: service.HealthCheck.HTTP.Path, - StatusCodes: service.HealthCheck.HTTP.StatusCodes, - TLS: service.HealthCheck.HTTP.TLS, - Response: service.HealthCheck.HTTP.Response, - } - } - loadBalancerSchema.Services = append(loadBalancerSchema.Services, serviceSchema) - } - for _, target := range loadBalancer.Targets { - targetSchema := schema.LoadBalancerTarget{ - Type: string(target.Type), - UsePrivateIP: target.UsePrivateIP, - } - if target.Type == hcloud.LoadBalancerTargetTypeServer { - targetSchema.Server = &schema.LoadBalancerTargetServer{ID: target.Server.Server.ID} - } - if target.Type == hcloud.LoadBalancerTargetTypeLabelSelector { - targetSchema.LabelSelector = &schema.LoadBalancerTargetLabelSelector{Selector: target.LabelSelector.Selector} - } - if target.Type == hcloud.LoadBalancerTargetTypeIP { - targetSchema.IP = &schema.LoadBalancerTargetIP{IP: target.IP.IP} - } - for _, healthStatus := range target.HealthStatus { - targetSchema.HealthStatus = append(targetSchema.HealthStatus, schema.LoadBalancerTargetHealthStatus{ - ListenPort: healthStatus.ListenPort, - Status: string(healthStatus.Status), - }) - } - loadBalancerSchema.Targets = append(loadBalancerSchema.Targets, targetSchema) - } - - loadBalancerSchemas = append(loadBalancerSchemas, loadBalancerSchema) + loadBalancerSchemas = append(loadBalancerSchemas, hcloud.SchemaFromLoadBalancer(loadBalancer)) } return loadBalancerSchemas }, diff --git a/internal/cmd/loadbalancertype/list.go b/internal/cmd/loadbalancertype/list.go index 1eaf7dbc..7bc2bce8 100644 --- a/internal/cmd/loadbalancertype/list.go +++ b/internal/cmd/loadbalancertype/list.go @@ -7,7 +7,6 @@ import ( "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/output" - "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" @@ -42,7 +41,7 @@ var ListCmd = base.ListCmd{ loadBalancerTypeSchemas := make([]schema.LoadBalancerType, 0, len(resources)) for _, resource := range resources { loadBalancerType := resource.(*hcloud.LoadBalancerType) - loadBalancerTypeSchemas = append(loadBalancerTypeSchemas, util.LoadBalancerTypeToSchema(*loadBalancerType)) + loadBalancerTypeSchemas = append(loadBalancerTypeSchemas, hcloud.SchemaFromLoadBalancerType(loadBalancerType)) } return loadBalancerTypeSchemas }, diff --git a/internal/cmd/location/list.go b/internal/cmd/location/list.go index 87369a82..fb1c0751 100644 --- a/internal/cmd/location/list.go +++ b/internal/cmd/location/list.go @@ -7,7 +7,6 @@ import ( "github.com/hetznercloud/cli/internal/cmd/base" "github.com/hetznercloud/cli/internal/cmd/output" - "github.com/hetznercloud/cli/internal/cmd/util" "github.com/hetznercloud/cli/internal/hcapi2" "github.com/hetznercloud/hcloud-go/v2/hcloud" "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" @@ -41,7 +40,7 @@ var ListCmd = base.ListCmd{ locationSchemas := make([]schema.Location, 0, len(resources)) for _, resource := range resources { location := resource.(*hcloud.Location) - locationSchemas = append(locationSchemas, util.LocationToSchema(*location)) + locationSchemas = append(locationSchemas, hcloud.SchemaFromLocation(location)) } return locationSchemas }, diff --git a/internal/cmd/network/list.go b/internal/cmd/network/list.go index 46eea6b8..9765b848 100644 --- a/internal/cmd/network/list.go +++ b/internal/cmd/network/list.go @@ -75,34 +75,7 @@ var ListCmd = base.ListCmd{ networkSchemas := make([]schema.Network, 0, len(resources)) for _, resource := range resources { network := resource.(*hcloud.Network) - - networkSchema := schema.Network{ - ID: network.ID, - Name: network.Name, - IPRange: network.IPRange.String(), - Protection: schema.NetworkProtection{Delete: network.Protection.Delete}, - Created: network.Created, - Labels: network.Labels, - ExposeRoutesToVSwitch: network.ExposeRoutesToVSwitch, - } - for _, subnet := range network.Subnets { - networkSchema.Subnets = append(networkSchema.Subnets, schema.NetworkSubnet{ - Type: string(subnet.Type), - IPRange: subnet.IPRange.String(), - NetworkZone: string(subnet.NetworkZone), - Gateway: subnet.Gateway.String(), - }) - } - for _, route := range network.Routes { - networkSchema.Routes = append(networkSchema.Routes, schema.NetworkRoute{ - Destination: route.Destination.String(), - Gateway: route.Gateway.String(), - }) - } - for _, server := range network.Servers { - networkSchema.Servers = append(networkSchema.Servers, server.ID) - } - networkSchemas = append(networkSchemas, networkSchema) + networkSchemas = append(networkSchemas, hcloud.SchemaFromNetwork(network)) } return networkSchemas }, diff --git a/internal/cmd/placementgroup/list.go b/internal/cmd/placementgroup/list.go index b0529454..60675fe0 100644 --- a/internal/cmd/placementgroup/list.go +++ b/internal/cmd/placementgroup/list.go @@ -59,16 +59,7 @@ var ListCmd = base.ListCmd{ placementGroupSchemas := make([]schema.PlacementGroup, 0, len(resources)) for _, resource := range resources { placementGroup := resource.(*hcloud.PlacementGroup) - placementGroupSchema := schema.PlacementGroup{ - ID: placementGroup.ID, - Name: placementGroup.Name, - Labels: placementGroup.Labels, - Created: placementGroup.Created, - Servers: placementGroup.Servers, - Type: string(placementGroup.Type), - } - - placementGroupSchemas = append(placementGroupSchemas, placementGroupSchema) + placementGroupSchemas = append(placementGroupSchemas, hcloud.SchemaFromPlacementGroup(placementGroup)) } return placementGroupSchemas }, diff --git a/internal/cmd/primaryip/list.go b/internal/cmd/primaryip/list.go index 89cfe443..a460352a 100644 --- a/internal/cmd/primaryip/list.go +++ b/internal/cmd/primaryip/list.go @@ -100,30 +100,7 @@ var ListCmd = base.ListCmd{ primaryIPsSchema := make([]schema.PrimaryIP, 0, len(resources)) for _, resource := range resources { primaryIP := resource.(*hcloud.PrimaryIP) - var dnsPtrs []hcloud.PrimaryIPDNSPTR - for i, d := range primaryIP.DNSPtr { - dnsPtrs = append(dnsPtrs, hcloud.PrimaryIPDNSPTR{ - DNSPtr: d, - IP: i, - }) - } - var primaryIPSchema = schema.PrimaryIP{ - ID: primaryIP.ID, - Name: primaryIP.Name, - IP: primaryIP.IP.String(), - Type: string(primaryIP.Type), - AssigneeID: primaryIP.AssigneeID, - AssigneeType: primaryIP.AssigneeType, - AutoDelete: primaryIP.AutoDelete, - Created: primaryIP.Created, - Datacenter: util.DatacenterToSchema(*primaryIP.Datacenter), - - Protection: schema.PrimaryIPProtection{ - Delete: primaryIP.Protection.Delete, - }, - Labels: primaryIP.Labels, - } - primaryIPsSchema = append(primaryIPsSchema, primaryIPSchema) + primaryIPsSchema = append(primaryIPsSchema, hcloud.SchemaFromPrimaryIP(primaryIP)) } return primaryIPsSchema }, diff --git a/internal/cmd/server/list.go b/internal/cmd/server/list.go index 59d169fb..c85c71b9 100644 --- a/internal/cmd/server/list.go +++ b/internal/cmd/server/list.go @@ -132,73 +132,7 @@ var ListCmd = base.ListCmd{ serversSchema := make([]schema.Server, 0, len(resources)) for _, resource := range resources { server := resource.(*hcloud.Server) - - serverSchema := schema.Server{ - ID: server.ID, - Name: server.Name, - Status: string(server.Status), - Created: server.Created, - Datacenter: util.DatacenterToSchema(*server.Datacenter), - ServerType: util.ServerTypeToSchema(*server.ServerType), - PublicNet: schema.ServerPublicNet{ - IPv4: schema.ServerPublicNetIPv4{ - IP: server.PublicNet.IPv4.IP.String(), - Blocked: server.PublicNet.IPv4.Blocked, - DNSPtr: server.PublicNet.IPv4.DNSPtr, - }, - IPv6: schema.ServerPublicNetIPv6{ - IP: server.PublicNet.IPv6.IP.String(), - Blocked: server.PublicNet.IPv6.Blocked, - }, - }, - RescueEnabled: server.RescueEnabled, - BackupWindow: hcloud.String(server.BackupWindow), - OutgoingTraffic: &server.OutgoingTraffic, - IngoingTraffic: &server.IngoingTraffic, - IncludedTraffic: server.IncludedTraffic, - Protection: schema.ServerProtection{ - Delete: server.Protection.Delete, - Rebuild: server.Protection.Rebuild, - }, - Labels: server.Labels, - PrimaryDiskSize: server.PrimaryDiskSize, - } - if server.PlacementGroup != nil { - serverPlacementGroup := util.PlacementGroupToSchema(*server.PlacementGroup) - serverSchema.PlacementGroup = &serverPlacementGroup - } - if server.Image != nil { - serverImage := util.ImageToSchema(*server.Image) - serverSchema.Image = &serverImage - } - if server.ISO != nil { - serverISO := util.ISOToSchema(*server.ISO) - serverSchema.ISO = &serverISO - } - for ip, dnsPTR := range server.PublicNet.IPv6.DNSPtr { - serverSchema.PublicNet.IPv6.DNSPtr = append(serverSchema.PublicNet.IPv6.DNSPtr, schema.ServerPublicNetIPv6DNSPtr{ - IP: ip, - DNSPtr: dnsPTR, - }) - } - for _, floatingIP := range server.PublicNet.FloatingIPs { - serverSchema.PublicNet.FloatingIPs = append(serverSchema.PublicNet.FloatingIPs, floatingIP.ID) - } - for _, volume := range server.Volumes { - serverSchema.Volumes = append(serverSchema.Volumes, volume.ID) - } - for _, privateNet := range server.PrivateNet { - privateNetSchema := schema.ServerPrivateNet{ - Network: privateNet.Network.ID, - IP: privateNet.IP.String(), - MACAddress: privateNet.MACAddress, - } - for _, aliasIP := range privateNet.Aliases { - privateNetSchema.AliasIPs = append(privateNetSchema.AliasIPs, aliasIP.String()) - } - serverSchema.PrivateNet = append(serverSchema.PrivateNet, privateNetSchema) - } - serversSchema = append(serversSchema, serverSchema) + serversSchema = append(serversSchema, hcloud.SchemaFromServer(server)) } return serversSchema }, diff --git a/internal/cmd/servertype/list.go b/internal/cmd/servertype/list.go index 4330660f..44321e82 100644 --- a/internal/cmd/servertype/list.go +++ b/internal/cmd/servertype/list.go @@ -56,7 +56,7 @@ var ListCmd = base.ListCmd{ serverTypeSchemas := make([]schema.ServerType, 0, len(resources)) for _, resource := range resources { serverType := resource.(*hcloud.ServerType) - serverTypeSchemas = append(serverTypeSchemas, util.ServerTypeToSchema(*serverType)) + serverTypeSchemas = append(serverTypeSchemas, hcloud.SchemaFromServerType(serverType)) } return serverTypeSchemas }, diff --git a/internal/cmd/sshkey/list.go b/internal/cmd/sshkey/list.go index 1fdf800d..82923e29 100644 --- a/internal/cmd/sshkey/list.go +++ b/internal/cmd/sshkey/list.go @@ -54,15 +54,7 @@ var ListCmd = base.ListCmd{ sshKeySchemas := make([]schema.SSHKey, 0, len(resources)) for _, resource := range resources { sshKey := resource.(*hcloud.SSHKey) - sshKeySchema := schema.SSHKey{ - ID: sshKey.ID, - Name: sshKey.Name, - Fingerprint: sshKey.Fingerprint, - PublicKey: sshKey.PublicKey, - Labels: sshKey.Labels, - Created: sshKey.Created, - } - sshKeySchemas = append(sshKeySchemas, sshKeySchema) + sshKeySchemas = append(sshKeySchemas, hcloud.SchemaFromSSHKey(sshKey)) } return sshKeySchemas }, diff --git a/internal/cmd/util/util.go b/internal/cmd/util/util.go index 05d44149..158415f3 100644 --- a/internal/cmd/util/util.go +++ b/internal/cmd/util/util.go @@ -11,9 +11,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - - "github.com/hetznercloud/hcloud-go/v2/hcloud" - "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func YesNo(b bool) string { @@ -162,165 +159,6 @@ func DescribeJSON(object interface{}) error { return enc.Encode(object) } -func LocationToSchema(location hcloud.Location) schema.Location { - return schema.Location{ - ID: location.ID, - Name: location.Name, - Description: location.Description, - Country: location.Country, - City: location.City, - Latitude: location.Latitude, - Longitude: location.Longitude, - NetworkZone: string(location.NetworkZone), - } -} - -func DatacenterToSchema(datacenter hcloud.Datacenter) schema.Datacenter { - datacenterSchema := schema.Datacenter{ - ID: datacenter.ID, - Name: datacenter.Name, - Description: datacenter.Description, - Location: LocationToSchema(*datacenter.Location), - } - for _, st := range datacenter.ServerTypes.Supported { - datacenterSchema.ServerTypes.Supported = append(datacenterSchema.ServerTypes.Supported, st.ID) - } - for _, st := range datacenter.ServerTypes.Available { - datacenterSchema.ServerTypes.Available = append(datacenterSchema.ServerTypes.Available, st.ID) - } - return datacenterSchema -} - -func ServerTypeToSchema(serverType hcloud.ServerType) schema.ServerType { - serverTypeSchema := schema.ServerType{ - ID: serverType.ID, - Name: serverType.Name, - Description: serverType.Description, - Cores: serverType.Cores, - Memory: serverType.Memory, - Disk: serverType.Disk, - StorageType: string(serverType.StorageType), - CPUType: string(serverType.CPUType), - Architecture: string(serverType.Architecture), - IncludedTraffic: serverType.IncludedTraffic, - DeprecatableResource: DeprecatableResourceToSchema(serverType.DeprecatableResource), - } - for _, pricing := range serverType.Pricings { - serverTypeSchema.Prices = append(serverTypeSchema.Prices, schema.PricingServerTypePrice{ - Location: pricing.Location.Name, - PriceHourly: schema.Price{ - Net: pricing.Hourly.Net, - Gross: pricing.Hourly.Gross, - }, - PriceMonthly: schema.Price{ - Net: pricing.Monthly.Net, - Gross: pricing.Monthly.Gross, - }, - }) - } - return serverTypeSchema -} - -func ImageToSchema(image hcloud.Image) schema.Image { - imageSchema := schema.Image{ - ID: image.ID, - Name: hcloud.String(image.Name), - Description: image.Description, - Status: string(image.Status), - Type: string(image.Type), - ImageSize: &image.ImageSize, - DiskSize: image.DiskSize, - Created: image.Created, - OSFlavor: image.OSFlavor, - OSVersion: hcloud.String(image.OSVersion), - Architecture: string(image.Architecture), - RapidDeploy: image.RapidDeploy, - Protection: schema.ImageProtection{ - Delete: image.Protection.Delete, - }, - Deprecated: image.Deprecated, - Labels: image.Labels, - } - if image.CreatedFrom != nil { - imageSchema.CreatedFrom = &schema.ImageCreatedFrom{ - ID: image.CreatedFrom.ID, - Name: image.CreatedFrom.Name, - } - } - if image.BoundTo != nil { - imageSchema.BoundTo = hcloud.Ptr(image.BoundTo.ID) - } - return imageSchema -} - -func ISOToSchema(iso hcloud.ISO) schema.ISO { - isoSchema := schema.ISO{ - ID: iso.ID, - Name: iso.Name, - Description: iso.Description, - Type: string(iso.Type), - Deprecated: iso.Deprecated, - } - - if iso.Architecture != nil { - isoSchema.Architecture = hcloud.Ptr(string(*iso.Architecture)) - } - - return isoSchema -} - -func LoadBalancerTypeToSchema(loadBalancerType hcloud.LoadBalancerType) schema.LoadBalancerType { - loadBalancerTypeSchema := schema.LoadBalancerType{ - ID: loadBalancerType.ID, - Name: loadBalancerType.Name, - Description: loadBalancerType.Description, - MaxConnections: loadBalancerType.MaxConnections, - MaxServices: loadBalancerType.MaxServices, - MaxTargets: loadBalancerType.MaxTargets, - MaxAssignedCertificates: loadBalancerType.MaxAssignedCertificates, - } - for _, pricing := range loadBalancerType.Pricings { - loadBalancerTypeSchema.Prices = append(loadBalancerTypeSchema.Prices, schema.PricingLoadBalancerTypePrice{ - Location: pricing.Location.Name, - PriceHourly: schema.Price{ - Net: pricing.Hourly.Net, - Gross: pricing.Hourly.Gross, - }, - PriceMonthly: schema.Price{ - Net: pricing.Monthly.Net, - Gross: pricing.Monthly.Gross, - }, - }) - } - return loadBalancerTypeSchema -} - -func PlacementGroupToSchema(placementGroup hcloud.PlacementGroup) schema.PlacementGroup { - return schema.PlacementGroup{ - ID: placementGroup.ID, - Name: placementGroup.Name, - Labels: placementGroup.Labels, - Created: placementGroup.Created, - Type: string(placementGroup.Type), - Servers: placementGroup.Servers, - } -} - -func DeprecatableResourceToSchema(deprecatableResource hcloud.DeprecatableResource) schema.DeprecatableResource { - var deprecation *schema.DeprecationInfo - - if deprecatableResource.IsDeprecated() { - deprecation = &schema.DeprecationInfo{ - Announced: deprecatableResource.Deprecation.Announced, - UnavailableAfter: deprecatableResource.Deprecation.UnavailableAfter, - } - } - - return schema.DeprecatableResource{ - Deprecation: deprecation, - } -} - // ValidateRequiredFlags ensures that flags has values for all flags with // the passed names. // diff --git a/internal/cmd/volume/list.go b/internal/cmd/volume/list.go index fed1f483..c6e7cb04 100644 --- a/internal/cmd/volume/list.go +++ b/internal/cmd/volume/list.go @@ -80,20 +80,7 @@ var ListCmd = base.ListCmd{ volumesSchema := make([]schema.Volume, 0, len(resources)) for _, resource := range resources { volume := resource.(*hcloud.Volume) - volumeSchema := schema.Volume{ - ID: volume.ID, - Name: volume.Name, - Location: util.LocationToSchema(*volume.Location), - Size: volume.Size, - LinuxDevice: volume.LinuxDevice, - Labels: volume.Labels, - Created: volume.Created, - Protection: schema.VolumeProtection{Delete: volume.Protection.Delete}, - } - if volume.Server != nil { - volumeSchema.Server = hcloud.Ptr(volume.Server.ID) - } - volumesSchema = append(volumesSchema, volumeSchema) + volumesSchema = append(volumesSchema, hcloud.SchemaFromVolume(volume)) } return volumesSchema },