use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class StorageExporter method exportApis.
private void exportApis(String orgId) {
try {
writer.startApis();
Iterator<ApiBean> apiIter = storage.getAllApis(orgId);
while (apiIter.hasNext()) {
ApiBean apiBean = apiIter.next();
writer.startApi(apiBean);
writer.startApiVersions();
Iterator<ApiVersionBean> versionIter = storage.getAllApiVersions(orgId, apiBean.getId());
while (versionIter.hasNext()) {
ApiVersionBean versionBean = versionIter.next();
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageExporter.ExportingApiVersion") + versionBean);
writer.startApiVersion(versionBean);
writer.startApiPolicies();
Iterator<PolicyBean> policyIter = storage.getAllPolicies(orgId, apiBean.getId(), versionBean.getVersion(), PolicyType.Api);
while (policyIter.hasNext()) {
PolicyBean policyBean = policyIter.next();
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageExporter.ExportingApiPolicy") + policyBean);
writer.writeApiPolicy(policyBean);
}
writer.endApiPolicies();
// Api definition
if (versionBean.getDefinitionType() != null && versionBean.getDefinitionType() != None) {
logger.info(Messages.i18n.format("StorageExporter.ExportingApiDefinition", versionBean.getDefinitionType()));
InputStream data = storage.getApiDefinition(orgId, apiBean.getId(), versionBean.getVersion());
if (data != null) {
writer.writeApiDefinition(data);
}
}
writer.endApiVersion();
}
writer.endApiVersions();
writer.endApi();
}
writer.endApis();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class StorageImportDispatcher method publishApis.
/**
* Publishes any apis that were imported in the "Published" state.
* @throws StorageException
*/
private void publishApis() throws StorageException {
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageExporter.PublishingApis"));
try {
for (EntityInfo info : apisToPublish) {
// $NON-NLS-1$
logger.info(Messages.i18n.format("StorageExporter.PublishingApi", info));
ApiVersionBean versionBean = storage.getApiVersion(info.organizationId, info.id, info.version);
Api gatewayApi = new Api();
gatewayApi.setEndpoint(versionBean.getEndpoint());
gatewayApi.setEndpointType(versionBean.getEndpointType().toString());
gatewayApi.setEndpointProperties(versionBean.getEndpointProperties());
gatewayApi.setOrganizationId(versionBean.getApi().getOrganization().getId());
gatewayApi.setApiId(versionBean.getApi().getId());
gatewayApi.setVersion(versionBean.getVersion());
gatewayApi.setPublicAPI(versionBean.isPublicAPI());
gatewayApi.setParsePayload(versionBean.isParsePayload());
if (versionBean.isPublicAPI()) {
List<Policy> policiesToPublish = new ArrayList<>();
Iterator<PolicyBean> apiPolicies = storage.getAllPolicies(info.organizationId, info.id, info.version, PolicyType.Api);
while (apiPolicies.hasNext()) {
PolicyBean apiPolicy = apiPolicies.next();
Policy policyToPublish = new Policy();
policyToPublish.setPolicyJsonConfig(apiPolicy.getConfiguration());
policyToPublish.setPolicyImpl(apiPolicy.getDefinition().getPolicyImpl());
policiesToPublish.add(policyToPublish);
}
gatewayApi.setApiPolicies(policiesToPublish);
}
// Publish the api to all relevant gateways
Set<ApiGatewayBean> gateways = versionBean.getGateways();
if (gateways == null) {
// $NON-NLS-1$
throw new RuntimeException("No gateways specified for api!");
}
for (ApiGatewayBean apiGatewayBean : gateways) {
IGatewayLink gatewayLink = createGatewayLink(apiGatewayBean.getGatewayId());
gatewayLink.publishApi(gatewayApi);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_i18n.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_i18n() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("i18n");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
template.setLanguage(null);
// $NON-NLS-1$
template.setTemplate("Default language message.");
def.getTemplates().add(template);
template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setLanguage("en");
// $NON-NLS-1$
template.setTemplate("English language message.");
def.getTemplates().add(template);
template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setLanguage("en_US");
// $NON-NLS-1$
template.setTemplate("English (US) language message.");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{}");
try {
AbstractMessages.setLocale(Locale.ENGLISH);
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("English language message.", policy.getDescription());
AbstractMessages.setLocale(Locale.US);
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("English (US) language message.", policy.getDescription());
} finally {
AbstractMessages.clearLocale();
}
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_arrays.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_arrays() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("arrays");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("@{messages[0]} @{messages[1]}");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{ \"messages\" : [ \"Hello\", \"World\" ] }");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Hello World", policy.getDescription());
}
use of io.apiman.manager.api.beans.policies.PolicyBean in project apiman by apiman.
the class PolicyTemplateUtilTest method testGeneratePolicyDescription_basicauth.
/**
* Test method for {@link io.apiman.manager.api.core.util.PolicyTemplateUtil#generatePolicyDescription(io.apiman.manager.api.beans.policies.PolicyBean)}.
* @throws Exception any exception
*/
@Test
public void testGeneratePolicyDescription_basicauth() throws Exception {
PolicyBean policy = new PolicyBean();
PolicyDefinitionBean def = new PolicyDefinitionBean();
// $NON-NLS-1$
def.setId("basicauth");
PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
// $NON-NLS-1$
template.setTemplate("Access to the API is protected by BASIC Authentication through the @{realm} authentication realm. @if{forwardIdentityHttpHeader != null}Successfully authenticated requests will include '@{forwardIdentityHttpHeader}' as a custom HTTP header to the back end API.@end{}");
def.getTemplates().add(template);
policy.setDefinition(def);
// $NON-NLS-1$
policy.setConfiguration("{ \"realm\" : \"Example\", \"forwardIdentityHttpHeader\" : \"X-Authenticated-Identity\" }");
PolicyTemplateUtil.generatePolicyDescription(policy);
// $NON-NLS-1$
Assert.assertEquals("Access to the API is protected by BASIC Authentication through the Example authentication realm. Successfully authenticated requests will include 'X-Authenticated-Identity' as a custom HTTP header to the back end API.", policy.getDescription());
}
Aggregations