PluginContext
Structure
Every time a plugin is called by the IDE (or a by another plugin), a PluginContext
is generated and passed throughout, providing access to the core functionality and data of Omniview. The context provides access to various aspects of the request, including the request options, authentication context, resource context, and plugin configuration.
The PluginContext
struct is defined as follows:
type PluginContext struct {
Context context.Context
RequestID string
RequesterID string
RequestOptions *RequestOptions
AuthContext *AuthContext
ResourceContext *ResourceContext
PluginConfig *PluginConfig
GlobalConfig *GlobalConfig
}
Key | Default | Description |
---|---|---|
Context | N/A | Standard context for the request, which can be used for cancellation and timeouts. |
RequestID | Random UUID | The unique identifier for the request. This can also be used as an idempotency token. |
RequesterID | CORE | The identifier of who made the request. This can either be the IDE core (labelled as CORE ) or the ID of the plugin that made the request. |
RequestOptions | N/A | The options that control the behavior of the request. |
AuthContext | N/A | The authorization context for the request. |
ResourceContext | N/A | The context of the resource being operated on. |
PluginConfig | N/A | The configuration of the plugin. |
GlobalConfig | N/A | The global configuration of the IDE. |
🌐 RequestOptions
Request options are used to control the behavior of the request. This includes the timeout, the number of retries, and the backoff interval.
type RequestOptions struct {
Timeout time.Duration
MaxRetries int
BackoffInterval time.Duration
}
Key | Default | Description |
---|---|---|
Timeout | 10s | Length of time that the plugin should wait for a response from the plugin. |
MaxRetries | 3 | The maximum number of times the plugin should retry the request in case of failure. |
BackoffInterval | 1.1s | The time to wait between retries. |
🔑 AuthContext
Stores information about the authorization context for the request to the backend, as well settings the user has configured for the specific authorization context instance. This also includes a data store that the client factories can inject into for passing arbitrary scoped data down the call stack.
Examples of auth contexts defined in the IDE include things such as:
- An AWS profile
- A Kubernetes context
- A GCP service account
sensitiveData
will be exposed to the user. Do not store sensitive data outside the sensitiveData
storetype AuthContext struct {
ID string
UID string
Name string
Description string
Labels map[string]string
ExpiryTime time.Duration
LastRefresh time.Time
Data map[string]interface{}
sensitiveData map[string]interface{}
}
Key | Default | Description |
---|---|---|
ID | N/A | Identifier of the authorization context. |
UID | Random UUID | Unique identifier of the authorization context, used by the IDE to track the instance. This is generated by the IDE and is not user-configurable. |
Name | Value of ID | Human-readable name of the authorization context. This is configured by the user. |
Description | N/A | User description of the authorization context. |
Labels | Empty Map | Arbitrary key-value pairs that either the user or plugin can use to store additional metadata about the authorization context. |
ExpiryTime | 24h | The time at which the authorization context will expire. This is used to determine when the context should be refreshed, and should be set by the client factory. |
LastRefresh | N/A | The last time this authorization context was refreshed. |
IsAuthed
Check if the request is authenticated.
func (c *AuthContext) IsAuthed() bool
GetData
Get non-sensitive data attached to the auth context by the client factory
func (c *AuthContext) GetData() map[string]interface{}
SetData
Set non-sensitive data on the context. This will overwrite any existing data.
func (c *AuthContext) SetData(data map[string]interface{})
GetDataKey
Get an item from the data store by key
func (c *AuthContext) GetDataKey(key string) (interface{}, bool)
SetDataKey
Set an item in the data store by key.
func (c *AuthContext) SetDataKey(key string, value interface{})
GetSensitiveData
Get sensitive data attached to the auth context by the client factory
func (c *AuthContext) GetSensitiveData() map[string]interface{}
SetSensitiveData
Set sensitive data on the context. This will overwrite any existing data.
func (c *AuthContext) SetSensitiveData(data map[string]interface{})
SetSensitiveDataKey
Set an item in the sensitive data store by key.
func (c *AuthContext) SetSensitiveDataKey(key string, value interface{})
GetSensitiveDataKey
Get an item from the sensitive data store by key
func (c *AuthContext) GetSensitiveDataKey(key string) (interface{}, bool)
📦 ResourceContext
The context of the resource being operated on. This is only available when the plugin is called from a resource context.
type ResourceContext struct {
ID string
Metadata ResourceMetadata
Data map[string]string
}
Key | Default | Description |
---|---|---|
ID | N/A | Identifier of the resource. |
Metadata | N/A | Metadata about the resource. See the Resource Plugin documentation for more information. |
Labels | Empty Map | Arbitrary key-value store that either the user or plugin can use to store additional metadata about the resource. |
🛠 PluginConfig
Configuration of the plugin itself by the user, as defined in the settings options in the plugin setup function.
The available keys here are defined when you setup the plugin. For example, if we were to initialize a plugin with the following PluginOpts
:
package main
import (
"github.com/omniview/kubernetes/pkg/plugin/resource"
"github.com/omniviewdev/plugin/pkg/resource/types"
"github.com/omniviewdev/plugin/pkg/sdk"
sdksettings "github.com/omniviewdev/plugin/pkg/settings"
)
func main() {
plugin := sdk.NewPlugin(sdk.PluginOpts{
Settings: []interface{}{
sdksettings.Multitext{
ID: "kubeconfigs",
Name: "Kubeconfigs",
Description: "A list of available Kubeconfigs to use",
Default: []string{"~/.kube/config"},
},
sdksettings.Text{
ID: "shell",
Name: "Shell",
Description: "The default shell to use for running commands and authenticating with Kubernetes clusters.",
Default: "/bin/zsh",
},
},
})
// ...
// ...
We can access the PluginConfig
in the plugin context with the following keys:
func SomeFunction(c *sdk.PluginContext) {
kubeconfigs, _ := c.PluginConfig.Get[[]string]("kubeconfigs")
shell, _ := c.PluginConfig.Get[string]("shell")
}
Get
Get a global configuration value by key
func (c *PluginContext) Get[K comparable](key string) (K, bool)
Set
Set a global configuration value by key
func (c *PluginContext) Set(key string, value interface{})
🌍 GlobalConfig
Configuration of the IDE itself by the user, as defined in the settings options in the IDE setup function. The most common settings found here can be accessed via the exported symbols:
globals.SHELL
globals.EDITOR
globals.THEME
globals.LANGUAGE
Detailed documentation on the global configuration settings can be found here.
Get
Get a global configuration value by key
func (c *GlobalConfig) Get[K comparable](key string) (K, bool)
Set
Set a global configuration value by key
func (c *GlobalConfig) Set(key string, value interface{})
Last updated 12 Mar 2024, 22:16 -0500 .