From b0ed23bb8b25781eea5688ab19bccbd9ff224d06 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 17 Jun 2024 18:59:34 +0200 Subject: [PATCH] fix: set credential as password (#151) * feat: add credential to item datasource Issue GH-52 * feat: add credential to item datasource Issue GH-52 * Remove 'credential' type from the data-source * Remove 'credential' type from the resource docs --------- Co-authored-by: Volodymyr Zotov --- docs/data-sources/item.md | 1 + internal/provider/const.go | 19 +++++---- .../provider/onepassword_item_data_source.go | 42 ++++++++++++------- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/docs/data-sources/item.md b/docs/data-sources/item.md index b72276a..7877629 100644 --- a/docs/data-sources/item.md +++ b/docs/data-sources/item.md @@ -35,6 +35,7 @@ data "onepassword_item" "example" { ### Read-Only - `category` (String) The category of the item. One of ["login" "password" "database" "secure_note" "document"] +- `credential` (String, Sensitive) API credential for this item. - `database` (String) (Only applies to the database category) The name of the database. - `file` (Block List) A list of files attached to the item. (see [below for nested schema](#nestedblock--file)) - `hostname` (String) (Only applies to the database category) The address where the database can be found diff --git a/internal/provider/const.go b/internal/provider/const.go index 51c1d8f..afae4b4 100644 --- a/internal/provider/const.go +++ b/internal/provider/const.go @@ -9,15 +9,16 @@ import ( const ( terraformItemIDDescription = "The Terraform resource identifier for this item in the format `vaults//items/`." - itemUUIDDescription = "The UUID of the item. Item identifiers are unique within a specific vault." - vaultUUIDDescription = "The UUID of the vault the item is in." - categoryDescription = "The category of the item." - itemTitleDescription = "The title of the item." - urlDescription = "The primary URL for the item." - tagsDescription = "An array of strings of the tags assigned to the item." - usernameDescription = "Username for this item." - passwordDescription = "Password for this item." - noteValueDescription = "Secure Note value." + itemUUIDDescription = "The UUID of the item. Item identifiers are unique within a specific vault." + vaultUUIDDescription = "The UUID of the vault the item is in." + categoryDescription = "The category of the item." + itemTitleDescription = "The title of the item." + urlDescription = "The primary URL for the item." + tagsDescription = "An array of strings of the tags assigned to the item." + usernameDescription = "Username for this item." + passwordDescription = "Password for this item." + credentialDescription = "API credential for this item." + noteValueDescription = "Secure Note value." dbHostnameDescription = "(Only applies to the database category) The address where the database can be found" dbDatabaseDescription = "(Only applies to the database category) The name of the database." diff --git a/internal/provider/onepassword_item_data_source.go b/internal/provider/onepassword_item_data_source.go index b468bd8..9f98c53 100644 --- a/internal/provider/onepassword_item_data_source.go +++ b/internal/provider/onepassword_item_data_source.go @@ -33,22 +33,23 @@ type OnePasswordItemDataSource struct { // OnePasswordItemDataSourceModel describes the data source data model. type OnePasswordItemDataSourceModel struct { - ID types.String `tfsdk:"id"` - Vault types.String `tfsdk:"vault"` - UUID types.String `tfsdk:"uuid"` - Title types.String `tfsdk:"title"` - Category types.String `tfsdk:"category"` - URL types.String `tfsdk:"url"` - Hostname types.String `tfsdk:"hostname"` - Database types.String `tfsdk:"database"` - Port types.String `tfsdk:"port"` - Type types.String `tfsdk:"type"` - Tags types.List `tfsdk:"tags"` - Username types.String `tfsdk:"username"` - Password types.String `tfsdk:"password"` - NoteValue types.String `tfsdk:"note_value"` - Section []OnePasswordItemSectionModel `tfsdk:"section"` - File []OnePasswordItemFileModel `tfsdk:"file"` + ID types.String `tfsdk:"id"` + Vault types.String `tfsdk:"vault"` + UUID types.String `tfsdk:"uuid"` + Title types.String `tfsdk:"title"` + Category types.String `tfsdk:"category"` + URL types.String `tfsdk:"url"` + Hostname types.String `tfsdk:"hostname"` + Database types.String `tfsdk:"database"` + Port types.String `tfsdk:"port"` + Type types.String `tfsdk:"type"` + Tags types.List `tfsdk:"tags"` + Username types.String `tfsdk:"username"` + Password types.String `tfsdk:"password"` + NoteValue types.String `tfsdk:"note_value"` + Credential types.String `tfsdk:"credential"` + Section []OnePasswordItemSectionModel `tfsdk:"section"` + File []OnePasswordItemFileModel `tfsdk:"file"` } type OnePasswordItemFileModel struct { @@ -168,6 +169,11 @@ func (d *OnePasswordItemDataSource) Schema(ctx context.Context, req datasource.S Computed: true, Sensitive: true, }, + "credential": schema.StringAttribute{ + MarkdownDescription: credentialDescription, + Computed: true, + Sensitive: true, + }, "note_value": schema.StringAttribute{ MarkdownDescription: noteValueDescription, Computed: true, @@ -356,6 +362,10 @@ func (d *OnePasswordItemDataSource) Read(ctx context.Context, req datasource.Rea data.Type = types.StringValue(f.Value) } } + + if f.ID == "credential" && item.Category == "API_CREDENTIAL" { + data.Credential = types.StringValue(f.Value) + } } }