2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_delete_options.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_delete_options_t *v1_delete_options_create(
|
|
|
|
|
char *api_version,
|
|
|
|
|
list_t *dry_run,
|
|
|
|
|
long grace_period_seconds,
|
|
|
|
|
char *kind,
|
|
|
|
|
int orphan_dependents,
|
|
|
|
|
v1_preconditions_t *preconditions,
|
|
|
|
|
char *propagation_policy
|
|
|
|
|
) {
|
|
|
|
|
v1_delete_options_t *v1_delete_options_local_var = malloc(sizeof(v1_delete_options_t));
|
|
|
|
|
if (!v1_delete_options_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_delete_options_local_var->api_version = api_version;
|
|
|
|
|
v1_delete_options_local_var->dry_run = dry_run;
|
|
|
|
|
v1_delete_options_local_var->grace_period_seconds = grace_period_seconds;
|
|
|
|
|
v1_delete_options_local_var->kind = kind;
|
|
|
|
|
v1_delete_options_local_var->orphan_dependents = orphan_dependents;
|
|
|
|
|
v1_delete_options_local_var->preconditions = preconditions;
|
|
|
|
|
v1_delete_options_local_var->propagation_policy = propagation_policy;
|
|
|
|
|
|
|
|
|
|
return v1_delete_options_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void v1_delete_options_free(v1_delete_options_t *v1_delete_options) {
|
|
|
|
|
if(NULL == v1_delete_options){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_delete_options->api_version) {
|
|
|
|
|
free(v1_delete_options->api_version);
|
|
|
|
|
v1_delete_options->api_version = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_delete_options->dry_run) {
|
|
|
|
|
list_ForEach(listEntry, v1_delete_options->dry_run) {
|
|
|
|
|
free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_delete_options->dry_run);
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_delete_options->dry_run = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_delete_options->kind) {
|
|
|
|
|
free(v1_delete_options->kind);
|
|
|
|
|
v1_delete_options->kind = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_delete_options->preconditions) {
|
|
|
|
|
v1_preconditions_free(v1_delete_options->preconditions);
|
|
|
|
|
v1_delete_options->preconditions = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_delete_options->propagation_policy) {
|
|
|
|
|
free(v1_delete_options->propagation_policy);
|
|
|
|
|
v1_delete_options->propagation_policy = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
free(v1_delete_options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_delete_options_convertToJSON(v1_delete_options_t *v1_delete_options) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->api_version
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->api_version) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "apiVersion", v1_delete_options->api_version) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->dry_run
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->dry_run) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *dry_run = cJSON_AddArrayToObject(item, "dryRun");
|
|
|
|
|
if(dry_run == NULL) {
|
|
|
|
|
goto fail; //primitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *dry_runListEntry;
|
|
|
|
|
list_ForEach(dry_runListEntry, v1_delete_options->dry_run) {
|
|
|
|
|
if(cJSON_AddStringToObject(dry_run, "", (char*)dry_runListEntry->data) == NULL)
|
|
|
|
|
{
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->grace_period_seconds
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->grace_period_seconds) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "gracePeriodSeconds", v1_delete_options->grace_period_seconds) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->kind
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->kind) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "kind", v1_delete_options->kind) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->orphan_dependents
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->orphan_dependents) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddBoolToObject(item, "orphanDependents", v1_delete_options->orphan_dependents) == NULL) {
|
|
|
|
|
goto fail; //Bool
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->preconditions
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->preconditions) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *preconditions_local_JSON = v1_preconditions_convertToJSON(v1_delete_options->preconditions);
|
|
|
|
|
if(preconditions_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "preconditions", preconditions_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_delete_options->propagation_policy
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_delete_options->propagation_policy) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "propagationPolicy", v1_delete_options->propagation_policy) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
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_delete_options_t *v1_delete_options_parseFromJSON(cJSON *v1_delete_optionsJSON){
|
|
|
|
|
|
|
|
|
|
v1_delete_options_t *v1_delete_options_local_var = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local list for v1_delete_options->dry_run
|
|
|
|
|
list_t *dry_runList = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_delete_options->preconditions
|
|
|
|
|
v1_preconditions_t *preconditions_local_nonprim = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_delete_options->api_version
|
|
|
|
|
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "apiVersion");
|
|
|
|
|
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_delete_options->dry_run
|
|
|
|
|
cJSON *dry_run = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "dryRun");
|
|
|
|
|
if (dry_run) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *dry_run_local = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
if(!cJSON_IsArray(dry_run)) {
|
|
|
|
|
goto end;//primitive container
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
dry_runList = list_createList();
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(dry_run_local, dry_run)
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsString(dry_run_local))
|
|
|
|
|
{
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
list_addElement(dry_runList , strdup(dry_run_local->valuestring));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->grace_period_seconds
|
|
|
|
|
cJSON *grace_period_seconds = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "gracePeriodSeconds");
|
|
|
|
|
if (grace_period_seconds) {
|
|
|
|
|
if(!cJSON_IsNumber(grace_period_seconds))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->kind
|
|
|
|
|
cJSON *kind = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "kind");
|
|
|
|
|
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_delete_options->orphan_dependents
|
|
|
|
|
cJSON *orphan_dependents = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "orphanDependents");
|
|
|
|
|
if (orphan_dependents) {
|
|
|
|
|
if(!cJSON_IsBool(orphan_dependents))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Bool
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->preconditions
|
|
|
|
|
cJSON *preconditions = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "preconditions");
|
|
|
|
|
if (preconditions) {
|
|
|
|
|
preconditions_local_nonprim = v1_preconditions_parseFromJSON(preconditions); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_delete_options->propagation_policy
|
|
|
|
|
cJSON *propagation_policy = cJSON_GetObjectItemCaseSensitive(v1_delete_optionsJSON, "propagationPolicy");
|
|
|
|
|
if (propagation_policy) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(propagation_policy) && !cJSON_IsNull(propagation_policy))
|
2020-03-18 17:24:33 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_delete_options_local_var = v1_delete_options_create (
|
2022-12-29 10:58:47 +08:00
|
|
|
api_version && !cJSON_IsNull(api_version) ? strdup(api_version->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
dry_run ? dry_runList : NULL,
|
|
|
|
|
grace_period_seconds ? grace_period_seconds->valuedouble : 0,
|
2022-12-29 10:58:47 +08:00
|
|
|
kind && !cJSON_IsNull(kind) ? strdup(kind->valuestring) : NULL,
|
2020-03-18 17:24:33 +08:00
|
|
|
orphan_dependents ? orphan_dependents->valueint : 0,
|
|
|
|
|
preconditions ? preconditions_local_nonprim : NULL,
|
2022-12-29 10:58:47 +08:00
|
|
|
propagation_policy && !cJSON_IsNull(propagation_policy) ? strdup(propagation_policy->valuestring) : NULL
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_delete_options_local_var;
|
|
|
|
|
end:
|
2022-03-29 10:12:05 +08:00
|
|
|
if (dry_runList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, dry_runList) {
|
|
|
|
|
free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(dry_runList);
|
|
|
|
|
dry_runList = NULL;
|
|
|
|
|
}
|
2021-01-11 12:15:24 +08:00
|
|
|
if (preconditions_local_nonprim) {
|
|
|
|
|
v1_preconditions_free(preconditions_local_nonprim);
|
|
|
|
|
preconditions_local_nonprim = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|