func (cl *Client) UpsertSecret(project, id string, data []byte) (string, error) {
	parent := "projects/" + project
	err := cl.ValidateSecret(project, id)
	if err != nil {
		if status.Code(err) == codes.NotFound {
			err := cl.CreateSecret(project, id)
			if err != nil {
				return "", err
			}
		} else {
			return "", err
		}
	}
	verReq := &secretmanagerpb.AddSecretVersionRequest{
		Parent: parent + "/secrets/" + id,
		Payload: &secretmanagerpb.SecretPayload{
			Data: data,
		},
	}
	verResp, err := cl.AddSecretVersion(context.TODO(), verReq)
	if err != nil {
		return "", err
	}
	splits := strings.Split(verResp.Name, "/")
	latestVersion := splits[len(splits)-1]
	return latestVersion, nil
}
UpsertSecret adds a new version to the secret specified by project, id.
It inserts a new secret if id doesn't already exist.
If successful the latest version will have 'data' as its secret value,
and returns the latest version number if successful, otherwise returns error
package client
import (
	"context"
	"github.com/golang/protobuf/ptypes"
	"google.golang.org/genproto/protobuf/field_mask"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"strings"
	"time"
	secretmanager "cloud.google.com/go/secretmanager/apiv1"
	secretmanagerpb "google.golang.org/genproto/googleapis/cloud/secretmanager/v1"
)
type Client struct {
	*secretmanager.Client
}
func NewClient(ctx context.Context) (*Client, error) {
	gsmClient, err := secretmanager.NewClient(ctx)
	if err != nil {
		return nil, err
	}
	return &Client{gsmClient}, nil
}
type Interface interface {
	ValidateSecret(project, id string) error
	ValidateSecretVersion(project, id, version string) error
	CreateSecret(project, id string) error
	UpsertSecret(project, id string, data []byte) (string, error)
	GetCreateTime(project, id, version string) (time.Time, error)
	GetSecretLabels(project, id string) (map[string]string, error)
	GetSecretVersionData(project, id, version string) ([]byte, error)
	GetSecretVersionState(project, id, version string) (secretmanagerpb.SecretVersion_State, error)
	EnableSecretVersion(project, id, version string) error
	DisableSecretVersion(project, id, version string) error
	DestroySecretVersion(project, id, version string) error
	UpsertSecretLabel(project, id, key, val string) error
	DeleteSecretLabel(project, id, key string) error
}
func (cl *Client) ValidateSecret(project, id string) error {
	ctx := context.TODO()
	name := "projects/" + project + "/secrets/" + id
	getReq := &secretmanagerpb.GetSecretRequest{
		Name: name,
	}
	_, err := cl.GetSecret(ctx, getReq)
	return err
}
func (cl *Client) ValidateSecretVersion(project, id, version string) error {
	ctx := context.TODO()
	name := "projects/" + project + "/secrets/" + id + "/versions/" + version
	getReq := &secretmanagerpb.GetSecretVersionRequest{
		Name: name,
	}
	_, err := cl.GetSecretVersion(ctx, getReq)
	return err
}
func (cl *Client) CreateSecret(project, id string) error {
	parent := "projects/" + project
	req := &secretmanagerpb.CreateSecretRequest{
		Parent:   parent,
		SecretId: id,
		Secret: &secretmanagerpb.Secret{
			Replication: &secretmanagerpb.Replication{
				Replication: &secretmanagerpb.Replication_Automatic_{
					Automatic: &secretmanagerpb.Replication_Automatic{},
				},
			},
		},
	}
	_, err := cl.Client.CreateSecret(context.TODO(), req)
	return err
}