Use NativeJSON from Rhino shell script - json

I'd like to use the NativeJSON class from a Rhino shell script. The only things I can find about how to use it on the Web are from Java.
// Load the configuration file
load(arguments[0]);
// Extract the configuration for the target environment
print(NativeJSON.stringify(environments[arguments[1]]));
Any clue how I'd get at it from a Rhino shell script?

The NativeJSON class is an implementation of the JSON object from ECMAScript 5, so you shouldn't need to do anything special. You can access it by calling JSON.stringify(object) or JSON.parse(jsonString).

Related

Passing sensitive information to cloud functions

Is there an "official" solution for passing sensitive information, such as API keys, to Google Cloud Functions? In particular it would be nice to avoid passing this information as arguments to the function since it will be the same for every invocation. AWS Lambda has a built-in solution using encrypted environment variables for this. Is there some similar approach for Google Cloud Functions?
I could imagine using a cloud storage bucket or cloud datastore for this, but that feels very manual.
If you're using Cloud Functions with Firebase, you're looking for environment configuration.
With that, you deploy configuration data from the Firebase CLI:
firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"
And then read it in your functions with:
functions.config().someservice.id
You can use Google Secret Manager.
https://cloud.google.com/secret-manager/docs
See this article for an example:
https://dev.to/googlecloud/using-secrets-in-google-cloud-functions-5aem
The other answers are outdated, since firebase-functions v3.18.0 the recommended way is to use secrets (like env but passed explicitly to specific functions and without .env but a remote config) : https://firebase.google.com/docs/functions/config-env?hl=en#secret-manager
Before environment variable support was released in firebase-functions v3.18.0, using functions.config() was the recommended approach for environment configuration. This approach is still supported, but we recommend all new projects use environment variables instead, as they are simpler to use and improve the portability of your code.
You can use it like this:
firebase functions:secrets:set MY_SECRET
And answer a value to the CLI.
And then in your function:
exports.processPayment = functions
// Make the secret available to this function
.runWith({ secrets: ["MY_SECRET"] })
.onCall((data, context) => {
// Now you have access to process.env.MY_SECRET
});
Few options that you can go about this:
GCP Runtime Configuration. Set up a schema that can be only accessed by your service account and put your secret there. You do that prior to your deployment. Your app should be able to use Runtime Configuration API to access these. You can use this nifty library: https://www.npmjs.com/package/#google-cloud/rcloadenv
Generate a JS on the fly including that information as part of your cloud function build/deploy and include that file as part of you cloud function.
Use Google KMS to store the keys and access it with KMS's API
As for now, there's no way to do this.
https://issuetracker.google.com/issues/35907643

Using Delphi component under C++ Builder makes calls to a wrong function

I'm trying to use Graphics32 package. Graphics32 was compiled and installed without any issue.
When I try to execute (debug) following code under C++ Builder XE3
TBitmap32* bmp = new TBitmap32();
bmp->LoadFromFile("d:\\sample.bmp");//This calls SaveToStream instead of LoadFromFile
...
it calls another member function SaveToStream which I can trace into and step while debugging until AV rises.
I have never encountered such behavior before.
Is there any compiler directive I'm missing or some workaround to make proper function call?
Update: I use the Graphics32 source from SVN. Everything works good if I use code prior to revision 2122.

Using JUnit in Jython - NameError for assertTrue

Environment Details
Mac OS X 10.9
Oracle JDK 1.7.0_55 64-bit
jython-standalone-2.5.3.jar
junit-4.11
What I have done so far
I have added the junit jar to /Library/Java/Extensions.
I invoked Jython as follows java -jar jython-standalone-2.5.3.jar
In the Jython interpreter, I imported the following import org.junit.Assert, and this import was successful.
Problem
When I tried to use assertTrue, I got a NameError in the interpreter. Why is this so?
I understand that assertTrue is a static method. Not sure what implication this has when I try to use it in Jython.
Additional Context
I am using XMLUnit in Jython. Was able to successfully import the Diff class from org.custommonkey.xmlunit in Jython. Also able to use the methods in this class, and call them on a Diff object. The result of this method call is what I am trying to pass to assertTrue, when it throws the error.
from org.custommonkey.xmlunit import Diff
import org.junit.Assert
xml1 = ...some XML string...
xml2 = ...some XML string...
myDiff = Diff(xml1, xml2)
assertTrue(myDiff.similar())
Hope this additional information is useful in identifying a solution to this problem.
Latest Status
I narrowed it down to setting this property python.security.respectJavaAccessibility = false, since the Assert() constructor is protected.
Still trying to get it to work. Any help is greatly appreciated.
Figured it out.
In addition to junit.jar file, the hamcrest-core.jar file also needed to be copied to /Library/Java/Extensions.
Then I got rid of the jython.jar file, and instead installed it using the jython installer.
After the installation was completed, I updated the registry file in the installation folder, specifically setting this property python.security.respectJavaAccessibility = false.
Now I am able to see the assertTrue method, and no longer getting a NameError.

Jenkins/Hudson job parameters at runtime?

PROBLEM
Let's say I have a jenkins/hudson job (for example free-style) that takes two parameters PARAM_ONE and PARAM_TWO. Now, I do not know the values of those parameters, but I can run some script (perl/shell) to find values of those parameters and then I want the user to select from a dropdown list after which I can start the build.
Is there any way of doing that?
Sounds like you've found a plug-in that does what you need, that is pretty similar to the built-in Parameterized Builds functionality.
To answer your second question: when you define parameterized builds, the parameters are typically passed to your job as environment variables. So you'd access them however you access environment variables in your language, for instance, if you defined a parameter PARAM_ONE, you'd access it as:
In bash:
$PARAM_ONE
In Windows batch:
%PARAM_ONE%
In Python:
import os
os.getenv('PARAM_ONE')
etc.
I imagine this would be the same for the Extended Choice Parameter plugin you are using.
Just install this, and give the parameter in the build script like:
Windows
"your build script" %PARAMONE% %PARAMTWO%
In Java, you can access these parameters off the run object
EnvVars envVars = new EnvVars();
envVars = run.getEnvironment(listener);
for (String envName2 : envVars.keySet()) {
listener.getLogger().println(envName2 + " = " + envVars.get(envName2));
}

How to configure custom ejabberd roster module?

I have to replace the standard mod_roster with my own custom roster. I wrote the module and see that it loads because it's start function is called by no other functions are called.
I also tried putting log output in all the methods of the standard mod_roster but I can't see any methods called which I log in using the Adium client.
Has anyone configured a custom roster module in ejabberd? Any ideas what I am doing wrong?
Look for {mod_roster, []}, in the ejabberd.cfg file and replace mode_roster with your module.