-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/major-dotnet-monorepo
- Loading branch information
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" |