Skip to content

Commit 5e97b09

Browse files
committed
Add API credential fields to item data source
Add support for `valid_from`, `expires`, and `filename` fields in the `API_CREDENTIAL` category. Update documentation and internal descriptions to reflect these additions, ensuring consistent handling of API credential metadata.
1 parent a1cf724 commit 5e97b09

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

docs/data-sources/item.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data "onepassword_item" "example" {
3434

3535
### Read-Only
3636

37-
- `category` (String) The category of the item. One of ["login" "password" "database" "secure_note" "document" "ssh_key"]
37+
- `category` (String) The category of the item. One of ["login" "password" "database" "secure_note" "document" "ssh_key" "credential"]
3838
- `credential` (String, Sensitive) API credential for this item.
3939
- `database` (String) (Only applies to the database category) The name of the database.
4040
- `file` (Block List) A list of files attached to the item. (see [below for nested schema](#nestedblock--file))
@@ -46,9 +46,10 @@ data "onepassword_item" "example" {
4646
- `public_key` (String) SSH Public Key for this item.
4747
- `section` (Block List) A list of custom sections in an item (see [below for nested schema](#nestedblock--section))
4848
- `tags` (List of String) An array of strings of the tags assigned to the item.
49-
- `type` (String) (Only applies to the database category) The type of database. One of ["db2" "filemaker" "msaccess" "mssql" "mysql" "oracle" "postgresql" "sqlite" "other"]
49+
- `type` (String) (Applies to the database and API credential categories) The type of database or API credential. For the database category, one of ["db2" "filemaker" "msaccess" "mssql" "mysql" "oracle" "postgresql" "sqlite" "other"]. For API credentials, it can be any string.
5050
- `url` (String) The primary URL for the item.
5151
- `username` (String) Username for this item.
52+
- `filename` (String) (Applies to the API credential category) Filename for this item.
5253

5354
<a id="nestedblock--file"></a>
5455
### Nested Schema for `file`

internal/provider/const.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ const (
1717
tagsDescription = "An array of strings of the tags assigned to the item."
1818
usernameDescription = "Username for this item."
1919
passwordDescription = "Password for this item."
20-
credentialDescription = "API credential for this item."
2120
noteValueDescription = "Secure Note value."
2221
publicKeyDescription = "SSH Public Key for this item."
2322
privateKeyDescription = "SSH Private Key for this item."
2423

24+
credentialDescription = "(Only applies to the API credential category) API credential for this item."
25+
validFromDescription = "(Only applies to the API credential category) The timestamp from which the API credential is valid."
26+
expiresDescription = "(Only applies to the API credential category) The timestamp when the API credential expires."
27+
filenameDescription = "(Only applies to the API credential category) The filename associated with the API credential."
28+
2529
dbHostnameDescription = "(Only applies to the database category) The address where the database can be found"
2630
dbDatabaseDescription = "(Only applies to the database category) The name of the database."
2731
dbPortDescription = "(Only applies to the database category) The port the database is listening on."
28-
dbTypeDescription = "(Only applies to the database category) The type of database."
32+
dbTypeDescription = "(Only applies to database and API credential categories) For the database category"
2933

3034
sectionsDescription = "A list of custom sections in an item"
3135
sectionDescription = "A custom section in an item that contains custom fields"
@@ -72,6 +76,7 @@ var (
7276
dataSourceCategories = append(categories,
7377
strings.ToLower(string(op.Document)),
7478
strings.ToLower(string(op.SSHKey)),
79+
strings.ToLower(string(op.ApiCredential)),
7580
)
7681

7782
fieldPurposes = []string{

internal/provider/onepassword_item_data_source.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type OnePasswordItemDataSourceModel struct {
4848
Password types.String `tfsdk:"password"`
4949
NoteValue types.String `tfsdk:"note_value"`
5050
Credential types.String `tfsdk:"credential"`
51+
Filename types.String `tfsdk:"filename"`
52+
ValidFrom types.String `tfsdk:"valid_from"`
53+
Expires types.String `tfsdk:"expires"`
5154
PublicKey types.String `tfsdk:"public_key"`
5255
PrivateKey types.String `tfsdk:"private_key"`
5356
Section []OnePasswordItemSectionModel `tfsdk:"section"`
@@ -176,6 +179,18 @@ func (d *OnePasswordItemDataSource) Schema(ctx context.Context, req datasource.S
176179
Computed: true,
177180
Sensitive: true,
178181
},
182+
"valid_from": schema.StringAttribute{
183+
MarkdownDescription: validFromDescription,
184+
Computed: true,
185+
},
186+
"expires": schema.StringAttribute{
187+
MarkdownDescription: expiresDescription,
188+
Computed: true,
189+
},
190+
"filename": schema.StringAttribute{
191+
MarkdownDescription: filenameDescription,
192+
Computed: true,
193+
},
179194
"note_value": schema.StringAttribute{
180195
MarkdownDescription: noteValueDescription,
181196
Computed: true,
@@ -377,6 +392,12 @@ func (d *OnePasswordItemDataSource) Read(ctx context.Context, req datasource.Rea
377392
data.PrivateKey = types.StringValue(f.Value)
378393
case "credential":
379394
data.Credential = types.StringValue(f.Value)
395+
case "valid_from":
396+
data.ValidFrom = types.StringValue(f.Value)
397+
case "expires":
398+
data.Expires = types.StringValue(f.Value)
399+
case "filename":
400+
data.Filename = types.StringValue(f.Value)
380401
}
381402
}
382403
}

0 commit comments

Comments
 (0)