diff --git a/internal/provider/datasource-account.go b/internal/provider/datasource-account.go index b691a90..aea94e1 100644 --- a/internal/provider/datasource-account.go +++ b/internal/provider/datasource-account.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/account" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -29,7 +30,7 @@ func NewAccountDataSource() datasource.DataSource { } type accountDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *accountDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *accountDataSource) Configure(ctx context.Context, req datasource.Config return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *accountDataSource) Configure(ctx context.Context, req datasource.Config return } - d.client = client + d.providerData = providerData } func (d *accountDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *accountDataSource) Read(ctx context.Context, req datasource.ReadRequest }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Account().Get(ctx, &keyhubreq.AccountRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Account().Get(ctx, &keyhubreq.AccountRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.AccountRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-certificate.go b/internal/provider/datasource-certificate.go index c9eda70..b6268bc 100644 --- a/internal/provider/datasource-certificate.go +++ b/internal/provider/datasource-certificate.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/certificate" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -29,7 +30,7 @@ func NewCertificateDataSource() datasource.DataSource { } type certificateDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *certificateDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *certificateDataSource) Configure(ctx context.Context, req datasource.Co return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *certificateDataSource) Configure(ctx context.Context, req datasource.Co return } - d.client = client + d.providerData = providerData } func (d *certificateDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *certificateDataSource) Read(ctx context.Context, req datasource.ReadReq }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Certificate().Get(ctx, &keyhubreq.CertificateRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Certificate().Get(ctx, &keyhubreq.CertificateRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.CertificateRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-client.go b/internal/provider/datasource-client.go index eeb64cd..1bd9c40 100644 --- a/internal/provider/datasource-client.go +++ b/internal/provider/datasource-client.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/client" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -29,7 +30,7 @@ func NewClientDataSource() datasource.DataSource { } type clientDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *clientDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *clientDataSource) Configure(ctx context.Context, req datasource.Configu return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *clientDataSource) Configure(ctx context.Context, req datasource.Configu return } - d.client = client + d.providerData = providerData } func (d *clientDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *clientDataSource) Read(ctx context.Context, req datasource.ReadRequest, }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Client().Get(ctx, &keyhubreq.ClientRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Client().Get(ctx, &keyhubreq.ClientRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.ClientRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-directory.go b/internal/provider/datasource-directory.go index d08af26..4e63a67 100644 --- a/internal/provider/datasource-directory.go +++ b/internal/provider/datasource-directory.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/directory" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -29,7 +30,7 @@ func NewDirectoryDataSource() datasource.DataSource { } type directoryDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *directoryDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *directoryDataSource) Configure(ctx context.Context, req datasource.Conf return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *directoryDataSource) Configure(ctx context.Context, req datasource.Conf return } - d.client = client + d.providerData = providerData } func (d *directoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *directoryDataSource) Read(ctx context.Context, req datasource.ReadReque }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Directory().Get(ctx, &keyhubreq.DirectoryRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Directory().Get(ctx, &keyhubreq.DirectoryRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.DirectoryRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-group.go b/internal/provider/datasource-group.go index 7a30cb4..27d7235 100644 --- a/internal/provider/datasource-group.go +++ b/internal/provider/datasource-group.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/group" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -29,7 +30,7 @@ func NewGroupDataSource() datasource.DataSource { } type groupDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *groupDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *groupDataSource) Configure(ctx context.Context, req datasource.Configur return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *groupDataSource) Configure(ctx context.Context, req datasource.Configur return } - d.client = client + d.providerData = providerData } func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *groupDataSource) Read(ctx context.Context, req datasource.ReadRequest, }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Group().Get(ctx, &keyhubreq.GroupRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Group().Get(ctx, &keyhubreq.GroupRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.GroupRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-groupclassification.go b/internal/provider/datasource-groupclassification.go index 95d0d1f..cb2cbe0 100644 --- a/internal/provider/datasource-groupclassification.go +++ b/internal/provider/datasource-groupclassification.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/groupclassification" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -29,7 +30,7 @@ func NewGroupclassificationDataSource() datasource.DataSource { } type groupclassificationDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *groupclassificationDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *groupclassificationDataSource) Configure(ctx context.Context, req datas return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *groupclassificationDataSource) Configure(ctx context.Context, req datas return } - d.client = client + d.providerData = providerData } func (d *groupclassificationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *groupclassificationDataSource) Read(ctx context.Context, req datasource }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Groupclassification().Get(ctx, &keyhubreq.GroupclassificationRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Groupclassification().Get(ctx, &keyhubreq.GroupclassificationRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.GroupclassificationRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-organizationalunit.go b/internal/provider/datasource-organizationalunit.go index 04d96d6..5356608 100644 --- a/internal/provider/datasource-organizationalunit.go +++ b/internal/provider/datasource-organizationalunit.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/organizationalunit" ) @@ -29,7 +30,7 @@ func NewOrganizationalunitDataSource() datasource.DataSource { } type organizationalunitDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *organizationalunitDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *organizationalunitDataSource) Configure(ctx context.Context, req dataso return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *organizationalunitDataSource) Configure(ctx context.Context, req dataso return } - d.client = client + d.providerData = providerData } func (d *organizationalunitDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *organizationalunitDataSource) Read(ctx context.Context, req datasource. }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Organizationalunit().Get(ctx, &keyhubreq.OrganizationalunitRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Organizationalunit().Get(ctx, &keyhubreq.OrganizationalunitRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.OrganizationalunitRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-serviceaccount.go b/internal/provider/datasource-serviceaccount.go index 969177f..a19cda4 100644 --- a/internal/provider/datasource-serviceaccount.go +++ b/internal/provider/datasource-serviceaccount.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/serviceaccount" ) @@ -29,7 +30,7 @@ func NewServiceaccountDataSource() datasource.DataSource { } type serviceaccountDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *serviceaccountDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *serviceaccountDataSource) Configure(ctx context.Context, req datasource return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *serviceaccountDataSource) Configure(ctx context.Context, req datasource return } - d.client = client + d.providerData = providerData } func (d *serviceaccountDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *serviceaccountDataSource) Read(ctx context.Context, req datasource.Read }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Serviceaccount().Get(ctx, &keyhubreq.ServiceaccountRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Serviceaccount().Get(ctx, &keyhubreq.ServiceaccountRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.ServiceaccountRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-system.go b/internal/provider/datasource-system.go index 8170786..aea0964 100644 --- a/internal/provider/datasource-system.go +++ b/internal/provider/datasource-system.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/system" ) @@ -29,7 +30,7 @@ func NewSystemDataSource() datasource.DataSource { } type systemDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *systemDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *systemDataSource) Configure(ctx context.Context, req datasource.Configu return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *systemDataSource) Configure(ctx context.Context, req datasource.Configu return } - d.client = client + d.providerData = providerData } func (d *systemDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *systemDataSource) Read(ctx context.Context, req datasource.ReadRequest, }) uuid := data.UUID.ValueString() - wrapper, err := d.client.System().Get(ctx, &keyhubreq.SystemRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.System().Get(ctx, &keyhubreq.SystemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.SystemRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-vaultrecord.go b/internal/provider/datasource-vaultrecord.go index 0573673..bba4220 100644 --- a/internal/provider/datasource-vaultrecord.go +++ b/internal/provider/datasource-vaultrecord.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/vaultrecord" ) @@ -29,7 +30,7 @@ func NewVaultrecordDataSource() datasource.DataSource { } type vaultrecordDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *vaultrecordDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *vaultrecordDataSource) Configure(ctx context.Context, req datasource.Co return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *vaultrecordDataSource) Configure(ctx context.Context, req datasource.Co return } - d.client = client + d.providerData = providerData } func (d *vaultrecordDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *vaultrecordDataSource) Read(ctx context.Context, req datasource.ReadReq }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Vaultrecord().Get(ctx, &keyhubreq.VaultrecordRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Vaultrecord().Get(ctx, &keyhubreq.VaultrecordRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.VaultrecordRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/datasource-webhook.go b/internal/provider/datasource-webhook.go index b5bd1a0..d409ada 100644 --- a/internal/provider/datasource-webhook.go +++ b/internal/provider/datasource-webhook.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -13,7 +15,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/webhook" ) @@ -29,7 +30,7 @@ func NewWebhookDataSource() datasource.DataSource { } type webhookDataSource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (d *webhookDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { @@ -49,7 +50,7 @@ func (d *webhookDataSource) Configure(ctx context.Context, req datasource.Config return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -60,7 +61,7 @@ func (d *webhookDataSource) Configure(ctx context.Context, req datasource.Config return } - d.client = client + d.providerData = providerData } func (d *webhookDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { @@ -77,7 +78,9 @@ func (d *webhookDataSource) Read(ctx context.Context, req datasource.ReadRequest }) uuid := data.UUID.ValueString() - wrapper, err := d.client.Webhook().Get(ctx, &keyhubreq.WebhookRequestBuilderGetRequestConfiguration{ + d.providerData.Mutex.RLock() + defer d.providerData.Mutex.RUnlock() + wrapper, err := d.providerData.Client.Webhook().Get(ctx, &keyhubreq.WebhookRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.WebhookRequestBuilderGetQueryParameters{ Uuid: []string{uuid}, Additional: additional, diff --git a/internal/provider/full-data-struct-ds.go b/internal/provider/full-data-struct-ds.go index 9281aee..7555ef2 100644 --- a/internal/provider/full-data-struct-ds.go +++ b/internal/provider/full-data-struct-ds.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-data-struct-rs.go b/internal/provider/full-data-struct-rs.go index 169897a..c48718c 100644 --- a/internal/provider/full-data-struct-rs.go +++ b/internal/provider/full-data-struct-rs.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-helpers.go b/internal/provider/full-helpers.go index be9bb42..03cf6c8 100644 --- a/internal/provider/full-helpers.go +++ b/internal/provider/full-helpers.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-object-attrs-ds.go b/internal/provider/full-object-attrs-ds.go index c6e1905..5a96065 100644 --- a/internal/provider/full-object-attrs-ds.go +++ b/internal/provider/full-object-attrs-ds.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-object-attrs-rs.go b/internal/provider/full-object-attrs-rs.go index 9b82103..32c30e9 100644 --- a/internal/provider/full-object-attrs-rs.go +++ b/internal/provider/full-object-attrs-rs.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-schema-ds.go b/internal/provider/full-schema-ds.go index 63241ad..0de1531 100644 --- a/internal/provider/full-schema-ds.go +++ b/internal/provider/full-schema-ds.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-schema-rs.go b/internal/provider/full-schema-rs.go index a7bd478..19af928 100644 --- a/internal/provider/full-schema-rs.go +++ b/internal/provider/full-schema-rs.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-tf-to-data-struct-ds.go b/internal/provider/full-tf-to-data-struct-ds.go index 1e3d9b3..0b5ed66 100644 --- a/internal/provider/full-tf-to-data-struct-ds.go +++ b/internal/provider/full-tf-to-data-struct-ds.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-tf-to-data-struct-rs.go b/internal/provider/full-tf-to-data-struct-rs.go index 7461d1d..642f673 100644 --- a/internal/provider/full-tf-to-data-struct-rs.go +++ b/internal/provider/full-tf-to-data-struct-rs.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-tf-to-tkh-ds.go b/internal/provider/full-tf-to-tkh-ds.go index 668d0d4..29e14b3 100644 --- a/internal/provider/full-tf-to-tkh-ds.go +++ b/internal/provider/full-tf-to-tkh-ds.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-tf-to-tkh-rs.go b/internal/provider/full-tf-to-tkh-rs.go index 981b944..93328da 100644 --- a/internal/provider/full-tf-to-tkh-rs.go +++ b/internal/provider/full-tf-to-tkh-rs.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-tkh-to-tf-ds.go b/internal/provider/full-tkh-to-tf-ds.go index 309c4a5..c8916f0 100644 --- a/internal/provider/full-tkh-to-tf-ds.go +++ b/internal/provider/full-tkh-to-tf-ds.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/full-tkh-to-tf-rs.go b/internal/provider/full-tkh-to-tf-rs.go index de0ceca..b0d13c1 100644 --- a/internal/provider/full-tkh-to-tf-rs.go +++ b/internal/provider/full-tkh-to-tf-rs.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 //lint:ignore U1000 Ignore unused functions in generated code package provider diff --git a/internal/provider/provider.go b/internal/provider/provider.go index be5bced..3fbe1e1 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -7,6 +7,7 @@ import ( "context" "net/http" "os" + "sync" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/path" @@ -37,6 +38,11 @@ type KeyHubProviderModel struct { ClientSecret types.String `tfsdk:"clientsecret"` } +type KeyHubProviderData struct { + Client *keyhub.KeyHubClient + Mutex sync.RWMutex +} + func (p *KeyHubProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { resp.TypeName = ProviderName resp.Version = p.version @@ -162,9 +168,11 @@ func (p *KeyHubProvider) Configure(ctx context.Context, req provider.ConfigureRe return } - client := keyhub.NewKeyHubClient(adapter) - resp.DataSourceData = client - resp.ResourceData = client + data := &KeyHubProviderData{ + Client: keyhub.NewKeyHubClient(adapter), + } + resp.DataSourceData = data + resp.ResourceData = data tflog.Info(ctx, "Connected to Topicus KeyHub", map[string]any{"success": true}) } diff --git a/internal/provider/resource-client_vaultrecord.go b/internal/provider/resource-client_vaultrecord.go index f7d5d21..54da346 100644 --- a/internal/provider/resource-client_vaultrecord.go +++ b/internal/provider/resource-client_vaultrecord.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -11,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/client" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -28,7 +29,7 @@ func NewClientVaultrecordResource() resource.Resource { } type clientVaultrecordResource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (r *clientVaultrecordResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -48,7 +49,7 @@ func (r *clientVaultrecordResource) Configure(ctx context.Context, req resource. return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -59,7 +60,7 @@ func (r *clientVaultrecordResource) Configure(ctx context.Context, req resource. return } - r.client = client + r.providerData = providerData } func (r *clientVaultrecordResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -69,7 +70,7 @@ func (r *clientVaultrecordResource) Create(ctx context.Context, req resource.Cre return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, clientApplicationVaultVaultRecordAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -82,6 +83,8 @@ func (r *clientVaultrecordResource) Create(ctx context.Context, req resource.Cre return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Creating Topicus KeyHub client_vaultrecord") newWrapper := keyhubmodels.NewVaultVaultRecordLinkableWrapper() newWrapper.SetItems([]keyhubmodels.VaultVaultRecordable{newTkh}) @@ -91,7 +94,7 @@ func (r *clientVaultrecordResource) Create(ctx context.Context, req resource.Cre return } - wrapper, err := r.client.Client().ByClientidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().Post( + wrapper, err := r.providerData.Client.Client().ByClientidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().Post( ctx, newWrapper, &keyhubreq.ItemVaultRecordRequestBuilderPostRequestConfiguration{ QueryParameters: &keyhubreq.ItemVaultRecordRequestBuilderPostQueryParameters{ Additional: collectAdditional(data), @@ -124,7 +127,9 @@ func (r *clientVaultrecordResource) Read(ctx context.Context, req resource.ReadR return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.RLock() + defer r.providerData.Mutex.RUnlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Reading client_vaultrecord from Topicus KeyHub") tkhParent, diags := findClientClientApplicationPrimerByUUID(ctx, data.ClientApplicationUUID.ValueStringPointer()) resp.Diagnostics.Append(diags...) @@ -132,7 +137,7 @@ func (r *clientVaultrecordResource) Read(ctx context.Context, req resource.ReadR return } - tkh, err := r.client.Client().ByClientidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( + tkh, err := r.providerData.Client.Client().ByClientidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( ctx, &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderGetQueryParameters{ Additional: collectAdditional(data), @@ -161,7 +166,7 @@ func (r *clientVaultrecordResource) Update(ctx context.Context, req resource.Upd return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, clientApplicationVaultVaultRecordAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -174,6 +179,8 @@ func (r *clientVaultrecordResource) Update(ctx context.Context, req resource.Upd return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Updating Topicus KeyHub client_vaultrecord") tkhParent, diags := findClientClientApplicationPrimerByUUID(ctx, data.ClientApplicationUUID.ValueStringPointer()) resp.Diagnostics.Append(diags...) @@ -181,7 +188,7 @@ func (r *clientVaultrecordResource) Update(ctx context.Context, req resource.Upd return } - tkh, err := r.client.Client().ByClientidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Put( + tkh, err := r.providerData.Client.Client().ByClientidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Put( ctx, newTkh, &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderPutRequestConfiguration{ QueryParameters: &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderPutQueryParameters{ Additional: collectAdditional(data), @@ -211,9 +218,11 @@ func (r *clientVaultrecordResource) Delete(ctx context.Context, req resource.Del return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Deleting client_vaultrecord from Topicus KeyHub") - err := r.client.Client().ByClientidInt64(-1).Vault().Record().ByRecordidInt64(-1).WithUrl(getSelfLink(data.Links).Href.ValueString()).Delete(ctx, nil) + err := r.providerData.Client.Client().ByClientidInt64(-1).Vault().Record().ByRecordidInt64(-1).WithUrl(getSelfLink(data.Links).Href.ValueString()).Delete(ctx, nil) if !isHttpStatusCodeOk(ctx, 404, err, &resp.Diagnostics) { return } diff --git a/internal/provider/resource-clientapplication.go b/internal/provider/resource-clientapplication.go index b259462..9bcb309 100644 --- a/internal/provider/resource-clientapplication.go +++ b/internal/provider/resource-clientapplication.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -11,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/client" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -28,7 +29,7 @@ func NewClientapplicationResource() resource.Resource { } type clientapplicationResource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (r *clientapplicationResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -48,7 +49,7 @@ func (r *clientapplicationResource) Configure(ctx context.Context, req resource. return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -59,7 +60,7 @@ func (r *clientapplicationResource) Configure(ctx context.Context, req resource. return } - r.client = client + r.providerData = providerData } func (r *clientapplicationResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -69,7 +70,7 @@ func (r *clientapplicationResource) Create(ctx context.Context, req resource.Cre return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, clientClientApplicationAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -82,10 +83,12 @@ func (r *clientapplicationResource) Create(ctx context.Context, req resource.Cre return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Creating Topicus KeyHub clientapplication") newWrapper := keyhubmodels.NewClientClientApplicationLinkableWrapper() newWrapper.SetItems([]keyhubmodels.ClientClientApplicationable{newTkh}) - wrapper, err := r.client.Client().Post( + wrapper, err := r.providerData.Client.Client().Post( ctx, newWrapper, &keyhubreq.ClientRequestBuilderPostRequestConfiguration{ QueryParameters: &keyhubreq.ClientRequestBuilderPostQueryParameters{ Additional: collectAdditional(data), @@ -117,9 +120,11 @@ func (r *clientapplicationResource) Read(ctx context.Context, req resource.ReadR return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.RLock() + defer r.providerData.Mutex.RUnlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Reading clientapplication from Topicus KeyHub") - tkh, err := r.client.Client().ByClientidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( + tkh, err := r.providerData.Client.Client().ByClientidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( ctx, &keyhubreq.WithClientItemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.WithClientItemRequestBuilderGetQueryParameters{ Additional: collectAdditional(data), diff --git a/internal/provider/resource-group.go b/internal/provider/resource-group.go index bc5d1b4..f14a18f 100644 --- a/internal/provider/resource-group.go +++ b/internal/provider/resource-group.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -11,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/group" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -28,7 +29,7 @@ func NewGroupResource() resource.Resource { } type groupResource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (r *groupResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -48,7 +49,7 @@ func (r *groupResource) Configure(ctx context.Context, req resource.ConfigureReq return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -59,7 +60,7 @@ func (r *groupResource) Configure(ctx context.Context, req resource.ConfigureReq return } - r.client = client + r.providerData = providerData } func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -69,7 +70,7 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, groupGroupAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -82,10 +83,12 @@ func (r *groupResource) Create(ctx context.Context, req resource.CreateRequest, return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Creating Topicus KeyHub group") newWrapper := keyhubmodels.NewGroupGroupLinkableWrapper() newWrapper.SetItems([]keyhubmodels.GroupGroupable{newTkh}) - wrapper, err := r.client.Group().Post( + wrapper, err := r.providerData.Client.Group().Post( ctx, newWrapper, &keyhubreq.GroupRequestBuilderPostRequestConfiguration{ QueryParameters: &keyhubreq.GroupRequestBuilderPostQueryParameters{ Additional: collectAdditional(data), @@ -117,9 +120,11 @@ func (r *groupResource) Read(ctx context.Context, req resource.ReadRequest, resp return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.RLock() + defer r.providerData.Mutex.RUnlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Reading group from Topicus KeyHub") - tkh, err := r.client.Group().ByGroupidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( + tkh, err := r.providerData.Client.Group().ByGroupidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( ctx, &keyhubreq.WithGroupItemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.WithGroupItemRequestBuilderGetQueryParameters{ Additional: collectAdditional(data), diff --git a/internal/provider/resource-group_vaultrecord.go b/internal/provider/resource-group_vaultrecord.go index 06dca83..b59cf36 100644 --- a/internal/provider/resource-group_vaultrecord.go +++ b/internal/provider/resource-group_vaultrecord.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -11,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubreq "github.com/topicuskeyhub/sdk-go/group" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" ) @@ -28,7 +29,7 @@ func NewGroupVaultrecordResource() resource.Resource { } type groupVaultrecordResource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (r *groupVaultrecordResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -48,7 +49,7 @@ func (r *groupVaultrecordResource) Configure(ctx context.Context, req resource.C return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -59,7 +60,7 @@ func (r *groupVaultrecordResource) Configure(ctx context.Context, req resource.C return } - r.client = client + r.providerData = providerData } func (r *groupVaultrecordResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -69,7 +70,7 @@ func (r *groupVaultrecordResource) Create(ctx context.Context, req resource.Crea return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, groupVaultVaultRecordAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -82,6 +83,8 @@ func (r *groupVaultrecordResource) Create(ctx context.Context, req resource.Crea return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Creating Topicus KeyHub group_vaultrecord") newWrapper := keyhubmodels.NewVaultVaultRecordLinkableWrapper() newWrapper.SetItems([]keyhubmodels.VaultVaultRecordable{newTkh}) @@ -91,7 +94,7 @@ func (r *groupVaultrecordResource) Create(ctx context.Context, req resource.Crea return } - wrapper, err := r.client.Group().ByGroupidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().Post( + wrapper, err := r.providerData.Client.Group().ByGroupidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().Post( ctx, newWrapper, &keyhubreq.ItemVaultRecordRequestBuilderPostRequestConfiguration{ QueryParameters: &keyhubreq.ItemVaultRecordRequestBuilderPostQueryParameters{ Additional: collectAdditional(data), @@ -124,7 +127,9 @@ func (r *groupVaultrecordResource) Read(ctx context.Context, req resource.ReadRe return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.RLock() + defer r.providerData.Mutex.RUnlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Reading group_vaultrecord from Topicus KeyHub") tkhParent, diags := findGroupGroupPrimerByUUID(ctx, data.GroupUUID.ValueStringPointer()) resp.Diagnostics.Append(diags...) @@ -132,7 +137,7 @@ func (r *groupVaultrecordResource) Read(ctx context.Context, req resource.ReadRe return } - tkh, err := r.client.Group().ByGroupidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( + tkh, err := r.providerData.Client.Group().ByGroupidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( ctx, &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderGetQueryParameters{ Additional: collectAdditional(data), @@ -161,7 +166,7 @@ func (r *groupVaultrecordResource) Update(ctx context.Context, req resource.Upda return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, groupVaultVaultRecordAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -174,6 +179,8 @@ func (r *groupVaultrecordResource) Update(ctx context.Context, req resource.Upda return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Updating Topicus KeyHub group_vaultrecord") tkhParent, diags := findGroupGroupPrimerByUUID(ctx, data.GroupUUID.ValueStringPointer()) resp.Diagnostics.Append(diags...) @@ -181,7 +188,7 @@ func (r *groupVaultrecordResource) Update(ctx context.Context, req resource.Upda return } - tkh, err := r.client.Group().ByGroupidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Put( + tkh, err := r.providerData.Client.Group().ByGroupidInt64(*tkhParent.GetLinks()[0].GetId()).Vault().Record().ByRecordidInt64(getSelfLink(data.Links).ID.ValueInt64()).Put( ctx, newTkh, &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderPutRequestConfiguration{ QueryParameters: &keyhubreq.ItemVaultRecordWithRecordItemRequestBuilderPutQueryParameters{ Additional: collectAdditional(data), @@ -211,9 +218,11 @@ func (r *groupVaultrecordResource) Delete(ctx context.Context, req resource.Dele return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Deleting group_vaultrecord from Topicus KeyHub") - err := r.client.Group().ByGroupidInt64(-1).Vault().Record().ByRecordidInt64(-1).WithUrl(getSelfLink(data.Links).Href.ValueString()).Delete(ctx, nil) + err := r.providerData.Client.Group().ByGroupidInt64(-1).Vault().Record().ByRecordidInt64(-1).WithUrl(getSelfLink(data.Links).Href.ValueString()).Delete(ctx, nil) if !isHttpStatusCodeOk(ctx, 404, err, &resp.Diagnostics) { return } diff --git a/internal/provider/resource-grouponsystem.go b/internal/provider/resource-grouponsystem.go index d19db29..655e0d2 100644 --- a/internal/provider/resource-grouponsystem.go +++ b/internal/provider/resource-grouponsystem.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -11,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/system" ) @@ -28,7 +29,7 @@ func NewGrouponsystemResource() resource.Resource { } type grouponsystemResource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (r *grouponsystemResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -48,7 +49,7 @@ func (r *grouponsystemResource) Configure(ctx context.Context, req resource.Conf return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -59,7 +60,7 @@ func (r *grouponsystemResource) Configure(ctx context.Context, req resource.Conf return } - r.client = client + r.providerData = providerData } func (r *grouponsystemResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -69,7 +70,7 @@ func (r *grouponsystemResource) Create(ctx context.Context, req resource.CreateR return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, nestedProvisioningGroupOnSystemAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -82,6 +83,8 @@ func (r *grouponsystemResource) Create(ctx context.Context, req resource.CreateR return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Creating Topicus KeyHub grouponsystem") newWrapper := keyhubmodels.NewProvisioningGroupOnSystemLinkableWrapper() newWrapper.SetItems([]keyhubmodels.ProvisioningGroupOnSystemable{newTkh}) @@ -91,7 +94,7 @@ func (r *grouponsystemResource) Create(ctx context.Context, req resource.CreateR return } - wrapper, err := r.client.System().BySystemidInt64(*tkhParent.GetLinks()[0].GetId()).Group().Post( + wrapper, err := r.providerData.Client.System().BySystemidInt64(*tkhParent.GetLinks()[0].GetId()).Group().Post( ctx, newWrapper, &keyhubreq.ItemGroupRequestBuilderPostRequestConfiguration{ QueryParameters: &keyhubreq.ItemGroupRequestBuilderPostQueryParameters{ Additional: collectAdditional(data), @@ -124,7 +127,9 @@ func (r *grouponsystemResource) Read(ctx context.Context, req resource.ReadReque return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.RLock() + defer r.providerData.Mutex.RUnlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Reading grouponsystem from Topicus KeyHub") tkhParent, diags := findProvisioningProvisionedSystemPrimerByUUID(ctx, data.ProvisionedSystemUUID.ValueStringPointer()) resp.Diagnostics.Append(diags...) @@ -132,7 +137,7 @@ func (r *grouponsystemResource) Read(ctx context.Context, req resource.ReadReque return } - tkh, err := r.client.System().BySystemidInt64(*tkhParent.GetLinks()[0].GetId()).Group().ByGroupidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( + tkh, err := r.providerData.Client.System().BySystemidInt64(*tkhParent.GetLinks()[0].GetId()).Group().ByGroupidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( ctx, &keyhubreq.ItemGroupWithGroupItemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.ItemGroupWithGroupItemRequestBuilderGetQueryParameters{ Additional: collectAdditional(data), diff --git a/internal/provider/resource-serviceaccount.go b/internal/provider/resource-serviceaccount.go index eae7269..5c862c2 100644 --- a/internal/provider/resource-serviceaccount.go +++ b/internal/provider/resource-serviceaccount.go @@ -1,4 +1,6 @@ // Code generated by "terraform-provider-keyhub-generator"; DO NOT EDIT. +// Copyright (c) Topicus Security B.V. +// SPDX-License-Identifier: APSL-2.0 package provider @@ -11,7 +13,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - keyhub "github.com/topicuskeyhub/sdk-go" keyhubmodels "github.com/topicuskeyhub/sdk-go/models" keyhubreq "github.com/topicuskeyhub/sdk-go/serviceaccount" ) @@ -28,7 +29,7 @@ func NewServiceaccountResource() resource.Resource { } type serviceaccountResource struct { - client *keyhub.KeyHubClient + providerData *KeyHubProviderData } func (r *serviceaccountResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -48,7 +49,7 @@ func (r *serviceaccountResource) Configure(ctx context.Context, req resource.Con return } - client, ok := req.ProviderData.(*keyhub.KeyHubClient) + providerData, ok := req.ProviderData.(*KeyHubProviderData) if !ok { resp.Diagnostics.AddError( @@ -59,7 +60,7 @@ func (r *serviceaccountResource) Configure(ctx context.Context, req resource.Con return } - r.client = client + r.providerData = providerData } func (r *serviceaccountResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -69,7 +70,7 @@ func (r *serviceaccountResource) Create(ctx context.Context, req resource.Create return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, serviceaccountServiceAccountAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -82,10 +83,12 @@ func (r *serviceaccountResource) Create(ctx context.Context, req resource.Create return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Creating Topicus KeyHub serviceaccount") newWrapper := keyhubmodels.NewServiceaccountServiceAccountLinkableWrapper() newWrapper.SetItems([]keyhubmodels.ServiceaccountServiceAccountable{newTkh}) - wrapper, err := r.client.Serviceaccount().Post( + wrapper, err := r.providerData.Client.Serviceaccount().Post( ctx, newWrapper, &keyhubreq.ServiceaccountRequestBuilderPostRequestConfiguration{ QueryParameters: &keyhubreq.ServiceaccountRequestBuilderPostQueryParameters{ Additional: collectAdditional(data), @@ -117,9 +120,11 @@ func (r *serviceaccountResource) Read(ctx context.Context, req resource.ReadRequ return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + r.providerData.Mutex.RLock() + defer r.providerData.Mutex.RUnlock() + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) tflog.Info(ctx, "Reading serviceaccount from Topicus KeyHub") - tkh, err := r.client.Serviceaccount().ByServiceaccountidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( + tkh, err := r.providerData.Client.Serviceaccount().ByServiceaccountidInt64(getSelfLink(data.Links).ID.ValueInt64()).Get( ctx, &keyhubreq.WithServiceaccountItemRequestBuilderGetRequestConfiguration{ QueryParameters: &keyhubreq.WithServiceaccountItemRequestBuilderGetQueryParameters{ Additional: collectAdditional(data), @@ -147,7 +152,7 @@ func (r *serviceaccountResource) Update(ctx context.Context, req resource.Update return } - ctx = context.WithValue(ctx, keyHubClientKey, r.client) + ctx = context.WithValue(ctx, keyHubClientKey, r.providerData.Client) obj, diags := types.ObjectValueFrom(ctx, serviceaccountServiceAccountAttrTypesRSRecurse, data) resp.Diagnostics.Append(diags...) if resp.Diagnostics.HasError() { @@ -160,8 +165,10 @@ func (r *serviceaccountResource) Update(ctx context.Context, req resource.Update return } + r.providerData.Mutex.Lock() + defer r.providerData.Mutex.Unlock() tflog.Info(ctx, "Updating Topicus KeyHub serviceaccount") - tkh, err := r.client.Serviceaccount().ByServiceaccountidInt64(getSelfLink(data.Links).ID.ValueInt64()).Put( + tkh, err := r.providerData.Client.Serviceaccount().ByServiceaccountidInt64(getSelfLink(data.Links).ID.ValueInt64()).Put( ctx, newTkh, &keyhubreq.WithServiceaccountItemRequestBuilderPutRequestConfiguration{ QueryParameters: &keyhubreq.WithServiceaccountItemRequestBuilderPutQueryParameters{ Additional: collectAdditional(data),