Skip to content

Commit

Permalink
# Fix issue #441
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Nov 15, 2023
1 parent fd58cd7 commit 246e97a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [1.14.3] In progress
### Fixed
- Error mapping is not applied when importing "app" (See issue [#437](https://github.com/Axway-API-Management-Plus/apim-cli/issues/437))
- Handling backend changes and removal of organization from api-config json file in one command [#441](https://github.com/Axway-API-Management-Plus/apim-cli/issues/441))

# [1.14.2] 2023-08-29
### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package com.axway.apim.apiimport;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.axway.apim.lib.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axway.apim.adapter.APIManagerAdapter;
import com.axway.apim.api.API;
import com.axway.apim.apiimport.lib.params.APIImportParams;
import com.axway.apim.lib.APIPropertyAnnotation;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.error.ErrorCode;
import com.axway.apim.lib.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
* This class is key, as the desired and actual API comes together.
Expand All @@ -39,8 +37,8 @@ public class APIChangeState {
private boolean updateExistingAPI = true;
private boolean recreateAPI = false;
private boolean proxyUpdateRequired = false;
private final List<String> breakingChanges = new Vector<>();
private final List<String> nonBreakingChanges = new Vector<>();
private final List<String> breakingChanges = new ArrayList<>();
private final List<String> nonBreakingChanges = new ArrayList<>();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void execute(APIChangeState changes, boolean reCreation) throws AppExcept
// Is a Quota is defined we must manage it
new APIQuotaManager(desiredAPI, actualAPI).execute(createdAPI);
// Grant access to the API
new ManageClientOrgs(desiredAPI, createdAPI).execute(reCreation);
new ManageClientOrganization(desiredAPI, createdAPI).execute(reCreation);
// Handle subscription to applications
new ManageClientApps(desiredAPI, createdAPI, actualAPI).execute(reCreation);
// Provide the ID of the created API to the desired API just for logging purposes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.error.ErrorCode;

public class ManageClientOrgs {
public class ManageClientOrganization {

private static final Logger LOG = LoggerFactory.getLogger(ManageClientOrgs.class);
private static final Logger LOG = LoggerFactory.getLogger(ManageClientOrganization.class);

APIManagerAdapter apiManager;

private final API desiredState;
private final API actualState;

public ManageClientOrgs(API desiredState, API actualState) throws AppException {
public ManageClientOrganization(API desiredState, API actualState) throws AppException {
this.desiredState = desiredState;
this.actualState = actualState;
apiManager = APIManagerAdapter.getInstance();

}

public void execute(boolean reCreation) throws AppException {
LOG.info("reCreation : {}", reCreation);
if (CoreParameters.getInstance().isIgnoreClientOrgs()) {
LOG.info("Configured client organizations are ignored, as flag ignoreClientOrgs has been set.");
return;
Expand All @@ -51,14 +52,15 @@ public void execute(boolean reCreation) throws AppException {
LOG.info("All desired organizations: {} have already access. Nothing to do.", desiredState.getClientOrganizations());
}
} else {
LOG.info("Granting access for organizations : {} to API : {}", missingDesiredOrgs, actualState.getName());
apiManager.getApiAdapter().grantClientOrganization(missingDesiredOrgs, actualState, false);
}
if (!removingActualOrgs.isEmpty()) {
if (CoreParameters.getInstance().getClientOrgsMode().equals(CoreParameters.Mode.replace)) {
LOG.info("Removing access for orgs: {} from API: {}", removingActualOrgs, actualState.getName());
LOG.info("Removing access for organizations: {} from API: {}", removingActualOrgs, actualState.getName());
apiManager.getAccessAdapter().removeClientOrganization(removingActualOrgs, actualState.getId());
} else {
LOG.info("NOT removing access for existing orgs: {} from API: {} as clientOrgsMode NOT set to replace.",removingActualOrgs,actualState.getName());
LOG.info("NOT removing access for existing organizations: {} from API: {} as clientOrgsMode NOT set to replace.",removingActualOrgs,actualState.getName());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.axway.apim.apiimport.actions;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axway.apim.adapter.APIStatusManager;
import com.axway.apim.api.API;
import com.axway.apim.apiimport.APIChangeState;
import com.axway.apim.lib.CoreParameters;
import com.axway.apim.lib.CoreParameters.Mode;
import com.axway.apim.lib.error.AppException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class RepublishToUpdateAPI {

Expand Down Expand Up @@ -50,6 +49,8 @@ public void execute(APIChangeState changes) throws AppException {
}
APIStatusManager statusManager = new APIStatusManager();
statusManager.update(actualAPI, API.STATE_UNPUBLISHED, true);
actualAPI.setClientOrganizations(new ArrayList<>()); // remove all client organizations
actualAPI.setApplications(new ArrayList<>()); // remove all consumer applications
UpdateExistingAPI updateExistingAPI = new UpdateExistingAPI();
updateExistingAPI.execute(changes);
LOG.debug("Existing API successfully updated: {} (ID: {})", actualAPI.getName(), actualAPI.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void execute(APIChangeState changes) throws AppException {
apiAdapter.updateAPIProxy(changes.getActualAPI());
}
new APIQuotaManager(changes.getDesiredAPI(), changes.getActualAPI()).execute(changes.getActualAPI());
new ManageClientOrgs(changes.getDesiredAPI(), changes.getActualAPI()).execute(false);
new ManageClientOrganization(changes.getDesiredAPI(), changes.getActualAPI()).execute(false);
// Handle subscription to applications
new ManageClientApps(changes.getDesiredAPI(), changes.getActualAPI(), null).execute(false);
if (actualAPI.getState().equals(API.STATE_DELETED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void run(@Optional @CitrusResource TestContext context) throws IOExceptio
echo("####### Validate application: '${appName}' (${appId}) has permissions for ALL users #######");
http(builder -> builder.client("apiManager").send().get("/applications/${appId}/permissions").header("Content-Type", "application/json"));

http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
http(builder -> builder.client("apiManager").receive().response(HttpStatus.OK).messageType(MessageType.JSON)
.validate("$.*.id", "@assertThat(hasSize(4))@") // Must be four, as the application is created by an OrgAdmin
.validate("$.[?(@.userId=='${userId-1}')].permission", "view")
.validate("$.[?(@.userId=='${userId-2}')].permission", "view")
Expand Down

0 comments on commit 246e97a

Please sign in to comment.