@@ -103,7 +103,7 @@ func AddCert(c *gin.Context) {
103103 "revoke_old" : "omitempty" ,
104104 }).
105105 BeforeExecuteHook (func (ctx * cosy.Ctx [model.Cert ]) {
106- sslCertificate := ctx .Payload ["ssl_certificate" ].( string )
106+ sslCertificate := cast . ToString ( ctx .Payload ["ssl_certificate" ])
107107 // Detect and set certificate type
108108 if sslCertificate != "" {
109109 keyType , err := cert .GetKeyType (sslCertificate )
@@ -125,18 +125,22 @@ func AddCert(c *gin.Context) {
125125 }
126126 }).
127127 ExecutedHook (func (ctx * cosy.Ctx [model.Cert ]) {
128- content := & cert.Content {
129- SSLCertificatePath : ctx .Model .SSLCertificatePath ,
130- SSLCertificateKeyPath : ctx .Model .SSLCertificateKeyPath ,
131- SSLCertificate : ctx .Payload ["ssl_certificate" ].(string ),
132- SSLCertificateKey : ctx .Payload ["ssl_certificate_key" ].(string ),
133- }
134- err := content .WriteFile ()
135- if err != nil {
136- ctx .AbortWithError (err )
137- return
128+ sslCertificate := cast .ToString (ctx .Payload ["ssl_certificate" ])
129+ sslCertificateKey := cast .ToString (ctx .Payload ["ssl_certificate_key" ])
130+ if sslCertificate != "" && sslCertificateKey != "" {
131+ content := & cert.Content {
132+ SSLCertificatePath : ctx .Model .SSLCertificatePath ,
133+ SSLCertificateKeyPath : ctx .Model .SSLCertificateKeyPath ,
134+ SSLCertificate : sslCertificate ,
135+ SSLCertificateKey : sslCertificateKey ,
136+ }
137+ err := content .WriteFile ()
138+ if err != nil {
139+ ctx .AbortWithError (err )
140+ return
141+ }
138142 }
139- err = cert .SyncToRemoteServer (& ctx .Model )
143+ err : = cert .SyncToRemoteServer (& ctx .Model )
140144 if err != nil {
141145 notification .Error ("Sync Certificate Error" , err .Error (), nil )
142146 return
@@ -165,7 +169,7 @@ func ModifyCert(c *gin.Context) {
165169 "revoke_old" : "omitempty" ,
166170 }).
167171 BeforeExecuteHook (func (ctx * cosy.Ctx [model.Cert ]) {
168- sslCertificate := ctx .Payload ["ssl_certificate" ].( string )
172+ sslCertificate := cast . ToString ( ctx .Payload ["ssl_certificate" ])
169173 // Detect and set certificate type
170174 if sslCertificate != "" {
171175 keyType , err := cert .GetKeyType (sslCertificate )
@@ -187,11 +191,14 @@ func ModifyCert(c *gin.Context) {
187191 }
188192 }).
189193 ExecutedHook (func (ctx * cosy.Ctx [model.Cert ]) {
194+ sslCertificate := cast .ToString (ctx .Payload ["ssl_certificate" ])
195+ sslCertificateKey := cast .ToString (ctx .Payload ["ssl_certificate_key" ])
196+
190197 content := & cert.Content {
191198 SSLCertificatePath : ctx .Model .SSLCertificatePath ,
192199 SSLCertificateKeyPath : ctx .Model .SSLCertificateKeyPath ,
193- SSLCertificate : ctx . Payload [ "ssl_certificate" ].( string ) ,
194- SSLCertificateKey : ctx . Payload [ "ssl_certificate_key" ].( string ) ,
200+ SSLCertificate : sslCertificate ,
201+ SSLCertificateKey : sslCertificateKey ,
195202 }
196203 err := content .WriteFile ()
197204 if err != nil {
@@ -203,7 +210,6 @@ func ModifyCert(c *gin.Context) {
203210 notification .Error ("Sync Certificate Error" , err .Error (), nil )
204211 return
205212 }
206-
207213 }).
208214 SetNextHandler (GetCert ).
209215 Modify ()
0 commit comments