Skip to content

Commit

Permalink
SM-1237: Update cgo flags and the BitwardenClient struct + interface
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed May 23, 2024
1 parent 88d20a3 commit a5a00f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions languages/go/bitwarden_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (

type BitwardenClientInterface interface {
AccessTokenLogin(accessToken string, statePath *string) error
GetProjects() ProjectsInterface
GetSecrets() SecretsInterface
Projects() ProjectsInterface
Secrets() SecretsInterface
Close()
}

type BitwardenClient struct {
client cinterface.ClientPointer
lib cinterface.BitwardenLibrary
commandRunner CommandRunnerInterface
Projects ProjectsInterface
Secrets SecretsInterface
projects ProjectsInterface
secrets SecretsInterface
}

func NewBitwardenClient(apiURL *string, identityURL *string) (BitwardenClientInterface, error) {
Expand Down Expand Up @@ -47,8 +47,8 @@ func NewBitwardenClient(apiURL *string, identityURL *string) (BitwardenClientInt
lib: lib,
client: client,
commandRunner: runner,
Projects: NewProjects(runner),
Secrets: NewSecrets(runner),
projects: NewProjects(runner),
secrets: NewSecrets(runner),
}, nil
}

Expand All @@ -65,12 +65,12 @@ func (c *BitwardenClient) AccessTokenLogin(accessToken string, statePath *string
return checkSuccessAndError(responseStr, &response)
}

func (c *BitwardenClient) GetProjects() ProjectsInterface {
return c.Projects
func (c *BitwardenClient) Projects() ProjectsInterface {
return c.projects
}

func (c *BitwardenClient) GetSecrets() SecretsInterface {
return c.Secrets
func (c *BitwardenClient) Secrets() SecretsInterface {
return c.secrets
}

func (c *BitwardenClient) Close() {
Expand Down
24 changes: 12 additions & 12 deletions languages/go/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,57 @@ func main() {
panic(err)
}

project, err := bitwardenClient.Projects.Create(organizationID.String(), projectName)
project, err := bitwardenClient.Projects().Create(organizationID.String(), projectName)
if err != nil {
panic(err)
}
fmt.Println(project)
projectID := project.ID
fmt.Println(projectID)

if _, err = bitwardenClient.Projects.List(organizationID.String()); err != nil {
if _, err = bitwardenClient.Projects().List(organizationID.String()); err != nil {
panic(err)
}

if _, err = bitwardenClient.Projects.Get(projectID); err != nil {
if _, err = bitwardenClient.Projects().Get(projectID); err != nil {
panic(err)
}

if _, err = bitwardenClient.Projects.Update(projectID, organizationID.String(), projectName+"2"); err != nil {
if _, err = bitwardenClient.Projects().Update(projectID, organizationID.String(), projectName+"2"); err != nil {
panic(err)
}

key := "key"
value := "value"
note := "note"

secret, err := bitwardenClient.Secrets.Create(key, value, note, organizationID.String(), []string{projectID})
secret, err := bitwardenClient.Secrets().Create(key, value, note, organizationID.String(), []string{projectID})
if err != nil {
panic(err)
}
secretID := secret.ID

if _, err = bitwardenClient.Secrets.List(organizationID.String()); err != nil {
if _, err = bitwardenClient.Secrets().List(organizationID.String()); err != nil {
panic(err)
}

if _, err = bitwardenClient.Secrets.Get(secretID); err != nil {
if _, err = bitwardenClient.Secrets().Get(secretID); err != nil {
panic(err)
}

if _, err = bitwardenClient.Secrets.Update(secretID, key, value, note, organizationID.String(), []string{projectID}); err != nil {
if _, err = bitwardenClient.Secrets().Update(secretID, key, value, note, organizationID.String(), []string{projectID}); err != nil {
panic(err)
}

if _, err = bitwardenClient.Secrets.Delete([]string{secretID}); err != nil {
if _, err = bitwardenClient.Secrets().Delete([]string{secretID}); err != nil {
panic(err)
}

if _, err = bitwardenClient.Projects.Delete([]string{projectID}); err != nil {
if _, err = bitwardenClient.Projects().Delete([]string{projectID}); err != nil {
panic(err)
}

secretIdentifiers, err := bitwardenClient.Secrets.List(organizationID.String())
secretIdentifiers, err := bitwardenClient.Secrets().List(organizationID.String())
if err != nil {
panic(err)
}
Expand All @@ -100,7 +100,7 @@ func main() {
secretIDs[i] = identifier.ID
}

secrets, err := bitwardenClient.Secrets.GetByIDS(secretIDs)
secrets, err := bitwardenClient.Secrets().GetByIDS(secretIDs)
if err != nil {
log.Fatalf("Error getting secrets: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions languages/go/internal/cinterface/bitwarden_library.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
#cgo LDFLAGS: -lbitwarden_c
#cgo linux,amd64 LDFLAGS: -L ./lib/linux-x64
#cgo linux,arm64 LDFLAGS: -L ./lib/linux-arm64
#cgo darwin,amd64 LDFLAGS: -L ./lib/darwin-x64
#cgo darwin,arm64 LDFLAGS: -L ./lib/darwin-arm64
#cgo windows,amd64 LDFLAGS: -L ./lib/windows-x64
#cgo darwin,amd64 LDFLAGS: -L ./lib/darwin-x64 -framework Security -framework SystemConfiguration
#cgo darwin,arm64 LDFLAGS: -L ./lib/darwin-arm64 -framework Security -framework SystemConfiguration
#cgo windows,amd64 LDFLAGS: -L ./lib/windows-x64 -lbitwarden_c -ladvapi32 -lbcrypt -lcrypt32 -lcryptnet -lkernel32 -lncrypt -lntdll -luserenv -lws2_32 -lmsvcrt
#include <stdlib.h>
typedef void* ClientPtr;
extern char* run_command(const char *command, ClientPtr client);
Expand Down

0 comments on commit a5a00f3

Please sign in to comment.