Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/typos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Spell check with typos

on:
push:
branches: ["main"]
pull_request:
branches: ["**"]

permissions: {}

jobs:
typos:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Run typos
uses: crate-ci/typos@d43b6c087ac471e2ea7b8af622ff15f05c0c365b # v1.50.1

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ buildx-machine:
docker buildx create --name=$(MACHINE) --platform=$(DEFAULT_PLATFORMS)

test-image:
# Instead of loading image, target all platforms, effectivelly testing
# Instead of loading image, target all platforms, effectively testing
# the build for the target architectures.
$(MAKE) build-image BUILD_ACTION="--platform=$(TARGET_PLATFORMS)"

Expand Down
66 changes: 66 additions & 0 deletions admin/src/main/scala/com/neu/core/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.neu.web.StaticResources
import com.typesafe.config.{ Config, ConfigValueFactory }
import com.typesafe.config.ConfigFactory.*
import com.typesafe.scalalogging.LazyLogging
import org.apache.log4j.PropertyConfigurator
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.ConnectionContext
import org.apache.pekko.http.scaladsl.Http
Expand All @@ -14,6 +15,7 @@ import org.apache.pekko.http.scaladsl.server.Route
import org.apache.pekko.http.scaladsl.settings.ServerSettings
import org.apache.pekko.stream.Materializer

import java.util.Properties
import scala.concurrent.ExecutionContextExecutor
import scala.concurrent.Future

Expand All @@ -31,11 +33,75 @@ trait BootedCore
given materializer: Materializer = Materializer(system)
given executionContext: ExecutionContextExecutor = system.dispatcher

private def configureLog4j(): Unit = {
val logFormat = sys.env.getOrElse("NV_LOG_FORMAT", "string").trim.toLowerCase
val layoutClass = logFormat match {
case "json" => "net.logstash.log4j.JSONEventLayoutV1"
case "string" | "plain" => "org.apache.log4j.PatternLayout"
case _ =>
logger.warn(s"Unsupported NV_LOG_FORMAT=$logFormat; defaulting to string format")
"org.apache.log4j.PatternLayout"
}
val pattern = "%d{yyyy-MM-dd HH:mm:ss,SSS}|%-5p|%c|%m%n"
val props = new Properties()
val stream = Option(getClass.getClassLoader.getResourceAsStream("log4j.properties"))
stream.foreach { in =>
props.load(in)
in.close()
}

props.setProperty("log4j.rootLogger", "INFO, stdout")
props.setProperty("log4j.appender.stdout.layout", layoutClass)
if (layoutClass == "org.apache.log4j.PatternLayout") {
props.setProperty("log4j.appender.stdout.layout.ConversionPattern", pattern)
} else {
props.remove("log4j.appender.stdout.layout.ConversionPattern")
}

props.setProperty("log4j.appender.adminAppender.layout", layoutClass)
if (layoutClass == "org.apache.log4j.PatternLayout") {
props.setProperty("log4j.appender.adminAppender.layout.ConversionPattern", pattern)
} else {
props.remove("log4j.appender.adminAppender.layout.ConversionPattern")
}

props.setProperty("log4j.appender.kafkaAppender.layout", layoutClass)
if (layoutClass == "org.apache.log4j.PatternLayout") {
props.setProperty("log4j.appender.kafkaAppender.layout.ConversionPattern", pattern)
} else {
props.remove("log4j.appender.kafkaAppender.layout.ConversionPattern")
}

props.setProperty("log4j.appender.pekkoAppender.layout", layoutClass)
if (layoutClass == "org.apache.log4j.PatternLayout") {
props.setProperty("log4j.appender.pekkoAppender.layout.ConversionPattern", pattern)
} else {
props.remove("log4j.appender.pekkoAppender.layout.ConversionPattern")
}

props.setProperty("log4j.appender.sourceAppender.layout", layoutClass)
if (layoutClass == "org.apache.log4j.PatternLayout") {
props.setProperty("log4j.appender.sourceAppender.layout.ConversionPattern", pattern)
} else {
props.remove("log4j.appender.sourceAppender.layout.ConversionPattern")
}

props.setProperty("log4j.appender.sinkAppender.layout", layoutClass)
if (layoutClass == "org.apache.log4j.PatternLayout") {
props.setProperty("log4j.appender.sinkAppender.layout.ConversionPattern", pattern)
} else {
props.remove("log4j.appender.sinkAppender.layout.ConversionPattern")
}

PropertyConfigurator.configure(props)
}

private val rootService: Route = routes ~ staticResources

IpGeoManager
CisNISTManager
System.setProperty("net.sf.ehcache.enableShutdownHook", "true")
configureLog4j()

private val useSSL: String = sys.env.getOrElse("MANAGER_SSL", "on")
private val httpMaxHeaderLength: String = sys.env.getOrElse("HTTP_MAX_HEADER_LENGTH", "32k")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ case class PolicyOutput(
applicationsInPolicy: List[(String, Int)]
)
/*=========================================
For new dashbaord API
For new dashboard API
=========================================*/
case class DashboardNotificationDTO(
criticalSecurityEvents: CriticalSecurityEventDTO,
Expand Down Expand Up @@ -945,7 +945,7 @@ object DashboardJsonProtocol extends DefaultJsonProtocol with LazyLogging {
)

/*=========================================
For new dashbaord API
For new dashboard API
=========================================*/

given podFormat: RootJsonFormat[Pod] = jsonFormat7(Pod.apply)
Expand Down
36 changes: 26 additions & 10 deletions admin/src/main/scala/com/neu/model/SystemConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,38 @@ package com.neu.model
/**
* Created by bxu on 4/28/16.
*/
case class RegistyHttpProxy(url: String, username: String, password: Option[String])
case class RegistyHttpsProxy(url: String, username: String, password: Option[String])
case class RegistyHttpProxyCfg(
case class RegistryHttpProxy(url: String, username: String, password: Option[String])
case class RegistryHttpsProxy(url: String, username: String, password: Option[String])
case class RegistryHttpProxyCfg(
url: Option[String],
username: Option[String],
password: Option[String]
)
case class RegistyHttpsProxyCfg(
case class RegistryHttpsProxyCfg(
url: Option[String],
username: Option[String],
password: Option[String]
)
case class Webhook(
name: String,
url: String,
enable: Boolean,
use_proxy: Boolean,
`type`: String,
cfg_type: String,
username: Option[String] = None,
password: Option[String] = None
)

case class MaskedWebhook(
name: String,
url: String,
enable: Boolean,
use_proxy: Boolean,
`type`: String,
cfg_type: String
)

case class RemoteRepository(
nickname: String,
provider: String,
Expand Down Expand Up @@ -71,8 +83,8 @@ case class SystemConfig(
webhooks: Option[Array[Webhook]] = None,
cluster_name: Option[String] = None,
auth_by_platform: Option[Boolean] = None,
registry_http_proxy: Option[RegistyHttpProxy] = None,
registry_https_proxy: Option[RegistyHttpsProxy] = None,
registry_http_proxy: Option[RegistryHttpProxy] = None,
registry_https_proxy: Option[RegistryHttpsProxy] = None,
registry_http_proxy_status: Option[Boolean] = None,
registry_https_proxy_status: Option[Boolean] = None,
xff_enabled: Option[Boolean] = None,
Expand Down Expand Up @@ -128,10 +140,10 @@ case class SystemConfigAuthCfgV2(
case class SystemConfigProxyCfgV2(
registry_http_proxy_status: Option[Boolean] = None,
registry_https_proxy_status: Option[Boolean] = None,
registry_http_proxy: Option[RegistyHttpProxy] = None,
registry_https_proxy: Option[RegistyHttpsProxy] = None,
registry_http_proxy_cfg: Option[RegistyHttpProxyCfg] = None,
registry_https_proxy_cfg: Option[RegistyHttpsProxyCfg] = None
registry_http_proxy: Option[RegistryHttpProxy] = None,
registry_https_proxy: Option[RegistryHttpsProxy] = None,
registry_http_proxy_cfg: Option[RegistryHttpProxyCfg] = None,
registry_https_proxy_cfg: Option[RegistryHttpsProxyCfg] = None
)

case class SystemConfigIBMSAVCfg2(
Expand Down Expand Up @@ -186,6 +198,10 @@ case class WebhookConfigWrap(
config: Webhook
)

case class MaskedWebhookConfigWrap(
config: MaskedWebhook
)

case class SystemConfig4DashboardWrap(
config: SystemConfig4Dashboard,
error: Option[Error]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import spray.json.*
*/
object SystemConfigJsonProtocol extends DefaultJsonProtocol {
given errorFormat: RootJsonFormat[Error] = jsonFormat1(Error.apply)
given registyHttpsProxyFormat: RootJsonFormat[RegistyHttpsProxy] = jsonFormat3(
RegistyHttpsProxy.apply
given registryHttpsProxyFormat: RootJsonFormat[RegistryHttpsProxy] = jsonFormat3(
RegistryHttpsProxy.apply
)
given registyHttpProxyFormat: RootJsonFormat[RegistyHttpProxy] = jsonFormat3(
RegistyHttpProxy.apply
given registryHttpProxyFormat: RootJsonFormat[RegistryHttpProxy] = jsonFormat3(
RegistryHttpProxy.apply
)
given registyHttpsProxyCfgFormat: RootJsonFormat[RegistyHttpsProxyCfg] = jsonFormat3(
RegistyHttpsProxyCfg.apply
given registryHttpsProxyCfgFormat: RootJsonFormat[RegistryHttpsProxyCfg] = jsonFormat3(
RegistryHttpsProxyCfg.apply
)
given registyHttpProxyCfgFormat: RootJsonFormat[RegistyHttpProxyCfg] = jsonFormat3(
RegistyHttpProxyCfg.apply
given registryHttpProxyCfgFormat: RootJsonFormat[RegistryHttpProxyCfg] = jsonFormat3(
RegistryHttpProxyCfg.apply
)
given githubConfigurationFormat: RootJsonFormat[GithubConfiguration] = jsonFormat6(
GithubConfiguration.apply
)
given azureDevopsConfigurationFormat: RootJsonFormat[AzureDevopsConfiguration] = jsonFormat5(
AzureDevopsConfiguration.apply
)
given webhookFormat: RootJsonFormat[Webhook] = jsonFormat6(Webhook.apply)
given webhookFormat: RootJsonFormat[Webhook] = jsonFormat8(Webhook.apply)
given remoteRepoFormat: RootJsonFormat[RemoteRepository] = jsonFormat6(RemoteRepository.apply)
given remoteRepositoryWrapFormat: RootJsonFormat[RemoteRepositoryWrap] = jsonFormat1(
RemoteRepositoryWrap.apply
Expand All @@ -52,6 +52,11 @@ object SystemConfigJsonProtocol extends DefaultJsonProtocol {
WebhookConfigWrap.apply
)

given MaskedWebhookFormat: RootJsonFormat[MaskedWebhook] = jsonFormat6(MaskedWebhook.apply)
given MaskedWebhookConfigWrapFormat: RootJsonFormat[MaskedWebhookConfigWrap] = jsonFormat1(
MaskedWebhookConfigWrap.apply
)

given systemConfigSvcCfgV2Format: RootJsonFormat[SystemConfigSvcCfgV2] = jsonFormat3(
SystemConfigSvcCfgV2.apply
)
Expand Down Expand Up @@ -104,6 +109,9 @@ object SystemConfigJsonProtocol extends DefaultJsonProtocol {
def webhookConfigWrapToJson(webhookConfigWrap: WebhookConfigWrap): String =
webhookConfigWrap.toJson.compactPrint

def maskedWebhookConfigWrapToJson(maskedWebhookConfigWrap: MaskedWebhookConfigWrap): String =
maskedWebhookConfigWrap.toJson.compactPrint

def remoteRepositoryToJson(remoteRepository: RemoteRepository): String =
remoteRepository.toJson.compactPrint

Expand Down
2 changes: 1 addition & 1 deletion admin/src/main/scala/com/neu/service/Services.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object Utils extends LazyLogging with Directives {
* bit1 bit2 bit3 bit4
* ----------------------------------------------------------------------------------------------------------------------------
* Supplemental bit 1 ONLY env MANAGER_SSL on: 1 Request static resources env IS_DEV == true or
* NOT requset js files off: 0 true: 1 true: 1 (undefined): 0 false: 0 false: 0
* NOT request js files off: 0 true: 1 true: 1 (undefined): 0 false: 0 false: 0
*/
val headerConfigMapKey: Short =
(1000 + isUsingSSLBit * 100 + isStaticResourceBit * 10 + isDevOrNotJsBit).toShort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OpenIdAuthService()(implicit
} else {
Await
.result(
handleExistingResoureces(code, state, ip, host, nonce),
handleExistingResources(code, state, ip, host, nonce),
RestClient.waitingLimit.seconds
)
}
Expand Down Expand Up @@ -105,7 +105,7 @@ class OpenIdAuthService()(implicit
}
}

private def handleExistingResoureces(
private def handleExistingResources(
code: Option[String],
state: Option[String],
ip: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ class DashboardService()(implicit executionContext: ExecutionContext)
)
logger.debug("Got {}", dashboardScoreDTO)
val endTime = new DateTime()
logger.info("Dashbaord scores - End: {}", endTime)
logger.info("Dashboard scores - End: {}", endTime)
logger.info(
"Dashbaord scores - Calculation Duration: {}",
"Dashboard scores - Calculation Duration: {}",
endTime.getMillis - calculationStartTime.getMillis
)
logger.info(
"Dashbaord scores - Duration: {}",
"Dashboard scores - Duration: {}",
endTime.getMillis - startTime.getMillis
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,21 @@ class DeviceService extends Directives with DefaultJsonFormats with LazyLogging
}

def updateWebhook(tokenId: String, webhook: Webhook, scope: Option[String]): Route = complete {
val printedPayload = maskedWebhookConfigWrapToJson(
MaskedWebhookConfigWrap(
MaskedWebhook(
name = webhook.name,
url = webhook.url,
enable = webhook.enable,
use_proxy = webhook.use_proxy,
`type` = webhook.`type`,
cfg_type = webhook.cfg_type
)
)
)
logger.info("Update config: {}", printedPayload)

val payload = webhookConfigWrapToJson(WebhookConfigWrap(webhook))
logger.info("Update config: {}", payload)

RestClient.httpRequestWithHeader(
scope.fold(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ class PolicyService() extends BaseService with DefaultJsonFormats with LazyLoggi
}

def addAdmissionRules(tokenId: String, admissionRuleConfig: AdmRuleConfig): Route = complete {
logger.info("Adding addmission rule: {}", admissionRuleConfig)
logger.info("Adding admission rule: {}", admissionRuleConfig)
logger.info(
"config in json: {}",
admissionRuleConfigToJson(admissionRuleConfig)
Expand All @@ -867,7 +867,7 @@ class PolicyService() extends BaseService with DefaultJsonFormats with LazyLoggi
}

def updateAdmissionRule(tokenId: String, admissionRuleConfig: AdmRuleConfig): Route = complete {
logger.info("Updating addmission rule: {}", admissionRuleConfig)
logger.info("Updating admission rule: {}", admissionRuleConfig)
logger.info(
"config in json: {}",
admissionRuleConfigToJson(admissionRuleConfig)
Expand Down
2 changes: 1 addition & 1 deletion admin/test/REST_API/test_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ base_url="https://127.0.0.1:8443"
file="${inputDir}/test_data.properties"

function start_test {
#Variables initialzation
#Variables initialization

#Remove all output files
rm -f ${outputDir}
Expand Down
Loading
Loading