Skip to content

Commit

Permalink
Merge pull request #516 from codacy/add-skip-ssl-flag
Browse files Browse the repository at this point in the history
[TCE-1203] Add Skip SSL Flag
  • Loading branch information
heliocodacy authored Jan 13, 2025
2 parents 88b1d75 + 051044f commit 78da4d8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Usage: codacy-coverage-reporter report
--coverage-reports | -r <your project coverage file name (supports globs)>
--partial <if the report is partial>
--prefix <the project path prefix>
--skip-ssl-verification` [default: false] - Skip the SSL certificate verification when communicating with the Codacy API
--force-coverage-parser <your coverage parser>
Available parsers are: opencover,clover,lcov,phpunit,jacoco,dotcover,cobertura,go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.codacy.api.client

import play.api.libs.json._
import com.codacy.api.util.JsonOps
import scalaj.http.Http
import scalaj.http.{Http, HttpOptions}

import java.net.URL
import scala.util.{Failure, Success, Try}
Expand All @@ -11,7 +11,8 @@ import scala.util.control.NonFatal
class CodacyClient(
apiUrl: Option[String] = None,
apiToken: Option[String] = None,
projectToken: Option[String] = None
projectToken: Option[String] = None,
allowUnsafeSSL: Boolean = false
) {

private case class ErrorJson(error: String)
Expand All @@ -28,6 +29,8 @@ class CodacyClient(

private val remoteUrl = new URL(new URL(apiUrl.getOrElse("https://api.codacy.com")), "/2.0").toString()

private def httpOptions = if (allowUnsafeSSL) Seq(HttpOptions.allowUnsafeSSL) else Seq.empty

/*
* Does an API post
*/
Expand All @@ -44,8 +47,10 @@ class CodacyClient(

val httpRequest = timeoutOpt match {
case Some(timeout) =>
Http(url).timeout(connTimeoutMs = timeout.connTimeoutMs, readTimeoutMs = timeout.readTimeoutMs)
case None => Http(url)
Http(url)
.timeout(connTimeoutMs = timeout.connTimeoutMs, readTimeoutMs = timeout.readTimeoutMs)
.options(httpOptions)
case None => Http(url).options(httpOptions)
}

val body = httpRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ case class BaseCommandConfig(
@Name("s") @ValueDescription("skip if token isn't defined")
skip: Int @@ Counter = Tag.of(0),
@Hidden
debug: Int @@ Counter = Tag.of(0)
debug: Int @@ Counter = Tag.of(0),
@ExtraName("i") @ValueDescription(
"[default: false] - Skip the SSL certificate verification when communicating with the Codacy API"
)
skipSslVerification: Int @@ Counter = Tag.of(0)
) {
val skipValue: Boolean = skip.## > 0
val debugValue: Boolean = debug.## > 0
val skipSslVerificationValue: Boolean = skipSslVerification.## > 0
}

object ConfigArgumentParsers {
Expand Down
7 changes: 6 additions & 1 deletion src/main/scala/com/codacy/di/Components.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ class Components(private val validatedConfig: Configuration) {
(None, Some(apiToken))
}

lazy val codacyClient = new CodacyClient(Some(validatedConfig.baseConfig.codacyApiBaseUrl), apiToken, projectToken)
lazy val codacyClient = new CodacyClient(
Some(validatedConfig.baseConfig.codacyApiBaseUrl),
apiToken,
projectToken,
validatedConfig.baseConfig.skipSslVerification
)

lazy val coverageServices = new CoverageServices(codacyClient)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ case class BaseConfig(
debug: Boolean,
timeout: RequestTimeout,
sleepTime: Int,
numRetries: Int
numRetries: Int,
skipSslVerification: Boolean
)

sealed trait CommitUUID extends Any {
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/codacy/rules/ConfigurationRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class ConfigurationRules(cmdConfig: CommandConfiguration, envVars: Map[String, S
baseConfig.debugValue,
timeout = RequestTimeout(connTimeoutMs = 1000, readTimeoutMs = baseConfig.httpTimeout),
baseConfig.sleepTime,
baseConfig.numRetries
baseConfig.numRetries,
baseConfig.skipSslVerificationValue
)
validatedConfig <- validateBaseConfigUrl(baseConf)
} yield {
Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/com/codacy/rules/ReportRulesSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class ReportRulesSpec extends AnyWordSpec with Matchers with PrivateMethodTester
debug = false,
timeout = RequestTimeout(1000, 10000),
sleepTime = 10000,
numRetries = 3
numRetries = 3,
skipSslVerification = false
)

def assertCodacyCoverage(
Expand Down

0 comments on commit 78da4d8

Please sign in to comment.