Skip to content

Commit

Permalink
fix: set credential as password (#151)
Browse files Browse the repository at this point in the history
* 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 <volodymyr.zotov@agilebits.com>
  • Loading branch information
SMillerDev and volodymyrZotov committed Jun 17, 2024
1 parent 1e24ccf commit b0ed23b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/item.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions internal/provider/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (
const (
terraformItemIDDescription = "The Terraform resource identifier for this item in the format `vaults/<vault_id>/items/<item_id>`."

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."
Expand Down
42 changes: 26 additions & 16 deletions internal/provider/onepassword_item_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit b0ed23b

Please sign in to comment.