Simple auth addon seems to not be reading env config - ember-cli

I am following the example here, and I have this in my config/environment.js file:
ENV['simple-auth'] = {
authorizer: 'simple-auth-authorizer:devise',
routeAfterAuthentication: 'landing-pages'
};
However, after my app authenticates it tries to go to the index route. I confirmed the configuration variable used had index as the routeAfterAuthentication property by adding a breakpoint in the sessionAuthenticationSucceeded method of the library.
I tried importing the configuration in the environment.js file ES6-style, but that doesn't seem possible.

Ember Simple Auth actually still relies on the window.ENV configuration variable, so you'll need to add it to your configuration. Do it like this:
window.MyAppENV = {{ENV}};
+ window.ENV = window.MyAppENV;
window.EmberENV = window.MyAppENV.EmberENV;

When used with the Ember CLI Simple Auth addon, Ember Simple Auth uses the ENV['simple-auth'] configuration set in config/environment.js like below:
...
var ENV = {
...
};
ENV['simple-auth'] = {
routeAfterAuthentication: 'some.route.name.you.choose'
};
...

Related

How to get property from application.property in Gatling

I'm trying to get some properties from an application.properties file in Gatling-Scala. I tried.
val properties: Config = ConfigFactory.load("application.properties")
val clientId: String = properties.getString("api.clientId")
I keep getting "com.typesafe.config.ConfigException$Missing No configuration setting found for key 'api'". I put the application.properties file inside src/test/resources/application.properties and also in the root folder of the project.
I tried also to put the same information inside src/test/resources/gatling.conf as follows:
gatling {
api {
clientId = "..."
}
}
But I get the error:
com.typesafe.config.ConfigException$Missing No configuration setting found for key 'gatling'
Is there something I'm missing?
I managed to get the information in the gatling.conf file by installing the plugin HOCON for .conf files and formatting it correctly.

Can I skip generating the {proxy+} when creating Rest API using Amplify

I am currently playing around with creating rest-api:s with amplify. I am trying to create the following structure:
/helloText
/helloText/{name}
But I get the following error when trying to push the backend:
Unable to create resource at path '/helloText/{proxy+}': A sibling ({name}) of this resource already has a variable path part -- only one is allowed
As I understand, it is because Amplify is creating "greedy paths" by default.
When manually removing these "greedy paths" from the template file RestTest-cloudformation-template.json it works.
Is it somehow possible to create these paths by using only the command line?
There is no configuration switch for that in amplify-cli. You need to create an override. Reference: Amplify override api.
Run:
amplify override api
Then edit generated override.ts like:
import { AmplifyApiRestResourceStackTemplate } from '#aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyApiRestResourceStackTemplate) {
const {paths} = resources.restApi.body;
Object.keys(paths).forEach((path) => {
if (path.includes('{proxy+}')) {
delete paths[path];
}
});
}

Scala config lookup secrets

I have application.conf file which contains secrets(password for DB etc..) And this secret will be mounted as a file(the file content will contain the actual secrets) in the running pod. How can scala config library be tweaked to handle this. i.e
instead of normal application.conf
db {
user = "username"
password = "xxx"
}
I would have something like this...
db {
user = "username"
password = "${file_location}"
}
As the file is parsed, it should identify that the value of key password, needs to be resolved by looking up the file and loading its contents.
A simple function can be written to load the content of this file, how can this is be integrated with seamlessly with scala config. ie. The rest of the code will continue to use
config.getString(db.password)
I assume you are using configuration of HOCON format and Typesafe configuration library for it.
I don't think it has such feature out of the box, but as an possible alternative you can take a look at include feature - you can include content of another file into your application.conf:
db {
user = "username"
}
include /path/to/pod.conf //include env specific configuration file
and put inside /path/to/pod.conf:
db {
password = "pod_db_pass"
}
So eventually contents of both files will be merged inside application during loading, and your final config will contain password at path db.password
UPDATE
Another possible option load password from file and merge into config file with withFallback method. Example:
import com.typesafe.config._
val passord = "password_from_file"
val passwordConfig = ConfigFactory.parseString(s"db.password=$passord")
val applicationConfig = ConfigFactory.parseString(s"db.user=db_user")// Replace this with `ConfigFactory.load()`
val config = applicationConfig.withFallback(passwordConfig)
println(config)
Printout result:
Config(SimpleConfigObject({"db":{"password":"password_from_file","user":"db_user"}}))
Scatie: https://scastie.scala-lang.org/WW3weuqiT9WRUKfdrZgwcw

Scala Config: Include another file.conf

Currently, I have a resources/application.conf file which has the following keys:
development {
server = www.myapp.com
aws_key = my_aws_key
aws_secret = my_aws_secret
}
I would like to remove my aws_key and aws_secret from the file.
I was thinking of creating another file called resources/credentials.conf and storing my personal authentications there.
credentials {
aws_key = my_aws_key
aws_secret = my_aws_secret
}
and then include it some way in my application.conf or merge that config to the Config object in addition to application.conf.
credentials.conf would be git ignored. A sample file would be checked in credentials-sample.conf which each developer would change according to his own credentials and rename the sample file to credentials.conf
I tried different variation of include like
include "credentials"
include "credentials.conf"
include "./credentials.conf"
include file("./credentials.conf")
and so on.
I know I can pass it via system variables but I would like to try it like mentioned above. If you know of a better way, please let me know.
Typesafe Config provide the way to fallback from one configuration to another. You can try the ConfigFactory.Load() to load different config and use withFallback to line them up in your designated order. Such as:
ConfigFactory.Load("credentials.conf") withFallback ConfigFactory.Load("application.conf")
Inside your conf file, add
include "another_file.conf"
ie: https://github.com/cicco94/scala-akka-slick-demo/blob/master/src/main/resources/application.conf

sails.js Is it possible to set process.env variables from application?

I am trying to use npm module fb to use facebook api. The config file is located in the module and here is the snapshot of the same
var config = { };
// should end in /
config.rootUrl = process.env.ROOT_URL || 'http://localhost:3000/';
config.facebook = {
appId: process.env.FACEBOOK_APPID || '130243393813697',
appSecret: process.env.FACEBOOK_APPSECRET || 'c82696768ae4ad8b63db874cb64eb558',
appNamespace: process.env.FACEBOOK_APPNAMESPACE || 'nodescrumptious',
redirectUri: process.env.FACEBOOK_REDIRECTURI || config.rootUrl + 'login/callback'
};
module.exports = config;
I don't wish to change the config file of the module since node_modules folder is kept in the gitignore list. For configuring the module to use my app's appId and appSecret, I need to set the process.env variables FACEBOOK_APPID and FACEBOOK_APPSECRET
I understand that it can be done while calling the sails lift but is it by any means possible to set these values inside the app so that I only have to call
sails lift
without any of those variables and those should be set automatically ? Or what is the best way to achieve what I am trying to do here ?
You should set the environment-variables outside of your App.
Instead of sails lift you could also use node app.js. With that you can define environment-variables for your node-application with:
$> FOO='bar' node app.js
In your case:
$> FACEBOOK_APPID='232322a22' FACEBOOK_APPSECRET='mysecrete' node app.js
If you want to set this vars in your app (I wouldn't suggest that!) you could set them before including your npm-module. For example in your config/bootstrap.js:
module.exports.bootstrap = function(cb) {
process.env.FACEBOOK_APPID = "myvar";
process.env.FACEBOOK_APPSECRET = "mysecrete";
sails.facebook = require("yourmodule");
cb();
};
Here is a good link for setting environment variables when "Production", "Staging" and "Development" in Sails feels fragmented.
Here is a quick video tutorial which simply explains how to create environment variables in node.js
Step1:
Install the package dotenv as dependency
$ npm install dotenv --save
Step2:
Then require dotenv in app.js and load the .env file
var dotenv = require('dotenv');
dotenv.load();
Step3:
Create a .env file in the root folder (ie. at the same document level as app.js file)
Step4:
Add your environment variables
S3_KEY=enfiownqefniqofewqofnieqwvewlk
S3_SECRET=123456789
Now you can access those environment variables anywhere in the app (probably in some config/ files):
return {
key: process.env.S3_KEY,
secret: process.env.S3_SECRET,
region: 's3-eu-west-1',
bucket: 'myBucket',
s3params: {
ACL: 'public-read'
}
}
Credit goes to Noah Bass for providing this tutorial.