Skip to content

Commit

Permalink
feat: add credential to item datasource
Browse files Browse the repository at this point in the history
Issue GH-52
  • Loading branch information
SMillerDev committed May 27, 2024
1 parent 69451ed commit ce2ba05
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
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
40 changes: 25 additions & 15 deletions internal/provider/onepassword_item_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ 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"`
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"`
}

type OnePasswordItemSectionModel struct {
Expand Down Expand Up @@ -135,6 +136,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 @@ -295,6 +301,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 ce2ba05

Please sign in to comment.