Migrate dagger.#Secret and dagger.#Stream to new format

- Refactored to keep every transformation of built-in types (e.g. FS,
  Secret, etc) to/from CUE in the same place (plancontext)
- dagger.#Service and dagger.#Secret are now following the new FS-like format
  (e.g. `_service: id: string`)
- Backward compatibility
- dagger.#Stream is now an alias for dagger.#Service

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-11-30 17:51:28 -08:00
parent 5ab3c47dac
commit 5b7b1cab79
27 changed files with 284 additions and 217 deletions

View File

@@ -2,18 +2,10 @@ 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
@@ -28,25 +20,26 @@ func New() *Context {
platform: defaultPlatform,
},
FS: &fsContext{
store: make(map[ContextKey]*FS),
store: make(map[string]*FS),
},
LocalDirs: &localDirContext{
store: make(map[ContextKey]*LocalDir),
store: []string{},
},
Secrets: &secretContext{
store: make(map[ContextKey]*Secret),
store: make(map[string]*Secret),
},
Services: &serviceContext{
store: make(map[ContextKey]*Service),
store: make(map[string]*Service),
},
}
}
func hashID(v interface{}) ContextKey {
data, err := json.Marshal(v)
if err != nil {
panic(err)
func hashID(values ...string) string {
hash := sha256.New()
for _, v := range values {
if _, err := hash.Write([]byte(v)); err != nil {
panic(err)
}
}
hash := sha256.Sum256(data)
return ContextKey(fmt.Sprintf("%x", hash))
return fmt.Sprintf("%x", hash)
}