Importing Credentials into a Repository for External Transform is Failing

I am looking to pass in public/private keys into an external transform. I’ve added the credentials to my repository, i’ve added the decorator that specifies i’m passing in credentials in an external transform. At runtime when I call .get() on the credentials, I’m seeing the following error in the logs. Any clue what is going on? It would appear to be an issue in an underlying library that Foundry calls

An error occurred while calling o2.loadClass.
: java.lang.ClassNotFoundException: com.palantir.foundry.credential.api.OneTimeAccessKeyServiceBlocking

Hey @kkarg,
Can you provide the code snippet where you are trying to access the credentials? Note that you e.g. cannot access the credentials in a UDF.
Also, just in case, can you please make sure that the repository is upgraded to the most recent version?

Sure thing! Here’s the code that I’m calling, you’re correct that I’m trying to access credentials in a UDF. Let me know if you think that’s still the source of the issue. and I’ll try constructing the credentials variable outside of the UDF

    @udf(returnType=StringType())
    def reactivate_token(access_token_state, refresh_token):
        privateKey = flexpaCredentials.get("PrivateKey")
        publicKey = flexpaCredentials.get("PublicKey")
        if access_token_state == False and refresh_token:
            credentials = f"{publicKey}:{privateKey}"
            encoded_credentials = base64.b64encode(credentials.encode()).decode()
            headers = {
                "Authorization": f"Basic {encoded_credentials}",
                "Content-Type": "application/x-www-form-urlencoded",
            }
            body = {"grant_type": "refresh_token", "refresh_token": refresh_token}
            return requests.get(
                "https://api.flexpa.com/link/token",
                headers=headers,
                data=body,
                timeout=10,
            ).text

    subscribers = subscribers[["uuid", "flexpa_access_token", "flexpa_refresh_token"]]
    subscribers = subscribers.filter(subscribers.flexpa_access_token.isNotNull())
    subscribers = subscribers.withColumn(
        "access_token_is_valid", active_token(subscribers.flexpa_access_token)
    )

    subscribers = subscribers.withColumn(
        "refresh_call",
        reactivate_token(
            subscribers.flexpa_access_token, subscribers.flexpa_refresh_token
        ),
    )
I am looking to pass in public/private keys into an external transform. I've added the credentials to my repository, i've added the decorator that specifies i'm passing in credentials in an external transform. At runtime when I call .get() on the credentials, I'm seeing the following error in the logs. Any clue what is going on? It would appear to be an issue in an underlying library that Foundry calls

An error occurred while calling o2.loadClass.
: java.lang.ClassNotFoundException: com.palantir.foundry.credential.api.OneTimeAccessKeyServiceBlocking

Yup, that won’t work. You need to pass the credentials as an argument to reactivate_token, e.g. by updating it to def reactivate_token(access_token_state, refresh_token, privateKey, publicKey) and pass them via F.lit(privateKey). Let me know if that resolves your issue or if it still doesn’t work.

Thanks for the help, that solved it! I appreciate it.

1 Like