Skip to content

feat(examples): add comprehensive API examples#11

Merged
lightcap merged 2 commits into
mainfrom
worktree-feat+examples
May 15, 2026
Merged

feat(examples): add comprehensive API examples#11
lightcap merged 2 commits into
mainfrom
worktree-feat+examples

Conversation

@lightcap
Copy link
Copy Markdown
Owner

@lightcap lightcap commented May 13, 2026

Summary

Adds comprehensive API usage examples matching the 1Password Python SDK's example coverage:

  • examples/example.rs — Full SDK surface demo: secrets (single, batch, TOTP), password generation (PIN, memorable, random), item CRUD with fields/sections/tags/websites, batch operations, item sharing, SSH key items, document items, file field attachments, and vault lifecycle management
  • examples/desktop_app.rs — Expanded to include vault CRUD, batch item operations, and group permission management (grant, update, revoke)
  • examples/README.md — Usage guide with environment variable setup and operations coverage matrix

Note: This PR is draft because the examples have not yet been tested against a live 1Password account. We're waiting for access to a service account to verify runtime behavior.

Test plan

  • cargo fmt --check passes
  • cargo clippy -- -D warnings passes
  • cargo test passes (23 tests)
  • cargo check --example example --example service_account --example desktop_app --features desktop compiles
  • Run example.rs against a live 1Password service account
  • Run desktop_app.rs against the 1Password desktop app

🤖 Generated with Claude Code


Note

Medium Risk
Mostly adds/expands example code and documentation, but also changes ClientConfig.system_os serialization (mapping macos to darwin), which could affect core/API behavior on macOS if consumers rely on the previous value.

Overview
Adds a new examples/example.rs that exercises most of the Rust SDK surface area (secrets, password generation, item CRUD + batch ops, sharing, SSH keys, documents, file attachments, and vault lifecycle) and introduces an examples/README.md with setup instructions and an operations coverage matrix.

Expands examples/desktop_app.rs from a single secret lookup to a broader desktop-auth demo including vault CRUD, item listing, batch item create/get/delete, and group vault permission grant/update/revoke (with best-effort cleanup). examples/service_account.rs is updated to accept OP_SECRET_REF and avoids printing secret contents.

In core, ClientConfig.system_os now normalizes macos to darwin via normalize_os() and adds tests to lock in the mapping.

Reviewed by Cursor Bugbot for commit 6fd32ed. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread examples/example.rs Fixed
Comment thread examples/example.rs Fixed
Comment thread examples/example.rs Fixed
Comment thread examples/example.rs Fixed
lightcap added a commit that referenced this pull request May 14, 2026
Replace println! calls that print .len() of secrets and passwords
with simple success messages, consistent with the examples fix in
PR #11.
lightcap added a commit that referenced this pull request May 14, 2026
Replace println! calls that print .len() of secrets and passwords
with simple success messages, consistent with the examples fix in
PR #11.
Rust std::env::consts::OS returns "macos" but the 1Password core
expects "darwin" (Go runtime.GOOS convention). Map the value at
client config construction time.
@lightcap lightcap force-pushed the worktree-feat+examples branch from 59b385a to 945eb00 Compare May 14, 2026 22:52
@lightcap lightcap marked this pull request as ready for review May 14, 2026 23:34
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 945eb00. Configure here.

Comment thread examples/desktop_app.rs
Adds three example programs demonstrating the full SDK surface:

- example.rs: secrets, passwords, item CRUD, batch operations,
  sharing, SSH keys, documents, file attachments, vault lifecycle
- desktop_app.rs: desktop app auth, vault/item operations, group
  permission management using a temporary vault
- service_account.rs: minimal service account authentication

All credentials are generated dynamically (SDK password generator,
ssh-keygen) to avoid hardcoded secrets. Cleanup is best-effort to
prevent leaked resources on partial failures.
@lightcap lightcap force-pushed the worktree-feat+examples branch from 945eb00 to 6fd32ed Compare May 15, 2026 00:05
@lightcap lightcap merged commit e5242c2 into main May 15, 2026
6 checks passed
lightcap added a commit that referenced this pull request May 15, 2026
Replace println! calls that print .len() of secrets and passwords
with simple success messages, consistent with the examples fix in
PR #11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants