* Creates a parameter in the global location of the specified * project with specified format using the Google Cloud Parameter Manager SDK. * * @param {string} projectId - The Google Cloud project ID where the parameter is to be created. * @param {string} parameterId - The ID of the parameter to
(projectId, parameterId, formatType)
| 23 | * @param {string} formatType - The format type of the parameter (UNFORMATTED, YAML, JSON). |
| 24 | */ |
| 25 | async function main(projectId, parameterId, formatType) { |
| 26 | // [START parametermanager_create_structured_param] |
| 27 | /** |
| 28 | * TODO(developer): Uncomment these variables before running the sample. |
| 29 | */ |
| 30 | // const {protos} = require('@google-cloud/parametermanager'); |
| 31 | // const projectId = 'YOUR_PROJECT_ID'; |
| 32 | // const parameterId = 'YOUR_PARAMETER_ID'; |
| 33 | // const formatType = protos.google.cloud.parametermanager.v1.ParameterFormat.JSON; |
| 34 | |
| 35 | // Imports the Parameter Manager library |
| 36 | const {ParameterManagerClient} = require('@google-cloud/parametermanager'); |
| 37 | |
| 38 | // Instantiates a client |
| 39 | const client = new ParameterManagerClient(); |
| 40 | |
| 41 | async function createStructuredParam() { |
| 42 | const parent = client.locationPath(projectId, 'global'); |
| 43 | const request = { |
| 44 | parent: parent, |
| 45 | parameterId: parameterId, |
| 46 | parameter: { |
| 47 | format: formatType, |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | const [parameter] = await client.createParameter(request); |
| 52 | console.log( |
| 53 | `Created parameter ${parameter.name} with format ${parameter.format}` |
| 54 | ); |
| 55 | return parameter; |
| 56 | } |
| 57 | |
| 58 | return await createStructuredParam(); |
| 59 | // [END parametermanager_create_structured_param] |
| 60 | } |
| 61 | module.exports.main = main; |
| 62 | |
| 63 | /* c8 ignore next 10 */ |
no test coverage detected