Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Dec 18, 2024
1 parent a59ce68 commit 4d98fdd
Show file tree
Hide file tree
Showing 31 changed files with 102 additions and 125 deletions.
17 changes: 0 additions & 17 deletions internal/bitwarden/bwcli/filter.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/bitwarden/bwcli/password_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestGetItem(t *testing.T) {
}
}

func TestGetOrgCollection(t *testing.T) {
func TestGetOrganizationCollection(t *testing.T) {
removeMocks, commandsExecuted := test_command.MockCommands(t, map[string]string{
"get org-collection object-id --organizationid org-id": `{}`,
})
Expand Down
6 changes: 3 additions & 3 deletions internal/bitwarden/embedded/password_manager_webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (v *webAPIVault) CreateObject(ctx context.Context, obj models.Object) (*mod
return nil, fmt.Errorf("error encrypting collection for creation: %w", err)
}

resEncCollection, err := v.client.CreateOrgCollection(ctx, obj.OrganizationID, *encObj)
resEncCollection, err := v.client.CreateOrganizationCollection(ctx, obj.OrganizationID, *encObj)
if err != nil {
return nil, fmt.Errorf("error creating collection: %w", err)
}
Expand Down Expand Up @@ -408,7 +408,7 @@ func (v *webAPIVault) DeleteObject(ctx context.Context, obj models.Object) error
if obj.Object == models.ObjectTypeFolder {
err = v.client.DeleteFolder(ctx, obj.ID)
} else if obj.Object == models.ObjectTypeOrgCollection {
err = v.client.DeleteOrgCollection(ctx, obj.OrganizationID, obj.ID)
err = v.client.DeleteOrganizationCollection(ctx, obj.OrganizationID, obj.ID)
} else {
err = v.client.DeleteObject(ctx, obj.ID)
}
Expand Down Expand Up @@ -455,7 +455,7 @@ func (v *webAPIVault) EditObject(ctx context.Context, obj models.Object) (*model
return nil, fmt.Errorf("error encrypting collection for creation: %w", err)
}

resCollection, err := v.client.EditOrgCollection(ctx, obj.OrganizationID, obj.ID, *encObj)
resCollection, err := v.client.EditOrganizationCollection(ctx, obj.OrganizationID, obj.ID, *encObj)
if err != nil {
return nil, fmt.Errorf("error editing collection: %w", err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/bitwarden/webapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ type Client interface {
CreateObjectAttachment(ctx context.Context, itemId string, data []byte, req AttachmentRequestData) (*CreateObjectAttachmentResponse, error)
CreateObjectAttachmentData(ctx context.Context, itemId, attachmentId string, data []byte) error
CreateOrganization(ctx context.Context, req CreateOrganizationRequest) (*CreateOrganizationResponse, error)
CreateOrgCollection(ctx context.Context, orgId string, req OrganizationCreationRequest) (*Collection, error)
CreateOrganizationCollection(ctx context.Context, orgId string, req OrganizationCreationRequest) (*Collection, error)
CreateProject(ctx context.Context, project models.Project) (*models.Project, error)
CreateSecret(ctx context.Context, secret models.Secret) (*Secret, error)
DeleteFolder(ctx context.Context, objID string) error
DeleteObject(ctx context.Context, objID string) error
DeleteObjectAttachment(ctx context.Context, itemId, attachmentId string) error
DeleteOrgCollection(ctx context.Context, orgID, collectionID string) error
DeleteOrganizationCollection(ctx context.Context, orgID, collectionID string) error
DeleteProject(ctx context.Context, projectId string) error
DeleteSecret(ctx context.Context, secretId string) error
EditFolder(ctx context.Context, obj Folder) (*Folder, error)
EditObject(context.Context, models.Object) (*models.Object, error)
EditOrgCollection(ctx context.Context, orgId, objId string, obj OrganizationCreationRequest) (*Collection, error)
EditOrganizationCollection(ctx context.Context, orgId, objId string, obj OrganizationCreationRequest) (*Collection, error)
EditProject(context.Context, models.Project) (*models.Project, error)
EditSecret(ctx context.Context, secret models.Secret) (*Secret, error)
GetAPIKey(ctx context.Context, username, password string, kdfConfig models.KdfConfiguration) (*ApiKey, error)
Expand Down Expand Up @@ -179,7 +179,7 @@ func (c *client) CreateOrganization(ctx context.Context, req CreateOrganizationR
return doRequest[CreateOrganizationResponse](ctx, c.httpClient, httpReq)
}

func (c *client) CreateOrgCollection(ctx context.Context, orgId string, req OrganizationCreationRequest) (*Collection, error) {
func (c *client) CreateOrganizationCollection(ctx context.Context, orgId string, req OrganizationCreationRequest) (*Collection, error) {
httpReq, err := c.prepareRequest(ctx, "POST", fmt.Sprintf("%s/api/organizations/%s/collections", c.serverURL, orgId), req)
if err != nil {
return nil, fmt.Errorf("error preparing organization collection creation request: %w", err)
Expand Down Expand Up @@ -245,7 +245,7 @@ func (c *client) DeleteObjectAttachment(ctx context.Context, itemId, attachmentI
return err
}

func (c *client) DeleteOrgCollection(ctx context.Context, orgID, collectionID string) error {
func (c *client) DeleteOrganizationCollection(ctx context.Context, orgID, collectionID string) error {
httpReq, err := c.prepareRequest(ctx, "DELETE", fmt.Sprintf("%s/api/organizations/%s/collections/%s", c.serverURL, orgID, collectionID), nil)
if err != nil {
return fmt.Errorf("error preparing organization collection deletion request: %w", err)
Expand Down Expand Up @@ -303,7 +303,7 @@ func (c *client) EditObject(ctx context.Context, obj models.Object) (*models.Obj
return doRequest[models.Object](ctx, c.httpClient, req)
}

func (c *client) EditOrgCollection(ctx context.Context, orgId, objId string, obj OrganizationCreationRequest) (*Collection, error) {
func (c *client) EditOrganizationCollection(ctx context.Context, orgId, objId string, obj OrganizationCreationRequest) (*Collection, error) {
req, err := c.prepareRequest(ctx, "PUT", fmt.Sprintf("%s/api/organizations/%s/collections/%s", c.serverURL, orgId, objId), obj)
if err != nil {
return nil, fmt.Errorf("error preparing collection edition request: %w", err)
Expand Down
4 changes: 1 addition & 3 deletions internal/provider/data_source_item_secure_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
)

func dataSourceItemSecureNote() *schema.Resource {
dataSourceItemSecureNoteSchema := schema_definition.BaseSchema(schema_definition.DataSource)

return &schema.Resource{
Description: "Use this data source to get information on an existing secure note item.",
ReadContext: withPasswordManager(opItemRead(models.ItemTypeSecureNote)),
Schema: dataSourceItemSecureNoteSchema,
Schema: schema_definition.BaseSchema(schema_definition.DataSource),
}
}
4 changes: 1 addition & 3 deletions internal/provider/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
)

func dataSourceProject() *schema.Resource {
dataSourceProjectSchema := schema_definition.ProjectSchema(schema_definition.DataSource)

return &schema.Resource{
Description: "Use this data source to get information on an existing project.",
ReadContext: withSecretsManager(opProjectRead),
Schema: dataSourceProjectSchema,
Schema: schema_definition.ProjectSchema(schema_definition.DataSource),
}
}
4 changes: 1 addition & 3 deletions internal/provider/data_source_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
)

func dataSourceSecret() *schema.Resource {
dataSourceSecretSchema := schema_definition.SecretSchema(schema_definition.DataSource)

return &schema.Resource{
Description: "Use this data source to get information on an existing secret.",
ReadContext: withSecretsManager(opSecretRead),
Schema: dataSourceSecretSchema,
Schema: schema_definition.SecretSchema(schema_definition.DataSource),
}
}
4 changes: 2 additions & 2 deletions internal/provider/operation_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,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(transformation.AttachmentDataFromStruct(d, attachmentsAdded[0]))
return diag.FromErr(transformation.AttachmentObjectToSchema(d, attachmentsAdded[0]))
}

func opAttachmentDelete(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
Expand Down Expand Up @@ -99,7 +99,7 @@ func opAttachmentReadIgnoreMissing(ctx context.Context, d *schema.ResourceData,

for _, attachment := range obj.Attachments {
if attachment.ID == d.Id() {
return diag.FromErr(transformation.AttachmentDataFromStruct(d, attachment))
return diag.FromErr(transformation.AttachmentObjectToSchema(d, attachment))
}
}

Expand Down
12 changes: 6 additions & 6 deletions internal/provider/operation_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func opFolderCreate(ctx context.Context, d *schema.ResourceData, bwClient bitwar
return diag.FromErr(err)
}

return diag.FromErr(applyOperation(ctx, d, bwClient.CreateObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.CreateObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opFolderDelete(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeFolder)
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwClient.DeleteObject), transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwClient.DeleteObject), transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opFolderImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand All @@ -44,24 +44,24 @@ func opFolderRead(ctx context.Context, d *schema.ResourceData, bwClient bitwarde
return diag.FromErr(err)
}
if _, idProvided := d.GetOk(schema_definition.AttributeID); !idProvided {
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.ObjectDataFromStruct))
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.BaseObjectToSchema))
}

return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opFolderReadIgnoreMissing(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeFolder)
if err != nil {
return diag.FromErr(err)
}
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opFolderUpdate(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeFolder)
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, bwClient.EditObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.EditObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}
12 changes: 6 additions & 6 deletions internal/provider/operation_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func opItemCreate(attrType models.ItemType) passwordManagerOperation {
return diag.FromErr(err)
}

return diag.FromErr(applyOperation(ctx, d, bwClient.CreateObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.CreateObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}
}

Expand All @@ -32,7 +32,7 @@ func opItemDelete(ctx context.Context, d *schema.ResourceData, bwClient bitwarde
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwClient.DeleteObject), transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwClient.DeleteObject), transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opItemImport(attrType models.ItemType) schema.StateContextFunc {
Expand Down Expand Up @@ -68,9 +68,9 @@ func opItemRead(attrType models.ItemType) passwordManagerOperation {
return diag.FromErr(err)
}
if _, idProvided := d.GetOk(schema_definition.AttributeID); !idProvided {
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.ObjectDataFromStruct))
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.BaseObjectToSchema))
}
return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}
}

Expand All @@ -79,13 +79,13 @@ func opItemReadIgnoreMissing(ctx context.Context, d *schema.ResourceData, bwClie
if err != nil {
return diag.FromErr(err)
}
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opItemUpdate(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeItem)
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, bwClient.EditObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.EditObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}
12 changes: 6 additions & 6 deletions internal/provider/operation_org_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ func opOrganizationCollectionCreate(ctx context.Context, d *schema.ResourceData,
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, bwClient.CreateObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.CreateObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opOrganizationCollectionDelete(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeOrgCollection)
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwClient.DeleteObject), transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwClient.DeleteObject), transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opOrganizationCollectionImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand All @@ -51,24 +51,24 @@ func opOrganizationCollectionRead(ctx context.Context, d *schema.ResourceData, b
return diag.FromErr(err)
}
if _, idProvided := d.GetOk(schema_definition.AttributeID); !idProvided {
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.ObjectDataFromStruct))
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.BaseObjectToSchema))
}

return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opOrganizationCollectionReadIgnoreMissing(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeOrgCollection)
if err != nil {
return diag.FromErr(err)
}
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}

func opOrganizationCollectionUpdate(ctx context.Context, d *schema.ResourceData, bwClient bitwarden.PasswordManager) diag.Diagnostics {
err := d.Set(schema_definition.AttributeObject, models.ObjectTypeOrgCollection)
if err != nil {
return diag.FromErr(err)
}
return diag.FromErr(applyOperation(ctx, d, bwClient.EditObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.EditObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}
4 changes: 2 additions & 2 deletions internal/provider/operation_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func opOrganizationRead(ctx context.Context, d *schema.ResourceData, bwClient bi
}

if _, idProvided := d.GetOk(schema_definition.AttributeID); !idProvided {
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.ObjectDataFromStruct))
return diag.FromErr(searchOperation(ctx, d, bwClient.ListObjects, transformation.BaseObjectToSchema))
}

return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.ObjectStructFromData, transformation.ObjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwClient.GetObject, transformation.BaseSchemaToObject, transformation.BaseObjectToSchema))
}
10 changes: 5 additions & 5 deletions internal/provider/operation_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

func opProjectCreate(ctx context.Context, d *schema.ResourceData, bwsClient bitwarden.SecretsManager) diag.Diagnostics {
return diag.FromErr(applyOperation(ctx, d, bwsClient.CreateProject, transformation.ProjectStructFromData, transformation.ProjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwsClient.CreateProject, transformation.ProjectSchemaToObject, transformation.ProjectObjectToSchema))
}

func opProjectDelete(ctx context.Context, d *schema.ResourceData, bwsClient bitwarden.SecretsManager) diag.Diagnostics {
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwsClient.DeleteProject), transformation.ProjectStructFromData, transformation.ProjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, withNilReturn(bwsClient.DeleteProject), transformation.ProjectSchemaToObject, transformation.ProjectObjectToSchema))
}

func opProjectImport(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
Expand All @@ -25,13 +25,13 @@ func opProjectImport(ctx context.Context, d *schema.ResourceData, meta interface

func opProjectRead(ctx context.Context, d *schema.ResourceData, bwsClient bitwarden.SecretsManager) diag.Diagnostics {
d.SetId(d.Get(schema_definition.AttributeID).(string))
return diag.FromErr(applyOperation(ctx, d, bwsClient.GetProject, transformation.ProjectStructFromData, transformation.ProjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwsClient.GetProject, transformation.ProjectSchemaToObject, transformation.ProjectObjectToSchema))
}

func opProjectReadIgnoreMissing(ctx context.Context, d *schema.ResourceData, bwsClient bitwarden.SecretsManager) diag.Diagnostics {
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwsClient.GetProject, transformation.ProjectStructFromData, transformation.ProjectDataFromStruct))
return ignoreMissing(ctx, d, applyOperation(ctx, d, bwsClient.GetProject, transformation.ProjectSchemaToObject, transformation.ProjectObjectToSchema))
}

func opProjectUpdate(ctx context.Context, d *schema.ResourceData, bwsClient bitwarden.SecretsManager) diag.Diagnostics {
return diag.FromErr(applyOperation(ctx, d, bwsClient.EditProject, transformation.ProjectStructFromData, transformation.ProjectDataFromStruct))
return diag.FromErr(applyOperation(ctx, d, bwsClient.EditProject, transformation.ProjectSchemaToObject, transformation.ProjectObjectToSchema))
}
Loading

0 comments on commit 4d98fdd

Please sign in to comment.