Skip to content

Commit 4982abe

Browse files
authored
Merge pull request #38 from sourceplusplus/issue-21
Issue 21
2 parents f562527 + bc90750 commit 4982abe

36 files changed

+273
-160
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,17 @@ jobs:
158158
- name: "[CLI] Remove developer"
159159
run: ./build/graal/spp-cli -v admin remove-developer test
160160
- name: "[CLI] Add live breakpoint"
161-
run: ./build/graal/spp-cli -v add-breakpoint -h 100 spp.example.webapp.model.User 48
161+
run: ./build/graal/spp-cli -v add breakpoint -h 100 spp.example.webapp.model.User 48
162162
- name: "[CLI] Add live log"
163-
run: ./build/graal/spp-cli -v add-log -h 100 spp.example.webapp.model.User 48 test-message
163+
run: ./build/graal/spp-cli -v add log -h 100 spp.example.webapp.model.User 48 test-message
164164
- name: "[CLI] Get live instruments"
165-
run: ./build/graal/spp-cli -v get-instruments
165+
run: ./build/graal/spp-cli -v get instruments
166166
- name: "[CLI] Get live breakpoints"
167-
run: ./build/graal/spp-cli -v get-breakpoints
167+
run: ./build/graal/spp-cli -v get breakpoints
168168
- name: "[CLI] Get live logs"
169-
run: ./build/graal/spp-cli -v get-logs
169+
run: ./build/graal/spp-cli -v get logs
170170
- name: "[CLI] Remove live instruments"
171-
run: ./build/graal/spp-cli -v remove-instruments spp.example.webapp.model.User 48
171+
run: ./build/graal/spp-cli -v remove instruments spp.example.webapp.model.User 48
172172
- name: "[CLI] Reset"
173173
run: ./build/graal/spp-cli -v admin reset
174174

build.gradle.kts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ plugins {
1111

1212
val cliGroup: String by project
1313
val projectVersion: String by project
14-
val jacksonVersion: String by project
1514
val apolloVersion: String by project
1615
val commonsLang3Version: String by project
1716
val cliktVersion: String by project
@@ -34,7 +33,7 @@ dependencies {
3433
implementation("com.apollographql.apollo3:apollo-runtime:$apolloVersion")
3534
api("com.apollographql.apollo3:apollo-api:$apolloVersion")
3635

37-
implementation("com.github.sourceplusplus.protocol:protocol:$projectVersion")
36+
implementation("com.github.sourceplusplus.protocol:protocol:2bd4bea9ad")
3837

3938
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
4039
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
@@ -47,13 +46,10 @@ dependencies {
4746
implementation("com.github.ajalt.clikt:clikt:$cliktVersion")
4847
implementation("org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion")
4948
implementation("org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion")
50-
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
51-
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$jacksonVersion")
5249
implementation("commons-io:commons-io:$commonsIoVersion")
5350
implementation("com.auth0:java-jwt:$auth0JwtVersion")
5451
implementation("eu.geekplace.javapinning:java-pinning-core:1.2.0")
5552

56-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")
5753
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
5854

5955
testImplementation("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ projectVersion=0.4.1
55

66
vertxVersion=4.2.4
77
graalVersion = 21.3.0
8-
jacksonVersion=2.13.1
98
apolloVersion=3.1.0
109
commonsLang3Version = 3.12.0
1110
cliktVersion = 3.2.0

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

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
package spp.cli
1919

2020
import com.github.ajalt.clikt.core.subcommands
21+
import spp.cli.commands.Admin
22+
import spp.cli.commands.Developer
2123
import spp.cli.commands.Version
22-
import spp.cli.commands.admin.Admin
2324
import spp.cli.commands.admin.Reset
2425
import spp.cli.commands.admin.access.*
2526
import spp.cli.commands.admin.developer.AddDeveloper
@@ -31,12 +32,12 @@ import spp.cli.commands.admin.permission.GetDeveloperPermissions
3132
import spp.cli.commands.admin.permission.GetRolePermissions
3233
import spp.cli.commands.admin.permission.RemoveRolePermission
3334
import spp.cli.commands.admin.role.*
34-
import spp.cli.commands.developer.GetSelf
35-
import spp.cli.commands.instrument.*
36-
import spp.cli.commands.view.AddViewSubscription
37-
import spp.cli.commands.view.ClearViewSubscriptions
38-
import spp.cli.commands.view.GetViewSubscriptions
39-
import spp.cli.commands.view.SubscribeView
35+
import spp.cli.commands.developer.*
36+
import spp.cli.commands.developer.instrument.*
37+
import spp.cli.commands.developer.view.AddView
38+
import spp.cli.commands.developer.view.GetViews
39+
import spp.cli.commands.developer.view.RemoveAllViews
40+
import spp.cli.commands.developer.view.SubscribeView
4041

4142
object Main {
4243

@@ -77,27 +78,43 @@ object Main {
7778
//etc
7879
Reset()
7980
),
80-
//instrument
81-
AddBreakpoint(),
82-
AddLog(),
83-
AddMeter(),
84-
AddSpan(),
85-
GetBreakpoints(),
86-
GetInstruments(),
87-
GetLogs(),
88-
GetMeters(),
89-
GetSpans(),
90-
RemoveInstrument(),
91-
RemoveInstruments(),
92-
ClearInstruments(),
93-
SubscribeEvents(),
94-
//view
95-
AddViewSubscription(),
96-
ClearViewSubscriptions(),
97-
GetViewSubscriptions(),
98-
SubscribeView(),
81+
Developer().subcommands(
82+
GetSelf()
83+
),
84+
Add().subcommands(
85+
//instrument
86+
AddBreakpoint(),
87+
AddLog(),
88+
AddMeter(),
89+
AddSpan(),
90+
//view
91+
AddView()
92+
),
93+
Get().subcommands(
94+
//instrument
95+
GetInstruments(),
96+
GetBreakpoints(),
97+
GetLogs(),
98+
GetMeters(),
99+
GetSpans(),
100+
//view
101+
GetViews()
102+
),
103+
Remove().subcommands(
104+
//instrument
105+
RemoveInstrument(),
106+
RemoveInstruments(),
107+
RemoveAllInstruments(),
108+
//view
109+
RemoveAllViews()
110+
),
111+
Subscribe().subcommands(
112+
//instrument
113+
SubscribeInstrument(),
114+
//view
115+
SubscribeView()
116+
),
99117
//etc
100-
GetSelf(),
101118
Version()
102119
).main(args)
103120
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ import com.apollographql.apollo3.exception.ApolloException
2222
import com.apollographql.apollo3.network.okHttpClient
2323
import com.auth0.jwt.JWT
2424
import com.auth0.jwt.algorithms.Algorithm
25-
import com.fasterxml.jackson.databind.module.SimpleModule
2625
import com.github.ajalt.clikt.core.CliktCommand
2726
import com.github.ajalt.clikt.parameters.options.default
2827
import com.github.ajalt.clikt.parameters.options.flag
2928
import com.github.ajalt.clikt.parameters.options.option
3029
import com.github.ajalt.clikt.parameters.types.file
3130
import eu.geekplace.javapinning.JavaPinning
32-
import io.vertx.core.json.jackson.DatabindCodec
3331
import kotlinx.datetime.Clock
3432
import kotlinx.datetime.DateTimeUnit
35-
import kotlinx.datetime.Instant
3633
import kotlinx.datetime.plus
3734
import okhttp3.OkHttpClient
3835
import okhttp3.Request
@@ -44,7 +41,6 @@ import org.bouncycastle.openssl.PEMParser
4441
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
4542
import org.bouncycastle.util.encoders.Hex
4643
import spp.protocol.platform.developer.Developer
47-
import spp.protocol.util.KSerializers
4844
import java.io.File
4945
import java.io.StringReader
5046
import java.security.SecureRandom
@@ -82,14 +78,9 @@ object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = t
8278
}
8379
var developer: Developer = Developer("system")
8480

85-
override fun run() {
86-
val module = SimpleModule()
87-
module.addSerializer(Instant::class.java, KSerializers.KotlinInstantSerializer())
88-
module.addDeserializer(Instant::class.java, KSerializers.KotlinInstantDeserializer())
89-
DatabindCodec.mapper().registerModule(module)
90-
}
81+
override fun run() = Unit
9182

92-
private fun connectToPlatform(): ApolloClient {
83+
fun connectToPlatform(): ApolloClient {
9384
val serverUrl = if (platformHost.startsWith("http")) {
9485
platformHost
9586
} else {
@@ -142,7 +133,7 @@ object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = t
142133

143134
if (resp.code != 202) {
144135
val decoded = JWT.decode(jwtToken)
145-
developer = Developer(decoded.getClaim("developer_id").asString())
136+
developer = Developer(decoded.getClaim("developer_id").asString(), jwtToken)
146137
}
147138
} else if (resp.code == 401 && accessToken.isNullOrEmpty()) {
148139
throw IllegalStateException("Connection failed. Reason: Missing access token")

src/main/kotlin/spp/cli/commands/admin/Admin.kt renamed to src/main/kotlin/spp/cli/commands/Admin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
* You should have received a copy of the GNU Affero General Public License
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
18-
package spp.cli.commands.admin
18+
package spp.cli.commands
1919

2020
import com.github.ajalt.clikt.core.CliktCommand
2121

22-
class Admin : CliktCommand() {
22+
class Admin : CliktCommand(help = "Administrator commands") {
2323
override fun run() = Unit
2424
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Source++, the open-source live coding platform.
3+
* Copyright (C) 2022 CodeBrig, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as published
7+
* by the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
package spp.cli.commands
19+
20+
import com.github.ajalt.clikt.core.CliktCommand
21+
22+
class Developer : CliktCommand(help = "Developer commands") {
23+
override fun run() = Unit
24+
}

src/main/kotlin/spp/cli/commands/Version.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package spp.cli.commands
2020
import com.github.ajalt.clikt.core.CliktCommand
2121
import java.util.*
2222

23-
class Version : CliktCommand() {
23+
class Version : CliktCommand(help = "Display version information") {
2424
private val BUILD = ResourceBundle.getBundle("build")
2525

2626
override fun run() {

src/main/kotlin/spp/cli/commands/admin/access/AddAccessPermission.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import spp.cli.PlatformCLI
3131
import spp.cli.PlatformCLI.echoError
3232
import spp.cli.protocol.access.AddAccessPermissionMutation
3333
import spp.cli.protocol.access.adapter.AddAccessPermissionMutation_ResponseAdapter.AddAccessPermission
34-
import spp.cli.protocol.type.AccessType
3534
import spp.cli.util.JsonCleaner
35+
import spp.protocol.platform.auth.AccessType
3636
import kotlin.system.exitProcess
3737

3838
class AddAccessPermission : CliktCommand(printHelpOnEmptyArgs = true) {
@@ -43,7 +43,10 @@ class AddAccessPermission : CliktCommand(printHelpOnEmptyArgs = true) {
4343
override fun run() = runBlocking {
4444
val response = try {
4545
PlatformCLI.apolloClient.mutation(
46-
AddAccessPermissionMutation(Optional.Present(locationPatterns), type)
46+
AddAccessPermissionMutation(
47+
Optional.Present(locationPatterns),
48+
spp.cli.protocol.type.AccessType.valueOf(type.toString())
49+
)
4750
).execute()
4851
} catch (e: Exception) {
4952
echoError(e)

src/main/kotlin/spp/cli/commands/admin/permission/AddRolePermission.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import spp.cli.Main
2525
import spp.cli.PlatformCLI.apolloClient
2626
import spp.cli.PlatformCLI.echoError
2727
import spp.cli.protocol.permission.AddRolePermissionMutation
28-
import spp.cli.protocol.type.RolePermission
28+
import spp.protocol.platform.auth.RolePermission
2929
import kotlin.system.exitProcess
3030

3131
class AddRolePermission : CliktCommand(printHelpOnEmptyArgs = true) {

0 commit comments

Comments
 (0)