0aea10d23e
- Implement dagger.#FS support - Migrate `context.imports` to dagger.#FS - Backward compat: dagger.#FS can be passed in lieu of a dagger.#Artifact - For instance, an import (`dagger.#FS`) can be passed to the current `yarn.#Package` implementation Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
53 lines
994 B
Go
53 lines
994 B
Go
package plancontext
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
type ContextKey string
|
|
|
|
// Context holds the execution context for a plan.
|
|
//
|
|
// Usage:
|
|
// ctx := plancontext.New()
|
|
// id := ctx.Secrets.Register("mysecret")
|
|
// secret := ctx.Secrets.Get(id)
|
|
type Context struct {
|
|
Platform *platformContext
|
|
FS *fsContext
|
|
LocalDirs *localDirContext
|
|
Secrets *secretContext
|
|
Services *serviceContext
|
|
}
|
|
|
|
func New() *Context {
|
|
return &Context{
|
|
Platform: &platformContext{
|
|
platform: defaultPlatform,
|
|
},
|
|
FS: &fsContext{
|
|
store: make(map[ContextKey]*FS),
|
|
},
|
|
LocalDirs: &localDirContext{
|
|
store: make(map[ContextKey]*LocalDir),
|
|
},
|
|
Secrets: &secretContext{
|
|
store: make(map[ContextKey]*Secret),
|
|
},
|
|
Services: &serviceContext{
|
|
store: make(map[ContextKey]*Service),
|
|
},
|
|
}
|
|
}
|
|
|
|
func hashID(v interface{}) ContextKey {
|
|
data, err := json.Marshal(v)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
hash := sha256.Sum256(data)
|
|
return ContextKey(fmt.Sprintf("%x", hash))
|
|
}
|