|
| 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