-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vaultfs): Add extension methods WithClient and WithConfig (#881)
Signed-off-by: Dave Henderson <[email protected]>
- Loading branch information
1 parent
915267e
commit 8c0f527
Showing
3 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package vaultfs | ||
|
||
import ( | ||
"io/fs" | ||
|
||
"github.com/hashicorp/vault/api" | ||
) | ||
|
||
type withClienter interface { | ||
WithClient(client *api.Client) fs.FS | ||
} | ||
|
||
// WithClient injects a Vault client into the filesystem fs, if the | ||
// filesystem supports it (i.e. is a [FS], or some other type with a | ||
// WithClient method). The current client will be replaced. It is the | ||
// caller's responsibility to ensure the client is configured correctly. | ||
func WithClient(client *api.Client, fsys fs.FS) fs.FS { | ||
if cfsys, ok := fsys.(withClienter); ok { | ||
return cfsys.WithClient(client) | ||
} | ||
|
||
return fsys | ||
} | ||
|
||
type withConfiger interface { | ||
WithConfig(config *api.Config) fs.FS | ||
} | ||
|
||
// WithConfig injects a Vault configuration into the filesystem fs, if the | ||
// filesystem supports it (i.e. is a [FS], or some other type with a | ||
// WithConfig method). The current client will be replaced. If the | ||
// configuration is invalid, an error will be logged and nil will be returned. | ||
func WithConfig(config *api.Config, fsys fs.FS) fs.FS { | ||
if cfsys, ok := fsys.(withConfiger); ok { | ||
return cfsys.WithConfig(config) | ||
} | ||
|
||
return fsys | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters