Skip to content

Commit df97480

Browse files
author
rathnapandi
committed
- fix #576 and #587
1 parent c89a5a0 commit df97480

10 files changed

Lines changed: 120 additions & 78 deletions

File tree

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIFilter.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -455,22 +455,25 @@ public String toString() {
455455
}
456456

457457
public boolean filter(API api) {
458-
if (this.getApiPath() == null && this.getVhost() == null && this.getQueryStringVersion() == null && this.getPolicyName() == null && this.getBackendBasepath() == null
459-
&& this.getTag() == null && this.getInboundSecurity() == null && this.getOutboundAuthentication() == null && this.getOrganization() == null) { // Nothing given to filter out.
458+
if (getApiPath() == null && getVhost() == null && getQueryStringVersion() == null && getPolicyName() == null && getBackendBasepath() == null
459+
&& getTag() == null && getInboundSecurity() == null && getOutboundAuthentication() == null && getOrganization() == null && state == null) { // Nothing given to filter out.
460460
return false;
461461
}
462-
if (this.getPolicyName() != null && (!isPolicyUsed(api, this.getPolicyName()))) {
462+
if (getPolicyName() != null && (!isPolicyUsed(api, getPolicyName()))) {
463463
return true;
464464
}
465-
if (this.getInboundSecurity() != null) {
465+
if (state != null && !state.equalsIgnoreCase(api.getState())) {
466+
return true;
467+
}
468+
if (getInboundSecurity() != null) {
466469
boolean match = false;
467470
if (api.getInboundProfiles() != null) {
468471
for (InboundProfile profile : api.getInboundProfiles().values()) {
469472
if (profile.getSecurityProfile() != null) {
470473
for (SecurityProfile securityProfile : api.getSecurityProfiles()) {
471474
for (SecurityDevice securityDevice : securityProfile.getDevices()) {
472475
List<String> deviceNames = Arrays.asList(securityDevice.getType().getAlternativeNames());
473-
if (deviceNames.contains(this.getInboundSecurity().toLowerCase())) {
476+
if (deviceNames.contains(getInboundSecurity().toLowerCase())) {
474477
match = true;
475478
break;
476479
}
@@ -480,29 +483,29 @@ public boolean filter(API api) {
480483
}
481484
}
482485
if (!match) { // No match found so far, check policy names
483-
match = isPolicyUsed(api, this.getInboundSecurity());
486+
match = isPolicyUsed(api, getInboundSecurity());
484487
}
485488
if (!match) return true; // Requested security is finally not found, return true
486489
}
487-
if (this.getBackendBasepath() != null) {
488-
Pattern pattern = Pattern.compile(this.getBackendBasepath().replace("*", ".*"));
490+
if (getBackendBasepath() != null) {
491+
Pattern pattern = Pattern.compile(getBackendBasepath().replace("*", ".*"));
489492
Matcher matcher = pattern.matcher(api.getServiceProfiles().get("_default").getBasePath());
490493
if (!matcher.matches()) {
491494
return true;
492495
}
493496
}
494-
if (this.getApiType().equals(APIManagerAdapter.TYPE_FRONT_END)) {
495-
if (this.getVhost() != null && !this.getVhost().equals(api.getVhost())) return true;
496-
if (this.getQueryStringVersion() != null && !this.getQueryStringVersion().equals(api.getApiRoutingKey()))
497+
if (getApiType().equals(APIManagerAdapter.TYPE_FRONT_END)) {
498+
if (getVhost() != null && !getVhost().equals(api.getVhost())) return true;
499+
if (getQueryStringVersion() != null && !getQueryStringVersion().equals(api.getApiRoutingKey()))
497500
return true;
498501
}
499-
if (this.getTag() != null) {
502+
if (getTag() != null) {
500503
// Simple filter format tag: "tagValue*"
501-
String tagGroupFilter = this.getTag();
502-
String tagValueFilter = this.getTag();
503-
if (this.getTag().contains("=")) { // Group specific format: "tagGroup=tagValue*"
504-
tagGroupFilter = this.getTag().split("=")[0];
505-
tagValueFilter = this.getTag().split("=")[1];
504+
String tagGroupFilter = getTag();
505+
String tagValueFilter = getTag();
506+
if (getTag().contains("=")) { // Group specific format: "tagGroup=tagValue*"
507+
tagGroupFilter = getTag().split("=")[0];
508+
tagValueFilter = getTag().split("=")[1];
506509
}
507510
Pattern groupPattern = Pattern.compile(tagGroupFilter.toLowerCase().replace("*", ".*"));
508511
Pattern valuePattern = Pattern.compile(tagValueFilter.toLowerCase().replace("*", ".*"));
@@ -531,22 +534,22 @@ public boolean filter(API api) {
531534
// If none of the tags match, filter out this API
532535
if (!match) return true;
533536
}
534-
if (this.getOutboundAuthentication() != null) {
537+
if (getOutboundAuthentication() != null) {
535538
boolean match = false;
536539
if (api.getOutboundProfiles() != null) {
537540
for (OutboundProfile profile : api.getOutboundProfiles().values()) {
538541
if (profile.getAuthenticationProfile() != null) {
539542
for (AuthenticationProfile authnProfile : api.getAuthenticationProfiles()) {
540543
if (authnProfile.getName().equals(profile.getAuthenticationProfile())) {
541544
List<String> authnNames = Arrays.asList(authnProfile.getType().getAlternativeNames());
542-
if (authnNames.contains(this.getOutboundAuthentication().toLowerCase())) {
545+
if (authnNames.contains(getOutboundAuthentication().toLowerCase())) {
543546
match = true;
544547
break;
545548
}
546549
if (authnProfile.getType() == AuthType.oauth) {
547550
String providerProfile = (String) authnProfile.getParameters().get("providerProfile");
548551
providerProfile = Utils.getExternalPolicyName(providerProfile, FedKeyType.OAuthAppProfile);
549-
Pattern pattern = Pattern.compile(this.getOutboundAuthentication().toLowerCase().replace("*", ".*"));
552+
Pattern pattern = Pattern.compile(getOutboundAuthentication().toLowerCase().replace("*", ".*"));
550553
Matcher matcher = pattern.matcher(providerProfile.toLowerCase());
551554
if (matcher.matches()) {
552555
match = true;
@@ -560,8 +563,8 @@ public boolean filter(API api) {
560563
}
561564
if (!match) return true;
562565
}
563-
if (this.getOrganization() != null) {
564-
Pattern pattern = Pattern.compile(this.getOrganization().toLowerCase().replace("*", ".*"));
566+
if (getOrganization() != null) {
567+
Pattern pattern = Pattern.compile(getOrganization().toLowerCase().replace("*", ".*"));
565568
Matcher matcher = pattern.matcher(api.getOrganization().getName().toLowerCase());
566569
return !matcher.matches();
567570
}

modules/apim-adapter/src/main/java/com/axway/apim/adapter/apis/APIManagerAPIAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public List<API> getAPIs(APIFilter filter, boolean logProgress) throws AppExcept
109109
Utils.progressPercentage(i, apis.size(), "Loading details of " + apis.size() + " APIs");
110110
}
111111
}
112-
Utils.addCustomPropertiesForEntity(apis, this.apiManagerResponse.get(filter), filter);
112+
Utils.addCustomPropertiesForEntity(apis, apiManagerResponse.get(filter), filter);
113113
if (logProgress && apis.size() > 5) Console.print("\n");
114114
} catch (IOException e) {
115115
throw new AppException("Cannot read APIs from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e);
@@ -136,7 +136,7 @@ public API getAPIWithId(String id) throws AppException {
136136
* @throws AppException if the API representation cannot be created
137137
*/
138138
private void readAPIsFromAPIManager(APIFilter filter) throws AppException {
139-
if (this.apiManagerResponse.get(filter) != null) return;
139+
if (apiManagerResponse.get(filter) != null) return;
140140
try {
141141
URI uri = getAPIRequestUri(filter);
142142
RestAPICall getRequest = new GETRequest(uri);
@@ -226,7 +226,7 @@ public String getVersion(APIFilter apiFilter) {
226226

227227
private List<API> filterAPIs(APIFilter filter) throws IOException {
228228
LOG.debug("Filtering APIs based on filter path: {}", filter);
229-
List<API> apis = mapper.readValue(this.apiManagerResponse.get(filter), new TypeReference<>() {
229+
List<API> apis = mapper.readValue(apiManagerResponse.get(filter), new TypeReference<>() {
230230
});
231231
apis.removeIf(filter::filter);
232232

modules/apim-cli/src/main/java/com/axway/apim/cli/APIManagerCLI.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ int run(String[] args) {
121121
int rc = 0;
122122
LOG.info("API-Manager CLI: {}", APIManagerCLI.class.getPackage().getImplementationVersion());
123123
if(LOG.isDebugEnabled()) {
124-
LOG.debug("API-Manager CLI args: {}", Arrays.toString(args));
124+
LOG.debug("API-Manager CLI args: {}", maskArgs(args));
125125
LOG.debug("Java Version: {}", System.getProperty("java.version"));
126126
}
127127
if (this.selectedMethod == null) {
@@ -142,4 +142,16 @@ private String getMethodName(Method m) {
142142
return (m.getAnnotation(CLIServiceMethod.class).name().isEmpty()) ? m.getName() : m.getAnnotation(CLIServiceMethod.class).name();
143143
}
144144

145+
public static String maskArgs(String[] args) {
146+
String[] masked = args.clone();
147+
for (int i = 0; i < masked.length; i++) {
148+
if (masked[i].equalsIgnoreCase("--password") || masked[i].equalsIgnoreCase("-p")) {
149+
if (i + 1 < masked.length) {
150+
masked[i + 1] = "****";
151+
}
152+
}
153+
}
154+
return Arrays.toString(masked);
155+
}
156+
145157
}

modules/apis/src/main/java/com/axway/apim/api/export/impl/APIResultHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ protected static List<String> getGrantedOrganizations(API api) {
276276
return grantedOrgs;
277277
}
278278
}
279-
protected APIFilter createFilter() {
279+
280+
protected Builder createFilterBuilder() {
280281
Builder builder = getBaseAPIFilterBuilder();
281282
switch (params.getWide()) {
282283
case standard:
@@ -294,6 +295,6 @@ protected APIFilter createFilter() {
294295
builder.includeClientOrganizations(true);
295296
break;
296297
}
297-
return builder.build();
298+
return builder;
298299
}
299300
}

modules/apis/src/main/java/com/axway/apim/api/export/impl/CSVAPIExporter.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,15 @@ private String getFormattedDate(Long longDate) {
254254

255255
@Override
256256
public APIFilter getFilter() {
257-
APIFilter apiFilter = createFilter();
258-
apiFilter.setState(params.getState());
259-
return apiFilter;
257+
APIFilter.Builder builder = createFilterBuilder();
258+
if (params.getState() != null && params.getState().equalsIgnoreCase("deprecated")) {
259+
builder.isDeprecated(true);
260+
builder.hasState(null);
261+
}
262+
if (params.getState() != null && params.getState().equalsIgnoreCase("retired")) {
263+
builder.isDeprecated(true);
264+
builder.hasState(null);
265+
}
266+
return builder.build();
260267
}
261268
}

modules/apis/src/main/java/com/axway/apim/api/export/impl/ConsoleAPIExporter.java

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,51 @@ public void execute(List<API> apis) throws AppException {
5454

5555
private void printStandard(List<API> apis) {
5656
Console.println(AsciiTable.getTable(borderStyle, apis, Arrays.asList(
57-
new Column().header(ID).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getId),
58-
new Column().header(PATH).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getPath),
59-
new Column().header(NAME).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getName),
60-
new Column().header(VERSION).with(API::getVersion),
61-
new Column().header(CREATED_ON).with(this::getFormattedDate)
57+
new Column().header(ID).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getId),
58+
new Column().header(PATH).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getPath),
59+
new Column().header(NAME).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getName),
60+
new Column().header(VERSION).with(API::getVersion),
61+
new Column().header(CREATED_ON).with(this::getFormattedDate)
6262
)));
6363
printDetails(apis);
6464
}
6565

6666
private void printWide(List<API> apis) {
6767
Console.println(AsciiTable.getTable(borderStyle, apis, Arrays.asList(
68-
new Column().header(ID).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getId),
69-
new Column().header(PATH).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getPath),
70-
new Column().header(NAME).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getName),
71-
new Column().header(VERSION).with(API::getVersion),
72-
new Column().header("V-Host").with(API::getVhost),
73-
new Column().header("State").with(this::getState),
74-
new Column().header("Backend").headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(APIResultHandler::getBackendPath),
75-
new Column().header("Inbound Security").with(APIResultHandler::getUsedSecurity),
76-
new Column().header("Outbound Security").with(APIResultHandler::getUsedOutboundAuthentication),
77-
new Column().header("Policies").dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(this::getUsedPoliciesForConsole),
78-
new Column().header("Organization").dataAlign(HorizontalAlign.LEFT).with(api -> api.getOrganization().getName()),
79-
new Column().header(CREATED_ON).with(this::getFormattedDate)
68+
new Column().header(ID).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getId),
69+
new Column().header(PATH).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getPath),
70+
new Column().header(NAME).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getName),
71+
new Column().header(VERSION).with(API::getVersion),
72+
new Column().header("V-Host").with(API::getVhost),
73+
new Column().header("State").with(this::getState),
74+
new Column().header("Backend").headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(APIResultHandler::getBackendPath),
75+
new Column().header("Inbound Security").with(APIResultHandler::getUsedSecurity),
76+
new Column().header("Outbound Security").with(APIResultHandler::getUsedOutboundAuthentication),
77+
new Column().header("Policies").dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(this::getUsedPoliciesForConsole),
78+
new Column().header("Organization").dataAlign(HorizontalAlign.LEFT).with(api -> api.getOrganization().getName()),
79+
new Column().header(CREATED_ON).with(this::getFormattedDate)
8080
)));
8181
printDetails(apis);
8282
}
8383

8484
private void printUltra(List<API> apis) {
8585
Console.println(AsciiTable.getTable(borderStyle, apis, Arrays.asList(
86-
new Column().header(ID).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getId),
87-
new Column().header(PATH).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getPath),
88-
new Column().header(NAME).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getName),
89-
new Column().header(VERSION).with(API::getVersion),
90-
new Column().header("V-Host").with(API::getVhost),
91-
new Column().header("State").with(this::getState),
92-
new Column().header("Backend").headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(APIResultHandler::getBackendPath),
93-
new Column().header("Inbound Security").with(APIResultHandler::getUsedSecurity),
94-
new Column().header("Outbound Security").with(APIResultHandler::getUsedOutboundAuthentication),
95-
new Column().header("Policies").dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(this::getUsedPoliciesForConsole),
96-
new Column().header("Organization").dataAlign(HorizontalAlign.LEFT).with(api -> api.getOrganization().getName()),
97-
new Column().header("Orgs").with(this::getOrgCount),
98-
new Column().header("Apps").with(this::getAppCount),
99-
new Column().header("Quotas").with(api -> Boolean.toString(hasQuota(api))),
100-
new Column().header("Tags").dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(api -> Boolean.toString(hasTags(api))),
101-
new Column().header(CREATED_ON).with(this::getFormattedDate)
86+
new Column().header(ID).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getId),
87+
new Column().header(PATH).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getPath),
88+
new Column().header(NAME).headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(API::getName),
89+
new Column().header(VERSION).with(API::getVersion),
90+
new Column().header("V-Host").with(API::getVhost),
91+
new Column().header("State").with(this::getState),
92+
new Column().header("Backend").headerAlign(HorizontalAlign.LEFT).dataAlign(HorizontalAlign.LEFT).with(APIResultHandler::getBackendPath),
93+
new Column().header("Inbound Security").with(APIResultHandler::getUsedSecurity),
94+
new Column().header("Outbound Security").with(APIResultHandler::getUsedOutboundAuthentication),
95+
new Column().header("Policies").dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(this::getUsedPoliciesForConsole),
96+
new Column().header("Organization").dataAlign(HorizontalAlign.LEFT).with(api -> api.getOrganization().getName()),
97+
new Column().header("Orgs").with(this::getOrgCount),
98+
new Column().header("Apps").with(this::getAppCount),
99+
new Column().header("Quotas").with(api -> Boolean.toString(hasQuota(api))),
100+
new Column().header("Tags").dataAlign(HorizontalAlign.LEFT).maxWidth(30).with(api -> Boolean.toString(hasTags(api))),
101+
new Column().header(CREATED_ON).with(this::getFormattedDate)
102102
)));
103103
printDetails(apis);
104104
}
@@ -148,12 +148,12 @@ private void printDetails(List<API> apis) {
148148

149149
private boolean hasQuota(API api) {
150150
return (api.getApplicationQuota() != null &&
151-
api.getApplicationQuota().getRestrictions() != null &&
152-
!api.getApplicationQuota().getRestrictions().isEmpty()) ||
153-
(api.getSystemQuota() != null &&
154-
api.getSystemQuota().getRestrictions() != null &&
155-
!api.getSystemQuota().getRestrictions().isEmpty())
156-
;
151+
api.getApplicationQuota().getRestrictions() != null &&
152+
!api.getApplicationQuota().getRestrictions().isEmpty()) ||
153+
(api.getSystemQuota() != null &&
154+
api.getSystemQuota().getRestrictions() != null &&
155+
!api.getSystemQuota().getRestrictions().isEmpty())
156+
;
157157
}
158158

159159
private String getState(API api) {
@@ -195,8 +195,15 @@ private String getSubscribedApplications(API api) {
195195

196196
@Override
197197
public APIFilter getFilter() {
198-
APIFilter apiFilter = createFilter();
199-
apiFilter.setState(params.getState());
200-
return apiFilter;
198+
APIFilter.Builder builder = createFilterBuilder();
199+
if (params.getState() != null && params.getState().equalsIgnoreCase("deprecated")) {
200+
builder.isDeprecated(true);
201+
builder.hasState(null);
202+
}
203+
if (params.getState() != null && params.getState().equalsIgnoreCase("retired")) {
204+
builder.isDeprecated(true);
205+
builder.hasState(null);
206+
}
207+
return builder.build();
201208
}
202209
}

0 commit comments

Comments
 (0)