Skip to content

Commit

Permalink
Changing some parameter to Option and then removing unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
saileshbaidya committed Sep 28, 2023
1 parent 14cf664 commit bd35087
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class InvalidJwtTokenException(message: String) extends Exception(message)
class JwtTokenExpiryMissingException(message: String) extends Exception(message)
class FabricTokenParser(JWToken: String) {
private val tokens: Array[String] = JWToken.split("\\.")
private val parsedToken: JsValue = tokenCheckAndDecode(tokens)
private val parsedToken: JsValue = tokenCheckAndDecode(Some(tokens))
def getExpiry: Long ={
val exp: Option[Long] = parsedToken.asJsObject.fields.get("exp").collect { case JsNumber(value) => value.toLong }
exp match {
Expand All @@ -21,18 +21,23 @@ class FabricTokenParser(JWToken: String) {
}
}

private def tokenCheckAndDecode(tokens: Array[String]): JsValue ={
if (tokens.length == 3) {
// Getting the JWT payload which is second member of [header].[payload].[signature]
val payload = tokens(1)
// Removing whitespace and url safe characters encoded that might have been added to token
val sanitizedPayload = payload.replace('-', '+').replace('_', '/').replaceAll("\\.", "").replaceAll("\\s", "")
val decodedPayload = java.util.Base64.getDecoder.decode(sanitizedPayload)
val decodedJson = new String(decodedPayload)
decodedJson.parseJson
}
else {
throw new InvalidJwtTokenException(s"Invalid JWT token. Here is the token = {$JWToken}")
private def tokenCheckAndDecode(tokens: Option[Array[String]]): JsValue ={
tokens match {
case Some(tokens) =>
if (tokens.length == 3) {
// Getting the JWT payload which is second member of [header].[payload].[signature]
val payload = tokens(1)
// Removing whitespace and url safe characters encoded that might have been added to token
val sanitizedPayload = payload.replace('-', '+').replace('_', '/').replaceAll("\\.", "").replaceAll("\\s", "")
val decodedPayload = java.util.Base64.getDecoder.decode(sanitizedPayload)
val decodedJson = new String(decodedPayload)
decodedJson.parseJson
}
else {
throw new InvalidJwtTokenException(s"Invalid JWT token. Here is the token = {$JWToken}")
}
case None =>
throw new NullPointerException("Invalid JWT token used for reporting usage data.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ object UsageTelemetry extends FabricConstants with WebUtils {
private lazy val PbiEnv = SC.getConf.get("spark.trident.pbienv", "").toLowerCase()

private lazy val SharedHost = getMlflowSharedHost(PbiEnv)
private val SharedEndpoint = f"{SharedHost}/metadata/workspaces/{WorkspaceId}/artifacts"
private val WlHost = getMlflowWorkloadHost(PbiEnv, CapacityId, WorkspaceId, Some(SharedHost))

def reportUsage(payload: FeatureUsagePayload): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.microsoft.azure.synapse.ml.logging.common

import com.microsoft.azure.synapse.ml.io.http.RESTHelpers
import com.microsoft.azure.synapse.ml.logging.SynapseMLLogging
import org.apache.commons.io.IOUtils
import org.apache.http.client.methods.{CloseableHttpResponse, HttpGet, HttpPost}
import org.apache.http.entity.StringEntity
Expand Down

0 comments on commit bd35087

Please sign in to comment.