Skip to content

Commit 615e993

Browse files
committed
re-impl subscribe
1 parent bf1050f commit 615e993

5 files changed

Lines changed: 51 additions & 39 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ import spp.cli.commands.admin.permission.GetDeveloperPermissions
3232
import spp.cli.commands.admin.permission.GetRolePermissions
3333
import spp.cli.commands.admin.permission.RemoveRolePermission
3434
import spp.cli.commands.admin.role.*
35-
import spp.cli.commands.developer.Add
36-
import spp.cli.commands.developer.Get
37-
import spp.cli.commands.developer.GetSelf
38-
import spp.cli.commands.developer.Remove
35+
import spp.cli.commands.developer.*
3936
import spp.cli.commands.developer.instrument.*
4037
import spp.cli.commands.developer.view.AddView
4138
import spp.cli.commands.developer.view.GetViews
4239
import spp.cli.commands.developer.view.RemoveAllViews
40+
import spp.cli.commands.developer.view.SubscribeView
4341

4442
object Main {
4543

@@ -108,10 +106,14 @@ object Main {
108106
RemoveInstruments(),
109107
RemoveAllInstruments(),
110108
//view
111-
RemoveAllViews(),
109+
RemoveAllViews()
110+
),
111+
Subscribe().subcommands(
112+
//instrument
113+
SubscribeInstrument(),
114+
//view
115+
SubscribeView()
112116
),
113-
// SubscribeEvents(),
114-
// SubscribeView(),
115117
//etc
116118
Version()
117119
).main(args)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = t
8989
DatabindCodec.mapper().registerModule(module)
9090
}
9191

92-
private fun connectToPlatform(): ApolloClient {
92+
fun connectToPlatform(): ApolloClient {
9393
val serverUrl = if (platformHost.startsWith("http")) {
9494
platformHost
9595
} else {
@@ -142,7 +142,7 @@ object PlatformCLI : CliktCommand(name = "spp-cli", allowMultipleSubcommands = t
142142

143143
if (resp.code != 202) {
144144
val decoded = JWT.decode(jwtToken)
145-
developer = Developer(decoded.getClaim("developer_id").asString())
145+
developer = Developer(decoded.getClaim("developer_id").asString(), jwtToken)
146146
}
147147
} else if (resp.code == 401 && accessToken.isNullOrEmpty()) {
148148
throw IllegalStateException("Connection failed. Reason: Missing access token")
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.developer
19+
20+
import com.github.ajalt.clikt.core.CliktCommand
21+
22+
class Subscribe : CliktCommand(help = "Subscribe to live instrument/view streams") {
23+
override fun run() = Unit
24+
}

src/main/kotlin/spp/cli/commands/developer/instrument/SubscribeEvents.kt renamed to src/main/kotlin/spp/cli/commands/developer/instrument/SubscribeInstrument.kt

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ import io.vertx.ext.eventbus.bridge.tcp.impl.protocol.FrameParser
3535
import io.vertx.kotlin.coroutines.await
3636
import kotlinx.coroutines.runBlocking
3737
import spp.cli.PlatformCLI
38-
import spp.protocol.marshall.ProtocolMarshaller.deserializeLiveInstrumentRemoved
3938
import spp.protocol.SourceServices.Provide.toLiveInstrumentSubscriberAddress
4039
import spp.protocol.extend.TCPServiceFrameParser
4140
import spp.protocol.instrument.event.LiveInstrumentEvent
4241
import spp.protocol.instrument.event.LiveInstrumentEventType
4342
import spp.protocol.instrument.event.LiveLogHit
4443
import spp.protocol.marshall.ProtocolMarshaller
44+
import spp.protocol.marshall.ProtocolMarshaller.deserializeLiveInstrumentRemoved
4545

46-
class SubscribeEvents : CliktCommand(
47-
help = "Listens for and outputs live events. Subscribes to all events by default"
46+
class SubscribeInstrument : CliktCommand(
47+
name = "instrument",
48+
help = "Listen to live instruments. Subscribes to all events by default"
4849
) {
4950

5051
val instrumentIds by argument(
@@ -62,7 +63,8 @@ class SubscribeEvents : CliktCommand(
6263
.flag(default = false)
6364

6465
override fun run() {
65-
var eventCount = 1
66+
PlatformCLI.connectToPlatform()
67+
6668
runBlocking {
6769
val vertx = Vertx.vertx()
6870
val client = if (PlatformCLI.certFingerprint != null) {
@@ -77,6 +79,7 @@ class SubscribeEvents : CliktCommand(
7779
vertx.createNetClient(options)
7880
} else {
7981
val options = NetClientOptions()
82+
.setTrustAll(true)
8083
.setReconnectAttempts(Int.MAX_VALUE).setReconnectInterval(5000)
8184
.setSsl(PlatformCLI.platformHost.startsWith("https"))
8285
vertx.createNetClient(options)
@@ -118,38 +121,18 @@ class SubscribeEvents : CliktCommand(
118121

119122
if (!includeBreakpoints && !includeLogs && !includeMeters && !includeTraces) {
120123
//listen for all events
121-
println(
122-
"\nEvent (${eventCount++}):\n" +
123-
"\tType: ${liveEvent.eventType}\n" +
124-
"\tData: ${liveEvent.data}"
125-
)
124+
println("\nType: ${liveEvent.eventType}\nData: ${liveEvent.data}")
126125
} else {
127126
//todo: impl filtering on platform
128127
//listen for specific events
129128
if (includeBreakpoints && liveEvent.eventType.name.startsWith("breakpoint", true)) {
130-
println(
131-
"\nEvent (${eventCount++}):\n" +
132-
"\tType: ${liveEvent.eventType}\n" +
133-
"\tData: ${liveEvent.data}"
134-
)
129+
println("\nType: ${liveEvent.eventType}\nData: ${liveEvent.data}")
135130
} else if (includeLogs && liveEvent.eventType.name.startsWith("log", true)) {
136-
println(
137-
"\nEvent (${eventCount++}):\n" +
138-
"\tType: ${liveEvent.eventType}\n" +
139-
"\tData: ${liveEvent.data}"
140-
)
131+
println("\nType: ${liveEvent.eventType}\nData: ${liveEvent.data}")
141132
} else if (includeMeters && liveEvent.eventType.name.startsWith("meter", true)) {
142-
println(
143-
"\nEvent (${eventCount++}):\n" +
144-
"\tType: ${liveEvent.eventType}\n" +
145-
"\tData: ${liveEvent.data}"
146-
)
133+
println("\nType: ${liveEvent.eventType}\nData: ${liveEvent.data}")
147134
} else if (includeTraces && liveEvent.eventType.name.startsWith("trace", true)) {
148-
println(
149-
"\nEvent (${eventCount++}):\n" +
150-
"\tType: ${liveEvent.eventType}\n" +
151-
"\tData: ${liveEvent.data}"
152-
)
135+
println("\nType: ${liveEvent.eventType}\nData: ${liveEvent.data}")
153136
}
154137
}
155138
}

src/main/kotlin/spp/cli/commands/developer/view/SubscribeView.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ import java.time.ZoneOffset
4545
import java.time.format.DateTimeFormatterBuilder
4646

4747
class SubscribeView : CliktCommand(
48-
help = "Listens for and outputs live views. Subscribes to all views by default"
48+
name = "view",
49+
help = "Listen to live views. Subscribes to all views by default"
4950
) {
5051

5152
companion object {
@@ -65,6 +66,8 @@ class SubscribeView : CliktCommand(
6566
).flag()
6667

6768
override fun run() {
69+
PlatformCLI.connectToPlatform()
70+
6871
runBlocking {
6972
val vertx = Vertx.vertx()
7073
val client = if (PlatformCLI.certFingerprint != null) {

0 commit comments

Comments
 (0)