Skip to content

Commit

Permalink
- Fix issue #499
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 9, 2024
1 parent 5aa928d commit 9800748
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Importing SOAP API with different endpoints (for import and for runtime calls) (See issue [#501](https://github.com/Axway-API-Management-Plus/apim-cli/issues/501))
- -returnCodeMapping option does not work on apim-cli org import (See issue [#496](https://github.com/Axway-API-Management-Plus/apim-cli/issues/496))
- The output of command 'apim api get' is not containing the complete list of client applications (array) of the api (See issue [#495](https://github.com/Axway-API-Management-Plus/apim-cli/issues/495))
- Update API with Assigned Quota (See issue [#499](https://github.com/Axway-API-Management-Plus/apim-cli/issues/499))

### Added
- Force APIM-cli to download the latest Trusted Certificates in a Frontend API (See issue [#494](https://github.com/Axway-API-Management-Plus/apim-cli/issues/494))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@ public class QuotaRestrictionSerializer extends StdSerializer<QuotaRestriction>
public static final String METHOD = "method";

public QuotaRestrictionSerializer() {
this(null);
}

public QuotaRestrictionSerializer(Class<QuotaRestriction> t) {
super(t);
}

@Override
public void serialize(QuotaRestriction quotaRestriction, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
if(quotaRestriction.getRestrictedAPI()==null) {
jgen.writeObjectField("api", "*");
jgen.writeObjectField(METHOD, "*");
} else { // API-Specific quota
// Don't write the API-Name as it's confusing it is ignored during import when the API-Path is given.
jgen.writeObjectField("apiPath", quotaRestriction.getRestrictedAPI().getPath());
if(quotaRestriction.getRestrictedAPI().getVhost()!=null) {
jgen.writeObjectField("vhost", quotaRestriction.getRestrictedAPI().getVhost());
}
if(quotaRestriction.getRestrictedAPI().getApiRoutingKey()!=null) {
jgen.writeObjectField("apiRoutingKey", quotaRestriction.getRestrictedAPI().getApiRoutingKey());
}
if(quotaRestriction.getMethod()==null || "*".equals(quotaRestriction.getMethod())) {
jgen.writeObjectField(METHOD, "*");
} else {
APIMethod method = APIManagerAdapter.getInstance().getMethodAdapter().getMethodForId(quotaRestriction.getApiId(), quotaRestriction.getMethod());
jgen.writeObjectField(METHOD, method.getName());
}
}
jgen.writePOJOField("type",quotaRestriction.getType());
jgen.writePOJOField("config",quotaRestriction.getConfig());
jgen.writeEndObject();
}

@Override
public Class<QuotaRestriction> handledType() {
return QuotaRestriction.class;
}
this(null);
}

public QuotaRestrictionSerializer(Class<QuotaRestriction> t) {
super(t);
}

@Override
public void serialize(QuotaRestriction quotaRestriction, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
if (quotaRestriction.getRestrictedAPI() == null) {
jgen.writeObjectField("api", "*");
jgen.writeObjectField(METHOD, "*");
} else { // API-Specific quota
// Don't write the API-Name as it's confusing it is ignored during import when the API-Path is given.
jgen.writeObjectField("apiPath", quotaRestriction.getRestrictedAPI().getPath());
if (quotaRestriction.getRestrictedAPI().getVhost() != null) {
jgen.writeObjectField("vhost", quotaRestriction.getRestrictedAPI().getVhost());
}
if (quotaRestriction.getRestrictedAPI().getApiRoutingKey() != null) {
jgen.writeObjectField("apiRoutingKey", quotaRestriction.getRestrictedAPI().getApiRoutingKey());
}
if (quotaRestriction.getMethod() == null || "*".equals(quotaRestriction.getMethod())) {
jgen.writeObjectField(METHOD, "*");
} else {
APIMethod method = APIManagerAdapter.getInstance().getMethodAdapter().getMethodForId(quotaRestriction.getApiId(), quotaRestriction.getMethod());
jgen.writeObjectField(METHOD, method.getName());
}
}
jgen.writePOJOField("type", quotaRestriction.getType());
jgen.writePOJOField("config", quotaRestriction.getConfig());
jgen.writeEndObject();
}

@Override
public Class<QuotaRestriction> handledType() {
return QuotaRestriction.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,14 @@ public void updateRestrictions(List<QuotaRestriction> actualRestrictions, List<Q
LOG.info("{} quota for API: {} Nothing to do.", type.getFriendlyName(), createdAPI.getName());
return;
}
APIManagerAPIMethodAdapter methodAdapter = APIManagerAdapter.getInstance().getMethodAdapter();
APIManagerQuotaAdapter quotaManager = APIManagerAdapter.getInstance().getQuotaAdapter();
LOG.info("Updating {} quota for API: {}", type.getFriendlyName(), createdAPI.getName());
LOG.debug("{}-Restrictions: Desired: {}, Actual: {}", type.getFriendlyName(), desiredRestrictions, actualRestrictions);
// In order to compare/merge the restrictions, we must translate the desired API-Method-Names, if not a "*", into the methodId of the createdAPI
if (desiredRestrictions != null) {
for (QuotaRestriction desiredRestriction : desiredRestrictions) {
if ("*".equals(desiredRestriction.getMethod()))
continue;
desiredRestriction.setMethod(methodAdapter.getMethodForName(createdAPI.getId(), desiredRestriction.getMethod()).getId());
}
}
// Load the entire current default quota
APIQuota currentDefaultQuota = quotaManager.getDefaultQuota(type);
LOG.debug("Current Default Quota : {}", currentDefaultQuota);
List<QuotaRestriction> mergedRestrictions = addOrMergeRestriction(actualRestrictions, desiredRestrictions);
LOG.debug("Merged Quota : {}", mergedRestrictions);
populateMethodId(createdAPI, mergedRestrictions);
// If there is an actual API, remove the restrictions for the current actual API
if (actualState != null) {
Expand Down Expand Up @@ -132,7 +124,7 @@ public void populateMethodId(API createdAPI, List<QuotaRestriction> mergedRestri
// Additionally, we have to change the methodId
// Load the method for actualAPI to get the name of the method to which the existing quota is applied to
if (actualState != null) {
APIMethod actualMethod = methodAdapter.getMethodForId(actualState.getId(), restriction.getMethod());
APIMethod actualMethod = methodAdapter.getMethodForName(actualState.getId(), restriction.getMethod());
if (actualMethod != null) {
// Now load the new method based on the name for the createdAPI
APIMethod newMethod = methodAdapter.getMethodForName(createdAPI.getId(), actualMethod.getName());
Expand All @@ -141,6 +133,10 @@ public void populateMethodId(API createdAPI, List<QuotaRestriction> mergedRestri
} else {
LOG.warn("API Method Name : {} not found in specification", restriction.getMethod());
}
}else {
// For new api creation
APIMethod newMethod = methodAdapter.getMethodForName(createdAPI.getId(), restriction.getMethod());
restriction.setMethod(newMethod.getId());
}
}
}
Expand Down

0 comments on commit 9800748

Please sign in to comment.