From 98cca37194aeb908bf11a6b07a1c4eea0004ac4f Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Wed, 10 Jul 2024 23:18:24 +0200 Subject: [PATCH] Do not rely on req.URL.Path to determine whether the auth header needs to be added Fixes #11 Signed-off-by: Nicola Murino --- .github/workflows/release.yml | 2 +- go.mod | 24 ++++++++-------- go.sum | 52 +++++++++++++++++------------------ sftpgo/client/actions.go | 10 +++---- sftpgo/client/admins.go | 10 +++---- sftpgo/client/auth.go | 4 +-- sftpgo/client/client.go | 11 ++++---- sftpgo/client/folders.go | 10 +++---- sftpgo/client/groups.go | 10 +++---- sftpgo/client/iplists.go | 10 +++---- sftpgo/client/roles.go | 10 +++---- sftpgo/client/rules.go | 10 +++---- sftpgo/client/users.go | 10 +++---- 13 files changed, 86 insertions(+), 87 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 32a70a7..a8ff191 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ on: - 'v*' env: - GO_VERSION: 1.22.4 + GO_VERSION: 1.22.5 # Releases need permissions to read and write the repository contents. # GitHub considers creating releases and uploading assets as writing contents. diff --git a/go.mod b/go.mod index 4ee7ff0..cc13efa 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,17 @@ module github.com/drakkan/terraform-provider-sftpgo go 1.22.2 require ( - github.com/hashicorp/terraform-plugin-framework v1.9.0 - github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 + github.com/hashicorp/terraform-plugin-framework v1.10.0 + github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 github.com/hashicorp/terraform-plugin-go v0.23.0 github.com/hashicorp/terraform-plugin-log v0.9.0 - github.com/hashicorp/terraform-plugin-testing v1.8.0 + github.com/hashicorp/terraform-plugin-testing v1.9.0 github.com/sftpgo/sdk v0.1.8 github.com/stretchr/testify v1.9.0 ) require ( - github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton // indirect + github.com/ProtonMail/go-crypto v1.1.0-alpha.3-proton // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/cloudflare/circl v1.3.9 // indirect @@ -31,7 +31,7 @@ require ( github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.7.0 // indirect github.com/hashicorp/hc-install v0.7.0 // indirect - github.com/hashicorp/hcl/v2 v2.20.1 // indirect + github.com/hashicorp/hcl/v2 v2.21.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.21.0 // indirect github.com/hashicorp/terraform-json v0.22.1 // indirect @@ -54,16 +54,16 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.14.4 // indirect - golang.org/x/crypto v0.24.0 // indirect - golang.org/x/mod v0.18.0 // indirect - golang.org/x/net v0.26.0 // indirect + golang.org/x/crypto v0.25.0 // indirect + golang.org/x/mod v0.19.0 // indirect + golang.org/x/net v0.27.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect - golang.org/x/tools v0.22.0 // indirect + golang.org/x/tools v0.23.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect - google.golang.org/grpc v1.64.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect + google.golang.org/grpc v1.65.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f0af987..fe3cf2d 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton h1:HKz85FwoXx86kVtTvFke7rgHvq/HoloSUvW5semjFWs= -github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +github.com/ProtonMail/go-crypto v1.1.0-alpha.3-proton h1:0RXAi0EJFs81j+MMsqvHNuAUGWzeVfCO9LnHAfoQ8NA= +github.com/ProtonMail/go-crypto v1.1.0-alpha.3-proton/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= @@ -66,26 +66,26 @@ github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKe github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hc-install v0.7.0 h1:Uu9edVqjKQxxuD28mR5TikkKDd/p55S8vzPC1659aBk= github.com/hashicorp/hc-install v0.7.0/go.mod h1:ELmmzZlGnEcqoUMKUuykHaPCIR1sYLYX+KSggWSKZuA= -github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc= -github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4= +github.com/hashicorp/hcl/v2 v2.21.0 h1:lve4q/o/2rqwYOgUg3y3V2YPyD1/zkCLGjIV74Jit14= +github.com/hashicorp/hcl/v2 v2.21.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec= github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A= -github.com/hashicorp/terraform-plugin-framework v1.9.0 h1:caLcDoxiRucNi2hk8+j3kJwkKfvHznubyFsJMWfZqKU= -github.com/hashicorp/terraform-plugin-framework v1.9.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= -github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= -github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= +github.com/hashicorp/terraform-plugin-framework v1.10.0 h1:xXhICE2Fns1RYZxEQebwkB2+kXouLC932Li9qelozrc= +github.com/hashicorp/terraform-plugin-framework v1.10.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM= +github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E= +github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo= github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co= github.com/hashicorp/terraform-plugin-go v0.23.0/go.mod h1:1E3Cr9h2vMlahWMbsSEcNrOCxovCZhOOIXjFHbjc/lQ= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 h1:kJiWGx2kiQVo97Y5IOGR4EMcZ8DtMswHhUuFibsCQQE= github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0/go.mod h1:sl/UoabMc37HA6ICVMmGO+/0wofkVIRxf+BMb/dnoIg= -github.com/hashicorp/terraform-plugin-testing v1.8.0 h1:wdYIgwDk4iO933gC4S8KbKdnMQShu6BXuZQPScmHvpk= -github.com/hashicorp/terraform-plugin-testing v1.8.0/go.mod h1:o2kOgf18ADUaZGhtOl0YCkfIxg01MAiMATT2EtIHlZk= +github.com/hashicorp/terraform-plugin-testing v1.9.0 h1:xOsQRqqlHKXpFq6etTxih3ubdK3HVDtfE1IY7Rpd37o= +github.com/hashicorp/terraform-plugin-testing v1.9.0/go.mod h1:fhhVx/8+XNJZTD5o3b4stfZ6+q7z9+lIWigIYdT6/44= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= @@ -156,21 +156,21 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= -github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= +github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= +golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 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-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= +golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -188,8 +188,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc 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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -202,17 +202,17 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= -golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= +golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 h1:Di6ANFilr+S60a4S61ZM00vLdw0IrQOSMS2/6mrnOU0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= diff --git a/sftpgo/client/actions.go b/sftpgo/client/actions.go index b355678..aea6fe3 100644 --- a/sftpgo/client/actions.go +++ b/sftpgo/client/actions.go @@ -197,7 +197,7 @@ func (c *Client) GetActions() ([]BaseEventAction, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -223,7 +223,7 @@ func (c *Client) CreateAction(action BaseEventAction) (*BaseEventAction, error) return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -240,7 +240,7 @@ func (c *Client) GetAction(name string) (*BaseEventAction, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -262,7 +262,7 @@ func (c *Client) UpdateAction(action BaseEventAction) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -272,6 +272,6 @@ func (c *Client) DeleteAction(name string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/admins.go b/sftpgo/client/admins.go index cc1d3f6..8180889 100644 --- a/sftpgo/client/admins.go +++ b/sftpgo/client/admins.go @@ -107,7 +107,7 @@ func (c *Client) GetAdmins() ([]Admin, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -132,7 +132,7 @@ func (c *Client) CreateAdmin(admin Admin) (*Admin, error) { return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -149,7 +149,7 @@ func (c *Client) GetAdmin(username string) (*Admin, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -171,7 +171,7 @@ func (c *Client) UpdateAdmin(admin Admin) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -181,6 +181,6 @@ func (c *Client) DeleteAdmin(username string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/auth.go b/sftpgo/client/auth.go index 96a3348..da12cbd 100644 --- a/sftpgo/client/auth.go +++ b/sftpgo/client/auth.go @@ -24,8 +24,8 @@ const ( authEndpoint = "/api/v2/token" ) -// SignInAdmin returns a new access token for the admin with the specified credentials. -func (c *Client) SignInAdmin() (*AuthResponse, error) { +// signInAdmin returns a new access token for the admin with the specified credentials. +func (c *Client) signInAdmin() (*AuthResponse, error) { if c.Auth.Username == "" || c.Auth.Password == "" { return nil, fmt.Errorf("define username and password") } diff --git a/sftpgo/client/client.go b/sftpgo/client/client.go index 47a48e6..74ab3da 100644 --- a/sftpgo/client/client.go +++ b/sftpgo/client/client.go @@ -113,10 +113,6 @@ func NewClient(host, username, password, apiKey *string, headers []KeyValue) (*C } func (c *Client) setAuthHeader(req *http.Request) error { - if req.URL.Path == authEndpoint { - // Authentication request, stop here. - return nil - } if c.APIKey != "" { req.Header.Set("X-SFTPGO-API-KEY", c.APIKey) return nil @@ -124,7 +120,7 @@ func (c *Client) setAuthHeader(req *http.Request) error { accessToken := c.getAccessToken() if accessToken == "" { - ar, err := c.SignInAdmin() + ar, err := c.signInAdmin() if err != nil { return err } @@ -138,11 +134,14 @@ func (c *Client) setAuthHeader(req *http.Request) error { return nil } -func (c *Client) doRequest(req *http.Request, expectedStatusCode int) ([]byte, error) { +func (c *Client) doRequestWithAuth(req *http.Request, expectedStatusCode int) ([]byte, error) { if err := c.setAuthHeader(req); err != nil { return nil, err } + return c.doRequest(req, expectedStatusCode) +} +func (c *Client) doRequest(req *http.Request, expectedStatusCode int) ([]byte, error) { for _, h := range c.Headers { req.Header.Set(h.Key, h.Value) } diff --git a/sftpgo/client/folders.go b/sftpgo/client/folders.go index 8a02828..fa947fd 100644 --- a/sftpgo/client/folders.go +++ b/sftpgo/client/folders.go @@ -31,7 +31,7 @@ func (c *Client) GetFolders() ([]sdk.BaseVirtualFolder, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func (c *Client) CreateFolder(folder sdk.BaseVirtualFolder) (*sdk.BaseVirtualFol return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func (c *Client) GetFolder(name string) (*sdk.BaseVirtualFolder, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func (c *Client) UpdateFolder(folder sdk.BaseVirtualFolder) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -105,6 +105,6 @@ func (c *Client) DeleteFolder(name string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/groups.go b/sftpgo/client/groups.go index 3429777..4bc607b 100644 --- a/sftpgo/client/groups.go +++ b/sftpgo/client/groups.go @@ -31,7 +31,7 @@ func (c *Client) GetGroups() ([]sdk.Group, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func (c *Client) CreateGroup(group sdk.Group) (*sdk.Group, error) { return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func (c *Client) GetGroup(name string) (*sdk.Group, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func (c *Client) UpdateGroup(group sdk.Group) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -105,6 +105,6 @@ func (c *Client) DeleteGroup(name string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/iplists.go b/sftpgo/client/iplists.go index 4d7c27b..2fc884d 100644 --- a/sftpgo/client/iplists.go +++ b/sftpgo/client/iplists.go @@ -55,7 +55,7 @@ func (c *Client) GetIPListEntries(listType int) ([]IPListEntry, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -86,7 +86,7 @@ func (c *Client) CreateIPListEntry(entry IPListEntry) (*IPListEntry, error) { return nil, err } - _, err = c.doRequest(req, http.StatusCreated) + _, err = c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -100,7 +100,7 @@ func (c *Client) GetIPListEntry(listType int, ipOrNet string) (*IPListEntry, err if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -122,7 +122,7 @@ func (c *Client) UpdateIPListEntry(entry IPListEntry) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -133,6 +133,6 @@ func (c *Client) DeleteIPListEntry(listType int, ipOrNet string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/roles.go b/sftpgo/client/roles.go index eb802d5..7cd8f65 100644 --- a/sftpgo/client/roles.go +++ b/sftpgo/client/roles.go @@ -45,7 +45,7 @@ func (c *Client) GetRoles() ([]Role, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -75,7 +75,7 @@ func (c *Client) CreateRole(role Role) (*Role, error) { return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -91,7 +91,7 @@ func (c *Client) GetRole(name string) (*Role, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -113,7 +113,7 @@ func (c *Client) UpdateRole(role Role) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -123,6 +123,6 @@ func (c *Client) DeleteRole(name string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/rules.go b/sftpgo/client/rules.go index ae38c41..f9d977e 100644 --- a/sftpgo/client/rules.go +++ b/sftpgo/client/rules.go @@ -112,7 +112,7 @@ func (c *Client) GetRules() ([]EventRule, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -142,7 +142,7 @@ func (c *Client) CreateRule(rule EventRule) (*EventRule, error) { return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -158,7 +158,7 @@ func (c *Client) GetRule(name string) (*EventRule, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -180,7 +180,7 @@ func (c *Client) UpdateRule(rule EventRule) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -190,6 +190,6 @@ func (c *Client) DeleteRule(name string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } diff --git a/sftpgo/client/users.go b/sftpgo/client/users.go index ec95ab8..d55b788 100644 --- a/sftpgo/client/users.go +++ b/sftpgo/client/users.go @@ -40,7 +40,7 @@ func (c *Client) GetUsers() ([]User, error) { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func (c *Client) CreateUser(user User) (*User, error) { return nil, err } - body, err := c.doRequest(req, http.StatusCreated) + body, err := c.doRequestWithAuth(req, http.StatusCreated) if err != nil { return nil, err } @@ -83,7 +83,7 @@ func (c *Client) GetUser(username string) (*User, error) { if err != nil { return nil, err } - body, err := c.doRequest(req, http.StatusOK) + body, err := c.doRequestWithAuth(req, http.StatusOK) if err != nil { return nil, err } @@ -105,7 +105,7 @@ func (c *Client) UpdateUser(user User) error { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err } @@ -115,6 +115,6 @@ func (c *Client) DeleteUser(username string) error { if err != nil { return err } - _, err = c.doRequest(req, http.StatusOK) + _, err = c.doRequestWithAuth(req, http.StatusOK) return err }