99 "log/slog"
1010 "strings"
1111
12+ "google.golang.org/grpc/codes"
13+ "google.golang.org/grpc/status"
14+
1215 "github.com/openkcm/plugin-sdk/api"
1316 "github.com/openkcm/plugin-sdk/pkg/plugin"
1417 configv1 "github.com/openkcm/plugin-sdk/proto/service/common/config/v1"
@@ -65,6 +68,10 @@ type Reconfigurable struct {
6568}
6669
6770func (r * Reconfigurable ) Reconfigure (ctx context.Context ) {
71+ if r .DataSource == nil {
72+ return
73+ }
74+
6875 if dataHash , err := ConfigurePlugin (ctx , r .Configurer , r .DataSource , r .LastHash ); err != nil {
6976 r .Log .Error ("Failed to reconfigure plugin" , "error" , err )
7077 } else if dataHash == r .LastHash {
@@ -97,7 +104,11 @@ func configurePlugin(ctx context.Context, pluginLog *slog.Logger, configurer Con
97104
98105 if ! dataSource .IsDynamic () {
99106 pluginLog .With ("reconfigurable" , false ).Info ("Configured plugin" )
100- return nil , nil
107+
108+ return & Reconfigurable {
109+ Log : pluginLog ,
110+ Configurer : configurer ,
111+ }, nil
101112 }
102113
103114 pluginLog .With ("reconfigurable" , true ).With ("hash" , dataHash ).Info ("Configured plugin" )
@@ -141,6 +152,8 @@ type configurerV1 struct {
141152 plugin.Facade
142153
143154 configv1.ConfigServiceClient
155+
156+ metadata map [string ]string
144157}
145158
146159var _ Configurer = (* configurerV1 )(nil )
@@ -155,10 +168,25 @@ func (v1 *configurerV1) Version() uint {
155168 return 1
156169}
157170
158- func (v1 * configurerV1 ) Configure (ctx context.Context , yamlConfiguration string ) error {
159- _ , err := v1 .ConfigServiceClient .Configure (ctx , & configv1.ConfigureRequest {
160- YamlConfiguration : yamlConfiguration ,
171+ func (v1 * configurerV1 ) GetMetadataByKey (key string ) any {
172+ if metadata , ok := v1 .metadata [key ]; ok {
173+ return metadata
174+ }
175+ return nil
176+ }
177+
178+ func (v1 * configurerV1 ) Configure (ctx context.Context , data string ) error {
179+ resp , err := v1 .ConfigServiceClient .Configure (ctx , & configv1.ConfigureRequest {
180+ YamlConfiguration : data ,
161181 })
182+ switch status .Code (err ) {
183+ case codes .OK :
184+ if v1 .metadata == nil {
185+ v1 .metadata = make (map [string ]string )
186+ }
187+ v1 .metadata [BuildInfoMetadata ] = extractBuildInfo (resp )
188+ }
189+
162190 return err
163191}
164192
@@ -167,3 +195,15 @@ func hashData(data string) string {
167195 _ , _ = io .Copy (h , strings .NewReader (data ))
168196 return hex .EncodeToString (h .Sum (nil )[:16 ])
169197}
198+
199+ func extractBuildInfo (resp * configv1.ConfigureResponse ) string {
200+ defer func () {
201+ _ = recover ()
202+ }()
203+
204+ if resp == nil {
205+ return ""
206+ }
207+
208+ return strings .TrimSpace (resp .GetBuildInfo ())
209+ }
0 commit comments