Skip to content

Commit c4d7dd3

Browse files
committed
MEDIUM: add certificates interface
1 parent 21a07b0 commit c4d7dd3

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

runtime/certs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *SingleRuntime) ShowCertEntry(storageName string) (*models.SslCertEntry,
7979
if storageName == "" {
8080
return nil, fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral)
8181
}
82-
cmd := fmt.Sprintf("show ssl cert %s", storageName)
82+
cmd := "show ssl cert " + storageName
8383
response, err := s.ExecuteWithResponse(cmd)
8484
if err != nil {
8585
return nil, fmt.Errorf("%s %w", err.Error(), native_errors.ErrNotFound)
@@ -154,7 +154,7 @@ func (s *SingleRuntime) NewCertEntry(storageName string) error {
154154
if storageName == "" {
155155
return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral)
156156
}
157-
cmd := fmt.Sprintf("new ssl cert %s", storageName)
157+
cmd := "new ssl cert " + storageName
158158
response, err := s.ExecuteWithResponse(cmd)
159159
if err != nil {
160160
return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral)
@@ -186,7 +186,7 @@ func (s *SingleRuntime) CommitCertEntry(storageName string) error {
186186
if storageName == "" {
187187
return fmt.Errorf("%s %w", "Argument storageName empty", native_errors.ErrGeneral)
188188
}
189-
cmd := fmt.Sprintf("commit ssl cert %s", storageName)
189+
cmd := "commit ssl cert " + storageName
190190
response, err := s.ExecuteWithResponse(cmd)
191191
if err != nil {
192192
return fmt.Errorf("%s %w", err.Error(), native_errors.ErrGeneral)

runtime/interface.go

+8
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ type Raw interface {
136136
ExecuteRaw(command string) ([]string, error)
137137
}
138138

139+
type Cert interface {
140+
NewCertEntry(filename string) error
141+
SetCertEntry(filename, payload string) error
142+
CommitCertEntry(filename string) error
143+
AddCrtListEntry(crtList string, entry CrtListEntry) error
144+
}
145+
139146
type Runtime interface {
140147
Info
141148
Frontend
@@ -145,6 +152,7 @@ type Runtime interface {
145152
ACLs
146153
Tables
147154
Raw
155+
Cert
148156
}
149157

150158
func New(_ context.Context, opt ...options.RuntimeOption) (Runtime, error) {

runtime/runtime_client.go

+68
Original file line numberDiff line numberDiff line change
@@ -1198,3 +1198,71 @@ func (c *client) CommitACL(version, name string) error {
11981198
}
11991199
return nil
12001200
}
1201+
1202+
func (c *client) NewCertEntry(filename string) error {
1203+
if len(c.runtimes) == 0 {
1204+
return fmt.Errorf("no valid runtimes found")
1205+
}
1206+
var lastErr error
1207+
for _, runtime := range c.runtimes {
1208+
err := runtime.NewCertEntry(filename)
1209+
if err != nil {
1210+
lastErr = err
1211+
}
1212+
}
1213+
if lastErr != nil {
1214+
return lastErr
1215+
}
1216+
return nil
1217+
}
1218+
1219+
func (c *client) SetCertEntry(filename string, payload string) error {
1220+
if len(c.runtimes) == 0 {
1221+
return fmt.Errorf("no valid runtimes found")
1222+
}
1223+
var lastErr error
1224+
for _, runtime := range c.runtimes {
1225+
err := runtime.SetCertEntry(filename, payload)
1226+
if err != nil {
1227+
lastErr = err
1228+
}
1229+
}
1230+
if lastErr != nil {
1231+
return lastErr
1232+
}
1233+
return nil
1234+
}
1235+
1236+
func (c *client) CommitCertEntry(filename string) error {
1237+
if len(c.runtimes) == 0 {
1238+
return fmt.Errorf("no valid runtimes found")
1239+
}
1240+
var lastErr error
1241+
for _, runtime := range c.runtimes {
1242+
err := runtime.CommitCertEntry(filename)
1243+
if err != nil {
1244+
lastErr = err
1245+
}
1246+
}
1247+
if lastErr != nil {
1248+
return lastErr
1249+
}
1250+
return nil
1251+
}
1252+
1253+
func (c *client) AddCrtListEntry(crtList string, entry CrtListEntry) error {
1254+
if len(c.runtimes) == 0 {
1255+
return fmt.Errorf("no valid runtimes found")
1256+
}
1257+
var lastErr error
1258+
for _, runtime := range c.runtimes {
1259+
err := runtime.AddCrtListEntry(crtList, entry)
1260+
if err != nil {
1261+
lastErr = err
1262+
}
1263+
}
1264+
if lastErr != nil {
1265+
return lastErr
1266+
}
1267+
return nil
1268+
}

0 commit comments

Comments
 (0)