mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Fix renaming issues (#17)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
* @mainflux/maintainers
|
||||
* @absmach/magistrala
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Pull request title should be `MF-XXX - description` or `NOISSUE - description` where XXX is ID of issue that this PR relate to.
|
||||
Pull request title should be `MG-XXX - description` or `NOISSUE - description` where XXX is ID of issue that this PR relate to.
|
||||
Please review the [CONTRIBUTING.md](https://github.com/absmach/magistrala/blob/master/CONTRIBUTING.md) file for detailed contributing guidelines.
|
||||
|
||||
### What does this do?
|
||||
|
||||
+1
-1
@@ -10,4 +10,4 @@ build
|
||||
tools/e2e/e2e
|
||||
tools/mqtt-bench/mqtt-bench
|
||||
tools/provision/provision
|
||||
tools/provision/mfconn.toml
|
||||
tools/provision/mgconn.toml
|
||||
|
||||
@@ -263,7 +263,7 @@ components:
|
||||
type: string
|
||||
format: uuid
|
||||
description: Corresponding Magistrala Thing ID.
|
||||
mainflux_key:
|
||||
magistrala_key:
|
||||
type: string
|
||||
format: uuid
|
||||
description: Corresponding Magistrala Thing key.
|
||||
|
||||
@@ -918,7 +918,7 @@ components:
|
||||
properties:
|
||||
identity:
|
||||
type: string
|
||||
example: admin@mainflux.com
|
||||
example: admin@magistrala.com
|
||||
description: User Identity for example email address.
|
||||
metadata:
|
||||
type: object
|
||||
@@ -1081,7 +1081,7 @@ components:
|
||||
properties:
|
||||
identity:
|
||||
type: string
|
||||
example: user@mainflux.com
|
||||
example: user@magistrala.com
|
||||
description: User Identity for example email address.
|
||||
secret:
|
||||
type: string
|
||||
@@ -1241,7 +1241,7 @@ components:
|
||||
properties:
|
||||
identity:
|
||||
type: string
|
||||
example: user@mainflux.com
|
||||
example: user@magistrala.com
|
||||
description: User Identity for example email address.
|
||||
required:
|
||||
- identity
|
||||
@@ -1266,7 +1266,7 @@ components:
|
||||
properties:
|
||||
owner:
|
||||
type: string
|
||||
example: user@mainflux.com
|
||||
example: user@magistrala.com
|
||||
description: User owner for example email address.
|
||||
required:
|
||||
- owner
|
||||
@@ -1345,7 +1345,7 @@ components:
|
||||
properties:
|
||||
identity:
|
||||
type: string
|
||||
example: user@mainflux.com
|
||||
example: user@magistrala.com
|
||||
description: User Identity for example email address.
|
||||
secret:
|
||||
type: string
|
||||
|
||||
+33
-31
@@ -1,9 +1,11 @@
|
||||
# Auth - Authentication and Authorization service
|
||||
|
||||
Auth service provides authentication features as an API for managing authentication keys as well as administering groups of entities - `things` and `users`.
|
||||
Auth service provides authentication features as an API for managing authentication keys as well as administering groups of entities - `things` and `users`.
|
||||
|
||||
## Authentication
|
||||
|
||||
# Authentication
|
||||
User service is using Auth service gRPC API to obtain login token or password reset token. Authentication key consists of the following fields:
|
||||
|
||||
- ID - key ID
|
||||
- Type - one of the three types described below
|
||||
- IssuerID - an ID of the Magistrala User who issued the key
|
||||
@@ -11,7 +13,7 @@ User service is using Auth service gRPC API to obtain login token or password re
|
||||
- IssuedAt - the timestamp when the key is issued
|
||||
- ExpiresAt - the timestamp after which the key is invalid
|
||||
|
||||
There are *three types of authentication keys*:
|
||||
There are _three types of authentication keys_:
|
||||
|
||||
- User key - keys issued to the user upon login request
|
||||
- API key - keys issued upon the user request
|
||||
@@ -21,7 +23,7 @@ Authentication keys are represented and distributed by the corresponding [JWT](j
|
||||
|
||||
User keys are issued when user logs in. Each user request (other than `registration` and `login`) contains user key that is used to authenticate the user.
|
||||
|
||||
API keys are similar to the User keys. The main difference is that API keys have configurable expiration time. If no time is set, the key will never expire. For that reason, API keys are _the only key type that can be revoked_. This also means that, despite being used as a JWT, it requires a query to the database to validate the API key. The user with API key can perform all the same actions as the user with login key (can act on behalf of the user for Thing, Channel, or user profile management), *except issuing new API keys*.
|
||||
API keys are similar to the User keys. The main difference is that API keys have configurable expiration time. If no time is set, the key will never expire. For that reason, API keys are _the only key type that can be revoked_. This also means that, despite being used as a JWT, it requires a query to the database to validate the API key. The user with API key can perform all the same actions as the user with login key (can act on behalf of the user for Thing, Channel, or user profile management), _except issuing new API keys_.
|
||||
|
||||
Recovery key is the password recovery key. It's short-lived token used for password recovery process.
|
||||
|
||||
@@ -35,7 +37,8 @@ The following actions are supported:
|
||||
- obtain (API keys only)
|
||||
- revoke (API keys only)
|
||||
|
||||
# Groups
|
||||
## Groups
|
||||
|
||||
User and Things service are using Auth gRPC API to get the list of ids that are part of a group. Groups can be organized as tree structure.
|
||||
Group consists of the following fields:
|
||||
|
||||
@@ -55,36 +58,35 @@ The service is configured using the environment variables presented in the
|
||||
following table. Note that any unset variables will be replaced with their
|
||||
default values.
|
||||
|
||||
| Variable | Description | Default |
|
||||
|-------------------------------|--------------------------------------------------------------------------|----------------|
|
||||
| MG_AUTH_LOG_LEVEL | Service level (debug, info, warn, error) | error |
|
||||
| MG_AUTH_DB_HOST | Database host address | localhost |
|
||||
| MG_AUTH_DB_PORT | Database host port | 5432 |
|
||||
| MG_AUTH_DB_USER | Database user | mainflux |
|
||||
| MG_AUTH_DB_PASSWORD | Database password | mainflux |
|
||||
| MG_AUTH_DB | Name of the database used by the service | auth |
|
||||
| MG_AUTH_DB_SSL_MODE | Database connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| MG_AUTH_DB_SSL_CERT | Path to the PEM encoded certificate file | |
|
||||
| MG_AUTH_DB_SSL_KEY | Path to the PEM encoded key file | |
|
||||
| MG_AUTH_DB_SSL_ROOT_CERT | Path to the PEM encoded root certificate file | |
|
||||
| MG_AUTH_HTTP_PORT | Auth service HTTP port | 8180 |
|
||||
| MG_AUTH_GRPC_PORT | Auth service gRPC port | 8181 |
|
||||
| MG_AUTH_SERVER_CERT | Path to server certificate in pem format | |
|
||||
| MG_AUTH_SERVER_KEY | Path to server key in pem format | |
|
||||
| MG_AUTH_SECRET | String used for signing tokens | auth |
|
||||
| MG_AUTH_LOGIN_TOKEN_DURATION | The login token expiration period | 10h |
|
||||
| MG_JAEGER_URL | Jaeger server URL | localhost:6831 |
|
||||
| MG_KETO_READ_REMOTE_HOST | Keto Read Host | mainflux-keto |
|
||||
| MG_KETO_WRITE_REMOTE_HOST | Keto Write Host | mainflux-keto |
|
||||
| MG_KETO_READ_REMOTE_PORT | Keto Read Port | 4466 |
|
||||
| MG_KETO_WRITE_REMOTE_PORT | Keto Write Port | 4467 |
|
||||
| Variable | Description | Default |
|
||||
| ---------------------------- | ----------------------------------------------------------------------- | -------------------------------- |
|
||||
| MG_AUTH_LOG_LEVEL | Service level (debug, info, warn, error) | error |
|
||||
| MG_AUTH_DB_HOST | Database host address | localhost |
|
||||
| MG_AUTH_DB_PORT | Database host port | 5432 |
|
||||
| MG_AUTH_DB_USER | Database user | magistrala |
|
||||
| MG_AUTH_DB_PASSWORD | Database password | magistrala |
|
||||
| MG_AUTH_DB | Name of the database used by the service | auth |
|
||||
| MG_AUTH_DB_SSL_MODE | Database connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| MG_AUTH_DB_SSL_CERT | Path to the PEM encoded certificate file | |
|
||||
| MG_AUTH_DB_SSL_KEY | Path to the PEM encoded key file | |
|
||||
| MG_AUTH_DB_SSL_ROOT_CERT | Path to the PEM encoded root certificate file | |
|
||||
| MG_AUTH_HTTP_PORT | Auth service HTTP port | 8180 |
|
||||
| MG_AUTH_GRPC_PORT | Auth service gRPC port | 8181 |
|
||||
| MG_AUTH_SERVER_CERT | Path to server certificate in pem format | |
|
||||
| MG_AUTH_SERVER_KEY | Path to server key in pem format | |
|
||||
| MG_AUTH_SECRET | String used for signing tokens | auth |
|
||||
| MG_AUTH_LOGIN_TOKEN_DURATION | The login token expiration period | 10h |
|
||||
| MG_JAEGER_URL | Jaeger server URL | <http://jaeger:14268/api/traces> |
|
||||
| MG_KETO_READ_REMOTE_HOST | Keto Read Host | magistrala-keto |
|
||||
| MG_KETO_WRITE_REMOTE_HOST | Keto Write Host | magistrala-keto |
|
||||
| MG_KETO_READ_REMOTE_PORT | Keto Read Port | 4466 |
|
||||
| MG_KETO_WRITE_REMOTE_PORT | Keto Write Port | 4467 |
|
||||
|
||||
## Deployment
|
||||
|
||||
The service itself is distributed as Docker container. Check the [`auth`](https://github.com/absmach/magistrala/blob/master/docker/docker-compose.yml#L71-L94) service section in
|
||||
The service itself is distributed as Docker container. Check the [`auth`](https://github.com/absmach/magistrala/blob/master/docker/docker-compose.yml#L71-L94) service section in
|
||||
docker-compose to see how service is deployed.
|
||||
|
||||
|
||||
To start the service outside of the container, execute the following shell script:
|
||||
|
||||
```bash
|
||||
@@ -100,7 +102,7 @@ make auth
|
||||
make install
|
||||
|
||||
# set the environment variables and run the service
|
||||
MG_AUTH_LOG_LEVEL=[Service log level] MG_AUTH_DB_HOST=[Database host address] MG_AUTH_DB_PORT=[Database host port] MG_AUTH_DB_USER=[Database user] MG_AUTH_DB_PASS=[Database password] MG_AUTH_DB=[Name of the database used by the service] MG_AUTH_DB_SSL_MODE=[SSL mode to connect to the database with] MG_AUTH_DB_SSL_CERT=[Path to the PEM encoded certificate file] MG_AUTH_DB_SSL_KEY=[Path to the PEM encoded key file] MG_AUTH_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file] MG_AUTH_HTTP_PORT=[Service HTTP port] MG_AUTH_GRPC_PORT=[Service gRPC port] MG_AUTH_SECRET=[String used for signing tokens] MG_AUTH_SERVER_CERT=[Path to server certificate] MG_AUTH_SERVER_KEY=[Path to server key] MG_JAEGER_URL=[Jaeger server URL] MG_AUTH_LOGIN_TOKEN_DURATION=[The login token expiration period] $GOBIN/mainflux-auth
|
||||
MG_AUTH_LOG_LEVEL=[Service log level] MG_AUTH_DB_HOST=[Database host address] MG_AUTH_DB_PORT=[Database host port] MG_AUTH_DB_USER=[Database user] MG_AUTH_DB_PASS=[Database password] MG_AUTH_DB=[Name of the database used by the service] MG_AUTH_DB_SSL_MODE=[SSL mode to connect to the database with] MG_AUTH_DB_SSL_CERT=[Path to the PEM encoded certificate file] MG_AUTH_DB_SSL_KEY=[Path to the PEM encoded key file] MG_AUTH_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file] MG_AUTH_HTTP_PORT=[Service HTTP port] MG_AUTH_GRPC_PORT=[Service gRPC port] MG_AUTH_SECRET=[String used for signing tokens] MG_AUTH_SERVER_CERT=[Path to server certificate] MG_AUTH_SERVER_KEY=[Path to server key] MG_JAEGER_URL=[Jaeger server URL] MG_AUTH_LOGIN_TOKEN_DURATION=[The login token expiration period] $GOBIN/magistrala-auth
|
||||
```
|
||||
|
||||
If `MG_EMAIL_TEMPLATE` doesn't point to any file service will function but password reset functionality will not work.
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcapi "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/auth/jwt"
|
||||
@@ -53,7 +53,7 @@ func newService() auth.Service {
|
||||
func startGRPCServer(svc auth.Service, port int) {
|
||||
listener, _ := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||
server := grpc.NewServer()
|
||||
mainflux.RegisterAuthServiceServer(server, grpcapi.NewServer(svc))
|
||||
magistrala.RegisterAuthServiceServer(server, grpcapi.NewServer(svc))
|
||||
go func() {
|
||||
if err := server.Serve(listener); err != nil {
|
||||
panic(fmt.Sprintf("failed to serve: %s", err))
|
||||
@@ -117,7 +117,7 @@ func TestIssue(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
_, err := client.Issue(context.Background(), &mainflux.IssueReq{Id: tc.id, Type: uint32(tc.kind)})
|
||||
_, err := client.Issue(context.Background(), &magistrala.IssueReq{Id: tc.id, Type: uint32(tc.kind)})
|
||||
e, ok := status.FromError(err)
|
||||
assert.True(t, ok, "gRPC status can't be extracted from the error")
|
||||
assert.Equal(t, tc.code, e.Code(), fmt.Sprintf("%s: expected %s got %s", tc.desc, tc.code, e.Code()))
|
||||
@@ -141,49 +141,49 @@ func TestIdentify(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
token string
|
||||
idt *mainflux.IdentityRes
|
||||
idt *magistrala.IdentityRes
|
||||
err error
|
||||
code codes.Code
|
||||
}{
|
||||
{
|
||||
desc: "identify user with user token",
|
||||
token: loginToken.AccessToken,
|
||||
idt: &mainflux.IdentityRes{Id: id},
|
||||
idt: &magistrala.IdentityRes{Id: id},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
desc: "identify user with recovery token",
|
||||
token: recoveryToken.AccessToken,
|
||||
idt: &mainflux.IdentityRes{Id: id},
|
||||
idt: &magistrala.IdentityRes{Id: id},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
desc: "identify user with API token",
|
||||
token: apiToken.AccessToken,
|
||||
idt: &mainflux.IdentityRes{Id: id},
|
||||
idt: &magistrala.IdentityRes{Id: id},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
desc: "identify user with invalid user token",
|
||||
token: "invalid",
|
||||
idt: &mainflux.IdentityRes{},
|
||||
idt: &magistrala.IdentityRes{},
|
||||
err: status.Error(codes.Unauthenticated, "unauthenticated access"),
|
||||
code: codes.Unauthenticated,
|
||||
},
|
||||
{
|
||||
desc: "identify user with empty token",
|
||||
token: "",
|
||||
idt: &mainflux.IdentityRes{},
|
||||
idt: &magistrala.IdentityRes{},
|
||||
err: status.Error(codes.InvalidArgument, "received invalid token request"),
|
||||
code: codes.Unauthenticated,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
idt, err := client.Identify(context.Background(), &mainflux.IdentityReq{Token: tc.token})
|
||||
idt, err := client.Identify(context.Background(), &magistrala.IdentityReq{Token: tc.token})
|
||||
if idt != nil {
|
||||
assert.Equal(t, tc.idt, idt, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.idt, idt))
|
||||
}
|
||||
@@ -207,7 +207,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject string
|
||||
object string
|
||||
relation string
|
||||
ar *mainflux.AuthorizeRes
|
||||
ar *magistrala.AuthorizeRes
|
||||
err error
|
||||
code codes.Code
|
||||
}{
|
||||
@@ -217,7 +217,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: id,
|
||||
object: authoritiesObj,
|
||||
relation: memberRelation,
|
||||
ar: &mainflux.AuthorizeRes{Authorized: true},
|
||||
ar: &magistrala.AuthorizeRes{Authorized: true},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
@@ -227,7 +227,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: id,
|
||||
object: authoritiesObj,
|
||||
relation: "unauthorizedRelation",
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &magistrala.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.PermissionDenied,
|
||||
},
|
||||
@@ -237,7 +237,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: id,
|
||||
object: "unauthorizedobject",
|
||||
relation: memberRelation,
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &magistrala.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.PermissionDenied,
|
||||
},
|
||||
@@ -247,7 +247,7 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: "unauthorizedSubject",
|
||||
object: authoritiesObj,
|
||||
relation: memberRelation,
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &magistrala.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.PermissionDenied,
|
||||
},
|
||||
@@ -257,13 +257,13 @@ func TestAuthorize(t *testing.T) {
|
||||
subject: "",
|
||||
object: "",
|
||||
relation: "",
|
||||
ar: &mainflux.AuthorizeRes{Authorized: false},
|
||||
ar: &magistrala.AuthorizeRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.InvalidArgument,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
ar, err := client.Authorize(context.Background(), &mainflux.AuthorizeReq{Subject: tc.subject, Object: tc.object, Relation: tc.relation})
|
||||
ar, err := client.Authorize(context.Background(), &magistrala.AuthorizeReq{Subject: tc.subject, Object: tc.object, Relation: tc.relation})
|
||||
if ar != nil {
|
||||
assert.Equal(t, tc.ar, ar, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.ar, ar))
|
||||
}
|
||||
@@ -290,7 +290,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
subject string
|
||||
object string
|
||||
relation string
|
||||
ar *mainflux.AddPolicyRes
|
||||
ar *magistrala.AddPolicyRes
|
||||
err error
|
||||
code codes.Code
|
||||
}{
|
||||
@@ -300,7 +300,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
subject: id,
|
||||
object: groupAdminObj,
|
||||
relation: memberRelation,
|
||||
ar: &mainflux.AddPolicyRes{Authorized: true},
|
||||
ar: &magistrala.AddPolicyRes{Authorized: true},
|
||||
err: nil,
|
||||
code: codes.OK,
|
||||
},
|
||||
@@ -310,13 +310,13 @@ func TestAddPolicy(t *testing.T) {
|
||||
subject: "",
|
||||
object: "",
|
||||
relation: "",
|
||||
ar: &mainflux.AddPolicyRes{Authorized: false},
|
||||
ar: &magistrala.AddPolicyRes{Authorized: false},
|
||||
err: nil,
|
||||
code: codes.InvalidArgument,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
apr, err := client.AddPolicy(context.Background(), &mainflux.AddPolicyReq{Subject: tc.subject, Object: tc.object, Relation: tc.relation})
|
||||
apr, err := client.AddPolicy(context.Background(), &magistrala.AddPolicyReq{Subject: tc.subject, Object: tc.object, Relation: tc.relation})
|
||||
if apr != nil {
|
||||
assert.Equal(t, tc.ar, apr, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.ar, apr))
|
||||
}
|
||||
@@ -338,7 +338,7 @@ func TestDeletePolicy(t *testing.T) {
|
||||
readRelation := "read"
|
||||
thingID := "thing"
|
||||
|
||||
apr, err := client.AddPolicy(context.Background(), &mainflux.AddPolicyReq{Subject: id, Object: thingID, Permission: readRelation})
|
||||
apr, err := client.AddPolicy(context.Background(), &magistrala.AddPolicyReq{Subject: id, Object: thingID, Permission: readRelation})
|
||||
assert.Nil(t, err, fmt.Sprintf("Adding read policy to user expected to succeed: %s", err))
|
||||
assert.True(t, apr.GetAuthorized(), fmt.Sprintf("Adding read policy expected to make user authorized, expected %v got %v", true, apr.GetAuthorized()))
|
||||
|
||||
@@ -348,7 +348,7 @@ func TestDeletePolicy(t *testing.T) {
|
||||
subject string
|
||||
object string
|
||||
relation string
|
||||
dpr *mainflux.DeletePolicyRes
|
||||
dpr *magistrala.DeletePolicyRes
|
||||
code codes.Code
|
||||
}{
|
||||
{
|
||||
@@ -357,7 +357,7 @@ func TestDeletePolicy(t *testing.T) {
|
||||
subject: id,
|
||||
object: thingID,
|
||||
relation: readRelation,
|
||||
dpr: &mainflux.DeletePolicyRes{Deleted: true},
|
||||
dpr: &magistrala.DeletePolicyRes{Deleted: true},
|
||||
code: codes.OK,
|
||||
},
|
||||
{
|
||||
@@ -366,12 +366,12 @@ func TestDeletePolicy(t *testing.T) {
|
||||
subject: "",
|
||||
object: "",
|
||||
relation: "",
|
||||
dpr: &mainflux.DeletePolicyRes{Deleted: false},
|
||||
dpr: &magistrala.DeletePolicyRes{Deleted: false},
|
||||
code: codes.InvalidArgument,
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
dpr, err := client.DeletePolicy(context.Background(), &mainflux.DeletePolicyReq{Subject: tc.subject, Object: tc.object, Relation: tc.relation})
|
||||
dpr, err := client.DeletePolicy(context.Background(), &magistrala.DeletePolicyReq{Subject: tc.subject, Object: tc.object, Relation: tc.relation})
|
||||
e, ok := status.FromError(err)
|
||||
assert.True(t, ok, "gRPC status can't be extracted from the error")
|
||||
assert.Equal(t, tc.code, e.Code(), fmt.Sprintf("%s: expected %s got %s", tc.desc, tc.code, e.Code()))
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
)
|
||||
|
||||
var (
|
||||
_ mainflux.Response = (*issueKeyRes)(nil)
|
||||
_ mainflux.Response = (*revokeKeyRes)(nil)
|
||||
_ magistrala.Response = (*issueKeyRes)(nil)
|
||||
_ magistrala.Response = (*revokeKeyRes)(nil)
|
||||
)
|
||||
|
||||
type issueKeyRes struct {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/logger"
|
||||
@@ -73,7 +73,7 @@ func decodeKeyReq(_ context.Context, r *http.Request) (interface{}, error) {
|
||||
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
|
||||
if ar, ok := response.(mainflux.Response); ok {
|
||||
if ar, ok := response.(magistrala.Response); ok {
|
||||
for k, v := range ar.Headers() {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/logger"
|
||||
@@ -59,7 +59,7 @@ func decodePoliciesRequest(_ context.Context, r *http.Request) (interface{}, err
|
||||
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
|
||||
if ar, ok := response.(mainflux.Response); ok {
|
||||
if ar, ok := response.(magistrala.Response); ok {
|
||||
for k, v := range ar.Headers() {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ package http
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
"github.com/absmach/magistrala/auth/api/http/keys"
|
||||
"github.com/absmach/magistrala/auth/api/http/policies"
|
||||
@@ -21,7 +21,7 @@ func MakeHandler(svc auth.Service, logger logger.Logger, instanceID string) http
|
||||
mux = keys.MakeHandler(svc, mux, logger)
|
||||
mux = policies.MakeHandler(svc, mux, logger)
|
||||
|
||||
mux.GetFunc("/health", mainflux.Health("auth", instanceID))
|
||||
mux.GetFunc("/health", magistrala.Health("auth", instanceID))
|
||||
mux.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return mux
|
||||
|
||||
+7
-7
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -29,8 +29,8 @@ const (
|
||||
parentGroupRelation = "parent_group"
|
||||
viewerRelation = "viewer"
|
||||
|
||||
mainfluxObject = "magistrala"
|
||||
refreshToken = "refresh_token"
|
||||
magistralaObject = "magistrala"
|
||||
refreshToken = "refresh_token"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -96,7 +96,7 @@ var _ Service = (*service)(nil)
|
||||
|
||||
type service struct {
|
||||
keys KeyRepository
|
||||
idProvider mainflux.IDProvider
|
||||
idProvider magistrala.IDProvider
|
||||
agent PolicyAgent
|
||||
tokenizer Tokenizer
|
||||
loginDuration time.Duration
|
||||
@@ -104,7 +104,7 @@ type service struct {
|
||||
}
|
||||
|
||||
// New instantiates the auth service implementation.
|
||||
func New(keys KeyRepository, idp mainflux.IDProvider, tokenizer Tokenizer, policyAgent PolicyAgent, loginDuration, refreshDuration time.Duration) Service {
|
||||
func New(keys KeyRepository, idp magistrala.IDProvider, tokenizer Tokenizer, policyAgent PolicyAgent, loginDuration, refreshDuration time.Duration) Service {
|
||||
return &service{
|
||||
tokenizer: tokenizer,
|
||||
keys: keys,
|
||||
@@ -198,7 +198,7 @@ func (svc service) AddPolicies(ctx context.Context, token, object string, subjec
|
||||
return err
|
||||
}
|
||||
|
||||
if err := svc.Authorize(ctx, PolicyReq{Object: mainfluxObject, Subject: user}); err != nil {
|
||||
if err := svc.Authorize(ctx, PolicyReq{Object: magistralaObject, Subject: user}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ func (svc service) DeletePolicies(ctx context.Context, token, object string, sub
|
||||
}
|
||||
|
||||
// Check if the user identified by token is the admin.
|
||||
if err := svc.Authorize(ctx, PolicyReq{Object: mainfluxObject, Subject: user}); err != nil {
|
||||
if err := svc.Authorize(ctx, PolicyReq{Object: magistralaObject, Subject: user}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ const (
|
||||
secret = "secret"
|
||||
email = "test@example.com"
|
||||
id = "testID"
|
||||
groupName = "mfx"
|
||||
groupName = "mgx"
|
||||
description = "Description"
|
||||
|
||||
memberRelation = "member"
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/absmach/magistrala/auth"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
|
||||
"github.com/authzed/authzed-go/v1"
|
||||
@@ -20,10 +20,10 @@ const defRetrieveAllLimit = 1000
|
||||
type policyAgent struct {
|
||||
client *authzed.Client
|
||||
permissionClient v1.PermissionsServiceClient
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
}
|
||||
|
||||
func NewPolicyAgent(client *authzed.Client, logger mflog.Logger) auth.PolicyAgent {
|
||||
func NewPolicyAgent(client *authzed.Client, logger mglog.Logger) auth.PolicyAgent {
|
||||
return &policyAgent{
|
||||
client: client,
|
||||
permissionClient: client.PermissionsServiceClient,
|
||||
|
||||
+10
-10
@@ -22,9 +22,9 @@ Thing Configuration consists of two logical parts: the custom configuration that
|
||||
|
||||
Enabling and disabling Thing (adding Thing to/from whitelist) is as simple as connecting corresponding Magistrala Thing to the given list of Channels. Configuration keeps _state_ of the Thing:
|
||||
|
||||
| State | What it means |
|
||||
| -------- | ------------------------------------------- |
|
||||
| Inactive | Thing is created, but isn't enabled |
|
||||
| State | What it means |
|
||||
| -------- | --------------------------------------------- |
|
||||
| Inactive | Thing is created, but isn't enabled |
|
||||
| Active | Thing is able to communicate using Magistrala |
|
||||
|
||||
Switching between states `Active` and `Inactive` enables and disables Thing, respectively.
|
||||
@@ -40,8 +40,8 @@ The service is configured using the environment variables presented in the follo
|
||||
| MG_BOOTSTRAP_LOG_LEVEL | Log level for Bootstrap (debug, info, warn, error) | info |
|
||||
| MG_BOOTSTRAP_DB_HOST | Database host address | localhost |
|
||||
| MG_BOOTSTRAP_DB_PORT | Database host port | 5432 |
|
||||
| MG_BOOTSTRAP_DB_USER | Database user | mainflux |
|
||||
| MG_BOOTSTRAP_DB_PASS | Database password | mainflux |
|
||||
| MG_BOOTSTRAP_DB_USER | Database user | magistrala |
|
||||
| MG_BOOTSTRAP_DB_PASS | Database password | magistrala |
|
||||
| MG_BOOTSTRAP_DB_NAME | Name of the database used by the service | bootstrap |
|
||||
| MG_BOOTSTRAP_DB_SSL_MODE | Database connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| MG_BOOTSTRAP_DB_SSL_CERT | Path to the PEM encoded certificate file | |
|
||||
@@ -60,9 +60,9 @@ The service is configured using the environment variables presented in the follo
|
||||
| MG_AUTH_GRPC_TIMEOUT | Users service gRPC request timeout in seconds | 1s |
|
||||
| MG_AUTH_GRPC_CLIENT_TLS | Enable TLS for gRPC client | false |
|
||||
| MG_AUTH_GRPC_CA_CERTS | CA certificates for gRPC client | |
|
||||
| MG_THINGS_URL | Base url for Magistrala Things | http://localhost:9000 |
|
||||
| MG_THINGS_URL | Base url for Magistrala Things | http://localhost:9000 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_BOOTSTRAP_INSTANCE_ID | Bootstrap service instance ID | |
|
||||
|
||||
## Deployment
|
||||
@@ -76,7 +76,7 @@ To start the service outside of the container, execute the following shell scrip
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the service
|
||||
make bootstrap
|
||||
@@ -110,9 +110,9 @@ MG_AUTH_GRPC_CLIENT_TLS=[Boolean value to enable/disable client TLS] \
|
||||
MG_AUTH_GRPC_CA_CERT=[Path to trusted CAs in PEM format] \
|
||||
MG_THINGS_URL=[Base url for Magistrala Things] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_BOOTSTRAP_INSTANCE_ID=[Bootstrap instance ID] \
|
||||
$GOBIN/mainflux-bootstrap
|
||||
$GOBIN/magistrala-bootstrap
|
||||
```
|
||||
|
||||
Setting `MG_BOOTSTRAP_CA_CERTS` expects a file in PEM format of trusted CAs. This will enable TLS against the Users gRPC endpoint trusting only those CAs that are provided.
|
||||
|
||||
@@ -26,10 +26,10 @@ import (
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/internal/groups"
|
||||
chmocks "github.com/absmach/magistrala/internal/groups/mocks"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfgroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mggroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/things"
|
||||
thapi "github.com/absmach/magistrala/things/api/http"
|
||||
@@ -170,19 +170,19 @@ func dec(in []byte) ([]byte, error) {
|
||||
|
||||
func newService(url string, auth magistrala.AuthServiceClient) bootstrap.Service {
|
||||
things := mocks.NewConfigsRepository()
|
||||
config := mfsdk.Config{
|
||||
config := mgsdk.Config{
|
||||
ThingsURL: url,
|
||||
}
|
||||
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
return bootstrap.New(auth, things, sdk, encKey)
|
||||
}
|
||||
|
||||
func generateChannels() map[string]mfgroups.Group {
|
||||
channels := make(map[string]mfgroups.Group, channelsNum)
|
||||
func generateChannels() map[string]mggroups.Group {
|
||||
channels := make(map[string]mggroups.Group, channelsNum)
|
||||
for i := 0; i < channelsNum; i++ {
|
||||
id := strconv.Itoa(i + 1)
|
||||
channels[id] = mfgroups.Group{
|
||||
channels[id] = mggroups.Group{
|
||||
ID: id,
|
||||
Owner: email,
|
||||
Metadata: metadata,
|
||||
@@ -191,7 +191,7 @@ func generateChannels() map[string]mfgroups.Group {
|
||||
return channels
|
||||
}
|
||||
|
||||
func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServiceClient) {
|
||||
func newThingsService() (things.Service, mggroups.Service, magistrala.AuthServiceClient) {
|
||||
auth := new(authmocks.Service)
|
||||
thingCache := thmocks.NewCache()
|
||||
idProvider := uuid.NewMock()
|
||||
@@ -201,8 +201,8 @@ func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServic
|
||||
return things.NewService(auth, cRepo, gRepo, thingCache, idProvider), groups.NewService(gRepo, idProvider, auth), auth
|
||||
}
|
||||
|
||||
func newThingsServer(tsvc things.Service, gsvc mfgroups.Service) *httptest.Server {
|
||||
logger := mflog.NewMock()
|
||||
func newThingsServer(tsvc things.Service, gsvc mggroups.Service) *httptest.Server {
|
||||
logger := mglog.NewMock()
|
||||
mux := chi.NewRouter()
|
||||
thapi.MakeHandler(tsvc, gsvc, mux, logger, instanceID)
|
||||
|
||||
@@ -210,7 +210,7 @@ func newThingsServer(tsvc things.Service, gsvc mfgroups.Service) *httptest.Serve
|
||||
}
|
||||
|
||||
func newBootstrapServer(svc bootstrap.Service) *httptest.Server {
|
||||
logger := mflog.NewMock()
|
||||
logger := mglog.NewMock()
|
||||
mux := bsapi.MakeHandler(svc, bootstrap.NewConfigReader(encKey), logger, instanceID)
|
||||
return httptest.NewServer(mux)
|
||||
}
|
||||
@@ -354,8 +354,8 @@ func TestView(t *testing.T) {
|
||||
bs := newBootstrapServer(svc)
|
||||
c := newConfig([]bootstrap.Channel{})
|
||||
|
||||
mfChs := generateChannels()
|
||||
for id, ch := range mfChs {
|
||||
mgChs := generateChannels()
|
||||
for id, ch := range mgChs {
|
||||
c.Channels = append(c.Channels, bootstrap.Channel{
|
||||
ID: ch.ID,
|
||||
Name: fmt.Sprintf("%s%s", "name ", id),
|
||||
|
||||
@@ -11,18 +11,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
)
|
||||
|
||||
var _ bootstrap.Service = (*loggingMiddleware)(nil)
|
||||
|
||||
type loggingMiddleware struct {
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
svc bootstrap.Service
|
||||
}
|
||||
|
||||
// LoggingMiddleware adds logging facilities to the bootstrap service.
|
||||
func LoggingMiddleware(svc bootstrap.Service, logger mflog.Logger) bootstrap.Service {
|
||||
func LoggingMiddleware(svc bootstrap.Service, logger mglog.Logger) bootstrap.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) Magistrala
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
|
||||
@@ -7,16 +7,16 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
)
|
||||
|
||||
var (
|
||||
_ mainflux.Response = (*removeRes)(nil)
|
||||
_ mainflux.Response = (*configRes)(nil)
|
||||
_ mainflux.Response = (*stateRes)(nil)
|
||||
_ mainflux.Response = (*viewRes)(nil)
|
||||
_ mainflux.Response = (*listRes)(nil)
|
||||
_ magistrala.Response = (*removeRes)(nil)
|
||||
_ magistrala.Response = (*configRes)(nil)
|
||||
_ magistrala.Response = (*stateRes)(nil)
|
||||
_ magistrala.Response = (*viewRes)(nil)
|
||||
_ magistrala.Response = (*listRes)(nil)
|
||||
)
|
||||
|
||||
type removeRes struct{}
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
kithttp "github.com/go-kit/kit/transport/http"
|
||||
"github.com/go-zoo/bone"
|
||||
@@ -35,7 +35,7 @@ var (
|
||||
)
|
||||
|
||||
// MakeHandler returns a HTTP handler for API endpoints.
|
||||
func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mflog.Logger, instanceID string) http.Handler {
|
||||
func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mglog.Logger, instanceID string) http.Handler {
|
||||
opts := []kithttp.ServerOption{
|
||||
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, encodeError)),
|
||||
}
|
||||
@@ -101,7 +101,7 @@ func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mf
|
||||
encodeResponse,
|
||||
opts...), "remove"))
|
||||
|
||||
r.GetFunc("/health", mainflux.Health("bootstrap", instanceID))
|
||||
r.GetFunc("/health", magistrala.Health("bootstrap", instanceID))
|
||||
r.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return r
|
||||
@@ -230,7 +230,7 @@ func decodeEntityRequest(_ context.Context, r *http.Request) (interface{}, error
|
||||
|
||||
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
if ar, ok := response.(mainflux.Response); ok {
|
||||
if ar, ok := response.(magistrala.Response); ok {
|
||||
for k, v := range ar.Headers() {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
|
||||
// Config represents Configuration entity. It wraps information about external entity
|
||||
// as well as info about corresponding Magistrala entities.
|
||||
// MFThing represents corresponding Magistrala Thing ID.
|
||||
// MFKey is key of corresponding Magistrala Thing.
|
||||
// MFChannels is a list of Magistrala Channels corresponding Magistrala Thing connects to.
|
||||
// MGThing represents corresponding Magistrala Thing ID.
|
||||
// MGKey is key of corresponding Magistrala Thing.
|
||||
// MGChannels is a list of Magistrala Channels corresponding Magistrala Thing connects to.
|
||||
type Config struct {
|
||||
ThingID string `json:"thing_id"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
@@ -94,12 +94,12 @@ func (ce configEvent) Encode() (map[string]interface{}, error) {
|
||||
}
|
||||
|
||||
type removeConfigEvent struct {
|
||||
mfThing string
|
||||
mgThing string
|
||||
}
|
||||
|
||||
func (rce removeConfigEvent) Encode() (map[string]interface{}, error) {
|
||||
return map[string]interface{}{
|
||||
"thing_id": rce.mfThing,
|
||||
"thing_id": rce.mgThing,
|
||||
"operation": configRemove,
|
||||
}, nil
|
||||
}
|
||||
@@ -188,27 +188,27 @@ func (be bootstrapEvent) Encode() (map[string]interface{}, error) {
|
||||
}
|
||||
|
||||
type changeStateEvent struct {
|
||||
mfThing string
|
||||
mgThing string
|
||||
state bootstrap.State
|
||||
}
|
||||
|
||||
func (cse changeStateEvent) Encode() (map[string]interface{}, error) {
|
||||
return map[string]interface{}{
|
||||
"thing_id": cse.mfThing,
|
||||
"thing_id": cse.mgThing,
|
||||
"state": cse.state.String(),
|
||||
"operation": thingStateChange,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type updateConnectionsEvent struct {
|
||||
mfThing string
|
||||
mfChannels []string
|
||||
mgThing string
|
||||
mgChannels []string
|
||||
}
|
||||
|
||||
func (uce updateConnectionsEvent) Encode() (map[string]interface{}, error) {
|
||||
return map[string]interface{}{
|
||||
"thing_id": uce.mfThing,
|
||||
"channels": fmt.Sprintf("[%s]", strings.Join(uce.mfChannels, ", ")),
|
||||
"thing_id": uce.mgThing,
|
||||
"channels": fmt.Sprintf("[%s]", strings.Join(uce.mgChannels, ", ")),
|
||||
"operation": thingUpdateConnections,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/absmach/magistrala/pkg/events/store"
|
||||
)
|
||||
|
||||
const streamID = "mainflux.bootstrap"
|
||||
const streamID = "magistrala.bootstrap"
|
||||
|
||||
var _ bootstrap.Service = (*eventStore)(nil)
|
||||
|
||||
@@ -105,8 +105,8 @@ func (es *eventStore) UpdateConnections(ctx context.Context, token, id string, c
|
||||
}
|
||||
|
||||
ev := updateConnectionsEvent{
|
||||
mfThing: id,
|
||||
mfChannels: connections,
|
||||
mgThing: id,
|
||||
mgChannels: connections,
|
||||
}
|
||||
|
||||
return es.Publish(ctx, ev)
|
||||
@@ -138,7 +138,7 @@ func (es *eventStore) Remove(ctx context.Context, token, id string) error {
|
||||
}
|
||||
|
||||
ev := removeConfigEvent{
|
||||
mfThing: id,
|
||||
mgThing: id,
|
||||
}
|
||||
|
||||
return es.Publish(ctx, ev)
|
||||
@@ -170,7 +170,7 @@ func (es *eventStore) ChangeState(ctx context.Context, token, id string, state b
|
||||
}
|
||||
|
||||
ev := changeStateEvent{
|
||||
mfThing: id,
|
||||
mgThing: id,
|
||||
state: state,
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ import (
|
||||
"github.com/absmach/magistrala/bootstrap/mocks"
|
||||
"github.com/absmach/magistrala/internal/groups"
|
||||
chmocks "github.com/absmach/magistrala/internal/groups/mocks"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfgroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mggroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/things"
|
||||
thapi "github.com/absmach/magistrala/things/api/http"
|
||||
@@ -35,7 +35,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
streamID = "mainflux.bootstrap"
|
||||
streamID = "magistrala.bootstrap"
|
||||
email = "user@example.com"
|
||||
validToken = "validToken"
|
||||
channelsNum = 3
|
||||
@@ -82,15 +82,15 @@ var (
|
||||
|
||||
func newService(url string, auth magistrala.AuthServiceClient) bootstrap.Service {
|
||||
configs := mocks.NewConfigsRepository()
|
||||
config := mfsdk.Config{
|
||||
config := mgsdk.Config{
|
||||
ThingsURL: url,
|
||||
}
|
||||
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
return bootstrap.New(auth, configs, sdk, encKey)
|
||||
}
|
||||
|
||||
func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServiceClient) {
|
||||
func newThingsService() (things.Service, mggroups.Service, magistrala.AuthServiceClient) {
|
||||
auth := new(authmocks.Service)
|
||||
thingCache := thmocks.NewCache()
|
||||
idProvider := uuid.NewMock()
|
||||
@@ -100,8 +100,8 @@ func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServic
|
||||
return things.NewService(auth, cRepo, gRepo, thingCache, idProvider), groups.NewService(gRepo, idProvider, auth), auth
|
||||
}
|
||||
|
||||
func newThingsServer(tsvc things.Service, gsvc mfgroups.Service) *httptest.Server {
|
||||
logger := mflog.NewMock()
|
||||
func newThingsServer(tsvc things.Service, gsvc mggroups.Service) *httptest.Server {
|
||||
logger := mglog.NewMock()
|
||||
mux := chi.NewRouter()
|
||||
thapi.MakeHandler(tsvc, gsvc, mux, logger, instanceID)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/internal/postgres"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/jackc/pgerrcode"
|
||||
@@ -31,24 +31,24 @@ var (
|
||||
)
|
||||
|
||||
const cleanupQuery = `DELETE FROM channels ch WHERE NOT EXISTS (
|
||||
SELECT channel_id FROM connections c WHERE ch.mainflux_channel = c.channel_id);`
|
||||
SELECT channel_id FROM connections c WHERE ch.magistrala_channel = c.channel_id);`
|
||||
|
||||
var _ bootstrap.ConfigRepository = (*configRepository)(nil)
|
||||
|
||||
type configRepository struct {
|
||||
db postgres.Database
|
||||
log mflog.Logger
|
||||
log mglog.Logger
|
||||
}
|
||||
|
||||
// NewConfigRepository instantiates a PostgreSQL implementation of config
|
||||
// repository.
|
||||
func NewConfigRepository(db postgres.Database, log mflog.Logger) bootstrap.ConfigRepository {
|
||||
func NewConfigRepository(db postgres.Database, log mglog.Logger) bootstrap.ConfigRepository {
|
||||
return &configRepository{db: db, log: log}
|
||||
}
|
||||
|
||||
func (cr configRepository) Save(ctx context.Context, cfg bootstrap.Config, chsConnIDs []string) (string, error) {
|
||||
q := `INSERT INTO configs (mainflux_thing, owner, name, client_cert, client_key, ca_cert, mainflux_key, external_id, external_key, content, state)
|
||||
VALUES (:mainflux_thing, :owner, :name, :client_cert, :client_key, :ca_cert, :mainflux_key, :external_id, :external_key, :content, :state)`
|
||||
q := `INSERT INTO configs (magistrala_thing, owner, name, client_cert, client_key, ca_cert, magistrala_key, external_id, external_key, content, state)
|
||||
VALUES (:magistrala_thing, :owner, :name, :client_cert, :client_key, :ca_cert, :magistrala_key, :external_id, :external_key, :content, :state)`
|
||||
|
||||
tx, err := cr.db.BeginTxx(ctx, nil)
|
||||
if err != nil {
|
||||
@@ -86,9 +86,9 @@ func (cr configRepository) Save(ctx context.Context, cfg bootstrap.Config, chsCo
|
||||
}
|
||||
|
||||
func (cr configRepository) RetrieveByID(ctx context.Context, owner, id string) (bootstrap.Config, error) {
|
||||
q := `SELECT mainflux_thing, mainflux_key, external_id, external_key, name, content, state, client_cert, ca_cert
|
||||
q := `SELECT magistrala_thing, magistrala_key, external_id, external_key, name, content, state, client_cert, ca_cert
|
||||
FROM configs
|
||||
WHERE mainflux_thing = :mainflux_thing AND owner = :owner`
|
||||
WHERE magistrala_thing = :magistrala_thing AND owner = :owner`
|
||||
|
||||
dbcfg := dbConfig{
|
||||
ThingID: id,
|
||||
@@ -111,10 +111,10 @@ func (cr configRepository) RetrieveByID(ctx context.Context, owner, id string) (
|
||||
return bootstrap.Config{}, err
|
||||
}
|
||||
|
||||
q = `SELECT mainflux_channel, name, metadata FROM channels ch
|
||||
q = `SELECT magistrala_channel, name, metadata FROM channels ch
|
||||
INNER JOIN connections conn
|
||||
ON ch.mainflux_channel = conn.channel_id AND ch.owner = conn.config_owner
|
||||
WHERE conn.config_id = :mainflux_thing AND conn.config_owner = :owner`
|
||||
ON ch.magistrala_channel = conn.channel_id AND ch.owner = conn.config_owner
|
||||
WHERE conn.config_id = :magistrala_thing AND conn.config_owner = :owner`
|
||||
|
||||
rows, err := cr.db.NamedQueryContext(ctx, q, dbcfg)
|
||||
if err != nil {
|
||||
@@ -149,8 +149,8 @@ func (cr configRepository) RetrieveAll(ctx context.Context, owner string, filter
|
||||
search, params := cr.retrieveAll(owner, filter)
|
||||
n := len(params)
|
||||
|
||||
q := `SELECT mainflux_thing, mainflux_key, external_id, external_key, name, content, state
|
||||
FROM configs %s ORDER BY mainflux_thing LIMIT $%d OFFSET $%d`
|
||||
q := `SELECT magistrala_thing, magistrala_key, external_id, external_key, name, content, state
|
||||
FROM configs %s ORDER BY magistrala_thing LIMIT $%d OFFSET $%d`
|
||||
q = fmt.Sprintf(q, search, n+1, n+2)
|
||||
|
||||
rows, err := cr.db.QueryContext(ctx, q, append(params, limit, offset)...)
|
||||
@@ -192,7 +192,7 @@ func (cr configRepository) RetrieveAll(ctx context.Context, owner string, filter
|
||||
}
|
||||
|
||||
func (cr configRepository) RetrieveByExternalID(ctx context.Context, externalID string) (bootstrap.Config, error) {
|
||||
q := `SELECT mainflux_thing, mainflux_key, external_key, owner, name, client_cert, client_key, ca_cert, content, state
|
||||
q := `SELECT magistrala_thing, magistrala_key, external_key, owner, name, client_cert, client_key, ca_cert, content, state
|
||||
FROM configs
|
||||
WHERE external_id = :external_id`
|
||||
dbcfg := dbConfig{
|
||||
@@ -215,10 +215,10 @@ func (cr configRepository) RetrieveByExternalID(ctx context.Context, externalID
|
||||
return bootstrap.Config{}, errors.Wrap(errors.ErrViewEntity, err)
|
||||
}
|
||||
|
||||
q = `SELECT mainflux_channel, name, metadata FROM channels ch
|
||||
q = `SELECT magistrala_channel, name, metadata FROM channels ch
|
||||
INNER JOIN connections conn
|
||||
ON ch.mainflux_channel = conn.channel_id AND ch.owner = conn.config_owner
|
||||
WHERE conn.config_id = :mainflux_thing AND conn.config_owner = :owner`
|
||||
ON ch.magistrala_channel = conn.channel_id AND ch.owner = conn.config_owner
|
||||
WHERE conn.config_id = :magistrala_thing AND conn.config_owner = :owner`
|
||||
|
||||
rows, err := cr.db.NamedQueryContext(ctx, q, dbcfg)
|
||||
if err != nil {
|
||||
@@ -251,7 +251,7 @@ func (cr configRepository) RetrieveByExternalID(ctx context.Context, externalID
|
||||
}
|
||||
|
||||
func (cr configRepository) Update(ctx context.Context, cfg bootstrap.Config) error {
|
||||
q := `UPDATE configs SET name = :name, content = :content WHERE mainflux_thing = :mainflux_thing AND owner = :owner `
|
||||
q := `UPDATE configs SET name = :name, content = :content WHERE magistrala_thing = :magistrala_thing AND owner = :owner `
|
||||
|
||||
dbcfg := dbConfig{
|
||||
Name: nullString(cfg.Name),
|
||||
@@ -278,8 +278,8 @@ func (cr configRepository) Update(ctx context.Context, cfg bootstrap.Config) err
|
||||
}
|
||||
|
||||
func (cr configRepository) UpdateCert(ctx context.Context, owner, thingID, clientCert, clientKey, caCert string) (bootstrap.Config, error) {
|
||||
q := `UPDATE configs SET client_cert = :client_cert, client_key = :client_key, ca_cert = :ca_cert WHERE mainflux_thing = :mainflux_thing AND owner = :owner
|
||||
RETURNING mainflux_thing, client_cert, client_key, ca_cert`
|
||||
q := `UPDATE configs SET client_cert = :client_cert, client_key = :client_key, ca_cert = :ca_cert WHERE magistrala_thing = :magistrala_thing AND owner = :owner
|
||||
RETURNING magistrala_thing, client_cert, client_key, ca_cert`
|
||||
|
||||
dbcfg := dbConfig{
|
||||
ThingID: thingID,
|
||||
@@ -336,7 +336,7 @@ func (cr configRepository) UpdateConnections(ctx context.Context, owner, id stri
|
||||
}
|
||||
|
||||
func (cr configRepository) Remove(ctx context.Context, owner, id string) error {
|
||||
q := `DELETE FROM configs WHERE mainflux_thing = :mainflux_thing AND owner = :owner`
|
||||
q := `DELETE FROM configs WHERE magistrala_thing = :magistrala_thing AND owner = :owner`
|
||||
dbcfg := dbConfig{
|
||||
ThingID: id,
|
||||
Owner: owner,
|
||||
@@ -354,7 +354,7 @@ func (cr configRepository) Remove(ctx context.Context, owner, id string) error {
|
||||
}
|
||||
|
||||
func (cr configRepository) ChangeState(ctx context.Context, owner, id string, state bootstrap.State) error {
|
||||
q := `UPDATE configs SET state = :state WHERE mainflux_thing = :mainflux_thing AND owner = :owner;`
|
||||
q := `UPDATE configs SET state = :state WHERE magistrala_thing = :magistrala_thing AND owner = :owner;`
|
||||
|
||||
dbcfg := dbConfig{
|
||||
ThingID: id,
|
||||
@@ -390,7 +390,7 @@ func (cr configRepository) ListExisting(ctx context.Context, owner string, ids [
|
||||
return []bootstrap.Channel{}, err
|
||||
}
|
||||
|
||||
q := "SELECT mainflux_channel, name, metadata FROM channels WHERE owner = $1 AND mainflux_channel = ANY ($2)"
|
||||
q := "SELECT magistrala_channel, name, metadata FROM channels WHERE owner = $1 AND magistrala_channel = ANY ($2)"
|
||||
rows, err := cr.db.QueryxContext(ctx, q, owner, chans)
|
||||
if err != nil {
|
||||
return []bootstrap.Channel{}, errors.Wrap(errors.ErrViewEntity, err)
|
||||
@@ -416,7 +416,7 @@ func (cr configRepository) ListExisting(ctx context.Context, owner string, ids [
|
||||
}
|
||||
|
||||
func (cr configRepository) RemoveThing(ctx context.Context, id string) error {
|
||||
q := `DELETE FROM configs WHERE mainflux_thing = $1`
|
||||
q := `DELETE FROM configs WHERE magistrala_thing = $1`
|
||||
_, err := cr.db.ExecContext(ctx, q, id)
|
||||
|
||||
if _, err := cr.db.ExecContext(ctx, cleanupQuery); err != nil {
|
||||
@@ -435,7 +435,7 @@ func (cr configRepository) UpdateChannel(ctx context.Context, c bootstrap.Channe
|
||||
}
|
||||
|
||||
q := `UPDATE channels SET name = :name, metadata = :metadata, updated_at = :updated_at, updated_by = :updated_by
|
||||
WHERE mainflux_channel = :mainflux_channel`
|
||||
WHERE magistrala_channel = :magistrala_channel`
|
||||
if _, err = cr.db.NamedExecContext(ctx, q, dbch); err != nil {
|
||||
return errors.Wrap(errUpdateChannels, err)
|
||||
}
|
||||
@@ -443,7 +443,7 @@ func (cr configRepository) UpdateChannel(ctx context.Context, c bootstrap.Channe
|
||||
}
|
||||
|
||||
func (cr configRepository) RemoveChannel(ctx context.Context, id string) error {
|
||||
q := `DELETE FROM channels WHERE mainflux_channel = $1`
|
||||
q := `DELETE FROM channels WHERE magistrala_channel = $1`
|
||||
if _, err := cr.db.ExecContext(ctx, q, id); err != nil {
|
||||
return errors.Wrap(errRemoveChannels, err)
|
||||
}
|
||||
@@ -488,7 +488,7 @@ func (cr configRepository) rollback(content string, tx *sqlx.Tx) {
|
||||
}
|
||||
}
|
||||
|
||||
func insertChannels(ctx context.Context, owner string, channels []bootstrap.Channel, tx *sqlx.Tx) error {
|
||||
func insertChannels(_ context.Context, owner string, channels []bootstrap.Channel, tx *sqlx.Tx) error {
|
||||
if len(channels) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -501,8 +501,8 @@ func insertChannels(ctx context.Context, owner string, channels []bootstrap.Chan
|
||||
}
|
||||
chans = append(chans, dbch)
|
||||
}
|
||||
q := `INSERT INTO channels (mainflux_channel, owner, name, metadata, parent_id, description, created_at, updated_at, updated_by, status)
|
||||
VALUES (:mainflux_channel, :owner, :name, :metadata, :parent_id, :description, :created_at, :updated_at, :updated_by, :status)`
|
||||
q := `INSERT INTO channels (magistrala_channel, owner, name, metadata, parent_id, description, created_at, updated_at, updated_by, status)
|
||||
VALUES (:magistrala_channel, :owner, :name, :metadata, :parent_id, :description, :created_at, :updated_at, :updated_by, :status)`
|
||||
if _, err := tx.NamedExec(q, chans); err != nil {
|
||||
e := err
|
||||
if pqErr, ok := err.(*pgconn.PgError); ok && pqErr.Code == pgerrcode.UniqueViolation {
|
||||
@@ -514,7 +514,7 @@ func insertChannels(ctx context.Context, owner string, channels []bootstrap.Chan
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertConnections(ctx context.Context, cfg bootstrap.Config, connections []string, tx *sqlx.Tx) error {
|
||||
func insertConnections(_ context.Context, cfg bootstrap.Config, connections []string, tx *sqlx.Tx) error {
|
||||
if len(connections) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -536,7 +536,7 @@ func insertConnections(ctx context.Context, cfg bootstrap.Config, connections []
|
||||
return err
|
||||
}
|
||||
|
||||
func updateConnections(ctx context.Context, owner, id string, connections []string, tx *sqlx.Tx) error {
|
||||
func updateConnections(_ context.Context, owner, id string, connections []string, tx *sqlx.Tx) error {
|
||||
if len(connections) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -610,13 +610,13 @@ func nullTime(t time.Time) sql.NullTime {
|
||||
}
|
||||
|
||||
type dbConfig struct {
|
||||
ThingID string `db:"mainflux_thing"`
|
||||
ThingID string `db:"magistrala_thing"`
|
||||
Owner string `db:"owner"`
|
||||
Name sql.NullString `db:"name"`
|
||||
ClientCert sql.NullString `db:"client_cert"`
|
||||
ClientKey sql.NullString `db:"client_key"`
|
||||
CaCert sql.NullString `db:"ca_cert"`
|
||||
ThingKey string `db:"mainflux_key"`
|
||||
ThingKey string `db:"magistrala_key"`
|
||||
ExternalID string `db:"external_id"`
|
||||
ExternalKey string `db:"external_key"`
|
||||
Content sql.NullString `db:"content"`
|
||||
@@ -672,7 +672,7 @@ func toConfig(dbcfg dbConfig) bootstrap.Config {
|
||||
}
|
||||
|
||||
type dbChannel struct {
|
||||
ID string `db:"mainflux_channel"`
|
||||
ID string `db:"magistrala_channel"`
|
||||
Name sql.NullString `db:"name"`
|
||||
Owner sql.NullString `db:"owner"`
|
||||
Metadata string `db:"metadata"`
|
||||
|
||||
@@ -21,8 +21,8 @@ const numConfigs = 10
|
||||
|
||||
var (
|
||||
config = bootstrap.Config{
|
||||
ThingID: "mf-thing",
|
||||
ThingKey: "mf-key",
|
||||
ThingID: "mg-thing",
|
||||
ThingKey: "mg-key",
|
||||
ExternalID: "external-id",
|
||||
ExternalKey: "external-key",
|
||||
Owner: "user@email.com",
|
||||
|
||||
@@ -75,6 +75,14 @@ func Migration() *migrate.MemoryMigrationSource {
|
||||
`ALTER TABLE IF EXISTS channels ADD COLUMN IF NOT EXISTS status SMALLINT NOT NULL DEFAULT 0 CHECK (status >= 0)`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Id: "configs_4",
|
||||
Up: []string{
|
||||
`ALTER TABLE IF EXISTS configs RENAME COLUMN mainflux_thing TO magistrala_thing`,
|
||||
`ALTER TABLE IF EXISTS configs RENAME COLUMN mainflux_key TO magistrala_key`,
|
||||
`ALTER TABLE IF EXISTS channels RENAME COLUMN mainflux_channel TO magistrala_channel`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -11,7 +11,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -50,27 +50,27 @@ func dec(in []byte) ([]byte, error) {
|
||||
|
||||
func TestReadConfig(t *testing.T) {
|
||||
cfg := bootstrap.Config{
|
||||
ThingID: "mf_id",
|
||||
ThingID: "mg_id",
|
||||
ClientCert: "client_cert",
|
||||
ClientKey: "client_key",
|
||||
CACert: "ca_cert",
|
||||
ThingKey: "mf_key",
|
||||
ThingKey: "mg_key",
|
||||
Channels: []bootstrap.Channel{
|
||||
{
|
||||
ID: "mf_id",
|
||||
Name: "mf_name",
|
||||
ID: "mg_id",
|
||||
Name: "mg_name",
|
||||
Metadata: map[string]interface{}{"key": "value}"},
|
||||
},
|
||||
},
|
||||
Content: "content",
|
||||
}
|
||||
ret := readResp{
|
||||
ThingID: "mf_id",
|
||||
ThingKey: "mf_key",
|
||||
ThingID: "mg_id",
|
||||
ThingKey: "mg_key",
|
||||
Channels: []readChan{
|
||||
{
|
||||
ID: "mf_id",
|
||||
Name: "mf_name",
|
||||
ID: "mg_id",
|
||||
Name: "mg_name",
|
||||
Metadata: map[string]interface{}{"key": "value}"},
|
||||
},
|
||||
},
|
||||
@@ -118,7 +118,7 @@ func TestReadConfig(t *testing.T) {
|
||||
b, err := json.Marshal(res)
|
||||
assert.Nil(t, err, fmt.Sprintf("Marshalling expected to succeed: %s.\n", err))
|
||||
assert.Equal(t, tc.enc, b, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.enc, b))
|
||||
resp, ok := res.(mainflux.Response)
|
||||
resp, ok := res.(magistrala.Response)
|
||||
assert.True(t, ok, "If not encrypted, reader should return response.")
|
||||
assert.False(t, resp.Empty(), fmt.Sprintf("Response should not be empty %s.", err))
|
||||
assert.Equal(t, http.StatusOK, resp.Code(), "Default config response code should be 200.")
|
||||
|
||||
+13
-13
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -105,12 +105,12 @@ type ConfigReader interface {
|
||||
type bootstrapService struct {
|
||||
auth magistrala.AuthServiceClient
|
||||
configs ConfigRepository
|
||||
sdk mfsdk.SDK
|
||||
sdk mgsdk.SDK
|
||||
encKey []byte
|
||||
}
|
||||
|
||||
// New returns new Bootstrap service.
|
||||
func New(auth magistrala.AuthServiceClient, configs ConfigRepository, sdk mfsdk.SDK, encKey []byte) Service {
|
||||
func New(auth magistrala.AuthServiceClient, configs ConfigRepository, sdk mgsdk.SDK, encKey []byte) Service {
|
||||
return &bootstrapService{
|
||||
configs: configs,
|
||||
sdk: sdk,
|
||||
@@ -140,15 +140,15 @@ func (bs bootstrapService) Add(ctx context.Context, token string, cfg Config) (C
|
||||
}
|
||||
|
||||
id := cfg.ThingID
|
||||
mfThing, err := bs.thing(id, token)
|
||||
mgThing, err := bs.thing(id, token)
|
||||
if err != nil {
|
||||
return Config{}, errors.Wrap(errThingNotFound, err)
|
||||
}
|
||||
|
||||
cfg.ThingID = mfThing.ID
|
||||
cfg.ThingID = mgThing.ID
|
||||
cfg.Owner = owner
|
||||
cfg.State = Inactive
|
||||
cfg.ThingKey = mfThing.Credentials.Secret
|
||||
cfg.ThingKey = mgThing.Credentials.Secret
|
||||
|
||||
saved, err := bs.configs.Save(ctx, cfg, toConnect)
|
||||
if err != nil {
|
||||
@@ -240,7 +240,7 @@ func (bs bootstrapService) UpdateConnections(ctx context.Context, token, id stri
|
||||
}
|
||||
|
||||
for _, c := range connect {
|
||||
conIDs := mfsdk.Connection{
|
||||
conIDs := mgsdk.Connection{
|
||||
ChannelID: c,
|
||||
ThingID: id,
|
||||
}
|
||||
@@ -309,7 +309,7 @@ func (bs bootstrapService) ChangeState(ctx context.Context, token, id string, st
|
||||
switch state {
|
||||
case Active:
|
||||
for _, c := range cfg.Channels {
|
||||
conIDs := mfsdk.Connection{
|
||||
conIDs := mgsdk.Connection{
|
||||
ChannelID: c.ID,
|
||||
ThingID: cfg.ThingID,
|
||||
}
|
||||
@@ -374,16 +374,16 @@ func (bs bootstrapService) identify(ctx context.Context, token string) (string,
|
||||
}
|
||||
|
||||
// Method thing retrieves Magistrala Thing creating one if an empty ID is passed.
|
||||
func (bs bootstrapService) thing(id, token string) (mfsdk.Thing, error) {
|
||||
var thing mfsdk.Thing
|
||||
func (bs bootstrapService) thing(id, token string) (mgsdk.Thing, error) {
|
||||
var thing mgsdk.Thing
|
||||
var err error
|
||||
var sdkErr errors.SDKError
|
||||
|
||||
thing.ID = id
|
||||
if id == "" {
|
||||
thing, sdkErr = bs.sdk.CreateThing(mfsdk.Thing{}, token)
|
||||
thing, sdkErr = bs.sdk.CreateThing(mgsdk.Thing{}, token)
|
||||
if err != nil {
|
||||
return mfsdk.Thing{}, errors.Wrap(errCreateThing, errors.New(sdkErr.Err().Msg()))
|
||||
return mgsdk.Thing{}, errors.Wrap(errCreateThing, errors.New(sdkErr.Err().Msg()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ func (bs bootstrapService) thing(id, token string) (mfsdk.Thing, error) {
|
||||
err = errors.Wrap(errors.New(sdkErr.Msg()), errors.New(sdkErr2.Msg()))
|
||||
}
|
||||
}
|
||||
return mfsdk.Thing{}, errors.Wrap(ErrThings, err)
|
||||
return mgsdk.Thing{}, errors.Wrap(ErrThings, err)
|
||||
}
|
||||
|
||||
return thing, nil
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
"github.com/absmach/magistrala/bootstrap/mocks"
|
||||
"github.com/absmach/magistrala/internal/groups"
|
||||
chmocks "github.com/absmach/magistrala/internal/groups/mocks"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfgroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mggroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/things"
|
||||
thapi "github.com/absmach/magistrala/things/api/http"
|
||||
@@ -62,15 +62,15 @@ var (
|
||||
|
||||
func newService(url string, auth magistrala.AuthServiceClient) bootstrap.Service {
|
||||
things := mocks.NewConfigsRepository()
|
||||
config := mfsdk.Config{
|
||||
config := mgsdk.Config{
|
||||
ThingsURL: url,
|
||||
}
|
||||
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
return bootstrap.New(auth, things, sdk, encKey)
|
||||
}
|
||||
|
||||
func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServiceClient) {
|
||||
func newThingsService() (things.Service, mggroups.Service, magistrala.AuthServiceClient) {
|
||||
auth := new(authmocks.Service)
|
||||
thingCache := thmocks.NewCache()
|
||||
idProvider := uuid.NewMock()
|
||||
@@ -80,8 +80,8 @@ func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServic
|
||||
return things.NewService(auth, cRepo, gRepo, thingCache, idProvider), groups.NewService(gRepo, idProvider, auth), auth
|
||||
}
|
||||
|
||||
func newThingsServer(tsvc things.Service, gsvc mfgroups.Service) *httptest.Server {
|
||||
logger := mflog.NewMock()
|
||||
func newThingsServer(tsvc things.Service, gsvc mggroups.Service) *httptest.Server {
|
||||
logger := mglog.NewMock()
|
||||
mux := chi.NewRouter()
|
||||
thapi.MakeHandler(tsvc, gsvc, mux, logger, instanceID)
|
||||
|
||||
|
||||
@@ -11,18 +11,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/certs"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
)
|
||||
|
||||
var _ certs.Service = (*loggingMiddleware)(nil)
|
||||
|
||||
type loggingMiddleware struct {
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
svc certs.Service
|
||||
}
|
||||
|
||||
// LoggingMiddleware adds logging facilities to the bootstrap service.
|
||||
func LoggingMiddleware(svc certs.Service, logger mflog.Logger) certs.Service {
|
||||
func LoggingMiddleware(svc certs.Service, logger mglog.Logger) certs.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/certs"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/logger"
|
||||
@@ -64,7 +64,7 @@ func MakeHandler(svc certs.Service, logger logger.Logger, instanceID string) htt
|
||||
), "list_serials"))
|
||||
|
||||
r.Handle("/metrics", promhttp.Handler())
|
||||
r.GetFunc("/health", mainflux.Health("certs", instanceID))
|
||||
r.GetFunc("/health", magistrala.Health("certs", instanceID))
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func MakeHandler(svc certs.Service, logger logger.Logger, instanceID string) htt
|
||||
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
|
||||
if ar, ok := response.(mainflux.Response); ok {
|
||||
if ar, ok := response.(magistrala.Response); ok {
|
||||
for k, v := range ar.Headers() {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/certs/pki"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -47,12 +47,12 @@ type Service interface {
|
||||
type certsService struct {
|
||||
auth magistrala.AuthServiceClient
|
||||
certsRepo Repository
|
||||
sdk mfsdk.SDK
|
||||
sdk mgsdk.SDK
|
||||
pki pki.Agent
|
||||
}
|
||||
|
||||
// New returns new Certs service.
|
||||
func New(auth magistrala.AuthServiceClient, certs Repository, sdk mfsdk.SDK, pki pki.Agent) Service {
|
||||
func New(auth magistrala.AuthServiceClient, certs Repository, sdk mgsdk.SDK, pki pki.Agent) Service {
|
||||
return &certsService{
|
||||
certsRepo: certs,
|
||||
sdk: sdk,
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
chmocks "github.com/absmach/magistrala/internal/groups/mocks"
|
||||
"github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/things"
|
||||
httpapi "github.com/absmach/magistrala/things/api/http"
|
||||
@@ -49,11 +49,11 @@ func newService() (certs.Service, error) {
|
||||
tsvc, auth := newThingsService()
|
||||
server := newThingsServer(tsvc)
|
||||
|
||||
config := mfsdk.Config{
|
||||
config := mgsdk.Config{
|
||||
ThingsURL: server.URL,
|
||||
}
|
||||
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
repo := mocks.NewCertsRepository()
|
||||
|
||||
tlsCert, caCert, err := certs.LoadCertificates(caPath, caKeyPath)
|
||||
|
||||
+49
-49
@@ -15,7 +15,7 @@ make cli
|
||||
#### Get Magistrala Services Health Check
|
||||
|
||||
```bash
|
||||
mainflux-cli health <service>
|
||||
magistrala-cli health <service>
|
||||
```
|
||||
|
||||
### Users management
|
||||
@@ -23,51 +23,51 @@ mainflux-cli health <service>
|
||||
#### Create User
|
||||
|
||||
```bash
|
||||
mainflux-cli users create <user_name> <user_email> <user_password>
|
||||
magistrala-cli users create <user_name> <user_email> <user_password>
|
||||
|
||||
mainflux-cli users create <user_name> <user_email> <user_password> <user_token>
|
||||
magistrala-cli users create <user_name> <user_email> <user_password> <user_token>
|
||||
```
|
||||
|
||||
#### Login User
|
||||
|
||||
```bash
|
||||
mainflux-cli users token <user_email> <user_password>
|
||||
magistrala-cli users token <user_email> <user_password>
|
||||
```
|
||||
|
||||
#### Get User
|
||||
|
||||
```bash
|
||||
mainflux-cli users get <user_id> <user_token>
|
||||
magistrala-cli users get <user_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Users
|
||||
|
||||
```bash
|
||||
mainflux-cli users get all <user_token>
|
||||
magistrala-cli users get all <user_token>
|
||||
```
|
||||
|
||||
#### Update User Metadata
|
||||
|
||||
```bash
|
||||
mainflux-cli users update <user_id> '{"name":"value1", "metadata":{"value2": "value3"}}' <user_token>
|
||||
magistrala-cli users update <user_id> '{"name":"value1", "metadata":{"value2": "value3"}}' <user_token>
|
||||
```
|
||||
|
||||
#### Update User Password
|
||||
|
||||
```bash
|
||||
mainflux-cli users password <old_password> <password> <user_token>
|
||||
magistrala-cli users password <old_password> <password> <user_token>
|
||||
```
|
||||
|
||||
#### Enable User
|
||||
|
||||
```bash
|
||||
mainflux-cli users enable <user_id> <user_token>
|
||||
magistrala-cli users enable <user_id> <user_token>
|
||||
```
|
||||
|
||||
#### Disable User
|
||||
|
||||
```bash
|
||||
mainflux-cli users disable <user_id> <user_token>
|
||||
magistrala-cli users disable <user_id> <user_token>
|
||||
```
|
||||
|
||||
### System Provisioning
|
||||
@@ -75,19 +75,19 @@ mainflux-cli users disable <user_id> <user_token>
|
||||
#### Create Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things create '{"name":"myThing"}' <user_token>
|
||||
magistrala-cli things create '{"name":"myThing"}' <user_token>
|
||||
```
|
||||
|
||||
#### Create Thing with metadata
|
||||
|
||||
```bash
|
||||
mainflux-cli things create '{"name":"myThing", "metadata": {"key1":"value1"}}' <user_token>
|
||||
magistrala-cli things create '{"name":"myThing", "metadata": {"key1":"value1"}}' <user_token>
|
||||
```
|
||||
|
||||
#### Bulk Provision Things
|
||||
|
||||
```bash
|
||||
mainflux-cli provision things <file> <user_token>
|
||||
magistrala-cli provision things <file> <user_token>
|
||||
```
|
||||
|
||||
- `file` - A CSV or JSON file containing thing names (must have extension `.csv` or `.json`)
|
||||
@@ -131,55 +131,55 @@ With JSON you can be able to specify more fields of the channels you want to cre
|
||||
#### Update Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things update <thing_id> '{"name":"value1", "metadata":{"key1": "value2"}}' <user_token>
|
||||
magistrala-cli things update <thing_id> '{"name":"value1", "metadata":{"key1": "value2"}}' <user_token>
|
||||
```
|
||||
|
||||
#### Identify Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things identify <thing_key>
|
||||
magistrala-cli things identify <thing_key>
|
||||
```
|
||||
|
||||
#### Enable Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things enable <thing_id> <user_token>
|
||||
magistrala-cli things enable <thing_id> <user_token>
|
||||
```
|
||||
|
||||
#### Disable Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things disable <thing_id> <user_token>
|
||||
magistrala-cli things disable <thing_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things get <thing_id> <user_token>
|
||||
magistrala-cli things get <thing_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Things
|
||||
|
||||
```bash
|
||||
mainflux-cli things get all <user_token>
|
||||
magistrala-cli things get all <user_token>
|
||||
```
|
||||
|
||||
#### Get a subset list of provisioned Things
|
||||
|
||||
```bash
|
||||
mainflux-cli things get all --offset=1 --limit=5 <user_token>
|
||||
magistrala-cli things get all --offset=1 --limit=5 <user_token>
|
||||
```
|
||||
|
||||
#### Create Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli channels create '{"name":"myChannel"}' <user_token>
|
||||
magistrala-cli channels create '{"name":"myChannel"}' <user_token>
|
||||
```
|
||||
|
||||
#### Bulk Provision Channels
|
||||
|
||||
```bash
|
||||
mainflux-cli provision channels <file> <user_token>
|
||||
magistrala-cli provision channels <file> <user_token>
|
||||
```
|
||||
|
||||
- `file` - A CSV or JSON file containing channel names (must have extension `.csv` or `.json`)
|
||||
@@ -222,37 +222,37 @@ With JSON you can be able to specify more fields of the channels you want to cre
|
||||
#### Update Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli channels update '{"id":"<channel_id>","name":"myNewName"}' <user_token>
|
||||
magistrala-cli channels update '{"id":"<channel_id>","name":"myNewName"}' <user_token>
|
||||
```
|
||||
|
||||
#### Enable Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli channels enable <channel_id> <user_token>
|
||||
magistrala-cli channels enable <channel_id> <user_token>
|
||||
```
|
||||
|
||||
#### Disable Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli channels disable <channel_id> <user_token>
|
||||
magistrala-cli channels disable <channel_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli channels get <channel_id> <user_token>
|
||||
magistrala-cli channels get <channel_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Channels
|
||||
|
||||
```bash
|
||||
mainflux-cli channels get all <user_token>
|
||||
magistrala-cli channels get all <user_token>
|
||||
```
|
||||
|
||||
#### Get a subset list of provisioned Channels
|
||||
|
||||
```bash
|
||||
mainflux-cli channels get all --offset=1 --limit=5 <user_token>
|
||||
magistrala-cli channels get all --offset=1 --limit=5 <user_token>
|
||||
```
|
||||
|
||||
### Access control
|
||||
@@ -260,13 +260,13 @@ mainflux-cli channels get all --offset=1 --limit=5 <user_token>
|
||||
#### Connect Thing to Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli things connect <thing_id> <channel_id> <user_token>
|
||||
magistrala-cli things connect <thing_id> <channel_id> <user_token>
|
||||
```
|
||||
|
||||
#### Bulk Connect Things to Channels
|
||||
|
||||
```bash
|
||||
mainflux-cli provision connect <file> <user_token>
|
||||
magistrala-cli provision connect <file> <user_token>
|
||||
```
|
||||
|
||||
- `file` - A CSV or JSON file containing thing and channel ids (must have extension `.csv` or `.json`)
|
||||
@@ -293,19 +293,19 @@ A comparable JSON file would be
|
||||
#### Disconnect Thing from Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli things disconnect <thing_id> <channel_id> <user_token>
|
||||
magistrala-cli things disconnect <thing_id> <channel_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get a subset list of Channels connected to Thing
|
||||
|
||||
```bash
|
||||
mainflux-cli things connections <thing_id> <user_token>
|
||||
magistrala-cli things connections <thing_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get a subset list of Things connected to Channel
|
||||
|
||||
```bash
|
||||
mainflux-cli channels connections <channel_id> <user_token>
|
||||
magistrala-cli channels connections <channel_id> <user_token>
|
||||
```
|
||||
|
||||
### Messaging
|
||||
@@ -313,13 +313,13 @@ mainflux-cli channels connections <channel_id> <user_token>
|
||||
#### Send a message over HTTP
|
||||
|
||||
```bash
|
||||
mainflux-cli messages send <channel_id> '[{"bn":"Dev1","n":"temp","v":20}, {"n":"hum","v":40}, {"bn":"Dev2", "n":"temp","v":20}, {"n":"hum","v":40}]' <thing_secret>
|
||||
magistrala-cli messages send <channel_id> '[{"bn":"Dev1","n":"temp","v":20}, {"n":"hum","v":40}, {"bn":"Dev2", "n":"temp","v":20}, {"n":"hum","v":40}]' <thing_secret>
|
||||
```
|
||||
|
||||
#### Read messages over HTTP
|
||||
|
||||
```bash
|
||||
mainflux-cli messages read <channel_id> <user_token> -R <reader_url>
|
||||
magistrala-cli messages read <channel_id> <user_token> -R <reader_url>
|
||||
```
|
||||
|
||||
### Bootstrap
|
||||
@@ -327,31 +327,31 @@ mainflux-cli messages read <channel_id> <user_token> -R <reader_url>
|
||||
#### Add configuration
|
||||
|
||||
```bash
|
||||
mainflux-cli bootstrap create '{"external_id": "myExtID", "external_key": "myExtKey", "name": "myName", "content": "myContent"}' <user_token> -b <bootstrap-url>
|
||||
magistrala-cli bootstrap create '{"external_id": "myExtID", "external_key": "myExtKey", "name": "myName", "content": "myContent"}' <user_token> -b <bootstrap-url>
|
||||
```
|
||||
|
||||
#### View configuration
|
||||
|
||||
```bash
|
||||
mainflux-cli bootstrap get <thing_id> <user_token> -b <bootstrap-url>
|
||||
magistrala-cli bootstrap get <thing_id> <user_token> -b <bootstrap-url>
|
||||
```
|
||||
|
||||
#### Update configuration
|
||||
|
||||
```bash
|
||||
mainflux-cli bootstrap update '{"thing_id":"<thing_id>", "name": "newName", "content": "newContent"}' <user_token> -b <bootstrap-url>
|
||||
magistrala-cli bootstrap update '{"thing_id":"<thing_id>", "name": "newName", "content": "newContent"}' <user_token> -b <bootstrap-url>
|
||||
```
|
||||
|
||||
#### Remove configuration
|
||||
|
||||
```bash
|
||||
mainflux-cli bootstrap remove <thing_id> <user_token> -b <bootstrap-url>
|
||||
magistrala-cli bootstrap remove <thing_id> <user_token> -b <bootstrap-url>
|
||||
```
|
||||
|
||||
#### Bootstrap configuration
|
||||
|
||||
```bash
|
||||
mainflux-cli bootstrap bootstrap <external_id> <external_key> -b <bootstrap-url>
|
||||
magistrala-cli bootstrap bootstrap <external_id> <external_key> -b <bootstrap-url>
|
||||
```
|
||||
|
||||
### Groups
|
||||
@@ -359,53 +359,53 @@ mainflux-cli bootstrap bootstrap <external_id> <external_key> -b <bootstrap-url>
|
||||
#### Create Group
|
||||
|
||||
```bash
|
||||
mainflux-cli groups create '{"name":"<group_name>","description":"<description>","parentID":"<parent_id>","metadata":"<metadata>"}' <user_token>
|
||||
magistrala-cli groups create '{"name":"<group_name>","description":"<description>","parentID":"<parent_id>","metadata":"<metadata>"}' <user_token>
|
||||
```
|
||||
|
||||
#### Get Group
|
||||
|
||||
```bash
|
||||
mainflux-cli groups get <group_id> <user_token>
|
||||
magistrala-cli groups get <group_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Groups
|
||||
|
||||
```bash
|
||||
mainflux-cli groups get all <user_token>
|
||||
magistrala-cli groups get all <user_token>
|
||||
```
|
||||
|
||||
#### Get Group Members
|
||||
|
||||
```bash
|
||||
mainflux-cli groups members <group_id> <user_token>
|
||||
magistrala-cli groups members <group_id> <user_token>
|
||||
```
|
||||
|
||||
#### Get Memberships
|
||||
|
||||
```bash
|
||||
mainflux-cli groups membership <member_id> <user_token>
|
||||
magistrala-cli groups membership <member_id> <user_token>
|
||||
```
|
||||
|
||||
#### Assign Members to Group
|
||||
|
||||
```bash
|
||||
mainflux-cli groups assign <member_ids> <member_type> <group_id> <user_token>
|
||||
magistrala-cli groups assign <member_ids> <member_type> <group_id> <user_token>
|
||||
```
|
||||
|
||||
#### Unassign Members to Group
|
||||
|
||||
```bash
|
||||
mainflux-cli groups unassign <member_ids> <group_id> <user_token>
|
||||
magistrala-cli groups unassign <member_ids> <group_id> <user_token>
|
||||
```
|
||||
|
||||
#### Enable Group
|
||||
|
||||
```bash
|
||||
mainflux-cli groups enable <group_id> <user_token>
|
||||
magistrala-cli groups enable <group_id> <user_token>
|
||||
```
|
||||
|
||||
#### Disable Group
|
||||
|
||||
```bash
|
||||
mainflux-cli groups disable <group_id> <user_token>
|
||||
magistrala-cli groups disable <group_id> <user_token>
|
||||
```
|
||||
|
||||
+5
-5
@@ -6,7 +6,7 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ var cmdBootstrap = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var cfg mfxsdk.BootstrapConfig
|
||||
var cfg mgxsdk.BootstrapConfig
|
||||
if err := json.Unmarshal([]byte(args[0]), &cfg); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
@@ -47,7 +47,7 @@ var cmdBootstrap = []cobra.Command{
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pageMetadata := mfxsdk.PageMetadata{
|
||||
pageMetadata := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
State: State,
|
||||
@@ -86,7 +86,7 @@ var cmdBootstrap = []cobra.Command{
|
||||
return
|
||||
}
|
||||
if args[0] == "config" {
|
||||
var cfg mfxsdk.BootstrapConfig
|
||||
var cfg mgxsdk.BootstrapConfig
|
||||
if err := json.Unmarshal([]byte(args[0]), &cfg); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
@@ -184,7 +184,7 @@ var cmdBootstrap = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var cfg mfxsdk.BootstrapConfig
|
||||
var cfg mgxsdk.BootstrapConfig
|
||||
if err := json.Unmarshal([]byte(args[0]), &cfg); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
|
||||
+17
-17
@@ -6,7 +6,7 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ var cmdChannels = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var channel mfxsdk.Channel
|
||||
var channel mgxsdk.Channel
|
||||
if err := json.Unmarshal([]byte(args[0]), &channel); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
@@ -55,7 +55,7 @@ var cmdChannels = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
pageMetadata := mfxsdk.PageMetadata{
|
||||
pageMetadata := mgxsdk.PageMetadata{
|
||||
Name: "",
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
@@ -91,7 +91,7 @@ var cmdChannels = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
var channel mfxsdk.Channel
|
||||
var channel mgxsdk.Channel
|
||||
if err := json.Unmarshal([]byte(args[1]), &channel); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
@@ -115,7 +115,7 @@ var cmdChannels = []cobra.Command{
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -171,7 +171,7 @@ var cmdChannels = []cobra.Command{
|
||||
Short: "Assign user",
|
||||
Long: "Assign user to a channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli channels assign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli channels assign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 5 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -182,7 +182,7 @@ var cmdChannels = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
if err := sdk.AddUserToChannel(args[2], mfxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
if err := sdk.AddUserToChannel(args[2], mgxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
@@ -194,7 +194,7 @@ var cmdChannels = []cobra.Command{
|
||||
Short: "Unassign user",
|
||||
Long: "Unassign user from a channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli channels unassign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli channels unassign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 5 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -205,7 +205,7 @@ var cmdChannels = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
if err := sdk.RemoveUserFromChannel(args[2], mfxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
if err := sdk.RemoveUserFromChannel(args[2], mgxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
@@ -217,7 +217,7 @@ var cmdChannels = []cobra.Command{
|
||||
Short: "Assign group",
|
||||
Long: "Assign group to a channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli channels assign group '[\"<group_id_1>\", \"<group_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli channels assign group '[\"<group_id_1>\", \"<group_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 5 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -228,7 +228,7 @@ var cmdChannels = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
if err := sdk.AddUserGroupToChannel(args[1], mfxsdk.UserGroupsRequest{UserGroupIDs: groupIDs}, args[2]); err != nil {
|
||||
if err := sdk.AddUserGroupToChannel(args[1], mgxsdk.UserGroupsRequest{UserGroupIDs: groupIDs}, args[2]); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
@@ -240,7 +240,7 @@ var cmdChannels = []cobra.Command{
|
||||
Short: "Unassign group",
|
||||
Long: "Unassign group from a channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli channels unassign group '[\"<group_id_1>\", \"<group_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli channels unassign group '[\"<group_id_1>\", \"<group_id_2>\"]' <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 5 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -251,7 +251,7 @@ var cmdChannels = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
if err := sdk.RemoveUserGroupFromChannel(args[1], mfxsdk.UserGroupsRequest{UserGroupIDs: groupIDs}, args[2]); err != nil {
|
||||
if err := sdk.RemoveUserGroupFromChannel(args[1], mgxsdk.UserGroupsRequest{UserGroupIDs: groupIDs}, args[2]); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
@@ -263,13 +263,13 @@ var cmdChannels = []cobra.Command{
|
||||
Short: "List users",
|
||||
Long: "List users of a channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli channels users <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli channels users <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -287,13 +287,13 @@ var cmdChannels = []cobra.Command{
|
||||
Short: "List groups",
|
||||
Long: "List groups of a channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli channels groups <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli channels groups <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
|
||||
+2
-2
@@ -12,7 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -74,7 +74,7 @@ func read(file string) (config, error) {
|
||||
}
|
||||
|
||||
// ParseConfig - parses the config file.
|
||||
func ParseConfig(sdkConf mfxsdk.Config) (mfxsdk.Config, error) {
|
||||
func ParseConfig(sdkConf mgxsdk.Config) (mgxsdk.Config, error) {
|
||||
if ConfigPath == "" {
|
||||
ConfigPath = defaultConfigPath
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ var cmdSubscription = []cobra.Command{
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pageMetadata := mfxsdk.PageMetadata{
|
||||
pageMetadata := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
Topic: Topic,
|
||||
|
||||
+24
-24
@@ -6,8 +6,8 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -17,18 +17,18 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Create group",
|
||||
Long: "Creates new group\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups create '{\"name\":\"new group\", \"description\":\"new group description\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n",
|
||||
"\tmagistrala-cli groups create '{\"name\":\"new group\", \"description\":\"new group description\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
var group mfxsdk.Group
|
||||
var group mgxsdk.Group
|
||||
if err := json.Unmarshal([]byte(args[0]), &group); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
group.Status = mfclients.EnabledStatus.String()
|
||||
group.Status = mgclients.EnabledStatus.String()
|
||||
group, err := sdk.CreateGroup(group, args[1])
|
||||
if err != nil {
|
||||
logError(err)
|
||||
@@ -42,14 +42,14 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Update group",
|
||||
Long: "Updates group\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups update '{\"id\":\"<group_id>\", \"name\":\"new group\", \"description\":\"new group description\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n",
|
||||
"\tmagistrala-cli groups update '{\"id\":\"<group_id>\", \"name\":\"new group\", \"description\":\"new group description\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
var group mfxsdk.Group
|
||||
var group mgxsdk.Group
|
||||
if err := json.Unmarshal([]byte(args[0]), &group); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
@@ -69,10 +69,10 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Get group",
|
||||
Long: "Get all users groups, group children or group by id.\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups get all $USERTOKEN - lists all groups\n" +
|
||||
"\tmainflux-cli groups get children <group_id> $USERTOKEN - lists all children groups of <group_id>\n" +
|
||||
"\tmainflux-cli groups get parents <group_id> $USERTOKEN - lists all parent groups of <group_id>\n" +
|
||||
"\tmainflux-cli groups get <group_id> $USERTOKEN - shows group with provided group ID\n",
|
||||
"\tmagistrala-cli groups get all $USERTOKEN - lists all groups\n" +
|
||||
"\tmagistrala-cli groups get children <group_id> $USERTOKEN - lists all children groups of <group_id>\n" +
|
||||
"\tmagistrala-cli groups get parents <group_id> $USERTOKEN - lists all parent groups of <group_id>\n" +
|
||||
"\tmagistrala-cli groups get <group_id> $USERTOKEN - shows group with provided group ID\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) < 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -83,7 +83,7 @@ var cmdGroups = []cobra.Command{
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -100,7 +100,7 @@ var cmdGroups = []cobra.Command{
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -117,7 +117,7 @@ var cmdGroups = []cobra.Command{
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -146,7 +146,7 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Assign user",
|
||||
Long: "Assign user to a group\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups assign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <group_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli groups assign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <group_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 5 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -157,7 +157,7 @@ var cmdGroups = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
if err := sdk.AddUserToGroup(args[2], mfxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
if err := sdk.AddUserToGroup(args[2], mgxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
@@ -169,7 +169,7 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Unassign user",
|
||||
Long: "Unassign user from a group\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups unassign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <group_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli groups unassign user <relation> '[\"<user_id_1>\", \"<user_id_2>\"]' <group_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 5 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -180,7 +180,7 @@ var cmdGroups = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
if err := sdk.RemoveUserFromGroup(args[2], mfxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
if err := sdk.RemoveUserFromGroup(args[2], mgxsdk.UsersRelationRequest{Relation: args[0], UserIDs: userIDs}, args[3]); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
@@ -193,13 +193,13 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "List users",
|
||||
Long: "List users in a group\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups users <group_id> $USERTOKEN",
|
||||
"\tmagistrala-cli groups users <group_id> $USERTOKEN",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
Status: Status,
|
||||
@@ -217,13 +217,13 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "List channels",
|
||||
Long: "List channels in a group\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups channels <group_id> $USERTOKEN",
|
||||
"\tmagistrala-cli groups channels <group_id> $USERTOKEN",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
Status: Status,
|
||||
@@ -241,7 +241,7 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Change group status to enabled",
|
||||
Long: "Change group status to enabled\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups enable <group_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli groups enable <group_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -262,7 +262,7 @@ var cmdGroups = []cobra.Command{
|
||||
Short: "Change group status to disabled",
|
||||
Long: "Change group status to disabled\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli groups disable <group_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli groups disable <group_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ func NewHealthCmd() *cobra.Command {
|
||||
Short: "Health Check",
|
||||
Long: "Magistrala service Health Check\n" +
|
||||
"usage:\n" +
|
||||
"\tmainflux-cli health <service>",
|
||||
"\tmagistrala-cli health <service>",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
logUsage(cmd.Use)
|
||||
|
||||
+40
-40
@@ -14,7 +14,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/docker/docker/pkg/namesgenerator"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -114,8 +114,8 @@ var cmdProvision = []cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
numThings := 2
|
||||
numChan := 2
|
||||
things := []mfxsdk.Thing{}
|
||||
channels := []mfxsdk.Channel{}
|
||||
things := []mgxsdk.Thing{}
|
||||
channels := []mgxsdk.Channel{}
|
||||
|
||||
if len(args) != 0 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -125,13 +125,13 @@ var cmdProvision = []cobra.Command{
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
name := namesgenerator.GetRandomName(0)
|
||||
// Create test user
|
||||
user := mfxsdk.User{
|
||||
user := mgxsdk.User{
|
||||
Name: name,
|
||||
Credentials: mfxsdk.Credentials{
|
||||
Credentials: mgxsdk.Credentials{
|
||||
Identity: fmt.Sprintf("%s@email.com", name),
|
||||
Secret: "12345678",
|
||||
},
|
||||
Status: mfxsdk.EnabledStatus,
|
||||
Status: mgxsdk.EnabledStatus,
|
||||
}
|
||||
user, err := sdk.CreateUser(user, "")
|
||||
if err != nil {
|
||||
@@ -149,9 +149,9 @@ var cmdProvision = []cobra.Command{
|
||||
// Create things
|
||||
for i := 0; i < numThings; i++ {
|
||||
n := fmt.Sprintf("d%d", i)
|
||||
t := mfxsdk.Thing{
|
||||
t := mgxsdk.Thing{
|
||||
Name: n,
|
||||
Status: mfxsdk.EnabledStatus,
|
||||
Status: mgxsdk.EnabledStatus,
|
||||
}
|
||||
|
||||
things = append(things, t)
|
||||
@@ -166,9 +166,9 @@ var cmdProvision = []cobra.Command{
|
||||
for i := 0; i < numChan; i++ {
|
||||
n := fmt.Sprintf("c%d", i)
|
||||
|
||||
c := mfxsdk.Channel{
|
||||
c := mgxsdk.Channel{
|
||||
Name: n,
|
||||
Status: mfxsdk.EnabledStatus,
|
||||
Status: mgxsdk.EnabledStatus,
|
||||
}
|
||||
|
||||
channels = append(channels, c)
|
||||
@@ -180,7 +180,7 @@ var cmdProvision = []cobra.Command{
|
||||
}
|
||||
|
||||
// Connect things to channels - first thing to both channels, second only to first
|
||||
conIDs := mfxsdk.Connection{
|
||||
conIDs := mgxsdk.Connection{
|
||||
ChannelID: channels[0].ID,
|
||||
ThingID: things[0].ID,
|
||||
}
|
||||
@@ -189,7 +189,7 @@ var cmdProvision = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
conIDs = mfxsdk.Connection{
|
||||
conIDs = mgxsdk.Connection{
|
||||
ChannelID: channels[1].ID,
|
||||
ThingID: things[0].ID,
|
||||
}
|
||||
@@ -198,7 +198,7 @@ var cmdProvision = []cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
conIDs = mfxsdk.Connection{
|
||||
conIDs = mgxsdk.Connection{
|
||||
ChannelID: channels[0].ID,
|
||||
ThingID: things[1].ID,
|
||||
}
|
||||
@@ -227,18 +227,18 @@ func NewProvisionCmd() *cobra.Command {
|
||||
return &cmd
|
||||
}
|
||||
|
||||
func thingsFromFile(path string) ([]mfxsdk.Thing, error) {
|
||||
func thingsFromFile(path string) ([]mgxsdk.Thing, error) {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return []mfxsdk.Thing{}, err
|
||||
return []mgxsdk.Thing{}, err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
|
||||
if err != nil {
|
||||
return []mfxsdk.Thing{}, err
|
||||
return []mgxsdk.Thing{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
things := []mfxsdk.Thing{}
|
||||
things := []mgxsdk.Thing{}
|
||||
switch filepath.Ext(path) {
|
||||
case csvExt:
|
||||
reader := csv.NewReader(file)
|
||||
@@ -249,14 +249,14 @@ func thingsFromFile(path string) ([]mfxsdk.Thing, error) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return []mfxsdk.Thing{}, err
|
||||
return []mgxsdk.Thing{}, err
|
||||
}
|
||||
|
||||
if len(l) < 1 {
|
||||
return []mfxsdk.Thing{}, errors.New("empty line found in file")
|
||||
return []mgxsdk.Thing{}, errors.New("empty line found in file")
|
||||
}
|
||||
|
||||
thing := mfxsdk.Thing{
|
||||
thing := mgxsdk.Thing{
|
||||
Name: l[0],
|
||||
}
|
||||
|
||||
@@ -265,27 +265,27 @@ func thingsFromFile(path string) ([]mfxsdk.Thing, error) {
|
||||
case jsonExt:
|
||||
err := json.NewDecoder(file).Decode(&things)
|
||||
if err != nil {
|
||||
return []mfxsdk.Thing{}, err
|
||||
return []mgxsdk.Thing{}, err
|
||||
}
|
||||
default:
|
||||
return []mfxsdk.Thing{}, err
|
||||
return []mgxsdk.Thing{}, err
|
||||
}
|
||||
|
||||
return things, nil
|
||||
}
|
||||
|
||||
func channelsFromFile(path string) ([]mfxsdk.Channel, error) {
|
||||
func channelsFromFile(path string) ([]mgxsdk.Channel, error) {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return []mfxsdk.Channel{}, err
|
||||
return []mgxsdk.Channel{}, err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
|
||||
if err != nil {
|
||||
return []mfxsdk.Channel{}, err
|
||||
return []mgxsdk.Channel{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
channels := []mfxsdk.Channel{}
|
||||
channels := []mgxsdk.Channel{}
|
||||
switch filepath.Ext(path) {
|
||||
case csvExt:
|
||||
reader := csv.NewReader(file)
|
||||
@@ -296,14 +296,14 @@ func channelsFromFile(path string) ([]mfxsdk.Channel, error) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return []mfxsdk.Channel{}, err
|
||||
return []mgxsdk.Channel{}, err
|
||||
}
|
||||
|
||||
if len(l) < 1 {
|
||||
return []mfxsdk.Channel{}, errors.New("empty line found in file")
|
||||
return []mgxsdk.Channel{}, errors.New("empty line found in file")
|
||||
}
|
||||
|
||||
channel := mfxsdk.Channel{
|
||||
channel := mgxsdk.Channel{
|
||||
Name: l[0],
|
||||
}
|
||||
|
||||
@@ -312,27 +312,27 @@ func channelsFromFile(path string) ([]mfxsdk.Channel, error) {
|
||||
case jsonExt:
|
||||
err := json.NewDecoder(file).Decode(&channels)
|
||||
if err != nil {
|
||||
return []mfxsdk.Channel{}, err
|
||||
return []mgxsdk.Channel{}, err
|
||||
}
|
||||
default:
|
||||
return []mfxsdk.Channel{}, err
|
||||
return []mgxsdk.Channel{}, err
|
||||
}
|
||||
|
||||
return channels, nil
|
||||
}
|
||||
|
||||
func connectionsFromFile(path string) ([]mfxsdk.Connection, error) {
|
||||
func connectionsFromFile(path string) ([]mgxsdk.Connection, error) {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return []mfxsdk.Connection{}, err
|
||||
return []mgxsdk.Connection{}, err
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
|
||||
if err != nil {
|
||||
return []mfxsdk.Connection{}, err
|
||||
return []mgxsdk.Connection{}, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
connections := []mfxsdk.Connection{}
|
||||
connections := []mgxsdk.Connection{}
|
||||
switch filepath.Ext(path) {
|
||||
case csvExt:
|
||||
reader := csv.NewReader(file)
|
||||
@@ -343,13 +343,13 @@ func connectionsFromFile(path string) ([]mfxsdk.Connection, error) {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return []mfxsdk.Connection{}, err
|
||||
return []mgxsdk.Connection{}, err
|
||||
}
|
||||
|
||||
if len(l) < 1 {
|
||||
return []mfxsdk.Connection{}, errors.New("empty line found in file")
|
||||
return []mgxsdk.Connection{}, errors.New("empty line found in file")
|
||||
}
|
||||
connections = append(connections, mfxsdk.Connection{
|
||||
connections = append(connections, mgxsdk.Connection{
|
||||
ThingID: l[0],
|
||||
ChannelID: l[1],
|
||||
})
|
||||
@@ -357,10 +357,10 @@ func connectionsFromFile(path string) ([]mfxsdk.Connection, error) {
|
||||
case jsonExt:
|
||||
err := json.NewDecoder(file).Decode(&connections)
|
||||
if err != nil {
|
||||
return []mfxsdk.Connection{}, err
|
||||
return []mgxsdk.Connection{}, err
|
||||
}
|
||||
default:
|
||||
return []mfxsdk.Connection{}, err
|
||||
return []mgxsdk.Connection{}, err
|
||||
}
|
||||
|
||||
return connections, nil
|
||||
|
||||
+4
-4
@@ -3,12 +3,12 @@
|
||||
|
||||
package cli
|
||||
|
||||
import mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
import mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
|
||||
// Keep SDK handle in global var.
|
||||
var sdk mfxsdk.SDK
|
||||
var sdk mgxsdk.SDK
|
||||
|
||||
// SetSDK sets mainflux SDK instance.
|
||||
func SetSDK(s mfxsdk.SDK) {
|
||||
// SetSDK sets magistrala SDK instance.
|
||||
func SetSDK(s mgxsdk.SDK) {
|
||||
sdk = s
|
||||
}
|
||||
|
||||
+29
-29
@@ -6,8 +6,8 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -17,19 +17,19 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Create thing",
|
||||
Long: "Creates new thing with provided name and metadata\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things create '{\"name\":\"new thing\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n",
|
||||
"\tmagistrala-cli things create '{\"name\":\"new thing\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
var thing mfxsdk.Thing
|
||||
var thing mgxsdk.Thing
|
||||
if err := json.Unmarshal([]byte(args[0]), &thing); err != nil {
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
thing.Status = mfclients.EnabledStatus.String()
|
||||
thing.Status = mgclients.EnabledStatus.String()
|
||||
thing, err := sdk.CreateThing(thing, args[1])
|
||||
if err != nil {
|
||||
logError(err)
|
||||
@@ -44,9 +44,9 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Get things",
|
||||
Long: "Get all things or get thing by id. Things can be filtered by name or metadata\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things get all $USERTOKEN - lists all things\n" +
|
||||
"\tmainflux-cli things get all $USERTOKEN --offset=10 --limit=10 - lists all things with offset and limit\n" +
|
||||
"\tmainflux-cli things get <thing_id> $USERTOKEN - shows thing with provided <thing_id>\n",
|
||||
"\tmagistrala-cli things get all $USERTOKEN - lists all things\n" +
|
||||
"\tmagistrala-cli things get all $USERTOKEN --offset=10 --limit=10 - lists all things with offset and limit\n" +
|
||||
"\tmagistrala-cli things get <thing_id> $USERTOKEN - shows thing with provided <thing_id>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -57,7 +57,7 @@ var cmdThings = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
pageMetadata := mfxsdk.PageMetadata{
|
||||
pageMetadata := mgxsdk.PageMetadata{
|
||||
Name: Name,
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
@@ -86,7 +86,7 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Identify thing",
|
||||
Long: "Validates thing's key and returns its ID\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things identify <thing_key>\n",
|
||||
"\tmagistrala-cli things identify <thing_key>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -107,17 +107,17 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Update thing",
|
||||
Long: "Updates thing with provided id, name and metadata, or updates thing tags, secret or owner\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things update <thing_id> '{\"name\":\"new name\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n" +
|
||||
"\tmainflux-cli things update tags <thing_id> '{\"tag1\":\"value1\", \"tag2\":\"value2\"}' $USERTOKEN\n" +
|
||||
"\tmainflux-cli things update secret <thing_id> newsecret $USERTOKEN\n" +
|
||||
"\tmainflux-cli things update owner <thing_id> <owner_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things update <thing_id> '{\"name\":\"new name\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN\n" +
|
||||
"\tmagistrala-cli things update tags <thing_id> '{\"tag1\":\"value1\", \"tag2\":\"value2\"}' $USERTOKEN\n" +
|
||||
"\tmagistrala-cli things update secret <thing_id> newsecret $USERTOKEN\n" +
|
||||
"\tmagistrala-cli things update owner <thing_id> <owner_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 && len(args) != 3 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
var thing mfxsdk.Thing
|
||||
var thing mgxsdk.Thing
|
||||
if args[0] == "tags" {
|
||||
if err := json.Unmarshal([]byte(args[2]), &thing.Tags); err != nil {
|
||||
logError(err)
|
||||
@@ -177,7 +177,7 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Change thing status to enabled",
|
||||
Long: "Change thing status to enabled\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things enable <thing_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things enable <thing_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -198,7 +198,7 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Change thing status to disabled",
|
||||
Long: "Change thing status to disabled\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things disable <thing_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things disable <thing_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -219,13 +219,13 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Share thing with a user",
|
||||
Long: "Share thing with a user\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things share <thing_id> <user_id> <relation> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things share <thing_id> <user_id> <relation> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
req := mfxsdk.UsersRelationRequest{
|
||||
req := mgxsdk.UsersRelationRequest{
|
||||
Relation: args[2],
|
||||
UserIDs: []string{args[1]},
|
||||
}
|
||||
@@ -243,13 +243,13 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Unshare thing with a user",
|
||||
Long: "Unshare thing with a user\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things share <thing_id> <user_id> <relation> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things share <thing_id> <user_id> <relation> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
req := mfxsdk.UsersRelationRequest{
|
||||
req := mgxsdk.UsersRelationRequest{
|
||||
Relation: args[2],
|
||||
UserIDs: []string{args[1]},
|
||||
}
|
||||
@@ -267,14 +267,14 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Connect thing",
|
||||
Long: "Connect thing to the channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things connect <thing_id> <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things connect <thing_id> <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
connIDs := mfxsdk.Connection{
|
||||
connIDs := mgxsdk.Connection{
|
||||
ChannelID: args[1],
|
||||
ThingID: args[0],
|
||||
}
|
||||
@@ -291,14 +291,14 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Disconnect thing",
|
||||
Long: "Disconnect thing to the channel\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things disconnect <thing_id> <channel_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things disconnect <thing_id> <channel_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
connIDs := mfxsdk.Connection{
|
||||
connIDs := mgxsdk.Connection{
|
||||
ThingID: args[0],
|
||||
ChannelID: args[1],
|
||||
}
|
||||
@@ -315,13 +315,13 @@ var cmdThings = []cobra.Command{
|
||||
Short: "Connected list",
|
||||
Long: "List of Channels connected to Thing\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli connections <thing_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli connections <thing_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -339,13 +339,13 @@ var cmdThings = []cobra.Command{
|
||||
Short: "List users",
|
||||
Long: "List users of a thing\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli things users <thing_id> $USERTOKEN\n",
|
||||
"\tmagistrala-cli things users <thing_id> $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
|
||||
+31
-31
@@ -6,8 +6,8 @@ package cli
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mfxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mgxsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Create user",
|
||||
Long: "Create user with provided name, username and password. Token in optional\n" +
|
||||
"For example:\n" +
|
||||
"\tmainflux-cli users create user user@example.com 12345678 $USER_AUTH_TOKEN\n",
|
||||
"\tmagistrala-cli users create user user@example.com 12345678 $USER_AUTH_TOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) < 3 || len(args) > 4 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -27,13 +27,13 @@ var cmdUsers = []cobra.Command{
|
||||
args = append(args, "")
|
||||
}
|
||||
|
||||
user := mfxsdk.User{
|
||||
user := mgxsdk.User{
|
||||
Name: args[0],
|
||||
Credentials: mfxsdk.Credentials{
|
||||
Credentials: mgxsdk.Credentials{
|
||||
Identity: args[1],
|
||||
Secret: args[2],
|
||||
},
|
||||
Status: mfclients.EnabledStatus.String(),
|
||||
Status: mgclients.EnabledStatus.String(),
|
||||
}
|
||||
user, err := sdk.CreateUser(user, args[3])
|
||||
if err != nil {
|
||||
@@ -49,9 +49,9 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Get users",
|
||||
Long: "Get all users or get user by id. Users can be filtered by name or metadata or status\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users get all <user_auth_token> - lists all users\n" +
|
||||
"\tmainflux-cli users get all <user_auth_token> --offset <offset> --limit <limit> - lists all users with provided offset and limit\n" +
|
||||
"\tmainflux-cli users get <user_id> <user_auth_token> - shows user with provided <user_id>\n",
|
||||
"\tmagistrala-cli users get all <user_auth_token> - lists all users\n" +
|
||||
"\tmagistrala-cli users get all <user_auth_token> --offset <offset> --limit <limit> - lists all users with provided offset and limit\n" +
|
||||
"\tmagistrala-cli users get <user_id> <user_auth_token> - shows user with provided <user_id>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -62,7 +62,7 @@ var cmdUsers = []cobra.Command{
|
||||
logError(err)
|
||||
return
|
||||
}
|
||||
pageMetadata := mfxsdk.PageMetadata{
|
||||
pageMetadata := mgxsdk.PageMetadata{
|
||||
Email: Email,
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
@@ -92,15 +92,15 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Get token",
|
||||
Long: "Generate new token from username and password\n" +
|
||||
"For example:\n" +
|
||||
"\tmainflux-cli users token user@example.com 12345678\n",
|
||||
"\tmagistrala-cli users token user@example.com 12345678\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
user := mfxsdk.User{
|
||||
Credentials: mfxsdk.Credentials{
|
||||
user := mgxsdk.User{
|
||||
Credentials: mgxsdk.Credentials{
|
||||
Identity: args[0],
|
||||
Secret: args[1],
|
||||
},
|
||||
@@ -119,7 +119,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Get token",
|
||||
Long: "Generate new token from refresh token\n" +
|
||||
"For example:\n" +
|
||||
"\tmainflux-cli users refreshtoken <refresh_token>\n",
|
||||
"\tmagistrala-cli users refreshtoken <refresh_token>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -140,17 +140,17 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Update user",
|
||||
Long: "Updates either user name and metadata or user tags or user identity or user owner\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users update <user_id> '{\"name\":\"new name\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN - updates user name and metadata\n" +
|
||||
"\tmainflux-cli users update tags <user_id> '[\"tag1\", \"tag2\"]' $USERTOKEN - updates user tags\n" +
|
||||
"\tmainflux-cli users update identity <user_id> newidentity@example.com $USERTOKEN - updates user identity\n" +
|
||||
"\tmainflux-cli users update owner <user_id> <owner_id> $USERTOKEN - updates user owner\n",
|
||||
"\tmagistrala-cli users update <user_id> '{\"name\":\"new name\", \"metadata\":{\"key\": \"value\"}}' $USERTOKEN - updates user name and metadata\n" +
|
||||
"\tmagistrala-cli users update tags <user_id> '[\"tag1\", \"tag2\"]' $USERTOKEN - updates user tags\n" +
|
||||
"\tmagistrala-cli users update identity <user_id> newidentity@example.com $USERTOKEN - updates user identity\n" +
|
||||
"\tmagistrala-cli users update owner <user_id> <owner_id> $USERTOKEN - updates user owner\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 4 && len(args) != 3 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
var user mfxsdk.User
|
||||
var user mgxsdk.User
|
||||
if args[0] == "tags" {
|
||||
if err := json.Unmarshal([]byte(args[2]), &user.Tags); err != nil {
|
||||
logError(err)
|
||||
@@ -214,7 +214,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Get user profile",
|
||||
Long: "Get user profile\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users profile $USERTOKEN\n",
|
||||
"\tmagistrala-cli users profile $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -235,7 +235,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Send reset password request",
|
||||
Long: "Send reset password request\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users resetpasswordrequest example@mail.com\n",
|
||||
"\tmagistrala-cli users resetpasswordrequest example@mail.com\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -255,7 +255,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Reset password",
|
||||
Long: "Reset password\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users resetpassword 12345678 12345678 $REQUESTTOKEN\n",
|
||||
"\tmagistrala-cli users resetpassword 12345678 12345678 $REQUESTTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -275,7 +275,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Update password",
|
||||
Long: "Update password\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users password old_password new_password $USERTOKEN\n",
|
||||
"\tmagistrala-cli users password old_password new_password $USERTOKEN\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -296,7 +296,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Change user status to enabled",
|
||||
Long: "Change user status to enabled\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users enable <user_id> <user_auth_token>\n",
|
||||
"\tmagistrala-cli users enable <user_id> <user_auth_token>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -317,7 +317,7 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "Change user status to disabled",
|
||||
Long: "Change user status to disabled\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users disable <user_id> <user_auth_token>\n",
|
||||
"\tmagistrala-cli users disable <user_id> <user_auth_token>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
@@ -339,14 +339,14 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "List channels",
|
||||
Long: "List channels of user\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users channels <user_id> <user_auth_token>\n",
|
||||
"\tmagistrala-cli users channels <user_id> <user_auth_token>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -366,14 +366,14 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "List things",
|
||||
Long: "List things of user\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users things <user_id> <user_auth_token>\n",
|
||||
"\tmagistrala-cli users things <user_id> <user_auth_token>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
@@ -392,14 +392,14 @@ var cmdUsers = []cobra.Command{
|
||||
Short: "List groups",
|
||||
Long: "List groups of user\n" +
|
||||
"Usage:\n" +
|
||||
"\tmainflux-cli users groups <user_id> <user_auth_token>\n",
|
||||
"\tmagistrala-cli users groups <user_id> <user_auth_token>\n",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
logUsage(cmd.Use)
|
||||
return
|
||||
}
|
||||
|
||||
pm := mfxsdk.PageMetadata{
|
||||
pm := mgxsdk.PageMetadata{
|
||||
Offset: Offset,
|
||||
Limit: Limit,
|
||||
}
|
||||
|
||||
+7
-7
@@ -10,7 +10,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
api "github.com/absmach/magistrala/auth/api"
|
||||
grpcapi "github.com/absmach/magistrala/auth/api/grpc"
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
grpcserver "github.com/absmach/magistrala/internal/server/grpc"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
|
||||
"github.com/authzed/authzed-go/v1"
|
||||
@@ -75,13 +75,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err.Error())
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
logger.Fatal(fmt.Sprintf("failed to init logger: %s", err.Error()))
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -141,13 +141,13 @@ func main() {
|
||||
}
|
||||
registerAuthServiceServer := func(srv *grpc.Server) {
|
||||
reflection.Register(srv)
|
||||
mainflux.RegisterAuthServiceServer(srv, grpcapi.NewServer(svc))
|
||||
magistrala.RegisterAuthServiceServer(srv, grpcapi.NewServer(svc))
|
||||
}
|
||||
|
||||
gs := grpcserver.New(ctx, cancel, svcName, grpcServerConfig, registerAuthServiceServer, logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func initSchema(client *authzed.Client, schemaFilePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, cfg config, dbConfig pgclient.Config, logger mflog.Logger, spicedbClient *authzed.Client) auth.Service {
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, cfg config, dbConfig pgclient.Config, logger mglog.Logger, spicedbClient *authzed.Client) auth.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
keysRepo := apostgres.New(database)
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ import (
|
||||
"github.com/absmach/magistrala/internal/postgres"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/events/store"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/jmoiron/sqlx"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
@@ -42,7 +42,7 @@ const (
|
||||
defDB = "bootstrap"
|
||||
defSvcHTTPPort = "9013"
|
||||
|
||||
thingsStream = "mainflux.things"
|
||||
thingsStream = "magistrala.things"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -66,13 +66,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -158,16 +158,16 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config) (bootstrap.Service, error) {
|
||||
func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mglog.Logger, cfg config, dbConfig pgclient.Config) (bootstrap.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
|
||||
repoConfig := bootstrappg.NewConfigRepository(database, logger)
|
||||
|
||||
config := mfsdk.Config{
|
||||
config := mgsdk.Config{
|
||||
ThingsURL: cfg.ThingsURL,
|
||||
}
|
||||
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
|
||||
svc := bootstrap.New(auth, repoConfig, sdk, []byte(cfg.EncKey))
|
||||
|
||||
@@ -184,7 +184,7 @@ func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
func subscribeToThingsES(ctx context.Context, svc bootstrap.Service, cfg config, logger mflog.Logger) error {
|
||||
func subscribeToThingsES(ctx context.Context, svc bootstrap.Service, cfg config, logger mglog.Logger) error {
|
||||
subscriber, err := store.NewSubscriber(ctx, cfg.ESURL, thingsStream, cfg.ESConsumerName, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
cassandraclient "github.com/absmach/magistrala/internal/clients/cassandra"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
"github.com/absmach/magistrala/readers/api"
|
||||
@@ -50,13 +50,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s service configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -108,7 +108,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(csdSession *gocql.Session, logger mflog.Logger) readers.MessageRepository {
|
||||
func newService(csdSession *gocql.Session, logger mglog.Logger) readers.MessageRepository {
|
||||
repo := cassandra.New(csdSession)
|
||||
repo = api.LoggingMiddleware(repo, logger)
|
||||
counter, latency := internal.MakeMetrics("cassandra", "message_reader")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
consumertracing "github.com/absmach/magistrala/consumers/tracing"
|
||||
"github.com/absmach/magistrala/consumers/writers/api"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
@@ -57,13 +57,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(session *gocql.Session, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
func newService(session *gocql.Session, logger mglog.Logger) consumers.BlockingConsumer {
|
||||
repo := cassandra.New(session)
|
||||
repo = api.LoggingMiddleware(repo, logger)
|
||||
counter, latency := internal.MakeMetrics("cassandra", "message_writer")
|
||||
|
||||
+7
-7
@@ -24,8 +24,8 @@ import (
|
||||
"github.com/absmach/magistrala/internal/postgres"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/jmoiron/sqlx"
|
||||
chclient "github.com/mainflux/callhome/pkg/client"
|
||||
@@ -70,13 +70,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -162,14 +162,14 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(auth magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
func newService(auth magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mglog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
certsRepo := certspg.NewRepository(database, logger)
|
||||
config := mfsdk.Config{
|
||||
config := mgsdk.Config{
|
||||
CertsURL: cfg.CertsURL,
|
||||
ThingsURL: cfg.ThingsURL,
|
||||
}
|
||||
sdk := mfsdk.NewSDK(config)
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
svc := certs.New(auth, certsRepo, sdk, pkiAgent)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics(svcName, "api")
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@ func main() {
|
||||
|
||||
// Root
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "mainflux-cli",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
Use: "magistrala-cli",
|
||||
PersistentPreRun: func(_ *cobra.Command, _ []string) {
|
||||
cliConf, err := cli.ParseConfig(sdkConf)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse config: %s", err)
|
||||
|
||||
+5
-5
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/coap"
|
||||
"github.com/absmach/magistrala/coap/api"
|
||||
"github.com/absmach/magistrala/coap/tracing"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
coapserver "github.com/absmach/magistrala/internal/server/coap"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
@@ -55,13 +55,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -131,7 +131,7 @@ func main() {
|
||||
cs := coapserver.New(ctx, cancel, svcName, coapServerConfig, api.MakeCoAPHandler(svc, logger), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
|
||||
+7
-8
@@ -11,7 +11,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
adapter "github.com/absmach/magistrala/http"
|
||||
"github.com/absmach/magistrala/http/api"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
@@ -59,13 +59,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -120,7 +120,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, targetServerCfg, api.MakeHandler(cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(pub messaging.Publisher, tc mainflux.AuthzServiceClient, logger mflog.Logger, tracer trace.Tracer) session.Handler {
|
||||
func newService(pub messaging.Publisher, tc magistrala.AuthzServiceClient, logger mglog.Logger, tracer trace.Tracer) session.Handler {
|
||||
svc := adapter.NewHandler(pub, logger, tc)
|
||||
svc = handler.NewTracing(tracer, svc)
|
||||
svc = handler.LoggingMiddleware(svc, logger)
|
||||
@@ -150,7 +150,7 @@ func newService(pub messaging.Publisher, tc mainflux.AuthzServiceClient, logger
|
||||
return svc
|
||||
}
|
||||
|
||||
func proxyHTTP(ctx context.Context, cfg server.Config, logger mflog.Logger, handler session.Handler) error {
|
||||
func proxyHTTP(ctx context.Context, cfg server.Config, logger mglog.Logger, handler session.Handler) error {
|
||||
address := fmt.Sprintf("%s:%s", "", cfg.Port)
|
||||
target := fmt.Sprintf("%s:%s", targetHTTPHost, targetHTTPPort)
|
||||
mp, err := mproxy.NewProxy(address, target, handler, logger)
|
||||
@@ -171,7 +171,6 @@ func proxyHTTP(ctx context.Context, cfg server.Config, logger mflog.Logger, hand
|
||||
errCh <- mp.Listen()
|
||||
}()
|
||||
logger.Info(fmt.Sprintf("%s service http server listening at %s:%s without TLS", svcName, cfg.Host, cfg.Port))
|
||||
|
||||
}
|
||||
|
||||
select {
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
influxdbclient "github.com/absmach/magistrala/internal/clients/influxdb"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
"github.com/absmach/magistrala/readers/api"
|
||||
@@ -49,13 +49,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -117,7 +117,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(client influxdb2.Client, repocfg influxdb.RepoConfig, logger mflog.Logger) readers.MessageRepository {
|
||||
func newService(client influxdb2.Client, repocfg influxdb.RepoConfig, logger mglog.Logger) readers.MessageRepository {
|
||||
repo := influxdb.New(client, repocfg)
|
||||
repo = api.LoggingMiddleware(repo, logger)
|
||||
counter, latency := internal.MakeMetrics("influxdb", "message_reader")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
consumertracing "github.com/absmach/magistrala/consumers/tracing"
|
||||
"github.com/absmach/magistrala/consumers/writers/api"
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
@@ -54,13 +54,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -124,7 +124,7 @@ func main() {
|
||||
repo = consumertracing.NewAsync(tracer, repo, httpServerConfig)
|
||||
|
||||
// Start consuming and logging errors.
|
||||
go func(log mflog.Logger) {
|
||||
go func(log mglog.Logger) {
|
||||
for err := range repo.Errors() {
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
@@ -141,7 +141,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -11,14 +11,14 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
"github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
redisclient "github.com/absmach/magistrala/internal/clients/redis"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/lora"
|
||||
"github.com/absmach/magistrala/lora/api"
|
||||
"github.com/absmach/magistrala/lora/events"
|
||||
@@ -42,7 +42,7 @@ const (
|
||||
thingsRMPrefix = "thing"
|
||||
channelsRMPrefix = "channel"
|
||||
connsRMPrefix = "connection"
|
||||
thingsStream = "mainflux.things"
|
||||
thingsStream = "magistrala.things"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -71,13 +71,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -148,7 +148,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func connectToMQTTBroker(url, user, password string, timeout time.Duration, logger mflog.Logger) (mqttpaho.Client, error) {
|
||||
func connectToMQTTBroker(url, user, password string, timeout time.Duration, logger mglog.Logger) (mqttpaho.Client, error) {
|
||||
opts := mqttpaho.NewClientOptions()
|
||||
opts.AddBroker(url)
|
||||
opts.SetUsername(user)
|
||||
@@ -186,7 +186,7 @@ func connectToMQTTBroker(url, user, password string, timeout time.Duration, logg
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func subscribeToLoRaBroker(svc lora.Service, mc mqttpaho.Client, timeout time.Duration, topic string, logger mflog.Logger) error {
|
||||
func subscribeToLoRaBroker(svc lora.Service, mc mqttpaho.Client, timeout time.Duration, topic string, logger mglog.Logger) error {
|
||||
mqtt := mqtt.NewBroker(svc, mc, timeout, logger)
|
||||
logger.Info("Subscribed to Lora MQTT broker")
|
||||
if err := mqtt.Subscribe(topic); err != nil {
|
||||
@@ -195,7 +195,7 @@ func subscribeToLoRaBroker(svc lora.Service, mc mqttpaho.Client, timeout time.Du
|
||||
return nil
|
||||
}
|
||||
|
||||
func subscribeToThingsES(ctx context.Context, svc lora.Service, cfg config, logger mflog.Logger) error {
|
||||
func subscribeToThingsES(ctx context.Context, svc lora.Service, cfg config, logger mglog.Logger) error {
|
||||
subscriber, err := store.NewSubscriber(ctx, cfg.ESURL, thingsStream, cfg.ESConsumerName, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -208,12 +208,12 @@ func subscribeToThingsES(ctx context.Context, svc lora.Service, cfg config, logg
|
||||
return subscriber.Subscribe(ctx, handler)
|
||||
}
|
||||
|
||||
func newRouteMapRepository(client *redis.Client, prefix string, logger mflog.Logger) lora.RouteMapRepository {
|
||||
func newRouteMapRepository(client *redis.Client, prefix string, logger mglog.Logger) lora.RouteMapRepository {
|
||||
logger.Info(fmt.Sprintf("Connected to %s Redis Route-map", prefix))
|
||||
return events.NewRouteMapRepository(client, prefix)
|
||||
}
|
||||
|
||||
func newService(pub messaging.Publisher, rmConn *redis.Client, thingsRMPrefix, channelsRMPrefix, connsRMPrefix string, logger mflog.Logger) lora.Service {
|
||||
func newService(pub messaging.Publisher, rmConn *redis.Client, thingsRMPrefix, channelsRMPrefix, connsRMPrefix string, logger mglog.Logger) lora.Service {
|
||||
thingsRM := newRouteMapRepository(rmConn, thingsRMPrefix, logger)
|
||||
chansRM := newRouteMapRepository(rmConn, channelsRMPrefix, logger)
|
||||
connsRM := newRouteMapRepository(rmConn, connsRMPrefix, logger)
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
mongoclient "github.com/absmach/magistrala/internal/clients/mongo"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
"github.com/absmach/magistrala/readers/api"
|
||||
@@ -49,13 +49,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -103,7 +103,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *mongo.Database, logger mflog.Logger) readers.MessageRepository {
|
||||
func newService(db *mongo.Database, logger mglog.Logger) readers.MessageRepository {
|
||||
repo := mongodb.New(db)
|
||||
repo = api.LoggingMiddleware(repo, logger)
|
||||
counter, latency := internal.MakeMetrics("mongodb", "message_reader")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
consumertracing "github.com/absmach/magistrala/consumers/tracing"
|
||||
"github.com/absmach/magistrala/consumers/writers/api"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
@@ -56,13 +56,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -120,7 +120,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *mongo.Database, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
func newService(db *mongo.Database, logger mglog.Logger) consumers.BlockingConsumer {
|
||||
repo := mongodb.New(db)
|
||||
repo = api.LoggingMiddleware(repo, logger)
|
||||
counter, latency := internal.MakeMetrics("mongodb", "message_writer")
|
||||
|
||||
+7
-7
@@ -13,12 +13,12 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
authapi "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/mqtt"
|
||||
"github.com/absmach/magistrala/mqtt/events"
|
||||
mqtttracing "github.com/absmach/magistrala/mqtt/tracing"
|
||||
@@ -68,13 +68,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -170,7 +170,7 @@ func main() {
|
||||
h = handler.NewTracing(tracer, h)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func proxyMQTT(ctx context.Context, cfg config, logger mflog.Logger, handler session.Handler) error {
|
||||
func proxyMQTT(ctx context.Context, cfg config, logger mglog.Logger, handler session.Handler) error {
|
||||
address := fmt.Sprintf(":%s", cfg.MQTTPort)
|
||||
target := fmt.Sprintf("%s:%s", cfg.MQTTTargetHost, cfg.MQTTTargetPort)
|
||||
mp := mp.New(address, target, handler, logger)
|
||||
@@ -216,7 +216,7 @@ func proxyMQTT(ctx context.Context, cfg config, logger mflog.Logger, handler ses
|
||||
}
|
||||
}
|
||||
|
||||
func proxyWS(ctx context.Context, cfg config, logger mflog.Logger, handler session.Handler) error {
|
||||
func proxyWS(ctx context.Context, cfg config, logger mglog.Logger, handler session.Handler) error {
|
||||
target := fmt.Sprintf("%s:%s", cfg.HTTPTargetHost, cfg.HTTPTargetPort)
|
||||
wp := websocket.New(target, cfg.HTTPTargetPath, "ws", handler, logger)
|
||||
http.Handle("/mqtt", wp.Handler())
|
||||
|
||||
+10
-10
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
jaegerclient "github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
redisclient "github.com/absmach/magistrala/internal/clients/redis"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/opcua"
|
||||
"github.com/absmach/magistrala/opcua/api"
|
||||
"github.com/absmach/magistrala/opcua/db"
|
||||
@@ -41,7 +41,7 @@ const (
|
||||
channelsRMPrefix = "channel"
|
||||
connectionRMPrefix = "connection"
|
||||
|
||||
thingsStream = "mainflux.things"
|
||||
thingsStream = "magistrala.things"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -70,13 +70,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s opcua client configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -143,7 +143,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, httpCancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, httpCancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, httpCancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func subscribeToStoredSubs(ctx context.Context, sub opcua.Subscriber, cfg opcua.Config, logger mflog.Logger) {
|
||||
func subscribeToStoredSubs(ctx context.Context, sub opcua.Subscriber, cfg opcua.Config, logger mglog.Logger) {
|
||||
// Get all stored subscriptions
|
||||
nodes, err := db.ReadAll()
|
||||
if err != nil {
|
||||
@@ -178,7 +178,7 @@ func subscribeToStoredSubs(ctx context.Context, sub opcua.Subscriber, cfg opcua.
|
||||
}
|
||||
}
|
||||
|
||||
func subscribeToThingsES(ctx context.Context, svc opcua.Service, cfg config, logger mflog.Logger) error {
|
||||
func subscribeToThingsES(ctx context.Context, svc opcua.Service, cfg config, logger mglog.Logger) error {
|
||||
subscriber, err := store.NewSubscriber(ctx, cfg.ESURL, thingsStream, cfg.ESConsumerName, logger)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -191,12 +191,12 @@ func subscribeToThingsES(ctx context.Context, svc opcua.Service, cfg config, log
|
||||
return subscriber.Subscribe(ctx, handler)
|
||||
}
|
||||
|
||||
func newRouteMapRepositoy(client *redis.Client, prefix string, logger mflog.Logger) opcua.RouteMapRepository {
|
||||
func newRouteMapRepositoy(client *redis.Client, prefix string, logger mglog.Logger) opcua.RouteMapRepository {
|
||||
logger.Info(fmt.Sprintf("Connected to %s Redis Route-map", prefix))
|
||||
return events.NewRouteMapRepository(client, prefix)
|
||||
}
|
||||
|
||||
func newService(sub opcua.Subscriber, browser opcua.Browser, thingRM, chanRM, connRM opcua.RouteMapRepository, opcuaConfig opcua.Config, logger mflog.Logger) opcua.Service {
|
||||
func newService(sub opcua.Subscriber, browser opcua.Browser, thingRM, chanRM, connRM opcua.RouteMapRepository, opcuaConfig opcua.Config, logger mglog.Logger) opcua.Service {
|
||||
svc := opcua.New(sub, browser, thingRM, chanRM, connRM, opcuaConfig, logger)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("opc_ua_adapter", "api")
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
pgclient "github.com/absmach/magistrala/internal/clients/postgres"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
"github.com/absmach/magistrala/readers/api"
|
||||
@@ -50,13 +50,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -111,7 +111,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, logger mflog.Logger) readers.MessageRepository {
|
||||
func newService(db *sqlx.DB, logger mglog.Logger) readers.MessageRepository {
|
||||
svc := postgres.New(db)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("postgres", "message_reader")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
consumertracing "github.com/absmach/magistrala/consumers/tracing"
|
||||
"github.com/absmach/magistrala/consumers/writers/api"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
@@ -57,13 +57,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -121,7 +121,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
func newService(db *sqlx.DB, logger mglog.Logger) consumers.BlockingConsumer {
|
||||
svc := writerpg.New(db)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("postgres", "message_writer")
|
||||
|
||||
+14
-14
@@ -12,15 +12,15 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfgroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
mggroups "github.com/absmach/magistrala/pkg/groups"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/provision"
|
||||
"github.com/absmach/magistrala/provision/api"
|
||||
@@ -48,13 +48,13 @@ func main() {
|
||||
log.Fatalf(fmt.Sprintf("failed to load %s configuration : %s", svcName, err))
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.Server.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.Server.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -73,15 +73,15 @@ func main() {
|
||||
logger.Info("Continue with settings from file: " + cfg.File)
|
||||
}
|
||||
|
||||
SDKCfg := mfsdk.Config{
|
||||
SDKCfg := mgsdk.Config{
|
||||
UsersURL: cfg.Server.UsersURL,
|
||||
ThingsURL: cfg.Server.ThingsURL,
|
||||
BootstrapURL: cfg.Server.MfBSURL,
|
||||
CertsURL: cfg.Server.MfCertsURL,
|
||||
BootstrapURL: cfg.Server.MgBSURL,
|
||||
CertsURL: cfg.Server.MgCertsURL,
|
||||
MsgContentType: contentType,
|
||||
TLSVerification: cfg.Server.TLS,
|
||||
}
|
||||
SDK := mfsdk.NewSDK(SDKCfg)
|
||||
SDK := mgsdk.NewSDK(SDKCfg)
|
||||
|
||||
svc := provision.New(cfg, SDK, logger)
|
||||
svc = api.NewLoggingMiddleware(svc, logger)
|
||||
@@ -90,7 +90,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ func loadConfig() (provision.Config, error) {
|
||||
Content: content,
|
||||
},
|
||||
// This is default conf for provision if there is no config file
|
||||
Channels: []mfgroups.Group{
|
||||
Channels: []mggroups.Group{
|
||||
{
|
||||
Name: "control-channel",
|
||||
Metadata: map[string]interface{}{"type": "control"},
|
||||
@@ -150,7 +150,7 @@ func loadConfig() (provision.Config, error) {
|
||||
Metadata: map[string]interface{}{"type": "data"},
|
||||
},
|
||||
},
|
||||
Things: []mfclients.Client{
|
||||
Things: []mgclients.Client{
|
||||
{
|
||||
Name: "thing",
|
||||
Metadata: map[string]interface{}{"external_id": "xxxxxx"},
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/absmach/magistrala/consumers/notifiers"
|
||||
"github.com/absmach/magistrala/consumers/notifiers/api"
|
||||
notifierpg "github.com/absmach/magistrala/consumers/notifiers/postgres"
|
||||
mfsmpp "github.com/absmach/magistrala/consumers/notifiers/smpp"
|
||||
mgsmpp "github.com/absmach/magistrala/consumers/notifiers/smpp"
|
||||
"github.com/absmach/magistrala/consumers/notifiers/tracing"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/ulid"
|
||||
@@ -63,13 +63,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -86,7 +86,7 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
smppConfig := mfsmpp.Config{}
|
||||
smppConfig := mgsmpp.Config{}
|
||||
if err := env.Parse(&smppConfig); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load SMPP configuration from environment : %s", err))
|
||||
exitCode = 1
|
||||
@@ -158,11 +158,11 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth magistrala.AuthServiceClient, c config, sc mfsmpp.Config, logger mflog.Logger) notifiers.Service {
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth magistrala.AuthServiceClient, c config, sc mgsmpp.Config, logger mglog.Logger) notifiers.Service {
|
||||
database := notifierpg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierpg.New(database))
|
||||
idp := ulid.New()
|
||||
notifier := mfsmpp.New(sc)
|
||||
notifier := mgsmpp.New(sc)
|
||||
svc := notifiers.New(auth, repo, idp, notifier, c.From)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("notifier", "smpp")
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/ulid"
|
||||
@@ -64,13 +64,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -168,7 +168,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth magistrala.AuthServiceClient, c config, ec email.Config, logger mflog.Logger) (notifiers.Service, error) {
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth magistrala.AuthServiceClient, c config, ec email.Config, logger mglog.Logger) (notifiers.Service, error) {
|
||||
database := notifierpg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierpg.New(database))
|
||||
idp := ulid.New()
|
||||
|
||||
+6
-6
@@ -18,7 +18,7 @@ import (
|
||||
pgclient "github.com/absmach/magistrala/internal/clients/postgres"
|
||||
redisclient "github.com/absmach/magistrala/internal/clients/redis"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
mfgroups "github.com/absmach/magistrala/internal/groups"
|
||||
mggroups "github.com/absmach/magistrala/internal/groups"
|
||||
gapi "github.com/absmach/magistrala/internal/groups/api"
|
||||
gpostgres "github.com/absmach/magistrala/internal/groups/postgres"
|
||||
gtracing "github.com/absmach/magistrala/internal/groups/tracing"
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
grpcserver "github.com/absmach/magistrala/internal/server/grpc"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/groups"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/things"
|
||||
@@ -81,13 +81,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -205,7 +205,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth magistrala.AuthServiceClient, cacheClient *redis.Client, keyDuration, esURL string, tracer trace.Tracer, logger mflog.Logger) (things.Service, groups.Service, error) {
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth magistrala.AuthServiceClient, cacheClient *redis.Client, keyDuration, esURL string, tracer trace.Tracer, logger mglog.Logger) (things.Service, groups.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := thingspg.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
@@ -220,7 +220,7 @@ func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth
|
||||
thingCache := thcache.NewCache(cacheClient, kDuration)
|
||||
|
||||
csvc := things.NewService(auth, cRepo, gRepo, thingCache, idp)
|
||||
gsvc := mfgroups.NewService(gRepo, idp, auth)
|
||||
gsvc := mggroups.NewService(gRepo, idp, auth)
|
||||
|
||||
csvc, err = thevents.NewEventStoreMiddleware(ctx, csvc, esURL)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
pgclient "github.com/absmach/magistrala/internal/clients/postgres"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
"github.com/absmach/magistrala/readers/api"
|
||||
@@ -50,13 +50,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -109,7 +109,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, logger mflog.Logger) readers.MessageRepository {
|
||||
func newService(db *sqlx.DB, logger mglog.Logger) readers.MessageRepository {
|
||||
svc := timescale.New(db)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("timescale", "message_reader")
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
consumertracing "github.com/absmach/magistrala/consumers/tracing"
|
||||
"github.com/absmach/magistrala/consumers/writers/api"
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
@@ -57,13 +57,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s service configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
func newService(db *sqlx.DB, logger mglog.Logger) consumers.BlockingConsumer {
|
||||
svc := timescale.New(db)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := internal.MakeMetrics("timescale", "message_writer")
|
||||
|
||||
+5
-5
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
@@ -68,13 +68,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -171,7 +171,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, id string, ps messaging.PubSub, cfg config, users magistrala.AuthServiceClient, tracer trace.Tracer, db *mongo.Database, cacheclient *redis.Client, logger mflog.Logger) (twins.Service, error) {
|
||||
func newService(ctx context.Context, id string, ps messaging.PubSub, cfg config, users magistrala.AuthServiceClient, tracer trace.Tracer, db *mongo.Database, cacheclient *redis.Client, logger mglog.Logger) (twins.Service, error) {
|
||||
twinRepo := twmongodb.NewTwinRepository(db)
|
||||
twinRepo = tracing.TwinRepositoryMiddleware(tracer, twinRepo)
|
||||
|
||||
@@ -206,7 +206,7 @@ func newService(ctx context.Context, id string, ps messaging.PubSub, cfg config,
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
func handle(ctx context.Context, logger mflog.Logger, chanID string, svc twins.Service) handlerFunc {
|
||||
func handle(ctx context.Context, logger mglog.Logger, chanID string, svc twins.Service) handlerFunc {
|
||||
return func(msg *messaging.Message) error {
|
||||
if msg.Channel == chanID {
|
||||
return nil
|
||||
|
||||
+12
-12
@@ -19,7 +19,7 @@ import (
|
||||
pgclient "github.com/absmach/magistrala/internal/clients/postgres"
|
||||
"github.com/absmach/magistrala/internal/email"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
mfgroups "github.com/absmach/magistrala/internal/groups"
|
||||
mggroups "github.com/absmach/magistrala/internal/groups"
|
||||
gapi "github.com/absmach/magistrala/internal/groups/api"
|
||||
gevents "github.com/absmach/magistrala/internal/groups/events"
|
||||
gpostgres "github.com/absmach/magistrala/internal/groups/postgres"
|
||||
@@ -27,8 +27,8 @@ import (
|
||||
"github.com/absmach/magistrala/internal/postgres"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/groups"
|
||||
"github.com/absmach/magistrala/pkg/uuid"
|
||||
"github.com/absmach/magistrala/users"
|
||||
@@ -86,13 +86,13 @@ func main() {
|
||||
}
|
||||
cfg.PassRegex = passRegex
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
logger.Fatal(fmt.Sprintf("failed to init logger: %s", err.Error()))
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -184,7 +184,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx.DB, dbConfig pgclient.Config, tracer trace.Tracer, c config, ec email.Config, logger mflog.Logger) (users.Service, groups.Service, error) {
|
||||
func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx.DB, dbConfig pgclient.Config, tracer trace.Tracer, c config, ec email.Config, logger mglog.Logger) (users.Service, groups.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := clientspg.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
@@ -198,7 +198,7 @@ func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx
|
||||
}
|
||||
|
||||
csvc := users.NewService(cRepo, auth, emailer, hsr, idp, c.PassRegex)
|
||||
gsvc := mfgroups.NewService(gRepo, idp, auth)
|
||||
gsvc := mggroups.NewService(gRepo, idp, auth)
|
||||
|
||||
csvc, err = uevents.NewEventStoreMiddleware(ctx, csvc, c.ESURL)
|
||||
if err != nil {
|
||||
@@ -236,20 +236,20 @@ func createAdmin(ctx context.Context, c config, crepo clientspg.Repository, hsr
|
||||
return err
|
||||
}
|
||||
|
||||
client := mfclients.Client{
|
||||
client := mgclients.Client{
|
||||
ID: id,
|
||||
Name: "admin",
|
||||
Credentials: mfclients.Credentials{
|
||||
Credentials: mgclients.Credentials{
|
||||
Identity: c.AdminEmail,
|
||||
Secret: hash,
|
||||
},
|
||||
Metadata: mfclients.Metadata{
|
||||
Metadata: mgclients.Metadata{
|
||||
"role": "admin",
|
||||
},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
Role: mfclients.AdminRole,
|
||||
Status: mfclients.EnabledStatus,
|
||||
Role: mgclients.AdminRole,
|
||||
Status: mgclients.EnabledStatus,
|
||||
}
|
||||
|
||||
if _, err := crepo.RetrieveByIdentity(ctx, client.Credentials.Identity); err == nil {
|
||||
|
||||
+7
-7
@@ -10,14 +10,14 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authapi "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
httpserver "github.com/absmach/magistrala/internal/server/http"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
@@ -58,13 +58,13 @@ func main() {
|
||||
log.Fatalf("failed to load %s configuration : %s", svcName, err)
|
||||
}
|
||||
|
||||
logger, err := mflog.New(os.Stdout, cfg.LogLevel)
|
||||
logger, err := mglog.New(os.Stdout, cfg.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to init logger: %s", err)
|
||||
}
|
||||
|
||||
var exitCode int
|
||||
defer mflog.ExitWithError(&exitCode)
|
||||
defer mglog.ExitWithError(&exitCode)
|
||||
|
||||
if cfg.InstanceID == "" {
|
||||
if cfg.InstanceID, err = uuid.New().ID(); err != nil {
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, targetServerConf, api.MakeHandler(ctx, svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(tc mainflux.AuthzServiceClient, nps messaging.PubSub, logger mflog.Logger, tracer trace.Tracer) ws.Service {
|
||||
func newService(tc magistrala.AuthzServiceClient, nps messaging.PubSub, logger mglog.Logger, tracer trace.Tracer) ws.Service {
|
||||
svc := ws.New(tc, nps)
|
||||
svc = tracing.New(tracer, svc)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
@@ -153,7 +153,7 @@ func newService(tc mainflux.AuthzServiceClient, nps messaging.PubSub, logger mfl
|
||||
return svc
|
||||
}
|
||||
|
||||
func proxyWS(ctx context.Context, cfg server.Config, logger mflog.Logger, handler session.Handler) error {
|
||||
func proxyWS(ctx context.Context, cfg server.Config, logger mglog.Logger, handler session.Handler) error {
|
||||
target := fmt.Sprintf("ws://%s:%s", targetWSHost, targetWSPort)
|
||||
address := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
|
||||
wp, err := websockets.NewProxy(address, target, logger, handler)
|
||||
|
||||
+4
-4
@@ -26,7 +26,7 @@ default values.
|
||||
| MG_THINGS_AUTH_GRPC_CA_CERTS | Path to trusted CAs in PEM format | |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker instance URL | nats://localhost:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_COAP_ADAPTER_INSTANCE_ID | CoAP adapter instance ID | |
|
||||
|
||||
## Deployment
|
||||
@@ -41,7 +41,7 @@ To start the service outside of the container, execute the following shell scrip
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the http
|
||||
make coap
|
||||
@@ -65,9 +65,9 @@ MG_THINGS_AUTH_GRPC_CLIENT_TLS=[Flag that indicates if TLS should be turned on]
|
||||
MG_THINGS_AUTH_GRPC_CA_CERTS=[Path to trusted CAs in PEM format] \
|
||||
MG_MESSAGE_BROKER_URL=[Message broker instance URL] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_COAP_ADAPTER_INSTANCE_ID=[CoAP adapter instance ID] \
|
||||
$GOBIN/mainflux-coap
|
||||
$GOBIN/magistrala-coap
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
+6
-6
@@ -11,7 +11,7 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
)
|
||||
@@ -39,13 +39,13 @@ var _ Service = (*adapterService)(nil)
|
||||
|
||||
// Observers is a map of maps,.
|
||||
type adapterService struct {
|
||||
auth mainflux.AuthzServiceClient
|
||||
auth magistrala.AuthzServiceClient
|
||||
pubsub messaging.PubSub
|
||||
obsLock sync.Mutex
|
||||
}
|
||||
|
||||
// New instantiates the CoAP adapter implementation.
|
||||
func New(auth mainflux.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
func New(auth magistrala.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
as := &adapterService{
|
||||
auth: auth,
|
||||
pubsub: pubsub,
|
||||
@@ -56,7 +56,7 @@ func New(auth mainflux.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
}
|
||||
|
||||
func (svc *adapterService) Publish(ctx context.Context, key string, msg *messaging.Message) error {
|
||||
ar := &mainflux.AuthorizeReq{
|
||||
ar := &magistrala.AuthorizeReq{
|
||||
Namespace: "",
|
||||
SubjectType: "thing",
|
||||
Permission: "publish",
|
||||
@@ -77,7 +77,7 @@ func (svc *adapterService) Publish(ctx context.Context, key string, msg *messagi
|
||||
}
|
||||
|
||||
func (svc *adapterService) Subscribe(ctx context.Context, key, chanID, subtopic string, c Client) error {
|
||||
ar := &mainflux.AuthorizeReq{
|
||||
ar := &magistrala.AuthorizeReq{
|
||||
Namespace: "",
|
||||
SubjectType: "thing",
|
||||
Permission: "subscribe",
|
||||
@@ -105,7 +105,7 @@ func (svc *adapterService) Subscribe(ctx context.Context, key, chanID, subtopic
|
||||
}
|
||||
|
||||
func (svc *adapterService) Unsubscribe(ctx context.Context, key, chanID, subtopic, token string) error {
|
||||
ar := &mainflux.AuthorizeReq{
|
||||
ar := &magistrala.AuthorizeReq{
|
||||
Namespace: "",
|
||||
SubjectType: "thing",
|
||||
Permission: "subscribe",
|
||||
|
||||
+3
-3
@@ -11,19 +11,19 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/coap"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
)
|
||||
|
||||
var _ coap.Service = (*loggingMiddleware)(nil)
|
||||
|
||||
type loggingMiddleware struct {
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
svc coap.Service
|
||||
}
|
||||
|
||||
// LoggingMiddleware adds logging facilities to the adapter.
|
||||
func LoggingMiddleware(svc coap.Service, logger mflog.Logger) coap.Service {
|
||||
func LoggingMiddleware(svc coap.Service, logger mglog.Logger) coap.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/coap"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/go-zoo/bone"
|
||||
@@ -44,21 +44,21 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
service coap.Service
|
||||
)
|
||||
|
||||
// MakeHandler returns a HTTP handler for API endpoints.
|
||||
func MakeHandler(instanceID string) http.Handler {
|
||||
b := bone.New()
|
||||
b.GetFunc("/health", mainflux.Health(protocol, instanceID))
|
||||
b.GetFunc("/health", magistrala.Health(protocol, instanceID))
|
||||
b.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// MakeCoAPHandler creates handler for CoAP messages.
|
||||
func MakeCoAPHandler(svc coap.Service, l mflog.Logger) mux.HandlerFunc {
|
||||
func MakeCoAPHandler(svc coap.Service, l mglog.Logger) mux.HandlerFunc {
|
||||
logger = l
|
||||
service = svc
|
||||
|
||||
|
||||
@@ -11,18 +11,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/consumers/notifiers"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
)
|
||||
|
||||
var _ notifiers.Service = (*loggingMiddleware)(nil)
|
||||
|
||||
type loggingMiddleware struct {
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
svc notifiers.Service
|
||||
}
|
||||
|
||||
// LoggingMiddleware adds logging facilities to the core service.
|
||||
func LoggingMiddleware(svc notifiers.Service, logger mflog.Logger) notifiers.Service {
|
||||
func LoggingMiddleware(svc notifiers.Service, logger mglog.Logger) notifiers.Service {
|
||||
return &loggingMiddleware{logger, svc}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
)
|
||||
|
||||
var (
|
||||
_ mainflux.Response = (*createSubRes)(nil)
|
||||
_ mainflux.Response = (*viewSubRes)(nil)
|
||||
_ mainflux.Response = (*listSubsRes)(nil)
|
||||
_ mainflux.Response = (*removeSubRes)(nil)
|
||||
_ magistrala.Response = (*createSubRes)(nil)
|
||||
_ magistrala.Response = (*viewSubRes)(nil)
|
||||
_ magistrala.Response = (*listSubsRes)(nil)
|
||||
_ magistrala.Response = (*removeSubRes)(nil)
|
||||
)
|
||||
|
||||
type createSubRes struct {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers/notifiers"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/logger"
|
||||
@@ -66,7 +66,7 @@ func MakeHandler(svc notifiers.Service, logger logger.Logger, instanceID string)
|
||||
opts...,
|
||||
), "delete"))
|
||||
|
||||
mux.GetFunc("/health", mainflux.Health("notifier", instanceID))
|
||||
mux.GetFunc("/health", magistrala.Health("notifier", instanceID))
|
||||
mux.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return mux
|
||||
@@ -122,7 +122,7 @@ func decodeList(_ context.Context, r *http.Request) (interface{}, error) {
|
||||
}
|
||||
|
||||
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
if ar, ok := response.(mainflux.Response); ok {
|
||||
if ar, ok := response.(magistrala.Response); ok {
|
||||
for k, v := range ar.Headers() {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ default values.
|
||||
| MG_SMPP_NOTIFIER_HTTP_SERVER_KEY | Service HTTP server key | "" |
|
||||
| MG_SMPP_NOTIFIER_DB_HOST | Database host address | localhost |
|
||||
| MG_SMPP_NOTIFIER_DB_PORT | Database host port | 5432 |
|
||||
| MG_SMPP_NOTIFIER_DB_USER | Database user | mainflux |
|
||||
| MG_SMPP_NOTIFIER_DB_PASS | Database password | mainflux |
|
||||
| MG_SMPP_NOTIFIER_DB_USER | Database user | magistrala |
|
||||
| MG_SMPP_NOTIFIER_DB_PASS | Database password | magistrala |
|
||||
| MG_SMPP_NOTIFIER_DB_NAME | Name of the database used by the service | subscriptions |
|
||||
| MG_SMPP_NOTIFIER_DB_SSL_MODE | DB connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| MG_SMPP_NOTIFIER_DB_SSL_CERT | Path to the PEM encoded certificate file | "" |
|
||||
@@ -40,7 +40,7 @@ default values.
|
||||
| MG_AUTH_GRPC_CA_CERT | Path to Auth client CA certs in pem format | "" |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker URL | nats://127.0.0.1:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_SMPP_NOTIFIER_INSTANCE_ID | SMPP Notifier instance ID | "" |
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -19,8 +19,8 @@ default values.
|
||||
| MG_SMTP_NOTIFIER_HTTP_SERVER_KEY | SMTP Notifier service HTTP server key | "" |
|
||||
| MG_SMTP_NOTIFIER_DB_HOST | Database host address | localhost |
|
||||
| MG_SMTP_NOTIFIER_DB_PORT | Database host port | 5432 |
|
||||
| MG_SMTP_NOTIFIER_DB_USER | Database user | mainflux |
|
||||
| MG_SMTP_NOTIFIER_DB_PASS | Database password | mainflux |
|
||||
| MG_SMTP_NOTIFIER_DB_USER | Database user | magistrala |
|
||||
| MG_SMTP_NOTIFIER_DB_PASS | Database password | magistrala |
|
||||
| MG_SMTP_NOTIFIER_DB_NAME | Name of the database used by the service | subscriptions |
|
||||
| MG_SMTP_NOTIFIER_DB_SSL_MODE | Database connection SSL mode (disable, require, verify-ca, verify-full) | disable |
|
||||
| MG_SMTP_NOTIFIER_DB_SSL_CERT | Path to the PEM encoded cert file | "" |
|
||||
@@ -41,7 +41,7 @@ default values.
|
||||
| MG_AUTH_GRPC_CA_CERT | Path to Users service CA cert in pem format | "" |
|
||||
| MG_AUTH_CLIENT_TLS | Auth client TLS flag | false |
|
||||
| MG_AUTH_CA_CERTS | Path to Auth client CA certs in pem format | "" |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_SMTP_NOTIFIER_INSTANCE_ID | SMTP Notifier instance ID | "" |
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/internal/server"
|
||||
mfjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
mgjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
"github.com/absmach/magistrala/pkg/transformers/senml"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
@@ -69,7 +69,7 @@ func NewBlocking(tracer trace.Tracer, consumerBlock consumers.BlockingConsumer,
|
||||
func (tm *tracingMiddlewareBlock) ConsumeBlocking(ctx context.Context, messages interface{}) error {
|
||||
var span trace.Span
|
||||
switch m := messages.(type) {
|
||||
case mfjson.Messages:
|
||||
case mgjson.Messages:
|
||||
if len(m.Data) > 0 {
|
||||
firstMsg := m.Data[0]
|
||||
ctx, span = createSpan(ctx, consumeBlockingOP, firstMsg.Publisher, firstMsg.Channel, firstMsg.Subtopic, len(m.Data), tm.host, trace.SpanKindConsumer, tm.tracer)
|
||||
@@ -89,7 +89,7 @@ func (tm *tracingMiddlewareBlock) ConsumeBlocking(ctx context.Context, messages
|
||||
func (tm *tracingMiddlewareAsync) ConsumeAsync(ctx context.Context, messages interface{}) {
|
||||
var span trace.Span
|
||||
switch m := messages.(type) {
|
||||
case mfjson.Messages:
|
||||
case mgjson.Messages:
|
||||
if len(m.Data) > 0 {
|
||||
firstMsg := m.Data[0]
|
||||
ctx, span = createSpan(ctx, consumeAsyncOP, firstMsg.Publisher, firstMsg.Channel, firstMsg.Subtopic, len(m.Data), tm.host, trace.SpanKindConsumer, tm.tracer)
|
||||
|
||||
@@ -11,18 +11,18 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
)
|
||||
|
||||
var _ consumers.BlockingConsumer = (*loggingMiddleware)(nil)
|
||||
|
||||
type loggingMiddleware struct {
|
||||
logger mflog.Logger
|
||||
logger mglog.Logger
|
||||
consumer consumers.BlockingConsumer
|
||||
}
|
||||
|
||||
// LoggingMiddleware adds logging facilities to the adapter.
|
||||
func LoggingMiddleware(consumer consumers.BlockingConsumer, logger mflog.Logger) consumers.BlockingConsumer {
|
||||
func LoggingMiddleware(consumer consumers.BlockingConsumer, logger mglog.Logger) consumers.BlockingConsumer {
|
||||
return &loggingMiddleware{
|
||||
logger: logger,
|
||||
consumer: consumer,
|
||||
|
||||
@@ -6,7 +6,7 @@ package api
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/go-zoo/bone"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// MakeHandler returns a HTTP API handler with health check and metrics.
|
||||
func MakeHandler(svcName, instanceID string) http.Handler {
|
||||
r := bone.New()
|
||||
r.GetFunc("/health", mainflux.Health(svcName, instanceID))
|
||||
r.GetFunc("/health", magistrala.Health(svcName, instanceID))
|
||||
r.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return r
|
||||
|
||||
@@ -17,13 +17,13 @@ default values.
|
||||
| MG_CASSANDRA_WRITER_HTTP_SERVER_CERT | Cassandra service HTTP server certificate path | |
|
||||
| MG_CASSANDRA_WRITER_HTTP_SERVER_KEY | Cassandra service HTTP server key path | |
|
||||
| MG_CASSANDRA_CLUSTER | Cassandra cluster comma separated addresses | 127.0.0.1 |
|
||||
| MG_CASSANDRA_KEYSPACE | Cassandra keyspace name | mainflux |
|
||||
| MG_CASSANDRA_USER | Cassandra DB username | mainflux |
|
||||
| MG_CASSANDRA_PASS | Cassandra DB password | mainflux |
|
||||
| MG_CASSANDRA_KEYSPACE | Cassandra keyspace name | magistrala |
|
||||
| MG_CASSANDRA_USER | Cassandra DB username | magistrala |
|
||||
| MG_CASSANDRA_PASS | Cassandra DB password | magistrala |
|
||||
| MG_CASSANDRA_PORT | Cassandra DB port | 9042 |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker instance URL | nats://localhost:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_CASSANDRA_WRITER_INSANCE_ID | Cassandra writer instance ID | |
|
||||
|
||||
## Deployment
|
||||
@@ -36,7 +36,7 @@ To start the service, execute the following shell script:
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the cassandra writer
|
||||
make cassandra-writer
|
||||
@@ -58,9 +58,9 @@ MG_CASSANDRA_PASS=[Cassandra DB password] \
|
||||
MG_CASSANDRA_PORT=[Cassandra DB port] \
|
||||
MG_MESSAGE_BROKER_URL=[Message Broker instance URL] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_CASSANDRA_WRITER_INSANCE_ID=[Cassandra writer instance ID] \
|
||||
$GOBIN/mainflux-cassandra-writer
|
||||
$GOBIN/magistrala-cassandra-writer
|
||||
```
|
||||
|
||||
### Using docker-compose
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
mgjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
"github.com/absmach/magistrala/pkg/transformers/senml"
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
@@ -32,7 +32,7 @@ func New(session *gocql.Session) consumers.BlockingConsumer {
|
||||
|
||||
func (cr *cassandraRepository) ConsumeBlocking(_ context.Context, message interface{}) error {
|
||||
switch m := message.(type) {
|
||||
case mfjson.Messages:
|
||||
case mgjson.Messages:
|
||||
return cr.saveJSON(m)
|
||||
default:
|
||||
return cr.saveSenml(m)
|
||||
@@ -62,7 +62,7 @@ func (cr *cassandraRepository) saveSenml(messages interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *cassandraRepository) saveJSON(msgs mfjson.Messages) error {
|
||||
func (cr *cassandraRepository) saveJSON(msgs mgjson.Messages) error {
|
||||
if err := cr.insertJSON(msgs); err != nil {
|
||||
if err == errNoTable {
|
||||
if err := cr.createTable(msgs.Format); err != nil {
|
||||
@@ -75,7 +75,7 @@ func (cr *cassandraRepository) saveJSON(msgs mfjson.Messages) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cr *cassandraRepository) insertJSON(msgs mfjson.Messages) error {
|
||||
func (cr *cassandraRepository) insertJSON(msgs mgjson.Messages) error {
|
||||
cql := `INSERT INTO %s (id, channel, created, subtopic, publisher, protocol, payload) VALUES (?, ?, ?, ?, ?, ?, ?)`
|
||||
cql = fmt.Sprintf(cql, msgs.Format)
|
||||
for _, msg := range msgs.Data {
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/absmach/magistrala/internal/clients/cassandra"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/gocql/gocql"
|
||||
"github.com/ory/dockertest/v3"
|
||||
)
|
||||
|
||||
var logger, _ = mflog.New(os.Stdout, mflog.Info.String())
|
||||
var logger, _ = mglog.New(os.Stdout, mglog.Info.String())
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
pool, err := dockertest.NewPool("")
|
||||
|
||||
@@ -17,21 +17,21 @@ default values.
|
||||
| MG_INFLUX_WRITER_HTTP_SERVER_CERT | Path to server certificate in pem format | |
|
||||
| MG_INFLUX_WRITER_HTTP_SERVER_KEY | Path to server key in pem format | |
|
||||
| MG_INFLUXDB_PROTOCOL | InfluxDB protocol | http |
|
||||
| MG_INFLUXDB_HOST | InfluxDB host name | mainflux-influxdb |
|
||||
| MG_INFLUXDB_HOST | InfluxDB host name | magistrala-influxdb |
|
||||
| MG_INFLUXDB_PORT | Default port of InfluxDB database | 8086 |
|
||||
| MG_INFLUXDB_ADMIN_USER | Default user of InfluxDB database | mainflux |
|
||||
| MG_INFLUXDB_ADMIN_PASSWORD | Default password of InfluxDB user | mainflux |
|
||||
| MG_INFLUXDB_NAME | InfluxDB database name | mainflux |
|
||||
| MG_INFLUXDB_BUCKET | InfluxDB bucket name | mainflux-bucket |
|
||||
| MG_INFLUXDB_ORG | InfluxDB organization name | mainflux |
|
||||
| MG_INFLUXDB_TOKEN | InfluxDB API token | mainflux-token |
|
||||
| MG_INFLUXDB_ADMIN_USER | Default user of InfluxDB database | magistrala |
|
||||
| MG_INFLUXDB_ADMIN_PASSWORD | Default password of InfluxDB user | magistrala |
|
||||
| MG_INFLUXDB_NAME | InfluxDB database name | magistrala |
|
||||
| MG_INFLUXDB_BUCKET | InfluxDB bucket name | magistrala-bucket |
|
||||
| MG_INFLUXDB_ORG | InfluxDB organization name | magistrala |
|
||||
| MG_INFLUXDB_TOKEN | InfluxDB API token | magistrala-token |
|
||||
| MG_INFLUXDB_DBURL | InfluxDB database URL | |
|
||||
| MG_INFLUXDB_USER_AGENT | InfluxDB user agent | |
|
||||
| MG_INFLUXDB_TIMEOUT | InfluxDB client connection readiness timeout | 1s |
|
||||
| MG_INFLUXDB_INSECURE_SKIP_VERIFY | InfluxDB client connection insecure skip verify | false |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker instance URL | nats://localhost:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_INFLUX_WRITER_INSTANCE_ID | InfluxDB writer instance ID | |
|
||||
|
||||
## Deployment
|
||||
@@ -44,7 +44,7 @@ To start the service, execute the following shell script:
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the influxdb
|
||||
make influxdb
|
||||
@@ -74,9 +74,9 @@ MG_INFLUXDB_TIMEOUT=[InfluxDB timeout] \
|
||||
MG_INFLUXDB_INSECURE_SKIP_VERIFY=[InfluxDB insecure skip verify] \
|
||||
MG_MESSAGE_BROKER_URL=[Message broker instance URL] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_INFLUX_WRITER_INSTANCE_ID=[Influx writer instance ID] \
|
||||
$GOBIN/mainflux-influxdb
|
||||
$GOBIN/magistrala-influxdb
|
||||
```
|
||||
|
||||
### Using docker-compose
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
writer "github.com/absmach/magistrala/consumers/writers/influxdb"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/transformers/json"
|
||||
"github.com/absmach/magistrala/pkg/transformers/senml"
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
const valueFields = 5
|
||||
|
||||
var (
|
||||
testLog, _ = mflog.New(os.Stdout, mflog.Info.String())
|
||||
testLog, _ = mglog.New(os.Stdout, mglog.Info.String())
|
||||
streamsSize = 250
|
||||
rowCountSenml = fmt.Sprintf(`from(bucket: "%s")
|
||||
|> range(start: -1h, stop: 1h)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) Magistrala
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package influxdb
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) Magistrala
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package influxdb
|
||||
|
||||
import (
|
||||
|
||||
@@ -21,7 +21,7 @@ default values.
|
||||
| MG_MONGO_PORT | Default MongoDB database port | 27017 |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker instance URL | nats://localhost:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_MONGO_WRITER_INSTANCE_ID | MongoDB writer instance ID | "" |
|
||||
|
||||
## Deployment
|
||||
@@ -34,7 +34,7 @@ To start the service, execute the following shell script:
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the mongodb writer
|
||||
make mongodb-writer
|
||||
@@ -54,10 +54,10 @@ MG_MONGO_HOST=[MongoDB database host] \
|
||||
MG_MONGO_PORT=[MongoDB database port] \
|
||||
MG_MESSAGE_BROKER_URL=[Message broker instance URL] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_MONGO_WRITER_INSTANCE_ID=[MongoDB writer instance ID] \
|
||||
|
||||
$GOBIN/mainflux-mongodb-writer
|
||||
$GOBIN/magistrala-mongodb-writer
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/absmach/magistrala/consumers/writers/mongodb"
|
||||
mflog "github.com/absmach/magistrala/logger"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/transformers/json"
|
||||
"github.com/absmach/magistrala/pkg/transformers/senml"
|
||||
"github.com/gofrs/uuid"
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
var (
|
||||
port string
|
||||
addr string
|
||||
testLog, _ = mflog.New(os.Stdout, mflog.Info.String())
|
||||
testLog, _ = mglog.New(os.Stdout, mglog.Info.String())
|
||||
testDB = "test"
|
||||
collection = "messages"
|
||||
msgsNum = 100
|
||||
|
||||
@@ -18,8 +18,8 @@ default values.
|
||||
| MG_POSTGRES_WRITER_HTTP_SERVER_KEY | Service HTTP server key | "" |
|
||||
| MG_POSTGRES_HOST | Postgres DB host | postgres |
|
||||
| MG_POSTGRES_PORT | Postgres DB port | 5432 |
|
||||
| MG_POSTGRES_USER | Postgres user | mainflux |
|
||||
| MG_POSTGRES_PASS | Postgres password | mainflux |
|
||||
| MG_POSTGRES_USER | Postgres user | magistrala |
|
||||
| MG_POSTGRES_PASS | Postgres password | magistrala |
|
||||
| MG_POSTGRES_NAME | Postgres database name | messages |
|
||||
| MG_POSTGRES_SSL_MODE | Postgres SSL mode | disabled |
|
||||
| MG_POSTGRES_SSL_CERT | Postgres SSL certificate path | "" |
|
||||
@@ -27,7 +27,7 @@ default values.
|
||||
| MG_POSTGRES_SSL_ROOT_CERT | Postgres SSL root certificate path | "" |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker instance URL | nats://localhost:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_POSTGRES_WRITER_INSTANCE_ID | Service instance ID | "" |
|
||||
|
||||
## Deployment
|
||||
@@ -40,7 +40,7 @@ To start the service, execute the following shell script:
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the postgres writer
|
||||
make postgres-writer
|
||||
@@ -66,10 +66,10 @@ MG_POSTGRES_SSL_KEY=[Postgres SSL key] \
|
||||
MG_POSTGRES_SSL_ROOT_CERT=[Postgres SSL Root cert] \
|
||||
MG_MESSAGE_BROKER_URL=[Message broker instance URL] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_POSTGRES_WRITER_INSTANCE_ID=[Service instance ID] \
|
||||
|
||||
$GOBIN/mainflux-postgres-writer
|
||||
$GOBIN/magistrala-postgres-writer
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
mgjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
"github.com/absmach/magistrala/pkg/transformers/senml"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/jackc/pgerrcode"
|
||||
@@ -38,7 +38,7 @@ func New(db *sqlx.DB) consumers.BlockingConsumer {
|
||||
|
||||
func (pr postgresRepo) ConsumeBlocking(ctx context.Context, message interface{}) (err error) {
|
||||
switch m := message.(type) {
|
||||
case mfjson.Messages:
|
||||
case mgjson.Messages:
|
||||
return pr.saveJSON(ctx, m)
|
||||
default:
|
||||
return pr.saveSenml(ctx, m)
|
||||
@@ -94,7 +94,7 @@ func (pr postgresRepo) saveSenml(ctx context.Context, messages interface{}) (err
|
||||
return err
|
||||
}
|
||||
|
||||
func (pr postgresRepo) saveJSON(ctx context.Context, msgs mfjson.Messages) error {
|
||||
func (pr postgresRepo) saveJSON(ctx context.Context, msgs mgjson.Messages) error {
|
||||
if err := pr.insertJSON(ctx, msgs); err != nil {
|
||||
if err == errNoTable {
|
||||
if err := pr.createTable(msgs.Format); err != nil {
|
||||
@@ -107,7 +107,7 @@ func (pr postgresRepo) saveJSON(ctx context.Context, msgs mfjson.Messages) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pr postgresRepo) insertJSON(ctx context.Context, msgs mfjson.Messages) error {
|
||||
func (pr postgresRepo) insertJSON(ctx context.Context, msgs mgjson.Messages) error {
|
||||
tx, err := pr.db.BeginTxx(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(errSaveMessage, err)
|
||||
@@ -184,7 +184,7 @@ type jsonMessage struct {
|
||||
Payload []byte `db:"payload"`
|
||||
}
|
||||
|
||||
func toJSONMessage(msg mfjson.Message) (jsonMessage, error) {
|
||||
func toJSONMessage(msg mgjson.Message) (jsonMessage, error) {
|
||||
id, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return jsonMessage{}, err
|
||||
|
||||
@@ -18,8 +18,8 @@ default values.
|
||||
| MG_TIMESCALE_WRITER_HTTP_SERVER_KEY | Service HTTP server key | "" |
|
||||
| MG_TIMESCALE_HOST | Timescale DB host | timescale |
|
||||
| MG_TIMESCALE_PORT | Timescale DB port | 5432 |
|
||||
| MG_TIMESCALE_USER | Timescale user | mainflux |
|
||||
| MG_TIMESCALE_PASS | Timescale password | mainflux |
|
||||
| MG_TIMESCALE_USER | Timescale user | magistrala |
|
||||
| MG_TIMESCALE_PASS | Timescale password | magistrala |
|
||||
| MG_TIMESCALE_NAME | Timescale database name | messages |
|
||||
| MG_TIMESCALE_SSL_MODE | Timescale SSL mode | disabled |
|
||||
| MG_TIMESCALE_SSL_CERT | Timescale SSL certificate path | "" |
|
||||
@@ -27,7 +27,7 @@ default values.
|
||||
| MG_TIMESCALE_SSL_ROOT_CERT | Timescale SSL root certificate path | "" |
|
||||
| MG_MESSAGE_BROKER_URL | Message broker instance URL | nats://localhost:4222 |
|
||||
| MG_JAEGER_URL | Jaeger server URL | http://jaeger:14268/api/traces |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to mainflux call home server | true |
|
||||
| MG_SEND_TELEMETRY | Send telemetry to magistrala call home server | true |
|
||||
| MG_TIMESCALE_WRITER_INSTANCE_ID | Timescale writer instance ID | "" |
|
||||
|
||||
## Deployment
|
||||
@@ -40,7 +40,7 @@ To start the service, execute the following shell script:
|
||||
# download the latest version of the service
|
||||
git clone https://github.com/absmach/magistrala
|
||||
|
||||
cd mainflux
|
||||
cd magistrala
|
||||
|
||||
# compile the timescale writer
|
||||
make timescale-writer
|
||||
@@ -66,9 +66,9 @@ MG_TIMESCALE_SSL_KEY=[Timescale SSL key] \
|
||||
MG_TIMESCALE_SSL_ROOT_CERT=[Timescale SSL Root cert] \
|
||||
MG_MESSAGE_BROKER_URL=[Message broker instance URL] \
|
||||
MG_JAEGER_URL=[Jaeger server URL] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to mainflux call home server] \
|
||||
MG_SEND_TELEMETRY=[Send telemetry to magistrala call home server] \
|
||||
MG_TIMESCALE_WRITER_INSTANCE_ID=[Timescale writer instance ID] \
|
||||
$GOBIN/mainflux-timescale-writer
|
||||
$GOBIN/magistrala-timescale-writer
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
mgjson "github.com/absmach/magistrala/pkg/transformers/json"
|
||||
"github.com/absmach/magistrala/pkg/transformers/senml"
|
||||
"github.com/jackc/pgerrcode"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
@@ -37,7 +37,7 @@ func New(db *sqlx.DB) consumers.BlockingConsumer {
|
||||
|
||||
func (tr *timescaleRepo) ConsumeBlocking(ctx context.Context, message interface{}) (err error) {
|
||||
switch m := message.(type) {
|
||||
case mfjson.Messages:
|
||||
case mgjson.Messages:
|
||||
return tr.saveJSON(ctx, m)
|
||||
default:
|
||||
return tr.saveSenml(ctx, m)
|
||||
@@ -89,7 +89,7 @@ func (tr timescaleRepo) saveSenml(ctx context.Context, messages interface{}) (er
|
||||
return err
|
||||
}
|
||||
|
||||
func (tr timescaleRepo) saveJSON(ctx context.Context, msgs mfjson.Messages) error {
|
||||
func (tr timescaleRepo) saveJSON(ctx context.Context, msgs mgjson.Messages) error {
|
||||
if err := tr.insertJSON(ctx, msgs); err != nil {
|
||||
if err == errNoTable {
|
||||
if err := tr.createTable(msgs.Format); err != nil {
|
||||
@@ -102,7 +102,7 @@ func (tr timescaleRepo) saveJSON(ctx context.Context, msgs mfjson.Messages) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tr timescaleRepo) insertJSON(ctx context.Context, msgs mfjson.Messages) error {
|
||||
func (tr timescaleRepo) insertJSON(ctx context.Context, msgs mgjson.Messages) error {
|
||||
tx, err := tr.db.BeginTxx(ctx, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(errSaveMessage, err)
|
||||
@@ -175,7 +175,7 @@ type jsonMessage struct {
|
||||
Payload []byte `db:"payload"`
|
||||
}
|
||||
|
||||
func toJSONMessage(msg mfjson.Message) (jsonMessage, error) {
|
||||
func toJSONMessage(msg mgjson.Message) (jsonMessage, error) {
|
||||
data := []byte("{}")
|
||||
if msg.Payload != nil {
|
||||
b, err := json.Marshal(msg.Payload)
|
||||
|
||||
+1
-1
@@ -309,7 +309,7 @@ MG_VAULT_CA_L=Belgrade
|
||||
|
||||
### LoRa
|
||||
MG_LORA_ADAPTER_LOG_LEVEL=debug
|
||||
MG_LORA_ADAPTER_MESSAGES_URL=tcp://mainflux-mqtt:1883
|
||||
MG_LORA_ADAPTER_MESSAGES_URL=tcp://magistrala-mqtt:1883
|
||||
MG_LORA_ADAPTER_MESSAGES_TOPIC=application/+/device/+/event/up
|
||||
MG_LORA_ADAPTER_MESSAGES_USER=
|
||||
MG_LORA_ADAPTER_MESSAGES_PASS=
|
||||
|
||||
+3
-4
@@ -2,22 +2,21 @@
|
||||
|
||||
Configure environment variables and run Magistrala Docker Composition.
|
||||
|
||||
*Note**: `docker-compose` uses `.env` file to set all environment variables. Ensure that you run the command from the same location as .env file.
|
||||
\*Note\*\*: `docker-compose` uses `.env` file to set all environment variables. Ensure that you run the command from the same location as .env file.
|
||||
|
||||
## Installation
|
||||
|
||||
Follow the [official documentation](https://docs.docker.com/compose/install/).
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Run following commands from project root directory.
|
||||
|
||||
```
|
||||
```bash
|
||||
docker-compose -f docker/docker-compose.yml up
|
||||
```
|
||||
|
||||
```
|
||||
```bash
|
||||
docker-compose -f docker/addons/<path>/docker-compose.yml up
|
||||
```
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ global:
|
||||
evaluation_interval: 15s
|
||||
|
||||
scrape_configs:
|
||||
- job_name: 'mainflux'
|
||||
- job_name: 'magistrala'
|
||||
honor_timestamps: true
|
||||
scrape_interval: 15s
|
||||
scrape_timeout: 10s
|
||||
|
||||
@@ -6,23 +6,23 @@ When the Vault service is started, some initialization steps need to be done to
|
||||
|
||||
## Configuration
|
||||
|
||||
| Variable | Description | Default |
|
||||
| --------------------- | ------------------------------------------------------- | -------------- |
|
||||
| MG_VAULT_HOST | Vault service address | vault |
|
||||
| MG_VAULT_PORT | Vault service port | 8200 |
|
||||
| MG_VAULT_UNSEAL_KEY_1 | Vault unseal key | "" |
|
||||
| MG_VAULT_UNSEAL_KEY_2 | Vault unseal key | "" |
|
||||
| MG_VAULT_UNSEAL_KEY_3 | Vault unseal key | "" |
|
||||
| MG_VAULT_TOKEN | Vault cli access token | "" |
|
||||
| MG_VAULT_PKI_PATH | Vault secrets engine path for CA | pki |
|
||||
| MG_VAULT_PKI_INT_PATH | Vault secrets engine path for intermediate CA | pki_int |
|
||||
| MG_VAULT_CA_ROLE_NAME | Vault secrets engine role | mainflux |
|
||||
| MG_VAULT_CA_NAME | Certificates name used by `vault-set-pki.sh` | mainflux |
|
||||
| MG_VAULT_CA_CN | Common name used for CA creation by `vault-set-pki.sh` | mainflux.com |
|
||||
| Variable | Description | Default |
|
||||
| --------------------- | ------------------------------------------------------- | ---------------- |
|
||||
| MG_VAULT_HOST | Vault service address | vault |
|
||||
| MG_VAULT_PORT | Vault service port | 8200 |
|
||||
| MG_VAULT_UNSEAL_KEY_1 | Vault unseal key | "" |
|
||||
| MG_VAULT_UNSEAL_KEY_2 | Vault unseal key | "" |
|
||||
| MG_VAULT_UNSEAL_KEY_3 | Vault unseal key | "" |
|
||||
| MG_VAULT_TOKEN | Vault cli access token | "" |
|
||||
| MG_VAULT_PKI_PATH | Vault secrets engine path for CA | pki |
|
||||
| MG_VAULT_PKI_INT_PATH | Vault secrets engine path for intermediate CA | pki_int |
|
||||
| MG_VAULT_CA_ROLE_NAME | Vault secrets engine role | magistrala |
|
||||
| MG_VAULT_CA_NAME | Certificates name used by `vault-set-pki.sh` | magistrala |
|
||||
| MG_VAULT_CA_CN | Common name used for CA creation by `vault-set-pki.sh` | magistrala.com |
|
||||
| MG_VAULT_CA_OU | Org unit used for CA creation by `vault-set-pki.sh` | Magistrala Cloud |
|
||||
| MG_VAULT_CA_O | Organization used for CA creation by `vault-set-pki.sh` | Magistrala Labs |
|
||||
| MG_VAULT_CA_C | Country used for CA creation by `vault-set-pki.sh` | Serbia |
|
||||
| MG_VAULT_CA_L | Location used for CA creation by `vault-set-pki.sh` | Belgrade |
|
||||
| MG_VAULT_CA_C | Country used for CA creation by `vault-set-pki.sh` | Serbia |
|
||||
| MG_VAULT_CA_L | Location used for CA creation by `vault-set-pki.sh` | Belgrade |
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -84,7 +84,7 @@ The CA parameters are obtained from the environment variables starting with `MG_
|
||||
|
||||
It can also be useful to run the Vault CLI for inspection and administration work.
|
||||
|
||||
This can be done directly using the Vault image in Docker: `docker run -it mainflux/vault:latest vault`
|
||||
This can be done directly using the Vault image in Docker: `docker run -it magistrala/vault:latest vault`
|
||||
|
||||
```bash
|
||||
Usage: vault <command> [args]
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user