5
5
package com .oracle .weblogic .imagetool .cli .cache ;
6
6
7
7
import com .oracle .weblogic .imagetool .api .meta .CacheStore ;
8
- import com .oracle .weblogic .imagetool .api .model .AbstractFile ;
9
8
import com .oracle .weblogic .imagetool .api .model .CommandResponse ;
10
9
import com .oracle .weblogic .imagetool .api .model .WLSInstallerType ;
11
- import com .oracle .weblogic .imagetool .util .ARUUtil ;
12
10
import com .oracle .weblogic .imagetool .util .Constants ;
13
- import com .oracle .weblogic .imagetool .util .SearchResult ;
14
11
import com .oracle .weblogic .imagetool .util .Utils ;
15
- import com .oracle .weblogic .imagetool .util .XPathUtil ;
16
- import org .apache .commons .codec .digest .DigestUtils ;
17
- import org .w3c .dom .Document ;
18
- import picocli .CommandLine .Command ;
19
- import picocli .CommandLine .Option ;
20
12
21
- import java .io .FileInputStream ;
22
- import java .io .IOException ;
23
13
import java .nio .file .Files ;
24
14
import java .nio .file .Path ;
15
+ import java .util .ArrayList ;
16
+ import java .util .List ;
25
17
import java .util .logging .Logger ;
26
18
19
+ import picocli .CommandLine .Command ;
20
+ import picocli .CommandLine .Option ;
21
+
27
22
@ Command (
28
23
name = "addPatch" ,
29
24
description = "Add cache entry for wls|fmw patch or psu" ,
@@ -42,24 +37,17 @@ public AddPatchEntry(boolean isCLIMode) {
42
37
43
38
@ Override
44
39
public CommandResponse call () throws Exception {
45
- String password = handlePasswordOptions ();
46
40
47
41
if (patchId != null && !patchId .isEmpty ()
48
42
&& location != null && Files .exists (location )
49
43
&& Files .isRegularFile (location )) {
50
44
51
- String patchNumber ;
52
- if (patchId .matches (Constants .PATCH_ID_REGEX )) {
53
- patchNumber = patchId .substring (1 );
54
- } else {
55
- return new CommandResponse (-1 , "Invalid patch id format: " + patchId );
56
- }
57
- if (userId != null && !userId .isEmpty () && password != null && !password .isEmpty () ) {
58
- return validateAndAddToCache (patchNumber , password );
59
- } else {
60
- logger .info ("Skipping patch validation, username and password were not provided" );
61
- return addToCache (patchNumber );
45
+ List <String > patches = new ArrayList <>();
46
+ patches .add (patchId );
47
+ if (!Utils .validatePatchIds (patches , true )) {
48
+ return new CommandResponse (-1 , "Patch ID validation failed" );
62
49
}
50
+ return addToCache (patchId );
63
51
}
64
52
65
53
String msg = "Invalid arguments" ;
@@ -81,25 +69,7 @@ public CommandResponse call() throws Exception {
81
69
* @throws Exception if the ARU call to get patch details failed
82
70
*/
83
71
private CommandResponse validateAndAddToCache (String patchNumber , String password ) throws Exception {
84
- boolean matches = false ;
85
-
86
- SearchResult searchResult = ARUUtil .getPatchDetail (type .toString (), version , patchNumber , userId , password );
87
-
88
- if (searchResult .isSuccess ()) {
89
- Document document = searchResult .getResults ();
90
- String patchDigest = XPathUtil .applyXPathReturnString (document , "string"
91
- + "(/results/patch[1]/files/file/digest[@type='SHA-256']/text())" );
92
- String localDigest = DigestUtils .sha256Hex (new FileInputStream (location .toFile ()));
93
-
94
- if (localDigest .equalsIgnoreCase (patchDigest )) {
95
- return addToCache (patchNumber );
96
- } else {
97
- return new CommandResponse (-1 , String .format (
98
- "Local file sha-256 digest %s != patch digest %s" , localDigest , patchDigest ));
99
- }
100
- }
101
-
102
- return new CommandResponse (-1 , String .format ("Unable to find patchId %s on Oracle Support" , patchId ));
72
+ return addToCache (patchNumber );
103
73
}
104
74
105
75
/**
@@ -108,33 +78,31 @@ private CommandResponse validateAndAddToCache(String patchNumber, String passwor
108
78
* @return CLI command response
109
79
*/
110
80
private CommandResponse addToCache (String patchNumber ) {
111
- String key = AbstractFile .generateKey (patchNumber , version );
81
+ logger .info ("adding key " + patchNumber );
82
+ String key = patchNumber ;
112
83
113
84
// Check if it is an Opatch patch
114
85
String opatchNumber = Utils .getOpatchVersionFromZip (location .toAbsolutePath ().toString ());
115
86
if (opatchNumber != null ) {
116
87
int lastSeparator = key .lastIndexOf (CacheStore .CACHE_KEY_SEPARATOR );
117
88
key = key .substring (0 ,lastSeparator ) + CacheStore .CACHE_KEY_SEPARATOR + Constants .OPATCH_PATCH_TYPE ;
118
89
}
90
+ logger .info ("adding key " + key );
91
+ if (cacheStore .getValueFromCache (key ) != null ) {
92
+ String error = String .format ("Cache key %s already exists, remove it first" , key );
93
+ logger .severe (error );
94
+ throw new IllegalArgumentException (error );
95
+ }
119
96
cacheStore .addToCache (key , location .toAbsolutePath ().toString ());
120
97
String msg = String .format ("Added Patch entry %s=%s for %s" , key , location .toAbsolutePath (), type );
121
98
logger .info (msg );
122
99
return new CommandResponse (0 , msg );
123
100
}
124
101
125
- /**
126
- * Determines the support password by parsing the possible three input options
127
- *
128
- * @return String form of password
129
- * @throws IOException in case of error
130
- */
131
- private String handlePasswordOptions () throws IOException {
132
- return Utils .getPasswordFromInputs (passwordStr , passwordFile , passwordEnv );
133
- }
134
102
135
103
@ Option (
136
104
names = {"--patchId" },
137
- description = "Patch number. Ex: p28186730 " ,
105
+ description = "Patch number. Ex: 28186730 " ,
138
106
required = true
139
107
)
140
108
private String patchId ;
@@ -147,13 +115,6 @@ private String handlePasswordOptions() throws IOException {
147
115
)
148
116
private WLSInstallerType type ;
149
117
150
- @ Option (
151
- names = {"--version" },
152
- description = "version of mw this patch is for. Ex: 12.2.1.3.0" ,
153
- required = true ,
154
- defaultValue = Constants .DEFAULT_WLS_VERSION
155
- )
156
- private String version ;
157
118
158
119
@ Option (
159
120
names = {"--path" },
@@ -162,31 +123,4 @@ private String handlePasswordOptions() throws IOException {
162
123
)
163
124
private Path location ;
164
125
165
- @ Option (
166
- names = {"--user" },
167
- paramLabel = "<support email>" ,
168
- description = "Oracle Support email id"
169
- )
170
- private String userId ;
171
-
172
- @ Option (
173
- names = {"--password" },
174
- paramLabel = "<password for support user id>" ,
175
- description = "Password for support userId"
176
- )
177
- String passwordStr ;
178
-
179
- @ Option (
180
- names = {"--passwordEnv" },
181
- paramLabel = "<environment variable>" ,
182
- description = "environment variable containing the support password"
183
- )
184
- String passwordEnv ;
185
-
186
- @ Option (
187
- names = {"--passwordFile" },
188
- paramLabel = "<password file>" ,
189
- description = "path to file containing just the password"
190
- )
191
- Path passwordFile ;
192
126
}
0 commit comments