Skip to content

Commit

Permalink
Added ACL facilities (#116)
Browse files Browse the repository at this point in the history
* Added ACL facilities
  • Loading branch information
JohnSharpe committed Jun 22, 2023
1 parent b67ebcf commit 9c85e2b
Show file tree
Hide file tree
Showing 23 changed files with 2,455 additions and 125 deletions.
28 changes: 17 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"regexp"
"strings"

"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/redis_rules"
"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/roles"
"github.com/RedisLabs/rediscloud-go-api/service/access_control_lists/users"

"github.com/RedisLabs/rediscloud-go-api/internal"
"github.com/RedisLabs/rediscloud-go-api/service/account"
"github.com/RedisLabs/rediscloud-go-api/service/cloud_accounts"
Expand All @@ -24,6 +28,10 @@ type Client struct {
Database *databases.API
Subscription *subscriptions.API
Regions *regions.API
// acl
RedisRules *redis_rules.API
Roles *roles.API
Users *users.API
}

func NewClient(configs ...Option) (*Client, error) {
Expand Down Expand Up @@ -51,18 +59,16 @@ func NewClient(configs ...Option) (*Client, error) {

t := internal.NewAPI(client, config.logger)

a := account.NewAPI(client)
c := cloud_accounts.NewAPI(client, t, config.logger)
d := databases.NewAPI(client, t, config.logger)
s := subscriptions.NewAPI(client, t, config.logger)
r := regions.NewAPI(client, t, config.logger)

return &Client{
Account: a,
CloudAccount: c,
Database: d,
Subscription: s,
Regions: r,
Account: account.NewAPI(client),
CloudAccount: cloud_accounts.NewAPI(client, t, config.logger),
Database: databases.NewAPI(client, t, config.logger),
Subscription: subscriptions.NewAPI(client, t, config.logger),
Regions: regions.NewAPI(client, t, config.logger),
// acl
RedisRules: redis_rules.NewAPI(client, t, config.logger),
Roles: roles.NewAPI(client, t, config.logger),
Users: users.NewAPI(client, t, config.logger),
}, nil
}

Expand Down
4 changes: 3 additions & 1 deletion cloud_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/http/httptest"
"testing"

"github.com/RedisLabs/rediscloud-go-api/internal"

"github.com/RedisLabs/rediscloud-go-api/redis"
"github.com/RedisLabs/rediscloud-go-api/service/cloud_accounts"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -156,7 +158,7 @@ func TestCloudAccount_Get_wraps404(t *testing.T) {
actual, err := subject.CloudAccount.Get(context.TODO(), 98765)

assert.Nil(t, actual)
assert.IsType(t, &cloud_accounts.NotFound{}, err)
assert.IsType(t, &internal.NotFound{}, err)
}

func TestCloudAccount_List(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions internal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,12 @@ func (e *Error) Error() string {

var errorStatusCode = regexp.MustCompile("^(\\d*).*$")
var _ error = &Error{}

// TaskResponse is the high-level response when a Create/Update/Delete operation is in progress.
type TaskResponse struct {
ID *string `json:"taskId,omitempty"`
}

func (o TaskResponse) String() string {
return ToString(o)
}
17 changes: 17 additions & 0 deletions internal/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"math"
"net/http"
"net/url"
"time"

Expand Down Expand Up @@ -166,3 +167,19 @@ func (e *taskNotFoundError) Error() string {
func (e taskNotFoundError) Unwrap() error {
return e.wrapped
}

func Wrap404Error(id int, entityType string, err error) error {
if v, ok := err.(*HTTPError); ok && v.StatusCode == http.StatusNotFound {
return &NotFound{ID: id, EntityType: entityType}
}
return err
}

type NotFound struct {
ID int
EntityType string
}

func (f *NotFound) Error() string {
return fmt.Sprintf("%s %d not found", f.EntityType, f.ID)
}
Loading

0 comments on commit 9c85e2b

Please sign in to comment.