Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set credential as password #151

Merged
merged 6 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading