小编Baf*_*tek的帖子

无法访问 GCP Secret Manager 中的密钥

我正在尝试将我的代码从使用存储在.env文件中的 API 密钥迁移到使用 Google Cloud Platform Secrets Manager。我已按照此处的说明进行操作但遇到错误,提示我无权访问该机密。

import * as admin from "firebase-admin"
import { SecretManagerServiceClient } from "@google-cloud/secret-manager"

admin.initializeApp()
const secretClient = new SecretManagerServiceClient()

async function main() {
  async function getSecret(): Promise<string | null | undefined> {
    const [version] = await secretClient.accessSecretVersion({ name: "TELEGRAM_TOKEN" })

    return version.payload?.data?.toString()
  }

  const TELEGRAM_TOKEN = await getSecret()
  console.log(TELEGRAM_TOKEN)
}

main().catch(console.error)
Run Code Online (Sandbox Code Playgroud)

这就是我得到的错误:

> node lib/app.js --telegram

{ Error: 7 PERMISSION_DENIED: Permission denied on resource project TELEGRAM_TOKEN.
    at …
Run Code Online (Sandbox Code Playgroud)

cloud google-cloud-platform gcloud google-secret-manager

11
推荐指数
3
解决办法
5385
查看次数

初始化时对 ListView 中的元素进行动画处理

我想实现如下所示的目标(动画风格并不重要,我正在寻找实现此目的的方法)

例子

但是,所有资源和问题仅解释如何创建项目添加或删除动画。

我当前的代码(我使用 BLoC 模式)

class _MembersPageState extends State<MembersPage> {
  @override
  Widget build(BuildContext context) {
    return BlocProvider<MembersPageBloc>(
      create: (context) =>
          MembersPageBloc(userRepository: UserRepository.instance)..add(MembersPageShowed()),
      child: BlocBuilder<MembersPageBloc, MembersPageState>(
        builder: (context, state) {
          if (state is MembersPageSuccess) {
            return ListView.builder(
              itemCount: state.users.length,
              itemBuilder: (context, index) {
                User user = state.users[index];

                return ListTile(
                  isThreeLine: true,
                  leading: Icon(Icons.person, size: 36),
                  title: Text(user.name),
                  subtitle: Text(user.username),
                  onTap: () => null,
                );
              },
            );
          } else
            return Text("I don't care");
        },
      ),
    );
  }
}

Run Code Online (Sandbox Code Playgroud)

flutter flutter-animation flutter-animatedlist

9
推荐指数
1
解决办法
1万
查看次数

如何从 Gradle 的“pluginManagement {}”块调用函数?

介绍

\n

您好,我正在尝试对我的应用程序中找到的代码进行重复数据删除settings.gradle。这是我的文件当前的样子:

\n
pluginManagement {\n    def localPropertiesFile = new File(rootProject.projectDir, "local.properties")\n    def properties = new Properties()\n    assert localPropertiesFile.exists()\n    localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }\n    def flutterSdkPath = properties.getProperty("flutter.sdk")\n    assert flutterSdkPath != null, "flutter.sdk not set in local.properties"\n\n    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")\n\n    plugins {\n        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false\n    }\n}\n\ninclude \':app\'\n\ndef localPropertiesFile = new File(rootProject.projectDir, "local.properties")\ndef properties = new Properties()\nassert localPropertiesFile.exists()\nlocalPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }\ndef flutterSdkPath = properties.getProperty("flutter.sdk")\nassert flutterSdkPath != null, "flutter.sdk not set in local.properties"\napply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"\n
Run Code Online (Sandbox Code Playgroud)\n …

gradle

5
推荐指数
1
解决办法
593
查看次数

Kotlin:如何将具有不同参数的函数作为参数传递给其他函数

所以,我正在重写我的应用程序代码,使其“干净”(层分离,遵循 Android 团队推荐的 MVVM 模式)

在这里,我有一个简单的 Retrofit 接口来与我的 API 通信

interface Api {

    @GET("comments")
    suspend fun getPlaceComments(@Query("placeId") placeId: String): Response<List<CommentResponse>>

    @POST("comments")
    suspend fun addPlaceComment(@Header("placeId") placeId: String, @Header("text") text: String): Response<Unit>

    @DELETE("comments")
    suspend fun deletePlaceComment(@Header("placeId") placeId: String): Response<Unit>
}
Run Code Online (Sandbox Code Playgroud)

只是一个简单的 CRUD。

现在,上一层,我有我的 SocialRepository。为了避免代码重复,我创建了一个通用方法callSafely,该方法将一个挂起的 API 函数和一个 placeId 作为其参数。

class SocialRepository {
    private val client: Api = ApiClient.webservice

    private suspend fun <T> callSafely(
        apiMethod: suspend (placeId: String) -> Response<T>,
        placeId: String,
    ): T? {
        Log.d(TAG, "$apiMethod called safely")

        var response: Response<T>? …
Run Code Online (Sandbox Code Playgroud)

generics android kotlin retrofit

4
推荐指数
1
解决办法
386
查看次数

无法构建项目 java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

我有一个在 Android Studio 中创建的 Android 项目,它运行良好。最近,我开始使用 IntelliJ IDEA,每次我想构建我的项目时,我都会收到以下异常:

e: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

Execution failed for task ':app:kaptDebugKotlin'.
> Internal compiler error. See log for more details
Run Code Online (Sandbox Code Playgroud)
Task :app:kaptDebugKotlin FAILED
e: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3137)
    at java.base/java.lang.Class.getConstructor0(Class.java:3342)
    at java.base/java.lang.Class.newInstance(Class.java:556)
    at org.jetbrains.kotlin.cli.jvm.plugins.ServiceLoaderLite.loadImplementations(ServiceLoaderLite.kt:50)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension$loadProcessors$efficientProcessorLoader$1.doLoadProcessors(Kapt3Extension.kt:83)
    at org.jetbrains.kotlin.kapt3.base.ProcessorLoader.loadProcessors(ProcessorLoader.kt:42)
    at org.jetbrains.kotlin.kapt3.base.ProcessorLoader.loadProcessors$default(ProcessorLoader.kt:25)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.loadProcessors(Kapt3Extension.kt:88)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:171)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:96)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:384)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:70)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:375)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:123)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:159)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93) …
Run Code Online (Sandbox Code Playgroud)

android intellij-idea gradle kotlin

1
推荐指数
1
解决办法
4740
查看次数