-
Notifications
You must be signed in to change notification settings - Fork 676
/
sdk.go
1415 lines (1264 loc) · 42.3 KB
/
sdk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package sdk
import (
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"github.com/absmach/magistrala/pkg/errors"
"moul.io/http2curl"
)
const (
// CTJSON represents JSON content type.
CTJSON ContentType = "application/json"
// CTJSONSenML represents JSON SenML content type.
CTJSONSenML ContentType = "application/senml+json"
// CTBinary represents binary content type.
CTBinary ContentType = "application/octet-stream"
// EnabledStatus represents enable status for a client.
EnabledStatus = "enabled"
// DisabledStatus represents disabled status for a client.
DisabledStatus = "disabled"
BearerPrefix = "Bearer "
ThingPrefix = "Thing "
)
// ContentType represents all possible content types.
type ContentType string
var _ SDK = (*mgSDK)(nil)
var (
// ErrFailedCreation indicates that entity creation failed.
ErrFailedCreation = errors.New("failed to create entity in the db")
// ErrFailedList indicates that entities list failed.
ErrFailedList = errors.New("failed to list entities")
// ErrFailedUpdate indicates that entity update failed.
ErrFailedUpdate = errors.New("failed to update entity")
// ErrFailedFetch indicates that fetching of entity data failed.
ErrFailedFetch = errors.New("failed to fetch entity")
// ErrFailedRemoval indicates that entity removal failed.
ErrFailedRemoval = errors.New("failed to remove entity")
// ErrFailedEnable indicates that client enable failed.
ErrFailedEnable = errors.New("failed to enable client")
// ErrFailedDisable indicates that client disable failed.
ErrFailedDisable = errors.New("failed to disable client")
ErrInvalidJWT = errors.New("invalid JWT")
)
type MessagePageMetadata struct {
PageMetadata
Subtopic string `json:"subtopic,omitempty"`
Publisher string `json:"publisher,omitempty"`
Comparator string `json:"comparator,omitempty"`
BoolValue *bool `json:"vb,omitempty"`
StringValue string `json:"vs,omitempty"`
DataValue string `json:"vd,omitempty"`
From float64 `json:"from,omitempty"`
To float64 `json:"to,omitempty"`
Aggregation string `json:"aggregation,omitempty"`
Interval string `json:"interval,omitempty"`
Value float64 `json:"value,omitempty"`
Protocol string `json:"protocol,omitempty"`
}
type PageMetadata struct {
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Order string `json:"order,omitempty"`
Direction string `json:"direction,omitempty"`
Level uint64 `json:"level,omitempty"`
Identity string `json:"identity,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
Status string `json:"status,omitempty"`
Action string `json:"action,omitempty"`
Subject string `json:"subject,omitempty"`
Object string `json:"object,omitempty"`
Permission string `json:"permission,omitempty"`
Tag string `json:"tag,omitempty"`
Owner string `json:"owner,omitempty"`
SharedBy string `json:"shared_by,omitempty"`
Visibility string `json:"visibility,omitempty"`
OwnerID string `json:"owner_id,omitempty"`
Topic string `json:"topic,omitempty"`
Contact string `json:"contact,omitempty"`
State string `json:"state,omitempty"`
ListPermissions string `json:"list_perms,omitempty"`
InvitedBy string `json:"invited_by,omitempty"`
UserID string `json:"user_id,omitempty"`
DomainID string `json:"domain_id,omitempty"`
Relation string `json:"relation,omitempty"`
Operation string `json:"operation,omitempty"`
From int64 `json:"from,omitempty"`
To int64 `json:"to,omitempty"`
WithMetadata bool `json:"with_metadata,omitempty"`
WithAttributes bool `json:"with_attributes,omitempty"`
ID string `json:"id,omitempty"`
}
// Credentials represent client credentials: it contains
// "identity" which can be a username, email, generated name;
// and "secret" which can be a password or access token.
type Credentials struct {
Identity string `json:"identity,omitempty"` // username or generated login ID
Secret string `json:"secret,omitempty"` // password or token
}
// SDK contains Magistrala API.
//
//go:generate mockery --name SDK --output=../mocks --filename sdk.go --quiet --note "Copyright (c) Abstract Machines"
type SDK interface {
// CreateUser registers magistrala user.
//
// example:
// user := sdk.User{
// Name: "John Doe",
// Credentials: sdk.Credentials{
// Identity: "john.doe@example",
// Secret: "12345678",
// },
// }
// user, _ := sdk.CreateUser(user)
// fmt.Println(user)
CreateUser(user User, token string) (User, errors.SDKError)
// User returns user object by id.
//
// example:
// user, _ := sdk.User("userID", "token")
// fmt.Println(user)
User(id, token string) (User, errors.SDKError)
// Users returns list of users.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "John Doe",
// }
// users, _ := sdk.Users(pm, "token")
// fmt.Println(users)
Users(pm PageMetadata, token string) (UsersPage, errors.SDKError)
// Members returns list of users that are members of a group.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// }
// members, _ := sdk.Members("groupID", pm, "token")
// fmt.Println(members)
Members(groupID string, meta PageMetadata, token string) (UsersPage, errors.SDKError)
// UserProfile returns user logged in.
//
// example:
// user, _ := sdk.UserProfile("token")
// fmt.Println(user)
UserProfile(token string) (User, errors.SDKError)
// UpdateUser updates existing user.
//
// example:
// user := sdk.User{
// ID: "userID",
// Name: "John Doe",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// user, _ := sdk.UpdateUser(user, "token")
// fmt.Println(user)
UpdateUser(user User, token string) (User, errors.SDKError)
// UpdateUserTags updates the user's tags.
//
// example:
// user := sdk.User{
// ID: "userID",
// Tags: []string{"tag1", "tag2"},
// }
// user, _ := sdk.UpdateUserTags(user, "token")
// fmt.Println(user)
UpdateUserTags(user User, token string) (User, errors.SDKError)
// UpdateUserIdentity updates the user's identity
//
// example:
// user := sdk.User{
// ID: "userID",
// Credentials: sdk.Credentials{
// Identity: "john.doe@example",
// },
// }
// user, _ := sdk.UpdateUserIdentity(user, "token")
// fmt.Println(user)
UpdateUserIdentity(user User, token string) (User, errors.SDKError)
// UpdateUserRole updates the user's role.
//
// example:
// user := sdk.User{
// ID: "userID",
// Role: "role",
// }
// user, _ := sdk.UpdateUserRole(user, "token")
// fmt.Println(user)
UpdateUserRole(user User, token string) (User, errors.SDKError)
// ResetPasswordRequest sends a password request email to a user.
//
// example:
// err := sdk.ResetPasswordRequest("[email protected]")
// fmt.Println(err)
ResetPasswordRequest(email string) errors.SDKError
// ResetPassword changes a user's password to the one passed in the argument.
//
// example:
// err := sdk.ResetPassword("password","password","token")
// fmt.Println(err)
ResetPassword(password, confPass, token string) errors.SDKError
// UpdatePassword updates user password.
//
// example:
// user, _ := sdk.UpdatePassword("oldPass", "newPass", "token")
// fmt.Println(user)
UpdatePassword(oldPass, newPass, token string) (User, errors.SDKError)
// EnableUser changes the status of the user to enabled.
//
// example:
// user, _ := sdk.EnableUser("userID", "token")
// fmt.Println(user)
EnableUser(id, token string) (User, errors.SDKError)
// DisableUser changes the status of the user to disabled.
//
// example:
// user, _ := sdk.DisableUser("userID", "token")
// fmt.Println(user)
DisableUser(id, token string) (User, errors.SDKError)
// DeleteUser deletes a user with the given id.
//
// example:
// err := sdk.DeleteUser("userID", "token")
// fmt.Println(err)
DeleteUser(id, token string) errors.SDKError
// CreateToken receives credentials and returns user token.
//
// example:
// lt := sdk.Login{
// Identity: "john.doe@example",
// Secret: "12345678",
// }
// token, _ := sdk.CreateToken(lt)
// fmt.Println(token)
CreateToken(lt Login) (Token, errors.SDKError)
// RefreshToken receives credentials and returns user token.
//
// example:
// lt := sdk.Login{
// DomainID: "domain_id",
// }
// example:
// token, _ := sdk.RefreshToken(lt,"refresh_token")
// fmt.Println(token)
RefreshToken(lt Login, token string) (Token, errors.SDKError)
// ListUserChannels list all channels belongs a particular user id.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "viewer", "guest", "editor", "contributor", "create"
// }
// channels, _ := sdk.ListUserChannels("user_id_1", pm, "token")
// fmt.Println(channels)
ListUserChannels(userID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
// ListUserGroups list all groups belongs a particular user id.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
// }
// groups, _ := sdk.ListUserGroups("user_id_1", pm, "token")
// fmt.Println(channels)
ListUserGroups(userID string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
// ListUserThings list all things belongs a particular user id.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
// }
// things, _ := sdk.ListUserThings("user_id_1", pm, "token")
// fmt.Println(things)
ListUserThings(userID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError)
// SeachUsers filters users and returns a page result.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "John Doe",
// }
// users, _ := sdk.SearchUsers(pm, "token")
// fmt.Println(users)
SearchUsers(pm PageMetadata, token string) (UsersPage, errors.SDKError)
// CreateThing registers new thing and returns its id.
//
// example:
// thing := sdk.Thing{
// Name: "My Thing",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// thing, _ := sdk.CreateThing(thing, "token")
// fmt.Println(thing)
CreateThing(thing Thing, token string) (Thing, errors.SDKError)
// CreateThings registers new things and returns their ids.
//
// example:
// things := []sdk.Thing{
// {
// Name: "My Thing 1",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// },
// {
// Name: "My Thing 2",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// },
// }
// things, _ := sdk.CreateThings(things, "token")
// fmt.Println(things)
CreateThings(things []Thing, token string) ([]Thing, errors.SDKError)
// Filters things and returns a page result.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Thing",
// }
// things, _ := sdk.Things(pm, "token")
// fmt.Println(things)
Things(pm PageMetadata, token string) (ThingsPage, errors.SDKError)
// ThingsByChannel returns page of things that are connected to specified channel.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Thing",
// }
// things, _ := sdk.ThingsByChannel("channelID", pm, "token")
// fmt.Println(things)
ThingsByChannel(chanID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError)
// Thing returns thing object by id.
//
// example:
// thing, _ := sdk.Thing("thingID", "token")
// fmt.Println(thing)
Thing(id, token string) (Thing, errors.SDKError)
// ThingPermissions returns user permissions on the thing id.
//
// example:
// thing, _ := sdk.Thing("thingID", "token")
// fmt.Println(thing)
ThingPermissions(id, token string) (Thing, errors.SDKError)
// UpdateThing updates existing thing.
//
// example:
// thing := sdk.Thing{
// ID: "thingID",
// Name: "My Thing",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// thing, _ := sdk.UpdateThing(thing, "token")
// fmt.Println(thing)
UpdateThing(thing Thing, token string) (Thing, errors.SDKError)
// UpdateThingTags updates the client's tags.
//
// example:
// thing := sdk.Thing{
// ID: "thingID",
// Tags: []string{"tag1", "tag2"},
// }
// thing, _ := sdk.UpdateThingTags(thing, "token")
// fmt.Println(thing)
UpdateThingTags(thing Thing, token string) (Thing, errors.SDKError)
// UpdateThingSecret updates the client's secret
//
// example:
// thing, err := sdk.UpdateThingSecret("thingID", "newSecret", "token")
// fmt.Println(thing)
UpdateThingSecret(id, secret, token string) (Thing, errors.SDKError)
// EnableThing changes client status to enabled.
//
// example:
// thing, _ := sdk.EnableThing("thingID", "token")
// fmt.Println(thing)
EnableThing(id, token string) (Thing, errors.SDKError)
// DisableThing changes client status to disabled - soft delete.
//
// example:
// thing, _ := sdk.DisableThing("thingID", "token")
// fmt.Println(thing)
DisableThing(id, token string) (Thing, errors.SDKError)
// ShareThing shares thing with other users.
//
// example:
// req := sdk.UsersRelationRequest{
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
// }
// err := sdk.ShareThing("thing_id", req, "token")
// fmt.Println(err)
ShareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError
// UnshareThing unshare a thing with other users.
//
// example:
// req := sdk.UsersRelationRequest{
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
// }
// err := sdk.UnshareThing("thing_id", req, "token")
// fmt.Println(err)
UnshareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError
// ListThingUsers all users in a thing.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
// }
// users, _ := sdk.ListThingUsers("thing_id", pm, "token")
// fmt.Println(users)
ListThingUsers(thingID string, pm PageMetadata, token string) (UsersPage, errors.SDKError)
// DeleteThing deletes a thing with the given id.
//
// example:
// err := sdk.DeleteThing("thingID", "token")
// fmt.Println(err)
DeleteThing(id, token string) errors.SDKError
// CreateGroup creates new group and returns its id.
//
// example:
// group := sdk.Group{
// Name: "My Group",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// group, _ := sdk.CreateGroup(group, "token")
// fmt.Println(group)
CreateGroup(group Group, token string) (Group, errors.SDKError)
// Groups returns page of groups.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Group",
// }
// groups, _ := sdk.Groups(pm, "token")
// fmt.Println(groups)
Groups(pm PageMetadata, token string) (GroupsPage, errors.SDKError)
// Parents returns page of users groups.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Group",
// }
// groups, _ := sdk.Parents("groupID", pm, "token")
// fmt.Println(groups)
Parents(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
// Children returns page of users groups.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Group",
// }
// groups, _ := sdk.Children("groupID", pm, "token")
// fmt.Println(groups)
Children(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
// Group returns users group object by id.
//
// example:
// group, _ := sdk.Group("groupID", "token")
// fmt.Println(group)
Group(id, token string) (Group, errors.SDKError)
// GroupPermissions returns user permissions by group ID.
//
// example:
// group, _ := sdk.Group("groupID", "token")
// fmt.Println(group)
GroupPermissions(id, token string) (Group, errors.SDKError)
// UpdateGroup updates existing group.
//
// example:
// group := sdk.Group{
// ID: "groupID",
// Name: "My Group",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// group, _ := sdk.UpdateGroup(group, "token")
// fmt.Println(group)
UpdateGroup(group Group, token string) (Group, errors.SDKError)
// EnableGroup changes group status to enabled.
//
// example:
// group, _ := sdk.EnableGroup("groupID", "token")
// fmt.Println(group)
EnableGroup(id, token string) (Group, errors.SDKError)
// DisableGroup changes group status to disabled - soft delete.
//
// example:
// group, _ := sdk.DisableGroup("groupID", "token")
// fmt.Println(group)
DisableGroup(id, token string) (Group, errors.SDKError)
// AddUserToGroup add user to a group.
//
// example:
// req := sdk.UsersRelationRequest{
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
// }
// err := sdk.AddUserToGroup("groupID",req, "token")
// fmt.Println(err)
AddUserToGroup(groupID string, req UsersRelationRequest, token string) errors.SDKError
// RemoveUserFromGroup remove user from a group.
//
// example:
// req := sdk.UsersRelationRequest{
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
// }
// err := sdk.RemoveUserFromGroup("groupID",req, "token")
// fmt.Println(err)
RemoveUserFromGroup(groupID string, req UsersRelationRequest, token string) errors.SDKError
// ListGroupUsers list all users in the group id .
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
// }
// groups, _ := sdk.ListGroupUsers("groupID", pm, "token")
// fmt.Println(groups)
ListGroupUsers(groupID string, pm PageMetadata, token string) (UsersPage, errors.SDKError)
// ListGroupChannels list all channels in the group id .
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
// }
// groups, _ := sdk.ListGroupChannels("groupID", pm, "token")
// fmt.Println(groups)
ListGroupChannels(groupID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
// DeleteGroup delete given group id.
//
// example:
// err := sdk.DeleteGroup("groupID", "token")
// fmt.Println(err)
DeleteGroup(id, token string) errors.SDKError
// CreateChannel creates new channel and returns its id.
//
// example:
// channel := sdk.Channel{
// Name: "My Channel",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// channel, _ := sdk.CreateChannel(channel, "token")
// fmt.Println(channel)
CreateChannel(channel Channel, token string) (Channel, errors.SDKError)
// Channels returns page of channels.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Channel",
// }
// channels, _ := sdk.Channels(pm, "token")
// fmt.Println(channels)
Channels(pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
// ChannelsByThing returns page of channels that are connected to specified thing.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Name: "My Channel",
// }
// channels, _ := sdk.ChannelsByThing("thingID", pm, "token")
// fmt.Println(channels)
ChannelsByThing(thingID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
// Channel returns channel data by id.
//
// example:
// channel, _ := sdk.Channel("channelID", "token")
// fmt.Println(channel)
Channel(id, token string) (Channel, errors.SDKError)
// ChannelPermissions returns user permissions on the channel ID.
//
// example:
// channel, _ := sdk.Channel("channelID", "token")
// fmt.Println(channel)
ChannelPermissions(id, token string) (Channel, errors.SDKError)
// UpdateChannel updates existing channel.
//
// example:
// channel := sdk.Channel{
// ID: "channelID",
// Name: "My Channel",
// Metadata: sdk.Metadata{
// "key": "value",
// },
// }
// channel, _ := sdk.UpdateChannel(channel, "token")
// fmt.Println(channel)
UpdateChannel(channel Channel, token string) (Channel, errors.SDKError)
// EnableChannel changes channel status to enabled.
//
// example:
// channel, _ := sdk.EnableChannel("channelID", "token")
// fmt.Println(channel)
EnableChannel(id, token string) (Channel, errors.SDKError)
// DisableChannel changes channel status to disabled - soft delete.
//
// example:
// channel, _ := sdk.DisableChannel("channelID", "token")
// fmt.Println(channel)
DisableChannel(id, token string) (Channel, errors.SDKError)
// AddUserToChannel add user to a channel.
//
// example:
// req := sdk.UsersRelationRequest{
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
// }
// err := sdk.AddUserToChannel("channel_id", req, "token")
// fmt.Println(err)
AddUserToChannel(channelID string, req UsersRelationRequest, token string) errors.SDKError
// RemoveUserFromChannel remove user from a group.
//
// example:
// req := sdk.UsersRelationRequest{
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
// }
// err := sdk.RemoveUserFromChannel("channel_id", req, "token")
// fmt.Println(err)
RemoveUserFromChannel(channelID string, req UsersRelationRequest, token string) errors.SDKError
// ListChannelUsers list all users in a channel .
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
// }
// users, _ := sdk.ListChannelUsers("channel_id", pm, "token")
// fmt.Println(users)
ListChannelUsers(channelID string, pm PageMetadata, token string) (UsersPage, errors.SDKError)
// AddUserGroupToChannel add user group to a channel.
//
// example:
// req := sdk.UserGroupsRequest{
// GroupsIDs: ["group_id_1", "group_id_2", "group_id_3"]
// }
// err := sdk.AddUserGroupToChannel("channel_id",req, "token")
// fmt.Println(err)
AddUserGroupToChannel(channelID string, req UserGroupsRequest, token string) errors.SDKError
// RemoveUserGroupFromChannel remove user group from a channel.
//
// example:
// req := sdk.UserGroupsRequest{
// GroupsIDs: ["group_id_1", "group_id_2", "group_id_3"]
// }
// err := sdk.RemoveUserGroupFromChannel("channel_id",req, "token")
// fmt.Println(err)
RemoveUserGroupFromChannel(channelID string, req UserGroupsRequest, token string) errors.SDKError
// ListChannelUserGroups list all user groups in a channel.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// Permission: "view",
// }
// groups, _ := sdk.ListChannelUserGroups("channel_id_1", pm, "token")
// fmt.Println(groups)
ListChannelUserGroups(channelID string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
// DeleteChannel delete given group id.
//
// example:
// err := sdk.DeleteChannel("channelID", "token")
// fmt.Println(err)
DeleteChannel(id, token string) errors.SDKError
// Connect bulk connects things to channels specified by id.
//
// example:
// conns := sdk.Connection{
// ChannelID: "channel_id_1",
// ThingID: "thing_id_1",
// }
// err := sdk.Connect(conns, "token")
// fmt.Println(err)
Connect(conns Connection, token string) errors.SDKError
// Disconnect
//
// example:
// conns := sdk.Connection{
// ChannelID: "channel_id_1",
// ThingID: "thing_id_1",
// }
// err := sdk.Disconnect(conns, "token")
// fmt.Println(err)
Disconnect(connIDs Connection, token string) errors.SDKError
// ConnectThing connects thing to specified channel by id.
//
// The `ConnectThing` method calls the `CreateThingPolicy` method under the hood.
//
// example:
// err := sdk.ConnectThing("thingID", "channelID", "token")
// fmt.Println(err)
ConnectThing(thingID, chanID, token string) errors.SDKError
// DisconnectThing disconnect thing from specified channel by id.
//
// The `DisconnectThing` method calls the `DeleteThingPolicy` method under the hood.
//
// example:
// err := sdk.DisconnectThing("thingID", "channelID", "token")
// fmt.Println(err)
DisconnectThing(thingID, chanID, token string) errors.SDKError
// SendMessage send message to specified channel.
//
// example:
// msg := '[{"bn":"some-base-name:","bt":1.276020076001e+09, "bu":"A","bver":5, "n":"voltage","u":"V","v":120.1}, {"n":"current","t":-5,"v":1.2}, {"n":"current","t":-4,"v":1.3}]'
// err := sdk.SendMessage("channelID", msg, "thingSecret")
// fmt.Println(err)
SendMessage(chanID, msg, key string) errors.SDKError
// ReadMessages read messages of specified channel.
//
// example:
// pm := sdk.MessagePageMetadata{
// Offset: 0,
// Limit: 10,
// }
// msgs, _ := sdk.ReadMessages(pm,"channelID", "token")
// fmt.Println(msgs)
ReadMessages(pm MessagePageMetadata, chanID, token string) (MessagesPage, errors.SDKError)
// SetContentType sets message content type.
//
// example:
// err := sdk.SetContentType("application/json")
// fmt.Println(err)
SetContentType(ct ContentType) errors.SDKError
// Health returns service health check.
//
// example:
// health, _ := sdk.Health("service")
// fmt.Println(health)
Health(service string) (HealthInfo, errors.SDKError)
// AddBootstrap add bootstrap configuration
//
// example:
// cfg := sdk.BootstrapConfig{
// ThingID: "thingID",
// Name: "bootstrap",
// ExternalID: "externalID",
// ExternalKey: "externalKey",
// Channels: []string{"channel1", "channel2"},
// }
// id, _ := sdk.AddBootstrap(cfg, "token")
// fmt.Println(id)
AddBootstrap(cfg BootstrapConfig, token string) (string, errors.SDKError)
// View returns Thing Config with given ID belonging to the user identified by the given token.
//
// example:
// bootstrap, _ := sdk.ViewBootstrap("id", "token")
// fmt.Println(bootstrap)
ViewBootstrap(id, token string) (BootstrapConfig, errors.SDKError)
// Update updates editable fields of the provided Config.
//
// example:
// cfg := sdk.BootstrapConfig{
// ThingID: "thingID",
// Name: "bootstrap",
// ExternalID: "externalID",
// ExternalKey: "externalKey",
// Channels: []string{"channel1", "channel2"},
// }
// err := sdk.UpdateBootstrap(cfg, "token")
// fmt.Println(err)
UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKError
// Update bootstrap config certificates.
//
// example:
// err := sdk.UpdateBootstrapCerts("id", "clientCert", "clientKey", "ca", "token")
// fmt.Println(err)
UpdateBootstrapCerts(id string, clientCert, clientKey, ca string, token string) (BootstrapConfig, errors.SDKError)
// UpdateBootstrapConnection updates connections performs update of the channel list corresponding Thing is connected to.
//
// example:
// err := sdk.UpdateBootstrapConnection("id", []string{"channel1", "channel2"}, "token")
// fmt.Println(err)
UpdateBootstrapConnection(id string, channels []string, token string) errors.SDKError
// Remove removes Config with specified token that belongs to the user identified by the given token.
//
// example:
// err := sdk.RemoveBootstrap("id", "token")
// fmt.Println(err)
RemoveBootstrap(id, token string) errors.SDKError
// Bootstrap returns Config to the Thing with provided external ID using external key.
//
// example:
// bootstrap, _ := sdk.Bootstrap("externalID", "externalKey")
// fmt.Println(bootstrap)
Bootstrap(externalID, externalKey string) (BootstrapConfig, errors.SDKError)
// BootstrapSecure retrieves a configuration with given external ID and encrypted external key.
//
// example:
// bootstrap, _ := sdk.BootstrapSecure("externalID", "externalKey", "cryptoKey")
// fmt.Println(bootstrap)
BootstrapSecure(externalID, externalKey, cryptoKey string) (BootstrapConfig, errors.SDKError)
// Bootstraps retrieves a list of managed configs.
//
// example:
// pm := sdk.PageMetadata{
// Offset: 0,
// Limit: 10,
// }
// bootstraps, _ := sdk.Bootstraps(pm, "token")
// fmt.Println(bootstraps)
Bootstraps(pm PageMetadata, token string) (BootstrapPage, errors.SDKError)
// Whitelist updates Thing state Config with given ID belonging to the user identified by the given token.
//
// example:
// err := sdk.Whitelist("thingID", 1, "token")
// fmt.Println(err)
Whitelist(thingID string, state int, token string) errors.SDKError
// IssueCert issues a certificate for a thing required for mTLS.
//
// example:
// cert, _ := sdk.IssueCert("thingID", "24h", "token")
// fmt.Println(cert)
IssueCert(thingID, validity, token string) (Cert, errors.SDKError)
// ViewCert returns a certificate given certificate ID
//
// example:
// cert, _ := sdk.ViewCert("certID", "token")
// fmt.Println(cert)
ViewCert(certID, token string) (Cert, errors.SDKError)
// ViewCertByThing retrieves a list of certificates' serial IDs for a given thing ID.
//
// example:
// cserial, _ := sdk.ViewCertByThing("thingID", "token")
// fmt.Println(cserial)
ViewCertByThing(thingID, token string) (CertSerials, errors.SDKError)
// RevokeCert revokes certificate for thing with thingID
//
// example:
// tm, _ := sdk.RevokeCert("thingID", "token")
// fmt.Println(tm)
RevokeCert(thingID, token string) (time.Time, errors.SDKError)
// CreateSubscription creates a new subscription
//
// example:
// subscription, _ := sdk.CreateSubscription("topic", "contact", "token")
// fmt.Println(subscription)
CreateSubscription(topic, contact, token string) (string, errors.SDKError)