Skip to content

Commit

Permalink
Update scalafmt to 3.0.6 and apply style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
beatriz committed Oct 31, 2021
1 parent e5df74d commit cf282f5
Show file tree
Hide file tree
Showing 49 changed files with 897 additions and 629 deletions.
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version = 2.7.5
version = 3.0.6

runner.dialect = scala213
maxColumn = 120
fileOverride {
"glob:**/*.sbt" {
runner.dialect = sbt1
align.preset = most
}
"glob:**/project/*.scala" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ trait ExtraMiscDirectives {

/** Inserts a "Cache-Control" header, instructing the browser to cache the HTTP response for the supplied duration.
* The header key "max-age" specifies the number of seconds during which the browser should cache the HTTP response.
* In case the supplied duration is less than 1 second, this directive defaults to the minimum duration allowed,
* 1 second.
* In case the supplied duration is less than 1 second, this directive defaults to the minimum duration allowed, 1
* second.
*
* @param maxAgeDuration the duration for how long to cache the HTTP response
* @return a Directive that inserts a Cache-Control header
* @param maxAgeDuration
* the duration for how long to cache the HTTP response
* @return
* a Directive that inserts a Cache-Control header
*/
def cacheControlMaxAge(maxAgeDuration: Option[FiniteDuration]): Directive0 = {
maxAgeDuration match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import com.velocidi.apso.Logging
* is continuously active and ready to route incoming requests.
*
* For one-off requests or requests to previously unknown hosts, this trait defines two routes:
* - `proxySingleTo` takes the original request and proxies it to the proxy URI;
* - `proxySingleToUnmatchedPath` copies only the unmatched path from the original URI, and adds it to the path of the
* proxy URI.
* - `proxySingleTo` takes the original request and proxies it to the proxy URI;
* - `proxySingleToUnmatchedPath` copies only the unmatched path from the original URI, and adds it to the path of
* the proxy URI.
*
* In order for the client ip to be propagated in `X-Forwarded-For` headers, the
* `akka.http.server.remote-address-attribute` config setting must be set to "on".
Expand Down Expand Up @@ -85,8 +85,10 @@ trait ProxySupport extends ClientIPDirectives {

/** Proxies a single request to a destination URI.
*
* @param uri the target URI
* @return a route that handles requests by proxying them to the given URI.
* @param uri
* the target URI
* @return
* a route that handles requests by proxying them to the given URI.
*/
def proxySingleTo(uri: Uri): Route = proxy() { case (ip, ctx) =>
ctx.request.withUri(uri).withHeaders(getHeaders(ip, ctx.request.headers.toList))
Expand All @@ -95,33 +97,40 @@ trait ProxySupport extends ClientIPDirectives {
/** Proxies a single request to a destination base URI. The target URI is created by concatenating the base URI with
* the unmatched path.
*
* @param uri the target base URI
* @return a route that handles requests by proxying them to the given URI.
* @param uri
* the target base URI
* @return
* a route that handles requests by proxying them to the given URI.
*/
def proxySingleToUnmatchedPath(uri: Uri): Route = proxy() { case (ip, ctx) =>
ctx.request
.withUri(uri.withPath(uri.path ++ ctx.unmatchedPath).withQuery(ctx.request.uri.query()))
.withHeaders(getHeaders(ip, ctx.request.headers.toList))
}

/** Proxies a single request to a destination URI.
* The response in not streamed, but converted to a strict entity with a set timeout.
/** Proxies a single request to a destination URI. The response in not streamed, but converted to a strict entity with
* a set timeout.
*
* @param uri the target URI
* @param timeout maximum time to wait for the full response.
* @return a route that handles requests by proxying them to the given URI.
* @param uri
* the target URI
* @param timeout
* maximum time to wait for the full response.
* @return
* a route that handles requests by proxying them to the given URI.
*/
def strictProxySingleTo(uri: Uri, timeout: FiniteDuration): Route = proxy(Some(timeout)) { case (ip, ctx) =>
ctx.request.withUri(uri).withHeaders(getHeaders(ip, ctx.request.headers.toList))
}

/** Proxies a single request to a destination base URI. The target URI is created by concatenating the base URI with
* the unmatched path.
* The response in not streamed, but converted to a strict entity with a set timeout.
* the unmatched path. The response in not streamed, but converted to a strict entity with a set timeout.
*
* @param uri the target base URI
* @param timeout maximum time to wait for the full response.
* @return a route that handles requests by proxying them to the given URI.
* @param uri
* the target base URI
* @param timeout
* maximum time to wait for the full response.
* @return
* a route that handles requests by proxying them to the given URI.
*/
def strictProxySingleToUnmatchedPath(uri: Uri, timeout: FiniteDuration): Route = proxy(Some(timeout)) {
case (ip, ctx) =>
Expand All @@ -136,10 +145,14 @@ trait ProxySupport extends ClientIPDirectives {
/** A representation of a reverse proxy for a remote host. This class internally materializes a flow that is
* continuously active and ready to route incoming requests.
*
* @param host the target host
* @param port the target port
* @param reqQueueSize the maximum size of the queue of pending backend requests
* @param strictTimeout maximum time to wait for the full response.
* @param host
* the target host
* @param port
* the target port
* @param reqQueueSize
* the maximum size of the queue of pending backend requests
* @param strictTimeout
* maximum time to wait for the full response.
*/
class Proxy(
host: String,
Expand Down Expand Up @@ -180,9 +193,12 @@ trait ProxySupport extends ClientIPDirectives {

/** Sends a manually crafted request to a destination URI.
*
* @param req the HTTP Request
* @param failOnDrop if the future should fail when the message is dropped, or complete with a 503
* @return the request result.
* @param req
* the HTTP Request
* @param failOnDrop
* if the future should fail when the message is dropped, or complete with a 503
* @return
* the request result.
*/
def sendRequest(req: HttpRequest, failOnDrop: Boolean): Future[RouteResult] = {
val promise = Promise[RouteResult]()
Expand All @@ -199,8 +215,10 @@ trait ProxySupport extends ClientIPDirectives {

/** Proxies a request to a destination URI.
*
* @param uri the target URI
* @return a route that handles requests by proxying them to the given URI.
* @param uri
* the target URI
* @return
* a route that handles requests by proxying them to the given URI.
*/
def proxyTo(uri: Uri): Route = {
optionalRemoteAddress { ip => ctx =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import com.amazonaws.auth._
import com.typesafe.config.{Config, ConfigFactory}

/** AWS credentials provider that retrieves credentials from a typesafe configuration.
* @param config the typesafe configuration
* @param accessKeyPath the path in the configuration that contains the access key
* @param secretKeyPath the path in the configuration that contains the secret key
* @param config
* the typesafe configuration
* @param accessKeyPath
* the path in the configuration that contains the access key
* @param secretKeyPath
* the path in the configuration that contains the secret key
*/
case class ConfigCredentialsProvider(
config: Config = ConfigFactory.load(),
Expand Down
108 changes: 69 additions & 39 deletions aws/src/main/scala/com/velocidi/apso/aws/S3Bucket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import com.velocidi.apso.{Logging, TryWith}
/** A representation of an Amazon's S3 bucket. This class wraps an `AmazonS3Client` and provides a higher level
* interface for pushing and pulling files to and from a bucket.
*
* @param bucketName the name of the bucket
* @param credentialsProvider optional AWS credentials provider to use (since AWSCredentials are not serializable).
* If the parameter is not supplied, they will be retrieved from the
* [[CredentialStore]].
* @param bucketName
* the name of the bucket
* @param credentialsProvider
* optional AWS credentials provider to use (since AWSCredentials are not serializable). If the parameter is not
* supplied, they will be retrieved from the [[CredentialStore]].
*/
class S3Bucket(
val bucketName: String,
Expand Down Expand Up @@ -99,20 +100,24 @@ class S3Bucket(

private[this] def sanitizeKey(key: String) = if (key.startsWith("./")) key.drop(2) else key

/** Returns size of the file in the location specified by `key` in the bucket. If the file doesn't
* exist the return value is 0.
/** Returns size of the file in the location specified by `key` in the bucket. If the file doesn't exist the return
* value is 0.
*
* @param key the remote pathname for the file
* @return the size of the file in the location specified by `key` in the bucket if the exists, 0 otherwise.
* @param key
* the remote pathname for the file
* @return
* the size of the file in the location specified by `key` in the bucket if the exists, 0 otherwise.
*/
def size(key: String): Long = retry {
s3.getObjectMetadata(bucketName, key).getContentLength
}.getOrElse(0)

/** Returns a list of objects in a bucket matching a given prefix.
*
* @param prefix the prefix to match
* @return a list of objects in a bucket matching a given prefix.
* @param prefix
* the prefix to match
* @return
* a list of objects in a bucket matching a given prefix.
*/
def getObjectsWithMatchingPrefix(prefix: String, includeDirectories: Boolean = false): Iterator[S3ObjectSummary] = {
log.info(s"Finding files matching prefix '$prefix'...")
Expand All @@ -130,17 +135,22 @@ class S3Bucket(

/** Returns a list of filenames and directories in a bucket matching a given prefix.
*
* @param prefix the prefix to match
* @return a list of filenames in a bucket matching a given prefix.
* @param prefix
* the prefix to match
* @return
* a list of filenames in a bucket matching a given prefix.
*/
def getFilesWithMatchingPrefix(prefix: String, includeDirectories: Boolean = false): Iterator[String] =
getObjectsWithMatchingPrefix(prefix, includeDirectories).map(_.getKey)

/** Pushes a given local `File` to the location specified by `key` in the bucket.
*
* @param key the remote pathname for the file
* @param file the local `File` to push
* @return true if the push was successful, false otherwise.
* @param key
* the remote pathname for the file
* @param file
* the local `File` to push
* @return
* true if the push was successful, false otherwise.
*/
def push(key: String, file: File): Boolean = retry {
log.info(s"Pushing file '${file.getPath}' to 's3://$bucketName/$key'")
Expand All @@ -151,10 +161,14 @@ class S3Bucket(

/** Pushes a given `InputStream` to the location specified by `key` in the bucket.
*
* @param key the remote pathname for the file
* @param inputStream the `InputStream` to push
* @param length the content lenght (setting this to `None` can impact performance
* @return true if the push was successful, false otherwise.
* @param key
* the remote pathname for the file
* @param inputStream
* the `InputStream` to push
* @param length
* the content lenght (setting this to `None` can impact performance
* @return
* true if the push was successful, false otherwise.
*/
def push(key: String, inputStream: InputStream, length: Option[Long]): Boolean = retry {
log.info(s"Pushing to 's3://$bucketName/$key'")
Expand All @@ -167,27 +181,33 @@ class S3Bucket(

/** Deletes the file in the location specified by `key` in the bucket.
*
* @param key the remote pathname for the file
* @return true if the deletion was successful, false otherwise.
* @param key
* the remote pathname for the file
* @return
* true if the deletion was successful, false otherwise.
*/
def delete(key: String): Boolean = retry {
s3.deleteObject(bucketName, sanitizeKey(key))
}.isDefined

/** Checks if the file in the location specified by `key` in the bucket exists.
* It returns false if just checking for the bucket existence.
/** Checks if the file in the location specified by `key` in the bucket exists. It returns false if just checking for
* the bucket existence.
*
* @param key the remote pathname for the file
* @return true if the file exists, false otherwise.
* @param key
* the remote pathname for the file
* @return
* true if the file exists, false otherwise.
*/
def exists(key: String): Boolean = retry {
key.nonEmpty && s3.doesObjectExist(bucketName, key)
}.getOrElse(false)

/** Checks if the location specified by `key` is a directory.
*
* @param key the remote pathname to the directory
* @return true if the path is a directory, false otherwise.
* @param key
* the remote pathname to the directory
* @return
* true if the path is a directory, false otherwise.
*/
def isDirectory(key: String): Boolean = retry {
s3.listObjects(
Expand All @@ -201,16 +221,19 @@ class S3Bucket(

/** Checks whether the bucket exists
*
* @return true if the bucket exists, false otherwise.
* @return
* true if the bucket exists, false otherwise.
*/
def bucketExists: Boolean = retry {
s3.doesBucketExistV2(bucketName)
}.getOrElse(false)

/** Sets an access control list on a given Amazon S3 object.
*
* @param key the remote pathname for the file
* @param acl the `CannedAccessControlList` to be applied to the Amazon S3 object
* @param key
* the remote pathname for the file
* @param acl
* the `CannedAccessControlList` to be applied to the Amazon S3 object
*/
def setAcl(key: String, acl: CannedAccessControlList) = {
log.info(s"Setting 's3://$bucketName/$key' permissions to '$acl'")
Expand All @@ -219,8 +242,10 @@ class S3Bucket(

/** Creates an empty directory at the given `key` location
*
* @param key the remote pathname to the directory
* @return true if the directory was created successfully, false otherwise.
* @param key
* the remote pathname to the directory
* @return
* true if the directory was created successfully, false otherwise.
*/
def createDirectory(key: String): Boolean = retry {
log.info(s"Creating directory in 's3://$bucketName/$key'")
Expand All @@ -232,11 +257,13 @@ class S3Bucket(
s3.putObject(new PutObjectRequest(bucketName, sanitizeKey(key) + "/", emptyContent, metadata))
}.isDefined

/** Backups a remote file with the given `key`. A backup consists in copying the supplied file to a backup folder under
* the same bucket and folder the file is currently in.
/** Backups a remote file with the given `key`. A backup consists in copying the supplied file to a backup folder
* under the same bucket and folder the file is currently in.
*
* @param key the remote pathname to backup
* @return true if the backup was successful, false otherwise.
* @param key
* the remote pathname to backup
* @return
* true if the backup was successful, false otherwise.
*/
def backup(key: String): Boolean = retry {
val sanitizedKey = sanitizeKey(key)
Expand All @@ -254,9 +281,12 @@ class S3Bucket(

/** Pulls a remote file with the given `key`, to the local storage in the pathname provided by `destination`.
*
* @param key the remote pathname to pull from
* @param destination the local pathname to pull to
* @return true if the pull was successful, false otherwise
* @param key
* the remote pathname to pull from
* @param destination
* the local pathname to pull to
* @return
* true if the pull was successful, false otherwise
*/
def pull(key: String, destination: String): Boolean = retry {
log.info(s"Pulling 's3://$bucketName/$key' to '$destination'")
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import spray.boilerplate.BoilerplatePlugin
ThisBuild / organization := "com.velocidi"

ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.6")
ThisBuild / scalaVersion := "2.13.6"
ThisBuild / scalaVersion := "2.13.6"

def module(project: Project, moduleName: String) =
(project in file(moduleName))
Expand Down Expand Up @@ -143,8 +143,8 @@ lazy val commonSettings = Seq(
// Enable the OrganizeImports Scalafix rule.
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.5.0"

releaseCrossBuild := true
releaseTagComment := s"Release ${(ThisBuild / version).value}"
releaseCrossBuild := true
releaseTagComment := s"Release ${(ThisBuild / version).value}"
releaseCommitMessage := s"Set version to ${(ThisBuild / version).value}"

releaseProcess := Seq[ReleaseStep](
Expand Down
Loading

0 comments on commit cf282f5

Please sign in to comment.