Rework of arbitrary APIs and qdata to support identifiers

qdata has reached the stage of needing parameterized arguments, but this is low priority now that we have data functionality within the UI itself.
This commit is contained in:
CalDescent 2021-11-12 17:42:21 +00:00
parent 8d44e07c32
commit 1c408db907
2 changed files with 138 additions and 15 deletions

View File

@ -349,12 +349,11 @@ public class ArbitraryResource {
) )
public String post(@PathParam("service") String serviceString, public String post(@PathParam("service") String serviceString,
@PathParam("name") String name, @PathParam("name") String name,
@QueryParam("identifier") String identifier,
String path) { String path) {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
// TODO: automatic PUT/PATCH // TODO: automatic PUT/PATCH
return this.upload(Method.PUT, Service.valueOf(serviceString), name, identifier, path); return this.upload(Method.PUT, Service.valueOf(serviceString), name, null, path);
} }
@PUT @PUT
@ -385,11 +384,10 @@ public class ArbitraryResource {
) )
public String put(@PathParam("service") String serviceString, public String put(@PathParam("service") String serviceString,
@PathParam("name") String name, @PathParam("name") String name,
@QueryParam("identifier") String identifier,
String path) { String path) {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
return this.upload(Method.PUT, Service.valueOf(serviceString), name, identifier, path); return this.upload(Method.PUT, Service.valueOf(serviceString), name, null, path);
} }
@PATCH @PATCH
@ -421,10 +419,117 @@ public class ArbitraryResource {
) )
public String patch(@PathParam("service") String serviceString, public String patch(@PathParam("service") String serviceString,
@PathParam("name") String name, @PathParam("name") String name,
@QueryParam("identifier") String identifier,
String path) { String path) {
Security.checkApiCallAllowed(request); Security.checkApiCallAllowed(request);
return this.upload(Method.PATCH, Service.valueOf(serviceString), name, null, path);
}
@POST
@Path("/{service}/{name}/{identifier}")
@Operation(
summary = "Build raw, unsigned, ARBITRARY transaction, based on a user-supplied path",
description = "A POST transaction automatically selects a PUT or PATCH method based on the data supplied",
requestBody = @RequestBody(
required = true,
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string", example = "/Users/user/Documents/MyDirectoryOrFile"
)
)
),
responses = {
@ApiResponse(
description = "raw, unsigned, ARBITRARY transaction encoded in Base58",
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string"
)
)
)
}
)
public String post(@PathParam("service") String serviceString,
@PathParam("name") String name,
@PathParam("identifier") String identifier,
String path) {
Security.checkApiCallAllowed(request);
// TODO: automatic PUT/PATCH
return this.upload(Method.PUT, Service.valueOf(serviceString), name, identifier, path);
}
@PUT
@Path("/{service}/{name}/{identifier}")
@Operation(
summary = "Build raw, unsigned, ARBITRARY transaction, based on a user-supplied path, using the PUT method",
description = "A PUT transaction replaces the data held for this name and service in its entirety.",
requestBody = @RequestBody(
required = true,
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string", example = "/Users/user/Documents/MyDirectoryOrFile"
)
)
),
responses = {
@ApiResponse(
description = "raw, unsigned, ARBITRARY transaction encoded in Base58",
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string"
)
)
)
}
)
public String put(@PathParam("service") String serviceString,
@PathParam("name") String name,
@PathParam("identifier") String identifier,
String path) {
Security.checkApiCallAllowed(request);
return this.upload(Method.PUT, Service.valueOf(serviceString), name, identifier, path);
}
@PATCH
@Path("/{service}/{name}/{identifier}")
@Operation(
summary = "Build raw, unsigned, ARBITRARY transaction, based on a user-supplied path, using the PATCH method",
description = "A PATCH transaction calculates the delta between the current state on the on-chain state, " +
"and then publishes only the differences.",
requestBody = @RequestBody(
required = true,
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string", example = "/Users/user/Documents/MyDirectoryOrFile"
)
)
),
responses = {
@ApiResponse(
description = "raw, unsigned, ARBITRARY transaction encoded in Base58",
content = @Content(
mediaType = MediaType.TEXT_PLAIN,
schema = @Schema(
type = "string"
)
)
)
}
)
public String patch(@PathParam("service") String serviceString,
@PathParam("name") String name,
@PathParam("identifier") String identifier,
String path) {
Security.checkApiCallAllowed(request);
return this.upload(Method.PATCH, Service.valueOf(serviceString), name, identifier, path); return this.upload(Method.PATCH, Service.valueOf(serviceString), name, identifier, path);
} }

View File

@ -8,10 +8,16 @@ if [ -z "$*" ]; then
echo "Usage:" echo "Usage:"
echo echo
echo "Host/update data:" echo "Host/update data:"
echo "qdata [PUT/PATCH] [service] [name] [dirpath]" echo "qdata [PUT/PATCH] [service] [name] [dirpath] <identifier>"
echo echo
echo "Fetch data:" echo "Fetch data:"
echo "qdata GET [service] [name] [filepath] <rebuild>" echo "qdata GET [service] [name] <identifier-or-default> <filepath-or-default> <rebuild>"
echo
echo "Notes:"
echo "- When requesting a resource, please supply the relative path to a file within the data structure,"
echo " or 'default' to indicate a file with no identifier."
echo "- The same applies when specifying the relative path to a file within the data structure; use 'default'"
echo " to indicate a single file resource."
echo echo
exit exit
fi fi
@ -33,6 +39,7 @@ fi
if [[ "${method}" == "PUT" || "${method}" == "PATCH" ]]; then if [[ "${method}" == "PUT" || "${method}" == "PATCH" ]]; then
directory=$4 directory=$4
identifier=$5
if [ -z "${directory}" ]; then if [ -z "${directory}" ]; then
echo "Error: missing directory"; exit echo "Error: missing directory"; exit
@ -42,7 +49,7 @@ if [[ "${method}" == "PUT" || "${method}" == "PATCH" ]]; then
fi fi
echo "Creating transaction - this can take a while..." echo "Creating transaction - this can take a while..."
tx_data=$(curl --silent --insecure -X ${method} "http://${host}:${port}/arbitrary/${service}/${name}" -d "${directory}") tx_data=$(curl --silent --insecure -X ${method} "http://${host}:${port}/arbitrary/${service}/${name}/${identifier}" -d "${directory}")
if [[ "${tx_data}" == *"error"* || "${tx_data}" == *"ERROR"* ]]; then if [[ "${tx_data}" == *"error"* || "${tx_data}" == *"ERROR"* ]]; then
echo "${tx_data}"; exit echo "${tx_data}"; exit
fi fi
@ -63,18 +70,29 @@ if [[ "${method}" == "PUT" || "${method}" == "PATCH" ]]; then
fi fi
elif [[ "${method}" == "GET" ]]; then elif [[ "${method}" == "GET" ]]; then
filepath=$4 identifier=$4
rebuild=$5 filepath=$5
rebuild=$6
if [ -z "${filepath}" ]; then
echo "Error: missing filepath. Please supply the relative path to a file within the data structure."; exit
fi
if [ -z "${rebuild}" ]; then if [ -z "${rebuild}" ]; then
rebuild="false" rebuild="false"
fi fi
response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}?rebuild=${rebuild}&filepath=${filepath}") # Handle default
if [[ "${identifier}" == "default" ]]; then
identifier=""
fi
if [[ "${filepath}" == "default" ]]; then
filepath=""
fi
# We use a different API depending on whether or not an identifier is supplied
if [ -n "${identifier}" ]; then
response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}/${identifier}?rebuild=${rebuild}&filepath=${filepath}")
else
response=$(curl --silent --insecure -X GET "http://${host}:${port}/arbitrary/${service}/${name}?rebuild=${rebuild}&filepath=${filepath}")
fi
if [ -z "${response}" ]; then if [ -z "${response}" ]; then
echo "Empty response from ${host}:${port}" echo "Empty response from ${host}:${port}"
fi fi