Skip to content

Commit

Permalink
JSSDK-95 - Update channels service to match new access control (#100)
Browse files Browse the repository at this point in the history
* update channels to match new auth

Signed-off-by: wambuipixel <[email protected]>

* fix rebase errors

Signed-off-by: wambuipixel <[email protected]>

* remove unused endpoints

Signed-off-by: wambuipixel <[email protected]>

* add changeset

Signed-off-by: wambuipixel <[email protected]>

* fix tests

Signed-off-by: wambuipixel <[email protected]>

* revert changes in groups file

Signed-off-by: wambuipixel <[email protected]>

* fix docStrings

Signed-off-by: wambuipixel <[email protected]>

* fix docstrings

Signed-off-by: wambuipixel <[email protected]>

* address requested changes

Signed-off-by: wambuipixel <[email protected]>

---------

Signed-off-by: wambuipixel <[email protected]>
  • Loading branch information
wambui-pixel authored Nov 21, 2024
1 parent 29c6472 commit 9fa7f26
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 782 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-lizards-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

update channels to match new access control
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ user_token = ""
things_url = "http://localhost:9000"
tls_verification = false
users_url = "http://localhost:9002"
channels_url = "http://localhost:9005"
168 changes: 46 additions & 122 deletions examples/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import SDK from "../src/sdk";
const defaultUrl = "http://localhost";

const mySdk = new SDK({
thingsUrl: `${defaultUrl}:9000`,
usersUrl: `${defaultUrl}:9002`,
channelsUrl: `${defaultUrl}:9005`,
});

// Channels.ts examples.
Expand All @@ -19,229 +18,154 @@ mySdk.channels
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Channel("<channelID>", domainId, token)
.Channel("<channelId>", domainId, token)
.then((response: any) => {
console.log(response);
})
.catch((error: any) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Channels({ offset: 0, limit: 10 }, domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
});

mySdk.channels
.UpdateChannel(
{ id: "<channelId>", name: "<channelName>" },
domainId,
token,
)
.CreateChannels([{ name: "<channelName1>" }, { name: "<channelName2>" }], domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Disable("<channelId>", domainId, token)
.Channels({ offset: 0, limit: 10 }, domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Enable("<channelId>", domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
});

mySdk.channels
.ChannelsByThing(
"<thingId>",
{ offset: 0, limit: 5 },
.UpdateChannelNameAndMetadata(
{ id: "<channelId>", name: "<channelName>", metadata: { key: "value" } },
domainId,
token,
token
)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.ConnectThing(
"<thingId>",
"<channelId>",
.UpdateChannelTags(
{ id: "<channelId>", tags: ["tag1", "tag2"] },
domainId,
token,
token
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
});

mySdk.channels
.DisconnectThing(
"<thingId>",
"<channelId>",
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Connect(
"<thingId>",
"<channelId>",
domainId,
token,
)
.DisableChannel("<channelId>", domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Disconnect(
"<thingId>",
"<channelId>",
domainId,
token,
)
.EnableChannel("<channelId>", domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.ListChannelUsers(
.ConnectClient(
["<clientId1>", "<clientId2>"],
"<channelId>",
{ offset: 0, limit: 5 },
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error: any) => {
console.log(error);
.catch((error) => {
console.error(error);
});

mySdk.channels
.ListChannelUserGroups(
.DisconnectClient(
["<clientId1>", "<clientId2>"],
"<channelId>",
{ offset: 0, limit: 5 },
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error: any) => {
console.log(error);
});

mySdk.channels
.ChannelPermissions("<channelId>", domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.AddUserToChannel(
"<channelId>",
[
"<userId1>", "<userId2>",
],
"administrator",
.Connect(
["<clientId1>", "<clientId2>"],
["<channelId1>", "<channelId1>"],
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.RemoveUserFromChannel(
"<channelId>",
[
"<userId1>", "<userId2>",
],
"administrator",
.Disconnect(
["<clientId1>", "<clientId2>"],
["<channelId1>", "<channelId1>"],
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.AddUserGroupToChannel(
"<channelId>",
[
"<UserGroupId1>", "<UserGroupId2>",
],
domainId,
token,
)
mySdk.channels.ChannelParents(domainId, "<channelId>", "<groupParentId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.RemoveUserGroupFromChannel(
"<channelId>",
[
"<UserGroupId1>", "<UserGroupId2>",
],
domainId,
token,
)
mySdk.channels.DeleteChannelParents(domainId, "<channelId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
Expand All @@ -254,5 +178,5 @@ mySdk.channels
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});
26 changes: 18 additions & 8 deletions examples/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const defaultUrl = "http://localhost";
const mySdk = new SDK({
usersUrl: `${defaultUrl}:9002`,
thingsUrl: `${defaultUrl}:9000`,
channelsUrl: `${defaultUrl}:9005`,
invitationsUrl: `${defaultUrl}:9020`,
journalUrl: `${defaultUrl}:9021`,
httpAdapterUrl: `${defaultUrl}:8008`,
Expand All @@ -20,7 +21,7 @@ mySdk.Health.Health("things")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Users service Health
Expand All @@ -29,7 +30,16 @@ mySdk.Health.Health("users")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Channels service Health
mySdk.Health.Health("channels")
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

// Bootstrap service Health
Expand All @@ -38,7 +48,7 @@ mySdk.Health.Health("bootstrap")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Certs service Health
Expand All @@ -47,7 +57,7 @@ mySdk.Health.Health("certs")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Reader service Health
Expand All @@ -56,7 +66,7 @@ mySdk.Health.Health("reader")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Http Adapter service Health
Expand All @@ -65,7 +75,7 @@ mySdk.Health.Health("http-adapter")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Journal service Health
Expand All @@ -74,7 +84,7 @@ mySdk.Health.Health("journal")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Invitations service Health
Expand All @@ -83,5 +93,5 @@ mySdk.Health.Health("invitations")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});
Loading

0 comments on commit 9fa7f26

Please sign in to comment.