backend/remote-state/gcloud: Make gcsBackend private.

This class is only used via the "backend".Backend interface, so there is
no need to export this type beyond the gcloud package.
This commit is contained in:
Florian Forster 2017-09-08 13:50:07 +02:00 committed by James Bardin
parent 9ec39573ee
commit 5d4e25ada4
2 changed files with 11 additions and 7 deletions

View File

@ -1,3 +1,4 @@
// Package gcloud implements remote storage of state on Google Cloud Storage (GCS).
package gcloud package gcloud
import ( import (
@ -15,7 +16,10 @@ import (
"google.golang.org/api/option" "google.golang.org/api/option"
) )
type Backend struct { // gcsBackend implements "backend".Backend for GCS.
// Input(), Validate() and Configure() are implemented by embedding *schema.Backend.
// State(), DeleteState() and States() are implemented explicitly.
type gcsBackend struct {
*schema.Backend *schema.Backend
storageClient *storage.Client storageClient *storage.Client
@ -26,7 +30,7 @@ type Backend struct {
} }
func New() backend.Backend { func New() backend.Backend {
be := &Backend{} be := &gcsBackend{}
be.Backend = &schema.Backend{ be.Backend = &schema.Backend{
ConfigureFunc: be.configure, ConfigureFunc: be.configure,
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
@ -54,7 +58,7 @@ func New() backend.Backend {
return be return be
} }
func (b *Backend) configure(ctx context.Context) error { func (b *gcsBackend) configure(ctx context.Context) error {
if b.storageClient != nil { if b.storageClient != nil {
return nil return nil
} }

View File

@ -21,7 +21,7 @@ const (
// States returns a list of names for the states found on GCS. The default // States returns a list of names for the states found on GCS. The default
// state is always returned as the first element in the slice. // state is always returned as the first element in the slice.
func (b *Backend) States() ([]string, error) { func (b *gcsBackend) States() ([]string, error) {
states := []string{backend.DefaultStateName} states := []string{backend.DefaultStateName}
bucket := b.storageClient.Bucket(b.bucketName) bucket := b.storageClient.Bucket(b.bucketName)
@ -54,7 +54,7 @@ func (b *Backend) States() ([]string, error) {
} }
// DeleteState deletes the named state. The "default" state cannot be deleted. // DeleteState deletes the named state. The "default" state cannot be deleted.
func (b *Backend) DeleteState(name string) error { func (b *gcsBackend) DeleteState(name string) error {
if name == backend.DefaultStateName { if name == backend.DefaultStateName {
return fmt.Errorf("cowardly refusing to delete the %q state", name) return fmt.Errorf("cowardly refusing to delete the %q state", name)
} }
@ -68,7 +68,7 @@ func (b *Backend) DeleteState(name string) error {
} }
// client returns a remoteClient for the named state. // client returns a remoteClient for the named state.
func (b *Backend) client(name string) (*remoteClient, error) { func (b *gcsBackend) client(name string) (*remoteClient, error) {
if name == "" { if name == "" {
return nil, fmt.Errorf("%q is not a valid state name", name) return nil, fmt.Errorf("%q is not a valid state name", name)
} }
@ -84,7 +84,7 @@ func (b *Backend) client(name string) (*remoteClient, error) {
// State reads and returns the named state from GCS. If the named state does // State reads and returns the named state from GCS. If the named state does
// not yet exist, a new state file is created. // not yet exist, a new state file is created.
func (b *Backend) State(name string) (state.State, error) { func (b *gcsBackend) State(name string) (state.State, error) {
c, err := b.client(name) c, err := b.client(name)
if err != nil { if err != nil {
return nil, err return nil, err