Skip to content

Commit

Permalink
SM-1371: Add GenerateSecret to Go SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonhurst committed Aug 3, 2024
1 parent c45d686 commit 14aea6c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions languages/go/bitwarden_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type BitwardenClientInterface interface {
AccessTokenLogin(accessToken string, stateFile *string) error
Projects() ProjectsInterface
Secrets() SecretsInterface
Generators() GeneratorsInterface
Close()
}

Expand All @@ -19,6 +20,7 @@ type BitwardenClient struct {
commandRunner CommandRunnerInterface
projects ProjectsInterface
secrets SecretsInterface
generators GeneratorsInterface
}

func NewBitwardenClient(apiURL *string, identityURL *string) (BitwardenClientInterface, error) {
Expand Down Expand Up @@ -49,6 +51,7 @@ func NewBitwardenClient(apiURL *string, identityURL *string) (BitwardenClientInt
commandRunner: runner,
projects: NewProjects(runner),
secrets: NewSecrets(runner),
generators: NewGenerators(runner),
}, nil
}

Expand All @@ -73,6 +76,10 @@ func (c *BitwardenClient) Secrets() SecretsInterface {
return c.secrets
}

func (c *BitwardenClient) Generators() GeneratorsInterface {
return c.generators
}

func (c *BitwardenClient) Close() {
c.lib.FreeMem(c.client)
}
34 changes: 34 additions & 0 deletions languages/go/generators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package sdk

type GeneratorsInterface interface {
GenerateSecret(request GenerateSecretRequest) (*GenerateSecretResponse, error)
}

type Generators struct {
CommandRunner CommandRunnerInterface
}

func NewGenerators(commandRunner CommandRunnerInterface) *Generators {
return &Generators{CommandRunner: commandRunner}
}

func (p *Generators) GenerateSecret(request GenerateSecretRequest) (*GenerateSecretResponse, error) {
command := Command{
Generators: &GeneratorsCommand{
GenerateSecret: request,
},
}
var response GenerateSecretResponse
if err := p.executeCommand(command, &response); err != nil {
return nil, err
}
return &response, nil
}

func (g *Generators) executeCommand(command Command, target interface{}) error {
responseStr, err := g.CommandRunner.RunCommand(command)
if err != nil {
return err
}
return checkSuccessAndError(responseStr, target)
}

0 comments on commit 14aea6c

Please sign in to comment.