Skip to content

Commit

Permalink
MG-2426 - Replace generic Clients in Things service (#2476)
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <[email protected]>
Signed-off-by: Felix Gateru <[email protected]>
Co-authored-by: Felix Gateru <[email protected]>
  • Loading branch information
Musilah and felixgateru authored Nov 4, 2024
1 parent ef8631b commit 87c390d
Show file tree
Hide file tree
Showing 76 changed files with 2,454 additions and 4,621 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ jobs:
- "logger/**"
- "pkg/events/**"
pkg-clients:
- "pkg/clients/**"
pkg-errors:
- "pkg/errors/**"
Expand All @@ -178,7 +175,6 @@ jobs:
pkg-sdk:
- "pkg/sdk/**"
- "pkg/clients/**"
- "pkg/errors/**"
- "pkg/groups/**"
- "auth/**"
Expand Down Expand Up @@ -226,7 +222,6 @@ jobs:
- "auth.pb.go"
- "auth_grpc.pb.go"
- "auth/**"
- "pkg/clients/**"
- "pkg/ulid/**"
- "pkg/uuid/**"
- "pkg/events/**"
Expand All @@ -237,7 +232,6 @@ jobs:
- "auth.pb.go"
- "auth_grpc.pb.go"
- "auth/**"
- "pkg/clients/**"
- "pkg/ulid/**"
- "pkg/uuid/**"
- "pkg/events/**"
Expand Down Expand Up @@ -314,11 +308,6 @@ jobs:
run: |
go test --race -v -count=1 -coverprofile=coverage/mqtt.out ./mqtt/...
- name: Run pkg clients tests
if: steps.changes.outputs.pkg-clients == 'true' || steps.changes.outputs.workflow == 'true'
run: |
go test --race -v -count=1 -coverprofile=coverage/pkg-clients.out ./pkg/clients/...
- name: Run pkg errors tests
if: steps.changes.outputs.pkg-errors == 'true' || steps.changes.outputs.workflow == 'true'
run: |
Expand Down
3 changes: 1 addition & 2 deletions auth/api/http/domains/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/absmach/magistrala/auth"
"github.com/absmach/magistrala/pkg/apiutil"
"github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
"github.com/go-kit/kit/endpoint"
)
Expand Down Expand Up @@ -72,7 +71,7 @@ func updateDomainEndpoint(svc auth.Service) endpoint.Endpoint {
return nil, err
}

var metadata clients.Metadata
var metadata auth.Metadata
if req.Metadata != nil {
metadata = *req.Metadata
}
Expand Down
37 changes: 18 additions & 19 deletions auth/api/http/domains/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/absmach/magistrala/internal/testsutil"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/apiutil"
mgclients "github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
svcerr "github.com/absmach/magistrala/pkg/errors/service"
policies "github.com/absmach/magistrala/pkg/policies"
Expand All @@ -29,7 +28,7 @@ import (
)

var (
validCMetadata = mgclients.Metadata{"role": "client"}
validCMetadata = auth.Metadata{"role": "client"}
ID = testsutil.GenerateUUID(&testing.T{})
domain = auth.Domain{
ID: ID,
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestCreateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -128,7 +127,7 @@ func TestCreateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -142,7 +141,7 @@ func TestCreateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -157,7 +156,7 @@ func TestCreateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -171,7 +170,7 @@ func TestCreateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "",
},
Expand All @@ -185,7 +184,7 @@ func TestCreateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand Down Expand Up @@ -646,7 +645,7 @@ func TestUpdateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -660,7 +659,7 @@ func TestUpdateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -674,7 +673,7 @@ func TestUpdateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand All @@ -689,7 +688,7 @@ func TestUpdateDomain(t *testing.T) {
domain: auth.Domain{
ID: ID,
Name: "test",
Metadata: mgclients.Metadata{"role": "domain"},
Metadata: auth.Metadata{"role": "domain"},
Tags: []string{"tag1", "tag2"},
Alias: "test",
},
Expand Down Expand Up @@ -1301,11 +1300,11 @@ func TestListDomainsByUserID(t *testing.T) {
}

type respBody struct {
Err string `json:"error"`
Message string `json:"message"`
Total int `json:"total"`
Permissions []string `json:"permissions"`
ID string `json:"id"`
Tags []string `json:"tags"`
Status mgclients.Status `json:"status"`
Err string `json:"error"`
Message string `json:"message"`
Total int `json:"total"`
Permissions []string `json:"permissions"`
ID string `json:"id"`
Tags []string `json:"tags"`
Status auth.Status `json:"status"`
}
64 changes: 33 additions & 31 deletions auth/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/absmach/magistrala/pkg/clients"
svcerr "github.com/absmach/magistrala/pkg/errors/service"
"github.com/absmach/magistrala/pkg/policies"
)
Expand Down Expand Up @@ -87,41 +86,44 @@ func (s *Status) UnmarshalJSON(data []byte) error {
}

type DomainReq struct {
Name *string `json:"name,omitempty"`
Metadata *clients.Metadata `json:"metadata,omitempty"`
Tags *[]string `json:"tags,omitempty"`
Alias *string `json:"alias,omitempty"`
Status *Status `json:"status,omitempty"`
Name *string `json:"name,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Tags *[]string `json:"tags,omitempty"`
Alias *string `json:"alias,omitempty"`
Status *Status `json:"status,omitempty"`
}
type Domain struct {
ID string `json:"id"`
Name string `json:"name"`
Metadata clients.Metadata `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
Alias string `json:"alias,omitempty"`
Status Status `json:"status"`
Permission string `json:"permission,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
Metadata Metadata `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
Alias string `json:"alias,omitempty"`
Status Status `json:"status"`
Permission string `json:"permission,omitempty"`
CreatedBy string `json:"created_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedBy string `json:"updated_by,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}

// Metadata represents arbitrary JSON.
type Metadata map[string]interface{}

type Page struct {
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Name string `json:"name,omitempty"`
Order string `json:"-"`
Dir string `json:"-"`
Metadata clients.Metadata `json:"metadata,omitempty"`
Tag string `json:"tag,omitempty"`
Permission string `json:"permission,omitempty"`
Status Status `json:"status,omitempty"`
ID string `json:"id,omitempty"`
IDs []string `json:"-"`
Identity string `json:"identity,omitempty"`
SubjectID string `json:"-"`
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Name string `json:"name,omitempty"`
Order string `json:"-"`
Dir string `json:"-"`
Metadata Metadata `json:"metadata,omitempty"`
Tag string `json:"tag,omitempty"`
Permission string `json:"permission,omitempty"`
Status Status `json:"status,omitempty"`
ID string `json:"id,omitempty"`
IDs []string `json:"-"`
Identity string `json:"identity,omitempty"`
SubjectID string `json:"-"`
}

type DomainsPage struct {
Expand Down
3 changes: 1 addition & 2 deletions auth/postgres/domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/absmach/magistrala/auth"
"github.com/absmach/magistrala/pkg/apiutil"
"github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
"github.com/absmach/magistrala/pkg/postgres"
Expand Down Expand Up @@ -473,7 +472,7 @@ func toDBDomain(d auth.Domain) (dbDomain, error) {
}

func toDomain(d dbDomain) (auth.Domain, error) {
var metadata clients.Metadata
var metadata auth.Metadata
if d.Metadata != nil {
if err := json.Unmarshal([]byte(d.Metadata), &metadata); err != nil {
return auth.Domain{}, errors.Wrap(errors.ErrMalformedEntity, err)
Expand Down
5 changes: 2 additions & 3 deletions auth/postgres/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/absmach/magistrala/auth"
"github.com/absmach/magistrala/auth/postgres"
"github.com/absmach/magistrala/internal/testsutil"
"github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
"github.com/absmach/magistrala/pkg/policies"
Expand Down Expand Up @@ -813,7 +812,7 @@ func TestUpdate(t *testing.T) {
})

updatedName := "test1"
updatedMetadata := clients.Metadata{
updatedMetadata := auth.Metadata{
"test1": "test1",
}
updatedTags := []string{"test1"}
Expand Down Expand Up @@ -917,7 +916,7 @@ func TestUpdate(t *testing.T) {
domainID: domainID,
d: auth.DomainReq{
Name: &updatedName,
Metadata: &clients.Metadata{"key": make(chan int)},
Metadata: &auth.Metadata{"key": make(chan int)},
},
response: auth.Domain{},
err: repoerr.ErrUpdateEntity,
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"time"

"github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/things"
)

// Config represents Configuration entity. It wraps information about external entity
Expand Down Expand Up @@ -41,7 +41,7 @@ type Channel struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
UpdatedBy string `json:"updated_by,omitempty"`
Status clients.Status `json:"status"`
Status things.Status `json:"status"`
}

// Filter is used for the search filters.
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/postgres/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"time"

"github.com/absmach/magistrala/bootstrap"
"github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
"github.com/absmach/magistrala/pkg/postgres"
"github.com/absmach/magistrala/things"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v5/pgconn"
Expand Down Expand Up @@ -715,7 +715,7 @@ type dbChannel struct {
CreatedAt time.Time `db:"created_at"`
UpdatedAt sql.NullTime `db:"updated_at,omitempty"`
UpdatedBy sql.NullString `db:"updated_by,omitempty"`
Status clients.Status `db:"status"`
Status things.Status `db:"status"`
}

func toDBChannel(domainID string, ch bootstrap.Channel) (dbChannel, error) {
Expand Down
4 changes: 2 additions & 2 deletions cli/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cli
import (
"encoding/json"

mgclients "github.com/absmach/magistrala/pkg/clients"
"github.com/absmach/magistrala/internal/groups"
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
"github.com/spf13/cobra"
)
Expand All @@ -28,7 +28,7 @@ var cmdGroups = []cobra.Command{
logErrorCmd(*cmd, err)
return
}
group.Status = mgclients.EnabledStatus.String()
group.Status = groups.EnabledStatus.String()
group, err := sdk.CreateGroup(group, args[1], args[2])
if err != nil {
logErrorCmd(*cmd, err)
Expand Down
4 changes: 2 additions & 2 deletions cli/things.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package cli
import (
"encoding/json"

mgclients "github.com/absmach/magistrala/pkg/clients"
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
"github.com/absmach/magistrala/things"
"github.com/spf13/cobra"
)

Expand All @@ -29,7 +29,7 @@ var cmdThings = []cobra.Command{
logErrorCmd(*cmd, err)
return
}
thing.Status = mgclients.EnabledStatus.String()
thing.Status = things.EnabledStatus.String()
thing, err := sdk.CreateThing(thing, args[1], args[2])
if err != nil {
logErrorCmd(*cmd, err)
Expand Down
Loading

0 comments on commit 87c390d

Please sign in to comment.