diff --git a/internal/provider/operation_attachment.go b/internal/provider/operation_attachment.go index 520eec2..ca797f6 100644 --- a/internal/provider/operation_attachment.go +++ b/internal/provider/operation_attachment.go @@ -16,6 +16,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden" "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden/models" "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" + "github.com/maxlaverse/terraform-provider-bitwarden/internal/transformation" ) func opAttachmentCreate(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics { @@ -50,7 +51,7 @@ func opAttachmentCreate(ctx context.Context, d *schema.ResourceData, bwClient bi return diag.FromErr(errors.New("BUG: at least one attachment removed")) } - return diag.FromErr(attachmentDataFromStruct(d, attachmentsAdded[0])) + return diag.FromErr(transformation.AttachmentDataFromStruct(d, attachmentsAdded[0])) } func opAttachmentDelete(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics { @@ -98,7 +99,7 @@ func opAttachmentReadIgnoreMissing(ctx context.Context, d *schema.ResourceData, for _, attachment := range obj.Attachments { if attachment.ID == d.Id() { - return diag.FromErr(attachmentDataFromStruct(d, attachment)) + return diag.FromErr(transformation.AttachmentDataFromStruct(d, attachment)) } } diff --git a/internal/provider/operation_object.go b/internal/provider/operation_object.go index 9c024ef..236ceae 100644 --- a/internal/provider/operation_object.go +++ b/internal/provider/operation_object.go @@ -12,6 +12,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden/bwcli" "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden/models" "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" + "github.com/maxlaverse/terraform-provider-bitwarden/internal/transformation" ) type objectOperationFunc func(ctx context.Context, secret models.Object) (*models.Object, error) @@ -124,7 +125,7 @@ func objectSearch(ctx context.Context, d *schema.ResourceData, bwClient bitwarde return fmt.Errorf("BUG: object type not set in the resource data") } - objs, err := bwClient.ListObjects(ctx, models.ObjectType(objType.(string)), listOptionsFromData(d)...) + objs, err := bwClient.ListObjects(ctx, models.ObjectType(objType.(string)), transformation.ListOptionsFromData(d)...) if err != nil { return err } @@ -159,14 +160,14 @@ func objectSearch(ctx context.Context, d *schema.ResourceData, bwClient bitwarde return errors.New("object is soft deleted") } - return objectDataFromStruct(ctx, d, &obj) + return transformation.ObjectDataFromStruct(ctx, d, &obj) } func objectOperation(ctx context.Context, d *schema.ResourceData, operation objectOperationFunc) error { - obj, err := operation(ctx, objectStructFromData(ctx, d)) + obj, err := operation(ctx, transformation.ObjectStructFromData(ctx, d)) if err != nil { return err } - return objectDataFromStruct(ctx, d, obj) + return transformation.ObjectDataFromStruct(ctx, d, obj) } diff --git a/internal/provider/operation_project.go b/internal/provider/operation_project.go index a5eab5f..007f7ca 100644 --- a/internal/provider/operation_project.go +++ b/internal/provider/operation_project.go @@ -10,6 +10,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden" "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden/models" "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" + "github.com/maxlaverse/terraform-provider-bitwarden/internal/transformation" ) type projectOperationFunc func(ctx context.Context, secret models.Project) (*models.Project, error) @@ -64,10 +65,10 @@ func opProjectUpdate(ctx context.Context, d *schema.ResourceData, bwsClient bitw } func projectOperation(ctx context.Context, d *schema.ResourceData, operation projectOperationFunc) error { - project, err := operation(ctx, projectStructFromData(ctx, d)) + project, err := operation(ctx, transformation.ProjectStructFromData(ctx, d)) if err != nil { return err } - return projectDataFromStruct(ctx, d, project) + return transformation.ProjectDataFromStruct(ctx, d, project) } diff --git a/internal/provider/operation_secret.go b/internal/provider/operation_secret.go index 4152e2c..341a498 100644 --- a/internal/provider/operation_secret.go +++ b/internal/provider/operation_secret.go @@ -11,6 +11,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden" "github.com/maxlaverse/terraform-provider-bitwarden/internal/bitwarden/models" "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" + "github.com/maxlaverse/terraform-provider-bitwarden/internal/transformation" ) type secretOperationFunc func(ctx context.Context, secret models.Secret) (*models.Secret, error) @@ -79,14 +80,14 @@ func secretSearch(ctx context.Context, d *schema.ResourceData, bwsClient bitward return err } - return secretDataFromStruct(ctx, d, secret) + return transformation.SecretDataFromStruct(ctx, d, secret) } func secretOperation(ctx context.Context, d *schema.ResourceData, operation secretOperationFunc) error { - secret, err := operation(ctx, secretStructFromData(ctx, d)) + secret, err := operation(ctx, transformation.SecretStructFromData(ctx, d)) if err != nil { return err } - return secretDataFromStruct(ctx, d, secret) + return transformation.SecretDataFromStruct(ctx, d, secret) } diff --git a/internal/provider/transformation_attachment.go b/internal/transformation/transformation_attachment.go similarity index 89% rename from internal/provider/transformation_attachment.go rename to internal/transformation/transformation_attachment.go index cd14572..aab5aaa 100644 --- a/internal/provider/transformation_attachment.go +++ b/internal/transformation/transformation_attachment.go @@ -1,4 +1,4 @@ -package provider +package transformation import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -6,7 +6,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" ) -func attachmentDataFromStruct(d *schema.ResourceData, attachment models.Attachment) error { +func AttachmentDataFromStruct(d *schema.ResourceData, attachment models.Attachment) error { d.SetId(attachment.ID) err := d.Set(schema_definition.AttributeAttachmentFileName, attachment.FileName) diff --git a/internal/provider/transformation_object.go b/internal/transformation/transformation_object.go similarity index 98% rename from internal/provider/transformation_object.go rename to internal/transformation/transformation_object.go index 129255f..599a59d 100644 --- a/internal/provider/transformation_object.go +++ b/internal/transformation/transformation_object.go @@ -1,4 +1,4 @@ -package provider +package transformation import ( "context" @@ -10,7 +10,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" ) -func objectDataFromStruct(ctx context.Context, d *schema.ResourceData, obj *models.Object) error { +func ObjectDataFromStruct(ctx context.Context, d *schema.ResourceData, obj *models.Object) error { if obj == nil { // Object has been deleted return nil @@ -129,7 +129,7 @@ func objectDataFromStruct(ctx context.Context, d *schema.ResourceData, obj *mode return nil } -func objectStructFromData(ctx context.Context, d *schema.ResourceData) models.Object { +func ObjectStructFromData(ctx context.Context, d *schema.ResourceData) models.Object { var obj models.Object obj.ID = d.Id() @@ -367,7 +367,7 @@ const ( URIMatchNever URIMatchStr = "never" ) -func listOptionsFromData(d *schema.ResourceData) []bitwarden.ListObjectsOption { +func ListOptionsFromData(d *schema.ResourceData) []bitwarden.ListObjectsOption { filters := []bitwarden.ListObjectsOption{} filterMap := map[string]bitwarden.ListObjectsOptionGenerator{ diff --git a/internal/provider/transformation_project.go b/internal/transformation/transformation_project.go similarity index 85% rename from internal/provider/transformation_project.go rename to internal/transformation/transformation_project.go index b816c30..7f587dc 100644 --- a/internal/provider/transformation_project.go +++ b/internal/transformation/transformation_project.go @@ -1,4 +1,4 @@ -package provider +package transformation import ( "context" @@ -8,7 +8,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" ) -func projectStructFromData(_ context.Context, d *schema.ResourceData) models.Project { +func ProjectStructFromData(_ context.Context, d *schema.ResourceData) models.Project { var project models.Project project.ID = d.Id() @@ -23,7 +23,7 @@ func projectStructFromData(_ context.Context, d *schema.ResourceData) models.Pro return project } -func projectDataFromStruct(_ context.Context, d *schema.ResourceData, project *models.Project) error { +func ProjectDataFromStruct(_ context.Context, d *schema.ResourceData, project *models.Project) error { if project == nil { // Project has been deleted return nil diff --git a/internal/provider/transformation_secret.go b/internal/transformation/transformation_secret.go similarity index 90% rename from internal/provider/transformation_secret.go rename to internal/transformation/transformation_secret.go index cd225ef..04e773f 100644 --- a/internal/provider/transformation_secret.go +++ b/internal/transformation/transformation_secret.go @@ -1,4 +1,4 @@ -package provider +package transformation import ( "context" @@ -8,7 +8,7 @@ import ( "github.com/maxlaverse/terraform-provider-bitwarden/internal/schema_definition" ) -func secretStructFromData(_ context.Context, d *schema.ResourceData) models.Secret { +func SecretStructFromData(_ context.Context, d *schema.ResourceData) models.Secret { var secret models.Secret secret.ID = d.Id() @@ -35,7 +35,7 @@ func secretStructFromData(_ context.Context, d *schema.ResourceData) models.Secr return secret } -func secretDataFromStruct(_ context.Context, d *schema.ResourceData, secret *models.Secret) error { +func SecretDataFromStruct(_ context.Context, d *schema.ResourceData, secret *models.Secret) error { if secret == nil { // Secret has been deleted return nil