@@ -2,8 +2,10 @@ package pkg
22
33import (
44 "fmt"
5+ "os"
56 "slices"
67
8+ jks "github.com/pavlo-v-chernykh/keystore-go/v4"
79 "github.com/wttech/aemc/pkg/common/pathx"
810 "github.com/wttech/aemc/pkg/keystore"
911)
@@ -13,7 +15,7 @@ type KeystoreManager struct {
1315}
1416
1517func (km * KeystoreManager ) Status (scope , id string ) (* keystore.Status , error ) {
16- userKeystorePath := composeUserPath (scope , id ) + ".ks.json"
18+ userKeystorePath := composeKeystoreStatusPath (scope , id )
1719
1820 response , err := km .instance .http .Request ().Get (userKeystorePath )
1921
@@ -49,7 +51,7 @@ func (km *KeystoreManager) Create(scope, id, keystorePassword string) (bool, err
4951 ":operation" : "createStore" ,
5052 }
5153
52- userKeystoreCreatePath := composeUserPath (scope , id ) + ".ks.html"
54+ userKeystoreCreatePath := composeKeystoreOperationsPath (scope , id )
5355 postResponse , postError := km .instance .http .Request ().SetQueryParams (pathParams ).Post (userKeystoreCreatePath )
5456
5557 if postError != nil {
@@ -103,7 +105,7 @@ func (km *KeystoreManager) AddKey(scope, id, keystoreFilePath, keystoreFilePassw
103105 "keyStore" : keystoreFilePath ,
104106 }
105107
106- keystorePath := composeUserPath (scope , id ) + ".ks.html"
108+ keystorePath := composeKeystoreOperationsPath (scope , id )
107109 formData := map [string ]string {
108110 "keyStorePass" : keystoreFilePassword ,
109111 "alias" : privateKeyAlias ,
@@ -143,7 +145,7 @@ func (km *KeystoreManager) DeleteKey(scope, id, privateKeyAlias string) (bool, e
143145 "removeAlias" : privateKeyAlias ,
144146 }
145147
146- userKeystorePath := composeUserPath (scope , id ) + ".ks.html"
148+ userKeystorePath := composeKeystoreOperationsPath (scope , id )
147149 response , err := km .instance .http .Request ().
148150 SetFormData (formData ).
149151 Post (userKeystorePath )
@@ -157,3 +159,27 @@ func (km *KeystoreManager) DeleteKey(scope, id, privateKeyAlias string) (bool, e
157159
158160 return true , nil
159161}
162+
163+ func composeKeystoreStatusPath (scope , id string ) string {
164+ return composeUserPath (scope , id ) + ".ks.json"
165+ }
166+
167+ func composeKeystoreOperationsPath (scope , id string ) string {
168+ return composeUserPath (scope , id ) + ".ks.html"
169+ }
170+
171+ func readKeyStore (filename string , password []byte ) (* jks.KeyStore , error ) {
172+ f , err := os .Open (filename )
173+ if err != nil {
174+ return nil , err
175+ }
176+
177+ defer f .Close ()
178+
179+ ks := jks .New ()
180+ if err := ks .Load (f , password ); err != nil {
181+ return nil , err
182+ }
183+
184+ return & ks , nil
185+ }
0 commit comments