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

Allow MQTTS and WSS for MQTT Integration #514

Merged
merged 17 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
45 changes: 45 additions & 0 deletions .github/workflows/registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Docker: Github Registry"

on:
push:
branches: [ feat-mqtts ]
mpfeil marked this conversation as resolved.
Show resolved Hide resolved

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=true
prefix=
suffix=

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 2 additions & 1 deletion packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@grpc/grpc-js": "^1.3.7",
"@grpc/proto-loader": "^0.6.4",
"@sensebox/osem-protos": "^1.1.0",
"@sensebox/sketch-templater": "^1.10.5",
"bcrypt": "^5.0.1",
"bunyan": "^1.8.15",
"config": "^3.3.6",
"got": "^11.8.2",
"grpc": "^1.24.7",
"isemail": "^3.0.0",
"jsonpath": "^1.1.1",
"lodash.isequal": "^4.5.0",
Expand Down
7 changes: 6 additions & 1 deletion packages/models/src/box/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const { mongoose } = require('../db'),

const mqttSchema = new mongoose.Schema({
enabled: { type: Boolean, default: false, required: true },
url: { type: String, trim: true, validate: [function validMqttUri (url) { return url === '' || url.startsWith('mqtt://') || url.startsWith('ws://'); }, '{PATH} must be either empty or start with mqtt:// or ws://'] },
url: { type: String, trim: true, validate: [function validMqttUri (url) { return (
url === '' ||
url.startsWith('mqtt://') ||
url.startsWith('mqtts://') ||
url.startsWith('ws://')
); }, '{PATH} must be either empty or start with mqtt(s):// or ws://'] },
topic: { type: String, trim: true },
messageFormat: { type: String, trim: true, enum: ['json', 'csv', 'application/json', 'text/csv', 'debug_plain', ''] },
decodeOptions: { type: String, trim: true, validate: isJSONParseableValidation },
Expand Down
12 changes: 9 additions & 3 deletions packages/models/src/box/mqttClient.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const grpc = require('grpc'),
const protoLoader = require('@grpc/proto-loader'),
grpcLibrary = require('@grpc/grpc-js'),
{ mqttProto } = require('@sensebox/osem-protos'),
log = require('../log'),
config = require('config').get('openSenseMap-API-models');
Expand All @@ -22,9 +23,14 @@ module.exports = {
return;
}

const { MqttService } = grpc.load(mqttProto);
const packageDefinition = protoLoader.loadSync(mqttProto);
const MqttService = grpcLibrary.loadPackageDefinition(packageDefinition).MqttService;

const credentials = grpc.credentials.createSsl(Buffer.from(ca_cert), Buffer.from(key), Buffer.from(cert));
const credentials = grpcLibrary.credentials.createSsl(
Buffer.from(ca_cert),
Buffer.from(key),
Buffer.from(cert)
);

const client = new MqttService(url, credentials);
log.info({ mqttClient: 'connected GRPC client' });
Expand Down
Loading