Skip to content

Commit aff187b

Browse files
author
Chris Wiechmann
committed
Merge branch 'develop' into test-with-7.7-20200130
2 parents c28e8e7 + bb32b6f commit aff187b

82 files changed

Lines changed: 1774 additions & 364 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,33 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
8+
### Added
9+
- Feature to use a YAML based API-Definition for Swagger & OpenAPI (API-Manager 7.7 only)
10+
- API Backend-Server information in wide and ultra view console get view
11+
- Option to filter API having a specificied backendBasepath
12+
- Show API detail information if only 1 API is found (See issue [#11](https://github.com/Axway-API-Management-Plus/apim-cli/issues/11))
13+
- Feature to load the API-Definition from FE-API (See issue [#4](https://github.com/Axway-API-Management-Plus/apim-cli/issues/4))
14+
- Feature to export APIs as a CSV-File
15+
- CLI usage information for all operations improved
16+
17+
### Changed
18+
- API Console ultra view not longer renders API-Tags in detail. Only indicated with True & False
19+
- renamed parameter -l / --localFolder TO -t / --target
20+
- renamed parameter -df / --deleteFolder TO -deleteTarget
21+
- renamed parameter -f / --format TO -o --output
22+
23+
### Fixed
24+
- Wrong info text during deletion of an unpublished API proxy (See issue [#25](https://github.com/Axway-API-Management-Plus/apim-cli/issues/25))
25+
26+
### Security
27+
- Bump jackson-databind from 2.9.10.4 to 2.9.10.5
28+
29+
## [1.0.1] 2020-06-17
830
### Fixed
931
- Custom-Properties missing in API-Export (See issue [#13](https://github.com/Axway-API-Management-Plus/apim-cli/issues/13))
32+
- NullPointerException during App export when using OrgAdmin (See issue [#16](https://github.com/Axway-API-Management-Plus/apim-cli/issues/16))
33+
- NullPointerException with option -ultra when using OrgAdmin (See issue [#12](https://github.com/Axway-API-Management-Plus/apim-cli/issues/12))
34+
- Wrong info text during update of an unpublished API proxy (See issue [#15](https://github.com/Axway-API-Management-Plus/apim-cli/issues/15))
1035

1136
## [1.0.0] 2020-06-15
1237
### Added

distribution/assembly/dist-release.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<includes>
6666
<include>README.md</include>
6767
<include>LICENSE</include>
68+
<include>CHANGELOG.md</include>
6869
</includes>
6970
</fileSet>
7071
</fileSets>

distribution/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<goal>single</goal>
4848
</goals>
4949
<configuration>
50-
<finalName>apimanager-apimcli-${project.version}</finalName>
50+
<finalName>axway-apimcli-${project.version}</finalName>
5151
<appendAssemblyId>false</appendAssemblyId>
5252
<descriptors>
5353
<descriptor>assembly/dist-release.xml</descriptor>

modules/api-export/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575
<groupId>com.fasterxml.jackson.core</groupId>
7676
<artifactId>jackson-databind</artifactId>
7777
</dependency>
78+
<dependency>
79+
<groupId>org.apache.commons</groupId>
80+
<artifactId>commons-csv</artifactId>
81+
</dependency>
7882
<dependency>
7983
<groupId>com.consol.citrus</groupId>
8084
<artifactId>citrus-core</artifactId>

modules/api-export/src/main/java/com/axway/apim/APIExportApp.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
import com.axway.apim.api.API;
1111
import com.axway.apim.api.export.impl.APIResultHandler;
1212
import com.axway.apim.api.export.impl.APIResultHandler.APIListImpl;
13+
import com.axway.apim.api.export.lib.APIDeleteCLIOptions;
1314
import com.axway.apim.api.export.lib.APIExportGetCLIOptions;
14-
import com.axway.apim.api.export.lib.APIExportCLIOptions;
1515
import com.axway.apim.api.export.lib.APIExportParams;
16-
import com.axway.apim.api.export.lib.APIDeleteCLIOptions;
16+
import com.axway.apim.api.export.lib.APIUnpublishCLIOptions;
1717
import com.axway.apim.cli.APIMCLIServiceProvider;
1818
import com.axway.apim.cli.CLIServiceMethod;
1919
import com.axway.apim.lib.errorHandling.AppException;
2020
import com.axway.apim.lib.errorHandling.ErrorCode;
21+
import com.axway.apim.lib.errorHandling.ErrorCodeMapper;
2122
import com.axway.apim.lib.errorHandling.ErrorState;
2223
import com.axway.apim.lib.utils.rest.APIMHttpClient;
2324

@@ -28,24 +29,38 @@
2829
public class APIExportApp implements APIMCLIServiceProvider {
2930

3031
private static Logger LOG = LoggerFactory.getLogger(APIExportApp.class);
32+
33+
private static ErrorState errorState = ErrorState.getInstance();
3134

3235
public static void main(String args[]) {
33-
int rc = delete(args);
36+
int rc = export(args);
3437
System.exit(rc);
3538
}
3639

3740
@CLIServiceMethod(name = "get", description = "Get APIs from the API-Manager in different formats")
3841
public static int export(String args[]) {
3942
try {
4043
APIExportParams params = new APIExportParams(new APIExportGetCLIOptions(args));
41-
switch(params.getExportFormat()) {
44+
switch(params.getOutputFormat()) {
4245
case console:
4346
return runExport(params, APIListImpl.CONSOLE_EXPORTER);
4447
case json:
4548
return runExport(params, APIListImpl.JSON_EXPORTER);
49+
case csv:
50+
return runExport(params, APIListImpl.CSV_EXPORTER);
4651
default:
4752
return runExport(params, APIListImpl.CONSOLE_EXPORTER);
4853
}
54+
} catch (AppException e) {
55+
56+
if(errorState.hasError()) {
57+
errorState.logErrorMessages(LOG);
58+
if(errorState.isLogStackTrace()) LOG.error(e.getMessage(), e);
59+
return new ErrorCodeMapper().getMapedErrorCode(errorState.getErrorCode()).getCode();
60+
} else {
61+
LOG.error(e.getMessage(), e);
62+
return new ErrorCodeMapper().getMapedErrorCode(e.getErrorCode()).getCode();
63+
}
4964
} catch (Exception e) {
5065
LOG.error(e.getMessage(), e);
5166
return ErrorCode.UNXPECTED_ERROR.getCode();
@@ -66,7 +81,7 @@ public static int delete(String args[]) {
6681
@CLIServiceMethod(name = "unpublish", description = "Unpublish the selected APIs")
6782
public static int unpublish(String args[]) {
6883
try {
69-
APIExportParams params = new APIExportParams(new APIDeleteCLIOptions(args));
84+
APIExportParams params = new APIExportParams(new APIUnpublishCLIOptions(args));
7085
return runExport(params, APIListImpl.API_UNPUBLISH_HANDLER);
7186
} catch (Exception e) {
7287
LOG.error(e.getMessage(), e);

modules/api-export/src/main/java/com/axway/apim/api/export/ExportAPI.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public String getDeprecated() {
205205

206206

207207
public Map<String, String> getCustomProperties() {
208+
if(this.actualAPIProxy.getCustomProperties()!=null && this.actualAPIProxy.getCustomProperties().size()==0) return null;
208209
return this.actualAPIProxy.getCustomProperties();
209210
}
210211

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

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.axway.apim.api.export.impl;
22

33
import java.lang.reflect.Constructor;
4+
import java.util.ArrayList;
5+
import java.util.Arrays;
6+
import java.util.HashMap;
7+
import java.util.Iterator;
48
import java.util.List;
9+
import java.util.Map;
510
import java.util.Scanner;
611

712
import org.slf4j.Logger;
@@ -12,10 +17,18 @@
1217
import com.axway.apim.adapter.apis.APIFilter;
1318
import com.axway.apim.adapter.apis.APIFilter.Builder;
1419
import com.axway.apim.adapter.apis.APIFilter.Builder.APIType;
20+
import com.axway.apim.adapter.apis.APIManagerPoliciesAdapter.PolicyType;
1521
import com.axway.apim.adapter.apis.APIFilter.METHOD_TRANSLATION;
1622
import com.axway.apim.adapter.apis.APIFilter.POLICY_TRANSLATION;
1723
import com.axway.apim.api.API;
24+
import com.axway.apim.api.export.ExportAPI;
1825
import com.axway.apim.api.export.lib.APIExportParams;
26+
import com.axway.apim.api.model.InboundProfile;
27+
import com.axway.apim.api.model.Organization;
28+
import com.axway.apim.api.model.OutboundProfile;
29+
import com.axway.apim.api.model.Policy;
30+
import com.axway.apim.api.model.SecurityDevice;
31+
import com.axway.apim.api.model.SecurityProfile;
1932
import com.axway.apim.lib.errorHandling.AppException;
2033
import com.axway.apim.lib.errorHandling.ErrorCode;
2134

@@ -30,6 +43,7 @@ public abstract class APIResultHandler {
3043
public enum APIListImpl {
3144
JSON_EXPORTER(JsonAPIExporter.class),
3245
CONSOLE_EXPORTER(ConsoleAPIExporter.class),
46+
CSV_EXPORTER(CSVAPIExporter.class),
3347
API_DELETE_HANDLER(DeleteAPIHandler.class),
3448
API_UNPUBLISH_HANDLER(UnpublishAPIHandler.class);
3549

@@ -77,9 +91,11 @@ protected Builder getBaseAPIFilterBuilder() {
7791
.hasId(params.getValue("id"))
7892
.hasName(params.getValue("name"))
7993
.hasState(params.getValue("state"))
94+
.hasBackendBasepath(params.getValue("backend"))
8095
.includeCustomProperties(APIManagerAdapter.getAllConfiguredCustomProperties(CUSTOM_PROP_TYPE.api))
8196
.translateMethods(METHOD_TRANSLATION.AS_NAME)
82-
.translatePolicies(POLICY_TRANSLATION.TO_NAME);
97+
.translatePolicies(POLICY_TRANSLATION.TO_NAME)
98+
.useFEAPIDefinition(params.isUseFEAPIDefinition());
8399
return builder;
84100
}
85101

@@ -94,11 +110,121 @@ protected static boolean askYesNo(String question, String positive, String negat
94110
negative = negative.toUpperCase();
95111
String answer;
96112
do {
97-
System.out.print(question);
113+
System.out.print(question+ " ");
98114
answer = input.next().trim().toUpperCase();
99115
} while (!answer.matches(positive) && !answer.matches(negative));
100116
input.close();
101117
// Assess if we match a positive response
102118
return answer.matches(positive);
103119
}
120+
121+
protected static String getBackendPath(API api) {
122+
ExportAPI exportAPI = new ExportAPI(api);
123+
return exportAPI.getBackendBasepath();
124+
}
125+
126+
protected static String getUsedSecurity(API api) {
127+
List<String> usedSecurity = new ArrayList<String>();
128+
Map<String, SecurityProfile> secProfilesMappedByName = new HashMap<String, SecurityProfile>();
129+
try {
130+
for(SecurityProfile secProfile : api.getSecurityProfiles()) {
131+
secProfilesMappedByName.put(secProfile.getName(), secProfile);
132+
}
133+
134+
Iterator<InboundProfile> it;
135+
it = api.getInboundProfiles().values().iterator();
136+
137+
while(it.hasNext()) {
138+
InboundProfile profile = it.next();
139+
SecurityProfile usedSecProfile = secProfilesMappedByName.get(profile.getSecurityProfile());
140+
for(SecurityDevice device : usedSecProfile.getDevices()) {
141+
usedSecurity.add(""+device.getType());
142+
}
143+
}
144+
String result = usedSecurity.toString().replace("[", "").replace("]", "");
145+
return result;
146+
} catch (AppException e) {
147+
LOG.error("Error getting security information for API", e);
148+
return "Err";
149+
}
150+
}
151+
152+
protected static List<String> getUsedPolicies(API api, PolicyType type) {
153+
return getUsedPolicies(api).get(type);
154+
}
155+
156+
protected static Map<PolicyType, List<String>> getUsedPolicies(API api) {
157+
Iterator<OutboundProfile> it;
158+
Map<PolicyType, List<String>> result = new HashMap<PolicyType, List<String>>();
159+
List<String> requestPolicies = new ArrayList<String>();
160+
List<String> routingPolicies = new ArrayList<String>();
161+
List<String> responsePolicies = new ArrayList<String>();
162+
List<String> faultHandlerPolicies = new ArrayList<String>();
163+
try {
164+
it = api.getOutboundProfiles().values().iterator();
165+
} catch (AppException e) {
166+
LOG.error("Error getting policy information for API", e);
167+
return result;
168+
}
169+
170+
while(it.hasNext()) {
171+
OutboundProfile profile = it.next();
172+
if(profile.getRouteType().equals("proxy")) continue;
173+
if(profile.getRequestPolicy()!=null && profile.getRequestPolicy().getName()!=null) {
174+
requestPolicies.add(profile.getRequestPolicy().getName());
175+
}
176+
if(profile.getRoutePolicy()!=null && profile.getRoutePolicy().getName()!=null) {
177+
routingPolicies.add(profile.getRoutePolicy().getName());
178+
}
179+
if(profile.getResponsePolicy()!=null && profile.getResponsePolicy().getName()!=null) {
180+
responsePolicies.add(profile.getResponsePolicy().getName());
181+
}
182+
if(profile.getFaultHandlerPolicy()!=null && profile.getFaultHandlerPolicy().getName()!=null) {
183+
faultHandlerPolicies.add(profile.getFaultHandlerPolicy().getName());
184+
}
185+
}
186+
result.put(PolicyType.REQUEST, requestPolicies);
187+
result.put(PolicyType.ROUTING, routingPolicies);
188+
result.put(PolicyType.RESPONSE, responsePolicies);
189+
result.put(PolicyType.FAULT_HANDLER, faultHandlerPolicies);
190+
return result;
191+
}
192+
193+
protected static String getCustomProps(API api) {
194+
if(api.getCustomProperties()==null) return "N/A";
195+
Iterator<String> it = api.getCustomProperties().keySet().iterator();
196+
List<String> props = new ArrayList<String>();
197+
while(it.hasNext()) {
198+
String property = it.next();
199+
String value = api.getCustomProperties().get(property);
200+
props.add(property + ": " + value);
201+
}
202+
return props.toString().replace("[", "").replace("]", "");
203+
}
204+
205+
protected static String getTags(API api) {
206+
if(api.getTags()==null) return "None";
207+
Iterator<String> it = api.getTags().keySet().iterator();
208+
List<String> tags = new ArrayList<String>();
209+
while(it.hasNext()) {
210+
String tagGroup = it.next();
211+
String[] tagValues = api.getTags().get(tagGroup);
212+
tags.add(tagGroup + ": " + Arrays.toString(tagValues));
213+
}
214+
return tags.toString().replace("[", "").replace("]", "");
215+
}
216+
217+
protected static List<String> getGrantedOrganizations(API api) {
218+
List<String> grantedOrgs = new ArrayList<String>();
219+
try {
220+
if(api.getClientOrganizations()==null) return grantedOrgs;
221+
for(Organization org : api.getClientOrganizations()) {
222+
grantedOrgs.add(org.getName());
223+
}
224+
return grantedOrgs;
225+
} catch (Exception e) {
226+
LOG.error("Error getting API client organization");
227+
return grantedOrgs;
228+
}
229+
}
104230
}

0 commit comments

Comments
 (0)