Missing VCAP_SERVICES while running local app with SAP cloud SDK - sdk

I goes along the tutorial at https://developers.sap.com/tutorials/s4sdk-odata-service-cloud-foundry.html. I set destinations as described to a running Mockserver on the Internet with no user and passwort. I'm using the latest version of the 3.xx SDK.
set destinations=[{name: "dest", url: "https://businesspartner-odata-mock-server-timely-lynx.cfapps.eu10.hana.ondemand.com"}]
I have verified the destinations variable and it's look fine. I add the businessServlet as described.
private final ErpHttpDestination destination = DestinationAccessor.getDestination("dest").asHttp().decorate(DefaultErpHttpDestination::new);
I run it local along the tutorial and use a debugger.The error is:
com.sap.cloud.sdk.cloudplatform.exception.CloudPlatformException: Environment variable 'VCAP_SERVICES' is not defined.
I seems the destination Environment Variable is not used. I have two questions:
How can I fix this problem to run the app local against an mockserver with business data? I read the troubleshooting area and try a lot of chances.
It is possible to set this Environment Variable in the application.properties or in another way?
Thanks a lot
Peter

You should define environmental variable destination if you are running app locally
cf set-env firstapp destinations "[{name: \"ErpQueryEndpoint\", url: \"https://URL\", username: \"USER\", password: \"PASSWORD\"}]"
Read the tutorial
https://blogs.sap.com/2017/05/21/step-4-with-sap-s4hana-cloud-sdk-calling-an-odata-service/
VCAP_SERVICES variable is not defined on local scenarios. BTW, the tutorial you use is intended for S/4HANA Cloud Foundry instance, not local.

Related

GCP Cloud run - how do I get CloudRun service parameters run-time

I have several CloudRun services running. I have the need to do some environment specific things (also because I have a docker container being built from the same sources too) in code. I searched around quite a bit to find out if I can get the following run-time:
Check if my code is running in a CloudRun instance or not
Get other environment variables like service-name, project-name, deploy-time, awake-time, region-name, etc. - for various reasons
This demo container code shows how to get that kind of information:
https://github.com/GoogleCloudPlatform/cloud-run-hello/blob/master/hello.go
Some things are available directly as environment variables like service and revision
service := os.Getenv("K_SERVICE")
revision := os.Getenv("K_REVISION")
The container contract docs page shows the full list
https://cloud.google.com/run/docs/container-contract
as well as information about the metadata server that can give you things like project-id or region.

Remix.run deployment on Vercel: process not defined error

I have deployed a remix application on Vercel. Further, I have defined some environment variables in Vercel and want to perform some checks and use env variables in my app:
if (process.env.NODE_ENV === 'production') {
setPaths({
path: process.env.prod_path,
})
}
It gives me error, process is not defined. I even tried adding process && in the if statement, it did not help.
Second, I am unable to even set the env variables locally. I followed remix docs but it gives me undefined every time when I console.log as mentioned in the docs.
Any guide/pointer towards using environmental variables in remix would be really helpful.
I was able to solve this problem. I was using loader/useLoaderData to access server side environment variables. The problem was that I was trying to call these at component level. Apparently, we can only call them at the route level.
I'm not sure, but the name of the function (setXXX makes me think this is the setter of a hook), makes me think you are trying to use process.env in the browser, but process.env is only available in server-side code, if you want to use env variables in your react app you can use this guide to send the variables from the server side to you react app. If this code is server side code, maybe it's worth making a reproduction in stackblitz so we can have a better look at it.

How do I get a Replit secret key to work using Svelte?

I'm stuck on what seems like a simple task. I want to run a weather app I built in Svelte and run it on Replit. The app uses an API with a key, so I added my key to Secrets in Replit and gave it the name MY_API_KEY.
In the file that calls the API, I used the following:
const MY_API_KEY = process.env.MY_API_KEY;
Unfortunately, that doesn't work. My app doesn't load. When I change the variable in my file to include the key itself, the app runs fine, so I must not be calling up the environmental variable right. Does anyone know how this works in Svelte? I'd appreciate any help.
The base Svelte template on Replit uses Vite for building it's apps. This means you can do it the Vite way:
Call your environment variables something like VITE_ApiKey=123
And in your code use import.meta.env.VITE_ApiKey
Note that this only works for environment variables prefixed with VITE_

Using Environment Variables for Per Environment Configuration in iOS

I am working on an iOS application that uses a pretty normal multi-environment deployment model. We have a QA, Prod, and "Dev" version of the app that all talk to their own corresponding backends. I am new to iOS development but am familiar with Node, Java, and a few other development environments.
The first thing I reached to for this problem was Environment Variables. I saw that XCode had a way to set environment variables in a Scheme and they could be read pretty easily. So I used 4 environment variables per environment to configure a few needed backend hosts. Everything seemed to be going fine until I realized that those environment variables seem to ONLY be available when running the app through XCode. Is that correct? Is there no way to configure environment variables that "bundle up" with an app? If so, the ability to configure environment variables at all seems like a footgun.
What I mean is, In a NodeJS or Java app, I can set a number of useful "necessary" configs like a backend hosts and use some approach to provide those values when running the app for real. It seems like in iOS / Swift, environment variables are only useful for development-time debugging settings? The asymmetry between what's available in XCode vs a "real" shipped app seems odd.
Is there a similar standard way that I can configure my app for multiple different environments that works on shipped applications and ideally just involves reading some value at runtime rather than using conditionals and/or using compiler flags or something?
You are correct. The Environment Variables are only meaningful when executing the Scheme in Xcode. Their primary use in that context is to activate debugging features that are not on all the time. For example, if you try to create a bitmap Core Graphics context (CGContext) with an invalid set of parameters, the debugger may tell you to set an environment variable to see additional debugging output from Core Graphics. Or you can set environment variables to turn on memory management debugging features.
When you are running an application on a server, the Unix framework in which the application is running is part of the "user experience". In that context it makes sense for the application to use things like environment variables.
As developers we understand that a mobile app is running inside a unix process, but that unix environment is mostly unavailable to us. A similar feature that is common to Unix apps is command line arguments. An iOS application on startup receives command line arguments (argc and argv) but there is no way specify those when the app is launched either.
There are a number of places you could include configuration information like that which you describe in your application. The most common that I can think of is to include the setting in the applications Info.plist. At runtime you could access the contents of the property list by fetching the main bundle and asking for it's infoDictionary:
let infoBundle = Bundle.main.infoDictionary
let mySetting = infoBundle["SomeSetting"]
When the application's info.plist is created, it DOES have access to the environment variables declared in the Scheme so you could put the environment variables in the scheme, reference them in the Info.plist, and retrieve them at runtime from the main bundle.
try Using FeatureFlags, maybe will help you, check this
https://medium.com/#rwbutler/feature-flags-a-b-testing-mvt-on-ios-718339ac7aa1

How to store api keys as variables via the terminal - Rails 4

i am trying to store my api keys in a variable via the terminal but i am unsure why it is not saving/storing my api keys.
for example, in the terminal when i type the below:
export GMAIL_USERNAME="myname#gmail.com"
then when i type in env i can see the varaibale has been stored:
but when i restart my terminal the variable GMAIL_USERNAME="myname#gmail.com" is no longer there
could one tell me where i am going wrong? all i would like to do is
store in development my api secret keys in a variable. your help would
be much appreciated
While you can persist environment variables by adding them to a script that gets called on shell startup, that approach has a few problems.
The biggest problem is that they are available globally across your shell, and not scoped to a project.
What happens if you have another project, and want to use a different gmail account?
A better solution is using dotenv or direnv and set those environment variables for the current project only.

Resources