-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factor accesstoken runtime-dependency wrapper out
- Loading branch information
Showing
2 changed files
with
29 additions
and
22 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
core/src/main/scala/com/microsoft/azure/synapse/ml/fabric/TokenLibrary.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in project root for information. | ||
|
||
package com.microsoft.azure.synapse.ml.fabric | ||
|
||
import scala.reflect.runtime.currentMirror | ||
import scala.reflect.runtime.universe._ | ||
object TokenLibrary { | ||
def getAccessToken: String = { | ||
val objectName = "com.microsoft.azure.trident.tokenlibrary.TokenLibrary" | ||
val mirror = currentMirror | ||
val module = mirror.staticModule(objectName) | ||
val obj = mirror.reflectModule(module).instance | ||
val objType = mirror.reflect(obj).symbol.toType | ||
val methodName = "getAccessToken" | ||
val methodSymbols = objType.decl(TermName(methodName)).asTerm.alternatives | ||
val argType = typeOf[String] | ||
val selectedMethodSymbol = methodSymbols.find { m => | ||
m.asMethod.paramLists match { | ||
case List(List(param)) => param.typeSignature =:= argType | ||
case _ => false | ||
} | ||
}.getOrElse(throw new NoSuchMethodException(s"Method $methodName with argument type $argType not found")) | ||
val methodMirror = mirror.reflect(obj).reflectMethod(selectedMethodSymbol.asMethod) | ||
methodMirror("pbi").asInstanceOf[String] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters