Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oklemenz2 committed Feb 19, 2025
1 parent 2c9b05c commit e864869
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
[![REUSE status](https://api.reuse.software/badge/github.com/cap-js-community/sap-afc-sdk)](https://api.reuse.software/info/github.com/cap-js-community/sap-afc-sdk)
[![Main CI](https://github.com/cap-js-community/sap-afc-sdk/actions/workflows/main-ci.yml/badge.svg)](https://github.com/cap-js-community/sap-afc-sdk/commits/main)

## About this project
## About this Project

[SAP Advanced Financial Closing SDK for CDS](https://www.npmjs.com/package/@cap-js-community/sap-afc-sdk) Provides an SDK for SAP Advanced Financial Closing to be consumed with SAP Cloud Application Programming Model (Node.js).
[SAP Advanced Financial Closing SDK for CDS](https://www.npmjs.com/package/@cap-js-community/sap-afc-sdk)
Provides an SDK for SAP Advanced Financial Closing to be consumed with SAP Cloud Application Programming Model (Node.js).

## Table of Contents

- [Getting Started](#getting-started)
- [Requirements and Setup](#requirements-and-setup)
- [Architecture](#architecture)
- [Usage](#usage)
- [Options](#options)
Expand All @@ -24,10 +25,6 @@

## Requirements and Setup

*Insert a short description what is required to get your project running...*

## Getting Started

- Run `npm add @cap-js-community/sap-afc-sdk` in `@sap/cds` project
- Execute `cds-serve` to start server
- Access welcome page at http://localhost:4004
Expand Down Expand Up @@ -594,4 +591,4 @@ We as members, contributors, and leaders pledge to make participation in our com

## Licensing

Copyright (20xx-)20xx SAP SE or an SAP affiliate company and <your-project> contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js-community/sap-afc-sdk).
Copyright (20xx-)20xx SAP SE or an SAP affiliate company and <your-project> contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js-community/sap-afc-sdk).
3 changes: 2 additions & 1 deletion bin/afc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ program
.description("Manage API")
.addArgument(new commander.Argument("<action>", "Manage API keys").choices(["key"]))
.option("-n, --new", "Create new API key")
.option("-p, --password", "Broker password")
.action(manageAPI)
.addHelpText(
"afterAll",
Expand Down Expand Up @@ -108,6 +109,6 @@ async function addFeature(argument) {
async function manageAPI(action) {
const options = this.opts();
const apiFn = require("./commands/api");
await apiFn(action, !!options.new);
await apiFn(action, { isNew: options.new, password: options.password });
console.log("Successfully managed API keys.");
}
24 changes: 21 additions & 3 deletions bin/commands/api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
/* eslint-disable no-console */
"use strict";

const fs = require("fs");
const path = require("path");
const shelljs = require("shelljs");

module.exports = (action, isNew) => {
module.exports = (action, { isNew, password }) => {
switch (action) {
case "key":
shelljs;
isNew;
manageKey(isNew, password);
break;
}
};

function manageKey(isNew, password) {
const brokerPath = path.join(process.cwd(), "srv/broker.json");
if (!fs.existsSync(brokerPath)) {
console.log(`broker.json not found at '${brokerPath}'. Call 'afc add broker'`);
return;
}
const broker = require(brokerPath);
const name = Object.keys(broker.SBF_SERVICE_CONFIG)[0];
if (!name) {
console.log(`No service found in broker configuration. Call 'afc add broker'`);
}
shelljs.exec(
`cf create-service-broker ${name}-broker broker-user '${password}' https://${isNew}.cfapps.sap.hana.ondemand.com/broker --space-scoped`,
);
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"audit": "npm audit --only=prod"
},
"dependencies": {
"@cap-js-community/event-queue": "^1.8.7",
"@cap-js-community/event-queue": "^1.9.0",
"@cap-js-community/feature-toggle-library": "^1.2.4",
"@cap-js-community/websocket": "^1.6.0",
"@sap/sbf": "^6.8.2",
Expand Down
2 changes: 1 addition & 1 deletion test/scheduling/__snapshots__/provider.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,4 @@ exports[`API Open API GET API Docs Root 2`] = `
"
`;
exports[`API Security GET CSP 1`] = `"default-src 'self' https://ui5.sap.com;base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data: blob: https://ui5.sap.com;object-src 'none';script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ui5.sap.com;script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests;connect-src wss: https://ui5.sap.com https://authentication.sap.hana.ondemand.com http://localhost"`;
exports[`API Security GET CSP 1`] = `"default-src 'self' https://ui5.sap.com;base-uri 'self';font-src 'self' https: data:;form-action 'self';frame-ancestors 'self';img-src 'self' data: blob: https://ui5.sap.com;object-src 'none';script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ui5.sap.com;script-src-attr 'none';style-src 'self' https: 'unsafe-inline';upgrade-insecure-requests;connect-src wss: https://ui5.sap.com https://authentication.sap.hana.ondemand.com https://sap-afc-sdk.sap.com"`;
13 changes: 9 additions & 4 deletions test/scheduling/provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const { JobStatus } = require("../../srv/scheduling/common/codelist");

const { GET, POST, PUT, DELETE, axios, test } = cds.test(__dirname + "/../..");

process.env.VCAP_APPLICATION = JSON.stringify({
uris: ["sap-afc-sdk.sap.com"],
});

process.env.PORT = 0; // Random

describe("API", () => {
Expand Down Expand Up @@ -47,16 +51,17 @@ describe("API", () => {
describe("Security", () => {
it("GET CSP", async () => {
let response = await GET("/api/job-scheduling/v1/JobDefinition");
const csp = response.headers["content-security-policy"].replace(/localhost:\d+/, "localhost");
expect(csp).toMatchSnapshot();
expect(response.headers["content-security-policy"]).toMatchSnapshot();
expect(response.headers).toMatchObject({
"cross-origin-opener-policy": "same-origin",
"cross-origin-resource-policy": "same-origin",
});
});

it("GET CORS", async () => {
let response = await GET("/api/job-scheduling/v1/JobDefinition");
expect(response.headers).toMatchObject({
"access-control-allow-origin": "*",
"cross-origin-opener-policy": "same-origin",
"cross-origin-resource-policy": "same-origin",
});
});
});
Expand Down

0 comments on commit e864869

Please sign in to comment.