How to access Bitrise Secret Environment Variable in Swift code? - ios

I'm using Bitrise as a CI solution for my iOS app. I would like not to commit my API token to the repository, hence I've stored it as a Secret in the workflow in Bitrise with key = "API_TOKEN"
I need to pass that value to my app as an environment variable and use it as follows:
ProcessInfo.processInfo.environment["API_TOKEN"]
However, this is always nil.
My bitrise.yml contains the following:
....
app:
envs:
- API_TOKEN: "${API_TOKEN}"
...
How can I correctly set the Secret from Bitrise as an environment variable for my iOS app?

Related

Setting environment properties from SSM parameters in Elastic beanstalk(rails) (Amazon linux 2)

In amazon linux 1 you could change the environment properties of rails application by changing the file /opt/elasticbeanstalk/deploy/configuration/containerconfiguration.So i could easily get the properties stored in SSM(aws system store manager) and set them in the former file and it works.
But in amazon linux 2(AML2) there is no such file which i can change to edit the environment properties.
Things i have tried:-
changing /opt/elasticbeanstalk/deployment/env file using SSM parameters
exporting the properties in SSM using export command in prebuild directory
changing the bash_profile using SSM parameters
None of the above work and the properties from SSM dont set in the environment andso my rails application deployment always fails(due to environment properties like AWS keys missing).
Kindly tell a way through which i can change environment properties using SSM parameters in AML2.

Unable to define params variables in Serverless console

According to the Serverless documentation, I should be able to define params within the dashboard/console. But when I navigate there, the inputs are disabled:
I've tried following the instructions to update via CLI, with: serverless deploy --param="domain=myapp.com" --param="key=value". The deploy runs successfully (I get a ✔ Service deployed to... message with no errors), but nothing appears in my dashboard. Likewise, when I run a command to check whether there are any params stored: serverless param list, I get
Running "serverless" from node_modules
No parameters stored
Passing param flags will not upload the parameters to Dashboard/Console, it will only expose them in your configuration so you can access them with ${param:<param-name>}. To my best knowledge, it is not possible to set Dashboard parameters with CLI, you need to set them manually via UI.
It was a permissions problem. The owner of the account updated the permissions and I was able to update the inputs.

Nuxt environment variables exposed in client when uploaded to Zeit/Now

I am deploying a Nuxt App with Zeit/Now. In the development phase I was using a .env file to store the secrets to my Contentful CMS, exposing the secrets to process.env with the nuxt-dotenv package. To do that, at the top of the nuxt.config I was calling require('dotenv').config().
I then stored the secrets with Zeit/Now and created a now.json to set them up for build and runtime like so:
{
"env": {
"DEMO_ID": "#demo_id"
},
"build": {
"env": {
"DEMO_ID": "#demo_id"
}
}
}
With that setup, the build was only working for the index page and all of the Javascript did not function. Only when I added the env-property to the nuxt.config.jsfile, the app started working properly on the Zeit-server.
require('dotenv').config()
export default {
...
env: {
DEMO_ID: process.env.DEMO_ID
},
...
modules: [
'#nuxtjs/dotenv'
],
...
}
BUT: When I then checked the uploaded Javascript files, my secrets were exposed, which I obviously don't want.
What am I doing wrong here? Thanks for your help.
You aren't necessarily doing anything wrong here, this is just how Nuxtjs works.
Variables declared in the env property are used to replace instances of process.env.MY_ENV, but because Nuxt is isomoorphic, this can be both on the server and client.
If you want these secrets accessible only on the server, then the easiest way to solve this is to use a serverMiddleware.
As serverMiddleware is decoupled from the main Nuxt build, env variables defined in nuxt.config.js are not available there.
This means your normal ENV variables should be accessible, since the server middleware are run on Node.
Obviously, this means these secrets won't be available client side, but this works if you have something like a Stripe secret key that you need to make backend requests with.
We had a similar problem in our project. Even, We created a nuxt project from scratch and checked to see if there was a situation we skipped. We noticed that, while nuxt building, it copies the .env variables into the utils.js in the nuxt folder. Through the document here, we changed the modules section in nuxt.config.js as follows,
modules: ['# nuxtjs / apollo', '# nuxtjs / axios', ['# nuxtjs / dotenv', { only: ['']}]],
Then we noticed that .env variables are not exposed.
I hope it helped.
Our nuxt version is "nuxt": "^ 2.13.0".
Also, some discussion over here.

How to deploy a Serverless function using Gitlab CI?

I'm trying to deploy my Serverless function using a .gitlab-ci.yml file, and to inject environment variables into my function I'm using this format in my serverless.yml file:
${file(./serverless.env.yml):${opt:stage, 'dev'}.VARIABLE_1_KEY}
My serverless.env.yml file looks something like this:
staging:
VARIABLE_1_KEY: xxxxxxx
VARIABLE_2_KEY: xxxxxxx
SUBNET_IDS:
- xxxxxx
- xxxxxx
production:
VARIABLE_1_KEY: xxxxxxx
VARAIBLE_2_KEY: xxxxxxx
SUBNET_IDS:
- xxxxxx
- xxxxxx
My issue is that I'm not committing my serverless.env.yml file, which means Gitlab won't be able to use it to deploy the function.
I could alter the variables to this format ${env:VARIABLE_KEY} but this leaves me with the issue where the SUBNET_IDS are a list of values and doesn't work when resolving the value from an environment variable.
Is there a better way to define secrets within the project that is compatible with the Gitlab CI process?
To define project level secrets you can go to:
Your Project -> Settings -> CI/CD -> Variables
The secrets will be available via environment variables. You can read more about variables here
Regarding your issue with SUBNET_IDS list. You can either define each one as a different variable, or you can concat them with a character (, or ; for example) and split them in your script.

VueJS & Webpack: ENV var unaccessible from built project

I'm working on an app with vuejs frontend and nodejs backend. My frontend makes API https requests to the backend. I've started my projet with vue-cli and webpack.
I need to get the backend API url from env variable (BACKEND_URL).
Since i'm using webpack, I added this line to config/prod.env.js :
module.exports = {
NODE_ENV: '"production"',
-> BACKEND_URL: JSON.stringify(process.env.BACKEND_URL)
}
It works flawlessly in dev mode using webpack-dev-server. I pass the env var throught docker-compose file:
environment:
- BACKEND_URL=https://whatever:3000
But when I run build, I use nginx to serve the static files (but the problem is the same using visual studio code live server extension). I send BACKEND_URL env var the same way as before. The thing is now the process.env.BACKEND_URL is undefined in the app (but defined in the container)!! So I cant make backend http calls :(
I'm struggling finding the problem, please don't be rude with the responses. Thank you
They aren not "translated" during build time, this is what is happening with you. On a node environment, when you ask for process.env it will show all environment variables available in the system, that is true. But a web application does not have access to process.env when it is executing. You need a way to translate them during build time.
To achieve that you have to use DefinePlugin. It translates anything during build time and writes a magical string where this other thing was.
Using you own example:
module.exports = {
NODE_ENV: '"production"',
BACKEND_URL: JSON.stringify(process.env.BACKEND_URL)
}
If you do this during build time, without DefinePlugin, webpack won't know what to do with it, and it is going to be a simple string.
If you use DefinePlugin:
new webpack.DefinePlugin({
"process.env.BACKEND_URL": JSON.stringify(process.env.BACKEND_URL)
});
By doing this, you are allowing webpack to translate this during build time.
Give this a shot: https://www.brandonbarnett.io/blog/2018/05/accessing-environment-variables-from-a-webpack-bundle-in-a-docker-container/
If I'm understanding your problem correctly, you're serving a webpack bundle using nginx, and trying to access an environment variable from that bundle.
Unfortunately, it doesn't quite work that way. Your JS file has no access to the environment since it's a resource that has been delivered to the client. I've proposed a solution that also delivers those env variables alongside the bundle in a separate JS file that gets created on container start.
From VueJS Docs: https://cli.vuejs.org/guide/mode-and-env.html
Using Env Variables in Client-side Code
Only variables that start with VUE_APP_ will be statically embedded into the client bundle with webpack.DefinePlugin. You can access them in your application code:
console.log(process.env.VUE_APP_SECRET)
During build, process.env.VUE_APP_SECRET will be replaced by the corresponding value. In the case of VUE_APP_SECRET=secret, it will be replaced by "secret".
So in your case, the following should do the trick. I had the same problem once in my project, which I started with vue/cli and vue create project ...
VUE_APP_BACKEND_URL=https://whatever:3000

Resources