Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F82717546
MetaDataService.scala
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 13, 01:31
Size
1 KB
Mime Type
text/x-c++
Expires
Sun, Sep 15, 01:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20737287
Attached To
R2664 SHRINE MedCo Fork
MetaDataService.scala
View Options
import akka.actor.{Actor, ActorRefFactory}
import com.typesafe.config.ConfigRenderOptions
import net.shrine.log.Loggable
import net.shrine.source.ConfigSource
import spray.http.{StatusCode, StatusCodes}
import spray.routing.{HttpService, Route}
import scala.util.Try
/**
* A super simple API that provides access to the MetaData section of SHRINE's configuration
*/
class MetaDataActor extends Actor with MetaDataService {
override def receive: Receive = runRoute(route)
override def actorRefFactory: ActorRefFactory = context
}
trait MetaDataService extends HttpService with Loggable {
lazy val config = MetaConfigSource.config.getConfig("shrine.metaData")
lazy val route: Route = get {
pathPrefix("ping") { complete("pong")} ~
pathPrefix("data") {
parameter("key") { (key: String) =>
complete(handleKey(key))
} ~ complete(handleAll)
}}
def handleAll:(StatusCode, String) = {
StatusCodes.OK -> config.root.render(ConfigRenderOptions.concise())
}
def handleKey(key: String): (StatusCode, String) = {
Try(StatusCodes.OK -> config.getValue(key).render(ConfigRenderOptions.concise()))
.getOrElse(StatusCodes.NotFound ->
s"Could not find a value for the specified path `$key`")
}
}
object MetaConfigSource extends ConfigSource
Event Timeline
Log In to Comment