-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
context: various cleanups and improvements #3790
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #3790 +/- ##
==========================================
- Coverage 59.29% 59.22% -0.07%
==========================================
Files 288 288
Lines 24641 24616 -25
==========================================
- Hits 14610 14578 -32
- Misses 9161 9163 +2
- Partials 870 875 +5 |
This comment was marked as outdated.
This comment was marked as outdated.
a5899ff
to
fa71c53
Compare
fc65436
to
9d98412
Compare
return filepath.Join(s.root, string(contextID), name) | ||
} | ||
|
||
func (s *tlsStore) filePath(contextID contextdir, endpointName, filename string) string { |
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'm slightly hesitant on removing these. IMO there's some value in having these helper functions due to the signature prompting you on what you should supply to obtain the final directory.
If I would be writing a new code and need to obtain the file path, then I would have to search for other code that does this to know how to construct the whole path with filepath.Join
.
With those conversion functions I just need to know that there is this function and then the arguments to the functions will guide me on what I need to provide. For example if I miss the endpointName
then the compiler will yell at me, whereas if I forget it in filepath.Join
then I won't know that at the compile time.
WDYT?
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 me have a look. My main reasons were that;
- Each of them would be reconstructing the parent directory, so I initially wanted to re-use
contextDir()
andendpointDir()
- The
fileDir()
one felt really redundant - The
endpointDir()
as used inlistContextData()
was really silly, as we already were traversing the directory, and then were re-constructing the name … to get the name of the directory we were in.
Perhaps I can bring back endpointDir()
, and only remove filePath()
; let me see how that looks.
There were some other changes I was considering;
- As the
contextDir
depends on the context store, I want to look at passing that directory in (effectively, calculating that path should be something done by the context store) - Given that for the TLS-store we only want
ca.pem
,cert.pem
andkey.pem
, perhaps add accessors for those instead of trying to keep it “too generic”
A lot of the code was written to be really “generic”, but that’s not how it’s used, and perhaps we should rewrite more code to be specific to how it’s actually used.
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.
Makes sense to me, thanks for the explanation! 👍
…d of ID This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
Looks like the intent here is to get the path of a subdirectory. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This allows callers to just pass the name, and handle the conversion to ID and path internally. This also fixes a test which incorrectly used "names" as pseudo-IDs. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This test was depending on the fact that contextDir's are a string, and for the test is was using the context _name_ as a pseudo-ID. This patch updates the test to be more explicit where ID's and where names are used. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
This allows callers to just pass the name, and handle the conversion to ID and path internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
9d98412
to
8909236
Compare
removing the extra abstraction, and simplify use of contextDir() Signed-off-by: Sebastiaan van Stijn <[email protected]>
The package defined various special errors; these errors existed for two reasons; - being able to distinguish "not found" errors from other errors (as "not found" errors can be ignored in various cases). - to be able to update the context _name_ in the error message after the error was created. This was needed in cases where the name was not available at the location where the error was produced (e.g. only the "id" was present), and the helpers to detect "not found" errors did not support wrapped errors (so wrapping the error with a "name" could break logic); a `setContextName` interface and corresponding `patchErrContextName()` utility was created for this (which was a "creative", but not very standard approach). This patch: - Removes the special error-types, replacing them with errdefs definitions (which is a more common approach in our code-base to detect error types / classes). - Removes the internal utilities for error-handling, and deprecates the exported utilities (to allow external consumers to adjust their code). - Some errors have been enriched with detailed information (which may be useful for debugging / problem solving). - Note that in some cases, `patchErrContextName()` was called, but the code producing the error would never return a `setContextName` error, so would never update the error message. Signed-off-by: Sebastiaan van Stijn <[email protected]>
Go conventions are for interfaces to be defined on the receiver side, and for producers to return concrete types. This patch changes the constructor to return a concrete type. Signed-off-by: Sebastiaan van Stijn <[email protected]>
There's no reason to stop listing contexts if a context does not exist while iterating over the directories, Signed-off-by: Sebastiaan van Stijn <[email protected]>
…ta() The existing `remove()` was unused, and using that as name makes it more consistent with the metadata-store. Also renaming `removeAllEndpointData` to just `removeEndpoint`, as it's part of the TLS-store, which should already make it clear it's about (TLS)data. Signed-off-by: Sebastiaan van Stijn <[email protected]>
8909236
to
cd7c493
Compare
@vvoland I updated, and restored the |
cli/context/store: metadataStore.get(), .remove(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally.
cli/context/store: listRecursivelyMetadataDirs(): use filepath.Join()
Looks like the intent here is to get the path of a subdirectory.
cli/context/store: removeAllContextData(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally. This also fixes a test which incorrectly used "names" as
pseudo-IDs.
cli/context/store: TestTlsCreateUpdateGetRemove(): use correct ID
This test was depending on the fact that contextDir's are a string,
and for the test is was using the context name as a pseudo-ID.
This patch updates the test to be more explicit where ID's and where
names are used.
cli/context/store: removeAllEndpointData(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally.
cli/context/store: createOrUpdate(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally.
cli/context/store: getData(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally.
cli/context/store: remove(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally.
cli/context/store: listContextData(): accept name instead of ID
This allows callers to just pass the name, and handle the conversion to ID and
path internally.
cli/context/store: remove endpointDir(), filePath()
These were just to produce the full path of subdirectories within the context
directory; removing the extra abstraction.
cli/context/store: simplify error handling, and make it more idiomatic
The package defined various special errors; these errors existed for two reasons;
errors can be ignored in various cases).
was created. This was needed in cases where the name was not available at the
location where the error was produced (e.g. only the "id" was present), and
the helpers to detect "not found" errors did not support wrapped errors (so
wrapping the error with a "name" could break logic); a
setContextName
interfaceand corresponding
patchErrContextName()
utility was created for this (whichwas a "creative", but not very standard approach).
This patch:
is a more common approach in our code-base to detect error types / classes).
utilities (to allow external consumers to adjust their code).
for debugging / problem solving).
patchErrContextName()
was called, but the codeproducing the error would never return a
setContextName
error, so wouldnever update the error message.
cli/context/store: New(): return concrete type
Go conventions are for interfaces to be defined on the receiver side,
and for producers to return concrete types. This patch changes the
constructor to return a concrete type.
cli/context/store: List(): don't interrupt listing for not-found errors
There's no reason to stop listing contexts if a context does not exist
while iterating over the directories,