func getGCSConfig()

in lib/notifiers/notifiers.go [355:388]


func getGCSConfig(ctx context.Context, grf gcsReaderFactory, path string) (*Config, error) {
	if !gcsConfigPattern.MatchString(path) {
		return nil, fmt.Errorf("expected path %q to match pattern %v", path, gcsConfigPattern)
	}
	// if trm := strings.TrimPrefix(path, "gs://"); trm != path {
	// 	// path started with the prefix
	// 	path = trm
	// } else {
	// 	return nil, fmt.Errorf("expected %q to start with `gs://`", path)
	// }

	// split := strings.SplitN(path, "/", 2)
	// log.V(2).Infof("got path split: %+v", split)
	// if len(split) != 2 {
	// 	return nil, fmt.Errorf("path has incorrect format (expected form: `[gs://]bucket/path/to/object`): %q => %s", path, strings.Join(split, ", "))
	// }
	split := gcsConfigPattern.FindStringSubmatch(path)
	if len(split) != 3 {
		return nil, fmt.Errorf("path has incorrect format (expected form: `[gs://]bucket/path/to/object`): %q => %s", path, strings.Join(split, ", "))
	}
	bucket, object := split[1], split[2]
	r, err := grf.NewReader(ctx, bucket, object)
	if err != nil {
		return nil, fmt.Errorf("failed to get reader for (bucket=%q, object=%q): %w", bucket, object, err)
	}
	defer r.Close()

	cfg, err := decodeConfig(r)
	if err != nil {
		return nil, fmt.Errorf("failed to parse configuration from YAML at %q: %w", path, err)
	}

	return cfg, nil
}