Skip to content

Commit

Permalink
MEDIUM: add certificates interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurand0710 committed Nov 6, 2024
1 parent 21a07b0 commit c4d7dd3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
6 changes: 3 additions & 3 deletions runtime/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *SingleRuntime) ShowCertEntry(storageName string) (*models.SslCertEntry,
if storageName == "" {
return nil, fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral)
}
cmd := fmt.Sprintf("show ssl cert %s", storageName)
cmd := "show ssl cert " + storageName
response, err := s.ExecuteWithResponse(cmd)
if err != nil {
return nil, fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound)
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *SingleRuntime) NewCertEntry(storageName string) error {
if storageName == "" {
return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral)
}
cmd := fmt.Sprintf("new ssl cert %s", storageName)
cmd := "new ssl cert " + storageName
response, err := s.ExecuteWithResponse(cmd)
if err != nil {
return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral)
Expand Down Expand Up @@ -186,7 +186,7 @@ func (s *SingleRuntime) CommitCertEntry(storageName string) error {
if storageName == "" {
return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral)
}
cmd := fmt.Sprintf("commit ssl cert %s", storageName)
cmd := "commit ssl cert " + storageName
response, err := s.ExecuteWithResponse(cmd)
if err != nil {
return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral)
Expand Down
8 changes: 8 additions & 0 deletions runtime/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ type Raw interface {
ExecuteRaw(command string) ([]string, error)
}

type Cert interface {
NewCertEntry(filename string) error
SetCertEntry(filename, payload string) error
CommitCertEntry(filename string) error
AddCrtListEntry(crtList string, entry CrtListEntry) error
}

type Runtime interface {
Info
Frontend
Expand All @@ -145,6 +152,7 @@ type Runtime interface {
ACLs
Tables
Raw
Cert
}

func New(_ context.Context, opt ...options.RuntimeOption) (Runtime, error) {
Expand Down
68 changes: 68 additions & 0 deletions runtime/runtime_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,3 +1198,71 @@ func (c *client) CommitACL(version, name string) error {
}
return nil
}

func (c *client) NewCertEntry(filename string) error {
if len(c.runtimes) == 0 {
return fmt.Errorf("no valid runtimes found")
}
var lastErr error
for _, runtime := range c.runtimes {
err := runtime.NewCertEntry(filename)
if err != nil {
lastErr = err
}
}
if lastErr != nil {
return lastErr
}
return nil
}

func (c *client) SetCertEntry(filename string, payload string) error {
if len(c.runtimes) == 0 {
return fmt.Errorf("no valid runtimes found")
}
var lastErr error
for _, runtime := range c.runtimes {
err := runtime.SetCertEntry(filename, payload)
if err != nil {
lastErr = err
}
}
if lastErr != nil {
return lastErr
}
return nil
}

func (c *client) CommitCertEntry(filename string) error {
if len(c.runtimes) == 0 {
return fmt.Errorf("no valid runtimes found")
}
var lastErr error
for _, runtime := range c.runtimes {
err := runtime.CommitCertEntry(filename)
if err != nil {
lastErr = err
}
}
if lastErr != nil {
return lastErr
}
return nil
}

func (c *client) AddCrtListEntry(crtList string, entry CrtListEntry) error {
if len(c.runtimes) == 0 {
return fmt.Errorf("no valid runtimes found")
}
var lastErr error
for _, runtime := range c.runtimes {
err := runtime.AddCrtListEntry(crtList, entry)
if err != nil {
lastErr = err
}
}
if lastErr != nil {
return lastErr
}
return nil
}

0 comments on commit c4d7dd3

Please sign in to comment.