Merge pull request #52 from ityuhui/yh-generic-client-patch
Add PATCH operation to the generic client
This commit is contained in:
@@ -46,6 +46,18 @@ int main(int argc, char *argv[])
|
|||||||
printf("%s\n", update);
|
printf("%s\n", update);
|
||||||
free(update);
|
free(update);
|
||||||
|
|
||||||
|
const char *patchBody = "[{\"op\": \"replace\", \"path\": \"/metadata/labels/foo\", \"value\": \"qux\" }]";
|
||||||
|
list_t *contentType = list_create();
|
||||||
|
// Kubernetes supports multiple content types:
|
||||||
|
list_addElement(contentType, "application/json-patch+json");
|
||||||
|
// list_addElement(contentType, "application/merge-patch+json");
|
||||||
|
// list_addElement(contentType, "application/strategic-merge-patch+json");
|
||||||
|
// list_addElement(contentType, "application/apply-patch+yaml");
|
||||||
|
char *patch = Generic_patchResource(genericClient, "test", patchBody, NULL, NULL, NULL, NULL, contentType);
|
||||||
|
printf("%s\n", patch);
|
||||||
|
list_free(contentType);
|
||||||
|
free(patch);
|
||||||
|
|
||||||
char *del = Generic_deleteResource(genericClient, "test");
|
char *del = Generic_deleteResource(genericClient, "test");
|
||||||
printf("%s\n", del);
|
printf("%s\n", del);
|
||||||
free(del);
|
free(del);
|
||||||
@@ -53,7 +65,6 @@ int main(int argc, char *argv[])
|
|||||||
genericClient_free(genericClient);
|
genericClient_free(genericClient);
|
||||||
genericClient = NULL;
|
genericClient = NULL;
|
||||||
|
|
||||||
|
|
||||||
apiClient_free(apiClient);
|
apiClient_free(apiClient);
|
||||||
apiClient = NULL;
|
apiClient = NULL;
|
||||||
free_client_config(basePath, sslConfig, apiKeys);
|
free_client_config(basePath, sslConfig, apiKeys);
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ char* Generic_createResource(genericClient_t *client, const char* body);
|
|||||||
char* Generic_replaceNamespacedResource(genericClient_t *client, const char *ns, const char *name, const char* body);
|
char* Generic_replaceNamespacedResource(genericClient_t *client, const char *ns, const char *name, const char* body);
|
||||||
char* Generic_replaceResource(genericClient_t *client, const char *name, const char* body);
|
char* Generic_replaceResource(genericClient_t *client, const char *name, const char* body);
|
||||||
|
|
||||||
|
char* Generic_patchNamespacedResource(genericClient_t *client, const char *ns, const char *name, const char *body, list_t *queryParameters, list_t *headerParameters, list_t *formParameters,
|
||||||
|
list_t *headerType, list_t *contentType);
|
||||||
|
char* Generic_patchResource(genericClient_t *client, const char *name, const char *body, list_t *queryParameters, list_t *headerParameters, list_t *formParameters, list_t *headerType,
|
||||||
|
list_t *contentType);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ void makeResourcePath(char* path, genericClient_t *client, const char* name) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* callInternal(genericClient_t *client, const char* path, const char* method, const char* body) {
|
char* callInternal(genericClient_t *client,
|
||||||
apiClient_invoke(client->client, path, NULL, NULL, NULL, NULL, NULL, body, method);
|
const char *path, list_t *queryParameters, list_t *headerParameters, list_t *formParameters, list_t *headerType, list_t *contentType, const char *body, const char *method)
|
||||||
|
{
|
||||||
|
apiClient_invoke(client->client, path, queryParameters, headerParameters, formParameters, headerType, contentType, body, method);
|
||||||
|
|
||||||
if (client->client->response_code == 200) {
|
if (client->client->response_code == 200) {
|
||||||
printf("%s\n","OK");
|
printf("%s\n","OK");
|
||||||
@@ -71,18 +73,23 @@ char* callInternal(genericClient_t *client, const char* path, const char* method
|
|||||||
return elementToReturn;
|
return elementToReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *callSimplifiedInternal(genericClient_t *client, const char *path, const char *method, const char *body)
|
||||||
|
{
|
||||||
|
return callInternal(client, path, NULL, NULL, NULL, NULL, NULL, body, method);
|
||||||
|
}
|
||||||
|
|
||||||
char* Generic_readNamespacedResource(genericClient_t *client, const char *namespace, const char *name) {
|
char* Generic_readNamespacedResource(genericClient_t *client, const char *namespace, const char *name) {
|
||||||
char path[128];
|
char path[128];
|
||||||
|
|
||||||
makeNamespacedResourcePath(path, client, namespace, name);
|
makeNamespacedResourcePath(path, client, namespace, name);
|
||||||
return callInternal(client, path, "GET", NULL);
|
return callSimplifiedInternal(client, path, "GET", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_readResource(genericClient_t *client, const char *name) {
|
char* Generic_readResource(genericClient_t *client, const char *name) {
|
||||||
char path[128];
|
char path[128];
|
||||||
|
|
||||||
makeResourcePath(path, client, name);
|
makeResourcePath(path, client, name);
|
||||||
return callInternal(client, path, "GET", NULL);
|
return callSimplifiedInternal(client, path, "GET", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Generic_listNamespaced(genericClient_t *client, const char *namespace) {
|
char *Generic_listNamespaced(genericClient_t *client, const char *namespace) {
|
||||||
@@ -94,7 +101,7 @@ char *Generic_listNamespaced(genericClient_t *client, const char *namespace) {
|
|||||||
snprintf(path, 128, "/api/%s/namespaces/%s/%s",
|
snprintf(path, 128, "/api/%s/namespaces/%s/%s",
|
||||||
client->apiVersion, namespace, client->resourcePlural);
|
client->apiVersion, namespace, client->resourcePlural);
|
||||||
}
|
}
|
||||||
return callInternal(client, path, "GET", NULL);
|
return callSimplifiedInternal(client, path, "GET", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Generic_list(genericClient_t *client) {
|
char *Generic_list(genericClient_t *client) {
|
||||||
@@ -106,42 +113,59 @@ char *Generic_list(genericClient_t *client) {
|
|||||||
snprintf(path, 128, "/api/%s/%s",
|
snprintf(path, 128, "/api/%s/%s",
|
||||||
client->apiVersion, client->resourcePlural);
|
client->apiVersion, client->resourcePlural);
|
||||||
}
|
}
|
||||||
return callInternal(client, path, "GET", NULL);
|
return callSimplifiedInternal(client, path, "GET", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_deleteNamespacedResource(genericClient_t *client, const char *namespace, const char *name) {
|
char* Generic_deleteNamespacedResource(genericClient_t *client, const char *namespace, const char *name) {
|
||||||
char path[128];
|
char path[128];
|
||||||
makeNamespacedResourcePath(path, client, namespace, name);
|
makeNamespacedResourcePath(path, client, namespace, name);
|
||||||
return callInternal(client, path, "DELETE", NULL);
|
return callSimplifiedInternal(client, path, "DELETE", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_deleteResource(genericClient_t *client, const char* name) {
|
char* Generic_deleteResource(genericClient_t *client, const char* name) {
|
||||||
char path[128];
|
char path[128];
|
||||||
makeResourcePath(path, client, name);
|
makeResourcePath(path, client, name);
|
||||||
return callInternal(client, path, "DELETE", NULL);
|
return callSimplifiedInternal(client, path, "DELETE", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_createNamespacedResource(genericClient_t *client, const char *ns, const char* body) {
|
char* Generic_createNamespacedResource(genericClient_t *client, const char *ns, const char* body) {
|
||||||
char path[128];
|
char path[128];
|
||||||
makeNamespacedResourcePath(path, client, ns, "");
|
makeNamespacedResourcePath(path, client, ns, "");
|
||||||
return callInternal(client, path, "POST", body);
|
return callSimplifiedInternal(client, path, "POST", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_createResource(genericClient_t *client, const char* body) {
|
char* Generic_createResource(genericClient_t *client, const char* body) {
|
||||||
char path[128];
|
char path[128];
|
||||||
makeResourcePath(path, client, "");
|
makeResourcePath(path, client, "");
|
||||||
printf("%s\n", path);
|
printf("%s\n", path);
|
||||||
return callInternal(client, path, "POST", body);
|
return callSimplifiedInternal(client, path, "POST", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_replaceNamespacedResource(genericClient_t *client, const char *ns, const char *name, const char* body) {
|
char* Generic_replaceNamespacedResource(genericClient_t *client, const char *ns, const char *name, const char* body) {
|
||||||
char path[128];
|
char path[128];
|
||||||
makeNamespacedResourcePath(path, client, ns, name);
|
makeNamespacedResourcePath(path, client, ns, name);
|
||||||
return callInternal(client, path, "PUT", body);
|
return callSimplifiedInternal(client, path, "PUT", body);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Generic_replaceResource(genericClient_t *client, const char *name, const char* body) {
|
char* Generic_replaceResource(genericClient_t *client, const char *name, const char* body) {
|
||||||
char path[128];
|
char path[128];
|
||||||
makeResourcePath(path, client, name);
|
makeResourcePath(path, client, name);
|
||||||
return callInternal(client, path, "PUT", body);
|
return callSimplifiedInternal(client, path, "PUT", body);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* Generic_patchNamespacedResource(genericClient_t * client,
|
||||||
|
const char *ns,
|
||||||
|
const char *name, const char *body, list_t *queryParameters, list_t *headerParameters, list_t *formParameters, list_t *headerType, list_t *contentType)
|
||||||
|
{
|
||||||
|
char path[128];
|
||||||
|
makeNamespacedResourcePath(path, client, ns, name);
|
||||||
|
return callInternal(client, path, queryParameters, headerParameters, formParameters, headerType, contentType, body, "PATCH");
|
||||||
|
}
|
||||||
|
|
||||||
|
char* Generic_patchResource(genericClient_t * client,
|
||||||
|
const char *name, const char *body, list_t *queryParameters, list_t *headerParameters, list_t *formParameters, list_t *headerType, list_t *contentType)
|
||||||
|
{
|
||||||
|
char path[128];
|
||||||
|
makeResourcePath(path, client, name);
|
||||||
|
return callInternal(client, path, queryParameters, headerParameters, formParameters, headerType, contentType, body, "PATCH");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user