Home > Net >  how to use google credential on workload identity use on java
how to use google credential on workload identity use on java

Time:02-10

i have set on my properties like this

gcp.storage.json-path=${GOOGLE_APPLICATION_CREDENTIALS}

and have code like this

public CloudStorageService(
            @Value("${gcp.storage.bucket-name-file}") String fileBucketName,
            @Value("${gcp.storage.bucket-name}") String bucketName,
            @Value("${gcp.storage.json-path}") String jsonPath
    ) {
        this.fileBucketName = fileBucketName;
        this.bucketName = bucketName;
        this.jsonPath = jsonPath;

        log.info("fileBuckerName: {}", fileBucketName);
        log.info("bucketName: {}", bucketName);
        log.info("jsonPath: {}", jsonPath);
    }

    @PostConstruct
    void init() {
        try {
            GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
                    .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/devstorage.read_write"));
           // storage = StorageOptions.getDefaultInstance().getService();

but when i deploy my code on kubernetes i cannot upload my file to GCS. my question is how to read data from my kubernetes workload identity using java ?

CodePudding user response:

  •  Tags:  
  • Related