Skip to content
Closed
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
150 changes: 145 additions & 5 deletions .github/workflows/download-server-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,77 @@ on:
permissions:
contents: read

env:
_BOT_NAME: "bw-ghapp[bot]"
_BOT_EMAIL: "178206702+bw-ghapp[bot]@users.noreply.github.com"

jobs:
download:
name: Download internal.json from bitwarden/server

name: Update API Bindings
runs-on: ubuntu-24.04
permissions:
pull-requests: write
actions: read
contents: write

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Switch to branch
id: switch-branch
run: |
BRANCH_NAME="sdlc/api-update"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT

if git switch $BRANCH_NAME; then
echo "✅ Switched to existing branch: $BRANCH_NAME"
echo "updating_existing_branch=true" >> $GITHUB_OUTPUT
else
echo "📝 Creating new branch: $BRANCH_NAME"
git switch -c $BRANCH_NAME
echo "updating_existing_branch=false" >> $GITHUB_OUTPUT
fi

- name: Prevent updating the branch when the last committer isn't the bot
if: ${{ steps.switch-branch.outputs.updating_existing_branch == 'true' }}
env:
_BRANCH_NAME: ${{ steps.switch-branch.outputs.branch_name }}
run: |
LATEST_COMMIT_AUTHOR=$(git log -1 --format='%ae' $_BRANCH_NAME)

- name: Download internal.json artifact
echo "Latest commit author in branch ($_BRANCH_NAME): $LATEST_COMMIT_AUTHOR"
echo "Expected bot email: $_BOT_EMAIL"

if [ "$LATEST_COMMIT_AUTHOR" != "$_BOT_EMAIL" ]; then
echo "::error::Branch $_BRANCH_NAME has a commit not made by the bot." \
"This indicates manual changes have been made to the branch," \
"PR has to be merged or closed before running this workflow again."
echo "👀 Fetching existing PR..."
gh pr list --head $_BRANCH_NAME --base main --state open --json number --jq '.[0].number // empty'
EXISTING_PR=$(gh pr list --head $_BRANCH_NAME --base main --state open --json number --jq '.[0].number // empty')
if [ -z "$EXISTING_PR" ]; then
echo "::error::Couldn't find an existing PR for branch $_BRANCH_NAME."
exit 1
fi
PR_URL="https://github.com/${{ github.repository }}/pull/$EXISTING_PR"
echo "## ❌ Merge or close: $PR_URL" >> $GITHUB_STEP_SUMMARY
exit 1
fi

echo "✅ Branch tip commit was made by the bot. Safe to proceed."

- name: Download json artifacts
uses: bitwarden/gh-actions/download-artifacts@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
repo: bitwarden/server
branch: main
artifacts: (internal|identity).json
workflow: build.yml
artifacts: "*.json"
path: artifacts/
name_is_regexp: true

- name: List downloaded files
run: |
Expand All @@ -33,3 +85,91 @@ jobs:
if [ -f "artifacts/internal.json" ]; then
echo "internal.json file size: $(stat -c%s artifacts/internal.json) bytes"
fi

- name: Set Rust Nightly Toolchain
id: nightly-toolchain
shell: bash
run: |
RUST_NIGHTLY_TOOLCHAIN="$(grep -oP '^nightly-channel.*"(\K.*?)(?=")' rust-toolchain.toml)"
echo "RUST_NIGHTLY_TOOLCHAIN=${RUST_NIGHTLY_TOOLCHAIN}" | tee -a "${GITHUB_OUTPUT}"

- name: Install rust nightly
run: |
rustup toolchain install "${{ steps.nightly-toolchain.outputs.RUST_NIGHTLY_TOOLCHAIN }}"
rustup component add rustfmt --toolchain "${{ steps.nightly-toolchain.outputs.RUST_NIGHTLY_TOOLCHAIN }}"-x86_64-unknown-linux-gnu

- name: Cache cargo registry
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7

- name: Set Node Version
id: retrieve-node-version
working-directory: ./
run: |
NODE_NVMRC=$(cat .nvmrc)
NODE_VERSION=${NODE_NVMRC/v/''}
echo "node_version=$NODE_VERSION" >> $GITHUB_OUTPUT

- name: Set up Node
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
cache: "npm"
cache-dependency-path: "package-lock.json"
node-version: ${{ env._NODE_VERSION }}
env:
_NODE_VERSION: ${{ steps.retrieve-node-version.outputs.node_version }}

- name: NPM setup
run: npm ci

- name: Generate API bindings
run: ./support/build-api-ci.sh

- name: Format
run: cargo +"${{ steps.nightly-toolchain.outputs.RUST_NIGHTLY_TOOLCHAIN }}" fmt

- name: Set Commit Info
id: commit-info
run: |
HASH=$(cat ./artifacts/identity.json | jq -r '.["x-git-commit"]')
echo "HASH=$HASH" >> $GITHUB_OUTPUT

- name: Create branch and commit
env:
_HASH: ${{ steps.commit-info.outputs.HASH }}
_BRANCH_NAME: ${{ steps.switch-branch.outputs.BRANCH_NAME }}
run: |
echo "👀 Committing SDK version update..."

git config user.name "$_BOT_NAME"
git config user.email "$_BOT_EMAIL"

git add crates/bitwarden-api-api crates/bitwarden-api-identity
git commit -m "Update API bindings - $_HASH" --no-verify
git push origin $_BRANCH_NAME

- name: Create or Update Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
_HASH: ${{ steps.commit-info.outputs.HASH }}
_BRANCH_NAME: ${{ steps.switch-branch.outputs.BRANCH_NAME }}
run: |
PR_BODY="Updates the API bindings to \`$_HASH\`"

EXISTING_PR=$(gh pr list --head $_BRANCH_NAME --base main --state open --json number --jq '.[0].number // empty')

if [ -n "$EXISTING_PR" ]; then
echo "🔄 Updating existing PR #$EXISTING_PR..."
echo -e "$PR_BODY" | gh pr edit $EXISTING_PR \
--title "Update API to $_HASH" \
--body-file -
PR_URL="https://github.com/${{ github.repository }}/pull/$EXISTING_PR"
echo "## ✅ Updated PR: $PR_URL" >> $GITHUB_STEP_SUMMARY
else
echo "📝 Creating new PR..."
PR_URL=$(echo -e "$PR_BODY" | gh pr create \
--title "Update API to $_HASH" \
--body-file - \
--base main \
--head $_BRANCH_NAME)
echo "## 🚀 Created PR: $PR_URL" >> $GITHUB_STEP_SUMMARY
fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ crates/bitwarden-uniffi/swift/tmp
crates/bitwarden-uniffi/swift/.build
crates/bitwarden-uniffi/swift/.swiftpm
crates/bitwarden-uniffi/kotlin/sdk/src/main/java/com/bitwarden/**/*.kt

# API Swagger files
/artifacts
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22
18 changes: 12 additions & 6 deletions crates/bitwarden-api-api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ src/apis/organization_domain_api.rs
src/apis/organization_export_api.rs
src/apis/organization_integration_api.rs
src/apis/organization_integration_configuration_api.rs
src/apis/organization_reports_api.rs
src/apis/organization_sponsorships_api.rs
src/apis/organization_users_api.rs
src/apis/organizations_api.rs
Expand All @@ -54,6 +55,7 @@ src/apis/secrets_api.rs
src/apis/secrets_manager_events_api.rs
src/apis/secrets_manager_porting_api.rs
src/apis/security_task_api.rs
src/apis/self_hosted_account_billing_api.rs
src/apis/self_hosted_organization_licenses_api.rs
src/apis/self_hosted_organization_sponsorships_api.rs
src/apis/sends_api.rs
Expand Down Expand Up @@ -156,13 +158,13 @@ src/models/collection_access_details_response_model_list_response_model.rs
src/models/collection_bulk_delete_request_model.rs
src/models/collection_details_response_model.rs
src/models/collection_details_response_model_list_response_model.rs
src/models/collection_request_model.rs
src/models/collection_response_model.rs
src/models/collection_response_model_list_response_model.rs
src/models/collection_type.rs
src/models/collection_with_id_request_model.rs
src/models/config_response_model.rs
src/models/create_client_organization_request_body.rs
src/models/create_collection_request_model.rs
src/models/credential_create_options.rs
src/models/delete_attachment_response_data.rs
src/models/delete_recover_request_model.rs
Expand All @@ -177,7 +179,6 @@ src/models/device_type.rs
src/models/device_verification_request_model.rs
src/models/device_verification_response_model.rs
src/models/domains_response_model.rs
src/models/drop_organization_report_request.rs
src/models/drop_password_health_report_application_request.rs
src/models/email_request_model.rs
src/models/email_token_request_model.rs
Expand Down Expand Up @@ -248,6 +249,7 @@ src/models/member_access_detail_report_response_model.rs
src/models/member_cipher_details_response_model.rs
src/models/member_decryption_type.rs
src/models/minimal_billing_address_request.rs
src/models/minimal_tokenized_payment_method_request.rs
src/models/mod.rs
src/models/notification_response_model.rs
src/models/notification_response_model_list_response_model.rs
Expand Down Expand Up @@ -280,8 +282,6 @@ src/models/organization_license.rs
src/models/organization_no_payment_create_request.rs
src/models/organization_password_manager_request_model.rs
src/models/organization_public_key_response_model.rs
src/models/organization_report.rs
src/models/organization_report_summary_model.rs
src/models/organization_response_model.rs
src/models/organization_seat_request_model.rs
src/models/organization_sponsorship_create_request_model.rs
Expand Down Expand Up @@ -352,6 +352,7 @@ src/models/policy_type.rs
src/models/potential_grantee_response_model.rs
src/models/potential_grantee_response_model_list_response_model.rs
src/models/pre_validate_sponsorship_response_model.rs
src/models/premium_cloud_hosted_subscription_request.rs
src/models/preview_individual_invoice_request_body.rs
src/models/preview_organization_invoice_request_body.rs
src/models/preview_tax_amount_for_organization_trial_request_body.rs
Expand Down Expand Up @@ -417,6 +418,7 @@ src/models/rotate_user_account_keys_and_data_request_model.rs
src/models/saml2_binding_type.rs
src/models/saml2_name_id_format.rs
src/models/saml2_signing_behavior.rs
src/models/save_policy_request.rs
src/models/secret_access_policies_requests_model.rs
src/models/secret_access_policies_response_model.rs
src/models/secret_create_request_model.rs
Expand All @@ -434,6 +436,7 @@ src/models/secrets_sync_response_model.rs
src/models/secrets_with_projects_inner_secret.rs
src/models/secure_note_type.rs
src/models/security_task_create_request.rs
src/models/security_task_metrics_response_model.rs
src/models/security_task_status.rs
src/models/security_task_type.rs
src/models/security_tasks_response_model.rs
Expand Down Expand Up @@ -495,7 +498,6 @@ src/models/two_factor_provider_response_model.rs
src/models/two_factor_provider_response_model_list_response_model.rs
src/models/two_factor_provider_type.rs
src/models/two_factor_recover_response_model.rs
src/models/two_factor_recovery_request_model.rs
src/models/two_factor_web_authn_delete_request_model.rs
src/models/two_factor_web_authn_request_model.rs
src/models/two_factor_web_authn_response_model.rs
Expand All @@ -505,8 +507,13 @@ src/models/unlock_data_request_model.rs
src/models/untrust_devices_request_model.rs
src/models/update_avatar_request_model.rs
src/models/update_client_organization_request_body.rs
src/models/update_collection_request_model.rs
src/models/update_devices_trust_request_model.rs
src/models/update_domains_request_model.rs
src/models/update_organization_report_application_data_request.rs
src/models/update_organization_report_data_request.rs
src/models/update_organization_report_request.rs
src/models/update_organization_report_summary_request.rs
src/models/update_payment_method_request_body.rs
src/models/update_profile_request_model.rs
src/models/update_tde_offboarding_password_request_model.rs
Expand All @@ -523,7 +530,6 @@ src/models/user_license.rs
src/models/user_verification_requirement.rs
src/models/verified_organization_domain_sso_detail_response_model.rs
src/models/verified_organization_domain_sso_details_response_model.rs
src/models/verify_bank_account_request.rs
src/models/verify_bank_account_request_body.rs
src/models/verify_delete_recover_request_model.rs
src/models/verify_email_request_model.rs
Expand Down
19 changes: 7 additions & 12 deletions crates/bitwarden-api-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "bitwarden-api-api"
description = "Api bindings for the Bitwarden API."
categories = ["api-bindings"]

version.workspace = true
Expand All @@ -13,14 +12,10 @@ license-file.workspace = true
keywords.workspace = true

[dependencies]
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_repr = { workspace = true }
serde_with = { version = ">=3.8, <4", default-features = false, features = [
"base64",
"std",
"macros",
] }
url = ">=2.5, <3"
uuid = { workspace = true }
serde = { version = "^1.0", features = ["derive"] }
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
uuid = { version = "^1.8", features = ["serde", "v4"] }
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart", "http2"] }
Loading