From 9325405a4949fc0454c4cc3e1918b23c9b791d65 Mon Sep 17 00:00:00 2001 From: Arvindh <30824765+arvindh123@users.noreply.github.com> Date: Thu, 24 Oct 2024 20:11:31 +0530 Subject: [PATCH] MG-2456 - Refactor auth (#2409) Signed-off-by: Arvindh --- channels/channelsroleactions.go | 41 +++++++++++++++++++++++++++++++++ cmd/users/main.go | 5 ++++ things/api/grpc/client.go | 8 +++++++ 3 files changed, 54 insertions(+) create mode 100644 channels/channelsroleactions.go diff --git a/channels/channelsroleactions.go b/channels/channelsroleactions.go new file mode 100644 index 0000000000..5d5ddcad05 --- /dev/null +++ b/channels/channelsroleactions.go @@ -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(), + } +} diff --git a/cmd/users/main.go b/cmd/users/main.go index 0bb3bd7cb3..ceb6cd3f6d 100644 --- a/cmd/users/main.go +++ b/cmd/users/main.go @@ -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" @@ -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 diff --git a/things/api/grpc/client.go b/things/api/grpc/client.go index 9d7711b3cc..fbb98e8645 100644 --- a/things/api/grpc/client.go +++ b/things/api/grpc/client.go @@ -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, } }