-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 🎟️ Tracking https://bitwarden.atlassian.net/browse/SM-1268 ## 📔 Objective Review Java language docs. ## ⏰ Reminders before review - Contributor guidelines followed - All formatters and local linters executed and passed - Written new unit and / or integration tests where applicable - Protected functional changes with optionality (feature flags) - Used internationalization (i18n) for all UI strings - CI builds passed - Communicated to DevOps any deployment requirements - Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team ## 🦮 Reviewer guidelines <!-- Suggested interactions but feel free to use (or not) as you desire! --> - 👍 (`:+1:`) or similar for great changes - 📝 (`:memo:`) or ℹ️ (`:information_source:`) for notes or general info - ❓ (`:question:`) for questions - 🤔 (`:thinking:`) or 💭 (`:thought_balloon:`) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion - 🎨 (`:art:`) for suggestions / improvements - ❌ (`:x:`) or⚠️ (`:warning:`) for more significant problems or concerns needing attention - 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements or indications of technical debt - ⛏ (`:pick:`) for minor or nitpick changes --------- Co-authored-by: Thomas Avery <[email protected]>
- Loading branch information
1 parent
6decd1f
commit 91cf1a5
Showing
7 changed files
with
171 additions
and
55 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Java build | ||
|
||
## Introduction | ||
|
||
Gradle is used to build Java Bitwarden client library. | ||
|
||
The output of the build is placed in `build/libs` directory and should contain `BitwardenSDK.jar` file. | ||
|
||
## Prerequisites | ||
|
||
- JDK 17 installed. | ||
- Bitwarden SDK native library build. See [SDK README.md](../../README.md) for instructions. | ||
|
||
## Build Commands | ||
|
||
```shell | ||
./gradlew build | ||
``` | ||
|
||
## Example | ||
|
||
### macOS | ||
|
||
#### Install Prerequisites | ||
|
||
Use brew to install JDK 17. | ||
|
||
```shell | ||
brew install --cask temurin@17 | ||
brew install jenv | ||
export PATH="$HOME/.jenv/bin:$PATH" | ||
eval "$(jenv init -)" | ||
jenv add /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home | ||
jenv shell 17 | ||
``` | ||
|
||
#### Build Commands | ||
|
||
```shell | ||
./gradlew build | ||
``` | ||
|
||
## Example SDK Usage Project | ||
|
||
```shell | ||
export ACCESS_TOKEN="<access_token>" | ||
export ORGANIZATION_ID="<organization_id>" | ||
export API_URL="https://api.bitwarden.com" | ||
export IDENTITY_URL="https://identity.bitwarden.com" | ||
|
||
./gradlew :example:run | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import java.lang.System; | ||
import java.util.UUID; | ||
|
||
import com.bitwarden.sdk.*; | ||
import com.bitwarden.sdk.schema.*; | ||
|
||
class Example { | ||
public static void main(String[] args) { | ||
if (!System.getenv().containsKey("ACCESS_TOKEN") || !System.getenv().containsKey("ORGANIZATION_ID")) { | ||
System.err.println("Missing environment variable ACCESS_TOKEN or ORGANIZATION_ID"); | ||
System.exit(1); | ||
} | ||
|
||
String accessToken = System.getenv("ACCESS_TOKEN"); | ||
UUID organizationId = UUID.fromString(System.getenv("ORGANIZATION_ID")); | ||
String apiUrl = System.getenv("API_URL"); | ||
String identityUrl = System.getenv("IDENTITY_URL"); | ||
|
||
// Configuring the URLS is optional, remove them to use the default values | ||
BitwardenSettings bitwardenSettings = new BitwardenSettings(); | ||
bitwardenSettings.setApiUrl(apiUrl); | ||
bitwardenSettings.setIdentityUrl(identityUrl); | ||
|
||
try (BitwardenClient client = new BitwardenClient(bitwardenSettings)) { | ||
client.accessTokenLogin(accessToken); | ||
|
||
ProjectResponse project = client.projects().create(organizationId, "Test Project"); | ||
System.out.println("Project id: " + project.getID()); | ||
|
||
project = client.projects().get(project.getID()); | ||
|
||
ProjectsResponse projects = client.projects().list(organizationId); | ||
System.out.println("Projects count: " + projects.getData().length); | ||
|
||
client.projects().update(project.getID(), organizationId, "Updated Test Project"); | ||
|
||
SecretResponse secret = client.secrets().create("Secret Key", "Secret Value", "Secret Note", | ||
organizationId, new UUID[]{project.getID()}); | ||
System.out.println("Secret id: " + secret.getID()); | ||
|
||
secret = client.secrets().get(secret.getID()); | ||
|
||
SecretIdentifiersResponse secrets = client.secrets().list(organizationId); | ||
System.out.println("Secrets count: " + secrets.getData().length); | ||
|
||
client.secrets().update(secret.getID(), "Updated Key", "Updated Value", "Updated Noye", organizationId, new UUID[]{project.getID()}); | ||
|
||
client.secrets().delete(new UUID[]{secret.getID()}); | ||
client.projects().delete(new UUID[]{project.getID()}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plugins { | ||
id 'application' | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation rootProject | ||
} | ||
|
||
application { | ||
mainClass = 'Example' | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java.srcDirs += '.' | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
*/ | ||
|
||
rootProject.name = 'BitwardenSDK' | ||
|
||
include "example" |