Skip to main content
Solved

Using Scripted parameter to return password or environment variable. fme string encoding help

  • October 5, 2021
  • 2 replies
  • 119 views

virtualcitymatt
Celebrity
Forum|alt.badge.img+47

I have a workspace which uses input user credentials to do stuff. I also want the workspace to work during testing by using System environment variables. 

This is working great for things like DBNAME, HOST, PORT etc where the user inputs are strings (text user parameters). I can simply just enter in ${PORT} for example and FME will look for a set environment variable.

 

Where I'm having trouble is with the password. I can't do the same thing for the password so I've created a simple scripted parameter which first checks if there is a user password set and if not try and see if there is an environment variable.

 

In most cases it works well, however, I've discovered that some special cahrachters are getting encoded by FME - So something like @ becomes '<at>'. 

Does anyone know a way to 'decode' these encoded strings. Ideally it'd be done in the scripted parameter, however, if it has to be done in the workspace so be it.

Short from using some kind of regex in a string replacer I'm a bit stuck.

 

For reference here's my super basic python scripted parameter:

 

import os
import fme
 
password = ''
 
userpass = fme.macroValues.get('PASSWORD', -1)
 
if userpass == '':
    password = os.getenv('ENV_PASSWORD')
if userpass == '-1':
    password = os.getenv('ENV_PASSWORD')
if userpass != -1 and userpass != '':
    password = userpass
 
return password

 

Best answer by david_r

Try something like this:

import fmeobjects
password = fmeobjects.FMESession().decodeFromFMEParsableText(userpass)

 Documentation: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_utilities/fmeobjects.FMESession.decodeFromFMEParsableText.html

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • 8391 replies
  • Best Answer
  • October 5, 2021

Try something like this:

import fmeobjects
password = fmeobjects.FMESession().decodeFromFMEParsableText(userpass)

 Documentation: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_utilities/fmeobjects.FMESession.decodeFromFMEParsableText.html


virtualcitymatt
Celebrity
Forum|alt.badge.img+47
  • Author
  • Celebrity
  • 2000 replies
  • October 5, 2021

Try something like this:

import fmeobjects
password = fmeobjects.FMESession().decodeFromFMEParsableText(userpass)

 Documentation: https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_utilities/fmeobjects.FMESession.decodeFromFMEParsableText.html

nailed it! thanks -  I found something on the community with this from Takashi from a few years ago but I was missing the () in FMESession!