4545public abstract class FileAwareFactoryFn <T >
4646 implements SerializableFunction <Map <String , Object >, T > {
4747
48- public static final String GCS_PATH_PREFIX = "gs ://" ;
48+ public static final String EXTERNAL_BUCKET_PREFIX = ".* ://" ;
4949 public static final String SECRET_VALUE_PREFIX = "secretValue:" ;
5050 public static final String DIRECTORY_PREFIX = "/tmp" ;
5151 private static final Pattern PATH_PATTERN =
52- Pattern .compile ("(gs ://[^\" ]+)|(secretValue:[^\" ]+)|(secretFile:[^\" ]+)" );
52+ Pattern .compile ("([a-zA-Z0-9]+ ://[^\" ]+)|(secretValue:[^\" ]+)|(secretFile:[^\" ]+)" );
5353
5454 private static final Map <String , byte []> secretCache = new ConcurrentHashMap <>();
5555
@@ -86,18 +86,18 @@ public T apply(Map<String, Object> config) {
8686 StringBuffer sb = new StringBuffer ();
8787
8888 while (matcher .find ()) {
89- String gcsPath = matcher .group (1 );
89+ String externalPath = matcher .group (1 );
9090 String secretValue = matcher .group (2 );
9191 String secretFile = matcher .group (3 );
9292
93- if (gcsPath != null ) {
93+ if (externalPath != null ) {
9494 try {
95- String tmpPath = replacePathWithLocal (gcsPath );
96- String localPath = downloadGcsFile ( gcsPath , tmpPath );
95+ String tmpPath = replacePathWithLocal (externalPath );
96+ String localPath = downloadExternalFile ( externalPath , tmpPath );
9797 matcher .appendReplacement (sb , Matcher .quoteReplacement (localPath ));
98- LOG .info ("Downloaded {} to {}" , gcsPath , localPath );
98+ LOG .info ("Downloaded {} to {}" , externalPath , localPath );
9999 } catch (IOException io ) {
100- throw new IOException ("Failed to download file : " + gcsPath , io );
100+ throw new IOException ("Failed to download file : " + externalPath , io );
101101 }
102102 } else if (secretValue != null ) {
103103 try {
@@ -131,16 +131,16 @@ public T apply(Map<String, Object> config) {
131131 }
132132
133133 /**
134- * A function to download files from their specified gcs path and copy them to the provided local
135- * filepath. The local filepath is provided by the replacePathWithLocal.
134+ * A function to download files from their specified external storage path and copy them to the
135+ * provided local filepath. The local filepath is provided by the replacePathWithLocal.
136136 *
137- * @param gcsFilePath
137+ * @param externalFilePath
138138 * @param outputFileString
139139 * @return
140140 * @throws IOException
141141 */
142- protected static synchronized String downloadGcsFile ( String gcsFilePath , String outputFileString )
143- throws IOException {
142+ protected static synchronized String downloadExternalFile (
143+ String externalFilePath , String outputFileString ) throws IOException {
144144 // create the file only if it doesn't exist
145145 if (new File (outputFileString ).exists ()) {
146146 return outputFileString ;
@@ -150,14 +150,15 @@ protected static synchronized String downloadGcsFile(String gcsFilePath, String
150150 if (parentDir != null ) {
151151 Files .createDirectories (parentDir );
152152 }
153- LOG .info ("Staging GCS file [{}] to [{}]" , gcsFilePath , outputFileString );
153+ LOG .info ("Staging external file [{}] to [{}]" , externalFilePath , outputFileString );
154154 Set <StandardOpenOption > options = new HashSet <>(2 );
155155 options .add (StandardOpenOption .CREATE );
156156 options .add (StandardOpenOption .WRITE );
157157
158- // Copy the GCS file into a local file and will throw an I/O exception in case file not found.
158+ // Copy the external file into a local file and will throw an I/O exception in case file not
159+ // found.
159160 try (ReadableByteChannel readerChannel =
160- FileSystems .open (FileSystems .matchSingleFileSpec (gcsFilePath ).resourceId ())) {
161+ FileSystems .open (FileSystems .matchSingleFileSpec (externalFilePath ).resourceId ())) {
161162 try (FileChannel writeChannel = FileChannel .open (outputFilePath , options )) {
162163 writeChannel .transferFrom (readerChannel , 0 , Long .MAX_VALUE );
163164 }
@@ -170,16 +171,20 @@ protected byte[] getSecretWithCache(String secretId) {
170171 }
171172
172173 /**
173- * A helper method to create a new string with the gcs paths replaced with their local path and
174- * subdirectory based on the factory type in the /tmp directory. For example, the kerberos factory
175- * type will replace the file paths with /tmp/kerberos/file.path
174+ * A helper method to create a new string with the external paths replaced with their local path
175+ * and subdirectory based on the factory type in the /tmp directory. For example, the kerberos
176+ * factory type will replace the file paths with /tmp/kerberos/file.path
176177 *
177- * @param gcsPath
178- * @return a string with all instances of GCS paths converted to the local paths where the files
179- * sit.
178+ * @param externalPath
179+ * @return a string with all instances of external paths converted to the local paths where the
180+ * files sit.
180181 */
181- private String replacePathWithLocal (String gcsPath ) throws IOException {
182- return DIRECTORY_PREFIX + "/" + factoryType + "/" + gcsPath .substring (GCS_PATH_PREFIX .length ());
182+ private String replacePathWithLocal (String externalPath ) throws IOException {
183+ return DIRECTORY_PREFIX
184+ + "/"
185+ + factoryType
186+ + "/"
187+ + externalPath .substring (EXTERNAL_BUCKET_PREFIX .length ());
183188 }
184189
185190 /**
0 commit comments