-
Notifications
You must be signed in to change notification settings - Fork 40
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
Expose Kong capabilities through a function in the client #48
Conversation
My initial thoughts:
|
|
This doesn't quite get away from the breaking change, since client users would still need to remove any existing workspace path they're putting in the base URL and call
One of those will work if the base URL is a Kong admin API. If we also need to know the workspace we're in, we can split the base URL path and use the last path segment.
I should have been a bit clearer on this: mtls-auth is the only credential type that's like this due to some weird history in its development, so it needs a unique capability value. We shouldn't see any other such oddball credentials in the future; the rest can share a single capabilities value, and should for simplicity. |
If we use the last path segment, a HEAD /workspaces/last_segment which returns a 200 should confirm the existence of the last_segment as a workspace? Any idea for the naming of the field for tag support of the credentials which aren't mtlsauth ? |
No strong opinion really. The original
is fine by me.
Looks like it, though the endpoint is a bit odd. If you're sending a request to a workspace other than the root/default workspace, those requests can see the workspace you're in, but not others:
The root can see everything, so |
@hbagdi , this seems to be the most DRY way to expose the Version and the calculed tag supports as this is repeated between projects (deck and kic to start with). This way the client doesn't need to know the logic but just use boolean properties. |
The versioning part could make sense. The tag part is going to go away in KIC and decK as they will drop support for Kong 1.x so we shouldn't be putting that in. |
kong/utils.go
Outdated
func getKong(root map[string]interface{}) (*Kong, error) { | ||
version := root["version"].(string) | ||
configuration := root["configuration"].(map[string]interface{}) | ||
semVer, err := cleanSemVer(version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not do this here since it is a lossy conversion.
The user of the library can interpret the version if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about providing both the cleaned semver and the original string with all our extra content? Elsewhere we're likely going to be performing semver comparisons for the most part, and I think it makes sense to have a standard conversion rather than each user implementing their own cleanSemVer()
variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better approach would be:
info, err := client.Root() // most powerful
version := utils.versionFromInfo(info) // package-level global function to fetch version from the info map
semanticVersion := utils.ParseSemanticVersion(version) // package-level function
This makes the code cleaner and keeps each function responsible for one and only one thing.
kong/client.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
return root, nil | ||
return getKong(root) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this pattern is good.
We should instead give a utility function to the user which takes the output /
or /kong
and answers the questions around support for tags, enterprise, etc.
The kong
packages is intended for talking to the API. Interpreting these specifics should not be part of this package.
If I summarize, there is nothing left to take from that attempt. The PR can be closed? |
@mmorel-35 Apologies for mixed reviews from our end on this one.
Again, apologies for the delay and confusion here. Let us know if you have questions. |
Codecov Report
@@ Coverage Diff @@
## main #48 +/- ##
=======================================
Coverage ? 39.64%
=======================================
Files ? 40
Lines ? 2525
Branches ? 0
=======================================
Hits ? 1001
Misses ? 1277
Partials ? 247
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
@hbagdi , is this what you want ? |
Expose versionFromInfo Lint
@mmorel-35 We are still interested in adding |
Co-authored-by: Harry <harrybagdi@gmail.com>
Co-authored-by: Harry <harrybagdi@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this!
Creates a function to expose kong's informations like it's version, if it's an enterprise edition , which database is used.
There is also a Credentials attribute to inform if they support tags which is not the case under 1.4.0 version.
As this is calculated here, deck won't require semver as a direct dependency to calculate it himself.
I also made the kong client aware of the workspace. This allows the Root to be / by default and /kong when a workspace is used.
I reused getSemVerVer of KIC as a version cleaner