2023-03-02 13:05:24 +01:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-06-25 19:45:43 +02:00
|
|
|
"forge.cadoles.com/Cadoles/emissary/pkg/client"
|
2023-03-02 13:05:24 +01:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextKey string
|
|
|
|
|
|
|
|
const (
|
2024-02-29 17:17:21 +01:00
|
|
|
contextKeyClient contextKey = "client"
|
|
|
|
contextKeyThumbprint contextKey = "thumbprint"
|
2023-03-02 13:05:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func withClient(ctx context.Context, client *client.Client) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyClient, client)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Client(ctx context.Context) *client.Client {
|
|
|
|
client, ok := ctx.Value(contextKeyClient).(*client.Client)
|
|
|
|
if !ok {
|
|
|
|
panic(errors.New("could not retrieve client from context"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return client
|
|
|
|
}
|
2024-02-29 17:17:21 +01:00
|
|
|
|
|
|
|
func withThumbprint(ctx context.Context, thumbprint string) context.Context {
|
|
|
|
return context.WithValue(ctx, contextKeyThumbprint, thumbprint)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Thumbprint(ctx context.Context) string {
|
|
|
|
thumbprint, ok := ctx.Value(contextKeyThumbprint).(string)
|
|
|
|
if !ok {
|
|
|
|
panic(errors.New("could not retrieve thumbprint from context"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return thumbprint
|
|
|
|
}
|