diff options
author | zachdriver <zach@driver.xyz> | 2017-05-18 16:12:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-18 16:12:32 -0700 |
commit | 6427b9dc1a60b670c70aca05f419e3fc3313cf6a (patch) | |
tree | 92ea3d3ab0b4b2f01531916e1ab7ae3fc5d1b24e /src/main/scala/xyz/driver/core/file/package.scala | |
parent | 3d2e8eb57e074e51da53d8c239c63b4ce7e5a820 (diff) | |
parent | 06cecf3761c77efbbc35b3d36178b34dd7ea7e64 (diff) | |
download | driver-core-6427b9dc1a60b670c70aca05f419e3fc3313cf6a.tar.gz driver-core-6427b9dc1a60b670c70aca05f419e3fc3313cf6a.tar.bz2 driver-core-6427b9dc1a60b670c70aca05f419e3fc3313cf6a.zip |
Merge pull request #34 from drivergroup/zsmith/PDW-336-gcsv0.12.7
PDW-336 Add GCS file storage implementation
Diffstat (limited to 'src/main/scala/xyz/driver/core/file/package.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/file/package.scala | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/core/file/package.scala b/src/main/scala/xyz/driver/core/file/package.scala new file mode 100644 index 0000000..9000894 --- /dev/null +++ b/src/main/scala/xyz/driver/core/file/package.scala @@ -0,0 +1,60 @@ +package xyz.driver.core + +import java.io.File +import java.nio.file.Path + +import xyz.driver.core.time.Time + +import scala.concurrent.Future +import scalaz.{ListT, OptionT} + +package file { + + import java.net.URL + + import scala.concurrent.duration.Duration + + final case class FileLink( + name: Name[File], + location: Path, + revision: Revision[File], + lastModificationDate: Time, + fileSize: Long + ) + + trait FileService { + + def getFileLink(id: Name[File]): FileLink + + def getFile(fileLink: FileLink): File + } + + trait FileStorage { + + def upload(localSource: File, destination: Path): Future[Unit] + + def download(filePath: Path): OptionT[Future, File] + + def delete(filePath: Path): Future[Unit] + + def list(path: Path): ListT[Future, FileLink] + + /** List of characters to avoid in S3 (I would say file names in general) + * + * @see http://stackoverflow.com/questions/7116450/what-are-valid-s3-key-names-that-can-be-accessed-via-the-s3-rest-api + */ + private val illegalChars = "\\^`><{}][#%~|&@:,$=+?; " + + protected def checkSafeFileName[T](filePath: Path)(f: => T): T = { + filePath.toString.find(c => illegalChars.contains(c)) match { + case Some(illegalCharacter) => + throw new IllegalArgumentException(s"File name cannot contain character `$illegalCharacter`") + case None => f + } + } + } + + trait SignedFileStorage extends FileStorage { + def signedFileUrl(filePath: Path, duration: Duration): OptionT[Future, URL] + } +} |