2

I am trying to use https://pub.dev/packages/googleapis and get a value from the SecretManagerApi.

This is my current code but it doesn't even resolve.

final secretVersion = await SecretManagerApi(Client())
          .projects
          .secrets
          .get("projects/myProjectId/secrets/mySec/versions/latest")

so secretVersion never gets a value. What am I doing wrong?

Christian
  • 834
  • 7
  • 18

1 Answers1

1

This is one way I use to authenticate with Secret Manager:

Add your google json file to path and then export GOOGLE_APPLICATION_CREDENTIALS=<YOUR_PATH_TO_JSON_FILE>

Then change to this code:

import 'package:googleapis/secretmanager/v1.dart';
...
final client await clientViaApplicationDefaultCredentials(
    scopes: [FirestoreApi.cloudPlatformScope]);
final api = SecretManagerApi(client);
final secrets = await api.projects.secrets.versions.access(<YOUR_SECRET_NAME>);
print(secrets.payload!.data.toString());
// print(utf8.decode(secrets.payload!.dataAsBytes));
...
  • Thank you very much. I almost got it to work but realized, that `clientViaApplicationDefaultCredentials` doesn't seem to work on a Web-App. How can I get the required Client on Web? – Christian Mar 26 '22 at 15:46