This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| InputStream firebaseCredential = createFirebaseCredential(); | |
| this.storageOptions = StorageOptions.newBuilder() | |
| .setProjectId(projectId) | |
| .setCredentials(GoogleCredentials.fromStream(firebaseCredential)) | |
| .build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IOUtils.toInputStream(jsonString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IOUtils.toInputStream(jsonString); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ObjectMapper mapper = new ObjectMapper(); | |
| String jsonString = mapper.writeValueAsString(firebaseCredential); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FirebaseCredential firebaseCredential = new FirebaseCredential(); | |
| //private key | |
| String privateKey = environment.getRequiredProperty("FIREBASE_PRIVATE_KEY").replace("\\n", "\n"); | |
| firebaseCredential.setType(environment.getRequiredProperty("FIREBASE_TYPE")); | |
| firebaseCredential.setProject_id(projectId); | |
| firebaseCredential.setPrivate_key_id("FIREBASE_PRIVATE_KEY_ID"); | |
| firebaseCredential.setPrivate_key(privateKey); | |
| firebaseCredential.setClient_email(environment.getRequiredProperty("FIREBASE_CLIENT_EMAIL")); | |
| firebaseCredential.setClient_id(environment.getRequiredProperty("FIREBASE_CLIENT_ID")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FIREBASE_BUCKET_NAME=<add-the-value-from-service-account-file.json> | |
| FIREBASE_PROJECT_ID=<add-the-value-from-service-account-file.json> | |
| FIREBASE_TYPE=<add-the-value-from-service-account-file.json> | |
| FIREBASE_PRIVATE_KEY_ID=<add-the-value-from-service-account-file.json> | |
| FIREBASE_PRIVATE_KEY=<add-the-value-from-service-account-file.json> | |
| FIREBASE_CLIENT_EMAIL=<add-the-value-from-service-account-file.json> | |
| FIREBASE_CLIENT_ID=<add-the-value-from-service-account-file.json> | |
| FIREBASE_AUTH_URI=<add-the-value-from-service-account-file.json> | |
| FIREBASE_TOKEN_URI=<add-the-value-from-service-account-file.json> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FirebaseCredential { | |
| private String type; | |
| private String project_id; | |
| private String private_key_id; | |
| private String private_key; | |
| private String client_email; | |
| private String client_id; | |
| private String auth_uri; | |
| private String token_uri; | |
| private String auth_provider_x509_cert_url; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| public class StorageFactory { | |
| private final Logger log = LoggerFactory.getLogger(StorageFactory.class); | |
| private final Environment environment; | |
| private final FirebaseStorageStrategy firebaseStorageStrategy; | |
| private final FileStorageStrategy fileStorageStrategy; | |
| public StorageFactory(Environment environment, FirebaseStorageStrategy firebaseStorageStrategy, FileStorageStrategy fileStorageStrategy) { | |
| this.environment = environment; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| public class FirebaseStorageStrategy implements StorageStrategy { | |
| private final Logger log = LoggerFactory.getLogger(FirebaseStorageStrategy.class); | |
| private final Environment environment; | |
| private StorageOptions storageOptions; | |
| private String bucketName; | |
| private String projectId; | |
| public FirebaseStorageStrategy(Environment environment) { | |
| this.environment = environment; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String bucketName = environment.getRequiredProperty("FIREBASE_BUCKET_NAME"); | |
| String projectId = environment.getRequiredProperty("FIREBASE_PROJECT_ID"); | |
| FileInputStream serviceAccount = | |
| new FileInputStream("/home/user/Downloads/service-account-file.json"); | |
| StorageOptions.newBuilder() | |
| .setProjectId(projectId) | |
| .setCredentials(GoogleCredentials.fromStream(serviceAccount)) | |
| .build(); |