1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

remove slack, source email from env var

This commit is contained in:
Matthias Kretschmann 2019-07-08 15:31:48 +02:00
parent fa078c6c4c
commit 050936a0c1
Signed by: m
GPG Key ID: 606EEEF3C479A91F
10 changed files with 35 additions and 122 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ dist
# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local

View File

@ -26,6 +26,8 @@ If you're a developer and want to contribute to, or want to utilize this marketp
- [🏖 Remote Ocean: Pacific](#-Remote-Ocean-Pacific)
- [🐳 Use with Barge](#-Use-with-Barge)
- [⛵️ Environment Variables](#-Environment-Variables)
- [Client](#Client)
- [Server](#Server)
- [👩‍🔬 Testing](#-Testing)
- [Unit Tests](#Unit-Tests)
- [End-to-End Integration Tests](#End-to-End-Integration-Tests)
@ -41,7 +43,7 @@ If you're a developer and want to contribute to, or want to utilize this marketp
This repo contains a client and a server, both written in TypeScript:
- **client**: React app setup with [squid-js](https://github.com/oceanprotocol/squid-js), bootstrapped with [Create React App](https://github.com/facebook/create-react-app)
- **server**: Node.js app, utilizing [Express](https://expressjs.com). The server provides various microservices, like remote file checking.
- **server**: Node.js app, utilizing [Express](https://expressjs.com). The server provides various microservices, like remote file checking. The endpoints are documented in [server Readme](server/).
To spin up both, the client and the server in a watch mode for local development, execute:
@ -79,6 +81,8 @@ Modify `./client/src/config.ts` or set environment variables to use those local
### ⛵️ Environment Variables
#### Client
The `./client/src/config.ts` file is setup to prioritize environment variables for setting each Ocean component endpoint.
By setting environment variables, you can easily switch between Ocean networks the commons client connects to, without directly modifying `./client/src/config.ts`. This is helpful e.g. for local development so you don't accidentially commit changes to the config file.
@ -92,6 +96,17 @@ cp client/.env.local.example client/.env.local
vi client/.env.local
```
#### Server
The server uses its own environment variables too:
```bash
cp server/.env.example server/.env
# edit variables
vi server/.env
```
## 👩‍🔬 Testing
Test suite is setup with [Jest](https://jestjs.io) and [react-testing-library](https://github.com/kentcdodds/react-testing-library) for unit testing, and [Cypress](https://www.cypress.io) for integration testing.

View File

@ -52,3 +52,5 @@ REACT_APP_BRIZO_ADDRESS="0x008c25ed3594e094db4592f4115d5fa74c4f41ea"
# REACT_APP_SECRET_STORE_URI="http://localhost:12001"
# REACT_APP_FAUCET_URI="http://localhost:3001"
# REACT_APP_BRIZO_ADDRESS="0x00bd138abd70e2f00903268f3db08f2d25677c9e"
REACT_APP_REPORT_EMAIL="test@example.com"

View File

@ -19,7 +19,7 @@
h3 {
font-size: $font-size-base;
margin-top: 0;
margin-bottom: $spacer / 4;
margin-bottom: $spacer / 8;
}
p {
@ -29,5 +29,6 @@
code {
padding: 0;
color: $brand-grey-light;
}
}

View File

@ -38,10 +38,10 @@ export default class Report extends PureComponent<
event.preventDefault()
const msg = {
to: 'test@example.com',
from: 'test@example.com',
to: process.env.REACT_APP_REPORT_EMAIL,
from: 'info@oceanprotocol.com',
subject: `[Report] ${this.props.title}`,
html: `<p>The following data set was reported:</p><p><strong>${this.props.title}</strong><br /><a href="https://commons.oceanprotocol.com/asset/${this.props.did}"><code>${this.props.did}</code></a></p><blockquote><p>${this.state.comment}</p></blockquote>`
html: `<p>The following data set was reported:</p><p><strong>${this.props.title}</strong><br /><a style="color:#ff4092;text-decoration:none" href="https://commons.oceanprotocol.com/asset/${this.props.did}"><code>${this.props.did}</code></a></p><blockquote><em>${this.state.comment}</em></blockquote>`
}
try {

1
server/.env.example Normal file
View File

@ -0,0 +1 @@
SENDGRID_API_KEY='xxx'

View File

@ -60,7 +60,7 @@ Url Checker returns size and additional information about requested file. This s
### Report
Report endpoints sends an email via SendGrid and posts a message to Slack. Requires `SENDGRID_API_KEY` & `SLACK_TOKEN` set as environment variables.
Report endpoints sends an email via SendGrid. Requires `SENDGRID_API_KEY` set as environment variables.
**Endpoint:** POST `/api/v1/report`

116
server/package-lock.json generated
View File

@ -379,38 +379,6 @@
"@sendgrid/helpers": "^6.4.0"
}
},
"@slack/logger": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@slack/logger/-/logger-1.0.0.tgz",
"integrity": "sha512-QDYhQR/58xKfB5iquvQwfpxPsmKPP/5SuDp8hRhZeUluCHsP1qBCOc3sW2Xb3cydxK0PAEnkLbBJf/ezsGwtlA==",
"requires": {
"@types/node": ">=8.9.0"
}
},
"@slack/types": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@slack/types/-/types-1.0.0.tgz",
"integrity": "sha512-IktC4uD/CHfLQcSitKSmjmRu4a6+Nf/KzfS6dTgUlDzENhh26l8aESKAuIpvYD5VOOE6NxDDIAdPJOXBvUGxlg=="
},
"@slack/web-api": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-5.0.1.tgz",
"integrity": "sha512-L2Nc8P+NjXH1yqnsNhqxsrbpW3Qv+//9X5PQqcM3bctDmvmwTuhuM1X208RVD2avhnC89aghY5PssyaayWj5sA==",
"requires": {
"@slack/logger": "^1.0.0",
"@slack/types": "^1.0.0",
"@types/form-data": "^2.2.1",
"@types/is-stream": "^1.1.0",
"@types/node": ">=8.9.0",
"@types/p-queue": "^2.3.2",
"axios": "^0.18.0",
"eventemitter3": "^3.1.0",
"form-data": "^2.3.3",
"is-stream": "^1.1.0",
"p-queue": "^2.4.2",
"p-retry": "^4.0.0"
}
},
"@types/babel__core": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.2.tgz",
@ -526,14 +494,6 @@
"@types/node": "*"
}
},
"@types/is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@types/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha512-jkZatu4QVbR60mpIzjINmtS1ZF4a/FqdTUTBeQDVOQ2PYyidtwFKr0B5G6ERukKwliq+7mIXvxyppwzG5EgRYg==",
"requires": {
"@types/node": "*"
}
},
"@types/istanbul-lib-coverage": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz",
@ -594,11 +554,6 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz",
"integrity": "sha512-Uy0PN4R5vgBUXFoJrKryf5aTk3kJ8Rv3PdlHjl6UaX+Cqp1QE0yPQ68MPXGrZOfG7gZVNDIJZYyot0B9ubXUrQ=="
},
"@types/p-queue": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/@types/p-queue/-/p-queue-2.3.2.tgz",
"integrity": "sha512-eKAv5Ql6k78dh3ULCsSBxX6bFNuGjTmof5Q/T6PiECDq0Yf8IIn46jCyp3RJvCi8owaEmm3DZH1PEImjBMd/vQ=="
},
"@types/range-parser": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.3.tgz",
@ -616,11 +571,6 @@
"@types/tough-cookie": "*"
}
},
"@types/retry": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
"integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA=="
},
"@types/serve-static": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.2.tgz",
@ -867,22 +817,6 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
},
"axios": {
"version": "0.18.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
"integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
},
"dependencies": {
"is-buffer": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
}
}
},
"babel-jest": {
"version": "24.8.0",
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.8.0.tgz",
@ -1695,6 +1629,11 @@
"is-obj": "^1.0.0"
}
},
"dotenv": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.0.0.tgz",
"integrity": "sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg=="
},
"duplexer3": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
@ -1809,11 +1748,6 @@
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
},
"eventemitter3": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz",
"integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q=="
},
"exec-sh": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.2.tgz",
@ -2132,24 +2066,6 @@
"locate-path": "^3.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
@ -3284,7 +3200,8 @@
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
"dev": true
},
"is-symbol": {
"version": "1.0.2",
@ -4591,26 +4508,12 @@
"p-limit": "^2.0.0"
}
},
"p-queue": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-2.4.2.tgz",
"integrity": "sha512-n8/y+yDJwBjoLQe1GSJbbaYQLTI7QHNZI2+rpmCDbe++WLf9HC3gf6iqj5yfPAV71W4UF3ql5W1+UBPXoXTxng=="
},
"p-reduce": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-reduce/-/p-reduce-1.0.0.tgz",
"integrity": "sha1-GMKw3ZNqRpClKfgjH1ig/bakffo=",
"dev": true
},
"p-retry": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.1.0.tgz",
"integrity": "sha512-oepllyG9gX1qH4Sm20YAKxg1GA7L7puhvGnTfimi31P07zSIj7SDV6YtuAx9nbJF51DES+2CIIRkXs8GKqWJxA==",
"requires": {
"@types/retry": "^0.12.0",
"retry": "^0.12.0"
}
},
"p-try": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
@ -5072,11 +4975,6 @@
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==",
"dev": true
},
"retry": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs="
},
"rimraf": {
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",

View File

@ -14,10 +14,10 @@
},
"dependencies": {
"@sendgrid/mail": "^6.4.0",
"@slack/web-api": "^5.0.1",
"body-parser": "^1.18.3",
"compression": "^1.7.4",
"debug": "^4.1.1",
"dotenv": "^8.0.0",
"express": "^4.17.1",
"express-validator": "^6.1.1",
"morgan": "^1.9.1",

View File

@ -1,9 +1,8 @@
import { Router, Request, Response } from 'express'
import SendgridMail from '@sendgrid/mail'
import { WebClient } from '@slack/web-api'
import 'dotenv/config'
SendgridMail.setApiKey(process.env.SENDGRID_API_KEY)
const slack = new WebClient(process.env.SLACK_TOKEN)
export class ReportRouter {
public router: Router
@ -19,10 +18,6 @@ export class ReportRouter {
try {
await SendgridMail.send(req.body.msg)
await slack.chat.postMessage({
text: req.body.msg.html,
channel: 'C88KZQEBB' // #form-submissions
})
return res.send({ status: 'success' })
} catch (error) {
console.error(`${error.code} - ${error.message}`) // eslint-disable-line