apigee / apigee-config-maven-plugin

apigee-config-maven-plugin
Apache License 2.0
55 stars 108 forks source link

apigee-config-maven-plugin:2.4.4:keyvaluemaps option UPDATE delete entries that doesnt exist in the kvms.json file #174

Closed eceledonio2296 closed 1 year ago

eceledonio2296 commented 1 year ago

Im trying to use the option: apigee-config:keyvaluemaps with the apigee-config-maven-plugin:2.4.4, but when I execute my maven command(mvn process-resources apigee-config:keyvaluemaps -Dapigee.config.options=update -Dapigee.bearer=$APIGEE_TOKEN) all the entries that are not specified in the kvms.json file are deleted and then the plugin create the new entries.

For example I have the next entry in my kvm:

{
    "keyValueEntries": [
        {
            "name": "ausername-novo2",
            "value": "EXMPL"
        }
    ],
    "nextPageToken": ""
}

then since I have the next entries in my kvms.json file:

[
    {
        "entry": [
            {
                "name": "ausername-novo3",
                "value": "EXMPL4"
            },
            {
                "name": "ausername-novo4",
                "value": "EXMPL4"
            }
        ],
        "name": "credenciales"
    }
]

I'm expecting that the result is the next:

{
    "keyValueEntries": [
        {
            "name": "ausername-novo2",
            "value": "EXMPL"
        },
       {
                "name": "ausername-novo3",
                "value": "EXMPL4"
        },
        {
                "name": "ausername-novo4",
                "value": "EXMPL4"
        }
    ],
    "nextPageToken": ""
}

But the command delete the key value map and then create only the last entries: kvms

{
    "keyValueEntries": [
        {
            "name": "ausername-novo3",
            "value": "EXMPL4"
        },
        {
            "name": "ausername-novo4",
            "value": "EXMPL4"
        }
    ],
    "nextPageToken": ""
}

my maven command is the next: mvn process-resources apigee-config:keyvaluemaps -Dapigee.config.options=update -Dapigee.bearer=$APIGEE_TOKEN

ssvaidyanathan commented 1 year ago

@eceledonio2296 - yes this is working as expected as there are no Apigee APIs to update the KVMs. So the plugin deletes the entries and creates them from the json file you pass. If you want to add more entries, you will need to add them to existing JSON file so that it updates all the entries per your json

The plugin uses the json file as the final state of your KVM. So if you have new entries to the KVM, that needs to be added to the json file so that it will recreate those entries.

eceledonio2296 commented 1 year ago

I understand but exist a reason for don't use the endpoint add entry instead?: curl --location 'https://apigee.googleapis.com/v1/organizations/{{org}}/environments/{{env}}/keyvaluemaps/{{keyvaluemapname}}/entries' \ --header 'Authorization: Bearer ' \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --data '{ "name": "name", "value": "value" }'

ssvaidyanathan commented 1 year ago

Yes - the plugin uses that API to add the entries and its part of the main the KVM goal. You are specifically asking to manage an entry to an existing KVM which does not exist today.