Skip to content

Commit

Permalink
Changes suggested from PR review and removed dependencies to be added…
Browse files Browse the repository at this point in the history
… in a separate PR
  • Loading branch information
sandeepsukhani committed Jun 28, 2019
1 parent 0e4d09e commit f954028
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10,068 deletions.
14 changes: 10 additions & 4 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ type Config struct {
StorageTransferBasePath string
clientStorageTransfer *storagetransfer.Service

bigtableClientFactory *BigtableClientFactory
BigtableAdminBasePath string
clientBigtableInstances *bigtableadmin.ProjectsInstancesService
bigtableClientFactory *BigtableClientFactory
BigtableAdminBasePath string
// Unlike other clients, the Bigtable Admin client doesn't use a single
// service. Instead, there are several distinct services created off
// the base service object. To imitate most other handwritten clients,
// we expose those directly instead of providing the `Service` object
// as a factory.
clientBigtableProjectsInstances *bigtableadmin.ProjectsInstancesService
}

var defaultClientScopes = []string{
Expand Down Expand Up @@ -431,14 +436,15 @@ func (c *Config) LoadAndValidate() error {
}

bigtableAdminBasePath := removeBasePathVersion(c.BigtableAdminBasePath)
log.Printf("[INFO] Instantiating Google Cloud BigtableAdmin for path %s", bigtableAdminBasePath)

clientBigtable, err := bigtableadmin.NewService(context, option.WithHTTPClient(client))
if err != nil {
return err
}
clientBigtable.UserAgent = userAgent
clientBigtable.BasePath = bigtableAdminBasePath
c.clientBigtableInstances = bigtableadmin.NewProjectsInstancesService(clientBigtable)
c.clientBigtableProjectsInstances = bigtableadmin.NewProjectsInstancesService(clientBigtable)

sourceRepoClientBasePath := removeBasePathVersion(c.SourceRepoBasePath)
log.Printf("[INFO] Instantiating Google Cloud Source Repo client for path %s", sourceRepoClientBasePath)
Expand Down
8 changes: 4 additions & 4 deletions google/iam_bigtable_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func BigtableInstanceIdParseFunc(d *schema.ResourceData, config *Config) error {

func (u *BigtableInstanceIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
req := &bigtableadmin.GetIamPolicyRequest{}
p, err := u.Config.clientBigtableInstances.GetIamPolicy(u.GetResourceId(), req).Do()
p, err := u.Config.clientBigtableProjectsInstances.GetIamPolicy(u.GetResourceId(), req).Do()
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -80,7 +80,7 @@ func (u *BigtableInstanceIamUpdater) SetResourceIamPolicy(policy *cloudresourcem
}

req := &bigtableadmin.SetIamPolicyRequest{Policy: bigtablePolicy}
_, err = u.Config.clientBigtableInstances.SetIamPolicy(u.GetResourceId(), req).Do()
_, err = u.Config.clientBigtableProjectsInstances.SetIamPolicy(u.GetResourceId(), req).Do()
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -104,7 +104,7 @@ func resourceManagerToBigtablePolicy(p *cloudresourcemanager.Policy) (*bigtablea
out := &bigtableadmin.Policy{}
err := Convert(p, out)
if err != nil {
return nil, errwrap.Wrapf("Cannot convert a dataproc policy to a cloudresourcemanager policy: {{err}}", err)
return nil, errwrap.Wrapf("Cannot convert a bigtable policy to a cloudresourcemanager policy: {{err}}", err)
}
return out, nil
}
Expand All @@ -113,7 +113,7 @@ func bigtableToResourceManagerPolicy(p *bigtableadmin.Policy) (*cloudresourceman
out := &cloudresourcemanager.Policy{}
err := Convert(p, out)
if err != nil {
return nil, errwrap.Wrapf("Cannot convert a cloudresourcemanager policy to a dataproc policy: {{err}}", err)
return nil, errwrap.Wrapf("Cannot convert a cloudresourcemanager policy to a bigtable policy: {{err}}", err)
}
return out, nil
}
4 changes: 2 additions & 2 deletions google/provider_handwritten_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ var StorageTransferCustomEndpointEntry = &schema.Schema{
}

var BigtableAdminDefaultBasePath = "https://bigtableadmin.googleapis.com/v2/"
var BigtableAdminCustomEndpointEntryKey = "bigtableadmin_custom_endpoint"
var BigtableAdminCustomEndpointEntryKey = "bigtable_custom_endpoint"
var BigtableAdminCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_BIGTABLE_ADMIN_CUSTOM_ENDPOINT",
"GOOGLE_BIGTABLE_CUSTOM_ENDPOINT",
}, BigtableAdminDefaultBasePath),
}

Expand Down
Loading

0 comments on commit f954028

Please sign in to comment.