mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00

* Reformat Policies Enpoint to Take Sub Obj Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Redirect to `policies` Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Make Delete Endpoint not to Contain Body Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove gRPC unused functions Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove Redirect Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Update CLI Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Use Switch Statement Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Uncomment Commented Parts Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Empty Line Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Remove Unused gRPC Req and Resp Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix Listing of Policies Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Rename Authorize Functions For Users and Things Service Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Authorize To CLI Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package http contains the domain concept definitions needed to support
|
|
// Mainflux http adapter service functionality.
|
|
package http
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
|
"github.com/mainflux/mainflux/pkg/messaging"
|
|
"github.com/mainflux/mainflux/things/policies"
|
|
)
|
|
|
|
// Service specifies coap service API.
|
|
type Service interface {
|
|
// Publish Messssage
|
|
Publish(ctx context.Context, token string, msg *messaging.Message) error
|
|
}
|
|
|
|
var _ Service = (*adapterService)(nil)
|
|
|
|
type adapterService struct {
|
|
publisher messaging.Publisher
|
|
things policies.AuthServiceClient
|
|
}
|
|
|
|
// New instantiates the HTTP adapter implementation.
|
|
func New(publisher messaging.Publisher, things policies.AuthServiceClient) Service {
|
|
return &adapterService{
|
|
publisher: publisher,
|
|
things: things,
|
|
}
|
|
}
|
|
|
|
func (as *adapterService) Publish(ctx context.Context, token string, msg *messaging.Message) error {
|
|
ar := &policies.AuthorizeReq{
|
|
Subject: token,
|
|
Object: msg.Channel,
|
|
Action: policies.WriteAction,
|
|
EntityType: policies.ThingEntityType,
|
|
}
|
|
res, err := as.things.Authorize(ctx, ar)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !res.GetAuthorized() {
|
|
return errors.ErrAuthorization
|
|
}
|
|
msg.Publisher = res.GetThingID()
|
|
|
|
return as.publisher.Publish(ctx, msg.Channel, msg)
|
|
}
|