Skip to content

Commit 4d3b6b5

Browse files
Merge pull request #284 from sdcio/blameConfig
Implements BlameConfig(...)
2 parents 4fd1fdf + 78245de commit 4d3b6b5

File tree

10 files changed

+370
-39
lines changed

10 files changed

+370
-39
lines changed

client/cmd/data_blameConfig.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
sdcpb "github.com/sdcio/sdc-protos/sdcpb"
9+
"github.com/spf13/cobra"
10+
"google.golang.org/protobuf/encoding/protojson"
11+
)
12+
13+
var (
14+
includeDefaults = true
15+
)
16+
17+
// dataBlameConfig represents the get-intent command
18+
var dataBlameConfig = &cobra.Command{
19+
Use: "blame",
20+
Short: "blame",
21+
SilenceUsage: true,
22+
RunE: func(cmd *cobra.Command, _ []string) error {
23+
req := &sdcpb.BlameConfigRequest{
24+
DatastoreName: datastoreName,
25+
IncludeDefaults: includeDefaults,
26+
}
27+
ctx, cancel := context.WithCancel(cmd.Context())
28+
defer cancel()
29+
dataClient, err := createDataClient(ctx, addr)
30+
if err != nil {
31+
return err
32+
}
33+
rsp, err := dataClient.BlameConfig(ctx, req)
34+
if err != nil {
35+
return err
36+
}
37+
switch format {
38+
case "":
39+
fmt.Println(rsp.GetConfigTree().ToString())
40+
case "json":
41+
opts := protojson.MarshalOptions{
42+
Indent: " ",
43+
}
44+
b, err := opts.Marshal(rsp.ConfigTree)
45+
if err != nil {
46+
fmt.Fprintf(os.Stdout, "%v", err)
47+
}
48+
fmt.Println(string(b))
49+
}
50+
return nil
51+
},
52+
}
53+
54+
func init() {
55+
dataCmd.AddCommand(dataBlameConfig)
56+
dataBlameConfig.Flags().BoolVarP(&includeDefaults, "includeDefaults", "", false, "include defaults in the blame")
57+
}

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ require (
2121
github.com/scrapli/scrapligo v1.3.3
2222
github.com/sdcio/cache v0.0.36
2323
github.com/sdcio/schema-server v0.0.30
24-
github.com/sdcio/sdc-protos v0.0.40
24+
github.com/sdcio/sdc-protos v0.0.41
2525
github.com/sdcio/yang-parser v0.0.11
2626
github.com/sirupsen/logrus v1.9.3
2727
github.com/spf13/cobra v1.9.1
2828
github.com/spf13/pflag v1.0.6
2929
go.uber.org/mock v0.5.2
30-
google.golang.org/grpc v1.72.1
30+
google.golang.org/grpc v1.73.0
3131
google.golang.org/protobuf v1.36.6
3232
gopkg.in/yaml.v2 v2.4.0
3333
sigs.k8s.io/controller-runtime v0.20.4
@@ -84,16 +84,16 @@ require (
8484
github.com/sirikothe/gotextfsm v1.0.1-0.20200816110946-6aa2cfd355e4 // indirect
8585
github.com/x448/float16 v0.8.4 // indirect
8686
go.opencensus.io v0.24.0 // indirect
87-
golang.org/x/crypto v0.33.0 // indirect
87+
golang.org/x/crypto v0.36.0 // indirect
8888
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
89-
golang.org/x/net v0.35.0 // indirect
90-
golang.org/x/oauth2 v0.26.0 // indirect
89+
golang.org/x/net v0.38.0 // indirect
90+
golang.org/x/oauth2 v0.28.0 // indirect
9191
golang.org/x/sync v0.14.0 // indirect
92-
golang.org/x/sys v0.30.0 // indirect
93-
golang.org/x/term v0.29.0 // indirect
94-
golang.org/x/text v0.22.0 // indirect
92+
golang.org/x/sys v0.31.0 // indirect
93+
golang.org/x/term v0.30.0 // indirect
94+
golang.org/x/text v0.23.0 // indirect
9595
golang.org/x/time v0.8.0 // indirect
96-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
96+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
9797
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
9898
gopkg.in/inf.v0 v0.9.1 // indirect
9999
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ github.com/sdcio/goyang v1.6.2-2 h1:qfeUKBmoKpiKAruuEc3+V8wgHKP/n1jRDEnTy23knV8=
202202
github.com/sdcio/goyang v1.6.2-2/go.mod h1:5WolITjek1NF8yrNERyVZ7jqjOClJTpO8p/+OwmETM4=
203203
github.com/sdcio/schema-server v0.0.30 h1:71/tb5T9qCC5qskbxfd3RYE/rQAyNUr2gOrU0NcsLSM=
204204
github.com/sdcio/schema-server v0.0.30/go.mod h1:q/S7DAIGTI5b7PZFlpzZ34cVXAtawVoGZtfju6uIaCo=
205-
github.com/sdcio/sdc-protos v0.0.40 h1:uexHKpoG6Td+JAg5dUlNegpOs8KYH0bsSf/tB2ACk3o=
206-
github.com/sdcio/sdc-protos v0.0.40/go.mod h1:pNoWbFaK4s478bLxQBEhjNTHJQWyEmXdhxJWMZFY7Sw=
205+
github.com/sdcio/sdc-protos v0.0.41 h1:Ftq/vQ5pPGazCsaiATBB4IP50cZN9Hk5VHniycyDc/Y=
206+
github.com/sdcio/sdc-protos v0.0.41/go.mod h1:7f8rDOqSk9HqymR1xcPrxZV7I60vlUHNi4zxD8/l2d4=
207207
github.com/sdcio/yang-parser v0.0.11 h1:cYOrojcAtcPpVhVOLlEyyu6JdeRJvND+vHCzY4hLQ6A=
208208
github.com/sdcio/yang-parser v0.0.11/go.mod h1:y/d8lg/mqSnZwaO2bkxyVuFBtuDQm9ys9hpsBs/WizU=
209209
github.com/sirikothe/gotextfsm v1.0.1-0.20200816110946-6aa2cfd355e4 h1:FHUL2HofYJuslFOQdy/JjjP36zxqIpd/dcoiwLMIs7k=
@@ -236,16 +236,16 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
236236
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
237237
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
238238
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
239-
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
240-
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
241-
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
242-
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
243-
go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A=
244-
go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU=
245-
go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk=
246-
go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w=
247-
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
248-
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
239+
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
240+
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
241+
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
242+
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
243+
go.opentelemetry.io/otel/sdk v1.35.0 h1:iPctf8iprVySXSKJffSS79eOjl9pvxV9ZqOWT0QejKY=
244+
go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg=
245+
go.opentelemetry.io/otel/sdk/metric v1.35.0 h1:1RriWBmCKgkeHEhM7a2uMjMUfP7MsOF5JpUCaEqEI9o=
246+
go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w=
247+
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
248+
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
249249
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
250250
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
251251
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -261,8 +261,8 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
261261
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
262262
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
263263
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
264-
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
265-
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
264+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
265+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
266266
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
267267
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo=
268268
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak=
@@ -281,11 +281,11 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
281281
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
282282
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
283283
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
284-
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
285-
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
284+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
285+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
286286
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
287-
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
288-
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
287+
golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc=
288+
golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
289289
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
290290
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
291291
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -302,14 +302,14 @@ golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBc
302302
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
303303
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
304304
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
305-
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
306-
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
307-
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
308-
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
305+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
306+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
307+
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
308+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
309309
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
310310
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
311-
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
312-
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
311+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
312+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
313313
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
314314
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
315315
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -335,16 +335,16 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA
335335
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
336336
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
337337
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
338-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4=
339-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ=
338+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g=
339+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A=
340340
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
341341
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
342342
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
343343
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
344344
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
345345
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
346-
google.golang.org/grpc v1.72.1 h1:HR03wO6eyZ7lknl75XlxABNVLLFc2PAb6mHlYh756mA=
347-
google.golang.org/grpc v1.72.1/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
346+
google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok=
347+
google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc=
348348
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
349349
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
350350
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

pkg/datastore/converter_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ func TestDatastore_expandUpdateLeafAsKeys(t *testing.T) {
227227

228228
schemaClient, schema, err := testhelper.InitSDCIOSchema()
229229
if err != nil {
230-
t.Fatal(err)
230+
t.Error(err)
231+
return
231232
}
232233

233234
scb := SchemaClient.NewSchemaClientBound(schema, schemaClient)
@@ -255,7 +256,8 @@ func TestDatastore_expandUpdateLeafAsKeys(t *testing.T) {
255256

256257
// compare the string arrays
257258
if diff := cmp.Diff(wantStrArr, gotStrArr); diff != "" {
258-
t.Fatalf("mismatch (-want +got)\n%s", diff)
259+
t.Errorf("mismatch (-want +got)\n%s", diff)
260+
return
259261
}
260262
})
261263
}

pkg/datastore/datastore_rpc.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,29 @@ func (d *Datastore) calculateDeviations(ctx context.Context) (<-chan *treetypes.
452452
return deviationChan, nil
453453
}
454454

455+
func (d *Datastore) BlameConfig(ctx context.Context, includeDefaults bool) (*sdcpb.BlameTreeElement, error) {
456+
// create a new TreeRoot by copying the syncTree
457+
d.syncTreeMutex.Lock()
458+
root, err := d.syncTree.DeepCopy(ctx)
459+
d.syncTreeMutex.Unlock()
460+
if err != nil {
461+
return nil, err
462+
}
463+
// load all intents
464+
_, err = d.LoadAllButRunningIntents(ctx, root)
465+
if err != nil {
466+
return nil, err
467+
}
468+
// calculate the Blame
469+
bte, err := root.BlameConfig(includeDefaults)
470+
if err != nil {
471+
return nil, err
472+
}
473+
// set the root level elements name to the target name
474+
bte.Name = d.config.Name
475+
return bte, nil
476+
}
477+
455478
// DatastoreRollbackAdapter implements the types.RollbackInterface and encapsulates the Datastore.
456479
type DatastoreRollbackAdapter struct {
457480
d *Datastore

pkg/server/datastore.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,25 @@ func (s *Server) datastoreToRsp(ctx context.Context, ds *datastore.Datastore) (*
261261
rsp.Schema = ds.Config().Schema.GetSchema()
262262
return rsp, nil
263263
}
264+
265+
func (s *Server) BlameConfig(ctx context.Context, req *sdcpb.BlameConfigRequest) (*sdcpb.BlameConfigResponse, error) {
266+
267+
if req.GetDatastoreName() == "" {
268+
return nil, status.Errorf(codes.InvalidArgument, "missing datastore name")
269+
}
270+
271+
ds, err := s.datastores.GetDataStore(req.GetDatastoreName())
272+
if err != nil {
273+
return nil, err
274+
}
275+
276+
tree, err := ds.BlameConfig(ctx, req.GetIncludeDefaults())
277+
if err != nil {
278+
return nil, err
279+
}
280+
281+
return &sdcpb.BlameConfigResponse{
282+
ConfigTree: tree,
283+
}, nil
284+
285+
}

pkg/tree/entry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type Entry interface {
154154
GetListChilds() ([]Entry, error)
155155
BreadthSearch(ctx context.Context, path string) ([]Entry, error)
156156
DeepCopy(tc *TreeContext, parent Entry) (Entry, error)
157+
BlameConfig(includeDefaults bool) (*sdcpb.BlameTreeElement, error)
157158
}
158159

159160
type EntryVisitor func(s *sharedEntryAttributes) error

pkg/tree/leaf_variants.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ func checkNotOwner(le *LeafEntry, owner string) bool {
187187
return le.Owner() != owner
188188
}
189189

190+
func (lv *LeafVariants) GetRunning() *LeafEntry {
191+
lv.lesMutex.RLock()
192+
defer lv.lesMutex.RUnlock()
193+
for _, e := range lv.les {
194+
if e.Update.Owner() == RunningIntentName {
195+
return e
196+
}
197+
}
198+
return nil
199+
}
200+
190201
// GetHighesNewUpdated returns the LeafEntry with the highes priority
191202
// nil if no leaf entry exists.
192203
func (lv *LeafVariants) GetHighestPrecedence(onlyNewOrUpdated bool, includeDefaults bool) *LeafEntry {

pkg/tree/sharedEntryAttributes.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/sdcio/data-server/pkg/utils"
1919
sdcpb "github.com/sdcio/sdc-protos/sdcpb"
2020
log "github.com/sirupsen/logrus"
21+
"google.golang.org/protobuf/proto"
2122
"google.golang.org/protobuf/types/known/emptypb"
2223
)
2324

@@ -1597,6 +1598,52 @@ func (s *sharedEntryAttributes) TreeExport(owner string) ([]*tree_persist.TreeEl
15971598
return nil, nil
15981599
}
15991600

1601+
func (s *sharedEntryAttributes) BlameConfig(includeDefaults bool) (*sdcpb.BlameTreeElement, error) {
1602+
name := s.pathElemName
1603+
if s.GetLevel() == 0 {
1604+
name = fmt.Sprintf("root")
1605+
}
1606+
result := sdcpb.NewBlameTreeElement(name)
1607+
1608+
// process Value
1609+
highestLe := s.leafVariants.GetHighestPrecedence(false, true)
1610+
if highestLe != nil {
1611+
if highestLe.Update.Owner() != DefaultsIntentName || includeDefaults {
1612+
result.SetValue(highestLe.Update.Value()).SetOwner(highestLe.Update.Owner())
1613+
1614+
// check if running equals the expected
1615+
runningLe := s.leafVariants.GetRunning()
1616+
if runningLe != nil {
1617+
if !proto.Equal(runningLe.Update.Value(), highestLe.Update.Value()) {
1618+
result.DeviationValue = runningLe.Value()
1619+
}
1620+
}
1621+
} else {
1622+
// if it is default but no default is meant to be returned
1623+
return nil, nil
1624+
}
1625+
}
1626+
1627+
// process Childs
1628+
for _, c := range s.filterActiveChoiceCaseChilds() {
1629+
childBlame, err := c.BlameConfig(includeDefaults)
1630+
if err != nil {
1631+
return nil, err
1632+
}
1633+
// if it is not meant to be added we will get nil, so check and skip in case
1634+
if childBlame != nil {
1635+
result.AddChild(childBlame)
1636+
}
1637+
}
1638+
1639+
// sort to make te output stable
1640+
slices.SortFunc(result.Childs, func(a *sdcpb.BlameTreeElement, b *sdcpb.BlameTreeElement) int {
1641+
return strings.Compare(a.GetName(), b.GetName())
1642+
})
1643+
1644+
return result, nil
1645+
}
1646+
16001647
// getKeyName checks if s is a key level element in the tree, if not an error is throw
16011648
// if it is a key level element, the name of the key is determined via the ancestor schemas
16021649
func (s *sharedEntryAttributes) getKeyName() (string, error) {

0 commit comments

Comments
 (0)