Skip to content

Commit

Permalink
changed: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
coutoPL committed May 19, 2019
1 parent 4f38443 commit a4ee2f6
Show file tree
Hide file tree
Showing 64 changed files with 217 additions and 205 deletions.
Expand Up @@ -14,10 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/
package tech.beshu.ror.configuration;
package tech.beshu.ror.settings;

import com.google.common.collect.ImmutableMap;
import tech.beshu.ror.settings.BasicSettings;

import java.util.Map;

Expand Down
Expand Up @@ -15,7 +15,7 @@
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/

package tech.beshu.ror.configuration;
package tech.beshu.ror.settings;


public class RorSettings {
Expand Down
19 changes: 19 additions & 0 deletions core/src/main/scala/tech/beshu/ror/RorEngine.scala
@@ -0,0 +1,19 @@
package tech.beshu.ror

import monix.eval.Task
import tech.beshu.ror.acl.factory.AsyncHttpClientsFactory
import tech.beshu.ror.acl.logging.AuditSink
import tech.beshu.ror.acl.{Acl, AclStaticContext}

object RorEngine {

def start(auditSink: AuditSink): Task[Engine] = ???
}

final class Engine(val acl: Acl, val context: AclStaticContext, httpClientsFactory: AsyncHttpClientsFactory) {
def shutdown(): Unit = {
httpClientsFactory.shutdown()
}
}


@@ -1,30 +1,15 @@
/*
* This file is part of ReadonlyREST.
*
* ReadonlyREST is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ReadonlyREST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/
package tech.beshu.ror.acl.helpers
package tech.beshu.ror

import java.time.Clock

import monix.eval.Task
import tech.beshu.ror.acl.factory.CoreFactory.AclCreationError.Reason
import tech.beshu.ror.acl.factory.{AsyncHttpClientsFactory, CoreFactory}
import tech.beshu.ror.acl.logging.{AclLoggingDecorator, AuditSink, AuditingTool}
import tech.beshu.ror.acl.utils.{JavaEnvVarsProvider, JavaUuidProvider, StaticVariablesResolver, UuidProvider}
import tech.beshu.ror.acl.utils.StaticVariablesResolver
import tech.beshu.ror.acl.{Acl, AclStaticContext}
import tech.beshu.ror.settings.SettingsMalformedException
import tech.beshu.ror.utils.{JavaEnvVarsProvider, JavaUuidProvider, UuidProvider}

object RorEngineFactory {

Expand Down Expand Up @@ -65,4 +50,5 @@ object RorEngineFactory {
}
}


}
Expand Up @@ -14,12 +14,11 @@
* You should have received a copy of the GNU General Public License
* along with ReadonlyREST. If not, see http://www.gnu.org/licenses/
*/
package tech.beshu.ror.acl.helpers
package tech.beshu.ror.acl

import cats.data._
import cats.implicits._
import org.apache.logging.log4j.scala.Logging
import tech.beshu.ror.acl.AclHandlingResult
import tech.beshu.ror.acl.AclHandlingResult.Result
import tech.beshu.ror.acl.blocks.BlockContext
import tech.beshu.ror.acl.domain.Header.Name
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/tech/beshu/ror/acl/blocks/Block.scala
Expand Up @@ -26,7 +26,7 @@ import tech.beshu.ror.acl.blocks.Block._
import tech.beshu.ror.acl.request.RequestContext
import tech.beshu.ror.acl.blocks.rules.Rule
import tech.beshu.ror.acl.blocks.rules.Rule.RuleResult
import tech.beshu.ror.acl.utils.TaskOps._
import tech.beshu.ror.utils.TaskOps._
import tech.beshu.ror.Constants.{ANSI_CYAN, ANSI_RESET, ANSI_YELLOW}
import tech.beshu.ror.acl.show.logs._

Expand Down
Expand Up @@ -22,7 +22,7 @@ import org.apache.logging.log4j.scala.Logging
import tech.beshu.ror.acl.domain
import tech.beshu.ror.acl.domain.User
import tech.beshu.ror.acl.show.logs._
import tech.beshu.ror.acl.utils.TaskOps._
import tech.beshu.ror.utils.TaskOps._

import scala.util.Success

Expand Down
Expand Up @@ -23,7 +23,7 @@ import com.unboundid.util.ssl.{SSLUtil, TrustAllTrustManager}
import monix.eval.Task
import org.apache.logging.log4j.scala.Logging
import tech.beshu.ror.acl.blocks.definitions.ldap.implementations.LdapConnectionConfig._
import tech.beshu.ror.acl.utils.ScalaOps.retry
import tech.beshu.ror.utils.ScalaOps.retry

import scala.util.control.NonFatal

Expand Down
Expand Up @@ -24,7 +24,7 @@ import tech.beshu.ror.acl.blocks.rules.Rule.AuthorizationRule
import tech.beshu.ror.acl.blocks.rules.Rule.RuleResult.{Fulfilled, Rejected}
import tech.beshu.ror.acl.domain.{Group, LoggedUser}
import tech.beshu.ror.acl.request.RequestContext
import tech.beshu.ror.acl.utils.ScalaOps._
import tech.beshu.ror.utils.ScalaOps._

abstract class BaseAuthorizationRule
extends AuthorizationRule {
Expand Down
Expand Up @@ -25,7 +25,7 @@ import tech.beshu.ror.acl.domain.Address
import tech.beshu.ror.acl.blocks.rules.Rule.RegularRule
import tech.beshu.ror.acl.blocks.{BlockContext, Value}
import tech.beshu.ror.acl.request.RequestContext
import tech.beshu.ror.acl.utils.TaskOps._
import tech.beshu.ror.utils.TaskOps._

import scala.util.Success

Expand Down
Expand Up @@ -29,7 +29,7 @@ import tech.beshu.ror.acl.blocks.{BlockContext, Value}
import tech.beshu.ror.acl.orders._
import tech.beshu.ror.acl.request.RequestContext
import tech.beshu.ror.acl.request.RequestContext.Id._
import tech.beshu.ror.acl.utils.ScalaOps._
import tech.beshu.ror.utils.ScalaOps._

import scala.collection.SortedSet

Expand Down
Expand Up @@ -29,7 +29,7 @@ import tech.beshu.ror.acl.blocks.rules.Rule.{RegularRule, RuleResult}
import tech.beshu.ror.acl.blocks.rules.SessionMaxIdleRule.Settings
import tech.beshu.ror.acl.request.RorSessionCookie.{ExtractingError, toSessionHeader}
import tech.beshu.ror.acl.request.{RequestContext, RorSessionCookie}
import tech.beshu.ror.acl.utils.UuidProvider
import tech.beshu.ror.utils.UuidProvider

import scala.concurrent.duration.FiniteDuration

Expand Down
Expand Up @@ -41,10 +41,11 @@ import tech.beshu.ror.acl.orders._
import tech.beshu.ror.acl.show.logs._
import tech.beshu.ror.acl.utils.CirceOps.DecoderHelpers.FieldListResult.{FieldListValue, NoField}
import tech.beshu.ror.acl.utils.CirceOps.{DecoderHelpers, DecodingFailureOps}
import tech.beshu.ror.acl.utils.ScalaOps._
import tech.beshu.ror.utils.ScalaOps._
import tech.beshu.ror.acl.utils._
import tech.beshu.ror.acl.{Acl, AclStaticContext, SequentialAcl}
import tech.beshu.ror.acl.utils.CirceOps._
import tech.beshu.ror.utils.{UuidProvider, YamlOps}

import scala.language.implicitConversions
import scala.util.{Failure, Success, Try}
Expand Down
Expand Up @@ -38,7 +38,7 @@ import tech.beshu.ror.acl.factory.HttpClientsFactory
import tech.beshu.ror.acl.orders._
import tech.beshu.ror.acl.refined._
import tech.beshu.ror.acl.utils.CirceOps._
import tech.beshu.ror.acl.utils.ScalaOps._
import tech.beshu.ror.utils.ScalaOps._
import tech.beshu.ror.acl.utils.SyncDecoderCreator

import scala.concurrent.duration._
Expand Down
Expand Up @@ -24,7 +24,7 @@ import tech.beshu.ror.acl.factory.decoders.definitions.Definitions.Item
import tech.beshu.ror.acl.utils.ADecoder
import tech.beshu.ror.acl.utils.CirceOps.DecoderHelpers
import tech.beshu.ror.acl.utils.CirceOps.DecoderHelpers.FieldListResult.{FieldListValue, NoField}
import tech.beshu.ror.acl.utils.ScalaOps._
import tech.beshu.ror.utils.ScalaOps._

object DefinitionsBaseDecoder {

Expand Down
Expand Up @@ -24,7 +24,7 @@ import tech.beshu.ror.acl.blocks.rules.Rule.AuthenticationRule
import tech.beshu.ror.acl.blocks.rules._
import tech.beshu.ror.acl.factory.decoders.definitions.{Definitions, DefinitionsPack}
import tech.beshu.ror.acl.factory.decoders.rules._
import tech.beshu.ror.acl.utils.UuidProvider
import tech.beshu.ror.utils.UuidProvider

import scala.language.implicitConversions

Expand Down
Expand Up @@ -23,8 +23,8 @@ import tech.beshu.ror.acl.blocks.rules.SessionMaxIdleRule.Settings
import tech.beshu.ror.acl.factory.CoreFactory.AclCreationError.RulesLevelCreationError
import tech.beshu.ror.acl.factory.decoders.common
import tech.beshu.ror.acl.factory.decoders.rules.RuleBaseDecoder.RuleDecoderWithoutAssociatedFields
import tech.beshu.ror.acl.utils.UuidProvider
import tech.beshu.ror.acl.utils.CirceOps._
import tech.beshu.ror.utils.UuidProvider

class SessionMaxIdleRuleDecoder(implicit clock: Clock, uuidProvider: UuidProvider)
extends RuleDecoderWithoutAssociatedFields(
Expand Down
Expand Up @@ -26,7 +26,7 @@ import tech.beshu.ror.acl.AclHandlingResult.Result
import tech.beshu.ror.acl.blocks.Block.Verbosity
import tech.beshu.ror.acl.logging.ResponseContext._
import tech.beshu.ror.acl.request.RequestContext
import tech.beshu.ror.acl.utils.TaskOps._
import tech.beshu.ror.utils.TaskOps._
import tech.beshu.ror.acl.{Acl, AclHandlingResult}
import tech.beshu.ror.acl.show.logs._

Expand Down
Expand Up @@ -28,10 +28,10 @@ import org.apache.logging.log4j.scala.Logging
import io.circe.parser._
import io.circe.{Decoder, Encoder}
import tech.beshu.ror.acl.request.RorSessionCookie.ExtractingError.{Absent, Expired, Invalid}
import tech.beshu.ror.acl.utils.UuidProvider
import tech.beshu.ror.acl.domain.{Header, LoggedUser, User}
import tech.beshu.ror.acl.domain.Header.Name.setCookie
import tech.beshu.ror.acl.show.logs._
import tech.beshu.ror.utils.UuidProvider

import scala.collection.JavaConverters._
import scala.util.Try
Expand Down
Expand Up @@ -24,6 +24,7 @@ import monix.eval.Task
import tech.beshu.ror.acl.factory.CoreFactory.AclCreationError
import tech.beshu.ror.acl.factory.CoreFactory.AclCreationError.Reason
import tech.beshu.ror.acl.utils.CirceOps._
import tech.beshu.ror.utils.YamlOps

import scala.annotation.tailrec
import scala.language.{higherKinds, implicitConversions}
Expand Down
Expand Up @@ -23,7 +23,7 @@ import monix.eval.Task

import scala.concurrent.duration.FiniteDuration
import scala.util.Success
import TaskOps._
import tech.beshu.ror.utils.TaskOps._
import scala.concurrent.ExecutionContext._

class CacheableAction[K, V](ttl: FiniteDuration Refined Positive,
Expand Down
27 changes: 0 additions & 27 deletions core/src/main/scala/tech/beshu/ror/acl/utils/ScalaJavaHelper.scala

This file was deleted.

Expand Up @@ -16,7 +16,7 @@
*/
package tech.beshu.ror.acl.utils

import scala.util.Try
import tech.beshu.ror.utils.EnvVarsProvider

class StaticVariablesResolver(envVarsProvider: EnvVarsProvider) {

Expand Down Expand Up @@ -63,12 +63,3 @@ class StaticVariablesResolver(envVarsProvider: EnvVarsProvider) {
}

}

trait EnvVarsProvider {
def getEnv(name: String): Option[String]
}

object JavaEnvVarsProvider extends EnvVarsProvider {
override def getEnv(name: String): Option[String] =
Try(Option(System.getenv(name))).toOption.flatten
}
33 changes: 0 additions & 33 deletions core/src/main/scala/tech/beshu/ror/acl/utils/YamlOps.scala

This file was deleted.

@@ -0,0 +1,8 @@
package tech.beshu.ror.configuration

import monix.eval.Task

trait ConfigLoader {

def load(): Task[RawRorConfig]
}
@@ -0,0 +1,8 @@
package tech.beshu.ror.configuration

import monix.eval.Task
import tech.beshu.ror.utils.EnvVarsProvider

class FileConfigLoader(envVarsProvider: EnvVarsProvider) extends ConfigLoader {
override def load(): Task[RawRorConfig] = ???
}
@@ -0,0 +1,7 @@
package tech.beshu.ror.configuration

import monix.eval.Task

class IndexConfigLoader extends ConfigLoader {
override def load(): Task[RawRorConfig] = ???
}
@@ -0,0 +1,24 @@
package tech.beshu.ror.configuration

import org.yaml.snakeyaml.Yaml
import tech.beshu.ror.acl.factory.CoreFactory.AclCreationError.Reason.Message
import tech.beshu.ror.acl.factory.CoreFactory.AclCreationError.{ReadonlyrestSettingsCreationError, UnparsableYamlContent}
import tech.beshu.ror.acl.factory.CoreFactory.{AclCreationError, Attributes}

import scala.util.{Failure, Success, Try}

final case class RawRorConfig private (validatedRorYaml: String) {

private def trimToRorPartOnly(settingsYamlString: String): Either[AclCreationError, String] = {
val yaml = new Yaml()
Try(yaml.load[java.util.Map[String, Object]](settingsYamlString)) match {
case Success(map) =>
Option(map.get("readonlyrest")).map(yaml.dump) match { // todo: "readonlyrest" from const
case Some(value) => Right(value)
case None => Left(ReadonlyrestSettingsCreationError(Message(s"No ${"readonlyrest"} section found"))) // fixme:
}
case Failure(ex) =>
Left(UnparsableYamlContent(Message(s"Malformed: $settingsYamlString")))
}
}
}
12 changes: 12 additions & 0 deletions core/src/main/scala/tech/beshu/ror/utils/EnvVarsProvider.scala
@@ -0,0 +1,12 @@
package tech.beshu.ror.utils

import scala.util.Try

trait EnvVarsProvider {
def getEnv(name: String): Option[String]
}

object JavaEnvVarsProvider extends EnvVarsProvider {
override def getEnv(name: String): Option[String] =
Try(Option(System.getenv(name))).toOption.flatten
}

0 comments on commit a4ee2f6

Please sign in to comment.