Documentation
¶
Overview ¶
Package lucictx implements a Go client for the protocol defined here:
https://github.com/luci/luci-py/blob/master/client/LUCI_CONTEXT.md
It differs from the python client in a couple ways:
- The initial LUCI_CONTEXT value is captured once at application start, and the environment variable is REMOVED.
- Writes are cached into the golang context.Context, not a global variable.
- The LUCI_CONTEXT environment variable is not changed automatically when using the Set function. To pass the new context on to a child process, you must use the Export function to dump the current context state to disk.
Index ¶
- Constants
- func Get(ctx context.Context, section string, out interface{}) error
- func Lookup(ctx context.Context, section string, out interface{}) (bool, error)
- func Set(ctx context.Context, section string, in interface{}) (context.Context, error)
- func SetLocalAuth(ctx context.Context, la *LocalAuth) context.Context
- func SetSwarming(ctx context.Context, swarm *Swarming) context.Context
- type Exported
- type LocalAuth
- type LocalAuthAccount
- type Swarming
Constants ¶
const EnvKey = "LUCI_CONTEXT"
EnvKey is the environment variable key for the LUCI_CONTEXT file.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get retrieves the current section from the current LUCI_CONTEXT, and deserializes it into out. Out may be any target for json.Unmarshal. If the section exists, it deserializes it into the provided out object. If not, then out is unmodified.
func Lookup ¶
Lookup retrieves the current section from the current LUCI_CONTEXT, and deserializes it into out. Out may be any target for json.Unmarshal. It returns a deserialization error (if any), and a boolean indicating if the section was actually found.
func Set ¶
Set writes the json serialization of `in` as the given section into the LUCI_CONTEXT, returning the new ctx object containing it. This ctx can be passed to Export to serialize it to disk.
If in is nil, it will clear that section of the LUCI_CONTEXT.
The returned context is always safe to use, even if this returns an error. This only returns an error if `in` cannot be marshalled to a JSON Object.
func SetLocalAuth ¶
SetLocalAuth Sets the LocalAuth in the LUCI_CONTEXT.
Types ¶
type Exported ¶
type Exported interface { io.Closer // SetInCmd sets/replaces the LUCI_CONTEXT environment variable in an // exec.Cmd. SetInCmd(c *exec.Cmd) // SetInEnviron sets/replaces the LUCI_CONTEXT in an environ.Env object. SetInEnviron(env environ.Env) }
Exported represents an exported on-disk LUCI_CONTEXT file. It lives for exactly the life of the callback function in Export.
func Export ¶
Export takes the current LUCI_CONTEXT information from ctx, writes it to a file and returns a wrapping Exported object. This exported value must then be installed into the environment of any subcommands (see the methods on Exported).
It is required that the caller of this function invoke Close() on the returned Exported object, or they will leak temporary files.
'dir', if not "", specifies a directory to put the exported file in. If empty, os.TempDir() will be used.
type LocalAuth ¶
type LocalAuth struct { // RPCPort and Secret define how to connect to the local auth server. RPCPort uint32 `json:"rpc_port"` Secret []byte `json:"secret"` // Accounts and DefaultAccountID defines what access tokens are available. Accounts []LocalAuthAccount `json:"accounts"` DefaultAccountID string `json:"default_account_id"` }
LocalAuth is a struct that may be used with the "local_auth" section of LUCI_CONTEXT.
func GetLocalAuth ¶
GetLocalAuth calls Lookup and returns the current LocalAuth from LUCI_CONTEXT if it was present. If no LocalAuth is in the context, this returns nil.
type LocalAuthAccount ¶
type LocalAuthAccount struct { // ID is logical identifier of the account, e.g. "system" or "task". ID string `json:"id"` }
LocalAuthAccount contains information about a service account available through a local auth server.