Skip to content

Commit

Permalink
fix: change zitadel clients to singleton pattern for better token han…
Browse files Browse the repository at this point in the history
fix: change zitadel clients to singleton pattern for better token han…
  • Loading branch information
stebenz authored Sep 13, 2023
2 parents 1f6c5a8 + c096cf0 commit 9e235a5
Show file tree
Hide file tree
Showing 47 changed files with 423 additions and 416 deletions.
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/envoyproxy/protoc-gen-validate v1.0.2
github.com/gabriel-vasile/mimetype v1.4.1
github.com/gogo/protobuf v1.3.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/hcl/v2 v2.16.2
github.com/hashicorp/terraform-plugin-framework v0.15.0
Expand All @@ -16,9 +16,9 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/zclconf/go-cty v1.13.1
github.com/zitadel/oidc v1.13.4
github.com/zitadel/zitadel-go/v2 v2.0.15
golang.org/x/oauth2 v0.10.0
google.golang.org/grpc v1.57.0-dev
github.com/zitadel/zitadel-go/v2 v2.0.19
golang.org/x/oauth2 v0.11.0
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
)

Expand Down Expand Up @@ -60,14 +60,14 @@ require (
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
github.com/vmihailenco/tagparser v0.1.1 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 // indirect
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)
46 changes: 23 additions & 23 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 h1:LSsiG61v9IzzxMkqEr6nrix4miJI62xlRjwT7BYD2SM=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1/go.mod h1:Hbb13e3/WtqQ8U5hLGkek9gJvBLasHuPFI0UEGfnQ10=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down Expand Up @@ -211,8 +211,8 @@ github.com/zclconf/go-cty v1.13.1 h1:0a6bRwuiSHtAmqCqNOE+c2oHgepv0ctoxU4FUe43kwc
github.com/zclconf/go-cty v1.13.1/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0=
github.com/zitadel/oidc v1.13.4 h1:+k2GKqP9Ld9S2MSFlj+KaNsoZ3J9oy+Ezw51EzSFuC8=
github.com/zitadel/oidc v1.13.4/go.mod h1:3h2DhUcP02YV6q/CA/BG4yla0o6rXjK+DkJGK/dwJfw=
github.com/zitadel/zitadel-go/v2 v2.0.15 h1:dL2VROG7w32xtdl2DlPqpef6+s7PEP70KEa3SEjGsuI=
github.com/zitadel/zitadel-go/v2 v2.0.15/go.mod h1:2xpHigKocm9hVdNuAHo9eway/jGSo6XhyunbfGr7924=
github.com/zitadel/zitadel-go/v2 v2.0.19 h1:oLs2iLfPGqMLrgtzHoffnLBWHfk8JmTSXZFCXRgb+YM=
github.com/zitadel/zitadel-go/v2 v2.0.19/go.mod h1:pCT8y65qnRqTDBFf7UT5+6NAsAdfjgQCfn4BQ6pMWZ0=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
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=
Expand All @@ -223,8 +223,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
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.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand All @@ -247,11 +247,11 @@ golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5o
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
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.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU=
golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
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=
Expand Down Expand Up @@ -279,19 +279,19 @@ 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.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/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.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
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.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand All @@ -306,14 +306,14 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e h1:Ao9GzfUMPH3zjVfzXG5rlWlk+Q8MXWKwWpwVQE1MXfw=
google.golang.org/genproto v0.0.0-20230526203410-71b5a4ffd15e/go.mod h1:zqTuNwFlFRsw5zIts5VnzLQxSRqh+CGOTVMlYbY0Eyk=
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc h1:kVKPf/IiYSBWEWtkIn6wZXwWGCnLKcC8oWfZvXjsGnM=
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:vHYtlOoi6TsQ3Uk2yxR7NI5z8uoV+3pZtR4jmHIkRig=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529 h1:DEH99RbiLZhMxrpEJCZ0A+wdTe0EOgou/poSLx9vWf4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230629202037-9506855d4529/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
google.golang.org/grpc v1.57.0-dev h1:XCvzqke2TBzQUs3a1MO1VsqVkWeAdJ/KmxHCAVtPpe8=
google.golang.org/grpc v1.57.0-dev/go.mod h1:ZPf89/axrdgRDfHqb7fa0GF5t4VUER0vWnqnPNuRP7k=
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g=
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8=
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q=
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M=
google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
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.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
Expand Down
16 changes: 8 additions & 8 deletions zitadel/action/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -32,7 +32,7 @@ func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.FromErr(err)
}

_, err = client.UpdateAction(ctx, &management.UpdateActionRequest{
_, err = client.UpdateAction(helper.CtxWithOrgID(ctx, d), &management.UpdateActionRequest{
Id: d.Id(),
Name: d.Get(NameVar).(string),
Script: d.Get(ScriptVar).(string),
Expand All @@ -53,12 +53,12 @@ func delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

_, err = client.DeleteAction(ctx, &management.DeleteActionRequest{
_, err = client.DeleteAction(helper.CtxWithOrgID(ctx, d), &management.DeleteActionRequest{
Id: d.Id(),
})
if err != nil {
Expand All @@ -75,7 +75,7 @@ func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -85,7 +85,7 @@ func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.FromErr(err)
}

resp, err := client.CreateAction(ctx, &management.CreateActionRequest{
resp, err := client.CreateAction(helper.CtxWithOrgID(ctx, d), &management.CreateActionRequest{
Name: d.Get(NameVar).(string),
Script: d.Get(ScriptVar).(string),
Timeout: durationpb.New(timeout),
Expand All @@ -106,12 +106,12 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

resp, err := client.ListActions(ctx, &management.ListActionsRequest{
resp, err := client.ListActions(helper.CtxWithOrgID(ctx, d), &management.ListActionsRequest{
Queries: []*management.ActionQuery{
{Query: &management.ActionQuery_ActionIdQuery{
ActionIdQuery: &action.ActionIDQuery{
Expand Down
18 changes: 9 additions & 9 deletions zitadel/application_api/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ func delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

_, err = client.RemoveApp(ctx, &management.RemoveAppRequest{
_, err = client.RemoveApp(helper.CtxWithOrgID(ctx, d), &management.RemoveAppRequest{
ProjectId: d.Get(ProjectIDVar).(string),
AppId: d.Id(),
})
Expand All @@ -43,14 +43,14 @@ func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

projectID := d.Get(ProjectIDVar).(string)
if d.HasChange(NameVar) {
_, err = client.UpdateApp(ctx, &management.UpdateAppRequest{
_, err = client.UpdateApp(helper.CtxWithOrgID(ctx, d), &management.UpdateAppRequest{
ProjectId: projectID,
AppId: d.Id(),
Name: d.Get(NameVar).(string),
Expand All @@ -61,7 +61,7 @@ func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
}

if d.HasChanges(authMethodTypeVar) {
_, err = client.UpdateAPIAppConfig(ctx, &management.UpdateAPIAppConfigRequest{
_, err = client.UpdateAPIAppConfig(helper.CtxWithOrgID(ctx, d), &management.UpdateAPIAppConfigRequest{
ProjectId: projectID,
AppId: d.Id(),
AuthMethodType: app.APIAuthMethodType(app.APIAuthMethodType_value[d.Get(authMethodTypeVar).(string)]),
Expand All @@ -81,12 +81,12 @@ func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

resp, err := client.AddAPIApp(ctx, &management.AddAPIAppRequest{
resp, err := client.AddAPIApp(helper.CtxWithOrgID(ctx, d), &management.AddAPIAppRequest{
ProjectId: d.Get(ProjectIDVar).(string),
Name: d.Get(NameVar).(string),
AuthMethodType: app.APIAuthMethodType(app.APIAuthMethodType_value[(d.Get(authMethodTypeVar).(string))]),
Expand Down Expand Up @@ -116,12 +116,12 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

resp, err := client.GetAppByID(ctx, &management.GetAppByIDRequest{ProjectId: d.Get(ProjectIDVar).(string), AppId: helper.GetID(d, AppIDVar)})
resp, err := client.GetAppByID(helper.CtxWithOrgID(ctx, d), &management.GetAppByIDRequest{ProjectId: d.Get(ProjectIDVar).(string), AppId: helper.GetID(d, AppIDVar)})
if err != nil && helper.IgnoreIfNotFoundError(err) == nil {
d.SetId("")
return nil
Expand Down
16 changes: 7 additions & 9 deletions zitadel/application_key/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

client, err := helper.GetManagementClient(clientinfo, d.Get(helper.OrgIDVar).(string))
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

_, err = client.RemoveAppKey(ctx, &management.RemoveAppKeyRequest{
_, err = client.RemoveAppKey(helper.CtxWithOrgID(ctx, d), &management.RemoveAppKeyRequest{
ProjectId: d.Get(ProjectIDVar).(string),
AppId: d.Get(AppIDVar).(string),
KeyId: d.Id(),
Expand All @@ -46,8 +46,7 @@ func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
return diag.Errorf("failed to get client")
}

orgID := d.Get(helper.OrgIDVar).(string)
client, err := helper.GetManagementClient(clientinfo, orgID)
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -67,7 +66,7 @@ func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
req.ExpirationDate = timestamppb.New(t)
}

resp, err := client.AddAppKey(ctx, req)
resp, err := client.AddAppKey(helper.CtxWithOrgID(ctx, d), req)
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -85,15 +84,14 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
return diag.Errorf("failed to get client")
}

orgID := d.Get(helper.OrgIDVar).(string)
client, err := helper.GetManagementClient(clientinfo, orgID)
client, err := helper.GetManagementClient(clientinfo)
if err != nil {
return diag.FromErr(err)
}

projectID := d.Get(ProjectIDVar).(string)
appID := d.Get(AppIDVar).(string)
resp, err := client.GetAppKey(ctx, &management.GetAppKeyRequest{
resp, err := client.GetAppKey(helper.CtxWithOrgID(ctx, d), &management.GetAppKeyRequest{
ProjectId: projectID,
AppId: appID,
KeyId: d.Id(),
Expand All @@ -111,7 +109,7 @@ func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
ExpirationDateVar: resp.GetKey().GetExpirationDate().AsTime().Format(time.RFC3339),
ProjectIDVar: projectID,
AppIDVar: appID,
helper.OrgIDVar: orgID,
helper.OrgIDVar: d.Get(helper.OrgIDVar).(string),
keyTypeVar: resp.GetKey().GetType().String(),
}
for k, v := range set {
Expand Down
Loading

0 comments on commit 9e235a5

Please sign in to comment.