fix: updating docs around -q parameter (#29151)

closes: #27877

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steven Hawkins
2024-05-02 10:48:43 -04:00
committed by GitHub
parent f3227c325a
commit 3b1ca46be2
8 changed files with 27 additions and 19 deletions

View File

@@ -113,7 +113,7 @@ public abstract class AbstractRequestCmd extends AbstractAuthOptionsCmd {
@ArgGroup(exclusive = true, multiplicity = "0..*")
List<AttributeOperations> rawAttributeOperations = new ArrayList<>();
@Option(names = {"-q", "--query"}, description = "Add to request URI a NAME query parameter with value VALUE")
@Option(names = {"-q", "--query"}, description = "Add to request URI a NAME query parameter with value VALUE, for example --query q=username:admin")
List<String> rawFilters = new LinkedList<>();
@Parameters(arity = "0..1")
@@ -142,12 +142,7 @@ public abstract class AbstractRequestCmd extends AbstractAuthOptionsCmd {
}
for (String arg : rawFilters) {
String[] keyVal;
if (arg.indexOf("=") == -1) {
keyVal = new String[] {"", arg};
} else {
keyVal = parseKeyVal(arg);
}
String[] keyVal = parseKeyVal(arg);
filter.put(keyVal[0], keyVal[1]);
}

View File

@@ -110,7 +110,7 @@ public class CreateCmd extends AbstractRequestCmd {
out.println(" -d, --delete NAME Remove a specific attribute NAME from JSON request body");
out.println(" -f, --file FILENAME Read object from file or standard input if FILENAME is set to '-'");
out.println(" -b, --body CONTENT Content to be sent as-is or used as a JSON object template");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE, for example --query q=username:admin");
out.println(" -h, --header NAME=VALUE Set request header NAME to VALUE");
out.println();
out.println(" -H, --print-headers Print response headers");

View File

@@ -74,7 +74,7 @@ public class DeleteCmd extends CreateCmd {
out.println(" -d, --delete NAME Remove a specific attribute NAME from JSON request body");
out.println(" -f, --file FILENAME Send a body with request - read object from file or standard input if FILENAME is set to '-'");
out.println(" -b, --body CONTENT Content to be sent as-is or used as a JSON object template");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE, for example --query q=username:admin");
out.println(" -h, --header NAME=VALUE Set request header NAME to VALUE");
out.println();
out.println(" -H, --print-headers Print response headers");

View File

@@ -106,7 +106,7 @@ public class GetCmd extends AbstractRequestCmd {
out.println(" realms, users, roles, groups, clients, keys, serverinfo, components ...");
out.println(" If it starts with 'http://' then it will be used as target resource url");
out.println(" -r, --target-realm REALM Target realm to issue requests against if not the one authenticated against");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE, for example --query q=username:admin");
out.println(" -h, --header NAME=VALUE Set request header NAME to VALUE");
out.println(" -o, --offset OFFSET Set paging offset - adds a query parameter 'first' which some endpoints recognize");
out.println(" -l, --limit LIMIT Set limit to number of items in result - adds a query parameter 'max' ");
@@ -164,7 +164,7 @@ public class GetCmd extends AbstractRequestCmd {
out.println("Note: 'users' endpoint knows how to handle --offset and --limit. Most other endpoints don't.");
out.println();
out.println("Get all users whose 'username' matches '*test*' pattern, and 'email' matches '*@google.com*':");
out.println(" " + PROMPT + " " + CMD + " get users -r demorealm -q username=test -q email=@google.com");
out.println(" " + PROMPT + " " + CMD + " get users -r demorealm -q q=\"username:test email:@google.com\"");
out.println();
out.println("Note: it is the 'users' endpoint that interprets query parameters 'username', and 'email' in such a way that");
out.println("it results in the described semantics. Another endpoint may provide a different semantics.");

View File

@@ -117,7 +117,7 @@ public class UpdateCmd extends AbstractRequestCmd {
out.println(" -d, --delete NAME Remove a specific attribute NAME from JSON request body");
out.println(" -f, --file FILENAME Read object from file or standard input if FILENAME is set to '-'");
out.println(" -b, --body CONTENT Content to be sent as-is or used as a JSON object template");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE");
out.println(" -q, --query NAME=VALUE Add to request URI a NAME query parameter with value VALUE, for example --query q=username:admin");
out.println(" -h, --header NAME=VALUE Set request header NAME to VALUE");
out.println(" -m, --merge Merge new values with existing configuration on the server");
out.println(" Merge is automatically enabled unless --file is specified");

View File

@@ -314,7 +314,7 @@ public class HttpUtil {
}
query.append(params.getKey()).append("=").append(URLEncoder.encode(params.getValue(), "utf-8"));
} catch (Exception e) {
throw new RuntimeException("Failed to encode query params: " + params.getKey() + "=" + params.getValue());
throw new IllegalArgumentException("Failed to encode query params: " + params.getKey() + "=" + params.getValue());
}
}