generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 75
Closed
Description
I try to search for that key kubernetes.io/serviceaccount/namespace, is this possible with this lib?
Here my naive sample code
#include <core_json.h>
#include <stdio.h>
int main()
{
// Variables used in this example.
JSONStatus_t result;
char buffer[] = "{\"iss\":\"kubernetes/serviceaccount\",\"kubernetes.io/serviceaccount/namespace\":\"openshift-logging\",\"foo\":\"abc\",\"bar\":{\"foo\":\"xyz\"}}";
size_t bufferLength = sizeof(buffer) - 1;
// char query[] = "kubernetes.io/serviceaccount/namespace";
char query[] = "iss";
size_t queryLength = sizeof(query) - 1;
char *value;
size_t valueLength;
// Calling JSON_Validate() is not necessary if the document is guaranteed to be valid.
result = JSON_Validate(buffer, bufferLength);
if (result == JSONSuccess)
{
result = JSON_Search(buffer, bufferLength, query, queryLength,
&value, &valueLength);
if (result == JSONSuccess)
{
// The pointer "value" will point to a location in the "buffer".
char save = value[valueLength];
// After saving the character, set it to a null byte for printing.
value[valueLength] = '\0';
// "Found: bar.foo -> xyz" will be printed.
printf("Found: %s -> %s\n", query, value);
// Restore the original character.
value[valueLength] = save;
} else {
printf("NOT JSON_Search Found: %d\n", result);
}
}
else
{
printf("NOT JSON_Validate Found: %s\n", query);
}
}build with this command
# kubernetes.io/serviceaccount/namespace
git-repos/coreJSON$ gcc -Isource/include/ source/core_json.c test/jwt/my-jwt.c -o test/jwt/my-jwt && test/jwt/my-jwt
# iss
gcc -Isource/include/ source/core_json.c test/jwt/my-jwt.c -o test/jwt/my-jwt && test/jwt/my-jwt
Found: iss -> kubernetes/serviceaccountReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels