summaryrefslogtreecommitdiff
path: root/internal/funcs/gcp.go
blob: d4278296c64b08c158e795609b5802a2c5e62a09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package funcs

import (
	"context"
	"sync"

	"github.com/hairyhenderson/gomplate/v4/gcp"
)

// CreateGCPFuncs -
func CreateGCPFuncs(ctx context.Context) map[string]any {
	ns := &GcpFuncs{
		ctx:     ctx,
		gcpopts: gcp.GetClientOptions(),
	}
	return map[string]any{
		"gcp": func() any { return ns },
	}
}

// GcpFuncs -
type GcpFuncs struct {
	ctx context.Context

	meta    *gcp.MetaClient
	gcpopts gcp.ClientOptions
}

// Meta -
func (a *GcpFuncs) Meta(key string, def ...string) (string, error) {
	a.meta = sync.OnceValue(func() *gcp.MetaClient {
		return gcp.NewMetaClient(a.ctx, a.gcpopts)
	})()

	return a.meta.Meta(key, def...)
}