Skip to content

Commit

Permalink
feat: support targeting Everyone group before RBAC v2 is turned on (#172
Browse files Browse the repository at this point in the history
)
  • Loading branch information
obs-gh-abhinavpappu authored Nov 18, 2024
1 parent 829e27f commit e0b8aa4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client/meta/rbac_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package meta

import (
"context"
"fmt"
"github.com/vektah/gqlparser/v2/gqlerror"

oid "github.com/observeinc/terraform-provider-observe/client/oid"
)
Expand Down Expand Up @@ -55,7 +55,14 @@ func (client *Client) LookupRbacGroup(ctx context.Context, name string) (*RbacGr
}
}
if out == nil {
return nil, fmt.Errorf("rbacgroup not found")
return nil, gqlerror.List{
&gqlerror.Error{
Message: "rbacgroup not found",
Extensions: map[string]interface{}{
"code": ErrNotFound,
},
},
}
}
return out, nil
}
Expand Down
13 changes: 13 additions & 0 deletions observe/data_source_rbac_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package observe

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -65,6 +66,18 @@ func dataSourceRbacGroupRead(ctx context.Context, data *schema.ResourceData, met
r, err = client.LookupRbacGroup(ctx, name)
}

// The Everyone group only exists if RBAC v2 is turned on for the customer.
// However, we want to support creating RBAC v2 statements before it's turned on,
// so we return the special Everyone group id 1 if name is "Everyone" and there
// is no existing v1 group called "Everyone".
if err != nil && gql.HasErrorCode(err, gql.ErrNotFound) && name == "Everyone" {
r = &gql.RbacGroup{
Id: fmt.Sprintf("o::%s:rbacgroup:%d", client.CustomerID, 1),
Name: "Everyone",
}
err = nil
}

if err != nil {
diags = diag.FromErr(err)
return
Expand Down

0 comments on commit e0b8aa4

Please sign in to comment.