gsm

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

Go GCP Secret Manager

Go GCP Secret Manager

If you are working on GCP Secret Manager, this package is a useful place to start. It offers simple and easy integrations. Use this package to get started.


codecov License Actions Status Go Report Card Open Source Love

A simple golang package for reading, writing, deleting, storing and editing secrets on Google Cloud Secret Manager.

With extensive test coverage and benchmarks.

Features

  • Lightweight and fast
  • Native Go implementation.
  • Context based client authorization
  • Integrated API wrapper
  • Improved API error handlers
  • Improved CRUD operations on GCP Secrets

Installation

Install the package to your $GOPATH with the go tool from shell:

$ go get github.com/kioie/gcp-secret-manager

Requirements

gcp-secret-manager package tested against Go >= 1.13.x.

Usage

Import the gcp-secret-manager package

import "github.com/kioie/gcp-secret-manager"

Declare global variable ProjectID

ProjectID="<your-project-id>"

Example

package main  
  
import (  
   "fmt"  
   "github.com/kioie/gcp-secret-manager"  
)  
  
func main() {  
 //Declare ProjectID
   ProjectID = "secret-manager-test"  
   //Check if "my-secret" exists
   fmt.Println(gcp_secret_manager.SecretExists("my-secret"))  
   //Get the secret  
   result, _ := gcp_secret_manager.GetSecret("my-secret", "")  
   fmt.Println(result)
}

Contributors

Copyright © 2020 Eddy Kioi

Go GCP-SECRET-MANAGER package released under Apache License .

Documentation

Index

Constants

This section is empty.

Variables

Declare Mock funcs

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a global exported Client struct

func NewClient

func NewClient(ctx context.Context) (*Client, error)

NewClient is a global exported function that creates a new client

func (*Client) AddNewSecretVersion

func (c *Client) AddNewSecretVersion(ctx context.Context, secretName string, projectId string, payload []byte) (*pb.SecretVersion, error)

AddNewSecretVersion Adds a new Version of a secret on a secret name

func (*Client) CreateEmptySecret

func (c *Client) CreateEmptySecret(ctx context.Context, secretName string, projectId string) (*pb.Secret, error)

CreateEmptySecret function

func (*Client) CreateSecretWithData

func (c *Client) CreateSecretWithData(ctx context.Context, secretName string, payload []byte, projectId string) (*pb.SecretVersion, error)

CreateSecretWithData creates secret with data

func (*Client) DeleteSecretAndVersions

func (c *Client) DeleteSecretAndVersions(ctx context.Context, secretName string, projectId string) error

DeleteSecretAndVersions Deletes secret with all the versions included

func (*Client) DeleteSecretVersion

func (c *Client) DeleteSecretVersion(ctx context.Context, secretName string, projectId string, version string) (*pb.SecretVersion, error)

DeleteSecretVersion Deletes specific version of a secret

func (*Client) DisableSecret

func (c *Client) DisableSecret(ctx context.Context, secretName string, projectId string, version string) (*pb.SecretVersion, error)

DisableSecret Disables secret

func (*Client) EnableSecret

func (c *Client) EnableSecret(ctx context.Context, secretName string, projectId string, version string) (*pb.SecretVersion, error)

EnableSecret Enables secret

func (*Client) GetSecret

func (c *Client) GetSecret(ctx context.Context, secretName string, projectId string, version string) (*pb.SecretPayload, error)

GetSecret Gets secret data

func (*Client) GetSecretMetadata

func (c *Client) GetSecretMetadata(ctx context.Context, secretName string, projectId string, version string) (*pb.SecretVersion, error)

GetSecretMetadata Gets metadata of a secret Name

func (*Client) SecretExists

func (c *Client) SecretExists(ctx context.Context, secretName string, projectId string) bool

SecretExists Checks if secret exists

type MockClient

MockClient is the mock client

func (*MockClient) AccessSecretVersion

AccessSecretVersion Mock Access SecretVersion

func (*MockClient) AddSecretVersion

AddSecretVersion Mock Add Secret Version

func (*MockClient) Close

func (m *MockClient) Close() error

Close Mock Close Client

func (*MockClient) CreateSecret

CreateSecret Mock Create Secret Version

func (*MockClient) DeleteSecret

func (m *MockClient) DeleteSecret(ctx context.Context, req *secretmanagerpb.DeleteSecretRequest, opts ...opt.CallOption) error

DeleteSecret Mock Delete Secret

func (*MockClient) DestroySecretVersion

DestroySecretVersion Mock Destroy Secret Version

func (*MockClient) DisableSecretVersion

DisableSecretVersion Mock Disable Secret Version

func (*MockClient) EnableSecretVersion

EnableSecretVersion Mock Enable Secret Version

func (*MockClient) GetSecret

GetSecret Mock Get Secret

func (*MockClient) GetSecretVersion

GetSecretVersion Mock Get Secret Version

type SecretClient

type SecretClient interface {
	AccessSecretVersion(ctx context.Context, req *pb.AccessSecretVersionRequest, opts ...opt.CallOption) (*pb.AccessSecretVersionResponse, error)
	DestroySecretVersion(ctx context.Context, req *pb.DestroySecretVersionRequest, opts ...opt.CallOption) (*pb.SecretVersion, error)
	CreateSecret(ctx context.Context, req *pb.CreateSecretRequest, opts ...opt.CallOption) (*pb.Secret, error)
	AddSecretVersion(ctx context.Context, req *pb.AddSecretVersionRequest, opts ...opt.CallOption) (*pb.SecretVersion, error)
	DeleteSecret(ctx context.Context, req *pb.DeleteSecretRequest, opts ...opt.CallOption) error
	GetSecret(ctx context.Context, req *pb.GetSecretRequest, opts ...opt.CallOption) (*pb.Secret, error)
	GetSecretVersion(ctx context.Context, req *pb.GetSecretVersionRequest, opts ...opt.CallOption) (*pb.SecretVersion, error)
	DisableSecretVersion(ctx context.Context, req *pb.DisableSecretVersionRequest, opts ...opt.CallOption) (*pb.SecretVersion, error)
	EnableSecretVersion(ctx context.Context, req *pb.EnableSecretVersionRequest, opts ...opt.CallOption) (*pb.SecretVersion, error)
	Close() error
}

SecretClient to interface into the smc Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL