Skip to content

Latest commit

 

History

History

native-image-sample

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Secret Manager Sample Application with Native Image

The Secret Manager sample application demonstrates some common operations with Google Cloud Secret Manager and is compatible with Native Image compilation.

This application will create a new secret named native-secretmanager-test-secret if it does not already exist. It will then add a new version of the secret and then attempt to read it.

Setup Instructions

You will need to follow these prerequisite steps in order to run these samples:

  1. If you have not already, create a Google Cloud Platform Project.

  2. Install the Google Cloud SDK which will allow you to run the sample with your project's credentials.

    Once installed, log in with Application Default Credentials using the following command:

    gcloud auth application-default login
    

    Note: Authenticating with Application Default Credentials is convenient to use during development, but we recommend alternate methods of authentication during production use.

  3. Install the native image compiler.

    You can follow the official installation instructions. After following the instructions, ensure that you install the Native Image extension installed by running:

    gu install native-image
    
  4. Enable the Secret Manager APIs.

Run with Native Image Compilation

Navigate to this directory in a new terminal.

  1. Compile the application using the native image compiler. This step may take a few minutes.

    mvn package -P native -DskipTests
    
  2. Run the application:

    ./target/native-image-sample
    
  3. The application runs through some basic Secret Manager operations (create, update, read) and then prints some results of the operations.

    Created secret: projects/xxxxxx/secrets/graal-secretmanager-test-secret
    Added Secret Version: projects/xxxxxx/secrets/graal-secretmanager-test-secret/versions/1
    Reading secret value: Hello World
    (Note: Don't print secret values in prod!)
    

Sample Integration test with Native Image Support

In order to run the sample integration test as a native image, call the following command:

mvn test -Pnative