Skip to content

Commit a987512

Browse files
authored
Add client access management commands (#95)
1 parent 0684b77 commit a987512

File tree

10 files changed

+215
-1
lines changed

10 files changed

+215
-1
lines changed

src/main/graphql/.graphqlconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"extensions": {
55
"endpoints": {
66
"Default GraphQL Endpoint": {
7-
"url": "https://localhost:12800/graphql",
7+
"url": "http://localhost:12800/graphql",
88
"headers": {
99
"user-agent": "JS GraphQL"
1010
},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mutation addClientAccess {
2+
addClientAccess {
3+
id
4+
secret
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
query getClientAccessors {
2+
getClientAccessors {
3+
id
4+
secret
5+
}
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation removeClientAccess($id: String!) {
2+
removeClientAccess(id: $id)
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mutation updateClientAccess($id: String!) {
2+
updateClientAccess(id: $id) {
3+
id
4+
secret
5+
}
6+
}

src/main/kotlin/spp/cli/Main.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import spp.cli.commands.Developer
2222
import spp.cli.commands.Version
2323
import spp.cli.commands.admin.Reset
2424
import spp.cli.commands.admin.access.*
25+
import spp.cli.commands.admin.client.AddClientAccess
26+
import spp.cli.commands.admin.client.GetClientAccessors
27+
import spp.cli.commands.admin.client.RemoveClientAccess
28+
import spp.cli.commands.admin.client.UpdateClientAccess
2529
import spp.cli.commands.admin.developer.AddDeveloper
2630
import spp.cli.commands.admin.developer.GetDevelopers
2731
import spp.cli.commands.admin.developer.RefreshDeveloperToken
@@ -66,6 +70,11 @@ object Main {
6670
GetDevelopers(),
6771
RemoveDeveloper(),
6872
RefreshDeveloperToken(),
73+
//client access
74+
AddClientAccess(),
75+
GetClientAccessors(),
76+
RemoveClientAccess(),
77+
UpdateClientAccess(),
6978
//instrument access
7079
AddAccessPermission(),
7180
AddRoleAccessPermission(),
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.cli.commands.admin.client
18+
19+
import com.github.ajalt.clikt.core.CliktCommand
20+
import kotlinx.coroutines.runBlocking
21+
import spp.cli.Main
22+
import spp.cli.PlatformCLI.apolloClient
23+
import spp.cli.PlatformCLI.echoError
24+
import spp.cli.protocol.client.AddClientAccessMutation
25+
import kotlin.system.exitProcess
26+
27+
class AddClientAccess : CliktCommand() {
28+
29+
override fun run() = runBlocking {
30+
val response = try {
31+
apolloClient.mutation(AddClientAccessMutation()).execute()
32+
} catch (e: Exception) {
33+
echoError(e)
34+
if (Main.standalone) exitProcess(-1) else return@runBlocking
35+
}
36+
if (response.hasErrors()) {
37+
echo(response.errors?.get(0)?.message, err = true)
38+
if (Main.standalone) exitProcess(-1) else return@runBlocking
39+
}
40+
41+
echo(response.data!!.addClientAccess.id!!)
42+
echo(response.data!!.addClientAccess.secret!!)
43+
if (Main.standalone) exitProcess(0)
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.cli.commands.admin.client
18+
19+
import com.github.ajalt.clikt.core.CliktCommand
20+
import kotlinx.coroutines.runBlocking
21+
import spp.cli.Main
22+
import spp.cli.PlatformCLI.apolloClient
23+
import spp.cli.PlatformCLI.echoError
24+
import spp.cli.protocol.client.GetClientAccessorsQuery
25+
import spp.cli.protocol.developer.GetDevelopersQuery
26+
import kotlin.system.exitProcess
27+
28+
class GetClientAccessors : CliktCommand() {
29+
30+
override fun run() = runBlocking {
31+
val response = try {
32+
apolloClient.query(GetClientAccessorsQuery()).execute()
33+
} catch (e: Exception) {
34+
echoError(e)
35+
if (Main.standalone) exitProcess(-1) else return@runBlocking
36+
}
37+
if (response.hasErrors()) {
38+
echo(response.errors?.get(0)?.message, err = true)
39+
if (Main.standalone) exitProcess(-1) else return@runBlocking
40+
}
41+
42+
echo(response.data!!.getClientAccessors.map { it.id })
43+
if (Main.standalone) exitProcess(0)
44+
}
45+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.cli.commands.admin.client
18+
19+
import com.github.ajalt.clikt.core.CliktCommand
20+
import com.github.ajalt.clikt.parameters.arguments.argument
21+
import kotlinx.coroutines.runBlocking
22+
import spp.cli.Main
23+
import spp.cli.PlatformCLI.apolloClient
24+
import spp.cli.PlatformCLI.echoError
25+
import spp.cli.protocol.client.RemoveClientAccessMutation
26+
import kotlin.system.exitProcess
27+
28+
class RemoveClientAccess : CliktCommand(printHelpOnEmptyArgs = true) {
29+
30+
val id by argument(help = "Client Access ID")
31+
32+
override fun run() = runBlocking {
33+
val response = try {
34+
apolloClient.mutation(RemoveClientAccessMutation(id)).execute()
35+
} catch (e: Exception) {
36+
echoError(e)
37+
if (Main.standalone) exitProcess(-1) else return@runBlocking
38+
}
39+
if (response.hasErrors()) {
40+
echo(response.errors?.get(0)?.message, err = true)
41+
if (Main.standalone) exitProcess(-1) else return@runBlocking
42+
}
43+
44+
echo(response.data!!.removeClientAccess)
45+
if (Main.standalone) exitProcess(0)
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package spp.cli.commands.admin.client
18+
19+
import com.github.ajalt.clikt.core.CliktCommand
20+
import com.github.ajalt.clikt.parameters.arguments.argument
21+
import kotlinx.coroutines.runBlocking
22+
import spp.cli.Main
23+
import spp.cli.PlatformCLI.apolloClient
24+
import spp.cli.PlatformCLI.echoError
25+
import spp.cli.protocol.client.UpdateClientAccessMutation
26+
import kotlin.system.exitProcess
27+
28+
class UpdateClientAccess : CliktCommand(printHelpOnEmptyArgs = true) {
29+
30+
val id by argument(help = "Client Access ID")
31+
32+
override fun run() = runBlocking {
33+
val response = try {
34+
apolloClient.mutation(UpdateClientAccessMutation(id)).execute()
35+
} catch (e: Exception) {
36+
echoError(e)
37+
if (Main.standalone) exitProcess(-1) else return@runBlocking
38+
}
39+
if (response.hasErrors()) {
40+
echo(response.errors?.get(0)?.message, err = true)
41+
if (Main.standalone) exitProcess(-1) else return@runBlocking
42+
}
43+
44+
echo(response.data!!.updateClientAccess.secret!!)
45+
if (Main.standalone) exitProcess(0)
46+
}
47+
}

0 commit comments

Comments
 (0)