2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_mutating_webhook_configuration.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
char *api_version,
|
|
|
|
|
char *kind,
|
|
|
|
|
v1_object_meta_t *metadata,
|
|
|
|
|
list_t *webhooks
|
|
|
|
|
) {
|
|
|
|
|
v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration_local_var = malloc(sizeof(v1_mutating_webhook_configuration_t));
|
|
|
|
|
if (!v1_mutating_webhook_configuration_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_mutating_webhook_configuration_local_var->api_version = api_version;
|
|
|
|
|
v1_mutating_webhook_configuration_local_var->kind = kind;
|
|
|
|
|
v1_mutating_webhook_configuration_local_var->metadata = metadata;
|
|
|
|
|
v1_mutating_webhook_configuration_local_var->webhooks = webhooks;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_mutating_webhook_configuration_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_mutating_webhook_configuration_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration_create(
|
|
|
|
|
char *api_version,
|
|
|
|
|
char *kind,
|
|
|
|
|
v1_object_meta_t *metadata,
|
|
|
|
|
list_t *webhooks
|
|
|
|
|
) {
|
|
|
|
|
return v1_mutating_webhook_configuration_create_internal (
|
|
|
|
|
api_version,
|
|
|
|
|
kind,
|
|
|
|
|
metadata,
|
|
|
|
|
webhooks
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_mutating_webhook_configuration_free(v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration) {
|
|
|
|
|
if(NULL == v1_mutating_webhook_configuration){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_mutating_webhook_configuration->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_mutating_webhook_configuration_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_mutating_webhook_configuration->api_version) {
|
|
|
|
|
free(v1_mutating_webhook_configuration->api_version);
|
|
|
|
|
v1_mutating_webhook_configuration->api_version = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_mutating_webhook_configuration->kind) {
|
|
|
|
|
free(v1_mutating_webhook_configuration->kind);
|
|
|
|
|
v1_mutating_webhook_configuration->kind = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_mutating_webhook_configuration->metadata) {
|
|
|
|
|
v1_object_meta_free(v1_mutating_webhook_configuration->metadata);
|
|
|
|
|
v1_mutating_webhook_configuration->metadata = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_mutating_webhook_configuration->webhooks) {
|
|
|
|
|
list_ForEach(listEntry, v1_mutating_webhook_configuration->webhooks) {
|
|
|
|
|
v1_mutating_webhook_free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_mutating_webhook_configuration->webhooks);
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_mutating_webhook_configuration->webhooks = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
free(v1_mutating_webhook_configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_mutating_webhook_configuration_convertToJSON(v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->api_version
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_mutating_webhook_configuration->api_version) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "apiVersion", v1_mutating_webhook_configuration->api_version) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->kind
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_mutating_webhook_configuration->kind) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "kind", v1_mutating_webhook_configuration->kind) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->metadata
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_mutating_webhook_configuration->metadata) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *metadata_local_JSON = v1_object_meta_convertToJSON(v1_mutating_webhook_configuration->metadata);
|
|
|
|
|
if(metadata_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "metadata", metadata_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->webhooks
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_mutating_webhook_configuration->webhooks) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *webhooks = cJSON_AddArrayToObject(item, "webhooks");
|
|
|
|
|
if(webhooks == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *webhooksListEntry;
|
|
|
|
|
if (v1_mutating_webhook_configuration->webhooks) {
|
|
|
|
|
list_ForEach(webhooksListEntry, v1_mutating_webhook_configuration->webhooks) {
|
|
|
|
|
cJSON *itemLocal = v1_mutating_webhook_convertToJSON(webhooksListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(webhooks, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration_parseFromJSON(cJSON *v1_mutating_webhook_configurationJSON){
|
|
|
|
|
|
|
|
|
|
v1_mutating_webhook_configuration_t *v1_mutating_webhook_configuration_local_var = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_mutating_webhook_configuration->metadata
|
|
|
|
|
v1_object_meta_t *metadata_local_nonprim = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local list for v1_mutating_webhook_configuration->webhooks
|
|
|
|
|
list_t *webhooksList = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_mutating_webhook_configuration->api_version
|
|
|
|
|
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_mutating_webhook_configurationJSON, "apiVersion");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(api_version)) {
|
|
|
|
|
api_version = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (api_version) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(api_version) && !cJSON_IsNull(api_version))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->kind
|
|
|
|
|
cJSON *kind = cJSON_GetObjectItemCaseSensitive(v1_mutating_webhook_configurationJSON, "kind");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(kind)) {
|
|
|
|
|
kind = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (kind) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(kind) && !cJSON_IsNull(kind))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->metadata
|
|
|
|
|
cJSON *metadata = cJSON_GetObjectItemCaseSensitive(v1_mutating_webhook_configurationJSON, "metadata");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(metadata)) {
|
|
|
|
|
metadata = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (metadata) {
|
|
|
|
|
metadata_local_nonprim = v1_object_meta_parseFromJSON(metadata); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_mutating_webhook_configuration->webhooks
|
|
|
|
|
cJSON *webhooks = cJSON_GetObjectItemCaseSensitive(v1_mutating_webhook_configurationJSON, "webhooks");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(webhooks)) {
|
|
|
|
|
webhooks = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (webhooks) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *webhooks_local_nonprimitive = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
if(!cJSON_IsArray(webhooks)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 10:56:53 +08:00
|
|
|
webhooksList = list_createList();
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(webhooks_local_nonprimitive,webhooks )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(webhooks_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1_mutating_webhook_t *webhooksItem = v1_mutating_webhook_parseFromJSON(webhooks_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(webhooksList, webhooksItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_mutating_webhook_configuration_local_var = v1_mutating_webhook_configuration_create_internal (
|
2022-12-29 10:58:47 +08:00
|
|
|
api_version && !cJSON_IsNull(api_version) ? strdup(api_version->valuestring) : NULL,
|
|
|
|
|
kind && !cJSON_IsNull(kind) ? strdup(kind->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
metadata ? metadata_local_nonprim : NULL,
|
|
|
|
|
webhooks ? webhooksList : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_mutating_webhook_configuration_local_var;
|
|
|
|
|
end:
|
2021-01-11 12:15:24 +08:00
|
|
|
if (metadata_local_nonprim) {
|
|
|
|
|
v1_object_meta_free(metadata_local_nonprim);
|
|
|
|
|
metadata_local_nonprim = NULL;
|
|
|
|
|
}
|
2022-03-29 10:12:05 +08:00
|
|
|
if (webhooksList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, webhooksList) {
|
|
|
|
|
v1_mutating_webhook_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(webhooksList);
|
|
|
|
|
webhooksList = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|