public static Map<String, String> parseUriQueryParams(URI uri) { String query = uri.getQuery(); return parseUriQueryParams(query); }
public static boolean hasNavigationQueryParams(URI uri) { if (uri.getQuery() == null) { return false; } Set<String> q = UriUtils.parseUriQueryParams(uri).keySet(); return q.contains(FORWARDING_URI_PARAM_NAME_PATH) || q.contains(FORWARDING_URI_PARAM_NAME_PEER); }
public static boolean hasODataQueryParams(URI uri) { if (uri.getQuery() == null) { return false; } Set<String> q = UriUtils.parseUriQueryParams(uri).keySet(); return q.contains(URI_PARAM_ODATA_TOP) || q.contains(URI_PARAM_ODATA_COUNT) || q.contains(URI_PARAM_ODATA_LIMIT) || q.contains(URI_PARAM_ODATA_SKIP) || q.contains(URI_PARAM_ODATA_SELECT) || q.contains(URI_PARAM_ODATA_ORDER_BY) || q.contains(URI_PARAM_ODATA_FILTER); }
public static String getODataFilterParamValue(URI uri) { String query = uri.getQuery(); if (query == null || query.isEmpty()) { return null; } if (!query.contains(URI_PARAM_ODATA_FILTER)) { return null; } Map<String, String> queryParams = parseUriQueryParams(uri); String filterParamValue = queryParams.get(URI_PARAM_ODATA_FILTER); if (filterParamValue == null || filterParamValue.isEmpty()) { return null; } return filterParamValue; }
public static String getODataParamValueAsString(final URI uri, final String uriParamOdataType) { String query = uri.getQuery(); if (query == null || query.isEmpty()) { return null; } if (!query.contains(uriParamOdataType)) { return null; } Map<String, String> queryParams = parseUriQueryParams(uri); String paramValue = queryParams.get(uriParamOdataType); if (paramValue == null || paramValue.isEmpty()) { return null; } return paramValue; }
public static boolean isPublicProjectsAccess(Operation op) { Map<String, String> queryParams = UriUtils.parseUriQueryParams(op.getUri()); return (op.getAction() == Action.GET) && queryParams.containsKey(QUERY_PARAM_PUBLIC) && (queryParams.get(QUERY_PARAM_PUBLIC).isEmpty() || Boolean.parseBoolean(queryParams.get(QUERY_PARAM_PUBLIC))); }
@Override public void handleGet(Operation get) { Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri()); String containerId = params.remove(CONTAINER_ID_QUERY_PARAM); if (containerId == null || containerId.isEmpty()) { get.fail(new IllegalArgumentException( "URL parameter 'id' expected with container id as value.")); return; } getContainerStateAndProcess(get, containerId); }
private boolean isPrincipalByCriteriaRequest(Operation op) { if (!UriUtilsExtended.uriPathMatches(op.getUri(), PATTERN_PRINCIPAL_SERVICE_BASE)) { return false; } String criteria = UriUtils.parseUriQueryParams(op.getUri()).get(CRITERIA_QUERY); return criteria != null && !criteria.isEmpty(); }
@Override public void handleGet(Operation get) { Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri()); String generation = params.get("logFileNumber"); if (generation == null || generation.isEmpty()) { generation = "0"; } String file = this.logFileName.replaceFirst("%g", generation); int max = Integer.MAX_VALUE; String lineCount = params.get("lineCount"); if (lineCount != null) { max = Integer.parseInt(lineCount); } AsyncLogFileReader reader = AsyncLogFileReader.create(getSelfLink()); try { reader.start(get, file, max); } catch (IOException e) { get.fail(e); } }
private void getEntitiesMatchingLabel(Operation get, String objectType) { Map<String, String> queryParams = UriUtils.parseUriQueryParams(get.getUri()); String labelSelectorKey = queryParams.get("labelSelector").split("=")[0]; String labelSelectorValue = queryParams.get("labelSelector").split("=")[1]; List<BaseKubernetesObject> items = deployedElements.stream() .filter(e -> e.kind.equals(objectType)) .filter(e -> { if (e.metadata.labels.containsKey(labelSelectorKey) && e.metadata.labels.get (labelSelectorKey).equals(labelSelectorValue)) { return true; } return false; }).collect(Collectors.toList()); HashMap<String, Object> response = new HashMap<>(); response.put("items", items); get.setBody(response).complete(); }
@Override public void handleGet(Operation op) { try { Map<String, String> queryParams = UriUtils.parseUriQueryParams(op.getUri()); String hostLink = queryParams.get(KUBERNETES_HOST_LINK_PARAM_NAME); AssertUtil.assertNotNullOrEmpty(hostLink, KUBERNETES_HOST_LINK_PARAM_NAME); getHostAndCredentials(op, hostLink, (compute, credentials) -> constructKubeConfig(op, compute, credentials)); } catch (Exception x) { logSevere(x); op.fail(x); } }
@Test public void testParseUriQueryParams() { URI u = UriUtils.buildUri("http://example.com:8000/?a=b&c=d&d&e=f=g&h=&=z"); Map<String, String> queryParams = UriUtils.parseUriQueryParams(u); assertEquals(5, queryParams.size()); assertTrue(queryParams.get("a").equals("b")); assertTrue(queryParams.get("c").equals("d")); assertTrue(queryParams.get("d").equals("")); assertTrue(queryParams.get("e").equals("f=g")); assertTrue(queryParams.get("h").equals("")); }
@Test public void testParseUriQueryParams() { URI u = UriUtils.buildUri("http://example.com:8000/?a=b&c=d&d&e=f=g&h=&=z"); Map<String, String> queryParams = UriUtils.parseUriQueryParams(u); assertEquals(5, queryParams.size()); assertTrue(queryParams.get("a").equals("b")); assertTrue(queryParams.get("c").equals("d")); assertTrue(queryParams.get("d").equals("")); assertTrue(queryParams.get("e").equals("f=g")); assertTrue(queryParams.get("h").equals("")); }
@Override public void handleGet(Operation get) { Map<String, String> queryParams = UriUtils.parseUriQueryParams(get.getUri()); String requestId = queryParams.remove(QUERY_PARAM); String host = queryParams.remove(HOST_PARAM); AssertUtil.assertNotEmpty(requestId, QUERY_PARAM); List<TaskServiceDocumentHistoryInternal> foundTasks = new ArrayList<>(); retrieveAllFromContext(requestId, host, foundTasks, (ex) -> { if (ex != null) { get.fail(ex); } else { RequestBrokerGraphResponse r = new RequestBrokerGraphResponse(); r.tasks = convert(foundTasks); populateRequestInfos(r, r.tasks, requestId); get.setBody(r); get.complete(); } }); }
@Override public void handleGet(Operation get) { Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri()); String podId = params.remove(POD_ID_QUERY_PARAM); if (podId == null || podId.isEmpty()) { get.fail(new IllegalArgumentException( "URL parameter 'id' expected with container id as value.")); return; } String podStateLink = UriUtils.buildUriPath(PodFactoryService.SELF_LINK, podId); sendRequest(Operation .createGet(this, podStateLink) .setCompletion((o, ex) -> { if (ex != null) { get.fail(ex); } else { PodState podState = o.getBody(PodState.class); processPodState(get, podState); } })); }
@Override public void handleGet(Operation get) { if (isSecurityContextRequest(get)) { handleGetSecurityContext(get); } else if (isRolesRequest(get)) { handleGetPrincipalRoles(get); } else if (isPrincipalByIdRequest(get)) { handleSearchById(get); } else if (isPrincipalByCriteriaRequest(get)) { Map<String, String> queryParams = UriUtils.parseUriQueryParams(get.getUri()); String roleQueryValue = queryParams.getOrDefault(ROLES_QUERY, null); handleSearchByCriteria(queryParams.get(CRITERIA_QUERY), roleQueryValue, get); } else { get.fail(new IllegalArgumentException( "Provide either criteria or principalId to search for.")); } }
@Override public void handlePost(Operation post) { if (!post.hasBody()) { post.fail(new IllegalArgumentException("body is required")); return; } Map<String, String> queryParams = UriUtils.parseUriQueryParams(post.getUri()); String reverseParam = queryParams.remove(REVERSE_PARENT_LINKS_PARAM); boolean reverse = Boolean.TRUE.equals(Boolean.parseBoolean(reverseParam)); String projectLink = OperationUtil.extractProjectFromHeader(post); try { CompositeDescription cd = post.getBody(CompositeDescription.class); validateStateOnStart(cd); String requestURL = cd.documentSelfLink + ManagementUriParts.EXPAND_SUFFIX; cloneCompositeDescription(requestURL, reverse, null, projectLink, (cdClone) -> post.setBody(cdClone).complete()); } catch (Throwable e) { logSevere(e); post.fail(e); } }
@Override public void handleGet(Operation get) { Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri()); String containerId = params.remove(CONTAINER_ID_QUERY_PARAM); if (containerId == null || containerId.isEmpty()) { get.fail(new IllegalArgumentException( "URL parameter 'id' expected with container id as value.")); return; } final String containerLogsLink = UriUtils.buildUriPath(LogService.FACTORY_LINK, containerId); sendRequest(Operation.createGet(this, containerLogsLink) .setCompletion((o, e) -> { if (e != null) { requestLog(get, containerId, params); } else { get.setBody(o.getBody(LogServiceState.class)).complete(); requestLog(null, containerId, params); } })); }
private void handleGetAuthorizationContext(Operation op) { AuthorizationContext ctx = op.getAuthorizationContext(); if (ctx == null) { op.fail(new IllegalStateException("ctx == null")); return; } Claims claims = ctx.getClaims(); if (claims == null) { op.fail(new IllegalStateException("claims == null")); return; } Map<String, String> params = UriUtils.parseUriQueryParams(op.getUri()); String expectContext = params.get(EXPECT_USER_CONTEXT); if (expectContext.equals(Boolean.toString(true))) { assertNotEquals(GuestUserService.SELF_LINK, claims.getSubject()); } else { assertEquals(GuestUserService.SELF_LINK, claims.getSubject()); } op.setBody(claims).complete(); } }
private void handleGetAuthorizationContext(Operation op) { AuthorizationContext ctx = op.getAuthorizationContext(); if (ctx == null) { op.fail(new IllegalStateException("ctx == null")); return; } Claims claims = ctx.getClaims(); if (claims == null) { op.fail(new IllegalStateException("claims == null")); return; } Map<String, String> params = UriUtils.parseUriQueryParams(op.getUri()); String expectContext = params.get(EXPECT_USER_CONTEXT); if (expectContext.equals(Boolean.toString(true))) { assertNotEquals(GuestUserService.SELF_LINK, claims.getSubject()); } else { assertEquals(GuestUserService.SELF_LINK, claims.getSubject()); } op.setBody(claims).complete(); } }