tvalentyn commented on code in PR #37974:
URL: https://github.com/apache/beam/pull/37974#discussion_r3184883220


##########
sdks/go/pkg/beam/artifact/options.go:
##########
@@ -0,0 +1,69 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package artifact
+
+import (
+       "context"
+
+       structpb "google.golang.org/protobuf/types/known/structpb"
+)
+
+type contextKey string
+
+const pipelineOptionsKey contextKey = "pipeline_options"
+
+// WithPipelineOptions returns a new context carrying the full pipeline 
options struct.
+func WithPipelineOptions(ctx context.Context, options *structpb.Struct) 
context.Context {
+       return context.WithValue(ctx, pipelineOptionsKey, options)
+}
+
+// PipelineOptions returns the pipeline options from the context if present.
+func PipelineOptions(ctx context.Context) *structpb.Struct {
+       options, _ := ctx.Value(pipelineOptionsKey).(*structpb.Struct)
+       return options
+}
+
+// GetExperiments extracts a list of experiments from the pipeline options.
+func GetExperiments(options *structpb.Struct) []string {
+       if options == nil {
+               return nil
+       }
+
+       // Try legacy style first
+       var exps []string
+       for _, v := range 
options.GetFields()["options"].GetStructValue().GetFields()["experiments"].GetListValue().GetValues()
 {
+               exps = append(exps, v.GetStringValue())
+       }
+       if len(exps) > 0 {
+               return exps
+       }
+
+       // Try URN style
+       for _, v := range 
options.GetFields()["beam:option:experiments:v1"].GetListValue().GetValues() {
+               exps = append(exps, v.GetStringValue())
+       }
+       return exps

Review Comment:
   i don't know if this a real failure mode but probably won't hurt to combine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to