Skip to content

Commit

Permalink
Merge branch 'main' into ps/pm-3436-username-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-garcia authored Dec 14, 2023
2 parents 43ef474 + 7ec2183 commit e252485
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 59 deletions.
4 changes: 4 additions & 0 deletions crates/bws/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Ability to output secrets in an `env` format with `bws` (#320)

## [0.3.1] - 2023-10-13

### Added
Expand Down
15 changes: 8 additions & 7 deletions languages/cpp/examples/Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ int main() {
const char* accessTokenEnv = std::getenv("ACCESS_TOKEN");
const char* organizationIdEnv = std::getenv("ORGANIZATION_ID");

const char* apiUrl = std::getenv("API_URL");
const char* identityUrl = std::getenv("IDENTITY_URL");

if (!accessTokenEnv || !organizationIdEnv) {
std::cerr << "Error: Environment variables ACCESS_TOKEN or ORGANIZATION_ID not set." << std::endl;
return 1;
Expand All @@ -15,15 +18,13 @@ int main() {
std::string accessToken = accessTokenEnv;
std::string organizationId = organizationIdEnv;



// Optional - commented to use default values
// BitwardenSettings bitwardenSettings;
// bitwardenSettings.set_api_url("<bitwarden-url>");
// bitwardenSettings.set_identity_url("<bitwarden-identity>");
// Configuring the URLS is optional, remove them to use the default values
BitwardenSettings bitwardenSettings;
bitwardenSettings.set_api_url(apiUrl);
bitwardenSettings.set_identity_url(identityUrl);

// Create a Bitwarden client instance
BitwardenClient bitwardenClient = BitwardenClient();
BitwardenClient bitwardenClient = BitwardenClient(bitwardenSettings);
// // Access token login
bitwardenClient.accessTokenLogin(accessToken);
// Organization ID
Expand Down
1 change: 1 addition & 0 deletions languages/go/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func main() {
// Configuring the URLS is optional, set them to nil to use the default values
apiURL := os.Getenv("API_URL")
identityURL := os.Getenv("IDENTITY_URL")

Expand Down
33 changes: 33 additions & 0 deletions languages/java/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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) {

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);
BitwardenClient client = new BitwardenClient(bitwardenSettings);
client.accessTokenLogin(accessToken);


ProjectResponse project = client.projects().create(organizationId, "Test Project");
ProjectsResponse list = client.projects().list(organizationId);

SecretResponse secret = client.secrets().create("Secret Key", "Secret Value", "Secret Note", organizationId, new UUID[] { project.getID() });

System.out.println("Secret: " + secret.getValue());

client.secrets().delete(new UUID[] { secret.getID() });
client.projects().delete(new UUID[] { project.getID() });
}
}
42 changes: 0 additions & 42 deletions languages/java/src/main/java/com/bitwarden/sdk/ExampleProgram.java

This file was deleted.

10 changes: 7 additions & 3 deletions languages/php/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

require_once 'vendor/autoload.php';

$access_token = '<you access token here>';
$organization_id = "<your organization id here>";
$access_token = getenv('ACCESS_TOKEN');
$organization_id = getenv('ORGANIZATION_ID');

$client_settings = new \Bitwarden\Sdk\BitwardenSettings();
// Configuring the URLS is optional, set them to null to use the default values
$api_url = getenv('API_URL');
$identity_url = getenv('IDENTITY_URL');

$client_settings = new \Bitwarden\Sdk\BitwardenSettings($api_url, $identity_url);

$bitwarden_client = new \Bitwarden\Sdk\BitwardenClient($client_settings);
$bitwarden_client->access_token_login($access_token);
Expand Down
2 changes: 1 addition & 1 deletion languages/ruby/bitwarden_sdk/lib/bitwarden-sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(bitwarden_settings)
)

@bitwarden = BitwardenLib
@handle = @bitwarden.init(client_settings.to_json)
@handle = @bitwarden.init(client_settings.to_dynamic.compact.to_json)
@command_runner = CommandRunner.new(@bitwarden, @handle)
@project_client = ProjectsClient.new(@command_runner)
@secrets_client = SecretsClient.new(@command_runner)
Expand Down
13 changes: 7 additions & 6 deletions languages/ruby/examples/example.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# NOTE - for example purpose only - import gem instead
require 'bitwarden-sdk'

token = '<insert access token here>'
organization_id = '<organization id here>'
token = ENV['ACCESS_TOKEN']
organization_id = ENV['ORGANIZATION_ID']

bitwarden_settings = BitwardenSDK::BitwardenSettings.new(
'https://api.bitwarden.com',
'https://identity.bitwarden.com/connect/token'
)
# Configuring the URLS is optional, set them to nil to use the default values
api_url = ENV['API_URL']
identity_url = ENV['IDENTITY_URL']

bitwarden_settings = BitwardenSDK::BitwardenSettings.new(api_url, identity_url)

bw_client = BitwardenSDK::BitwardenClient.new(bitwarden_settings)
response = bw_client.access_token_login(token)
Expand Down

0 comments on commit e252485

Please sign in to comment.