/** * Generates a valid document ID for a api, used to index the api in ES. * @param api an api * @return a api key */ private String getApiId(Api api) { return getApiId(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
@Override public void retire(String organizationId, String apiId, String version, AsyncResponse response) throws RegistrationException, NotAuthorizedException { Api api = new Api(); api.setOrganizationId(organizationId); api.setApiId(apiId); api.setVersion(version); registry.retireApi(api, handlerWithEmptyResult(response)); }
/** * Response API property replacements */ protected void resolvePropertyReplacements(Api api) { if (api == null) { return; } String endpoint = api.getEndpoint(); endpoint = resolveProperties(endpoint); api.setEndpoint(endpoint); Map<String, String> properties = api.getEndpointProperties(); for (Entry<String, String> entry : properties.entrySet()) { String value = entry.getValue(); value = resolveProperties(value); entry.setValue(value); } resolvePropertyReplacements(api.getApiPolicies()); }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(Api api, IAsyncResultHandler<Void> handler) { List<Policy> policies = api.getApiPolicies(); encryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); encryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); delegate.publishApi(api, handler); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); }
private void processData() { if (configs.size() == 0) { log.warn("File loaded into registry was empty. No entities created."); return; } try { // Naive version initially. for (Auth3ScaleBean bean : configs) { // Reflects the remote data structure. BackendConfiguration config = bean.getThreescaleConfig().getProxyConfig().getBackendConfig(); Api api = new Api(); api.setApiId(config.getSystemName()); api.setOrganizationId(defaultOrgName); api.setEndpoint(config.getProxy().getApiBackend()); api.setEndpointContentType("text/json"); // don't think there is an equivalent of this in 3scale api.setEndpointType("rest"); //don't think there is an equivalent of this in 3scale api.setParsePayload(false); // can let user override this? api.setPublicAPI(true); // is there an equivalent of this? api.setVersion(defaultVersion); // don't think this is relevant anymore setPolicies(api, bean); log.debug("Processing: {0}", config); log.debug("Creating API: {0}", api); apis.add(api); } dataProcessed = true; checkQueue(); } catch (DecodeException e) { failAll(e); } }
} else { Exception error = new NoContractFoundException(Messages.i18n.format("InMemoryRegistry.NoContractFound", //$NON-NLS-1$ client.getClientId(), api.getApiId())); handler.handle(AsyncResultImpl.create(error, ApiContract.class));
@Override public void listApis(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Api) .map(entity -> (Api) entity) .filter(api -> api.getOrganizationId().equals(organizationId)) .map(api -> api.getApiId()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
private void setPolicies(Api api, Auth3ScaleBean config) { // FIXME optimise // Add 3scale policy Policy pol = new Policy(); pol.setPolicyImpl(determinePolicyImpl()); // TODO get version? Hmm! Env? pol.setPolicyJsonConfig(Json.encode(config)); api.getApiPolicies().add(pol); // Add any policies user specified in remote config. policyConfigApis.stream() .filter(skeleton -> skeleton.getApiId().equals(api.getApiId())) // Apply policies from skeleton to 3scale API. .forEach(skeleton -> api.getApiPolicies().addAll(skeleton.getApiPolicies())); }
String endpoint = ApimanPathUtils.join(api.getEndpoint(), request.getDestination()); BasicAuthOptions options = new BasicAuthOptions(api.getEndpointProperties()); if (options.getUsername() != null && options.getPassword() != null) { if (options.isRequireSSL() && !isSsl) {
private URI parseApiEndpoint(Api api) { try { return new URI(api.getEndpoint()); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
@Override public void listOrgs(IAsyncResultHandler<List<String>> handler) { // TODO: We should track set of OrgId -> AtomicCounter if this API has meaningfully high usage. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .map(elem -> { if (elem instanceof Api) { return ((Api) elem).getOrganizationId(); } else { return ((Client) elem).getOrganizationId(); } }) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
private void processData() { if (configs.size() == 0) { log.warn("File loaded into registry was empty. No entities created."); return; } try { // Naive version initially. for (Auth3ScaleBean bean : configs) { // Reflects the remote data structure. BackendConfiguration config = bean.getThreescaleConfig().getProxyConfig().getBackendConfig(); Api api = new Api(); api.setApiId(config.getSystemName()); api.setOrganizationId(defaultOrgName); api.setEndpoint(config.getProxy().getApiBackend()); api.setEndpointContentType("text/json"); // don't think there is an equivalent of this in 3scale api.setEndpointType("rest"); //don't think there is an equivalent of this in 3scale api.setParsePayload(false); // can let user override this? api.setPublicAPI(true); // is there an equivalent of this? api.setVersion(defaultVersion); // don't think this is relevant anymore setPolicies(api, bean); log.debug("Processing: {0}", config); log.debug("Creating API: {0}", api); apis.add(api); } dataProcessed = true; checkQueue(); } catch (DecodeException e) { failAll(e); } }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(Api api, IAsyncResultHandler<Void> handler) { List<Policy> policies = api.getApiPolicies(); encryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); encryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); delegate.publishApi(api, handler); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); }
} else { Exception error = new NoContractFoundException(Messages.i18n.format("InMemoryRegistry.NoContractFound", //$NON-NLS-1$ client.getClientId(), api.getApiId())); handler.handle(AsyncResultImpl.create(error, ApiContract.class));
@Override public void listApis(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Api) .map(entity -> (Api) entity) .filter(api -> api.getOrganizationId().equals(organizationId)) .map(api -> api.getApiId()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
private void setPolicies(Api api, Auth3ScaleBean config) { // FIXME optimise // Add 3scale policy Policy pol = new Policy(); pol.setPolicyImpl(determinePolicyImpl()); // TODO get version? Hmm! Env? pol.setPolicyJsonConfig(Json.encode(config)); api.getApiPolicies().add(pol); // Add any policies user specified in remote config. policyConfigApis.stream() .filter(skeleton -> skeleton.getApiId().equals(api.getApiId())) // Apply policies from skeleton to 3scale API. .forEach(skeleton -> api.getApiPolicies().addAll(skeleton.getApiPolicies())); }
String endpoint = ApimanPathUtils.join(api.getEndpoint(), request.getDestination()); BasicAuthOptions options = new BasicAuthOptions(api.getEndpointProperties()); if (options.getUsername() != null && options.getPassword() != null) { if (options.isRequireSSL() && !isSsl) {
/** * Constructor. * @param api * @param request * @param handler */ public PolicyTesterApiConnection(Api api, ApiRequest request, IAsyncResultHandler<IApiConnectionResponse> handler) { this.request = request; this.handler = handler; this.output = null; this.backEndApi = createBackEndApi(api.getEndpoint()); }
@Override public void listOrgs(IAsyncResultHandler<List<String>> handler) { // TODO: We should track set of OrgId -> AtomicCounter if this API has meaningfully high usage. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .map(elem -> { if (elem instanceof Api) { return ((Api) elem).getOrganizationId(); } else { return ((Client) elem).getOrganizationId(); } }) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
policy.setPolicyJsonConfig(getPolicyConfiguration(config)); Api api = new Api(); api.setEndpoint(backEndApi.getName()); api.setEndpointType("TEST"); api.setOrganizationId(orgId); api.setApiId(apiId); api.setVersion(String.valueOf(version)); api.setPublicAPI(true); api.setApiPolicies(Collections.singletonList(policy));