Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using vcapFile to create/update cf user-provided service #53

Open
LuiSlacker opened this issue Nov 1, 2022 · 1 comment
Open

Using vcapFile to create/update cf user-provided service #53

LuiSlacker opened this issue Nov 1, 2022 · 1 comment

Comments

@LuiSlacker
Copy link

Hi,

I'm using cfenv to handle my credentials. I setup a cf user-provided service within cf and added a local vcapFile for running the app locally.

This is how I read the credentials (locally and prod)

// read envs from file if running locally =========================
let localVCAP = null;
try {
  localVCAP = require('./vcap-local-env.json');
} catch (error) {
  // silently ignoring failure when running inside cloudfoundry
}

// include environment variables from vcap service
const appEnv = cfenv.getAppEnv({ vcap: localVCAP });
const cfEnv = appEnv.getService('credential-service-test-app').credentials;

That all works fine, the only issue I see is when updating the user-provided service. In order to be able to use the same code for reading the envs, my vcapFile looks like this:

{
    "application": {
        "port": 4002
    },
    "services": {
        "credential-service-test-app": [
            {
                "credential-service-test-app",
                "credentials": {
                    "SECRET_PWD":"<***>",
                  
                }
            }
        ]
    }
}

But this way I'm not able to use the file for updating the service with cf update-user-provided-service credential-service-test-app -p ./vcap-local-env.json, since it will nest the application/services within the cf services object.

I don't want to use the interactive cf update-user-provided-service credential-service-test-app -p command every time a change a parameter and having to add all params again.

What would be the recommend way of maintaining the user-provided service amongst several coders?

@pmuellr
Copy link
Member

pmuellr commented Nov 2, 2022

I'd probably write a script to read one version of the data to produce the other version of the data. For example, read the vcap-local-env.json, then generate what's needed for the cf update-user-provided-service. I'd probably structure it as a tool that invoked cf update-user-provided-service with the data, which it would write to a temporary file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants