mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
lint: apply x/tools/modernize fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
e19c729d3e
commit
d5d3d3d502
@ -486,10 +486,8 @@ func (c Config) loadLinks(name string, t *Target, m map[string]*Target, o map[st
|
|||||||
if target == name {
|
if target == name {
|
||||||
return errors.Errorf("target %s cannot link to itself", target)
|
return errors.Errorf("target %s cannot link to itself", target)
|
||||||
}
|
}
|
||||||
for _, v := range visited {
|
if slices.Contains(visited, target) {
|
||||||
if v == target {
|
return errors.Errorf("infinite loop from %s to %s", name, target)
|
||||||
return errors.Errorf("infinite loop from %s to %s", name, target)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
t2, ok := m[target]
|
t2, ok := m[target]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -315,7 +315,7 @@ type (
|
|||||||
stringArray []string
|
stringArray []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func (sa *stringArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (sa *stringArray) UnmarshalYAML(unmarshal func(any) error) error {
|
||||||
var multi []string
|
var multi []string
|
||||||
err := unmarshal(&multi)
|
err := unmarshal(&multi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -332,7 +332,7 @@ func (sa *stringArray) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
|
|
||||||
// composeExtTarget converts Compose build extension x-bake to bake Target
|
// composeExtTarget converts Compose build extension x-bake to bake Target
|
||||||
// https://github.com/compose-spec/compose-spec/blob/master/spec.md#extension
|
// https://github.com/compose-spec/compose-spec/blob/master/spec.md#extension
|
||||||
func (t *Target) composeExtTarget(exts map[string]interface{}) error {
|
func (t *Target) composeExtTarget(exts map[string]any) error {
|
||||||
var xb xbake
|
var xb xbake
|
||||||
|
|
||||||
ext, ok := exts["x-bake"]
|
ext, ok := exts["x-bake"]
|
||||||
|
@ -306,7 +306,7 @@ func (c EntitlementConf) Prompt(ctx context.Context, isRemote bool, out io.Write
|
|||||||
fmt.Fprintf(out, "\nPass %q to grant requested privileges.\n", strings.Join(slices.Concat(flags, flagsFS), " "))
|
fmt.Fprintf(out, "\nPass %q to grant requested privileges.\n", strings.Join(slices.Concat(flags, flagsFS), " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
args := append([]string(nil), os.Args...)
|
args := slices.Clone(os.Args)
|
||||||
if v, ok := os.LookupEnv("DOCKER_CLI_PLUGIN_ORIGINAL_CLI_COMMAND"); ok && v != "" {
|
if v, ok := os.LookupEnv("DOCKER_CLI_PLUGIN_ORIGINAL_CLI_COMMAND"); ok && v != "" {
|
||||||
args[0] = v
|
args[0] = v
|
||||||
}
|
}
|
||||||
|
@ -1645,7 +1645,7 @@ func TestHCLIndexOfFunc(t *testing.T) {
|
|||||||
require.Empty(t, c.Targets[1].Tags[1])
|
require.Empty(t, c.Targets[1].Tags[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
func ptrstr(s interface{}) *string {
|
func ptrstr(s any) *string {
|
||||||
var n *string
|
var n *string
|
||||||
if reflect.ValueOf(s).Kind() == reflect.String {
|
if reflect.ValueOf(s).Kind() == reflect.String {
|
||||||
ss := s.(string)
|
ss := s.(string)
|
||||||
|
@ -15,11 +15,11 @@ import (
|
|||||||
|
|
||||||
// DecodeOptions allows customizing sections of the decoding process.
|
// DecodeOptions allows customizing sections of the decoding process.
|
||||||
type DecodeOptions struct {
|
type DecodeOptions struct {
|
||||||
ImpliedType func(gv interface{}) (cty.Type, error)
|
ImpliedType func(gv any) (cty.Type, error)
|
||||||
Convert func(in cty.Value, want cty.Type) (cty.Value, error)
|
Convert func(in cty.Value, want cty.Type) (cty.Value, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o DecodeOptions) DecodeBody(body hcl.Body, ctx *hcl.EvalContext, val interface{}) hcl.Diagnostics {
|
func (o DecodeOptions) DecodeBody(body hcl.Body, ctx *hcl.EvalContext, val any) hcl.Diagnostics {
|
||||||
o = o.withDefaults()
|
o = o.withDefaults()
|
||||||
|
|
||||||
rv := reflect.ValueOf(val)
|
rv := reflect.ValueOf(val)
|
||||||
@ -46,7 +46,7 @@ func (o DecodeOptions) DecodeBody(body hcl.Body, ctx *hcl.EvalContext, val inter
|
|||||||
// are returned then the given value may have been partially-populated but
|
// are returned then the given value may have been partially-populated but
|
||||||
// may still be accessed by a careful caller for static analysis and editor
|
// may still be accessed by a careful caller for static analysis and editor
|
||||||
// integration use-cases.
|
// integration use-cases.
|
||||||
func DecodeBody(body hcl.Body, ctx *hcl.EvalContext, val interface{}) hcl.Diagnostics {
|
func DecodeBody(body hcl.Body, ctx *hcl.EvalContext, val any) hcl.Diagnostics {
|
||||||
return DecodeOptions{}.DecodeBody(body, ctx, val)
|
return DecodeOptions{}.DecodeBody(body, ctx, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ func (o DecodeOptions) decodeBlockToValue(block *hcl.Block, ctx *hcl.EvalContext
|
|||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o DecodeOptions) DecodeExpression(expr hcl.Expression, ctx *hcl.EvalContext, val interface{}) hcl.Diagnostics {
|
func (o DecodeOptions) DecodeExpression(expr hcl.Expression, ctx *hcl.EvalContext, val any) hcl.Diagnostics {
|
||||||
o = o.withDefaults()
|
o = o.withDefaults()
|
||||||
|
|
||||||
srcVal, diags := expr.Value(ctx)
|
srcVal, diags := expr.Value(ctx)
|
||||||
@ -332,7 +332,7 @@ func (o DecodeOptions) DecodeExpression(expr hcl.Expression, ctx *hcl.EvalContex
|
|||||||
// are returned then the given value may have been partially-populated but
|
// are returned then the given value may have been partially-populated but
|
||||||
// may still be accessed by a careful caller for static analysis and editor
|
// may still be accessed by a careful caller for static analysis and editor
|
||||||
// integration use-cases.
|
// integration use-cases.
|
||||||
func DecodeExpression(expr hcl.Expression, ctx *hcl.EvalContext, val interface{}) hcl.Diagnostics {
|
func DecodeExpression(expr hcl.Expression, ctx *hcl.EvalContext, val any) hcl.Diagnostics {
|
||||||
return DecodeOptions{}.DecodeExpression(expr, ctx, val)
|
return DecodeOptions{}.DecodeExpression(expr, ctx, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDecodeBody(t *testing.T) {
|
func TestDecodeBody(t *testing.T) {
|
||||||
deepEquals := func(other interface{}) func(v interface{}) bool {
|
deepEquals := func(other any) func(v any) bool {
|
||||||
return func(v interface{}) bool {
|
return func(v any) bool {
|
||||||
return reflect.DeepEqual(v, other)
|
return reflect.DeepEqual(v, other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,19 +45,19 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Body map[string]interface{}
|
Body map[string]any
|
||||||
Target func() interface{}
|
Target func() any
|
||||||
Check func(v interface{}) bool
|
Check func(v any) bool
|
||||||
DiagCount int
|
DiagCount int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]any{},
|
||||||
makeInstantiateType(struct{}{}),
|
makeInstantiateType(struct{}{}),
|
||||||
deepEquals(struct{}{}),
|
deepEquals(struct{}{}),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]any{},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Name string `hcl:"name"`
|
Name string `hcl:"name"`
|
||||||
}{}),
|
}{}),
|
||||||
@ -67,7 +67,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
1, // name is required
|
1, // name is required
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]any{},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Name *string `hcl:"name"`
|
Name *string `hcl:"name"`
|
||||||
}{}),
|
}{}),
|
||||||
@ -77,7 +77,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
}, // name nil
|
}, // name nil
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]any{},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Name string `hcl:"name,optional"`
|
Name string `hcl:"name,optional"`
|
||||||
}{}),
|
}{}),
|
||||||
@ -87,9 +87,9 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
}, // name optional
|
}, // name optional
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]any{},
|
||||||
makeInstantiateType(withNameExpression{}),
|
makeInstantiateType(withNameExpression{}),
|
||||||
func(v interface{}) bool {
|
func(v any) bool {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -109,11 +109,11 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
},
|
},
|
||||||
makeInstantiateType(withNameExpression{}),
|
makeInstantiateType(withNameExpression{}),
|
||||||
func(v interface{}) bool {
|
func(v any) bool {
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
@ -145,7 +145,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 23,
|
"age": 23,
|
||||||
},
|
},
|
||||||
@ -158,7 +158,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
1, // Extraneous "age" property
|
1, // Extraneous "age" property
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 50,
|
"age": 50,
|
||||||
},
|
},
|
||||||
@ -166,7 +166,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Name string `hcl:"name"`
|
Name string `hcl:"name"`
|
||||||
Attrs hcl.Attributes `hcl:",remain"`
|
Attrs hcl.Attributes `hcl:",remain"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
got := gotI.(struct {
|
got := gotI.(struct {
|
||||||
Name string `hcl:"name"`
|
Name string `hcl:"name"`
|
||||||
Attrs hcl.Attributes `hcl:",remain"`
|
Attrs hcl.Attributes `hcl:",remain"`
|
||||||
@ -176,7 +176,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 50,
|
"age": 50,
|
||||||
},
|
},
|
||||||
@ -184,7 +184,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Name string `hcl:"name"`
|
Name string `hcl:"name"`
|
||||||
Remain hcl.Body `hcl:",remain"`
|
Remain hcl.Body `hcl:",remain"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
got := gotI.(struct {
|
got := gotI.(struct {
|
||||||
Name string `hcl:"name"`
|
Name string `hcl:"name"`
|
||||||
Remain hcl.Body `hcl:",remain"`
|
Remain hcl.Body `hcl:",remain"`
|
||||||
@ -197,7 +197,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"living": true,
|
"living": true,
|
||||||
},
|
},
|
||||||
@ -217,7 +217,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 50,
|
"age": 50,
|
||||||
},
|
},
|
||||||
@ -226,7 +226,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Body hcl.Body `hcl:",body"`
|
Body hcl.Body `hcl:",body"`
|
||||||
Remain hcl.Body `hcl:",remain"`
|
Remain hcl.Body `hcl:",remain"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
got := gotI.(struct {
|
got := gotI.(struct {
|
||||||
Name string `hcl:"name"`
|
Name string `hcl:"name"`
|
||||||
Body hcl.Body `hcl:",body"`
|
Body hcl.Body `hcl:",body"`
|
||||||
@ -241,76 +241,76 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{},
|
"noodle": map[string]any{},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle struct{} `hcl:"noodle,block"`
|
Noodle struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// Generating no diagnostics is good enough for this one.
|
// Generating no diagnostics is good enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{{}},
|
"noodle": []map[string]any{{}},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle struct{} `hcl:"noodle,block"`
|
Noodle struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// Generating no diagnostics is good enough for this one.
|
// Generating no diagnostics is good enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{{}, {}},
|
"noodle": []map[string]any{{}, {}},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle struct{} `hcl:"noodle,block"`
|
Noodle struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// Generating one diagnostic is good enough for this one.
|
// Generating one diagnostic is good enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{},
|
map[string]any{},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle struct{} `hcl:"noodle,block"`
|
Noodle struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// Generating one diagnostic is good enough for this one.
|
// Generating one diagnostic is good enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{},
|
"noodle": []map[string]any{},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle struct{} `hcl:"noodle,block"`
|
Noodle struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// Generating one diagnostic is good enough for this one.
|
// Generating one diagnostic is good enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{},
|
"noodle": map[string]any{},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
return gotI.(struct {
|
return gotI.(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}).Noodle != nil
|
}).Noodle != nil
|
||||||
@ -318,13 +318,13 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{{}},
|
"noodle": []map[string]any{{}},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
return gotI.(struct {
|
return gotI.(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}).Noodle != nil
|
}).Noodle != nil
|
||||||
@ -332,13 +332,13 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{},
|
"noodle": []map[string]any{},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
return gotI.(struct {
|
return gotI.(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}).Noodle == nil
|
}).Noodle == nil
|
||||||
@ -346,26 +346,26 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{{}, {}},
|
"noodle": []map[string]any{{}, {}},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle *struct{} `hcl:"noodle,block"`
|
Noodle *struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// Generating one diagnostic is good enough for this one.
|
// Generating one diagnostic is good enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{},
|
"noodle": []map[string]any{},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle []struct{} `hcl:"noodle,block"`
|
Noodle []struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
noodle := gotI.(struct {
|
noodle := gotI.(struct {
|
||||||
Noodle []struct{} `hcl:"noodle,block"`
|
Noodle []struct{} `hcl:"noodle,block"`
|
||||||
}).Noodle
|
}).Noodle
|
||||||
@ -374,13 +374,13 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{{}},
|
"noodle": []map[string]any{{}},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle []struct{} `hcl:"noodle,block"`
|
Noodle []struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
noodle := gotI.(struct {
|
noodle := gotI.(struct {
|
||||||
Noodle []struct{} `hcl:"noodle,block"`
|
Noodle []struct{} `hcl:"noodle,block"`
|
||||||
}).Noodle
|
}).Noodle
|
||||||
@ -389,13 +389,13 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": []map[string]interface{}{{}, {}},
|
"noodle": []map[string]any{{}, {}},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle []struct{} `hcl:"noodle,block"`
|
Noodle []struct{} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
noodle := gotI.(struct {
|
noodle := gotI.(struct {
|
||||||
Noodle []struct{} `hcl:"noodle,block"`
|
Noodle []struct{} `hcl:"noodle,block"`
|
||||||
}).Noodle
|
}).Noodle
|
||||||
@ -404,15 +404,15 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{},
|
"noodle": map[string]any{},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
Noodle struct {
|
Noodle struct {
|
||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
} `hcl:"noodle,block"`
|
} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
//nolint:misspell
|
//nolint:misspell
|
||||||
// Generating two diagnostics is good enough for this one.
|
// Generating two diagnostics is good enough for this one.
|
||||||
// (one for the missing noodle block and the other for
|
// (one for the missing noodle block and the other for
|
||||||
@ -423,9 +423,9 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
2,
|
2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{
|
"noodle": map[string]any{
|
||||||
"foo_foo": map[string]interface{}{},
|
"foo_foo": map[string]any{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
@ -433,7 +433,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
} `hcl:"noodle,block"`
|
} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
noodle := gotI.(struct {
|
noodle := gotI.(struct {
|
||||||
Noodle struct {
|
Noodle struct {
|
||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
@ -444,10 +444,10 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{
|
"noodle": map[string]any{
|
||||||
"foo_foo": map[string]interface{}{},
|
"foo_foo": map[string]any{},
|
||||||
"bar_baz": map[string]interface{}{},
|
"bar_baz": map[string]any{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
@ -455,17 +455,17 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
} `hcl:"noodle,block"`
|
} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
// One diagnostic is enough for this one.
|
// One diagnostic is enough for this one.
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{
|
"noodle": map[string]any{
|
||||||
"foo_foo": map[string]interface{}{},
|
"foo_foo": map[string]any{},
|
||||||
"bar_baz": map[string]interface{}{},
|
"bar_baz": map[string]any{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
makeInstantiateType(struct {
|
makeInstantiateType(struct {
|
||||||
@ -473,7 +473,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
} `hcl:"noodle,block"`
|
} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
noodles := gotI.(struct {
|
noodles := gotI.(struct {
|
||||||
Noodles []struct {
|
Noodles []struct {
|
||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
@ -484,9 +484,9 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"noodle": map[string]interface{}{
|
"noodle": map[string]any{
|
||||||
"foo_foo": map[string]interface{}{
|
"foo_foo": map[string]any{
|
||||||
"type": "rice",
|
"type": "rice",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -497,7 +497,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
Type string `hcl:"type"`
|
Type string `hcl:"type"`
|
||||||
} `hcl:"noodle,block"`
|
} `hcl:"noodle,block"`
|
||||||
}{}),
|
}{}),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
noodle := gotI.(struct {
|
noodle := gotI.(struct {
|
||||||
Noodle struct {
|
Noodle struct {
|
||||||
Name string `hcl:"name,label"`
|
Name string `hcl:"name,label"`
|
||||||
@ -510,7 +510,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 34,
|
"age": 34,
|
||||||
},
|
},
|
||||||
@ -522,31 +522,31 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 89,
|
"age": 89,
|
||||||
},
|
},
|
||||||
makeInstantiateType(map[string]*hcl.Attribute(nil)),
|
makeInstantiateType(map[string]*hcl.Attribute(nil)),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
got := gotI.(map[string]*hcl.Attribute)
|
got := gotI.(map[string]*hcl.Attribute)
|
||||||
return len(got) == 2 && got["name"] != nil && got["age"] != nil
|
return len(got) == 2 && got["name"] != nil && got["age"] != nil
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"age": 13,
|
"age": 13,
|
||||||
},
|
},
|
||||||
makeInstantiateType(map[string]hcl.Expression(nil)),
|
makeInstantiateType(map[string]hcl.Expression(nil)),
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
got := gotI.(map[string]hcl.Expression)
|
got := gotI.(map[string]hcl.Expression)
|
||||||
return len(got) == 2 && got["name"] != nil && got["age"] != nil
|
return len(got) == 2 && got["name"] != nil && got["age"] != nil
|
||||||
},
|
},
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"name": "Ermintrude",
|
"name": "Ermintrude",
|
||||||
"living": true,
|
"living": true,
|
||||||
},
|
},
|
||||||
@ -559,10 +559,10 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Retain "nested" block while decoding
|
// Retain "nested" block while decoding
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"plain": "foo",
|
"plain": "foo",
|
||||||
},
|
},
|
||||||
func() interface{} {
|
func() any {
|
||||||
return &withNestedBlock{
|
return &withNestedBlock{
|
||||||
Plain: "bar",
|
Plain: "bar",
|
||||||
Nested: &withTwoAttributes{
|
Nested: &withTwoAttributes{
|
||||||
@ -570,7 +570,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
foo := gotI.(withNestedBlock)
|
foo := gotI.(withNestedBlock)
|
||||||
return foo.Plain == "foo" && foo.Nested != nil && foo.Nested.A == "bar"
|
return foo.Plain == "foo" && foo.Nested != nil && foo.Nested.A == "bar"
|
||||||
},
|
},
|
||||||
@ -578,19 +578,19 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Retain values in "nested" block while decoding
|
// Retain values in "nested" block while decoding
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"nested": map[string]interface{}{
|
"nested": map[string]any{
|
||||||
"a": "foo",
|
"a": "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func() interface{} {
|
func() any {
|
||||||
return &withNestedBlock{
|
return &withNestedBlock{
|
||||||
Nested: &withTwoAttributes{
|
Nested: &withTwoAttributes{
|
||||||
B: "bar",
|
B: "bar",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
foo := gotI.(withNestedBlock)
|
foo := gotI.(withNestedBlock)
|
||||||
return foo.Nested.A == "foo" && foo.Nested.B == "bar"
|
return foo.Nested.A == "foo" && foo.Nested.B == "bar"
|
||||||
},
|
},
|
||||||
@ -598,14 +598,14 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Retain values in "nested" block list while decoding
|
// Retain values in "nested" block list while decoding
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"nested": []map[string]interface{}{
|
"nested": []map[string]any{
|
||||||
{
|
{
|
||||||
"a": "foo",
|
"a": "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func() interface{} {
|
func() any {
|
||||||
return &withListofNestedBlocks{
|
return &withListofNestedBlocks{
|
||||||
Nested: []*withTwoAttributes{
|
Nested: []*withTwoAttributes{
|
||||||
{
|
{
|
||||||
@ -614,7 +614,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
n := gotI.(withListofNestedBlocks)
|
n := gotI.(withListofNestedBlocks)
|
||||||
return n.Nested[0].A == "foo" && n.Nested[0].B == "bar"
|
return n.Nested[0].A == "foo" && n.Nested[0].B == "bar"
|
||||||
},
|
},
|
||||||
@ -622,14 +622,14 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Remove additional elements from the list while decoding nested blocks
|
// Remove additional elements from the list while decoding nested blocks
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"nested": []map[string]interface{}{
|
"nested": []map[string]any{
|
||||||
{
|
{
|
||||||
"a": "foo",
|
"a": "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func() interface{} {
|
func() any {
|
||||||
return &withListofNestedBlocks{
|
return &withListofNestedBlocks{
|
||||||
Nested: []*withTwoAttributes{
|
Nested: []*withTwoAttributes{
|
||||||
{
|
{
|
||||||
@ -641,7 +641,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
n := gotI.(withListofNestedBlocks)
|
n := gotI.(withListofNestedBlocks)
|
||||||
return len(n.Nested) == 1
|
return len(n.Nested) == 1
|
||||||
},
|
},
|
||||||
@ -649,8 +649,8 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Make sure decoding value slices works the same as pointer slices.
|
// Make sure decoding value slices works the same as pointer slices.
|
||||||
map[string]interface{}{
|
map[string]any{
|
||||||
"nested": []map[string]interface{}{
|
"nested": []map[string]any{
|
||||||
{
|
{
|
||||||
"b": "bar",
|
"b": "bar",
|
||||||
},
|
},
|
||||||
@ -659,7 +659,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
func() interface{} {
|
func() any {
|
||||||
return &withListofNestedBlocksNoPointers{
|
return &withListofNestedBlocksNoPointers{
|
||||||
Nested: []withTwoAttributes{
|
Nested: []withTwoAttributes{
|
||||||
{
|
{
|
||||||
@ -668,7 +668,7 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
func(gotI interface{}) bool {
|
func(gotI any) bool {
|
||||||
n := gotI.(withListofNestedBlocksNoPointers)
|
n := gotI.(withListofNestedBlocksNoPointers)
|
||||||
return n.Nested[0].B == "bar" && len(n.Nested) == 2
|
return n.Nested[0].B == "bar" && len(n.Nested) == 2
|
||||||
},
|
},
|
||||||
@ -710,8 +710,8 @@ func TestDecodeBody(t *testing.T) {
|
|||||||
func TestDecodeExpression(t *testing.T) {
|
func TestDecodeExpression(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Value cty.Value
|
Value cty.Value
|
||||||
Target interface{}
|
Target any
|
||||||
Want interface{}
|
Want any
|
||||||
DiagCount int
|
DiagCount int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -799,8 +799,8 @@ func (e *fixedExpression) Variables() []hcl.Traversal {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeInstantiateType(target interface{}) func() interface{} {
|
func makeInstantiateType(target any) func() any {
|
||||||
return func() interface{} {
|
return func() any {
|
||||||
return reflect.New(reflect.TypeOf(target)).Interface()
|
return reflect.New(reflect.TypeOf(target)).Interface()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ import (
|
|||||||
// Fields representing attributes should usually precede those representing
|
// Fields representing attributes should usually precede those representing
|
||||||
// blocks so that the attributes can group together in the result. For more
|
// blocks so that the attributes can group together in the result. For more
|
||||||
// control, use the hclwrite API directly.
|
// control, use the hclwrite API directly.
|
||||||
func EncodeIntoBody(val interface{}, dst *hclwrite.Body) {
|
func EncodeIntoBody(val any, dst *hclwrite.Body) {
|
||||||
rv := reflect.ValueOf(val)
|
rv := reflect.ValueOf(val)
|
||||||
ty := rv.Type()
|
ty := rv.Type()
|
||||||
if ty.Kind() == reflect.Ptr {
|
if ty.Kind() == reflect.Ptr {
|
||||||
@ -60,7 +60,7 @@ func EncodeIntoBody(val interface{}, dst *hclwrite.Body) {
|
|||||||
//
|
//
|
||||||
// This function has the same constraints as EncodeIntoBody and will panic
|
// This function has the same constraints as EncodeIntoBody and will panic
|
||||||
// if they are violated.
|
// if they are violated.
|
||||||
func EncodeAsBlock(val interface{}, blockType string) *hclwrite.Block {
|
func EncodeAsBlock(val any, blockType string) *hclwrite.Block {
|
||||||
rv := reflect.ValueOf(val)
|
rv := reflect.ValueOf(val)
|
||||||
ty := rv.Type()
|
ty := rv.Type()
|
||||||
if ty.Kind() == reflect.Ptr {
|
if ty.Kind() == reflect.Ptr {
|
||||||
@ -158,7 +158,7 @@ func populateBody(rv reflect.Value, ty reflect.Type, tags *fieldTags, dst *hclwr
|
|||||||
|
|
||||||
if isSeq {
|
if isSeq {
|
||||||
l := fieldVal.Len()
|
l := fieldVal.Len()
|
||||||
for i := 0; i < l; i++ {
|
for i := range l {
|
||||||
elemVal := fieldVal.Index(i)
|
elemVal := fieldVal.Index(i)
|
||||||
if !elemVal.IsValid() {
|
if !elemVal.IsValid() {
|
||||||
continue // ignore (elem value is nil pointer)
|
continue // ignore (elem value is nil pointer)
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
// This uses the tags on the fields of the struct to discover how each
|
// This uses the tags on the fields of the struct to discover how each
|
||||||
// field's value should be expressed within configuration. If an invalid
|
// field's value should be expressed within configuration. If an invalid
|
||||||
// mapping is attempted, this function will panic.
|
// mapping is attempted, this function will panic.
|
||||||
func ImpliedBodySchema(val interface{}) (schema *hcl.BodySchema, partial bool) {
|
func ImpliedBodySchema(val any) (schema *hcl.BodySchema, partial bool) {
|
||||||
ty := reflect.TypeOf(val)
|
ty := reflect.TypeOf(val)
|
||||||
|
|
||||||
if ty.Kind() == reflect.Ptr {
|
if ty.Kind() == reflect.Ptr {
|
||||||
@ -134,7 +134,7 @@ func getFieldTags(ty reflect.Type) *fieldTags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ct := ty.NumField()
|
ct := ty.NumField()
|
||||||
for i := 0; i < ct; i++ {
|
for i := range ct {
|
||||||
field := ty.Field(i)
|
field := ty.Field(i)
|
||||||
tag := field.Tag.Get("hcl")
|
tag := field.Tag.Get("hcl")
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
func TestImpliedBodySchema(t *testing.T) {
|
func TestImpliedBodySchema(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
val interface{}
|
val any
|
||||||
wantSchema *hcl.BodySchema
|
wantSchema *hcl.BodySchema
|
||||||
wantPartial bool
|
wantPartial bool
|
||||||
}{
|
}{
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -589,7 +590,7 @@ type ParseMeta struct {
|
|||||||
AllVariables []*Variable
|
AllVariables []*Variable
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parse(b hcl.Body, opt Opt, val interface{}) (*ParseMeta, hcl.Diagnostics) {
|
func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
|
||||||
reserved := map[string]struct{}{}
|
reserved := map[string]struct{}{}
|
||||||
schema, _ := gohcl.ImpliedBodySchema(val)
|
schema, _ := gohcl.ImpliedBodySchema(val)
|
||||||
|
|
||||||
@ -763,7 +764,7 @@ func Parse(b hcl.Body, opt Opt, val interface{}) (*ParseMeta, hcl.Diagnostics) {
|
|||||||
types := map[string]field{}
|
types := map[string]field{}
|
||||||
renamed := map[string]map[string][]string{}
|
renamed := map[string]map[string][]string{}
|
||||||
vt := reflect.ValueOf(val).Elem().Type()
|
vt := reflect.ValueOf(val).Elem().Type()
|
||||||
for i := 0; i < vt.NumField(); i++ {
|
for i := range vt.NumField() {
|
||||||
tags := strings.Split(vt.Field(i).Tag.Get("hcl"), ",")
|
tags := strings.Split(vt.Field(i).Tag.Get("hcl"), ",")
|
||||||
|
|
||||||
p.blockTypes[tags[0]] = vt.Field(i).Type.Elem().Elem()
|
p.blockTypes[tags[0]] = vt.Field(i).Type.Elem().Elem()
|
||||||
@ -831,7 +832,7 @@ func Parse(b hcl.Body, opt Opt, val interface{}) (*ParseMeta, hcl.Diagnostics) {
|
|||||||
oldValue, exists := t.values[lblName]
|
oldValue, exists := t.values[lblName]
|
||||||
if !exists && lblExists {
|
if !exists && lblExists {
|
||||||
if v.Elem().Field(t.idx).Type().Kind() == reflect.Slice {
|
if v.Elem().Field(t.idx).Type().Kind() == reflect.Slice {
|
||||||
for i := 0; i < v.Elem().Field(t.idx).Len(); i++ {
|
for i := range v.Elem().Field(t.idx).Len() {
|
||||||
if lblName == v.Elem().Field(t.idx).Index(i).Elem().Field(lblIndex).String() {
|
if lblName == v.Elem().Field(t.idx).Index(i).Elem().Field(lblIndex).String() {
|
||||||
exists = true
|
exists = true
|
||||||
oldValue = value{Value: v.Elem().Field(t.idx).Index(i), idx: i}
|
oldValue = value{Value: v.Elem().Field(t.idx).Index(i), idx: i}
|
||||||
@ -898,7 +899,7 @@ func wrapErrorDiagnostic(message string, err error, subject *hcl.Range, context
|
|||||||
|
|
||||||
func setName(v reflect.Value, name string) {
|
func setName(v reflect.Value, name string) {
|
||||||
numFields := v.Elem().Type().NumField()
|
numFields := v.Elem().Type().NumField()
|
||||||
for i := 0; i < numFields; i++ {
|
for i := range numFields {
|
||||||
parts := strings.Split(v.Elem().Type().Field(i).Tag.Get("hcl"), ",")
|
parts := strings.Split(v.Elem().Type().Field(i).Tag.Get("hcl"), ",")
|
||||||
for _, t := range parts[1:] {
|
for _, t := range parts[1:] {
|
||||||
if t == "label" {
|
if t == "label" {
|
||||||
@ -910,12 +911,10 @@ func setName(v reflect.Value, name string) {
|
|||||||
|
|
||||||
func getName(v reflect.Value) (string, bool) {
|
func getName(v reflect.Value) (string, bool) {
|
||||||
numFields := v.Elem().Type().NumField()
|
numFields := v.Elem().Type().NumField()
|
||||||
for i := 0; i < numFields; i++ {
|
for i := range numFields {
|
||||||
parts := strings.Split(v.Elem().Type().Field(i).Tag.Get("hcl"), ",")
|
parts := strings.Split(v.Elem().Type().Field(i).Tag.Get("hcl"), ",")
|
||||||
for _, t := range parts[1:] {
|
if slices.Contains(parts[1:], "label") {
|
||||||
if t == "label" {
|
return v.Elem().Field(i).String(), true
|
||||||
return v.Elem().Field(i).String(), true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
@ -923,12 +922,10 @@ func getName(v reflect.Value) (string, bool) {
|
|||||||
|
|
||||||
func getNameIndex(v reflect.Value) (int, bool) {
|
func getNameIndex(v reflect.Value) (int, bool) {
|
||||||
numFields := v.Elem().Type().NumField()
|
numFields := v.Elem().Type().NumField()
|
||||||
for i := 0; i < numFields; i++ {
|
for i := range numFields {
|
||||||
parts := strings.Split(v.Elem().Type().Field(i).Tag.Get("hcl"), ",")
|
parts := strings.Split(v.Elem().Type().Field(i).Tag.Get("hcl"), ",")
|
||||||
for _, t := range parts[1:] {
|
if slices.Contains(parts[1:], "label") {
|
||||||
if t == "label" {
|
return i, true
|
||||||
return i, true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, false
|
return 0, false
|
||||||
@ -988,7 +985,7 @@ func key(ks ...any) uint64 {
|
|||||||
return hash.Sum64()
|
return hash.Sum64()
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeBody(body hcl.Body, ctx *hcl.EvalContext, val interface{}) hcl.Diagnostics {
|
func decodeBody(body hcl.Body, ctx *hcl.EvalContext, val any) hcl.Diagnostics {
|
||||||
dec := gohcl.DecodeOptions{ImpliedType: ImpliedType}
|
dec := gohcl.DecodeOptions{ImpliedType: ImpliedType}
|
||||||
return dec.DecodeBody(body, ctx, val)
|
return dec.DecodeBody(body, ctx, val)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ import (
|
|||||||
// In particular, ImpliedType will never use capsule types in its returned
|
// In particular, ImpliedType will never use capsule types in its returned
|
||||||
// type, because it cannot know the capsule types supported by the calling
|
// type, because it cannot know the capsule types supported by the calling
|
||||||
// program.
|
// program.
|
||||||
func ImpliedType(gv interface{}) (cty.Type, error) {
|
func ImpliedType(gv any) (cty.Type, error) {
|
||||||
rt := reflect.TypeOf(gv)
|
rt := reflect.TypeOf(gv)
|
||||||
var path cty.Path
|
var path cty.Path
|
||||||
return impliedType(rt, path)
|
return impliedType(rt, path)
|
||||||
@ -148,7 +148,7 @@ func structTagIndices(st reflect.Type) map[string]int {
|
|||||||
ct := st.NumField()
|
ct := st.NumField()
|
||||||
ret := make(map[string]int, ct)
|
ret := make(map[string]int, ct)
|
||||||
|
|
||||||
for i := 0; i < ct; i++ {
|
for i := range ct {
|
||||||
field := st.Field(i)
|
field := st.Field(i)
|
||||||
attrName := field.Tag.Get("cty")
|
attrName := field.Tag.Get("cty")
|
||||||
if attrName != "" {
|
if attrName != "" {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
stderrors "errors"
|
stderrors "errors"
|
||||||
"net"
|
"net"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/containerd/platforms"
|
"github.com/containerd/platforms"
|
||||||
"github.com/docker/buildx/builder"
|
"github.com/docker/buildx/builder"
|
||||||
@ -37,15 +38,7 @@ func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platfor
|
|||||||
for _, ls := range resolved {
|
for _, ls := range resolved {
|
||||||
for _, rn := range ls {
|
for _, rn := range ls {
|
||||||
if platform != nil {
|
if platform != nil {
|
||||||
p := *platform
|
if !slices.ContainsFunc(rn.platforms, platforms.Only(*platform).Match) {
|
||||||
var found bool
|
|
||||||
for _, pp := range rn.platforms {
|
|
||||||
if platforms.Only(p).Match(pp) {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package build
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containerd/platforms"
|
"github.com/containerd/platforms"
|
||||||
@ -221,7 +222,7 @@ func (r *nodeResolver) get(p specs.Platform, matcher matchMaker, additionalPlatf
|
|||||||
for i, node := range r.nodes {
|
for i, node := range r.nodes {
|
||||||
platforms := node.Platforms
|
platforms := node.Platforms
|
||||||
if additionalPlatforms != nil {
|
if additionalPlatforms != nil {
|
||||||
platforms = append([]specs.Platform{}, platforms...)
|
platforms = slices.Clone(platforms)
|
||||||
platforms = append(platforms, additionalPlatforms(i, node)...)
|
platforms = append(platforms, additionalPlatforms(i, node)...)
|
||||||
}
|
}
|
||||||
for _, p2 := range platforms {
|
for _, p2 := range platforms {
|
||||||
|
@ -28,11 +28,11 @@ func TestSyncMultiReaderParallel(t *testing.T) {
|
|||||||
|
|
||||||
readers := make([]io.ReadCloser, numReaders)
|
readers := make([]io.ReadCloser, numReaders)
|
||||||
|
|
||||||
for i := 0; i < numReaders; i++ {
|
for i := range numReaders {
|
||||||
readers[i] = mr.NewReadCloser()
|
readers[i] = mr.NewReadCloser()
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < numReaders; i++ {
|
for i := range numReaders {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(readerId int) {
|
go func(readerId int) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -656,13 +657,7 @@ func parseBuildkitdFlags(inp string, driver string, driverOpts map[string]string
|
|||||||
flags.StringArrayVar(&allowInsecureEntitlements, "allow-insecure-entitlement", nil, "")
|
flags.StringArrayVar(&allowInsecureEntitlements, "allow-insecure-entitlement", nil, "")
|
||||||
_ = flags.Parse(res)
|
_ = flags.Parse(res)
|
||||||
|
|
||||||
var hasNetworkHostEntitlement bool
|
hasNetworkHostEntitlement := slices.Contains(allowInsecureEntitlements, "network.host")
|
||||||
for _, e := range allowInsecureEntitlements {
|
|
||||||
if e == "network.host" {
|
|
||||||
hasNetworkHostEntitlement = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var hasNetworkHostEntitlementInConf bool
|
var hasNetworkHostEntitlementInConf bool
|
||||||
if buildkitdConfigFile != "" {
|
if buildkitdConfigFile != "" {
|
||||||
@ -671,11 +666,8 @@ func parseBuildkitdFlags(inp string, driver string, driverOpts map[string]string
|
|||||||
return nil, err
|
return nil, err
|
||||||
} else if btoml != nil {
|
} else if btoml != nil {
|
||||||
if ies := btoml.GetArray("insecure-entitlements"); ies != nil {
|
if ies := btoml.GetArray("insecure-entitlements"); ies != nil {
|
||||||
for _, e := range ies.([]string) {
|
if slices.Contains(ies.([]string), "network.host") {
|
||||||
if e == "network.host" {
|
hasNetworkHostEntitlementInConf = true
|
||||||
hasNetworkHostEntitlementInConf = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
|
|||||||
// dynamic nodes are used in Kubernetes driver.
|
// dynamic nodes are used in Kubernetes driver.
|
||||||
// Kubernetes' pods are dynamically mapped to BuildKit Nodes.
|
// Kubernetes' pods are dynamically mapped to BuildKit Nodes.
|
||||||
if di.DriverInfo != nil && len(di.DriverInfo.DynamicNodes) > 0 {
|
if di.DriverInfo != nil && len(di.DriverInfo.DynamicNodes) > 0 {
|
||||||
for i := 0; i < len(di.DriverInfo.DynamicNodes); i++ {
|
for i := range di.DriverInfo.DynamicNodes {
|
||||||
diClone := di
|
diClone := di
|
||||||
if pl := di.DriverInfo.DynamicNodes[i].Platforms; len(pl) > 0 {
|
if pl := di.DriverInfo.DynamicNodes[i].Platforms; len(pl) > 0 {
|
||||||
diClone.Platforms = pl
|
diClone.Platforms = pl
|
||||||
|
@ -305,7 +305,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba
|
|||||||
desktop.PrintBuildDetails(os.Stderr, printer.BuildRefs(), term)
|
desktop.PrintBuildDetails(os.Stderr, printer.BuildRefs(), term)
|
||||||
}
|
}
|
||||||
if len(in.metadataFile) > 0 {
|
if len(in.metadataFile) > 0 {
|
||||||
dt := make(map[string]interface{})
|
dt := make(map[string]any)
|
||||||
for t, r := range resp {
|
for t, r := range resp {
|
||||||
dt[t] = decodeExporterResponse(r.ExporterResponse)
|
dt[t] = decodeExporterResponse(r.ExporterResponse)
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -156,7 +157,7 @@ func (o *buildOptions) toControllerOptions() (*controllerapi.BuildOptions, error
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
inAttests := append([]string{}, o.attests...)
|
inAttests := slices.Clone(o.attests)
|
||||||
if o.provenance != "" {
|
if o.provenance != "" {
|
||||||
inAttests = append(inAttests, buildflags.CanonicalizeAttest("provenance", o.provenance))
|
inAttests = append(inAttests, buildflags.CanonicalizeAttest("provenance", o.provenance))
|
||||||
}
|
}
|
||||||
@ -740,7 +741,7 @@ func checkWarnedFlags(f *pflag.Flag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeMetadataFile(filename string, dt interface{}) error {
|
func writeMetadataFile(filename string, dt any) error {
|
||||||
b, err := json.MarshalIndent(dt, "", " ")
|
b, err := json.MarshalIndent(dt, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -748,7 +749,7 @@ func writeMetadataFile(filename string, dt interface{}) error {
|
|||||||
return atomicwriter.WriteFile(filename, b, 0644)
|
return atomicwriter.WriteFile(filename, b, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func decodeExporterResponse(exporterResponse map[string]string) map[string]interface{} {
|
func decodeExporterResponse(exporterResponse map[string]string) map[string]any {
|
||||||
decFunc := func(k, v string) ([]byte, error) {
|
decFunc := func(k, v string) ([]byte, error) {
|
||||||
if k == "result.json" {
|
if k == "result.json" {
|
||||||
// result.json is part of metadata response for subrequests which
|
// result.json is part of metadata response for subrequests which
|
||||||
@ -757,16 +758,16 @@ func decodeExporterResponse(exporterResponse map[string]string) map[string]inter
|
|||||||
}
|
}
|
||||||
return base64.StdEncoding.DecodeString(v)
|
return base64.StdEncoding.DecodeString(v)
|
||||||
}
|
}
|
||||||
out := make(map[string]interface{})
|
out := make(map[string]any)
|
||||||
for k, v := range exporterResponse {
|
for k, v := range exporterResponse {
|
||||||
dt, err := decFunc(k, v)
|
dt, err := decFunc(k, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
out[k] = v
|
out[k] = v
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var raw map[string]interface{}
|
var raw map[string]any
|
||||||
if err = json.Unmarshal(dt, &raw); err != nil || len(raw) == 0 {
|
if err = json.Unmarshal(dt, &raw); err != nil || len(raw) == 0 {
|
||||||
var rawList []map[string]interface{}
|
var rawList []map[string]any
|
||||||
if err = json.Unmarshal(dt, &rawList); err != nil || len(rawList) == 0 {
|
if err = json.Unmarshal(dt, &rawList); err != nil || len(rawList) == 0 {
|
||||||
out[k] = v
|
out[k] = v
|
||||||
continue
|
continue
|
||||||
|
@ -124,7 +124,7 @@ func duCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func printKV(w io.Writer, k string, v interface{}) {
|
func printKV(w io.Writer, k string, v any) {
|
||||||
fmt.Fprintf(w, "%s:\t%v\n", k, v)
|
fmt.Fprintf(w, "%s:\t%v\n", k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ workers0:
|
|||||||
out.Error.Name = name
|
out.Error.Name = name
|
||||||
out.Error.Logs = logs
|
out.Error.Logs = logs
|
||||||
}
|
}
|
||||||
out.Error.Stack = []byte(fmt.Sprintf("%+v", stack.Formatter(retErr)))
|
out.Error.Stack = fmt.Appendf(nil, "%+v", stack.Formatter(retErr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ type lsContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *lsContext) MarshalJSON() ([]byte, error) {
|
func (c *lsContext) MarshalJSON() ([]byte, error) {
|
||||||
m := map[string]interface{}{
|
m := map[string]any{
|
||||||
"ref": c.FullRef(),
|
"ref": c.FullRef(),
|
||||||
"name": c.Name(),
|
"name": c.Name(),
|
||||||
"status": c.Status(),
|
"status": c.Status(),
|
||||||
|
@ -194,7 +194,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
|
|||||||
}
|
}
|
||||||
s := s
|
s := s
|
||||||
eg2.Go(func() error {
|
eg2.Go(func() error {
|
||||||
sub.Log(1, []byte(fmt.Sprintf("copying %s from %s to %s\n", s.Desc.Digest.String(), s.Ref.String(), t.String())))
|
sub.Log(1, fmt.Appendf(nil, "copying %s from %s to %s\n", s.Desc.Digest.String(), s.Ref.String(), t.String()))
|
||||||
return r.Copy(ctx, s, t)
|
return r.Copy(ctx, s, t)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
|
|||||||
if err := eg2.Wait(); err != nil {
|
if err := eg2.Wait(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sub.Log(1, []byte(fmt.Sprintf("pushing %s to %s\n", desc.Digest.String(), t.String())))
|
sub.Log(1, fmt.Appendf(nil, "pushing %s to %s\n", desc.Digest.String(), t.String()))
|
||||||
return r.Push(ctx, t, desc, dt)
|
return r.Push(ctx, t, desc, dt)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -24,11 +24,11 @@ func (w *writer) Write(status *client.SolveStatus) {
|
|||||||
|
|
||||||
func (w *writer) WriteBuildRef(target string, ref string) {}
|
func (w *writer) WriteBuildRef(target string, ref string) {}
|
||||||
|
|
||||||
func (w *writer) ValidateLogSource(digest.Digest, interface{}) bool {
|
func (w *writer) ValidateLogSource(digest.Digest, any) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *writer) ClearLogSource(interface{}) {}
|
func (w *writer) ClearLogSource(any) {}
|
||||||
|
|
||||||
func ToControlStatus(s *client.SolveStatus) *StatusResponse {
|
func ToControlStatus(s *client.SolveStatus) *StatusResponse {
|
||||||
resp := StatusResponse{}
|
resp := StatusResponse{}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package pb
|
package pb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/moby/buildkit/session"
|
"github.com/moby/buildkit/session"
|
||||||
"github.com/moby/buildkit/session/sshforward/sshprovider"
|
"github.com/moby/buildkit/session/sshforward/sshprovider"
|
||||||
)
|
)
|
||||||
@ -10,7 +12,7 @@ func CreateSSH(ssh []*SSH) (session.Attachable, error) {
|
|||||||
for _, ssh := range ssh {
|
for _, ssh := range ssh {
|
||||||
cfg := sshprovider.AgentConfig{
|
cfg := sshprovider.AgentConfig{
|
||||||
ID: ssh.ID,
|
ID: ssh.ID,
|
||||||
Paths: append([]string{}, ssh.Paths...),
|
Paths: slices.Clone(ssh.Paths),
|
||||||
}
|
}
|
||||||
configs = append(configs, cfg)
|
configs = append(configs, cfg)
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ func serveCmd(dockerCli command.Cli) *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pidF := filepath.Join(root, defaultPIDFilename)
|
pidF := filepath.Join(root, defaultPIDFilename)
|
||||||
if err := os.WriteFile(pidF, []byte(fmt.Sprintf("%d", os.Getpid())), 0600); err != nil {
|
if err := os.WriteFile(pidF, fmt.Appendf(nil, "%d", os.Getpid()), 0600); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -35,10 +35,10 @@ func testEndpoint(server, defaultNamespace string, ca, cert, key []byte, skipTLS
|
|||||||
}
|
}
|
||||||
|
|
||||||
var testStoreCfg = store.NewConfig(
|
var testStoreCfg = store.NewConfig(
|
||||||
func() interface{} {
|
func() any {
|
||||||
return &map[string]interface{}{}
|
return &map[string]any{}
|
||||||
},
|
},
|
||||||
store.EndpointTypeGetter(KubernetesEndpoint, func() interface{} { return &EndpointMeta{} }),
|
store.EndpointTypeGetter(KubernetesEndpoint, func() any { return &EndpointMeta{} }),
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSaveLoadContexts(t *testing.T) {
|
func TestSaveLoadContexts(t *testing.T) {
|
||||||
@ -197,7 +197,7 @@ func checkClientConfig(t *testing.T, ep Endpoint, server, namespace string, ca,
|
|||||||
|
|
||||||
func save(s store.Writer, ep Endpoint, name string) error {
|
func save(s store.Writer, ep Endpoint, name string) error {
|
||||||
meta := store.Metadata{
|
meta := store.Metadata{
|
||||||
Endpoints: map[string]interface{}{
|
Endpoints: map[string]any{
|
||||||
KubernetesEndpoint: ep.EndpointMeta,
|
KubernetesEndpoint: ep.EndpointMeta,
|
||||||
},
|
},
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -43,7 +43,7 @@ type Endpoint struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
command.RegisterDefaultStoreEndpoints(
|
command.RegisterDefaultStoreEndpoints(
|
||||||
store.EndpointTypeGetter(KubernetesEndpoint, func() interface{} { return &EndpointMeta{} }),
|
store.EndpointTypeGetter(KubernetesEndpoint, func() any { return &EndpointMeta{} }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (c *Endpoint) KubernetesConfig() clientcmd.ClientConfig {
|
|||||||
|
|
||||||
// ResolveDefault returns endpoint metadata for the default Kubernetes
|
// ResolveDefault returns endpoint metadata for the default Kubernetes
|
||||||
// endpoint, which is derived from the env-based kubeconfig.
|
// endpoint, which is derived from the env-based kubeconfig.
|
||||||
func (c *EndpointMeta) ResolveDefault() (interface{}, *store.EndpointTLSData, error) {
|
func (c *EndpointMeta) ResolveDefault() (any, *store.EndpointTLSData, error) {
|
||||||
kubeconfig := os.Getenv("KUBECONFIG")
|
kubeconfig := os.Getenv("KUBECONFIG")
|
||||||
if kubeconfig == "" {
|
if kubeconfig == "" {
|
||||||
kubeconfig = filepath.Join(homedir.Get(), ".kube/config")
|
kubeconfig = filepath.Join(homedir.Get(), ".kube/config")
|
||||||
|
@ -25,7 +25,7 @@ func GenerateNodeName(builderName string, txn *store.Txn) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var name string
|
var name string
|
||||||
for i := 0; i < 6; i++ {
|
for range 6 {
|
||||||
name, err = randomName()
|
name, err = randomName()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -5,9 +5,10 @@ ARG ALPINE_VERSION=3.21
|
|||||||
ARG XX_VERSION=1.6.1
|
ARG XX_VERSION=1.6.1
|
||||||
|
|
||||||
ARG GOLANGCI_LINT_VERSION=1.62.0
|
ARG GOLANGCI_LINT_VERSION=1.62.0
|
||||||
ARG GOPLS_VERSION=v0.26.0
|
# v0.31 requires go1.24
|
||||||
|
ARG GOPLS_VERSION=v0.30.0
|
||||||
# disabled: deprecated unusedvariable simplifyrange
|
# disabled: deprecated unusedvariable simplifyrange
|
||||||
ARG GOPLS_ANALYZERS="embeddirective fillreturns infertypeargs nonewvars noresultvalues simplifycompositelit simplifyslice undeclaredname unusedparams useany"
|
ARG GOPLS_ANALYZERS="embeddirective fillreturns hostport infertypeargs modernize nonewvars noresultvalues simplifycompositelit simplifyslice unusedparams yield"
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/docker/buildx/monitor/types"
|
"github.com/docker/buildx/monitor/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -50,14 +51,7 @@ func (cm *AttachCmd) Exec(ctx context.Context, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Errorf("failed to get the list of sessions: %v", err)
|
return errors.Errorf("failed to get the list of sessions: %v", err)
|
||||||
}
|
}
|
||||||
found := false
|
if !slices.Contains(refs, ref) {
|
||||||
for _, s := range refs {
|
|
||||||
if s == ref {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
return errors.Errorf("unknown ID: %q", ref)
|
return errors.Errorf("unknown ID: %q", ref)
|
||||||
}
|
}
|
||||||
cm.m.Detach() // Finish existing attach
|
cm.m.Detach() // Finish existing attach
|
||||||
|
@ -2,6 +2,7 @@ package store
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/platforms"
|
"github.com/containerd/platforms"
|
||||||
@ -44,7 +45,7 @@ func (ng *NodeGroup) Leave(name string) error {
|
|||||||
if len(ng.Nodes) == 1 {
|
if len(ng.Nodes) == 1 {
|
||||||
return errors.Errorf("can not leave last node, do you want to rm instance instead?")
|
return errors.Errorf("can not leave last node, do you want to rm instance instead?")
|
||||||
}
|
}
|
||||||
ng.Nodes = append(ng.Nodes[:i], ng.Nodes[i+1:]...)
|
ng.Nodes = slices.Delete(ng.Nodes, i, i+1)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func ValidateName(s string) (string, error) {
|
|||||||
|
|
||||||
func GenerateName(txn *Txn) (string, error) {
|
func GenerateName(txn *Txn) (string, error) {
|
||||||
var name string
|
var name string
|
||||||
for i := 0; i < 6; i++ {
|
for i := range 6 {
|
||||||
name = namesgenerator.GetRandomName(i)
|
name = namesgenerator.GetRandomName(i)
|
||||||
if _, err := txn.NodeGroupByName(name); err != nil {
|
if _, err := txn.NodeGroupByName(name); err != nil {
|
||||||
if !os.IsNotExist(errors.Cause(err)) {
|
if !os.IsNotExist(errors.Cause(err)) {
|
||||||
|
@ -1016,11 +1016,11 @@ FROM scratch
|
|||||||
COPY foo /foo
|
COPY foo /foo
|
||||||
`)
|
`)
|
||||||
destDir := t.TempDir()
|
destDir := t.TempDir()
|
||||||
bakefile := []byte(fmt.Sprintf(`
|
bakefile := fmt.Appendf(nil, `
|
||||||
target "default" {
|
target "default" {
|
||||||
output = ["type=local,dest=%s/not/exists"]
|
output = ["type=local,dest=%s/not/exists"]
|
||||||
}
|
}
|
||||||
`, destDir))
|
`, destDir)
|
||||||
dir := tmpdir(
|
dir := tmpdir(
|
||||||
t,
|
t,
|
||||||
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
||||||
@ -1050,11 +1050,11 @@ FROM scratch
|
|||||||
COPY foo /foo
|
COPY foo /foo
|
||||||
`)
|
`)
|
||||||
destDir := t.TempDir()
|
destDir := t.TempDir()
|
||||||
bakefile := []byte(fmt.Sprintf(`
|
bakefile := fmt.Appendf(nil, `
|
||||||
target "default" {
|
target "default" {
|
||||||
output = ["type=local,dest=%s"]
|
output = ["type=local,dest=%s"]
|
||||||
}
|
}
|
||||||
`, destDir))
|
`, destDir)
|
||||||
dir := tmpdir(
|
dir := tmpdir(
|
||||||
t,
|
t,
|
||||||
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
||||||
@ -1151,11 +1151,11 @@ COPY Dockerfile /foo
|
|||||||
keyDir := t.TempDir()
|
keyDir := t.TempDir()
|
||||||
err := writeTempPrivateKey(filepath.Join(keyDir, "id_rsa"))
|
err := writeTempPrivateKey(filepath.Join(keyDir, "id_rsa"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
bakefile := []byte(fmt.Sprintf(`
|
bakefile := fmt.Appendf(nil, `
|
||||||
target "default" {
|
target "default" {
|
||||||
ssh = ["key=%s"]
|
ssh = ["key=%s"]
|
||||||
}
|
}
|
||||||
`, filepath.Join(keyDir, "id_rsa")))
|
`, filepath.Join(keyDir, "id_rsa"))
|
||||||
dir := tmpdir(
|
dir := tmpdir(
|
||||||
t,
|
t,
|
||||||
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
fstest.CreateFile("docker-bake.hcl", bakefile, 0600),
|
||||||
@ -1314,8 +1314,8 @@ target "default" {
|
|||||||
|
|
||||||
type mdT struct {
|
type mdT struct {
|
||||||
Default struct {
|
Default struct {
|
||||||
BuildRef string `json:"buildx.build.ref"`
|
BuildRef string `json:"buildx.build.ref"`
|
||||||
BuildProvenance map[string]interface{} `json:"buildx.build.provenance"`
|
BuildProvenance map[string]any `json:"buildx.build.provenance"`
|
||||||
} `json:"default"`
|
} `json:"default"`
|
||||||
}
|
}
|
||||||
var md mdT
|
var md mdT
|
||||||
|
@ -804,8 +804,8 @@ func buildMetadataProvenance(t *testing.T, sb integration.Sandbox, metadataMode
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
type mdT struct {
|
type mdT struct {
|
||||||
BuildRef string `json:"buildx.build.ref"`
|
BuildRef string `json:"buildx.build.ref"`
|
||||||
BuildProvenance map[string]interface{} `json:"buildx.build.provenance"`
|
BuildProvenance map[string]any `json:"buildx.build.provenance"`
|
||||||
}
|
}
|
||||||
var md mdT
|
var md mdT
|
||||||
err = json.Unmarshal(dt, &md)
|
err = json.Unmarshal(dt, &md)
|
||||||
|
@ -50,7 +50,7 @@ func withDir(dir string) cmdOpt {
|
|||||||
|
|
||||||
func buildxCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
|
func buildxCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
|
||||||
cmd := exec.Command("buildx")
|
cmd := exec.Command("buildx")
|
||||||
cmd.Env = append([]string{}, os.Environ()...)
|
cmd.Env = os.Environ()
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(cmd)
|
opt(cmd)
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func buildxCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
|
|||||||
|
|
||||||
func dockerCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
|
func dockerCmd(sb integration.Sandbox, opts ...cmdOpt) *exec.Cmd {
|
||||||
cmd := exec.Command("docker")
|
cmd := exec.Command("docker")
|
||||||
cmd.Env = append([]string{}, os.Environ()...)
|
cmd.Env = os.Environ()
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(cmd)
|
opt(cmd)
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ func skipNoCompatBuildKit(t *testing.T, sb integration.Sandbox, constraint strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ptrstr(s interface{}) *string {
|
func ptrstr(s any) *string {
|
||||||
var n *string
|
var n *string
|
||||||
if reflect.ValueOf(s).Kind() == reflect.String {
|
if reflect.ValueOf(s).Kind() == reflect.String {
|
||||||
ss := s.(string)
|
ss := s.(string)
|
||||||
|
@ -45,7 +45,7 @@ func testRmMulti(t *testing.T, sb integration.Sandbox) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var builderNames []string
|
var builderNames []string
|
||||||
for i := 0; i < 3; i++ {
|
for range 3 {
|
||||||
out, err := createCmd(sb, withArgs("--driver", "docker-container"))
|
out, err := createCmd(sb, withArgs("--driver", "docker-container"))
|
||||||
require.NoError(t, err, out)
|
require.NoError(t, err, out)
|
||||||
builderName := strings.TrimSpace(out)
|
builderName := strings.TrimSpace(out)
|
||||||
|
@ -2,6 +2,7 @@ package workers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/moby/buildkit/util/testutil/integration"
|
"github.com/moby/buildkit/util/testutil/integration"
|
||||||
@ -49,23 +50,14 @@ func (s *backend) ExtraEnv() []string {
|
|||||||
|
|
||||||
func (s backend) Supports(feature string) bool {
|
func (s backend) Supports(feature string) bool {
|
||||||
if enabledFeatures := os.Getenv("BUILDKIT_TEST_ENABLE_FEATURES"); enabledFeatures != "" {
|
if enabledFeatures := os.Getenv("BUILDKIT_TEST_ENABLE_FEATURES"); enabledFeatures != "" {
|
||||||
for _, enabledFeature := range strings.Split(enabledFeatures, ",") {
|
if slices.Contains(strings.Split(enabledFeatures, ","), feature) {
|
||||||
if feature == enabledFeature {
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if disabledFeatures := os.Getenv("BUILDKIT_TEST_DISABLE_FEATURES"); disabledFeatures != "" {
|
if disabledFeatures := os.Getenv("BUILDKIT_TEST_DISABLE_FEATURES"); disabledFeatures != "" {
|
||||||
for _, disabledFeature := range strings.Split(disabledFeatures, ",") {
|
if slices.Contains(strings.Split(disabledFeatures, ","), feature) {
|
||||||
if feature == disabledFeature {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, unsupportedFeature := range s.unsupportedFeatures {
|
|
||||||
if feature == unsupportedFeature {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return !slices.Contains(s.unsupportedFeatures, feature)
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (a *Attest) ToPB() *controllerapi.Attest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Attest) MarshalJSON() ([]byte, error) {
|
func (a *Attest) MarshalJSON() ([]byte, error) {
|
||||||
m := make(map[string]interface{}, len(a.Attrs)+2)
|
m := make(map[string]any, len(a.Attrs)+2)
|
||||||
for k, v := range a.Attrs {
|
for k, v := range a.Attrs {
|
||||||
m[k] = v
|
m[k] = v
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ func (a *Attest) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Attest) UnmarshalJSON(data []byte) error {
|
func (a *Attest) UnmarshalJSON(data []byte) error {
|
||||||
var m map[string]interface{}
|
var m map[string]any
|
||||||
if err := json.Unmarshal(data, &m); err != nil {
|
if err := json.Unmarshal(data, &m); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ func (e *CacheOptionsEntry) UnmarshalText(text []byte) error {
|
|||||||
return e.validate(text)
|
return e.validate(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *CacheOptionsEntry) validate(gv interface{}) error {
|
func (e *CacheOptionsEntry) validate(gv any) error {
|
||||||
if e.Type == "" {
|
if e.Type == "" {
|
||||||
var text []byte
|
var text []byte
|
||||||
switch gv := gv.(type) {
|
switch gv := gv.(type) {
|
||||||
|
@ -33,7 +33,7 @@ func removeDupes[E comparable[E]](s []E) []E {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAndDelete(m map[string]cty.Value, attr string, gv interface{}) error {
|
func getAndDelete(m map[string]cty.Value, attr string, gv any) error {
|
||||||
if v, ok := m[attr]; ok && v.IsKnown() {
|
if v, ok := m[attr]; ok && v.IsKnown() {
|
||||||
delete(m, attr)
|
delete(m, attr)
|
||||||
return gocty.FromCtyValue(v, gv)
|
return gocty.FromCtyValue(v, gv)
|
||||||
|
@ -156,7 +156,7 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes
|
|||||||
case exptypes.AnnotationIndex:
|
case exptypes.AnnotationIndex:
|
||||||
indexAnnotation[k.Key] = v
|
indexAnnotation[k.Key] = v
|
||||||
case exptypes.AnnotationManifestDescriptor:
|
case exptypes.AnnotationManifestDescriptor:
|
||||||
for i := 0; i < len(newDescs); i++ {
|
for i := range newDescs {
|
||||||
if newDescs[i].Annotations == nil {
|
if newDescs[i].Annotations == nil {
|
||||||
newDescs[i].Annotations = map[string]string{}
|
newDescs[i].Annotations = map[string]string{}
|
||||||
}
|
}
|
||||||
|
@ -278,8 +278,8 @@ func (l *loader) scanConfig(ctx context.Context, fetcher remotes.Fetcher, desc o
|
|||||||
}
|
}
|
||||||
|
|
||||||
type sbomStub struct {
|
type sbomStub struct {
|
||||||
SPDX interface{} `json:",omitempty"`
|
SPDX any `json:",omitempty"`
|
||||||
AdditionalSPDXs []interface{} `json:",omitempty"`
|
AdditionalSPDXs []any `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
|
func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
|
||||||
@ -309,7 +309,7 @@ func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *resul
|
|||||||
}
|
}
|
||||||
|
|
||||||
var spdx struct {
|
var spdx struct {
|
||||||
Predicate interface{} `json:"predicate"`
|
Predicate any `json:"predicate"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(dt, &spdx); err != nil {
|
if err := json.Unmarshal(dt, &spdx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -330,7 +330,7 @@ func (l *loader) scanSBOM(ctx context.Context, fetcher remotes.Fetcher, r *resul
|
|||||||
}
|
}
|
||||||
|
|
||||||
type provenanceStub struct {
|
type provenanceStub struct {
|
||||||
SLSA interface{} `json:",omitempty"`
|
SLSA any `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
|
func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r *result, refs []digest.Digest, as *asset) error {
|
||||||
@ -360,7 +360,7 @@ func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
var slsa struct {
|
var slsa struct {
|
||||||
Predicate interface{} `json:"predicate"`
|
Predicate any `json:"predicate"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(dt, &slsa); err != nil {
|
if err := json.Unmarshal(dt, &slsa); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -89,7 +89,7 @@ func (p *Printer) Print(raw bool, out io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tpl, err := template.New("").Funcs(template.FuncMap{
|
tpl, err := template.New("").Funcs(template.FuncMap{
|
||||||
"json": func(v interface{}) string {
|
"json": func(v any) string {
|
||||||
b, _ := json.MarshalIndent(v, "", " ")
|
b, _ := json.MarshalIndent(v, "", " ")
|
||||||
return string(b)
|
return string(b)
|
||||||
},
|
},
|
||||||
@ -101,7 +101,7 @@ func (p *Printer) Print(raw bool, out io.Writer) error {
|
|||||||
imageconfigs := res.Configs()
|
imageconfigs := res.Configs()
|
||||||
format := tpl.Root.String()
|
format := tpl.Root.String()
|
||||||
|
|
||||||
var mfst interface{}
|
var mfst any
|
||||||
switch p.manifest.MediaType {
|
switch p.manifest.MediaType {
|
||||||
case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest:
|
case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest:
|
||||||
mfst = p.manifest
|
mfst = p.manifest
|
||||||
@ -206,7 +206,7 @@ func (p *Printer) printManifestList(out io.Writer) error {
|
|||||||
|
|
||||||
type tplInput struct {
|
type tplInput struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Manifest interface{} `json:"manifest,omitempty"`
|
Manifest any `json:"manifest,omitempty"`
|
||||||
Image *ocispecs.Image `json:"image,omitempty"`
|
Image *ocispecs.Image `json:"image,omitempty"`
|
||||||
|
|
||||||
result *result
|
result *result
|
||||||
@ -236,7 +236,7 @@ func (inp tplInput) Provenance() (provenanceStub, error) {
|
|||||||
|
|
||||||
type tplInputs struct {
|
type tplInputs struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Manifest interface{} `json:"manifest,omitempty"`
|
Manifest any `json:"manifest,omitempty"`
|
||||||
Image map[string]*ocispecs.Image `json:"image,omitempty"`
|
Image map[string]*ocispecs.Image `json:"image,omitempty"`
|
||||||
|
|
||||||
result *result
|
result *result
|
||||||
|
@ -126,7 +126,7 @@ func TestMuxIO(t *testing.T) {
|
|||||||
if tt.outputsNum != len(tt.wants) {
|
if tt.outputsNum != len(tt.wants) {
|
||||||
t.Fatalf("wants != outputsNum")
|
t.Fatalf("wants != outputsNum")
|
||||||
}
|
}
|
||||||
for i := 0; i < tt.outputsNum; i++ {
|
for i := range tt.outputsNum {
|
||||||
outBuf, out := newTestOut(i)
|
outBuf, out := newTestOut(i)
|
||||||
outBufs = append(outBufs, outBuf)
|
outBufs = append(outBufs, outBuf)
|
||||||
outs = append(outs, MuxOut{out, nil, nil})
|
outs = append(outs, MuxOut{out, nil, nil})
|
||||||
@ -304,7 +304,7 @@ func writeMasked(w io.Writer, s string) io.Writer {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
var masked string
|
var masked string
|
||||||
for i := 0; i < n; i++ {
|
for range n {
|
||||||
masked += s
|
masked += s
|
||||||
}
|
}
|
||||||
if _, err := w.Write([]byte(masked)); err != nil {
|
if _, err := w.Write([]byte(masked)); err != nil {
|
||||||
|
@ -83,9 +83,9 @@ type Log struct {
|
|||||||
|
|
||||||
// KeyValue is a key-value pair with typed value.
|
// KeyValue is a key-value pair with typed value.
|
||||||
type KeyValue struct {
|
type KeyValue struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Type ValueType `json:"type,omitempty"`
|
Type ValueType `json:"type,omitempty"`
|
||||||
Value interface{} `json:"value"`
|
Value any `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DependencyLink shows dependencies between services
|
// DependencyLink shows dependencies between services
|
||||||
|
@ -149,7 +149,7 @@ type keyValue struct {
|
|||||||
// value is a custom type used to unmarshal otel Value correctly.
|
// value is a custom type used to unmarshal otel Value correctly.
|
||||||
type value struct {
|
type value struct {
|
||||||
Type string
|
Type string
|
||||||
Value interface{}
|
Value any
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON implements json.Unmarshaler for Span which allows correctly
|
// UnmarshalJSON implements json.Unmarshaler for Span which allows correctly
|
||||||
@ -318,7 +318,7 @@ func (kv *keyValue) asAttributeKeyValue() (attribute.KeyValue, error) {
|
|||||||
switch sli := kv.Value.Value.(type) {
|
switch sli := kv.Value.Value.(type) {
|
||||||
case []string:
|
case []string:
|
||||||
strSli = sli
|
strSli = sli
|
||||||
case []interface{}:
|
case []any:
|
||||||
for i := range sli {
|
for i := range sli {
|
||||||
var v string
|
var v string
|
||||||
// best case we have a string, otherwise, cast it using
|
// best case we have a string, otherwise, cast it using
|
||||||
|
@ -131,7 +131,7 @@ func TestAsAttributeKeyValue(t *testing.T) {
|
|||||||
name: "stringslice (interface of string)",
|
name: "stringslice (interface of string)",
|
||||||
args: args{
|
args: args{
|
||||||
Type: attribute.STRINGSLICE.String(),
|
Type: attribute.STRINGSLICE.String(),
|
||||||
value: []interface{}{"value1", "value2"},
|
value: []any{"value1", "value2"},
|
||||||
},
|
},
|
||||||
want: attribute.StringSlice("key", []string{"value1", "value2"}),
|
want: attribute.StringSlice("key", []string{"value1", "value2"}),
|
||||||
},
|
},
|
||||||
@ -139,7 +139,7 @@ func TestAsAttributeKeyValue(t *testing.T) {
|
|||||||
name: "stringslice (interface mixed)",
|
name: "stringslice (interface mixed)",
|
||||||
args: args{
|
args: args{
|
||||||
Type: attribute.STRINGSLICE.String(),
|
Type: attribute.STRINGSLICE.String(),
|
||||||
value: []interface{}{"value1", 2},
|
value: []any{"value1", 2},
|
||||||
},
|
},
|
||||||
want: attribute.StringSlice("key", []string{"value1", "2"}),
|
want: attribute.StringSlice("key", []string{"value1", "2"}),
|
||||||
},
|
},
|
||||||
|
@ -27,7 +27,7 @@ type Printer struct {
|
|||||||
err error
|
err error
|
||||||
warnings []client.VertexWarning
|
warnings []client.VertexWarning
|
||||||
logMu sync.Mutex
|
logMu sync.Mutex
|
||||||
logSourceMap map[digest.Digest]interface{}
|
logSourceMap map[digest.Digest]any
|
||||||
metrics *metricWriter
|
metrics *metricWriter
|
||||||
|
|
||||||
// TODO: remove once we can use result context to pass build ref
|
// TODO: remove once we can use result context to pass build ref
|
||||||
@ -74,7 +74,7 @@ func (p *Printer) Warnings() []client.VertexWarning {
|
|||||||
return dedupWarnings(p.warnings)
|
return dedupWarnings(p.warnings)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) ValidateLogSource(dgst digest.Digest, v interface{}) bool {
|
func (p *Printer) ValidateLogSource(dgst digest.Digest, v any) bool {
|
||||||
p.logMu.Lock()
|
p.logMu.Lock()
|
||||||
defer p.logMu.Unlock()
|
defer p.logMu.Unlock()
|
||||||
src, ok := p.logSourceMap[dgst]
|
src, ok := p.logSourceMap[dgst]
|
||||||
@ -89,7 +89,7 @@ func (p *Printer) ValidateLogSource(dgst digest.Digest, v interface{}) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) ClearLogSource(v interface{}) {
|
func (p *Printer) ClearLogSource(v any) {
|
||||||
p.logMu.Lock()
|
p.logMu.Lock()
|
||||||
defer p.logMu.Unlock()
|
defer p.logMu.Unlock()
|
||||||
for d := range p.logSourceMap {
|
for d := range p.logSourceMap {
|
||||||
@ -125,7 +125,7 @@ func NewPrinter(ctx context.Context, out console.File, mode progressui.DisplayMo
|
|||||||
pw.closeOnce = sync.Once{}
|
pw.closeOnce = sync.Once{}
|
||||||
|
|
||||||
pw.logMu.Lock()
|
pw.logMu.Lock()
|
||||||
pw.logSourceMap = map[digest.Digest]interface{}{}
|
pw.logSourceMap = map[digest.Digest]any{}
|
||||||
pw.logMu.Unlock()
|
pw.logMu.Unlock()
|
||||||
|
|
||||||
resumeLogs := logutil.Pause(logrus.StandardLogger())
|
resumeLogs := logutil.Pause(logrus.StandardLogger())
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
type Writer interface {
|
type Writer interface {
|
||||||
Write(*client.SolveStatus)
|
Write(*client.SolveStatus)
|
||||||
WriteBuildRef(string, string)
|
WriteBuildRef(string, string)
|
||||||
ValidateLogSource(digest.Digest, interface{}) bool
|
ValidateLogSource(digest.Digest, any) bool
|
||||||
ClearLogSource(interface{})
|
ClearLogSource(any)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Write(w Writer, name string, f func() error) error {
|
func Write(w Writer, name string, f func() error) error {
|
||||||
|
@ -7,18 +7,18 @@ import (
|
|||||||
|
|
||||||
type Map struct {
|
type Map struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
m map[string]interface{}
|
m map[string]any
|
||||||
ch map[string]chan struct{}
|
ch map[string]chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *Map {
|
func New() *Map {
|
||||||
return &Map{
|
return &Map{
|
||||||
m: make(map[string]interface{}),
|
m: make(map[string]any),
|
||||||
ch: make(map[string]chan struct{}),
|
ch: make(map[string]chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Map) Set(key string, value interface{}) {
|
func (m *Map) Set(key string, value any) {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
defer m.mu.Unlock()
|
defer m.mu.Unlock()
|
||||||
|
|
||||||
@ -32,13 +32,13 @@ func (m *Map) Set(key string, value interface{}) {
|
|||||||
m.ch[key] = nil
|
m.ch[key] = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Map) Get(ctx context.Context, keys ...string) (map[string]interface{}, error) {
|
func (m *Map) Get(ctx context.Context, keys ...string) (map[string]any, error) {
|
||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
return map[string]interface{}{}, nil
|
return map[string]any{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(keys) > 1 {
|
if len(keys) > 1 {
|
||||||
out := make(map[string]interface{})
|
out := make(map[string]any)
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
mm, err := m.Get(ctx, key)
|
mm, err := m.Get(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,5 +70,5 @@ func (m *Map) Get(ctx context.Context, keys ...string) (map[string]interface{},
|
|||||||
res := m.m[key]
|
res := m.m[key]
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
|
|
||||||
return map[string]interface{}{key: res}, nil
|
return map[string]any{key: res}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user