Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds support for kvm entries upsert #488 #489

Merged
merged 4 commits into from
Jun 27, 2024
Merged

feat: adds support for kvm entries upsert #488 #489

merged 4 commits into from
Jun 27, 2024

Conversation

srinandan
Copy link
Collaborator

No description provided.

@srinandan srinandan linked an issue Jun 24, 2024 that may be closed by this pull request
@srinandan srinandan added the enhancement New feature or request label Jun 24, 2024
Copy link
Collaborator

@kurtkanaskie kurtkanaskie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating a KVM with upserts for plain entries that exist works, however, the output from the command shows 2 sets of values, apparently the values after deleting the "basepath" that has changed.

$ gorun kvms entries import --org=apigeex-mint-kurt --env=dev --map=issue488 --file=./testing-issue-488/issue488-update.json
{
	"name": "key1",
	"value": "value1"
}

{
	"name": "pathsuffix",
	"value": "/is/great"
}

{
	"name": "pathsuffix",
	"value": "/is/great"
}

{
	"name": "basepath",
	"value": "/christopher/duncan"
}

{
	"name": "key1",
	"value": "value1"
}
$ apigeeclix kvms entries list --org=apigeex-mint-kurt --env=dev --map=issue488
{
	"keyValueEntries": [
		{
			"name": "basepath",
			"value": "/christopher/duncan"
		},
		{
			"name": "key1",
			"value": "value1"
		},
		{
			"name": "pathsuffix",
			"value": "/is/great"
		}
	],
	"nextPageToken": ""
}

Import of KVM entries with JSON values fails on the entry with JSON value.
This works if I use import on the KVM, but not on entries

$ gorun kvms entries import --org=$ORG --env=dev --map=issue488-json --file=./testing-issue-488/issue488-json.json 
{
  "error": {
    "code": 404,
    "message": "KeyValueMap(Scope=KeyValueMapScope {ScopeType ='ENVIRONMENTS', Organization = 'apigeex-mint-kurt', Environment = 'dev'},Map=issue488-json) Entry=json1 does not exist",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.PreconditionFailure",
        "violations": [
          {
            "type": "keyvaluemap.service.keyvaluemap_entry_doesnt_exist",
            "subject": "[2002:add:ddd7:0:b0:3de:d529:9714]:4004:blcbt2-20020a0566939d8200b00078702e4343:9801:504140:53193567",
            "description": "KeyValueMap(Scope=KeyValueMapScope {ScopeType ='ENVIRONMENTS', Organization = 'apigeex-mint-kurt', Environment = 'dev'},Map=issue488-json) Entry=json1 does not exist"
          }
        ]
      },
      {
        "@type": "type.googleapis.com/google.rpc.RequestInfo",
        "requestId": "7183663024520603695"
      }
    ]
  }
}

{
  "error": {
    "code": 404,
    "message": "KeyValueMap(Scope=KeyValueMapScope {ScopeType ='ENVIRONMENTS', Organization = 'apigeex-mint-kurt', Environment = 'dev'},Map=issue488-json) Entry=pathsuffix does not exist",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.PreconditionFailure",
        "violations": [
          {
            "type": "keyvaluemap.service.keyvaluemap_entry_doesnt_exist",
            "subject": "[2002:ab0:ea91:0:b0:3db:18c2:1e66]:4001:bibik8-20020a056f19258800b003abbdcabb26:9801:967918:81993994",
            "description": "KeyValueMap(Scope=KeyValueMapScope {ScopeType ='ENVIRONMENTS', Organization = 'apigeex-mint-kurt', Environment = 'dev'},Map=issue488-json) Entry=pathsuffix does not exist"
          }
        ]
      },
      {
        "@type": "type.googleapis.com/google.rpc.RequestInfo",
        "requestId": "2143025881040377933"
      }
    ]
  }
}

{
  "error": {
    "code": 404,
    "message": "KeyValueMap(Scope=KeyValueMapScope {ScopeType ='ENVIRONMENTS', Organization = 'apigeex-mint-kurt', Environment = 'dev'},Map=issue488-json) Entry=basepath does not exist",
    "status": "NOT_FOUND",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.PreconditionFailure",
        "violations": [
          {
            "type": "keyvaluemap.service.keyvaluemap_entry_doesnt_exist",
            "subject": "[2002:ab0:f19a:0:b0:3de:d902:c746]:4004:bibmk11-20020a056f19390b00b00395eb164452:9801:659791:18930648",
            "description": "KeyValueMap(Scope=KeyValueMapScope {ScopeType ='ENVIRONMENTS', Organization = 'apigeex-mint-kurt', Environment = 'dev'},Map=issue488-json) Entry=basepath does not exist"
          }
        ]
      },
      {
        "@type": "type.googleapis.com/google.rpc.RequestInfo",
        "requestId": "5345608810271077102"
      }
    ]
  }
}

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Expected , or } after key:value pair.\n:\"json1\",\"value\":\"{\"message\":\"hello\"}\"}\n                    ^",
    "status": "INVALID_ARGUMENT"
  }
}

{
	"name": "pathsuffix",
	"value": "/is/great"
}

{
	"name": "basepath",
	"value": "/christopher/duncan"
}
$ gorun kvms entries list --org=$ORG --env=dev --map=issue488-json
{
	"keyValueEntries": [
		{
			"name": "basepath",
			"value": "/christopher/duncan"
		},
		{
			"name": "pathsuffix",
			"value": "/is/great"
		}
	],
	"nextPageToken": ""
}

@kurtkanaskie
Copy link
Collaborator

Removing an entry from the entries does not remove it, but I think that's as expected.

@kurtkanaskie
Copy link
Collaborator

Test for non-json entries

gorun kvms delete --org=$ORG --env=dev --name=issue488
gorun kvms create --org=$ORG --env=dev --name=issue488
gorun kvms entries import --org=apigeex-mint-kurt --env=dev --map=issue488 --file=./testing-issue-488/issue488.json
gorun kvms entries import --org=apigeex-mint-kurt --env=dev --map=issue488 --file=./testing-issue-488/issue488-update.json
gorun kvms entries list --org=apigeex-mint-kurt --env=dev --map=issue488

test issue488.json file

{
	"keyValueEntries": [
		{
			"name": "basepath",
			"value": "/chris/duncan"
		},
		{
			"name": "key1",
			"value": "value1"
		},
		{
			"name": "pathsuffix",
			"value": "/is/great"
		}
	],
	"nextPageToken": ""
}

Test issue488-update.json file

{
	"keyValueEntries": [
		{
			"name": "basepath",
			"value": "/christopher/duncan"
		},
		{
			"name": "pathsuffix",
			"value": "/is/great"
		}
	],
	"nextPageToken": ""
}

@kurtkanaskie
Copy link
Collaborator

Test for issue4880json

gorun kvms delete --org=$ORG --env=dev --name=issue488-json
gorun kvms create --org=$ORG --env=dev --name=issue488-json
gorun kvms entries import --org=$ORG --env=dev --map=issue488-json --file=./testing-issue-488/issue488-json.json 
gorun kvms entries list --org=apigeex-mint-kurt --env=dev --map=issue488

gorun kvms entries import --org=$ORG --env=dev --map=issue488-json --file=./testing-issue-488/issue488-json-update.json 
gorun kvms entries list --org=apigeex-mint-kurt --env=dev --map=issue488

test issue488-json.json file

{
	"keyValueEntries": [
		{
			"name": "json1",
			"value": "{\"message\":\"hello\"}"
		},
		{
			"name": "basepath",
			"value": "/chris/duncan"
		},
		{
			"name": "pathsuffix",
			"value": "/is/great"
		}
	],
	"nextPageToken": ""
}

test issue488-json-update.json file

{
	"keyValueEntries": [
		{
			"name": "json1",
			"value": "{\"message\":\"hello\"}"
		},
		{
			"name": "basepath",
			"value": "/christopher/duncan"
		},
		{
			"name": "pathsuffix",
			"value": "/is/great"
		}
	],
	"nextPageToken": ""
}

@srinandan srinandan requested a review from kurtkanaskie June 25, 2024 20:08
@kurtkanaskie
Copy link
Collaborator

Everything works, but wondering about outputs:
Import with new entries I see 404s for new entries that get created - OK

Import with changed entries I don't see anything, so I don't really know if anything happened.
Would be nice if entries that changed were output so I know something changed.

Copy link
Collaborator

@kurtkanaskie kurtkanaskie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@srinandan srinandan merged commit 6d7d437 into main Jun 27, 2024
4 checks passed
@srinandan srinandan deleted the issue488 branch June 27, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manage KVM as files and support update
2 participants