@@ -2,8 +2,10 @@ package pkg
2
2
3
3
import (
4
4
"fmt"
5
+ "os"
5
6
"slices"
6
7
8
+ jks "github.com/pavlo-v-chernykh/keystore-go/v4"
7
9
"github.com/wttech/aemc/pkg/common/pathx"
8
10
"github.com/wttech/aemc/pkg/keystore"
9
11
)
@@ -13,7 +15,7 @@ type KeystoreManager struct {
13
15
}
14
16
15
17
func (km * KeystoreManager ) Status (scope , id string ) (* keystore.Status , error ) {
16
- userKeystorePath := composeUserPath (scope , id ) + ".ks.json"
18
+ userKeystorePath := composeKeystoreStatusPath (scope , id )
17
19
18
20
response , err := km .instance .http .Request ().Get (userKeystorePath )
19
21
@@ -49,7 +51,7 @@ func (km *KeystoreManager) Create(scope, id, keystorePassword string) (bool, err
49
51
":operation" : "createStore" ,
50
52
}
51
53
52
- userKeystoreCreatePath := composeUserPath (scope , id ) + ".ks.html"
54
+ userKeystoreCreatePath := composeKeystoreOperationsPath (scope , id )
53
55
postResponse , postError := km .instance .http .Request ().SetQueryParams (pathParams ).Post (userKeystoreCreatePath )
54
56
55
57
if postError != nil {
@@ -103,7 +105,7 @@ func (km *KeystoreManager) AddKey(scope, id, keystoreFilePath, keystoreFilePassw
103
105
"keyStore" : keystoreFilePath ,
104
106
}
105
107
106
- keystorePath := composeUserPath (scope , id ) + ".ks.html"
108
+ keystorePath := composeKeystoreOperationsPath (scope , id )
107
109
formData := map [string ]string {
108
110
"keyStorePass" : keystoreFilePassword ,
109
111
"alias" : privateKeyAlias ,
@@ -143,7 +145,7 @@ func (km *KeystoreManager) DeleteKey(scope, id, privateKeyAlias string) (bool, e
143
145
"removeAlias" : privateKeyAlias ,
144
146
}
145
147
146
- userKeystorePath := composeUserPath (scope , id ) + ".ks.html"
148
+ userKeystorePath := composeKeystoreOperationsPath (scope , id )
147
149
response , err := km .instance .http .Request ().
148
150
SetFormData (formData ).
149
151
Post (userKeystorePath )
@@ -157,3 +159,27 @@ func (km *KeystoreManager) DeleteKey(scope, id, privateKeyAlias string) (bool, e
157
159
158
160
return true , nil
159
161
}
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