func getGCSTemplate()

in lib/notifiers/notifiers.go [391:417]


func getGCSTemplate(ctx context.Context, grf gcsReaderFactory, path string) (string, error) {
	if trm := strings.TrimPrefix(path, "gs://"); trm != path {
		// path started with the prefix
		path = trm
	} else {
		return "", 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 "", fmt.Errorf("path has incorrect format (expected form: `[gs://]bucket/path/to/object`): %q => %s", path, strings.Join(split, ", "))
	}

	bucket, object := split[0], split[1]
	r, err := grf.NewReader(ctx, bucket, object)
	if err != nil {
		return "", fmt.Errorf("failed to get reader for (bucket=%q, object=%q): %w", bucket, object, err)
	}
	defer r.Close()
	tmpl, err := decodeTemplate(r)
	if err != nil {
		return "", fmt.Errorf("failed to parse template at %q: %w", path, err)
	}

	return tmpl, nil
}