1Password/connect-sdk-go

Cannot Create Document type Items because File.content is not exported

snarlysodboxer opened this issue · 6 comments

Your environment

SDK Version: 1.2.0
Connect Server Version: 1.5.0
OS: MacOS
Go Version: 1.17.2

What happened?

File.content is not exported, so when calling Client.CreateItem(item) on an item with Files, the file's contents are left out by json.Marshal(item).

Here's how how I'm calling CreateItem

	// TODO generate random IDs?
	vaultID := "fdsasdkfjsdkfjhsd" // retrieved first
	itemName := "my-item"
	itemID := fmt.Sprintf("%s-id", itemName)
	fileName := "my-file.txt"
	fileID := fmt.Sprintf("%s-id", fileName)
	contents, err := os.ReadFile(fileName)
	if err != nil {
		return err
	}

	contentPath := fmt.Sprintf("v1/vaults/%s/items/%s/files/%s/content", vaultID, itemID, fileID)
	file := &onepassword.File{
		ID:          fileID,
		Name:        fileName,
		Size:        len(contents),
		ContentPath: contentPath,
	}
	file.SetContent(contents)

	item := &onepassword.Item{
		ID:       itemID,
		Title:    itemName,
		Vault:    onepassword.ItemVault{ID: vaultID},
		Category: onepassword.Document,
		Files:    []*onepassword.File{file},
	}

	_, err = client.CreateItem(item, vaultID)
	if err != nil {
		return err
	}

Using the above code against the the fix in mentioned PR, the content is now in the output of json.Marshal, however the API still returns Error: status 400: Validation: (validateVaultItem failed to Validate), Couldn't validate the item: "[ItemValidator] has found 1 errors, 0 warnings: \nErrors:{1. Field of unexpected type \"\" at \"item.details.documentAttributes\". Requires one of [\"object\"]}". There's no item.details.documentAttributes in the code or object schemas.

Anyone there?

Hey @snarlysodboxer,

Apologies for this late reply.

Unfortunately, at the moment, Connect does not support creating items with files in them. There is no API endpoint that supports this at the moment. Therefore, it's not possible to create Document type items with Connect. You can only fetch them.

However, we have this feature in our backlog, and we will let you know when this feature comes up.
When the new API endpoint will be up, we will update all our SDKs properly, so that you will be able to create Document type items with Connect using this SDK.

Thank you for your patience.

@edif2008 Thanks for the reply. It's a relief to know you plan to continue to support this client. We just built a 1Password provider using this client and contributed it to the popular project external-secrets.io. (The usage of this client is all in pkg/provider/onepassword/onepassword.go in case you're curious.)

They're going to cut a new release with 1Password support tomorrow, for now it can be seen here. If you search the word "bug" on that page, you'll see this self-same git issue mentioned. (Sorry, I thought it was a bug not just unimplemented.) You might also notice on this issue that there are a number of companies lining up to use 1Password with the external-secrets operator.

We have noticed some problems with the Connect Server that force us to restart it semi-frequently. - Should we submit issues about that at https://github.com/1Password/connect? Or somewhere else?

Hey @snarlysodboxer,

I've taken a quick look at the provider you mentioned and it's quite interesting. It's exciting to see that this SDK brings value to other products! 🎉

We have noticed some problems with the Connect Server that force us to restart it semi-frequently. - Should we submit issues about that at https://github.com/1Password/connect? Or somewhere else?

Definitely open an issue on that repo, along with some logs so that we can better understand what causes you to restart the server. In this way, we can identify the problem faster and, if applicable, come up with the proper fix for it.

Hope it's ok, I've opened a new issue to track this need since the direction of this particular issue no longer makes sense given the feedback.