Skip to content

Commit

Permalink
- Fix issue #522, #534, #528
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Jan 23, 2025
1 parent c047997 commit 8454d54
Show file tree
Hide file tree
Showing 14 changed files with 1,344 additions and 33 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


# [1.14.9] In progress

### Fixed

- File extension is missing in apiSpecification.resource when exporting API(See issue [#528](https://github.com/Axway-API-Management-Plus/apim-cli/issues/528))

### Added
- Support csv format for organization export (See issue [#534](https://github.com/Axway-API-Management-Plus/apim-cli/issues/534))
- Generate api-config.json with permethod override and methods tags (See issue [#522](https://github.com/Axway-API-Management-Plus/apim-cli/issues/522))
- import .dat APIs (See issue [#532](https://github.com/Axway-API-Management-Plus/apim-cli/issues/532))



# [1.14.8] 2024-11-06

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
Expand All @@ -67,6 +68,9 @@ public class APIManagerAPIAdapter {
public static final String APPLICATIONS = "/applications/";
public static final String FILENAME = "filename";
public static final String CONTENT_TYPE = "text/plain";
public static final String PASSWORD = "password";
public static final String HTML_5 = "html5";
public static final String UPLOAD_TYPE = "uploadType";
Map<APIFilter, String> apiManagerResponse = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
private final CoreParameters cmd;
Expand Down Expand Up @@ -698,7 +702,7 @@ public byte[] getAPIDatFile(API api, String password) throws AppException {
String locationHeader;
List<NameValuePair> parameters = new ArrayList<>();
parameters.add(new BasicNameValuePair(FILENAME, "api-export.dat"));
parameters.add(new BasicNameValuePair("password", password));
parameters.add(new BasicNameValuePair(PASSWORD, password));
parameters.add(new BasicNameValuePair("id", api.getId()));
HttpEntity entity = new UrlEncodedFormEntity(parameters);
URI uri = new URIBuilder(cmd.getAPIManagerURL())
Expand Down Expand Up @@ -731,6 +735,32 @@ public byte[] getAPIDatFile(API api, String password) throws AppException {
}
}

public void importAPIDatFile(File file, String password, String orgId) throws AppException {
try {
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create()
.addBinaryBody("file", file)
.addTextBody(ORGANIZATION_ID, orgId)
.addTextBody(UPLOAD_TYPE, HTML_5);
if (password != null) multipartEntityBuilder.addTextBody(PASSWORD, password);
HttpEntity entity = multipartEntityBuilder.build();

URI uri = new URIBuilder(cmd.getAPIManagerURL())
.setPath(cmd.getApiBasepath() + "/proxies/import")
.build();
RestAPICall request = new POSTRequest(entity, uri);
try (CloseableHttpResponse httpResponse = (CloseableHttpResponse) request.execute()) {
int statusCode = httpResponse.getStatusLine().getStatusCode();
String response = EntityUtils.toString(httpResponse.getEntity());
if (statusCode != 201) {
LOG.error("Error import DAT-File representation of API, Received Status-Code: {} Response: {}", statusCode, response);
throw new AppException("Error importing DAT-File representation of API", ErrorCode.ERR_IMPORTING_API_DAT_FILE);
}
}
} catch (Exception e) {
throw new AppException("Cannot export API-DAT file.", ErrorCode.ERR_IMPORTING_API_DAT_FILE, e);
}
}

public void updateAPIStatus(API api, String desiredState, String vhost) throws AppException {
LOG.debug("Update API-Proxy status to: {}", api.getState());
try {
Expand Down Expand Up @@ -835,7 +865,7 @@ public JsonNode importFromWSDL(API api) throws IOException {
nameValuePairs.add(new BasicNameValuePair("name", api.getName()));
if (username != null) {
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", pass));
nameValuePairs.add(new BasicNameValuePair(PASSWORD, pass));
}
HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs);
RestAPICall importWSDL = new POSTRequest(entity, uri);
Expand All @@ -861,7 +891,7 @@ public JsonNode importFromSwagger(API api) throws AppException {
.addTextBody("type", "swagger")
.addBinaryBody("file", api.getApiDefinition().getApiSpecificationContent(), ContentType.create("application/json"), FILENAME)
.addTextBody("fileName", "XYZ").addTextBody(ORGANIZATION_ID, api.getOrganization().getId(), ContentType.create(CONTENT_TYPE, StandardCharsets.UTF_8))
.addTextBody("integral", "false").addTextBody("uploadType", "html5").build();
.addTextBody("integral", "false").addTextBody(UPLOAD_TYPE, HTML_5).build();
return createBackend(entity, api);
}

Expand Down Expand Up @@ -892,7 +922,7 @@ public JsonNode importGraphql(API api, String backendBasePath) throws AppExcepti
.addBinaryBody("file", api.getApiDefinition().getApiSpecificationContent(), ContentType.create("application/octet-stream"), FILENAME)
.addTextBody("fileName", "XYZ").addTextBody(ORGANIZATION_ID, api.getOrganization().getId(), ContentType.create(CONTENT_TYPE, StandardCharsets.UTF_8))
.addTextBody("backendUrl", backendBasePath)
.addTextBody("integral", "false").addTextBody("uploadType", "html5").build();
.addTextBody("integral", "false").addTextBody(UPLOAD_TYPE, HTML_5).build();
return createBackend(entity, api);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public enum ErrorCode {
ERR_DELETING_API(91, "API could not be deleted.", false),
ERR_DELETING_ORG(92, "Organization could not be deleted.", false),
ERR_GRANTING_ACCESS_TO_API(93, "Error granting access to an API.", false),
ERR_EXPORTING_API_DAT_FILE(94, "Error exporting API-Date file.", false),
ERR_EXPORTING_API_DAT_FILE(94, "Error exporting API-Dat file.", false),
ERR_CREATING_APPLICATION(95, "Error creating/updating an application.", false),
ERR_PUBLISH_API(96, "API could not be changed to publish state", false),
ERR_UNPUBSLISH_API(97, "API could not be changed to unpublish state", false),
Expand All @@ -69,7 +69,8 @@ public enum ErrorCode {
CHECK_CERTS_FOUND_CERTS(101, "Certificates found that will expire within the given number of days.", false),
GRANT_ACCESS_APPLICATION_ERR(102, "Error granting application access to API."),
REVOKE_ACCESS_APPLICATION_ERR(103, "Error revoking application access to API."),
INVALID_SECURITY_PROFILE_CONFIG(104, "The given security profile is invalid.", false);
INVALID_SECURITY_PROFILE_CONFIG(104, "The given security profile is invalid.", false),
ERR_IMPORTING_API_DAT_FILE(105, "Error importing API-Dat file.", false);


private final int code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,4 +905,11 @@ public void filterApiBasedOnStateNoMatch() throws AppException {

}

@Test
public void importAPIDatFileTest() throws AppException {
Organization organization = orgAdapter.getOrgForName("orga");
String filePath = this.getClass().getClassLoader().getResource("com/axway/apim/adapter/api-export.dat").getFile();
apiManagerAPIAdapter.importAPIDatFile(new File(filePath),"changeme", organization.getId());
}

}
Loading

0 comments on commit 8454d54

Please sign in to comment.