-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SM-1371: Add GenerateSecret to Go SDK
- Loading branch information
1 parent
c45d686
commit 14aea6c
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
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,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) | ||
} |