From 954051ee78a038374e70e5bd11d6115c56686c1e Mon Sep 17 00:00:00 2001 From: Nathan Gaberel Date: Thu, 11 May 2023 16:32:21 -0700 Subject: [PATCH] Fix wrong pattern matching in SHOW WAREHOUSES. --- pkg/resources/warehouse.go | 8 +------- pkg/sdk/warehouse.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/resources/warehouse.go b/pkg/resources/warehouse.go index 090b3a41ce..103396fcc3 100644 --- a/pkg/resources/warehouse.go +++ b/pkg/resources/warehouse.go @@ -237,17 +237,11 @@ func ReadWarehouse(d *schema.ResourceData, meta interface{}) error { id := helpers.DecodeSnowflakeID(d.Id()).(sdk.AccountObjectIdentifier) - warehouses, err := client.Warehouses.Show(ctx, &sdk.WarehouseShowOptions{ - Like: &sdk.Like{ - Pattern: sdk.String(id.Name()), - }, - }) + w, err := client.Warehouses.ShowById(ctx, id) if err != nil { return err } - w := warehouses[0] - if err = d.Set("name", w.Name); err != nil { return err } diff --git a/pkg/sdk/warehouse.go b/pkg/sdk/warehouse.go index a843f02bdd..706ce37bf4 100644 --- a/pkg/sdk/warehouse.go +++ b/pkg/sdk/warehouse.go @@ -19,6 +19,8 @@ type Warehouses interface { Drop(ctx context.Context, id AccountObjectIdentifier, opts *WarehouseDropOptions) error // Show returns a list of warehouses. Show(ctx context.Context, opts *WarehouseShowOptions) ([]*Warehouse, error) + // Show + filter to return SHOW data for a single warehouse. + ShowById(ctx context.Context, id ObjectIdentifier) (*Warehouse, error) // Describe returns the details of a warehouse. Describe(ctx context.Context, id AccountObjectIdentifier) (*WarehouseDetails, error) } @@ -416,6 +418,24 @@ func (c *warehouses) Show(ctx context.Context, opts *WarehouseShowOptions) ([]*W return resultList, nil } +func (c *warehouses) ShowById(ctx context.Context, id ObjectIdentifier) (*Warehouse, error) { + results, err := c.Show(ctx, &WarehouseShowOptions{ + Like: &Like{ + Pattern: String(id.Name()), + }, + }) + if err != nil { + return nil, err + } + + for _, res := range results { + if res.ID().name == id.Name() { + return res, nil + } + } + return nil, ErrObjectNotExistOrAuthorized +} + type warehouseDescribeOptions struct { describe bool `ddl:"static" db:"DESCRIBE"` //lint:ignore U1000 This is used in the ddl tag warehouse bool `ddl:"static" db:"WAREHOUSE"` //lint:ignore U1000 This is used in the ddl tag