Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SM-1214] Add secrets syncing support to Go #742

Merged
merged 20 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
89ec8c0
generate API bindings
Thomas-Avery Mar 21, 2024
2325628
Add secrets sync
Thomas-Avery Mar 22, 2024
e12b0c1
Remove needless return
Thomas-Avery Mar 25, 2024
dd87d32
Merge branch 'main' into sm/sm-1153-update-bitwarden-api
Thomas-Avery Mar 25, 2024
324db70
Merge branch 'sm/sm-1153-update-bitwarden-api' into sm/sm-1153-secret…
Thomas-Avery Mar 25, 2024
e433c7c
Merge branch 'main' into sm/sm-1153-update-bitwarden-api
Thomas-Avery Apr 2, 2024
8006666
Merge branch 'sm/sm-1153-update-bitwarden-api' into sm/sm-1153-secret…
Thomas-Avery Apr 2, 2024
292d97c
use require
Thomas-Avery Apr 2, 2024
bf0310f
Merge branch 'main' into sm/sm-1153-update-bitwarden-api
Thomas-Avery Apr 26, 2024
aa38e42
Merge branch 'sm/sm-1153-update-bitwarden-api' into sm/sm-1153-secret…
Thomas-Avery Apr 26, 2024
8e9ac53
Add secret syncing support to Go
Thomas-Avery Apr 26, 2024
a83bdfc
run fmt
Thomas-Avery Apr 26, 2024
79902d8
Merge branch 'main' into sm/sm-1153-update-bitwarden-api
Thomas-Avery May 15, 2024
032363c
generate api bindings off of main
Thomas-Avery May 15, 2024
798b80d
Merge branch 'sm/sm-1153-update-bitwarden-api' into sm/sm-1153-secret…
Thomas-Avery May 15, 2024
7848c96
Merge branch 'sm/sm-1153-secrets-sync' into sm/sm-1214
Thomas-Avery May 15, 2024
e78de90
Merge branch 'main' into sm/sm-1153-secrets-sync
Thomas-Avery May 15, 2024
47a48fc
Add to change log
Thomas-Avery May 15, 2024
e993065
Merge branch 'sm/sm-1153-secrets-sync' into sm/sm-1214
Thomas-Avery May 15, 2024
93a97e3
Merge branch 'main' into sm/sm-1214
Thomas-Avery May 15, 2024
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
1 change: 1 addition & 0 deletions crates/bitwarden-json/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
SecretsCommand::List(req) => client.secrets().list(&req).await.into_string(),
SecretsCommand::Update(req) => client.secrets().update(&req).await.into_string(),
SecretsCommand::Delete(req) => client.secrets().delete(req).await.into_string(),
SecretsCommand::Sync(req) => client.secrets().sync(&req).await.into_string(),

Check warning on line 76 in crates/bitwarden-json/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-json/src/client.rs#L76

Added line #L76 was not covered by tests
},

#[cfg(feature = "secrets")]
Expand Down
12 changes: 11 additions & 1 deletion crates/bitwarden-json/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bitwarden::{
},
secrets::{
SecretCreateRequest, SecretGetRequest, SecretIdentifiersRequest, SecretPutRequest,
SecretsDeleteRequest, SecretsGetRequest,
SecretsDeleteRequest, SecretsGetRequest, SecretsSyncRequest,
},
},
};
Expand Down Expand Up @@ -123,6 +123,16 @@ pub enum SecretsCommand {
///
/// Returns: [SecretsDeleteResponse](bitwarden::secrets_manager::secrets::SecretsDeleteResponse)
Delete(SecretsDeleteRequest),

/// > Requires Authentication
/// > Requires using an Access Token for login
/// Retrieve the secrets accessible by the authenticated machine account
/// Optionally, provide the last synced date to assess whether any changes have occurred
/// If changes are detected, retrieves all the secrets accessible by the authenticated machine
/// account
///
/// Returns: [SecretsSyncResponse](bitwarden::secrets_manager::secrets::SecretsSyncResponse)
Sync(SecretsSyncRequest),
}

#[cfg(feature = "secrets")]
Expand Down
1 change: 1 addition & 0 deletions crates/sdk-schemas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct SchemaTypes {
secret: Response<bitwarden::secrets_manager::secrets::SecretResponse>,
secrets: Response<bitwarden::secrets_manager::secrets::SecretsResponse>,
secrets_delete: Response<bitwarden::secrets_manager::secrets::SecretsDeleteResponse>,
secrets_sync: Response<bitwarden::secrets_manager::secrets::SecretsSyncResponse>,
project: Response<bitwarden::secrets_manager::projects::ProjectResponse>,
projects: Response<bitwarden::secrets_manager::projects::ProjectsResponse>,
projects_delete: Response<bitwarden::secrets_manager::projects::ProjectsDeleteResponse>,
Expand Down
9 changes: 9 additions & 0 deletions languages/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ secret, err := client.Secrets.Update("secret_id", "new_key", "new_value", "new_n
secret, err := client.Secrets.Delete([]string{"secret_id_1", "secret_id_2"})
```

#### Secrets Sync

```go
secretsSync, err := client.Secrets.Sync("organization_id", nil)

lastSyncedDate := time.Now()
secretsSync, err := client.Secrets.Sync("organization_id", lastSyncedDate)
```

---

### Close Client
Expand Down
26 changes: 26 additions & 0 deletions languages/go/secrets.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package sdk

import "time"

type SecretsInterface interface {
Create(key, value, note string, organizationID string, projectIDs []string) (*SecretResponse, error)
List(organizationID string) (*SecretIdentifiersResponse, error)
Get(secretID string) (*SecretResponse, error)
GetByIDS(secretIDs []string) (*SecretsResponse, error)
Update(secretID string, key, value, note string, organizationID string, projectIDs []string) (*SecretResponse, error)
Delete(secretIDs []string) (*SecretsDeleteResponse, error)
Sync(organizationID string, lastSyncedDate *time.Time) (*SecretsSyncResponse, error)
}

type Secrets struct {
Expand Down Expand Up @@ -129,3 +132,26 @@ func (s *Secrets) Delete(ids []string) (*SecretsDeleteResponse, error) {
}
return &response, nil
}

func (s *Secrets) Sync(organizationID string, lastSyncedDate *time.Time) (*SecretsSyncResponse, error) {
var lastSyncedDateString *string
if lastSyncedDate != nil {
tempRfc3339 := lastSyncedDate.UTC().Format(time.RFC3339)
lastSyncedDateString = &tempRfc3339
}

command := Command{
Secrets: &SecretsCommand{
Sync: &SecretsSyncRequest{
OrganizationID: organizationID,
LastSyncedDate: lastSyncedDateString,
},
},
}

var response SecretsSyncResponse
if err := s.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}
Loading