Skip to content

Commit

Permalink
Merge pull request #12 from praveenkumarb1207/master
Browse files Browse the repository at this point in the history
fixed hidden params to hide user and password - issue #6
  • Loading branch information
mantovani authored Jun 15, 2021
2 parents 587f3eb + e9f8218 commit cdd7749
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ object Alias {
private[almaren] case class HTTP(
headers: Map[String, String],
params: Map[String, String],
hiddenParams: Map[String, String],
method: String,
requestHandler: (Row, Session, String, Map[String, String], Map[String, String], String, Int, Int) => requests.Response,
session: () => requests.Session,
Expand Down Expand Up @@ -72,7 +73,7 @@ private[almaren] case class HTTP(
private def request(row:Row, session:Session): Response = {
val url = row.getAs[Any](Alias.UrlCol).toString()
val startTime = System.currentTimeMillis()
val response = Try(requestHandler(row,session,url,headers,params,method,connectTimeout,readTimeout))
val response = Try(requestHandler(row,session,url,headers,params ++ hiddenParams,method,connectTimeout,readTimeout))
val elapsedTime = System.currentTimeMillis() - startTime
val id = row.getAs[Any](Alias.IdCol).toString()
response match {
Expand All @@ -96,6 +97,7 @@ private[almaren] case class HTTPBatch(
url: String,
headers: Map[String, String],
params: Map[String, String],
hiddenParams: Map[String, String],
method: String,
requestHandler: (String, Session, String, Map[String, String], Map[String, String], String, Int, Int) => requests.Response,
session: () => requests.Session,
Expand Down Expand Up @@ -142,7 +144,7 @@ private[almaren] case class HTTPBatch(
}

private def request(data:String, session:Session): requests.Response =
requestHandler(data,session,url,headers,params,method,connectTimeout,readTimeout)
requestHandler(data,session,url,headers,params ++ hiddenParams,method,connectTimeout,readTimeout)


}
Expand All @@ -152,6 +154,7 @@ private[almaren] trait HTTPConnector extends Core {
def http(
headers: Map[String, String] = Map(),
params: Map[String, String] = Map(),
hiddenParams: Map[String, String] = Map(),
method: String,
requestHandler: (Row, Session, String, Map[String, String], Map[String, String], String, Int, Int) => requests.Response = HTTPConn.defaultHandler,
session: () => requests.Session = HTTPConn.defaultSession,
Expand All @@ -162,6 +165,7 @@ private[almaren] trait HTTPConnector extends Core {
HTTP(
headers,
params,
hiddenParams,
method,
requestHandler,
session,
Expand All @@ -175,6 +179,7 @@ private[almaren] trait HTTPConnector extends Core {
url: String,
headers: Map[String, String] = Map(),
params: Map[String, String] = Map(),
hiddenParams: Map[String, String] = Map(),
method: String,
requestHandler: (String, Session, String, Map[String, String], Map[String, String], String, Int, Int) => requests.Response = HTTPConn.defaultHandlerBatch,
session: () => requests.Session = HTTPConn.defaultSession,
Expand All @@ -187,6 +192,7 @@ private[almaren] trait HTTPConnector extends Core {
url,
headers,
params,
hiddenParams,
method,
requestHandler,
session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Test extends FunSuite with BeforeAndAfter {
val tempDf = if (isSession) {
almaren.builder
.sourceSql(query).alias("PERSON_DATA")
.http(method = methodType, session = newSession)
.http(params = Map("username" -> "sample"),hiddenParams = Map("username" -> "sample","password" -> "sample"),method = methodType, session = newSession)
}
else {
almaren.builder
Expand Down Expand Up @@ -100,6 +100,8 @@ class Test extends FunSuite with BeforeAndAfter {
.sqlExpr("to_json(struct(*)) as __DATA__", "monotonically_increasing_id() as __ID__").alias("BATCH_DATA")
.httpBatch(
url = "http://127.0.0.1:3000/batchAPI",
params = Map("username" -> "sample"),
hiddenParams = Map("username" -> "sample","password" -> "sample"),
method = "POST",
batchSize = 3,
batchDelimiter = (rows: Seq[Row]) => s"""[${rows.map(row => row.getAs[String](Alias.DataCol)).mkString(",")}]""")
Expand Down

0 comments on commit cdd7749

Please sign in to comment.