Skip to content

Commit

Permalink
MG-2456 - Refactor auth (absmach#2409)
Browse files Browse the repository at this point in the history
Signed-off-by: Arvindh <[email protected]>
  • Loading branch information
arvindh123 authored and nyagamunene committed Oct 28, 2024
1 parent 5136390 commit 9325405
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
41 changes: 41 additions & 0 deletions channels/channelsroleactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package channels

import "github.com/absmach/magistrala/pkg/roles"

const (
ChannelUpdate roles.Action = "update"
ChannelRead roles.Action = "read"
ChannelDelete roles.Action = "delete"
ChannelSetParentGroup roles.Action = "set_parent_group"
ChannelConnectToChannel roles.Action = "connect_to_thing"
ChannelManageRole roles.Action = "manage_role"
ChannelAddRoleUsers roles.Action = "add_role_users"
ChannelRemoveRoleUsers roles.Action = "remove_role_users"
ChannelViewRoleUsers roles.Action = "view_role_users"
)

const (
BuiltInRoleAdmin = "admin"
)

func AvailableActions() []roles.Action {
return []roles.Action{
ChannelUpdate,
ChannelRead,
ChannelDelete,
ChannelSetParentGroup,
ChannelConnectToChannel,
ChannelManageRole,
ChannelAddRoleUsers,
ChannelRemoveRoleUsers,
ChannelViewRoleUsers,
}
}

func BuiltInRoles() map[roles.BuiltInRoleName][]roles.Action {
return map[roles.BuiltInRoleName][]roles.Action{
BuiltInRoleAdmin: AvailableActions(),
}
}
5 changes: 5 additions & 0 deletions cmd/users/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/absmach/magistrala/pkg/prometheus"
"github.com/absmach/magistrala/pkg/server"
httpserver "github.com/absmach/magistrala/pkg/server/http"
"github.com/absmach/magistrala/pkg/sid"
"github.com/absmach/magistrala/pkg/uuid"
"github.com/absmach/magistrala/users"
"github.com/absmach/magistrala/users/api"
Expand Down Expand Up @@ -259,6 +260,10 @@ func newService(ctx context.Context, authz mgauthz.Authorization, token grpcToke

database := pg.NewDatabase(db, dbConfig, tracer)
idp := uuid.New()
sid, err := sid.New()
if err != nil {
return nil, nil, err
}
hsr := hasher.New()

// Creating users service
Expand Down
8 changes: 8 additions & 0 deletions things/api/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) grpcThingsV1.Things
grpcThingsV1.UnsetParentGroupFromThingsRes{},
).Endpoint(),

removeChannelConnections: kitgrpc.NewClient(
conn,
svcName,
"RemoveChannelConnections",
encodeRemoveChannelConnectionsRequest,
decodeRemoveChannelConnectionsResponse,
grpcThingsV1.RemoveChannelConnectionsRes{},
).Endpoint(),
timeout: timeout,
}
}
Expand Down

0 comments on commit 9325405

Please sign in to comment.