Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions cap/package-lock.json

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

112 changes: 65 additions & 47 deletions cap/package.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,72 @@
{
"name": "cap",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^5.5.4",
"express": "^4",
"hdb": "^0.19"
"name": "cap",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^5.5.4",
"cors": "^2.8.5",
"express": "^4",
"hdb": "^0.19",
"helmet": "^4.6.0",
"passport": "^0.5.0"
},
"devDependencies": {
"sqlite3": "^5.0.2"
},
"scripts": {
"start": "cds run"
},
"eslintConfig": {
"extends": "eslint:recommended",
"env": {
"es2020": true,
"node": true,
"jest": true,
"mocha": true
},
"devDependencies": {
"sqlite3": "^5.0.2"
"globals": {
"SELECT": true,
"INSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"CDL": true,
"CQL": true,
"CXL": true,
"cds": true
},
"scripts": {
"start": "cds run"
},
"eslintConfig": {
"extends": "eslint:recommended",
"env": {
"es2020": true,
"node": true,
"jest": true,
"mocha": true
},
"globals": {
"SELECT": true,
"INSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"CDL": true,
"CQL": true,
"CXL": true,
"cds": true
},
"rules": {
"no-console": "off",
"require-atomic-updates": "off"
"rules": {
"no-console": "off",
"require-atomic-updates": "off"
}
},
"cds": {
"requires": {
"db": {
"kind": "sql"
},
"auth": {
"kind": "basic-auth",
"users": {
"employee": {
"roles": [
"Employee"
]
},
"admin": {
"roles": [
"Admin"
]
}
}
}
},
"cds": {
"requires": {
"db": {
"kind": "sql"
}
},
"hana": {
"deploy-format": "hdbtable"
}
"hana": {
"deploy-format": "hdbtable"
}
}
}
16 changes: 13 additions & 3 deletions cap/srv/cat-service.cds
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
using my.bookshop as my from '../db/data-model';

service CatalogService {
@readonly entity Books as projection on my.Books;
}
service CatalogService @(requires : 'authenticated-user') {
entity Books @(restrict : [
{
grant : ['READ'],
to : 'Employee',
where : 'stock > 100'
},
{
grant : ['*'],
to : 'Admin'
}
]) as projection on my.Books;
}
26 changes: 22 additions & 4 deletions cap/srv/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
const cds = require ('@sap/cds')
cds.on('bootstrap', (app) => {
const cds = require("@sap/cds");
const cors = require("cors");
const helmet = require("helmet");

})
cds.on("bootstrap", (app) => {
var corsOptions = {
origin: "http://localhost:4004",
optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
};

module.exports = cds.server
app.use(cors(corsOptions));
app.use(
helmet({
contentSecurityPolicy: {
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
// custom settings
},
},
})
);
});

module.exports = cds.server;
38 changes: 38 additions & 0 deletions cap/test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Read without authenticatino
GET http://localhost:4004/catalog/Books HTTP/1.1

### Read all with employee
GET http://localhost:4004/catalog/Books HTTP/1.1
Authorization: Basic employee:

### Single Read
GET http://localhost:4004/catalog/Books(1) HTTP/1.1
Authorization: Basic employee:

### Write with employee
PATCH http://localhost:4004/catalog/Books(1) HTTP/1.1
Authorization: Basic employee:
content-type: application/json

{
"stock": 200
}

### Delete with employee
DELETE http://localhost:4004/catalog/Books(1) HTTP/1.1
Authorization: Basic employee:


### Write with admin
PATCH http://localhost:4004/catalog/Books(1) HTTP/1.1
Authorization: Basic admin:
content-type: application/json

{
"stock": 200
}

### Delete with admin
DELETE http://localhost:4004/catalog/Books(1) HTTP/1.1
Authorization: Basic admin: