Skip to content

Commit 521006f

Browse files
Add "gh secret {list,create}" commands
1 parent a15955c commit 521006f

File tree

23 files changed

+881
-25
lines changed

23 files changed

+881
-25
lines changed

build.sc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ class Core(val crossScalaVersion: String) extends BuildLikeModule {
392392
| def defaultGraalVMVersion = "${deps.graalVmVersion}"
393393
|
394394
| def scalaCliSigningVersion = "${Deps.signingCli.dep.version}"
395+
|
396+
| def libsodiumVersion = "${deps.libsodiumVersion}"
397+
| def libsodiumjniVersion = "${Deps.libsodiumjni.dep.version}"
395398
|}
396399
|""".stripMargin
397400
if (!os.isFile(dest) || os.read(dest) != code)
@@ -620,10 +623,12 @@ trait Cli extends SbtModule with ProtoBuildModule with CliLaunchers
620623
Deps.jimfs, // scalaJsEnvNodeJs pulls jimfs:1.1, whose class path seems borked (bin compat issue with the guava version it depends on)
621624
Deps.jniUtils,
622625
Deps.jsoniterCore,
626+
Deps.libsodiumjni,
623627
Deps.metaconfigTypesafe,
624628
Deps.scalaPackager,
625629
Deps.signingCli,
626-
Deps.slf4jNop // to silence jgit
630+
Deps.slf4jNop, // to silence jgit
631+
Deps.sttp
627632
)
628633
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
629634
Deps.jsoniterMacros,
@@ -700,9 +705,11 @@ trait CliIntegrationBase extends SbtModule with ScalaCliPublishModule with HasTe
700705
trait Tests extends super.Tests with ScalaCliScalafixModule {
701706
def ivyDeps = super.ivyDeps() ++ Agg(
702707
Deps.bsp4j,
708+
Deps.coursier,
703709
Deps.dockerClient,
704710
Deps.jsoniterCore,
705711
Deps.jsoniterMacros,
712+
Deps.libsodiumjni,
706713
Deps.pprint,
707714
Deps.scalaAsync,
708715
Deps.slf4jNop
@@ -764,6 +771,7 @@ trait CliIntegrationBase extends SbtModule with ScalaCliPublishModule with HasTe
764771
| def mostlyStaticDockerfile = "${mostlyStaticDockerfile.toString.replace("\\", "\\\\")}"
765772
| def cs = "${settings.cs().replace("\\", "\\\\")}"
766773
| def workspaceDirName = "$workspaceDirName"
774+
| def libsodiumVersion = "${deps.libsodiumVersion}"
767775
|}
768776
|""".stripMargin
769777
if (!os.isFile(dest) || os.read(dest) != code)

modules/build/src/main/scala/scala/build/PersistentDiagnosticLogger.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ class PersistentDiagnosticLogger(parent: Logger) extends Logger {
3535
def scalaNativeCliInternalLoggerOptions: List[String] = parent.scalaNativeCliInternalLoggerOptions
3636

3737
def compilerOutputStream: PrintStream = parent.compilerOutputStream
38+
39+
def verbosity: Int = parent.verbosity
3840
}

modules/build/src/test/scala/scala/build/tests/BuildProjectTests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class BuildProjectTests extends munit.FunSuite {
5555

5656
override def compilerOutputStream: PrintStream = ???
5757

58+
override def verbosity = ???
59+
5860
}
5961

6062
val bloopJavaPath = Position.Bloop("/home/empty/jvm/8/")

modules/build/src/test/scala/scala/build/tests/TestLogger.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ case class TestLogger(info: Boolean = true, debug: Boolean = false) extends Logg
5555
def bloopCliInheritStderr = false
5656

5757
def compilerOutputStream = System.err
58+
59+
def verbosity =
60+
if (debug) 2
61+
else if (info) 0
62+
else -1
5863
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package scala.cli.commands.github
2+
3+
import caseapp._
4+
5+
import scala.cli.commands.CoursierOptions
6+
7+
// format: off
8+
final case class SecretCreateOptions(
9+
@Recurse
10+
shared: SharedSecretOptions = SharedSecretOptions(),
11+
@Recurse
12+
coursier: CoursierOptions = CoursierOptions(),
13+
@ExtraName("pubKey")
14+
publicKey: Option[String] = None,
15+
@ExtraName("n")
16+
dummy: Boolean = false,
17+
@Hidden
18+
printRequest: Boolean = false
19+
)
20+
// format: on
21+
22+
object SecretCreateOptions {
23+
implicit lazy val parser: Parser[SecretCreateOptions] = Parser.derive
24+
implicit lazy val help: Help[SecretCreateOptions] = Help.derive
25+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala.cli.commands.github
2+
3+
import caseapp._
4+
5+
// format: off
6+
final case class ListSecretsOptions(
7+
@Recurse
8+
shared: SharedSecretOptions
9+
)
10+
// format: on
11+
12+
object ListSecretsOptions {
13+
implicit lazy val parser: Parser[ListSecretsOptions] = Parser.derive
14+
implicit lazy val help: Help[ListSecretsOptions] = Help.derive
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package scala.cli.commands.github
2+
3+
import caseapp._
4+
5+
import scala.cli.internal.PasswordOptionParsers._
6+
import scala.cli.signing.shared.PasswordOption
7+
import scala.cli.commands.LoggingOptions
8+
import scala.cli.signing.shared.Secret
9+
10+
// format: off
11+
final case class SharedSecretOptions(
12+
@Recurse
13+
logging: LoggingOptions = LoggingOptions(),
14+
token: PasswordOption = PasswordOption.Value(Secret("")),
15+
@ExtraName("repo")
16+
repository: String = ""
17+
) {
18+
// format: on
19+
20+
lazy val (repoOrg, repoName) =
21+
repository.split('/') match {
22+
case Array(org, name) => (org, name)
23+
case _ =>
24+
sys.error(s"Malformed repository: '$repository' (expected 'org/name')")
25+
}
26+
}
27+
28+
object SharedSecretOptions {
29+
lazy val parser: Parser[SharedSecretOptions] = Parser.derive
30+
implicit lazy val parserAux: Parser.Aux[SharedSecretOptions, parser.D] = parser
31+
implicit lazy val help: Help[SharedSecretOptions] = Help.derive
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package scala.cli.internal;
2+
3+
import com.oracle.svm.core.annotate.AutomaticFeature;
4+
import com.oracle.svm.core.jdk.NativeLibrarySupport;
5+
import com.oracle.svm.core.jdk.PlatformNativeLibrarySupport;
6+
import com.oracle.svm.hosted.FeatureImpl;
7+
import com.oracle.svm.hosted.c.NativeLibraries;
8+
import org.graalvm.nativeimage.hosted.Feature;
9+
import org.graalvm.nativeimage.Platform;
10+
import org.graalvm.nativeimage.Platforms;
11+
12+
@AutomaticFeature
13+
@Platforms({Platform.WINDOWS.class})
14+
public class LibsodiumjniFeature implements Feature {
15+
16+
@Override
17+
public void beforeAnalysis(BeforeAnalysisAccess access) {
18+
NativeLibrarySupport.singleton().preregisterUninitializedBuiltinLibrary("sodiumjni");
19+
PlatformNativeLibrarySupport.singleton().addBuiltinPkgNativePrefix("libsodiumjni_");
20+
NativeLibraries nativeLibraries = ((FeatureImpl.BeforeAnalysisAccessImpl) access).getNativeLibraries();
21+
nativeLibraries.addStaticJniLibrary("sodiumjni");
22+
nativeLibraries.addDynamicNonJniLibrary("sodium");
23+
}
24+
}

modules/cli/src/main/scala/scala/cli/ScalaCliCommands.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import caseapp.core.help.{Help, RuntimeCommandsHelp}
66
import java.nio.file.InvalidPathException
77

88
import scala.cli.commands._
9+
import scala.cli.commands.github.{SecretCreate, SecretList}
910
import scala.cli.commands.pgp.PgpCommands
1011

1112
class ScalaCliCommands(
@@ -37,6 +38,8 @@ class ScalaCliCommands(
3738
Package,
3839
Publish,
3940
Run,
41+
SecretCreate,
42+
SecretList,
4043
SetupIde,
4144
Shebang,
4245
Test,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package scala.cli.commands.github
2+
3+
import com.github.plokhotnyuk.jsoniter_scala.core._
4+
import com.github.plokhotnyuk.jsoniter_scala.macros._
5+
6+
import java.util.Base64
7+
8+
object GitHubApi {
9+
10+
final case class Secret(
11+
name: String,
12+
created_at: String,
13+
updated_at: String
14+
)
15+
16+
final case class SecretList(
17+
total_count: Int,
18+
secrets: List[Secret]
19+
)
20+
21+
implicit val secretListCodec: JsonValueCodec[SecretList] =
22+
JsonCodecMaker.make
23+
24+
final case class PublicKey(
25+
key_id: String,
26+
key: String
27+
) {
28+
def decodedKey: Array[Byte] =
29+
Base64.getDecoder().decode(key)
30+
}
31+
32+
implicit val publicKeyCodec: JsonValueCodec[PublicKey] =
33+
JsonCodecMaker.make
34+
35+
final case class EncryptedSecret(
36+
encrypted_value: String,
37+
key_id: String
38+
)
39+
40+
implicit val encryptedSecretCodec: JsonValueCodec[EncryptedSecret] =
41+
JsonCodecMaker.make
42+
43+
}

0 commit comments

Comments
 (0)