├── aws-lambda └── serverless │ ├── .dockerignore │ ├── .build │ ├── package.json │ └── src │ │ ├── params.js │ │ ├── params.js.map │ │ ├── messenger.js.map │ │ ├── messenger.js │ │ ├── ieam.js.map │ │ └── ieam.js │ ├── Dockerfile │ ├── tsconfig.json │ ├── serverless.yml │ ├── src │ ├── messenger.ts │ ├── params.ts │ └── ieam.ts │ └── package.json ├── open-horizon ├── common │ └── src │ │ ├── index.ts │ │ ├── interface │ │ ├── index.ts │ │ └── hzn-env-vars.ts │ │ └── utils.ts ├── mms │ ├── examples │ │ ├── config.json │ │ └── object.json │ ├── config │ │ ├── policy.json │ │ ├── hzn.json │ │ ├── config.json │ │ ├── pattern.json │ │ ├── service.json │ │ └── env-hzn.json │ ├── Dockerfile.arm │ ├── Dockerfile.amd64 │ ├── Dockerfile.arm64 │ ├── test.js │ ├── node-mon.js │ ├── package.json │ ├── README.md │ └── scripts │ │ └── env.js ├── config │ ├── mms │ │ ├── policy.json │ │ ├── fyre │ │ │ ├── policy.json │ │ │ ├── config.json │ │ │ ├── pattern.json │ │ │ ├── service.json │ │ │ └── env-hzn.json │ │ ├── nx │ │ │ ├── policy.json │ │ │ ├── config.json │ │ │ ├── pattern.json │ │ │ ├── service.json │ │ │ └── env-hzn.json │ │ ├── pi │ │ │ ├── policy.json │ │ │ ├── config.json │ │ │ ├── pattern.json │ │ │ ├── service.json │ │ │ └── env-hzn.json │ │ ├── config.json │ │ ├── pattern.json │ │ ├── service.json │ │ └── env-hzn.json │ └── service │ │ ├── pi │ │ ├── pattern.json │ │ ├── service.json │ │ └── env-hzn.json │ │ ├── pattern.json │ │ ├── nx │ │ ├── pattern.json │ │ ├── service.json │ │ └── env-hzn.json │ │ ├── fyre │ │ ├── pattern.json │ │ └── service.json │ │ ├── service.json │ │ └── env-hzn.json ├── lib │ ├── mms-deploy.js.LICENSE.txt │ └── service-deploy.js.LICENSE.txt ├── setup │ ├── config │ │ ├── mms │ │ │ ├── policy.json │ │ │ ├── pattern.json │ │ │ └── service.json │ │ └── service │ │ │ ├── pattern.json │ │ │ └── service.json │ ├── Dockerfile-arm │ ├── Dockerfile-amd64 │ ├── Dockerfile-arm64 │ └── mms-docker │ │ ├── config │ │ └── config.json │ │ ├── package.json │ │ └── node-mon.js ├── Dockerfile.arm ├── Dockerfile.amd64 ├── Dockerfile.arm64 ├── services │ ├── config │ │ ├── pattern.json │ │ ├── service.json │ │ └── env-hzn.json │ ├── package.json │ └── scripts │ │ └── env.js ├── mms-docker │ ├── config │ │ └── config.json │ ├── package.json │ └── node-mon.js ├── webpack.config.js ├── src │ ├── service │ │ ├── deploy.ts │ │ └── env.ts │ └── mms │ │ └── env.ts ├── package.json └── README.md ├── cloud-function ├── hzn-action │ ├── .gitignore │ ├── tsconfig.json │ ├── manifest.yaml │ ├── bin │ │ ├── clean.js │ │ ├── switch-account.js │ │ └── deploy.js │ ├── webpack.config.js │ ├── package.json │ └── manifest-api.yaml ├── common │ ├── src │ │ ├── cos-client │ │ │ └── index.ts │ │ ├── db │ │ │ ├── index.ts │ │ │ └── couch-db.ts │ │ ├── utils │ │ │ ├── index.ts │ │ │ ├── messenger.ts │ │ │ └── utility.ts │ │ ├── params │ │ │ ├── index.ts │ │ │ ├── hzn-params.ts │ │ │ ├── api-params.ts │ │ │ └── params.ts │ │ └── index.ts │ ├── tsconfig.json │ └── package.json ├── demo │ ├── README.md │ ├── env-example │ ├── manifest.yaml │ ├── js │ │ └── messenger.js │ ├── tsconfig.json │ ├── bin │ │ ├── clean.js │ │ ├── switch-account.js │ │ ├── build.js │ │ └── deploy.js │ ├── manifest-api.yaml │ ├── package.json │ └── webpack.config.js ├── .gitignore └── README.md ├── code-engine ├── common │ ├── interface │ │ ├── index.ts │ │ └── model.ts │ ├── index.ts │ └── params │ │ ├── index.ts │ │ ├── hzn-params.ts │ │ ├── ldap-params.ts │ │ ├── api-params.ts │ │ └── params.ts ├── ieam-service │ ├── common │ │ ├── index.ts │ │ ├── interface │ │ │ ├── index.ts │ │ │ └── model.ts │ │ ├── params │ │ │ ├── index.ts │ │ │ ├── hzn-params.ts │ │ │ ├── ldap-params.ts │ │ │ ├── api-params.ts │ │ │ └── params.ts │ │ └── utils.ts │ ├── src │ │ └── index.ts │ ├── Dockerfile │ ├── env-example.json │ ├── webpack.config.js │ ├── README.md │ ├── tsconfig.json │ └── package.json ├── edge-slack-bot │ ├── Dockerfile │ ├── manifest.json │ ├── src │ │ └── index.ts │ ├── webpack.config.js │ ├── tsconfig.json │ └── package.json ├── hello-ce │ ├── Dockerfile │ ├── tsconfig.json │ ├── webpack.config.js │ ├── package.json │ ├── src │ │ └── server.ts │ └── bin │ │ └── deploy.js ├── ieam-action │ ├── Dockerfile │ ├── tsconfig.json │ ├── src │ │ ├── params.ts │ │ └── utility.ts │ ├── webpack.config.js │ ├── package.json │ └── bin │ │ └── deploy.js └── example │ ├── package.json │ ├── example_deprecated.js │ ├── README.md │ └── example.js ├── ieam-rhel-edge ├── setup │ ├── Dockerfile │ └── edge.ks └── README.md ├── .gitignore └── README.md /aws-lambda/serverless/.dockerignore: -------------------------------------------------------------------------------- 1 | .build/ -------------------------------------------------------------------------------- /open-horizon/common/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './utils'; -------------------------------------------------------------------------------- /cloud-function/hzn-action/.gitignore: -------------------------------------------------------------------------------- 1 | # System Files 2 | Dockerfile* -------------------------------------------------------------------------------- /code-engine/common/interface/index.ts: -------------------------------------------------------------------------------- 1 | export * from './model'; 2 | -------------------------------------------------------------------------------- /code-engine/ieam-service/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from './utils'; 2 | -------------------------------------------------------------------------------- /open-horizon/common/src/interface/index.ts: -------------------------------------------------------------------------------- 1 | export * from './hzn-env-vars'; -------------------------------------------------------------------------------- /code-engine/ieam-service/common/interface/index.ts: -------------------------------------------------------------------------------- 1 | export * from './model'; 2 | -------------------------------------------------------------------------------- /open-horizon/mms/examples/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "HW_WHO": "from the rpi4" 3 | } 4 | -------------------------------------------------------------------------------- /cloud-function/common/src/cos-client/index.ts: -------------------------------------------------------------------------------- 1 | export * from './cos-client'; 2 | 3 | -------------------------------------------------------------------------------- /code-engine/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from './interface'; 2 | export * from './params'; 3 | -------------------------------------------------------------------------------- /cloud-function/common/src/db/index.ts: -------------------------------------------------------------------------------- 1 | export * from './couch-db'; 2 | export * from './mongo-db'; 3 | -------------------------------------------------------------------------------- /cloud-function/common/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './messenger'; 2 | export * from './utility'; -------------------------------------------------------------------------------- /open-horizon/common/src/interface/hzn-env-vars.ts: -------------------------------------------------------------------------------- 1 | export interface HznEnvVars { 2 | biz: any; 3 | demo: any; 4 | } -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/package.json: -------------------------------------------------------------------------------- 1 | /Users/jeff/git_repo/sandbox/ieam/open-labs/aws-lambda/serverless/package.json -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/src/params.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | //# sourceMappingURL=params.js.map -------------------------------------------------------------------------------- /cloud-function/common/src/params/index.ts: -------------------------------------------------------------------------------- 1 | export * from './params'; 2 | export * from './api-params'; 3 | export * from './hzn-params'; -------------------------------------------------------------------------------- /cloud-function/demo/README.md: -------------------------------------------------------------------------------- 1 | ## 2 | Make a copy of env-example, rename it to .env-local and fill in the values for each environments as needed 3 | -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/src/params.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/params.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /cloud-function/common/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './db'; 2 | export * from './cos-client'; 3 | export * from './params'; 4 | export * from './utils'; 5 | -------------------------------------------------------------------------------- /code-engine/common/params/index.ts: -------------------------------------------------------------------------------- 1 | export * from './params'; 2 | export * from './api-params'; 3 | export * from './hzn-params'; 4 | export * from './ldap-params'; -------------------------------------------------------------------------------- /code-engine/edge-slack-bot/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:16.3.0-alpine 2 | WORKDIR /server 3 | COPY dist/index.js . 4 | EXPOSE 8080 5 | EXPOSE 3003 6 | CMD node index.js -------------------------------------------------------------------------------- /code-engine/hello-ce/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM icr.io/codeengine/node:12-alpine 2 | RUN npm install 3 | COPY dist/hello-ce.js . 4 | EXPOSE 8080 5 | CMD [ "node", "hello-ce.js" ] 6 | -------------------------------------------------------------------------------- /code-engine/ieam-service/common/params/index.ts: -------------------------------------------------------------------------------- 1 | export * from './params'; 2 | export * from './api-params'; 3 | export * from './hzn-params'; 4 | export * from './ldap-params'; -------------------------------------------------------------------------------- /code-engine/ieam-action/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM icr.io/codeengine/node:12-alpine 2 | RUN npm install 3 | COPY dist/ieam-action.js . 4 | EXPOSE 8080 5 | CMD [ "node", "ieam-action.js" ] 6 | -------------------------------------------------------------------------------- /open-horizon/config/mms/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "openhorizon.allowPrivileged", 5 | "value": true 6 | } 7 | ], 8 | "constraints": [ ] 9 | } -------------------------------------------------------------------------------- /open-horizon/mms/config/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "openhorizon.allowPrivileged", 5 | "value": true 6 | } 7 | ], 8 | "constraints": [ ] 9 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/fyre/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "openhorizon.allowPrivileged", 5 | "value": true 6 | } 7 | ], 8 | "constraints": [ ] 9 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/nx/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "openhorizon.allowPrivileged", 5 | "value": true 6 | } 7 | ], 8 | "constraints": [ ] 9 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/pi/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "openhorizon.allowPrivileged", 5 | "value": true 6 | } 7 | ], 8 | "constraints": [ ] 9 | } -------------------------------------------------------------------------------- /open-horizon/lib/mms-deploy.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * async 3 | * https://github.com/caolan/async 4 | * 5 | * Copyright 2010-2014 Caolan McMahon 6 | * Released under the MIT license 7 | */ 8 | -------------------------------------------------------------------------------- /open-horizon/lib/service-deploy.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * async 3 | * https://github.com/caolan/async 4 | * 5 | * Copyright 2010-2014 Caolan McMahon 6 | * Released under the MIT license 7 | */ 8 | -------------------------------------------------------------------------------- /open-horizon/setup/config/mms/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "openhorizon.allowPrivileged", 5 | "value": true 6 | } 7 | ], 8 | "constraints": [ ] 9 | } -------------------------------------------------------------------------------- /aws-lambda/serverless/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:12.20.0-alpine3.10 2 | RUN apk update 3 | WORKDIR /usr/src/app 4 | COPY package*.json ./ 5 | RUN npm install 6 | COPY . . 7 | EXPOSE 3000 8 | CMD [ "npx", "serverless", "offline", "--host", "0.0.0.0" ] 9 | -------------------------------------------------------------------------------- /code-engine/common/params/hzn-params.ts: -------------------------------------------------------------------------------- 1 | import { ApiParams } from './api-params'; 2 | 3 | export interface HznParams extends ApiParams { 4 | type: string; 5 | id: string; 6 | object: string; 7 | pattern: string; 8 | url: string; 9 | } -------------------------------------------------------------------------------- /cloud-function/common/src/params/hzn-params.ts: -------------------------------------------------------------------------------- 1 | import { ApiParams } from "./api-params"; 2 | 3 | export interface HznParams extends ApiParams { 4 | type: string; 5 | id: string; 6 | object: string; 7 | pattern: string; 8 | url: string; 9 | } -------------------------------------------------------------------------------- /code-engine/ieam-service/common/params/hzn-params.ts: -------------------------------------------------------------------------------- 1 | import { ApiParams } from './api-params'; 2 | 3 | export interface HznParams extends ApiParams { 4 | type: string; 5 | id: string; 6 | object: string; 7 | pattern: string; 8 | url: string; 9 | } -------------------------------------------------------------------------------- /code-engine/ieam-service/common/params/ldap-params.ts: -------------------------------------------------------------------------------- 1 | import { HznParams } from './hzn-params'; 2 | 3 | export interface LdapParams extends HznParams { 4 | ibmid: string; 5 | org: string; 6 | baseDN: string; 7 | fname: string; 8 | lname: string; 9 | } -------------------------------------------------------------------------------- /open-horizon/mms/Dockerfile.arm: -------------------------------------------------------------------------------- 1 | FROM alpine:3.10 2 | 3 | RUN apk --no-cache --update add curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY . /server 8 | RUN npm install -g npm 9 | RUN npm install 10 | 11 | CMD ["npm", "start"] 12 | -------------------------------------------------------------------------------- /ieam-rhel-edge/setup/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM registry.access.redhat.com/ubi8/ubi 2 | ARG kickstart 3 | ARG commit 4 | RUN yum -y install httpd && yum clean all 5 | ADD $kickstart /var/www/html/ 6 | ADD $commit /var/www/html/ 7 | EXPOSE 80 8 | CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"] 9 | -------------------------------------------------------------------------------- /open-horizon/Dockerfile.arm: -------------------------------------------------------------------------------- 1 | FROM alpine:3.10 2 | 3 | RUN apk --no-cache --update add curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY mms-docker /server/ 8 | 9 | RUN npm install -g npm 10 | RUN npm install 11 | 12 | CMD ["npm", "start"] 13 | -------------------------------------------------------------------------------- /open-horizon/mms/Dockerfile.amd64: -------------------------------------------------------------------------------- 1 | FROM amd64/alpine:latest 2 | 3 | RUN apk --no-cache --update add jq curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY . /server 8 | RUN npm install -g npm 9 | RUN npm install 10 | 11 | CMD ["npm", "start"] 12 | -------------------------------------------------------------------------------- /open-horizon/mms/Dockerfile.arm64: -------------------------------------------------------------------------------- 1 | FROM arm64v8/alpine:latest 2 | 3 | RUN apk --no-cache --update add jq curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY . /server 8 | RUN npm install -g npm 9 | RUN npm install 10 | 11 | CMD ["npm", "start"] 12 | -------------------------------------------------------------------------------- /open-horizon/setup/Dockerfile-arm: -------------------------------------------------------------------------------- 1 | FROM alpine:3.10 2 | 3 | RUN apk --no-cache --update add curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY mms-docker /server/ 8 | 9 | RUN npm install -g npm 10 | RUN npm install 11 | 12 | CMD ["npm", "start"] 13 | -------------------------------------------------------------------------------- /open-horizon/Dockerfile.amd64: -------------------------------------------------------------------------------- 1 | FROM amd64/alpine:latest 2 | 3 | RUN apk --no-cache --update add jq curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY mms-docker /server/ 8 | 9 | RUN npm install -g npm 10 | RUN npm install 11 | 12 | CMD ["npm", "start"] 13 | -------------------------------------------------------------------------------- /open-horizon/Dockerfile.arm64: -------------------------------------------------------------------------------- 1 | FROM arm64v8/alpine:latest 2 | 3 | RUN apk --no-cache --update add jq curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY mms-docker /server/ 8 | 9 | RUN npm install -g npm 10 | RUN npm install 11 | 12 | CMD ["npm", "start"] 13 | -------------------------------------------------------------------------------- /open-horizon/setup/Dockerfile-amd64: -------------------------------------------------------------------------------- 1 | FROM amd64/alpine:latest 2 | 3 | RUN apk --no-cache --update add jq curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY mms-docker /server/ 8 | 9 | RUN npm install -g npm 10 | RUN npm install 11 | 12 | CMD ["npm", "start"] 13 | -------------------------------------------------------------------------------- /open-horizon/setup/Dockerfile-arm64: -------------------------------------------------------------------------------- 1 | FROM arm64v8/alpine:latest 2 | 3 | RUN apk --no-cache --update add jq curl bash nodejs-current npm procps 4 | 5 | WORKDIR /server 6 | 7 | COPY mms-docker /server/ 8 | 9 | RUN npm install -g npm 10 | RUN npm install 11 | 12 | CMD ["npm", "start"] 13 | -------------------------------------------------------------------------------- /code-engine/common/params/ldap-params.ts: -------------------------------------------------------------------------------- 1 | import { HznParams } from './hzn-params'; 2 | 3 | export interface LdapParams extends HznParams { 4 | ibmid: string; 5 | org: string; 6 | baseDN: string; 7 | fname: string; 8 | lname: string; 9 | company: string; 10 | channel: string; 11 | } -------------------------------------------------------------------------------- /code-engine/edge-slack-bot/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display_information": { 3 | "name": "Edge Bot" 4 | }, 5 | "settings": { 6 | "org_deploy_enabled": false, 7 | "socket_mode_enabled": false, 8 | "is_hosted": false, 9 | "token_rotation_enabled": false 10 | } 11 | } -------------------------------------------------------------------------------- /aws-lambda/serverless/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "sourceMap": true, 4 | "moduleResolution": "node", 5 | "lib": [ 6 | "es5", 7 | "es6", 8 | "dom", 9 | "es2015", 10 | "esnext.asynciterable" 11 | ], 12 | "types" : ["node"] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /open-horizon/config/service/pi/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "$PATTERN_NAME", 3 | "services": [ 4 | { 5 | "serviceUrl": "$SERVICE_NAME", 6 | "serviceOrgid": "$HZN_ORG_ID", 7 | "serviceArch": "$ARCH", 8 | "serviceVersions": [ { "version": "$SERVICE_VERSION" } ] 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /open-horizon/services/config/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "$PATTERN_NAME", 3 | "services": [ 4 | { 5 | "serviceUrl": "$SERVICE_NAME", 6 | "serviceOrgid": "$HZN_ORG_ID", 7 | "serviceArch": "$ARCH", 8 | "serviceVersions": [ { "version": "$SERVICE_VERSION" } ] 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /open-horizon/setup/config/service/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "$PATTERN_NAME", 3 | "services": [ 4 | { 5 | "serviceUrl": "$SERVICE_NAME", 6 | "serviceOrgid": "$HZN_ORG_ID", 7 | "serviceArch": "$ARCH", 8 | "serviceVersions": [ { "version": "$SERVICE_VERSION" } ] 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /open-horizon/config/service/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${SERVICE_NAME}-$ARCH", 3 | "services": [ 4 | { 5 | "serviceUrl": "$SERVICE_NAME", 6 | "serviceOrgid": "$HZN_ORG_ID", 7 | "serviceArch": "$ARCH", 8 | "serviceVersions": [ { "version": "$SERVICE_VERSION" } ] 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /open-horizon/config/service/nx/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${SERVICE_NAME}-$ARCH", 3 | "services": [ 4 | { 5 | "serviceUrl": "$SERVICE_NAME", 6 | "serviceOrgid": "$HZN_ORG_ID", 7 | "serviceArch": "$ARCH", 8 | "serviceVersions": [ { "version": "$SERVICE_VERSION" } ] 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /open-horizon/config/service/fyre/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${SERVICE_NAME}-$ARCH", 3 | "services": [ 4 | { 5 | "serviceUrl": "$SERVICE_NAME", 6 | "serviceOrgid": "$HZN_ORG_ID", 7 | "serviceArch": "$ARCH", 8 | "serviceVersions": [ { "version": "$SERVICE_VERSION" } ] 9 | } 10 | ] 11 | } 12 | 13 | -------------------------------------------------------------------------------- /code-engine/common/params/api-params.ts: -------------------------------------------------------------------------------- 1 | import { Params } from "./params"; 2 | 3 | export interface ApiParams extends Params { 4 | days: string; 5 | language: string; 6 | units: string; 7 | basin: string; 8 | triggerFields: any; 9 | trigger_identity: string; 10 | user: any; 11 | apiKey: string; 12 | insightKey: string; 13 | } -------------------------------------------------------------------------------- /cloud-function/common/src/params/api-params.ts: -------------------------------------------------------------------------------- 1 | import { Params } from "./params"; 2 | 3 | export interface ApiParams extends Params { 4 | days: string; 5 | language: string; 6 | units: string; 7 | basin: string; 8 | triggerFields: any; 9 | trigger_identity: string; 10 | user: any; 11 | apiKey: string; 12 | insightKey: string; 13 | } -------------------------------------------------------------------------------- /code-engine/ieam-service/common/params/api-params.ts: -------------------------------------------------------------------------------- 1 | import { Params } from "./params"; 2 | 3 | export interface ApiParams extends Params { 4 | days: string; 5 | language: string; 6 | units: string; 7 | basin: string; 8 | triggerFields: any; 9 | trigger_identity: string; 10 | user: any; 11 | apiKey: string; 12 | insightKey: string; 13 | } -------------------------------------------------------------------------------- /code-engine/ieam-service/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Server } from './server'; 2 | 3 | const argv: string = process.argv.slice(2).toString() 4 | const match = argv.match(/--port=/) 5 | const port = match ? parseInt(argv.replace(match[0], '')) : 8080; 6 | 7 | export class Index { 8 | server = new Server(port); 9 | constructor() { 10 | 11 | } 12 | } 13 | 14 | new Index() -------------------------------------------------------------------------------- /code-engine/edge-slack-bot/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Server } from './server'; 2 | 3 | const argv: string = process.argv.slice(2).toString() 4 | const match = argv.match(/--port=/) 5 | const port = match ? parseInt(argv.replace(match[0], '')) : 8080; 6 | 7 | export class Index { 8 | server = new Server(port); 9 | constructor() { 10 | 11 | } 12 | } 13 | 14 | new Index() -------------------------------------------------------------------------------- /cloud-function/demo/env-example: -------------------------------------------------------------------------------- 1 | COS_ACCESS={"prod": {"access_key_id": "", "secret_access_key": "", "apikey": "", "resource_instance_id": "", "bucket": ""}, "stage": {"access_key_id": "", "secret_access_key": "", "apikey": "", "resource_instance_id": "", "bucket": "s-stg.w-x.co"}, "dev": {"access_key_id": "", "secret_access_key": "", "apikey": "", "resource_instance_id": "", "bucket": ""}} 2 | -------------------------------------------------------------------------------- /open-horizon/mms/config/hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "HZN_ORG_ID": "biz", 3 | "MetadataVars": { 4 | "DOCKER_IMAGE_BASE": "playbox21/my-mms-service", 5 | "MMS_SERVICE_NAME": "my-mms-service", 6 | "MMS_SERVICE_VERSION": "1.0.0", 7 | "OBJECT_TYPE": "object_detection", 8 | "OBJECT_ID": "config.json", 9 | "SHARED_VOLUME": "/shared_dir", 10 | "YOUR_SERVICE_NAME": "pi" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /code-engine/example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "code-engine-sdk-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "example.js", 6 | "scripts": { 7 | "test": "echo 'No tests'" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@kubernetes/client-node": "^0.13.2", 13 | "axios": "^0.21.1", 14 | "ibm-code-engine-sdk": "^0.1.5" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /ieam-rhel-edge/setup/edge.ks: -------------------------------------------------------------------------------- 1 | lang en_US.UTF-8 2 | keyboard us 3 | timezone America/New_York --isUtc 4 | zerombr 5 | clearpart --all --initlabel 6 | autopart --type=plain --fstype=xfs --nohome 7 | reboot 8 | text 9 | network --bootproto=dhcp 10 | user --name ieam --groups=wheel --password=ieam123 11 | services --enabled=ostree-remount 12 | ostreesetup --nogpg --osname=rhel --url=http://192.168.1.118:8080/repo/ --ref=rhel/8/x86_64/edge 13 | -------------------------------------------------------------------------------- /open-horizon/config/mms/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /open-horizon/mms/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /open-horizon/config/mms/fyre/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /open-horizon/config/mms/nx/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /open-horizon/config/mms/pi/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /open-horizon/mms-docker/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /open-horizon/setup/mms-docker/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "url": "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210901%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210901T130957Z&X-Amz-Expires=1200&X-Amz-Signature=27bc42101324b0cb3d91c8b72fb0cbf131dde3587e9cbdf15577fd0ee6c62ba2&X-Amz-SignedHeaders=host", 3 | "hello": "from the Open Horizon..." 4 | } 5 | -------------------------------------------------------------------------------- /aws-lambda/serverless/serverless.yml: -------------------------------------------------------------------------------- 1 | service: ieam-serverless 2 | 3 | # Add the serverless-webpack plugin 4 | plugins: 5 | - serverless-plugin-typescript 6 | - serverless-offline 7 | 8 | custom: 9 | serverless-offline: 10 | noPrependStageInUrl: true 11 | 12 | provider: 13 | name: aws 14 | runtime: nodejs12.x 15 | 16 | functions: 17 | ieam: 18 | handler: src/ieam.handler 19 | events: 20 | - http: 21 | method: post 22 | path: / 23 | -------------------------------------------------------------------------------- /aws-lambda/serverless/src/messenger.ts: -------------------------------------------------------------------------------- 1 | import { Params } from './params'; 2 | 3 | export class ResponseMessage { 4 | constructor ( 5 | public body: string, 6 | public headers: Object, 7 | public statusCode: number = 200) { 8 | } 9 | } 10 | 11 | export class Messenger { 12 | 13 | constructor (private params: Params) { 14 | } 15 | 16 | send(body: any, contentType = 'application/json'): ResponseMessage { 17 | return new ResponseMessage(JSON.stringify(body), {'Content-Type': contentType}); 18 | } 19 | } -------------------------------------------------------------------------------- /aws-lambda/serverless/src/params.ts: -------------------------------------------------------------------------------- 1 | export interface Params { 2 | message: string; 3 | action: string; 4 | bucket: string; 5 | directory: any; 6 | delimiter: any; 7 | acl: string; 8 | filename: any; 9 | apiKeyId: string; 10 | accessKeyId: string; 11 | secretAccessKey: string; 12 | endpoint: string; 13 | ibmAuthEndpoint: string; 14 | serviceInstanceId: string; 15 | region: string; 16 | cacheControl: string; 17 | body: any; 18 | name: string; 19 | contentType: string; 20 | key: string; 21 | } 22 | -------------------------------------------------------------------------------- /open-horizon/config/mms/nx/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${MMS_SERVICE_NAME}-$ARCH", 3 | "label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH", 4 | "description": "Pattern for $MMS_SERVICE_NAME for $ARCH", 5 | "public": false, 6 | "services": [ 7 | { 8 | "serviceUrl": "$MMS_SERVICE_NAME", 9 | "serviceOrgid": "$HZN_ORG_ID", 10 | "serviceArch": "$ARCH", 11 | "serviceVersions": [ 12 | { 13 | "version": "$MMS_SERVICE_VERSION" 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /open-horizon/config/mms/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${MMS_SERVICE_NAME}-$ARCH", 3 | "label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH", 4 | "description": "Pattern for $MMS_SERVICE_NAME for $ARCH", 5 | "public": false, 6 | "services": [ 7 | { 8 | "serviceUrl": "$MMS_SERVICE_NAME", 9 | "serviceOrgid": "$HZN_ORG_ID", 10 | "serviceArch": "$ARCH", 11 | "serviceVersions": [ 12 | { 13 | "version": "$MMS_SERVICE_VERSION" 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /open-horizon/config/mms/pi/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${MMS_SERVICE_NAME}-$ARCH", 3 | "label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH", 4 | "description": "Pattern for $MMS_SERVICE_NAME for $ARCH", 5 | "public": false, 6 | "services": [ 7 | { 8 | "serviceUrl": "$MMS_SERVICE_NAME", 9 | "serviceOrgid": "$HZN_ORG_ID", 10 | "serviceArch": "$ARCH", 11 | "serviceVersions": [ 12 | { 13 | "version": "$MMS_SERVICE_VERSION" 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /open-horizon/mms/config/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${MMS_SERVICE_NAME}-$ARCH", 3 | "label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH", 4 | "description": "Pattern for $MMS_SERVICE_NAME for $ARCH", 5 | "public": false, 6 | "services": [ 7 | { 8 | "serviceUrl": "$MMS_SERVICE_NAME", 9 | "serviceOrgid": "$HZN_ORG_ID", 10 | "serviceArch": "$ARCH", 11 | "serviceVersions": [ 12 | { 13 | "version": "$MMS_SERVICE_VERSION" 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /open-horizon/config/mms/fyre/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${MMS_SERVICE_NAME}-$ARCH", 3 | "label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH", 4 | "description": "Pattern for $MMS_SERVICE_NAME for $ARCH", 5 | "public": false, 6 | "services": [ 7 | { 8 | "serviceUrl": "$MMS_SERVICE_NAME", 9 | "serviceOrgid": "$HZN_ORG_ID", 10 | "serviceArch": "$ARCH", 11 | "serviceVersions": [ 12 | { 13 | "version": "$MMS_SERVICE_VERSION" 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /open-horizon/setup/config/mms/pattern.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pattern-${MMS_SERVICE_NAME}-$ARCH", 3 | "label": "Edge $MMS_SERVICE_NAME Service Pattern for $ARCH", 4 | "description": "Pattern for $MMS_SERVICE_NAME for $ARCH", 5 | "public": false, 6 | "services": [ 7 | { 8 | "serviceUrl": "$MMS_SERVICE_NAME", 9 | "serviceOrgid": "$HZN_ORG_ID", 10 | "serviceArch": "$ARCH", 11 | "serviceVersions": [ 12 | { 13 | "version": "$MMS_SERVICE_VERSION" 14 | } 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /aws-lambda/serverless/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "serverless", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "ljeff@us.ibm.com", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "@types/aws-lambda": "^8.10.83", 13 | "serverless": "^2.62.0", 14 | "serverless-offline": "^8.2.0", 15 | "serverless-plugin-typescript": "^2.1.0", 16 | "typescript": "^4.4.3" 17 | }, 18 | "dependencies": { 19 | "rxjs": "^7.4.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/src/messenger.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"messenger.js","sourceRoot":"","sources":["../../src/messenger.ts"],"names":[],"mappings":";;;AAEA;IACE,yBACS,IAAY,EACZ,OAAe,EACf,UAAwB;QAAxB,2BAAA,EAAA,gBAAwB;QAFxB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,eAAU,GAAV,UAAU,CAAc;IACjC,CAAC;IACH,sBAAC;AAAD,CAAC,AAND,IAMC;AANY,0CAAe;AAQ5B;IAEE,mBAAqB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IACnC,CAAC;IAED,wBAAI,GAAJ,UAAK,IAAS,EAAE,WAAgC;QAAhC,4BAAA,EAAA,gCAAgC;QAC9C,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAC,cAAc,EAAE,WAAW,EAAC,CAAC,CAAC;IAClF,CAAC;IACH,gBAAC;AAAD,CAAC,AARD,IAQC;AARY,8BAAS"} -------------------------------------------------------------------------------- /cloud-function/hzn-action/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "module": "commonjs", 5 | "target": "ES2017", 6 | "noImplicitAny": false, 7 | "sourceMap": true, 8 | "moduleResolution": "node", 9 | "resolveJsonModule": true, 10 | "outDir": "dist", 11 | "baseUrl": ".", 12 | "paths": { 13 | "@common/*": [ 14 | "../common/src/*" 15 | ] 16 | } 17 | }, 18 | "include": [ 19 | "src/**/*.ts", 20 | "../common/src/**/*.ts" 21 | ] 22 | } -------------------------------------------------------------------------------- /code-engine/hello-ce/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "module": "commonjs", 5 | "target": "ES2017", 6 | "noImplicitAny": false, 7 | "sourceMap": true, 8 | "moduleResolution": "node", 9 | "resolveJsonModule": true, 10 | "outDir": "dist", 11 | "baseUrl": ".", 12 | "paths": { 13 | "@common/*": [ 14 | "../../cloud-function/common/src/*" 15 | ] 16 | } 17 | }, 18 | "include": [ 19 | "src/**/*.ts", 20 | "../../cloud-function/common/src/**/*.ts" 21 | ] 22 | } -------------------------------------------------------------------------------- /code-engine/ieam-action/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "module": "commonjs", 5 | "target": "ES2017", 6 | "noImplicitAny": false, 7 | "sourceMap": true, 8 | "moduleResolution": "node", 9 | "resolveJsonModule": true, 10 | "outDir": "dist", 11 | "baseUrl": ".", 12 | "paths": { 13 | "@common/*": [ 14 | "../../cloud-function/common/src/*" 15 | ] 16 | } 17 | }, 18 | "include": [ 19 | "src/**/*.ts", 20 | "../../cloud-function/common/src/**/*.ts" 21 | ] 22 | } -------------------------------------------------------------------------------- /cloud-function/demo/manifest.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | ${PACKAGE}: 3 | version: 1.0 4 | license: Apache-2.0 5 | actions: 6 | demo-action: 7 | function: dist/demo-action.js 8 | runtime: nodejs:12 9 | web-export: true 10 | limits: 11 | timeout: 60000 12 | memorySize: 256 13 | inputs: 14 | accessKeyId: ${ACCESSKEYID} 15 | secretAccessKey: ${SECRETACCESSKEY} 16 | endpoint: ${COS_ENDPOINT} 17 | ibmAuthEndpoint: ${COS_IBMAUTHENDPOINT} 18 | serviceInstanceId: ${SERVICEINSTANCEID} 19 | region: ${REGION} 20 | bucket: ${BUCKET} -------------------------------------------------------------------------------- /cloud-function/common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "module": "commonjs", 5 | "target": "es6", 6 | "types": [ 7 | "jasmine", 8 | "jasmine-ajax", 9 | "node" 10 | ], 11 | "noImplicitAny": false, 12 | "sourceMap": false, 13 | "moduleResolution": "node", 14 | "outDir": "dist", 15 | "baseUrl": ".", 16 | "paths": { 17 | "*": [ 18 | "node_modules/*", 19 | "src/types/*" 20 | ] 21 | } 22 | }, 23 | "include": [ 24 | "src/**/*.ts", 25 | "node_modules/@types" 26 | ] 27 | } -------------------------------------------------------------------------------- /open-horizon/config/service/nx/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [], 11 | "deployment": { 12 | "services": { 13 | "$SERVICE_NAME": { 14 | "image": "$SERVICE_CONTAINER", 15 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"], 16 | "ports": [ 17 | { "HostIP": "0.0.0.0", "HostPort": "3000:3000/tcp" } 18 | ], 19 | "privileged": true 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /open-horizon/config/service/pi/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [], 11 | "deployment": { 12 | "services": { 13 | "$SERVICE_NAME": { 14 | "image": "$SERVICE_CONTAINER", 15 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"], 16 | "ports": [ 17 | { "HostIP": "0.0.0.0", "HostPort": "3000:3000/tcp" } 18 | ], 19 | "privileged": true 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /open-horizon/config/service/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [], 11 | "deployment": { 12 | "services": { 13 | "$SERVICE_NAME": { 14 | "image": "$SERVICE_CONTAINER", 15 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"], 16 | "ports": [ 17 | { "HostIP": "0.0.0.0", "HostPort": "3000:3000/tcp" } 18 | ], 19 | "privileged": true 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /open-horizon/services/config/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [], 11 | "deployment": { 12 | "services": { 13 | "$SERVICE_NAME": { 14 | "image": "$SERVICE_CONTAINER", 15 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"], 16 | "ports": [ 17 | { "HostIP": "0.0.0.0", "HostPort": "3000:3000/tcp" } 18 | ], 19 | "privileged": true 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /open-horizon/setup/config/service/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [], 11 | "deployment": { 12 | "services": { 13 | "$SERVICE_NAME": { 14 | "image": "$SERVICE_CONTAINER", 15 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"], 16 | "ports": [ 17 | { "HostIP": "0.0.0.0", "HostPort": "3000:3000/tcp" } 18 | ], 19 | "privileged": true 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /code-engine/ieam-service/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14.15.1-alpine 2 | WORKDIR /server 3 | ADD common /server/common 4 | ADD src /server/src 5 | COPY tsconfig.json /server 6 | COPY webpack.config.js /server 7 | COPY package.json /server 8 | RUN npm install &&\ 9 | apk update &&\ 10 | apk upgrade 11 | RUN wget https://github.com/IBM/cloud-pak-cli/releases/latest/download/cloudctl-linux-amd64.tar.gz 12 | RUN wget https://github.com/IBM/cloud-pak-cli/releases/latest/download/cloudctl-linux-amd64.tar.gz.sig 13 | RUN tar -xzf cloudctl-linux-amd64.tar.gz 14 | RUN mv cloudctl-linux-amd64 cloudctl 15 | RUN ls /server/common 16 | RUN ls /server/src 17 | RUN npm run bundle 18 | EXPOSE 8080 19 | CMD node dist/index.js -------------------------------------------------------------------------------- /cloud-function/common/src/utils/messenger.ts: -------------------------------------------------------------------------------- 1 | import { Params } from '../params'; 2 | 3 | export class ResponseMessage { 4 | constructor ( 5 | public data: any, 6 | public headers: Object, 7 | public statusCode: number = 200) { 8 | } 9 | } 10 | 11 | export class Messenger { 12 | 13 | constructor (private params: Params) { 14 | } 15 | 16 | send(body: any, statusCode: number = 200, headers = {'Content-Type': 'application/json'}): ResponseMessage { 17 | return new ResponseMessage(JSON.stringify(body), headers, statusCode); 18 | } 19 | 20 | error(msg: any, status: number = 400, headers = {'Content-Type': 'application/json'}): ResponseMessage { 21 | return new ResponseMessage(msg, headers, status); 22 | } 23 | } -------------------------------------------------------------------------------- /open-horizon/config/service/fyre/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$SERVICE_NAME for $ARCH", 4 | "url": "$SERVICE_NAME", 5 | "version": "$SERVICE_VERSION", 6 | "arch": "$ARCH", 7 | "public": true, 8 | "sharable": "singleton", 9 | "requiredServices": [], 10 | "userInput": [], 11 | "deployment": { 12 | "services": { 13 | "$SERVICE_NAME": { 14 | "image": "$SERVICE_CONTAINER", 15 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw", "/root/certs:/server/certs"], 16 | "ports": [ 17 | { "HostIP": "0.0.0.0", "HostPort": "80:80/tcp" }, 18 | { "HostIP": "0.0.0.0", "HostPort": "443:443/tcp" } 19 | ], 20 | "privileged": true 21 | } 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /code-engine/ieam-action/src/params.ts: -------------------------------------------------------------------------------- 1 | export interface Params { 2 | message: string; 3 | action: string; 4 | bucket: string; 5 | directory: any; 6 | delimiter: any; 7 | acl: string; 8 | filename: any; 9 | apiKeyId: string; 10 | accessKeyId: string; 11 | secretAccessKey: string; 12 | endpoint: string; 13 | ibmAuthEndpoint: string; 14 | serviceInstanceId: string; 15 | region: string; 16 | cacheControl: string; 17 | body: any; 18 | name: string; 19 | contentType: string; 20 | key: string; 21 | path: string; 22 | score: string; 23 | assetType: string; 24 | queryStringParameters: any; 25 | files: any; 26 | url: string; 27 | tableName: string; 28 | sessionId: string; 29 | sig: string; 30 | addr: string; 31 | } 32 | -------------------------------------------------------------------------------- /open-horizon/mms-docker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mms-docker", 3 | "version": "1.0.0", 4 | "description": "Model Management System", 5 | "main": "index.js", 6 | "directories": { 7 | "example": "open-horizon" 8 | }, 9 | "scripts": { 10 | "start": "node node-mon.js", 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/playground/open-labs" 16 | }, 17 | "keywords": [ 18 | "IEAM", 19 | "Open", 20 | "Horizon", 21 | "edge", 22 | "computing", 23 | "MMS", 24 | "Model", 25 | "Management", 26 | "Service" 27 | ], 28 | "author": "ljeff@us.ibm.com", 29 | "license": "ISC", 30 | "dependencies": { 31 | "find-process": "^1.4.4", 32 | "is-zip-file": "^1.0.2" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /open-horizon/setup/mms-docker/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mms-docker", 3 | "version": "1.0.0", 4 | "description": "Model Management System", 5 | "main": "index.js", 6 | "directories": { 7 | "example": "open-horizon" 8 | }, 9 | "scripts": { 10 | "start": "node node-mon.js", 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/playground/open-labs" 16 | }, 17 | "keywords": [ 18 | "IEAM", 19 | "Open", 20 | "Horizon", 21 | "edge", 22 | "computing", 23 | "MMS", 24 | "Model", 25 | "Management", 26 | "Service" 27 | ], 28 | "author": "ljeff@us.ibm.com", 29 | "license": "ISC", 30 | "dependencies": { 31 | "find-process": "^1.4.4", 32 | "is-zip-file": "^1.0.2" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /cloud-function/common/src/params/params.ts: -------------------------------------------------------------------------------- 1 | export interface Params { 2 | message: string; 3 | method: string; 4 | func: string; 5 | bucket: string; 6 | directory: any; 7 | delimiter: string; 8 | acl: string; 9 | filename: any; 10 | files: any[]; 11 | apiKeyId: string; 12 | accessKeyId: string; 13 | secretAccessKey: string; 14 | endpoint: string; 15 | ibmAuthEndpoint: string; 16 | serviceInstanceId: string; 17 | region: string; 18 | cacheControl: string; 19 | body: any; 20 | name: string; 21 | contentType: string; 22 | label: string; 23 | key: string; 24 | date: string; 25 | purge: string; 26 | lat: string; 27 | lng: string; 28 | days: string; 29 | language: string; 30 | units: string; 31 | basin: string; 32 | expires: string; 33 | value: any; 34 | sessionId: string; 35 | sig: string; 36 | addr: string; 37 | } -------------------------------------------------------------------------------- /cloud-function/demo/js/messenger.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.Messenger = exports.ResponseMessage = void 0; 4 | class ResponseMessage { 5 | constructor(data, headers, statusCode = 200) { 6 | this.data = data; 7 | this.headers = headers; 8 | this.statusCode = statusCode; 9 | } 10 | } 11 | exports.ResponseMessage = ResponseMessage; 12 | class Messenger { 13 | constructor(params) { 14 | this.params = params; 15 | } 16 | send(body, statusCode = 200, headers = { 'Content-Type': 'application/json' }) { 17 | return new ResponseMessage(body, headers, statusCode); 18 | } 19 | error(msg, status) { 20 | return new ResponseMessage(msg, { 'Content-Type': 'application/json' }, status); 21 | } 22 | } 23 | exports.Messenger = Messenger; 24 | //# sourceMappingURL=messenger.js.map -------------------------------------------------------------------------------- /cloud-function/demo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "module": "commonjs", 5 | "target": "ES2020", 6 | "noImplicitAny": false, 7 | "sourceMap": true, 8 | "moduleResolution": "node", 9 | "resolveJsonModule": true, 10 | "importHelpers": false, 11 | "forceConsistentCasingInFileNames": true, 12 | "outDir": "dist", 13 | "baseUrl": ".", 14 | "skipLibCheck": true, 15 | "types": [ 16 | "node", 17 | "jest" 18 | ], 19 | "typeRoots": [ 20 | "@types", 21 | "./node_modules/@types" 22 | ], 23 | "paths": { 24 | "@common/*": [ 25 | "../common/src/*" 26 | ] 27 | } 28 | }, 29 | "include": [ 30 | "src/**/*.ts", 31 | "../common/src/**/*.ts" 32 | ] 33 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | data 8 | #/model* 9 | 10 | # dependencies 11 | node_modules 12 | 13 | # IDEs and editors 14 | /.idea 15 | .project 16 | .classpath 17 | .c9/ 18 | *.launch 19 | .settings/ 20 | *.sublime-workspace 21 | *.code-workspace 22 | 23 | # IDE - VSCode 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | 30 | # misc 31 | /.sass-cache 32 | /connect.lock 33 | /coverage 34 | /libpeerconnection.log 35 | npm-debug.log 36 | testem.log 37 | /typings 38 | _timestamp.json 39 | .history/ 40 | 41 | # e2e 42 | /e2e/*.js 43 | /e2e/*.map 44 | 45 | # System Files 46 | .DS_Store 47 | Thumbs.db 48 | .env-* 49 | models 50 | inference_graph 51 | *.zip 52 | *.pem 53 | dist/ 54 | dist-old 55 | history*.txt 56 | notes/ 57 | temp/ 58 | -------------------------------------------------------------------------------- /code-engine/common/params/params.ts: -------------------------------------------------------------------------------- 1 | export interface Params { 2 | message: string; 3 | hash: string; 4 | method: string; 5 | func: string; 6 | bucket: string; 7 | directory: any; 8 | delimiter: string; 9 | acl: string; 10 | filename: any; 11 | files: any[]; 12 | apiKeyId: string; 13 | accessKeyId: string; 14 | secretAccessKey: string; 15 | endpoint: string; 16 | ibmAuthEndpoint: string; 17 | serviceInstanceId: string; 18 | region: string; 19 | cacheControl: string; 20 | body: any; 21 | name: string; 22 | contentType: string; 23 | label: string; 24 | key: string; 25 | date: string; 26 | purge: string; 27 | lat: string; 28 | lng: string; 29 | days: string; 30 | language: string; 31 | units: string; 32 | basin: string; 33 | expires: string; 34 | value: any; 35 | sessionId: string; 36 | sig: string; 37 | addr: string; 38 | url: string; 39 | email: string; 40 | } 41 | -------------------------------------------------------------------------------- /code-engine/ieam-service/common/params/params.ts: -------------------------------------------------------------------------------- 1 | export interface Params { 2 | message: string; 3 | hash: string; 4 | method: string; 5 | func: string; 6 | bucket: string; 7 | directory: any; 8 | delimiter: string; 9 | acl: string; 10 | filename: any; 11 | files: any[]; 12 | apiKeyId: string; 13 | accessKeyId: string; 14 | secretAccessKey: string; 15 | endpoint: string; 16 | ibmAuthEndpoint: string; 17 | serviceInstanceId: string; 18 | region: string; 19 | cacheControl: string; 20 | body: any; 21 | name: string; 22 | contentType: string; 23 | label: string; 24 | key: string; 25 | date: string; 26 | purge: string; 27 | lat: string; 28 | lng: string; 29 | days: string; 30 | language: string; 31 | units: string; 32 | basin: string; 33 | expires: string; 34 | value: any; 35 | sessionId: string; 36 | sig: string; 37 | addr: string; 38 | url: string; 39 | email: string; 40 | } 41 | -------------------------------------------------------------------------------- /cloud-function/hzn-action/manifest.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | ${PACKAGE}: 3 | version: 1.0 4 | license: Apache-2.0 5 | actions: 6 | demo-action: 7 | function: dist/hzn-action.js 8 | runtime: nodejs:12 9 | web-export: true 10 | limits: 11 | timeout: 60000 12 | memorySize: 256 13 | inputs: 14 | speechToTextUsername: ${SPEECH_TO_TEXT_USERNAME} 15 | speechToTextPassword: ${SPEECH_TO_TEXT_PASSWORD} 16 | speechToTextIamApikey: ${SPEECH_TO_TEXT_IAM_APIKEY} 17 | speechToTextUrl: ${SPEECH_TO_TEXT_URL} 18 | textToSpeechUsername: ${TEXT_TO_SPEECH_USERNAME} 19 | textToSpeechPassword: ${TEXT_TO_SPEECH_PASSWORD} 20 | textToSpeechIamApikey: ${TEXT_TO_SPEECH_IAM_APIKEY} 21 | textToSpeechUrl: ${TEXT_TO_SPEECH_URL} 22 | wuSlackBotToken: ${WU_SLACK_BOT_TOKEN} 23 | wusoSlackBotToken: ${WUSO_SLACK_BOT_TOKEN} -------------------------------------------------------------------------------- /cloud-function/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | data 8 | #/model* 9 | 10 | # dependencies 11 | node_modules 12 | 13 | # IDEs and editors 14 | /.idea 15 | .project 16 | .classpath 17 | .c9/ 18 | *.launch 19 | .settings/ 20 | *.sublime-workspace 21 | *.code-workspace 22 | 23 | # IDE - VSCode 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | 30 | # misc 31 | /.sass-cache 32 | /connect.lock 33 | /coverage 34 | /libpeerconnection.log 35 | npm-debug.log 36 | testem.log 37 | /typings 38 | _timestamp.json 39 | .history/ 40 | 41 | # e2e 42 | /e2e/*.js 43 | /e2e/*.map 44 | 45 | # System Files 46 | .DS_Store 47 | Thumbs.db 48 | .env-* 49 | models 50 | inference_graph 51 | *.zip 52 | *.pem 53 | dist 54 | dist-old 55 | history*.txt 56 | notes/ 57 | temp/ 58 | .env* 59 | env-local* 60 | -------------------------------------------------------------------------------- /cloud-function/common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "common", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jasmine-ts --config=jasmine.json", 8 | "testWithCoverage": "nyc -r text -e .ts -x \"tests/*.test.ts\" jasmine-ts --config=jasmine.json" 9 | }, 10 | "author": "ljeff@us.ibm.com", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@ibm-cloud/cloudant": "^0.4.1", 14 | "ibm-cos-sdk": "^1.13.0", 15 | "mongodb": "^5.1.0", 16 | "mongodb-client-encryption": "^2.7.1", 17 | "node-uuid": "^1.4.8", 18 | "rxjs": "^7.8.0" 19 | }, 20 | "devDependencies": { 21 | "@types/jasmine": "^4.3.1", 22 | "@types/jasmine-ajax": "^3.3.3", 23 | "@types/node": "^18.15.5", 24 | "jasmine": "^4.6.0", 25 | "jasmine-ajax": "^4.0.0", 26 | "jasmine-ts": "^0.4.0", 27 | "nyc": "^15.1.0", 28 | "ts-node": "^10.9.1", 29 | "typescript": "^5.0.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /cloud-function/demo/bin/clean.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const path = require('path'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | const fs = require('fs'); 6 | 7 | if(fs.existsSync('./index.js')) { 8 | const file = fs.readFileSync('./index.js').toString().split('\n'); 9 | let output = []; 10 | let match; 11 | file.forEach((line, i) => { 12 | if(line.indexOf('require("@common/') > 0) { 13 | output.push(line.replace('@common/', `./js/`)); 14 | } else if(line.indexOf('exports.default') >= 0) { 15 | output.push(line.replace('exports.default', 'exports.main')); 16 | } else { 17 | output.push(line); 18 | } 19 | }); 20 | let text = output.join('\n'); 21 | // console.log(text); 22 | fs.writeFile('./index.js', text, function (err) { 23 | if (err) { 24 | console.log(err); 25 | process.exit(1); 26 | } 27 | console.log('cleanse index.js'); 28 | output = []; 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /cloud-function/hzn-action/bin/clean.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const path = require('path'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | const fs = require('fs'); 6 | 7 | if(fs.existsSync('./index.js')) { 8 | const file = fs.readFileSync('./index.js').toString().split('\n'); 9 | let output = []; 10 | let match; 11 | file.forEach((line, i) => { 12 | if(line.indexOf('require("@common/') > 0) { 13 | output.push(line.replace('@common/', `./js/`)); 14 | } else if(line.indexOf('exports.default') >= 0) { 15 | output.push(line.replace('exports.default', 'exports.main')); 16 | } else { 17 | output.push(line); 18 | } 19 | }); 20 | let text = output.join('\n'); 21 | // console.log(text); 22 | fs.writeFile('./index.js', text, function (err) { 23 | if (err) { 24 | console.log(err); 25 | process.exit(1); 26 | } 27 | console.log('cleanse index.js'); 28 | output = []; 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/src/messenger.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | exports.Messenger = exports.ResponseMessage = void 0; 4 | var ResponseMessage = /** @class */ (function () { 5 | function ResponseMessage(body, headers, statusCode) { 6 | if (statusCode === void 0) { statusCode = 200; } 7 | this.body = body; 8 | this.headers = headers; 9 | this.statusCode = statusCode; 10 | } 11 | return ResponseMessage; 12 | }()); 13 | exports.ResponseMessage = ResponseMessage; 14 | var Messenger = /** @class */ (function () { 15 | function Messenger(params) { 16 | this.params = params; 17 | } 18 | Messenger.prototype.send = function (body, contentType) { 19 | if (contentType === void 0) { contentType = 'application/json'; } 20 | return new ResponseMessage(JSON.stringify(body), { 'Content-Type': contentType }); 21 | }; 22 | return Messenger; 23 | }()); 24 | exports.Messenger = Messenger; 25 | //# sourceMappingURL=messenger.js.map -------------------------------------------------------------------------------- /code-engine/ieam-service/env-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "prod": { 3 | "HZN_ORG_ID": "think-2023", 4 | "HZN_EXCHANGE_USER_AUTH": "123", 5 | "HZN_FSS_CSSURL": "123", 6 | "HZN_EXCHANGE_URL": "123", 7 | "bucket": "123", 8 | "REGISTRY_ACCESS_SECRET": "myregistry" 9 | }, 10 | "stage": { 11 | "HZN_ORG_ID": "think-2023", 12 | "HZN_EXCHANGE_USER_AUTH": "123", 13 | "HZN_FSS_CSSURL": "123", 14 | "HZN_EXCHANGE_URL": "123", 15 | "bucket": "123", 16 | "REGISTRY_ACCESS_SECRET": "global-registry" 17 | }, 18 | "dev": { 19 | "HZN_ORG_ID": "think-2023", 20 | "HZN_EXCHANGE_USER_AUTH": "123", 21 | "HZN_FSS_CSSURL": "123", 22 | "HZN_EXCHANGE_URL": "123", 23 | "bucket": "123", 24 | "REGISTRY_ACCESS_SECRET": "global-registry" 25 | }, 26 | "local": { 27 | "HZN_ORG_ID": "think-2023", 28 | "HZN_EXCHANGE_USER_AUTH": "123", 29 | "HZN_FSS_CSSURL": "123", 30 | "HZN_EXCHANGE_URL": "123", 31 | "bucket": "123", 32 | "REGISTRY_ACCESS_SECRET": "global-registry" 33 | } 34 | } -------------------------------------------------------------------------------- /open-horizon/mms/test.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const { createWriteStream, unlinkSync } = require('fs'); 3 | const https = require('https'); 4 | const { pipeline } = require('stream'); 5 | const cp = require('child_process'), 6 | exec = cp.exec; 7 | 8 | const tempFile = `${this.sharedVolume}/${this.tempFile}`; 9 | let writableStream = createWriteStream('model.zip'); 10 | let url = "https://weather-labs.s3-api.us-geo.objectstorage.softlayer.net/models/version_2.0/model.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=cbee834cb0994751862d9cfd5c096c6f%2F20210831%2Fus-geo%2Fs3%2Faws4_request&X-Amz-Date=20210831T020008Z&X-Amz-Expires=900&X-Amz-Signature=2131157e353a5cc6f5d0916724ae99cf045eaabb22702f58ca50f4c4461a58c6&X-Amz-SignedHeaders=host" 11 | 12 | https.get(url, (resp) => { 13 | pipeline(resp, writableStream, (err) => { 14 | if(!err) { 15 | console.log('done'); 16 | } else { 17 | console.log(err); 18 | unlinkSync(tempFile) 19 | } 20 | }) 21 | }); 22 | -------------------------------------------------------------------------------- /open-horizon/services/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "services", 3 | "version": "1.0.0", 4 | "description": "Services for IEAM/Open Horizon", 5 | "main": "index.js", 6 | "scripts": { 7 | "deploy": "scripts/deploy.js", 8 | "publish-service": "npm run deploy --task=publishService", 9 | "publish-pattern": "npm run deploy --task=publishPattern", 10 | "show-horizon-info": "npm run deploy --task=showHorizonInfo", 11 | "update-horizon-info": "npm run deploy --task=updateHorizonInfo", 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/playground/open-labs/services" 17 | }, 18 | "keywords": [ 19 | "IEAM", 20 | "Open", 21 | "Horizon", 22 | "edge", 23 | "computing", 24 | "MMS", 25 | "Model", 26 | "Management", 27 | "Service" 28 | ], 29 | "author": "ljeff@us.ibm.com", 30 | "license": "ISC", 31 | "dependencies": { 32 | "prompt": "^1.2.0", 33 | "rxjs": "^7.3.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /open-horizon/config/mms/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$MMS_SERVICE_NAME for $ARCH", 4 | "description": "A MMS example running with node js", 5 | "documentation": "https://github.com/playground/open-labs/master/edge/services/helloworld/README.md", 6 | "url": "$MMS_SERVICE_NAME", 7 | "version": "$MMS_SERVICE_VERSION", 8 | "arch": "$ARCH", 9 | "public": true, 10 | "sharable": "singleton", 11 | "requiredServices": [ 12 | { 13 | "org": "$HZN_ORG_ID", 14 | "url": "$SERVICE_NAME", 15 | "version": "$SERVICE_VERSION", 16 | "arch": "$ARCH" 17 | } 18 | ], 19 | "userInput": [ 20 | { "name": "MMS_OBJECT_TYPE", "label": "", "type": "string", "defaultValue": "$MMS_OBJECT_TYPE" }, 21 | { "name": "MMS_VOLUME_MOUNT", "label": "", "type": "string", "defaultValue": "$VOLUME_MOUNT" }, 22 | { "name": "UPDATE_FILE_NAME", "label": "", "type": "string", "defaultValue": "$UPDATE_FILE_NAME" } 23 | ], 24 | "deployment": { 25 | "services": { 26 | "$MMS_SERVICE_NAME": { 27 | "image": "$MMS_CONTAINER", 28 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"] 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/fyre/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$MMS_SERVICE_NAME for $ARCH", 4 | "description": "A MMS example running with node js", 5 | "documentation": "https://github.com/playground/open-labs/master/edge/services/helloworld/README.md", 6 | "url": "$MMS_SERVICE_NAME", 7 | "version": "$MMS_SERVICE_VERSION", 8 | "arch": "$ARCH", 9 | "public": true, 10 | "sharable": "singleton", 11 | "requiredServices": [ 12 | { 13 | "org": "$HZN_ORG_ID", 14 | "url": "$SERVICE_NAME", 15 | "version": "$SERVICE_VERSION", 16 | "arch": "$ARCH" 17 | } 18 | ], 19 | "userInput": [ 20 | { "name": "MMS_OBJECT_TYPE", "label": "", "type": "string", "defaultValue": "$MMS_OBJECT_TYPE" }, 21 | { "name": "MMS_VOLUME_MOUNT", "label": "", "type": "string", "defaultValue": "$VOLUME_MOUNT" }, 22 | { "name": "UPDATE_FILE_NAME", "label": "", "type": "string", "defaultValue": "$UPDATE_FILE_NAME" } 23 | ], 24 | "deployment": { 25 | "services": { 26 | "$MMS_SERVICE_NAME": { 27 | "image": "$MMS_CONTAINER", 28 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"] 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/nx/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$MMS_SERVICE_NAME for $ARCH", 4 | "description": "A MMS example running with node js", 5 | "documentation": "https://github.com/playground/open-labs/master/edge/services/helloworld/README.md", 6 | "url": "$MMS_SERVICE_NAME", 7 | "version": "$MMS_SERVICE_VERSION", 8 | "arch": "$ARCH", 9 | "public": true, 10 | "sharable": "singleton", 11 | "requiredServices": [ 12 | { 13 | "org": "$HZN_ORG_ID", 14 | "url": "$SERVICE_NAME", 15 | "version": "$SERVICE_VERSION", 16 | "arch": "$ARCH" 17 | } 18 | ], 19 | "userInput": [ 20 | { "name": "MMS_OBJECT_TYPE", "label": "", "type": "string", "defaultValue": "$MMS_OBJECT_TYPE" }, 21 | { "name": "MMS_VOLUME_MOUNT", "label": "", "type": "string", "defaultValue": "$VOLUME_MOUNT" }, 22 | { "name": "UPDATE_FILE_NAME", "label": "", "type": "string", "defaultValue": "$UPDATE_FILE_NAME" } 23 | ], 24 | "deployment": { 25 | "services": { 26 | "$MMS_SERVICE_NAME": { 27 | "image": "$MMS_CONTAINER", 28 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"] 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/pi/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$MMS_SERVICE_NAME for $ARCH", 4 | "description": "A MMS example running with node js", 5 | "documentation": "https://github.com/playground/open-labs/master/edge/services/helloworld/README.md", 6 | "url": "$MMS_SERVICE_NAME", 7 | "version": "$MMS_SERVICE_VERSION", 8 | "arch": "$ARCH", 9 | "public": true, 10 | "sharable": "singleton", 11 | "requiredServices": [ 12 | { 13 | "org": "$HZN_ORG_ID", 14 | "url": "$SERVICE_NAME", 15 | "version": "$SERVICE_VERSION", 16 | "arch": "$ARCH" 17 | } 18 | ], 19 | "userInput": [ 20 | { "name": "MMS_OBJECT_TYPE", "label": "", "type": "string", "defaultValue": "$MMS_OBJECT_TYPE" }, 21 | { "name": "MMS_VOLUME_MOUNT", "label": "", "type": "string", "defaultValue": "$VOLUME_MOUNT" }, 22 | { "name": "UPDATE_FILE_NAME", "label": "", "type": "string", "defaultValue": "$UPDATE_FILE_NAME" } 23 | ], 24 | "deployment": { 25 | "services": { 26 | "$MMS_SERVICE_NAME": { 27 | "image": "$MMS_CONTAINER", 28 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"] 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /open-horizon/setup/config/mms/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$MMS_SERVICE_NAME for $ARCH", 4 | "description": "A MMS example running with node js", 5 | "documentation": "https://github.com/playground/open-labs/master/edge/services/helloworld/README.md", 6 | "url": "$MMS_SERVICE_NAME", 7 | "version": "$MMS_SERVICE_VERSION", 8 | "arch": "$ARCH", 9 | "public": true, 10 | "sharable": "singleton", 11 | "requiredServices": [ 12 | { 13 | "org": "$HZN_ORG_ID", 14 | "url": "$SERVICE_NAME", 15 | "version": "$SERVICE_VERSION", 16 | "arch": "$ARCH" 17 | } 18 | ], 19 | "userInput": [ 20 | { "name": "MMS_OBJECT_TYPE", "label": "", "type": "string", "defaultValue": "$MMS_OBJECT_TYPE" }, 21 | { "name": "MMS_VOLUME_MOUNT", "label": "", "type": "string", "defaultValue": "$VOLUME_MOUNT" }, 22 | { "name": "UPDATE_FILE_NAME", "label": "", "type": "string", "defaultValue": "$UPDATE_FILE_NAME" } 23 | ], 24 | "deployment": { 25 | "services": { 26 | "$MMS_SERVICE_NAME": { 27 | "image": "$MMS_CONTAINER", 28 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"] 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /open-horizon/mms/config/service.json: -------------------------------------------------------------------------------- 1 | { 2 | "org": "$HZN_ORG_ID", 3 | "label": "$MMS_SERVICE_NAME for $ARCH", 4 | "description": "A MMS example running with node js", 5 | "documentation": "https://github.com/playground/open-labs/master/edge/services/helloworld/README.md", 6 | "url": "$MMS_SERVICE_NAME", 7 | "version": "$MMS_SERVICE_VERSION", 8 | "arch": "$ARCH", 9 | "public": true, 10 | "sharable": "singleton", 11 | "requiredServices": [ 12 | { 13 | "org": "$HZN_ORG_ID", 14 | "url": "$YOUR_SERVICE_NAME", 15 | "version": "$YOUR_SERVICE_VERSION", 16 | "arch": "$ARCH" 17 | } 18 | ], 19 | "userInput": [ 20 | { "name": "MMS_OBJECT_TYPE", "label": "", "type": "string", "defaultValue": "$MMS_OBJECT_TYPE" }, 21 | { "name": "MMS_VOLUME_MOUNT", "label": "", "type": "string", "defaultValue": "$VOLUME_MOUNT" }, 22 | { "name": "UPDATE_FILE_NAME", "label": "", "type": "string", "defaultValue": "$UPDATE_FILE_NAME" } 23 | ], 24 | "deployment": { 25 | "services": { 26 | "$MMS_SERVICE_NAME": { 27 | "image": "$MMS_CONTAINER", 28 | "binds": ["$MMS_SHARED_VOLUME:$VOLUME_MOUNT:rw"] 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /cloud-function/README.md: -------------------------------------------------------------------------------- 1 | # IBM Cloud Functions 2 | Set up local environment 3 | 4 | ### 5 | Install ibmcloud cli - https://cloud.ibm.com/docs/cli?topic=cloud-cli-getting-started 6 | 7 | ### Install wskdeploy 8 | brew install wskdeploy 9 | 10 | ### ibmcloud plugins 11 | ibmcloud plugin repo-plugins -r "IBM Cloud" 12 | ibmcloud plugin install cloud-functions 13 | 14 | ibmcloud plugin list 15 | Plugin Name Version Status Private endpoints supported 16 | cloud-functions/wsk/functions/fn 1.0.49 Update Available false 17 | cloud-object-storage 1.2.1 Update Available false 18 | container-registry 0.1.497 Update Available false 19 | sdk-gen 0.1.12 false 20 | 21 | 22 | ### Token expired 23 | delete /Users//.wskprops then run "ibmcloud fn package list" 24 | 25 | ### Environment variables for COS 26 | Make a copy of env-example, rename it to .env-local and fill in the values for each environment as needed 27 | 28 | ### Demo Cloud Functions 29 | demo-action in demo folder provides examples of GET, POST and interacting with COS Buckets. -------------------------------------------------------------------------------- /cloud-function/demo/manifest-api.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | ${PACKAGE}: 3 | version: 1.0 4 | license: Apache-2.0 5 | actions: 6 | demo-action: 7 | function: dist/demo-action.js 8 | runtime: nodejs:12 9 | web-export: true 10 | limits: 11 | timeout: 60000 12 | memorySize: 256 13 | inputs: 14 | accessKeyId: ${ACCESSKEYID} 15 | secretAccessKey: ${SECRETACCESSKEY} 16 | endpoint: ${COS_ENDPOINT} 17 | ibmAuthEndpoint: ${COS_IBMAUTHENDPOINT} 18 | serviceInstanceId: ${SERVICEINSTANCEID} 19 | region: ${REGION} 20 | bucket: ${BUCKET} 21 | apis: 22 | demo-api-gateway: 23 | demo: 24 | demo_get: 25 | demo-action: 26 | method: GET 27 | response: json 28 | demo_post: 29 | demo-action: 30 | method: POST 31 | response: json 32 | demo_cos_list: 33 | demo-action: 34 | method: POST 35 | response: json 36 | demo_cos_upload: 37 | demo-action: 38 | method: POST 39 | response: json 40 | -------------------------------------------------------------------------------- /open-horizon/mms/node-mon.js: -------------------------------------------------------------------------------- 1 | const findProcess = require('find-process'); 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | 5 | let timer; 6 | 7 | const find = (name) => { 8 | findProcess('name', name, true) 9 | .then(function (list) { 10 | if(!list.find(exist)) { 11 | clearInterval(timer); 12 | let child = exec('node index.js', {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 13 | console.log('restarting node index.js') 14 | console.log('there are %s node process(es)', list.length); 15 | sleep(5000).then(() => { 16 | setCheckInterval(10000); 17 | }) 18 | }); 19 | child.stdout.pipe(process.stdout); 20 | child.on('data', (data) => { 21 | console.log(data) 22 | }) 23 | child.on('error', (err) => { 24 | console.llog(err) 25 | }) 26 | } 27 | }); 28 | } 29 | 30 | const exist = (instance) => { 31 | return instance.cmd === 'node index.js'; 32 | } 33 | 34 | const setCheckInterval = (ms) => { 35 | timer = setInterval(() => { 36 | find('node'); 37 | }, ms); 38 | }; 39 | 40 | const sleep = (ms) => { 41 | return new Promise(resolve => setTimeout(resolve, ms)); 42 | } 43 | 44 | find('node'); 45 | -------------------------------------------------------------------------------- /open-horizon/mms-docker/node-mon.js: -------------------------------------------------------------------------------- 1 | const findProcess = require('find-process'); 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | 5 | let timer; 6 | 7 | const find = (name) => { 8 | findProcess('name', name, true) 9 | .then(function (list) { 10 | if(!list.find(exist)) { 11 | clearInterval(timer); 12 | let child = exec('node index.js', {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 13 | console.log('restarting node index.js') 14 | console.log('there are %s node process(es)', list.length); 15 | sleep(5000).then(() => { 16 | setCheckInterval(10000); 17 | }) 18 | }); 19 | child.stdout.pipe(process.stdout); 20 | child.on('data', (data) => { 21 | console.log(data) 22 | }) 23 | child.on('error', (err) => { 24 | console.llog(err) 25 | }) 26 | } 27 | }); 28 | } 29 | 30 | const exist = (instance) => { 31 | return instance.cmd === 'node index.js'; 32 | } 33 | 34 | const setCheckInterval = (ms) => { 35 | timer = setInterval(() => { 36 | find('node'); 37 | }, ms); 38 | }; 39 | 40 | const sleep = (ms) => { 41 | return new Promise(resolve => setTimeout(resolve, ms)); 42 | } 43 | 44 | find('node'); 45 | -------------------------------------------------------------------------------- /open-horizon/setup/mms-docker/node-mon.js: -------------------------------------------------------------------------------- 1 | const findProcess = require('find-process'); 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | 5 | let timer; 6 | 7 | const find = (name) => { 8 | findProcess('name', name, true) 9 | .then(function (list) { 10 | if(!list.find(exist)) { 11 | clearInterval(timer); 12 | let child = exec('node index.js', {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 13 | console.log('restarting node index.js') 14 | console.log('there are %s node process(es)', list.length); 15 | sleep(5000).then(() => { 16 | setCheckInterval(10000); 17 | }) 18 | }); 19 | child.stdout.pipe(process.stdout); 20 | child.on('data', (data) => { 21 | console.log(data) 22 | }) 23 | child.on('error', (err) => { 24 | console.llog(err) 25 | }) 26 | } 27 | }); 28 | } 29 | 30 | const exist = (instance) => { 31 | return instance.cmd === 'node index.js'; 32 | } 33 | 34 | const setCheckInterval = (ms) => { 35 | timer = setInterval(() => { 36 | find('node'); 37 | }, ms); 38 | }; 39 | 40 | const sleep = (ms) => { 41 | return new Promise(resolve => setTimeout(resolve, ms)); 42 | } 43 | 44 | find('node'); 45 | -------------------------------------------------------------------------------- /code-engine/ieam-service/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const { ContextReplacementPlugin, IgnorePlugin } = require('webpack'); 4 | const dist = 'dist'; // be aware 'dist' folder is also used for tsconfig output 5 | const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); 6 | 7 | var nodeModules = {}; 8 | 9 | module.exports = { 10 | entry: { 11 | 'index': `./src/index.ts` 12 | }, 13 | output: { 14 | path: path.resolve(__dirname, dist), 15 | filename: '[name].js', 16 | }, 17 | module: { 18 | rules: [ 19 | { 20 | test: /\.tsx?$/, 21 | use: 'ts-loader', 22 | use: { 23 | loader: 'ts-loader', 24 | options: { 25 | transpileOnly: true 26 | } 27 | }, 28 | exclude: /node_modules/ 29 | } 30 | ], 31 | }, 32 | plugins: [ 33 | ], 34 | resolve: { 35 | extensions: ['.js', '.ts', '.tsx', '.json'], 36 | plugins: [ 37 | new TsconfigPathsPlugin({ configFile: "./tsconfig.json" }) 38 | ], 39 | alias: { 40 | '@common/*': 'common' 41 | } 42 | }, 43 | externals: nodeModules, 44 | mode: 'production', 45 | target: 'node', 46 | node: { 47 | __dirname: true 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /code-engine/ieam-action/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const CopyPlugin = require('copy-webpack-plugin'); 4 | const { TsConfigPathsPlugin } = require('awesome-typescript-loader'); 5 | const { ContextReplacementPlugin, IgnorePlugin } = require('webpack'); 6 | const dist = 'dist'; // be aware 'dist' folder is also used for tsconfig output 7 | 8 | var nodeModules = {}; 9 | 10 | module.exports = { 11 | entry: { 12 | 'ieam-action': `./src/ieam-action.ts` 13 | }, 14 | output: { 15 | path: path.resolve(__dirname, dist), 16 | filename: '[name].js', 17 | }, 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.tsx?$/, 22 | use: { 23 | loader: 'ts-loader', 24 | options: { 25 | transpileOnly: true 26 | } 27 | }, 28 | exclude: /node_modules/ 29 | } 30 | ], 31 | }, 32 | plugins: [ 33 | new CopyPlugin([ 34 | ]) 35 | ], 36 | resolve: { 37 | extensions: ['.js', '.ts', '.tsx', '.json'], 38 | plugins: [ 39 | new TsConfigPathsPlugin({configFile: './tsconfig.json'}) 40 | ], 41 | alias: { 42 | '@common/*': '../common/src' 43 | } 44 | }, 45 | externals: nodeModules, 46 | mode: 'production', 47 | target: 'node', 48 | node: { 49 | __dirname: true 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /code-engine/edge-slack-bot/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const { ContextReplacementPlugin, IgnorePlugin } = require('webpack'); 4 | const dist = 'dist'; // be aware 'dist' folder is also used for tsconfig output 5 | const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); 6 | 7 | var nodeModules = { 8 | bufferutil: "bufferutil", 9 | "utf-8-validate": "utf-8-validate", 10 | }; 11 | 12 | module.exports = { 13 | entry: { 14 | 'index': `./src/index.ts` 15 | }, 16 | output: { 17 | path: path.resolve(__dirname, dist), 18 | filename: '[name].js', 19 | }, 20 | module: { 21 | rules: [ 22 | { 23 | test: /\.tsx?$/, 24 | use: 'ts-loader', 25 | use: { 26 | loader: 'ts-loader', 27 | options: { 28 | transpileOnly: true 29 | } 30 | }, 31 | exclude: /node_modules/ 32 | } 33 | ], 34 | }, 35 | plugins: [ 36 | ], 37 | resolve: { 38 | extensions: ['.js', '.ts', '.tsx', '.json'], 39 | plugins: [ 40 | new TsconfigPathsPlugin({ configFile: "./tsconfig.json" }) 41 | ], 42 | alias: { 43 | '@common/*': '../common' 44 | } 45 | }, 46 | externals: nodeModules, 47 | mode: 'production', 48 | target: 'node', 49 | node: { 50 | __dirname: true 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /open-horizon/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const dist = 'lib'; // be aware 'dist' folder is also used for tsconfig output 3 | const TsConfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); 4 | const webpack = require('webpack'); 5 | const nodeExternals = require('webpack-node-externals'); 6 | 7 | var nodeModules = {}; 8 | 9 | module.exports = { 10 | entry: { 11 | 'mms-deploy': `./src/mms/deploy.ts`, 12 | 'service-deploy': `./src/service/deploy.ts` 13 | }, 14 | output: { 15 | path: path.resolve(__dirname, dist), 16 | filename: '[name].js', 17 | }, 18 | module: { 19 | rules: [ 20 | { 21 | test: /\.tsx?$/, 22 | use: { 23 | loader: 'ts-loader', 24 | options: { 25 | transpileOnly: true 26 | } 27 | }, 28 | exclude: /node_modules/ 29 | } 30 | ], 31 | }, 32 | plugins: [ 33 | new webpack.BannerPlugin({ 34 | banner: '#!/usr/bin/env node', 35 | raw: true 36 | }) 37 | ], 38 | resolve: { 39 | extensions: ['.js', '.ts', '.tsx', '.json'], 40 | plugins: [ 41 | new TsConfigPathsPlugin({configFile: './tsconfig.json'}) 42 | ], 43 | alias: { 44 | '@common/*': 'common/src' 45 | } 46 | }, 47 | externals: [nodeModules], 48 | mode: 'production', 49 | target: 'node', 50 | node: { 51 | __dirname: true 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /cloud-function/common/src/db/couch-db.ts: -------------------------------------------------------------------------------- 1 | import { CloudantV1 } from '@ibm-cloud/cloudant'; 2 | import { Observable } from 'rxjs'; 3 | 4 | class CouchDBClass { 5 | cloudant: any; 6 | db: any; 7 | constructor(dbName) { 8 | let params = { 9 | url: 'https://d44a1815-07de-4807-bd7a-baf4b9adc1c4-bluemix:2808e309234a627482f093ca8880266394522d2b89c456ec3706cfd40aec3111@d44a1815-07de-4807-bd7a-baf4b9adc1c4-bluemix.cloudantnosqldb.appdomain.cloud' 10 | }; 11 | this.cloudant = CloudantV1.newInstance(params); 12 | this.db = this.cloudant.db.use(dbName); 13 | } 14 | 15 | dbFind(query) { 16 | return Observable.create((observer) => { 17 | this.db.find(query, (err, data) => { 18 | if (err) { 19 | console.log('$$$cloudant:err', err); 20 | observer.error(err); 21 | } 22 | else { 23 | observer.next(data); 24 | observer.complete(); 25 | } 26 | }); 27 | }); 28 | } 29 | 30 | index(field) { 31 | let first_name = {name:'time', type:'json', index:{fields:['time']}} 32 | return new Promise((resolve, reject) => { 33 | this.db.index(field, (err, response) => { 34 | if (err) { 35 | reject(err); 36 | } 37 | console.log('Index creation result: %s', response.result); 38 | resolve(response); 39 | }); 40 | }); 41 | } 42 | } 43 | 44 | export const CouchDB = CouchDBClass; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Open Labs 2 | Open Labs is a playground where I try out different technologies. This is also a place where I will share my experiences and findings. 3 | 4 | ### Traiing ML models with TensorflowJS 5 | * https://github.com/playground/tfjs-pipeline 6 | 7 | ### Edge Computing with IEAM/Open Horizon 8 | https://github.com/playground/tfjs-object-detection 9 | * ML/AI worker safety Demo with MMS(Model Management System) 10 | * With express web server https://github.com/playground/tfjs-object-detection/tree/main/saved-model-service 11 | * with AWS Lambda offline https://github.com/playground/tfjs-object-detection/tree/main/aws-serverless 12 | 13 | ### HZN Toolkit for Model Management System (MMS) & Service Deployment for IEAM/Open Horizon Agent 14 | * Use makefille to manage deployment https://github.com/playground/open-labs/tree/main/open-horizon 15 | * Use Node JS too manage deployment https://github.com/playground/hzn-cli 16 | 17 | ### Edge Computing with IEAM/RHEL for Edge 18 | * https://github.com/playground/open-labs/tree/main/ieam-rhel-edge 19 | 20 | [![Watch the video](https://i9.ytimg.com/vi/5UaxlHa1P2U/mq3.jpg?sqp=CJiKmo0G&rs=AOn4CLBcddkPtX-9UXKiec9kp_Z-a3i6dA)](https://youtu.be/5UaxlHa1P2U) 21 | 22 | ### hzn-cli toolkit for NodeJS developers to work with IEAM/Open Horizon 23 | * https://github.com/playground/hzn-cli 24 | 25 | ### IBM Cloud Fuctions 26 | * https://github.com/playground/open-labs/tree/main/cloud-function 27 | -------------------------------------------------------------------------------- /aws-lambda/serverless/src/ieam.ts: -------------------------------------------------------------------------------- 1 | // export const hello = (event, context, cb) => cb(null, 2 | // { message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!', event } 3 | // ); 4 | import { Observable, of } from 'rxjs'; 5 | import { Messenger } from './messenger'; 6 | import { Params } from './params'; 7 | 8 | export const handler = (params: Params, context, callback) => { 9 | Object.assign(params, params.body); 10 | params.contentType = params.contentType ? params.contentType : 'application/json'; 11 | const response = new Messenger(params); 12 | action.exec(params) 13 | .subscribe((data) => { 14 | callback(null, response.send(data)); 15 | }) 16 | } 17 | 18 | let action = { 19 | exec: (params: Params) => { 20 | try { 21 | const ct = null; 22 | params.body = params.body ? JSON.parse(params.body) : null; 23 | let method = params.body ? params.body.action : null; 24 | console.log('$$$params', method) 25 | return (action[method] || action.default)(params); 26 | } catch(e) { 27 | return of({data: e}); 28 | } 29 | }, 30 | sayHi: (params: Params) => { 31 | return new Observable((observer) => { 32 | observer.next(`Hello!`); 33 | observer.complete(); 34 | }); 35 | }, 36 | default: (params: Params) => { 37 | return new Observable((observer) => { 38 | console.log('$$$params', params) 39 | observer.next(`Method ${params.action} not found.`); 40 | observer.complete(); 41 | }); 42 | } 43 | } -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/src/ieam.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"ieam.js","sourceRoot":"","sources":["../../src/ieam.ts"],"names":[],"mappings":";;;AAAA,wDAAwD;AACxD,wGAAwG;AACxG,KAAK;AACL,6BAAsC;AACtC,yCAAwC;AAGjC,IAAM,OAAO,GAAG,UAAC,MAAc,EAAE,OAAO,EAAE,QAAQ;IACvD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAClF,IAAM,QAAQ,GAAG,IAAI,qBAAS,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SAClB,SAAS,CAAC,UAAC,IAAI;QACd,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AARY,QAAA,OAAO,WAQnB;AAED,IAAI,MAAM,GAAG;IACX,IAAI,EAAE,UAAC,MAAc;QACnB,IAAI;YACF,IAAM,EAAE,GAAG,IAAI,CAAC;YAChB,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC3D,IAAI,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;YACrD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;YAChC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,SAAO,CAAA,CAAC,CAAC,MAAM,CAAC,CAAC;SACnD;QAAC,OAAM,CAAC,EAAE;YACT,OAAO,IAAA,SAAE,EAAC,EAAC,IAAI,EAAE,CAAC,EAAC,CAAC,CAAC;SACtB;IACH,CAAC;IACD,KAAK,EAAE,UAAC,MAAc;QACpB,OAAO,IAAI,iBAAU,CAAC,UAAC,QAAQ;YAC7B,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxB,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,SAAO,EAAE,UAAC,MAAc;QACtB,OAAO,IAAI,iBAAU,CAAC,UAAC,QAAQ;YAC7B,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;YAChC,QAAQ,CAAC,IAAI,CAAC,YAAU,MAAM,CAAC,MAAM,gBAAa,CAAC,CAAC;YACpD,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA"} -------------------------------------------------------------------------------- /code-engine/hello-ce/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const CopyPlugin = require('copy-webpack-plugin'); 4 | const { TsConfigPathsPlugin } = require('awesome-typescript-loader'); 5 | const { ContextReplacementPlugin, IgnorePlugin } = require('webpack'); 6 | const dist = 'dist'; // be aware 'dist' folder is also used for tsconfig output 7 | 8 | var nodeModules = {}; 9 | // fs.readdirSync('node_modules') 10 | // .filter(function(x) { 11 | // return ['.bin'].indexOf(x) === -1; 12 | // }) 13 | // .forEach(function(mod) { 14 | // nodeModules[mod] = 'commonjs ' + mod; 15 | // }); 16 | 17 | module.exports = { 18 | entry: { 19 | 'hello-ce': `./src/server.ts` 20 | }, 21 | output: { 22 | path: path.resolve(__dirname, dist), 23 | filename: '[name].js', 24 | }, 25 | module: { 26 | rules: [ 27 | { 28 | test: /\.tsx?$/, 29 | use: { 30 | loader: 'ts-loader', 31 | options: { 32 | transpileOnly: true 33 | } 34 | }, 35 | exclude: /node_modules/ 36 | } 37 | ], 38 | }, 39 | plugins: [ 40 | new CopyPlugin([ 41 | ]) 42 | ], 43 | resolve: { 44 | extensions: ['.js', '.ts', '.tsx', '.json'], 45 | plugins: [ 46 | new TsConfigPathsPlugin({configFile: './tsconfig.json'}) 47 | ], 48 | alias: { 49 | '@common/*': '../common/src' 50 | } 51 | }, 52 | externals: nodeModules, 53 | mode: 'production', 54 | target: 'node', 55 | node: { 56 | __dirname: true 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /cloud-function/hzn-action/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const CopyPlugin = require('copy-webpack-plugin'); 4 | const { TsConfigPathsPlugin } = require('awesome-typescript-loader'); 5 | const { ContextReplacementPlugin, IgnorePlugin } = require('webpack'); 6 | const dist = 'dist'; // be aware 'dist' folder is also used for tsconfig output 7 | 8 | var nodeModules = {}; 9 | // fs.readdirSync('node_modules') 10 | // .filter(function(x) { 11 | // return ['.bin'].indexOf(x) === -1; 12 | // }) 13 | // .forEach(function(mod) { 14 | // nodeModules[mod] = 'commonjs ' + mod; 15 | // }); 16 | 17 | module.exports = { 18 | entry: { 19 | 'hzn-action': `./src/hzn-action.ts` 20 | }, 21 | output: { 22 | path: path.resolve(__dirname, dist), 23 | filename: '[name].js', 24 | }, 25 | module: { 26 | rules: [ 27 | { 28 | test: /\.tsx?$/, 29 | use: { 30 | loader: 'ts-loader', 31 | options: { 32 | transpileOnly: true 33 | } 34 | }, 35 | exclude: /node_modules/ 36 | } 37 | ], 38 | }, 39 | plugins: [ 40 | new CopyPlugin([ 41 | ]) 42 | ], 43 | resolve: { 44 | extensions: ['.js', '.ts', '.tsx', '.json'], 45 | plugins: [ 46 | new TsConfigPathsPlugin({configFile: './tsconfig.json'}) 47 | ], 48 | alias: { 49 | '@common/*': '../common/src' 50 | } 51 | }, 52 | externals: nodeModules, 53 | mode: 'production', 54 | target: 'node', 55 | node: { 56 | __dirname: true 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /code-engine/hello-ce/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-ce", 3 | "version": "1.0.0", 4 | "description": "Say hello to Code Engine", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "npm run tsc", 8 | "build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", 9 | "tsc": "tsc", 10 | "test": "mocha -r ts-node/register test/functionsTest.ts", 11 | "bundle": "webpack --config webpack.config.js", 12 | "build:doall": "npm run build:image && npm run build:push && npm run deploy", 13 | "build:image": "npm run build && npm run bundle && npm run wskdeploy --task=build", 14 | "build:push": "npm run wskdeploy --task=push", 15 | "deploy": "npm run wskdeploy --task=deploy", 16 | "deploy-dev": "npm run deploy --task=deployTS --package=demo --env=ieam-dev", 17 | "deploy-dev-api": "npm run deploy --task=deploy --package=demo --env=ieam-dev --api=true", 18 | "wskdeploy": "bin/deploy.js" 19 | }, 20 | "author": "ljeff@us.ibm.com", 21 | "license": "ISC", 22 | "dependencies": { 23 | "rxjs": "^7.5.5" 24 | }, 25 | "devDependencies": { 26 | "@types/node": "^16.4.12", 27 | "@typescript-eslint/parser": "^4.29.0", 28 | "awesome-typescript-loader": "^5.2.1", 29 | "copy-webpack-plugin": "^5.0.1", 30 | "dotenv": "^10.0.0", 31 | "jsonfile": "^6.1.0", 32 | "nodemon": "^2.0.12", 33 | "ts-loader": "^9.2.5", 34 | "ts-node": "^10.1.0", 35 | "typescript": "^3.9.10", 36 | "webpack": "^5.49.0", 37 | "webpack-cli": "^4.7.2", 38 | "webpack-node-externals": "^3.0.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /open-horizon/mms/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mms", 3 | "version": "1.0.0", 4 | "description": "Model Management System", 5 | "main": "index.js", 6 | "directories": { 7 | "example": "examples" 8 | }, 9 | "scripts": { 10 | "start": "node node-mon.js", 11 | "deploy": "scripts/deploy.js", 12 | "build": "npm run deploy --task=build", 13 | "push": "npm run deploy --task=push", 14 | "publish-service": "npm run deploy --task=publishService", 15 | "publish-pattern": "npm run deploy --task=publishPattern", 16 | "agent-run": "npm run deploy --task=agentRun", 17 | "publish-object": "npm run deploy --task=publishObject", 18 | "register-agent": "npm run deploy --task=registerAgent", 19 | "unregister-agent": "npm run deploy --task=unregisterAgent", 20 | "show-horizon-info": "npm run deploy --task=showHorizonInfo", 21 | "update-horizon-info": "npm run deploy --task=updateHorizonInfo", 22 | "list-service": "npm run deploy --task=listService", 23 | "list-pattern": "npm run deploy --task=listPattern", 24 | "test": "echo \"Error: no test specified\" && exit 1" 25 | }, 26 | "repository": { 27 | "type": "git", 28 | "url": "https://github.com/playground/open-labs/mms" 29 | }, 30 | "keywords": [ 31 | "IEAM", 32 | "Open", 33 | "Horizon", 34 | "edge", 35 | "computing", 36 | "MMS", 37 | "Model", 38 | "Management", 39 | "Service" 40 | ], 41 | "author": "ljeff@us.ibm.com", 42 | "license": "ISC", 43 | "dependencies": { 44 | "find-process": "^1.4.4", 45 | "is-zip-file": "^1.0.2", 46 | "jsonfile": "^6.1.0", 47 | "prompt": "^1.2.0", 48 | "rxjs": "^7.1.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /code-engine/ieam-service/README.md: -------------------------------------------------------------------------------- 1 | # IBM Code Engine for IEAM Service 2 | Set up local environment 3 | 4 | ## Create IBM Cloud account 5 | https://www.ibm.com/cloud 6 | 7 | ## Install ibmcloud CLI 8 | https://cloud.ibm.com/docs/cli?topic=cloud-cli-getting-started 9 | 10 | ## Local environment setup 11 | ### ibmcloud plugins 12 | - ibmcloud plugin repo-plugins -r "IBM Cloud" 13 | - ibmcloud plugin install code-engine container-registry 14 | 15 | ### Show list of plugins installed 16 | - ibmcloud plugin list 17 | ``` 18 | Plugin Name Version Status Private endpoints supported 19 | cloud-object-storage 1.6.0 false 20 | code-engine[ce] 1.42.0 Update Available true 21 | container-registry[cr] 1.0.6 true 22 | ``` 23 | 24 | ### Login 25 | - ibmcloud login --sso 26 | - ibmcloud target -g Default 27 | - ibmcloud ce project create --name ieam 28 | - ibmcloud cr region-set us-south 29 | - ibmcloud cr namespace-add jeff-lu 30 | 31 | ### Once your local environment is setup, subsequent login can be done with 32 | - npm run ibm-login 33 | 34 | ### Create region policy with role for resource in order to be able to push images to container registry 35 | - ibmcloud iam user-policy-create ljeff@us.ibm.com --service-name container-registry --region us-east --roles Administrator --resource-type namespace --resource ieam 36 | 37 | ## Development 38 | - npm install 39 | - Make a copy of env-example.json and it to .env-local.json and fill in the values for each environment as needed 40 | - npm run watch:start - will run service locally and hot reload when there are code changes 41 | -------------------------------------------------------------------------------- /cloud-function/hzn-action/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hzn-action", 3 | "version": "1.0.0", 4 | "description": "Open Horizon Actions & Examples", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "npm run tsc", 8 | "build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", 9 | "tsc": "tsc", 10 | "test": "mocha -r ts-node/register test/functionsTest.ts", 11 | "bundle": "webpack --config webpack.config.js", 12 | "deploy": "npm run build && npm run bundle && npm run wskdeploy", 13 | "deploy-dev": "npm run deploy --task=deployTS --package=demo --env=ieam-dev", 14 | "deploy-dev-api": "npm run deploy --task=deploy --package=demo --env=ieam-dev --api=true", 15 | "wskdeploy": "bin/deploy.js", 16 | "deploy-composer": "npm run deploy --package=wx-labs --env=dev --task=createComposer", 17 | "switch-account": "bin/switch-account.js" 18 | }, 19 | "author": "ljeff@us.ibm.com", 20 | "license": "ISC", 21 | "dependencies": { 22 | "ibm-cos-sdk": "^1.10.2", 23 | "node-uuid": "^1.4.8", 24 | "openwhisk-composer": "^0.12.0", 25 | "parted": "^0.1.1", 26 | "rxjs": "^7.3.0", 27 | "string-to-stream": "^3.0.1" 28 | }, 29 | "devDependencies": { 30 | "@types/node": "^16.4.12", 31 | "@typescript-eslint/parser": "^4.29.0", 32 | "awesome-typescript-loader": "^5.2.1", 33 | "copy-webpack-plugin": "^5.0.1", 34 | "dotenv": "^10.0.0", 35 | "jsonfile": "^6.1.0", 36 | "nodemon": "^2.0.12", 37 | "ts-loader": "^9.2.5", 38 | "ts-node": "^10.1.0", 39 | "typescript": "^3.9.10", 40 | "webpack": "^5.49.0", 41 | "webpack-cli": "^4.7.2", 42 | "webpack-node-externals": "^3.0.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /cloud-function/hzn-action/manifest-api.yaml: -------------------------------------------------------------------------------- 1 | packages: 2 | ${PACKAGE}: 3 | version: 1.0 4 | license: Apache-2.0 5 | actions: 6 | hzn-action: 7 | function: dist/hzn-action.js 8 | runtime: nodejs:12 9 | web-export: true 10 | limits: 11 | timeout: 60000 12 | memorySize: 256 13 | inputs: 14 | speechToTextUsername: ${SPEECH_TO_TEXT_USERNAME} 15 | speechToTextPassword: ${SPEECH_TO_TEXT_PASSWORD} 16 | speechToTextIamApikey: ${SPEECH_TO_TEXT_IAM_APIKEY} 17 | speechToTextUrl: ${SPEECH_TO_TEXT_URL} 18 | textToSpeechUsername: ${TEXT_TO_SPEECH_USERNAME} 19 | textToSpeechPassword: ${TEXT_TO_SPEECH_PASSWORD} 20 | textToSpeechIamApikey: ${TEXT_TO_SPEECH_IAM_APIKEY} 21 | textToSpeechUrl: ${TEXT_TO_SPEECH_URL} 22 | wuSlackBotToken: ${WU_SLACK_BOT_TOKEN} 23 | wusoSlackBotToken: ${WUSO_SLACK_BOT_TOKEN} 24 | apis: 25 | hzn-api-gateway: 26 | hzn: 27 | hzn_mms: 28 | hzn-action: 29 | method: GET 30 | response: json 31 | hzn_obj_url: 32 | hzn-action: 33 | method: GET 34 | response: json 35 | hzn_mms_url: 36 | hzn-action: 37 | method: GET 38 | response: json 39 | hzn_list: 40 | hzn-action: 41 | method: POST 42 | response: json 43 | hzn_get: 44 | hzn-action: 45 | method: GET 46 | response: json 47 | hzn_post: 48 | hzn-action: 49 | method: POST 50 | response: json 51 | -------------------------------------------------------------------------------- /open-horizon/mms/config/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "YOUR_SERVICE_NAME": "", 10 | "YOUR_SERVICE_VERSION": "", 11 | "YOUR_DOCKERHUB_ID": "", 12 | "VOLUME_MOUNT": "", 13 | "MMS_SHARED_VOLUME": "", 14 | "MMS_CONTAINER_CREDS": "", 15 | "MMS_SERVICE_NAME": "", 16 | "MMS_SERVICE_VERSION": "", 17 | "MMS_OBJECT_TYPE": "", 18 | "MMS_OBJECT_ID": "", 19 | "MMS_OBJECT_FILE": "config/config.json", 20 | "UPDATE_FILE_NAME": "" 21 | }, 22 | "metaVars": { 23 | } 24 | }, 25 | "demo": 26 | { 27 | "HZN_ORG_ID": "", 28 | "HZN_EXCHANGE_USER_AUTH": "", 29 | "HZN_EXCHANGE_URL": "", 30 | "HZN_FSS_CSSURL": "", 31 | "YOUR_SERVICE_NAME": "", 32 | "YOUR_SERVICE_VERSION": "", 33 | "YOUR_DOCKERHUB_ID": "", 34 | "VOLUME_MOUNT": "", 35 | "MMS_SHARED_VOLUME": "", 36 | "MMS_CONTAINER_CREDS": "", 37 | "MMS_SERVICE_NAME": "", 38 | "MMS_SERVICE_VERSION": "", 39 | "MMS_OBJECT_TYPE": "", 40 | "MMS_OBJECT_ID": "", 41 | "MMS_OBJECT_FILE": "config/config.json", 42 | "UPDATE_FILE_NAME": "" 43 | } 44 | } -------------------------------------------------------------------------------- /open-horizon/services/config/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "YOUR_SERVICE_NAME": "", 10 | "YOUR_SERVICE_VERSION": "", 11 | "YOUR_DOCKERHUB_ID": "", 12 | "VOLUME_MOUNT": "", 13 | "MMS_SHARED_VOLUME": "", 14 | "MMS_CONTAINER_CREDS": "", 15 | "MMS_SERVICE_NAME": "", 16 | "MMS_SERVICE_VERSION": "", 17 | "MMS_OBJECT_TYPE": "", 18 | "MMS_OBJECT_ID": "", 19 | "MMS_OBJECT_FILE": "config/config.json", 20 | "UPDATE_FILE_NAME": "" 21 | }, 22 | "metaVars": { 23 | } 24 | }, 25 | "demo": 26 | { 27 | "HZN_ORG_ID": "", 28 | "HZN_EXCHANGE_USER_AUTH": "", 29 | "HZN_EXCHANGE_URL": "", 30 | "HZN_FSS_CSSURL": "", 31 | "YOUR_SERVICE_NAME": "", 32 | "YOUR_SERVICE_VERSION": "", 33 | "YOUR_DOCKERHUB_ID": "", 34 | "VOLUME_MOUNT": "", 35 | "MMS_SHARED_VOLUME": "", 36 | "MMS_CONTAINER_CREDS": "", 37 | "MMS_SERVICE_NAME": "", 38 | "MMS_SERVICE_VERSION": "", 39 | "MMS_OBJECT_TYPE": "", 40 | "MMS_OBJECT_ID": "", 41 | "MMS_OBJECT_FILE": "config/config.json", 42 | "UPDATE_FILE_NAME": "" 43 | } 44 | } -------------------------------------------------------------------------------- /open-horizon/config/service/nx/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "YOUR_SERVICE_NAME": "", 10 | "YOUR_SERVICE_VERSION": "", 11 | "YOUR_DOCKERHUB_ID": "", 12 | "VOLUME_MOUNT": "", 13 | "MMS_SHARED_VOLUME": "", 14 | "MMS_CONTAINER_CREDS": "", 15 | "MMS_SERVICE_NAME": "", 16 | "MMS_SERVICE_VERSION": "", 17 | "MMS_OBJECT_TYPE": "", 18 | "MMS_OBJECT_ID": "", 19 | "MMS_OBJECT_FILE": "config/config.json", 20 | "UPDATE_FILE_NAME": "" 21 | }, 22 | "metaVars": { 23 | } 24 | }, 25 | "demo": 26 | { 27 | "HZN_ORG_ID": "", 28 | "HZN_EXCHANGE_USER_AUTH": "", 29 | "HZN_EXCHANGE_URL": "", 30 | "HZN_FSS_CSSURL": "", 31 | "YOUR_SERVICE_NAME": "", 32 | "YOUR_SERVICE_VERSION": "", 33 | "YOUR_DOCKERHUB_ID": "", 34 | "VOLUME_MOUNT": "", 35 | "MMS_SHARED_VOLUME": "", 36 | "MMS_CONTAINER_CREDS": "", 37 | "MMS_SERVICE_NAME": "", 38 | "MMS_SERVICE_VERSION": "", 39 | "MMS_OBJECT_TYPE": "", 40 | "MMS_OBJECT_ID": "", 41 | "MMS_OBJECT_FILE": "config/config.json", 42 | "UPDATE_FILE_NAME": "" 43 | } 44 | } -------------------------------------------------------------------------------- /open-horizon/config/service/pi/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "YOUR_SERVICE_NAME": "", 10 | "YOUR_SERVICE_VERSION": "", 11 | "YOUR_DOCKERHUB_ID": "", 12 | "VOLUME_MOUNT": "", 13 | "MMS_SHARED_VOLUME": "", 14 | "MMS_CONTAINER_CREDS": "", 15 | "MMS_SERVICE_NAME": "", 16 | "MMS_SERVICE_VERSION": "", 17 | "MMS_OBJECT_TYPE": "", 18 | "MMS_OBJECT_ID": "", 19 | "MMS_OBJECT_FILE": "config/config.json", 20 | "UPDATE_FILE_NAME": "" 21 | }, 22 | "metaVars": { 23 | } 24 | }, 25 | "demo": 26 | { 27 | "HZN_ORG_ID": "", 28 | "HZN_EXCHANGE_USER_AUTH": "", 29 | "HZN_EXCHANGE_URL": "", 30 | "HZN_FSS_CSSURL": "", 31 | "YOUR_SERVICE_NAME": "", 32 | "YOUR_SERVICE_VERSION": "", 33 | "YOUR_DOCKERHUB_ID": "", 34 | "VOLUME_MOUNT": "", 35 | "MMS_SHARED_VOLUME": "", 36 | "MMS_CONTAINER_CREDS": "", 37 | "MMS_SERVICE_NAME": "", 38 | "MMS_SERVICE_VERSION": "", 39 | "MMS_OBJECT_TYPE": "", 40 | "MMS_OBJECT_ID": "", 41 | "MMS_OBJECT_FILE": "config/config.json", 42 | "UPDATE_FILE_NAME": "" 43 | } 44 | } -------------------------------------------------------------------------------- /aws-lambda/serverless/.build/src/ieam.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | exports.handler = void 0; 4 | // export const hello = (event, context, cb) => cb(null, 5 | // { message: 'Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!', event } 6 | // ); 7 | var rxjs_1 = require("rxjs"); 8 | var messenger_1 = require("./messenger"); 9 | var handler = function (params, context, callback) { 10 | Object.assign(params, params.body); 11 | params.contentType = params.contentType ? params.contentType : 'application/json'; 12 | var response = new messenger_1.Messenger(params); 13 | action.exec(params) 14 | .subscribe(function (data) { 15 | callback(null, response.send(data)); 16 | }); 17 | }; 18 | exports.handler = handler; 19 | var action = { 20 | exec: function (params) { 21 | try { 22 | var ct = null; 23 | params.body = params.body ? JSON.parse(params.body) : null; 24 | var method = params.body ? params.body.action : null; 25 | console.log('$$$params', method); 26 | return (action[method] || action["default"])(params); 27 | } 28 | catch (e) { 29 | return (0, rxjs_1.of)({ data: e }); 30 | } 31 | }, 32 | sayHi: function (params) { 33 | return new rxjs_1.Observable(function (observer) { 34 | observer.next("Hello!"); 35 | observer.complete(); 36 | }); 37 | }, 38 | "default": function (params) { 39 | return new rxjs_1.Observable(function (observer) { 40 | console.log('$$$params', params); 41 | observer.next("Method " + params.action + " not found."); 42 | observer.complete(); 43 | }); 44 | } 45 | }; 46 | //# sourceMappingURL=ieam.js.map -------------------------------------------------------------------------------- /open-horizon/config/mms/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "SERVICE_NAME": "", 10 | "SERVICE_VERSION": "", 11 | "SERVICE_CONTAINER_CREDS": "", 12 | "YOUR_DOCKERHUB_ID": "", 13 | "VOLUME_MOUNT": "", 14 | "MMS_SHARED_VOLUME": "", 15 | "MMS_CONTAINER_CREDS": "", 16 | "MMS_SERVICE_NAME": "", 17 | "MMS_SERVICE_VERSION": "", 18 | "MMS_OBJECT_TYPE": "", 19 | "MMS_OBJECT_ID": "", 20 | "MMS_OBJECT_FILE": "config/config.json", 21 | "UPDATE_FILE_NAME": "" 22 | }, 23 | "metaVars": { 24 | } 25 | }, 26 | "demo": 27 | { 28 | "HZN_ORG_ID": "", 29 | "HZN_EXCHANGE_USER_AUTH": "", 30 | "HZN_EXCHANGE_URL": "", 31 | "HZN_FSS_CSSURL": "", 32 | "SERVICE_NAME": "", 33 | "SERVICE_VERSION": "", 34 | "SERVICE_CONTAINER_CREDS": "", 35 | "YOUR_DOCKERHUB_ID": "", 36 | "VOLUME_MOUNT": "", 37 | "MMS_SHARED_VOLUME": "", 38 | "MMS_CONTAINER_CREDS": "", 39 | "MMS_SERVICE_NAME": "", 40 | "MMS_SERVICE_VERSION": "", 41 | "MMS_OBJECT_TYPE": "", 42 | "MMS_OBJECT_ID": "", 43 | "MMS_OBJECT_FILE": "config/config.json", 44 | "UPDATE_FILE_NAME": "" 45 | } 46 | } -------------------------------------------------------------------------------- /open-horizon/config/service/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "SERVICE_NAME": "", 10 | "SERVICE_VERSION": "", 11 | "SERVICE_CONTAINER_CREDS": "", 12 | "YOUR_DOCKERHUB_ID": "", 13 | "VOLUME_MOUNT": "", 14 | "MMS_SHARED_VOLUME": "", 15 | "MMS_CONTAINER_CREDS": "", 16 | "MMS_SERVICE_NAME": "", 17 | "MMS_SERVICE_VERSION": "", 18 | "MMS_OBJECT_TYPE": "", 19 | "MMS_OBJECT_ID": "", 20 | "MMS_OBJECT_FILE": "config/config.json", 21 | "UPDATE_FILE_NAME": "" 22 | }, 23 | "metaVars": { 24 | } 25 | }, 26 | "demo": 27 | { 28 | "HZN_ORG_ID": "", 29 | "HZN_EXCHANGE_USER_AUTH": "", 30 | "HZN_EXCHANGE_URL": "", 31 | "HZN_FSS_CSSURL": "", 32 | "SERVICE_NAME": "", 33 | "SERVICE_VERSION": "", 34 | "SERVICE_CONTAINER_CREDS": "", 35 | "YOUR_DOCKERHUB_ID": "", 36 | "VOLUME_MOUNT": "", 37 | "MMS_SHARED_VOLUME": "", 38 | "MMS_CONTAINER_CREDS": "", 39 | "MMS_SERVICE_NAME": "", 40 | "MMS_SERVICE_VERSION": "", 41 | "MMS_OBJECT_TYPE": "", 42 | "MMS_OBJECT_ID": "", 43 | "MMS_OBJECT_FILE": "config/config.json", 44 | "UPDATE_FILE_NAME": "" 45 | } 46 | } -------------------------------------------------------------------------------- /open-horizon/mms/examples/object.json: -------------------------------------------------------------------------------- 1 | { 2 | "objectID": "config.json", /* Required: A unique identifier of the object. */ 3 | "objectType": "$HZN_DEVICE_ID.hello-mms", /* Required: The type of the object. */ 4 | "destinationOrgID": "$HZN_ORG_ID", /* Required: The organization ID of the object (an object belongs to exactly one organization). */ 5 | "destinationID": "$HZN_DEVICE_ID", /* The node id (without org prefix) where the object should be placed. */ 6 | /* If omitted the object is sent to all nodes with the same destinationType. */ 7 | /* Delete this field when you are using destinationPolicy. */ 8 | "destinationType": "pattern-${SERVICE_NAME}-$ARCH", /* The pattern in use by nodes that should receive this object. */ 9 | /* If omitted (and if destinationsList is omitted too) the object is broadcast to all known nodes. */ 10 | /* Delete this field when you are using policy. */ 11 | "destinationsList": null, /* The list of destinations as an array of pattern:nodeId pairs that should receive this object. */ 12 | /* If provided, destinationType and destinationID must be omitted. */ 13 | /* Delete this field when you are using policy. */ 14 | "expiration": "", /* A timestamp/date indicating when the object expires (it is automatically deleted). The timestamp should be provided in RFC3339 format. */ 15 | "version": "", /* Arbitrary string value. The value is not semantically interpreted. The Model Management System does not keep multiple version of an object. */ 16 | "description": "", /* An arbitrary description. */ 17 | "activationTime": "" /* A timestamp/date as to when this object should automatically be activated. The timestamp should be provided in RFC3339 format. */ 18 | } 19 | -------------------------------------------------------------------------------- /open-horizon/config/mms/fyre/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "SERVICE_NAME": "", 10 | "SERVICE_VERSION": "", 11 | "SERVICE_CONTAINER_CREDS": "", 12 | "YOUR_DOCKERHUB_ID": "", 13 | "VOLUME_MOUNT": "", 14 | "MMS_SHARED_VOLUME": "", 15 | "MMS_CONTAINER_CREDS": "", 16 | "MMS_SERVICE_NAME": "", 17 | "MMS_SERVICE_VERSION": "", 18 | "MMS_OBJECT_TYPE": "", 19 | "MMS_OBJECT_ID": "", 20 | "MMS_OBJECT_FILE": "config/config.json", 21 | "UPDATE_FILE_NAME": "" 22 | }, 23 | "metaVars": { 24 | } 25 | }, 26 | "demo": 27 | { 28 | "envVars": { 29 | "HZN_ORG_ID": "", 30 | "HZN_EXCHANGE_USER_AUTH": "", 31 | "HZN_EXCHANGE_URL": "", 32 | "HZN_FSS_CSSURL": "", 33 | "SERVICE_NAME": "", 34 | "SERVICE_VERSION": "", 35 | "SERVICE_CONTAINER_CREDS": "", 36 | "YOUR_DOCKERHUB_ID": "", 37 | "VOLUME_MOUNT": "", 38 | "MMS_SHARED_VOLUME": "", 39 | "MMS_CONTAINER_CREDS": "", 40 | "MMS_SERVICE_NAME": "", 41 | "MMS_SERVICE_VERSION": "", 42 | "MMS_OBJECT_TYPE": "", 43 | "MMS_OBJECT_ID": "", 44 | "MMS_OBJECT_FILE": "config/config.json", 45 | "UPDATE_FILE_NAME": "" 46 | }, 47 | "metaVars": { 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/nx/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "SERVICE_NAME": "", 10 | "SERVICE_VERSION": "", 11 | "SERVICE_CONTAINER_CREDS": "", 12 | "YOUR_DOCKERHUB_ID": "", 13 | "VOLUME_MOUNT": "", 14 | "MMS_SHARED_VOLUME": "", 15 | "MMS_CONTAINER_CREDS": "", 16 | "MMS_SERVICE_NAME": "", 17 | "MMS_SERVICE_VERSION": "", 18 | "MMS_OBJECT_TYPE": "", 19 | "MMS_OBJECT_ID": "", 20 | "MMS_OBJECT_FILE": "config/config.json", 21 | "UPDATE_FILE_NAME": "" 22 | }, 23 | "metaVars": { 24 | } 25 | }, 26 | "demo": 27 | { 28 | "envVars": { 29 | "HZN_ORG_ID": "", 30 | "HZN_EXCHANGE_USER_AUTH": "", 31 | "HZN_EXCHANGE_URL": "", 32 | "HZN_FSS_CSSURL": "", 33 | "SERVICE_NAME": "", 34 | "SERVICE_VERSION": "", 35 | "SERVICE_CONTAINER_CREDS": "", 36 | "YOUR_DOCKERHUB_ID": "", 37 | "VOLUME_MOUNT": "", 38 | "MMS_SHARED_VOLUME": "", 39 | "MMS_CONTAINER_CREDS": "", 40 | "MMS_SERVICE_NAME": "", 41 | "MMS_SERVICE_VERSION": "", 42 | "MMS_OBJECT_TYPE": "", 43 | "MMS_OBJECT_ID": "", 44 | "MMS_OBJECT_FILE": "config/config.json", 45 | "UPDATE_FILE_NAME": "" 46 | }, 47 | "metaVars": { 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /open-horizon/config/mms/pi/env-hzn.json: -------------------------------------------------------------------------------- 1 | { 2 | "biz": 3 | { 4 | "envVars": { 5 | "HZN_ORG_ID": "", 6 | "HZN_EXCHANGE_USER_AUTH": "", 7 | "HZN_EXCHANGE_URL": "", 8 | "HZN_FSS_CSSURL": "", 9 | "SERVICE_NAME": "", 10 | "SERVICE_VERSION": "", 11 | "SERVICE_CONTAINER_CREDS": "", 12 | "YOUR_DOCKERHUB_ID": "", 13 | "VOLUME_MOUNT": "", 14 | "MMS_SHARED_VOLUME": "", 15 | "MMS_CONTAINER_CREDS": "", 16 | "MMS_SERVICE_NAME": "", 17 | "MMS_SERVICE_VERSION": "", 18 | "MMS_OBJECT_TYPE": "", 19 | "MMS_OBJECT_ID": "", 20 | "MMS_OBJECT_FILE": "config/config.json", 21 | "UPDATE_FILE_NAME": "" 22 | }, 23 | "metaVars": { 24 | } 25 | }, 26 | "demo": 27 | { 28 | "envVars": { 29 | "HZN_ORG_ID": "", 30 | "HZN_EXCHANGE_USER_AUTH": "", 31 | "HZN_EXCHANGE_URL": "", 32 | "HZN_FSS_CSSURL": "", 33 | "SERVICE_NAME": "", 34 | "SERVICE_VERSION": "", 35 | "SERVICE_CONTAINER_CREDS": "", 36 | "YOUR_DOCKERHUB_ID": "", 37 | "VOLUME_MOUNT": "", 38 | "MMS_SHARED_VOLUME": "", 39 | "MMS_CONTAINER_CREDS": "", 40 | "MMS_SERVICE_NAME": "", 41 | "MMS_SERVICE_VERSION": "", 42 | "MMS_OBJECT_TYPE": "", 43 | "MMS_OBJECT_ID": "", 44 | "MMS_OBJECT_FILE": "config/config.json", 45 | "UPDATE_FILE_NAME": "" 46 | }, 47 | "metaVars": { 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /cloud-function/demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo", 3 | "version": "1.0.0", 4 | "description": "Demo & Examples", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "npm run tsc", 8 | "build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", 9 | "tsc": "tsc", 10 | "bundle": "webpack --config webpack.config.js", 11 | "deploy": "npm run build && npm run bundle && npm run wskdeploy", 12 | "deploy-dev": "npm run deploy --package=demo --env=dev", 13 | "deploy-dev-api": "npm run deploy --package=demo --env=dev --api=true", 14 | "deploy-stage": "npm run deploy --package=demo --env=stage", 15 | "deploy-stage-api": "npm run deploy --package=demo --env=stage --api=true", 16 | "deploy-js": "npm run build && npm run bundle && bin/clean.js && bin/deploy.js", 17 | "deploy-stage-js": "npm run deploy-js --task=deployJS --package=demo --env=stage", 18 | "deploy-stage-js-api": "npm run deploy --task=deployJS --package=demo --env=stage --api=true", 19 | "wskdeploy": "bin/deploy.js", 20 | "switch-account": "bin/switch-account.js" 21 | }, 22 | "author": "ljeff@us.ibm.com", 23 | "license": "ISC", 24 | "_moduleAliases": { 25 | "@common": "dist/common/src" 26 | }, 27 | "dependencies": { 28 | "ibm-cos-sdk": "^1.13.0", 29 | "node-uuid": "^1.4.8", 30 | "parted": "^0.1.1", 31 | "rxjs": "^7.8.0", 32 | "string-to-stream": "^3.0.1" 33 | }, 34 | "devDependencies": { 35 | "@types/node": "^16.18.18", 36 | "@typescript-eslint/parser": "^4.33.0", 37 | "copy-webpack-plugin": "^11.0.0", 38 | "dotenv": "^10.0.0", 39 | "jest": "^29.5.0", 40 | "jsonfile": "^6.1.0", 41 | "nodemon": "^2.0.21", 42 | "ts-loader": "^9.4.2", 43 | "ts-node": "^10.9.1", 44 | "tsconfig-paths-webpack-plugin": "^4.0.1", 45 | "typescript": "^5.0.2", 46 | "webpack": "^5.76.2", 47 | "webpack-cli": "^5.0.1", 48 | "webpack-node-externals": "^3.0.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /code-engine/example/example_deprecated.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | /* eslint-disable require-jsdoc */ 3 | /* eslint-disable node/no-unpublished-require */ 4 | const CodeEngineV1 = require('../dist/ibm-cloud-code-engine/v1'); // require('ibm-code-engine-sdk/ibm-cloud-code-engine/v1'); 5 | const { IamAuthenticator } = require('../dist/auth'); // require('ibm-code-engine-sdk/auth'); 6 | const k8s = require('@kubernetes/client-node'); 7 | 8 | if (!process.env.CE_API_KEY || !process.env.CE_PROJECT_ID || !process.env.CE_PROJECT_REGION) { 9 | throw new Error( 10 | 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID before using the example.' 11 | ); 12 | } 13 | 14 | // Create an IAM authenticator. 15 | const authenticator = new IamAuthenticator({ 16 | apikey: process.env.CE_API_KEY, 17 | clientId: 'bx', 18 | clientSecret: 'bx', 19 | }); 20 | 21 | // Construct the Code Engine client using the IAM authenticator. 22 | const ceClient = new CodeEngineV1({ 23 | authenticator, 24 | serviceUrl: `https://api.${process.env.CE_PROJECT_REGION}.codeengine.cloud.ibm.com/api/v1`, 25 | }); 26 | 27 | async function main() { 28 | // Get tokens using the Authenticator. 29 | const tokenResponse = await authenticator.tokenManager.requestToken(); 30 | 31 | // Get Code Engine project config using the Code Engine client. 32 | const configResponse = await ceClient.listKubeconfig({ 33 | refreshToken: tokenResponse.result.refresh_token, 34 | id: process.env.CE_PROJECT_ID, 35 | }); 36 | 37 | // Setup Kubernetes client. 38 | const kubeConfig = new k8s.KubeConfig(); 39 | kubeConfig.loadFromString(configResponse.result); 40 | const kubeClient = kubeConfig.makeApiClient(k8s.CoreV1Api); 41 | 42 | // Get something from project. 43 | const { namespace } = kubeConfig.getCurrentContextObject(); 44 | const configMapList = await kubeClient.listNamespacedConfigMap(namespace); 45 | console.log( 46 | `Project ${process.env.CE_PROJECT_ID} has ${configMapList.body.items.length} configmaps.` 47 | ); 48 | } 49 | 50 | main(); 51 | -------------------------------------------------------------------------------- /code-engine/ieam-action/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ieam-action", 3 | "version": "1.0.0", 4 | "description": "IEAM CE toolkit", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "npm run tsc", 8 | "build:live": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts", 9 | "tsc": "tsc", 10 | "test": "mocha -r ts-node/register test/functionsTest.ts", 11 | "bundle": "webpack --config webpack.config.js", 12 | "build:doall": "npm run wskdeploy --task=doall", 13 | "build:image": "npm run build && npm run bundle && npm run wskdeploy --task=build", 14 | "build:push": "npm run wskdeploy --task=push", 15 | "deploy": "npm run wskdeploy --task=deploy", 16 | "deploy:prod": "npm run build:doall --name=ieam-action --image_version=1.0.0 --env=prod", 17 | "deploy-dev": "npm run deploy --task=deployTS --package=demo --env=ieam-dev", 18 | "deploy-dev-api": "npm run deploy --task=deploy --package=demo --env=ieam-dev --api=true", 19 | "ibm-login": "ibmcloud login --sso && npm run select-target && npm run select-project", 20 | "select-project": "ibmcloud ce project select -n ieam", 21 | "select-target": "ibmcloud target -g default", 22 | "app-list": "ibmcloud ce app list", 23 | "get-app": "ibmcloud ce app -n ieam-action-prod", 24 | "get-logs": "ibmcloud ce app logs -f -n ieam-action-prod", 25 | "wskdeploy": "bin/deploy.js" 26 | }, 27 | "author": "ljeff@us.ibm.com", 28 | "license": "ISC", 29 | "dependencies": { 30 | "crypto-js": "^4.1.1", 31 | "ethers": "^5.6.6", 32 | "jsonfile": "^6.1.0", 33 | "rxjs": "^7.5.5" 34 | }, 35 | "devDependencies": { 36 | "@types/node": "^16.4.12", 37 | "@typescript-eslint/parser": "^4.29.0", 38 | "awesome-typescript-loader": "^5.2.1", 39 | "copy-webpack-plugin": "^5.0.1", 40 | "dotenv": "^10.0.0", 41 | "nodemon": "^2.0.12", 42 | "ts-loader": "^9.2.5", 43 | "ts-node": "^10.1.0", 44 | "typescript": "^3.9.10", 45 | "webpack": "^5.49.0", 46 | "webpack-cli": "^4.7.2", 47 | "webpack-node-externals": "^3.0.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /code-engine/ieam-service/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 4 | "module": "commonjs", /* Specify what module code is generated. */ 5 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 6 | "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 7 | "resolveJsonModule": true, /* Enable importing .json files */ 8 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 9 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 10 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 11 | "importHelpers": false, 12 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ 13 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 14 | "strict": false, /* Enable all strict type-checking options. */ 15 | "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 16 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 17 | "types": [ 18 | "node", 19 | "jest" 20 | ], 21 | "typeRoots": [ 22 | "@types", 23 | "./node_modules/@types" 24 | ], 25 | "paths": { 26 | "@common/*": [ 27 | "common/*" 28 | ] 29 | } 30 | }, 31 | "include": [ 32 | "src/**/*.ts", 33 | "common/**/*.ts" 34 | ] 35 | } -------------------------------------------------------------------------------- /code-engine/edge-slack-bot/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 4 | "module": "commonjs", /* Specify what module code is generated. */ 5 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 6 | "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 7 | "resolveJsonModule": true, /* Enable importing .json files */ 8 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 9 | "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 10 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 11 | "importHelpers": false, 12 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ 13 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 14 | "strict": false, /* Enable all strict type-checking options. */ 15 | "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 16 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 17 | "types": [ 18 | "node", 19 | "jest" 20 | ], 21 | "typeRoots": [ 22 | "@types", 23 | "./node_modules/@types" 24 | ], 25 | "paths": { 26 | "@common/*": [ 27 | "../common/*" 28 | ] 29 | } 30 | }, 31 | "include": [ 32 | "src/**/*.ts", 33 | "../common/**/*.ts" 34 | ] 35 | } -------------------------------------------------------------------------------- /open-horizon/mms/README.md: -------------------------------------------------------------------------------- 1 | # MMS (Modle Management System) build with Node JS 2 | 3 | This is a port over of https://github.com/TheMosquito/MMS_Helper repo for Node JS. 4 | 5 | A simple Horizon sample edge service that shows how to use a Model Management System (MMS) service with your service. The idea is to be able to deliver updates to the applications/services that are running on the edge node. The update could be a new ML model file or a config json file with relevant information for the application to consume and/or take appropriate actions. This project provides a script that consists of all the steps neccessary to build the docker image for the MMS services with all the required environment variables and parameters all the way through registering the agent with Management Hub. Once the agent is registered with the Management Hub and if all goes well, MMS service will start up and it will periodically check for a new update using the local MMS API (aka ESS) that the Horizon agent provides to services. If an update is available, it will fetch the update and make it available for your applications/services. 6 | 7 | ### Note: Make a copy of env-hzn.json and name it as .env-hzn.json on your local machine and fill in all the required values in the .env-hzn.json file 8 | 9 | 10 | The deploy.js script will perform the following tasks: 11 | * Build docker image 12 | * Push docker image 13 | * Publish MMS service 14 | * Publish MMS pattern 15 | * Register agent 16 | * Unregister agent 17 | * Publish new updates using MMS 18 | 19 | 20 | 21 | # NPM commands 22 | 23 | ## npm run register-agent 24 | - Will perform all of the following commands 25 | 26 | ## npm run builld 27 | - Builds the docker image 28 | 29 | ## npm run push 30 | - Pushes the docker image to Docker Hub 31 | 32 | ## npm run publish-service 33 | - Publishes MMS Service 34 | 35 | ## npm run publish-pattern 36 | - Publishes MMS Pattern 37 | 38 | ## npm run agent-run 39 | - Registers agent with Management Hub 40 | 41 | ## npm run unregister-agent 42 | - Unregisgers agent 43 | 44 | ## Publish new/update model 45 | - hzn mms object publish --type=object_detection --id=config.json --object=/demo-model/demo/version1/model.zip --pattern=pattern-pi-mms-service-arm -------------------------------------------------------------------------------- /code-engine/example/README.md: -------------------------------------------------------------------------------- 1 | # Code Engine NodeJS SDK Example 2 | 3 | ## Running example.js 4 | 5 | To run the example, create a Code Engine project from the Console or Code Engine CLI, and run the following commands from this directory: 6 | 1. `npm install` 7 | 2. `export CE_API_KEY=` 8 | 3. `export CE_PROJECT_ID=` 9 | 4. `export CE_PROJECT_REGION=` 10 | 5. `node example.js` 11 | 12 | ## How-to 13 | 14 | ### Set up an authenticator 15 | ```js 16 | const authenticator = new IamAuthenticator({ 17 | apikey: process.env.CE_API_KEY, 18 | clientId: 'bx', 19 | clientSecret: 'bx', 20 | }); 21 | ``` 22 | 23 | ### Set up a Code Engine client 24 | ```js 25 | const ceClient = new CodeEngineV1({ 26 | authenticator, 27 | serviceUrl: `https://api.us-south.codeengine.cloud.ibm.com/api/v1`, 28 | }); 29 | ``` 30 | 31 | ### Use an HTTP library of your choice to get a Delegated Refresh Token from IAM 32 | This example uses [Axios](https://www.npmjs.com/package/axios) for its async/await support and [querystring](https://nodejs.org/api/querystring.html) to encode the request parameters. 33 | ```js 34 | const iamResponse = await axios.post('https://iam.cloud.ibm.com/identity/token', querystring.stringify({ 35 | grant_type: 'urn:ibm:params:oauth:grant-type:apikey', 36 | apikey: process.env.CE_API_KEY, 37 | response_type: 'delegated_refresh_token', 38 | receiver_client_ids: 'ce', 39 | delegated_refresh_token_expiry: '3600' 40 | }), { 41 | headers: { 42 | 'Content-Type': 'application/x-www-form-urlencoded' 43 | } 44 | }) 45 | const delegatedRefreshToken = iamResponse.data.delegated_refresh_token; 46 | ``` 47 | 48 | ### Use the Code Engine client to get a Kubernetes config 49 | ```js 50 | const configResponse = await ceClient.getKubeconfig({ 51 | xDelegatedRefreshToken: delegatedRefreshToken, 52 | id: process.env.CE_PROJECT_ID, 53 | }); 54 | const kubeConfigString = configResponse.result; 55 | ``` 56 | 57 | ## Deprecated endpoint 58 | 59 | The `/namespaces/{id}/config` endpoint function, `listKubeconfig()`, is deprecated, and will be removed before Code Engine is out of Beta. Please use the `getKubeconfig()` function, demonstrated in the example above. 60 | -------------------------------------------------------------------------------- /cloud-function/demo/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | const CopyPlugin = require('copy-webpack-plugin'); 4 | const { ContextReplacementPlugin, IgnorePlugin } = require('webpack'); 5 | const dist = 'dist'; // be aware 'dist' folder is also used for tsconfig output 6 | const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); 7 | 8 | var nodeModules = {}; 9 | // fs.readdirSync('node_modules') 10 | // .filter(function(x) { 11 | // return ['.bin'].indexOf(x) === -1; 12 | // }) 13 | // .forEach(function(mod) { 14 | // nodeModules[mod] = 'commonjs ' + mod; 15 | // }); 16 | 17 | module.exports = { 18 | //stats: { 19 | // // Configure the console output 20 | // errorDetails: true, //this does show errors 21 | // colors: false, 22 | // modules: true, 23 | // reasons: true 24 | //}, 25 | entry: { 26 | 'demo-action': `./src/demo-action.ts` 27 | }, 28 | output: { 29 | path: path.resolve(__dirname, dist), 30 | filename: '[name].js', 31 | }, 32 | module: { 33 | rules: [ 34 | { 35 | test: /\.tsx?$/, 36 | use: 'ts-loader', 37 | use: { 38 | loader: 'ts-loader', 39 | options: { 40 | transpileOnly: true 41 | } 42 | }, 43 | exclude: /node_modules/ 44 | } 45 | ], 46 | }, 47 | plugins: [ 48 | //new CopyPlugin({ 49 | // patterns: [ 50 | // { 51 | // from: 'dist/common/src/cos-client.js', 52 | // to: '../js/cos-client.js' 53 | // }, 54 | // { 55 | // from: 'dist/common/src/utility.js', 56 | // to: '../js/utility.js' 57 | // }, 58 | // { 59 | // from: 'dist/common/src/messenger.js', 60 | // to: '../js/messenger.js' 61 | // }, 62 | // { 63 | // from: 'dist/demo/src/demo-action.js', 64 | // to: '../index.js' 65 | // } 66 | // ] 67 | //}) 68 | ], 69 | resolve: { 70 | extensions: ['.js', '.ts', '.tsx', '.json'], 71 | plugins: [ 72 | new TsconfigPathsPlugin({ configFile: "./tsconfig.json" }) 73 | ], 74 | alias: { 75 | '@common/*': '../common/src' 76 | } 77 | }, 78 | externals: nodeModules, 79 | mode: 'production', 80 | target: 'node', 81 | node: { 82 | __dirname: true 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /cloud-function/demo/bin/switch-account.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const path = require('path'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | const fs = require('fs'); 6 | const jsonfile = require('jsonfile') 7 | const dotenv = require('dotenv'); 8 | 9 | if(fs.existsSync('.env-local')) { 10 | const localEnv = dotenv.parse(fs.readFileSync('.env-local')); 11 | for(var i in localEnv) { 12 | process.env[i] = localEnv[i]; 13 | } 14 | } 15 | 16 | const task = process.env.npm_config_task || 'switchAccount'; 17 | const package = process.env.npm_config_package || 'weather-dev'; 18 | const env = process.env.npm_config_env || 'dev'; 19 | const region = process.env.npm_config_region || 'us-south'; 20 | const account = process.env.npm_config_account; 21 | const composer = process.env.npm_config_composer; 22 | 23 | let build = { 24 | getEnvVar: () => { 25 | const cosAccess = JSON.parse(process.env.COS_ACCESS); 26 | let pEnv = process.env; 27 | pEnv.PACKAGE = package; 28 | pEnv.ACCESSKEYID = cosAccess[env]['access_key_id']; 29 | pEnv.SECRETACCESSKEY = cosAccess[env]['secret_access_key']; 30 | pEnv.APIKEYID = cosAccess[env]['apikey']; 31 | pEnv.SERVICEINSTANCEID = cosAccess[env]['resource_instance_id']; 32 | pEnv.BUCKET = cosAccess[env]['bucket']; 33 | }, 34 | switchTarget: (cb) => { 35 | if(account) { 36 | console.log(process.env.HOME); 37 | jsonfile.readFile(`${process.env.HOME}/apikeys/${account}.json`, function (err, obj) { 38 | if (!err) { 39 | const arg = `ibmcloud login --apikey ${obj.apiKey} -r ${region} -o ${obj.org} -s ${obj.space} && ibmcloud fn api list`; 40 | console.log(`switch to ${arg}`); 41 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 42 | if(!err) { 43 | console.log(stdout) 44 | console.log(`switch account successfully`); 45 | cb(); 46 | } else { 47 | console.log('failed to switch account', err); 48 | } 49 | }); 50 | } else { 51 | console.error(err) 52 | } 53 | }) 54 | } else { 55 | cb(); 56 | } 57 | }, 58 | switchAccount: () => { 59 | if(account) { 60 | build.getEnvVar(); 61 | build.switchTarget(() => { 62 | console.log('done'); 63 | }); 64 | } else { 65 | console.log('specify an acount to switch to.') 66 | } 67 | } 68 | } 69 | 70 | build[task](); 71 | -------------------------------------------------------------------------------- /cloud-function/hzn-action/bin/switch-account.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const path = require('path'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | const fs = require('fs'); 6 | const jsonfile = require('jsonfile') 7 | const dotenv = require('dotenv'); 8 | 9 | if(fs.existsSync('.env-local')) { 10 | const localEnv = dotenv.parse(fs.readFileSync('.env-local')); 11 | for(var i in localEnv) { 12 | process.env[i] = localEnv[i]; 13 | } 14 | } 15 | 16 | const task = process.env.npm_config_task || 'switchAccount'; 17 | const package = process.env.npm_config_package || 'weather-dev'; 18 | const env = process.env.npm_config_env || 'dev'; 19 | const region = process.env.npm_config_region || 'us-south'; 20 | const account = process.env.npm_config_account; 21 | const composer = process.env.npm_config_composer; 22 | 23 | let build = { 24 | getEnvVar: () => { 25 | const cosAccess = JSON.parse(process.env.COS_ACCESS); 26 | let pEnv = process.env; 27 | pEnv.PACKAGE = package; 28 | pEnv.ACCESSKEYID = cosAccess[env]['access_key_id']; 29 | pEnv.SECRETACCESSKEY = cosAccess[env]['secret_access_key']; 30 | pEnv.APIKEYID = cosAccess[env]['apikey']; 31 | pEnv.SERVICEINSTANCEID = cosAccess[env]['resource_instance_id']; 32 | pEnv.BUCKET = cosAccess[env]['bucket']; 33 | }, 34 | switchTarget: (cb) => { 35 | if(account) { 36 | console.log(process.env.HOME); 37 | jsonfile.readFile(`${process.env.HOME}/apikeys/${account}.json`, function (err, obj) { 38 | if (!err) { 39 | const arg = `ibmcloud login --apikey ${obj.apiKey} -r ${region} -o ${obj.org} -s ${obj.space} && ibmcloud fn api list`; 40 | console.log(`switch to ${arg}`); 41 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 42 | if(!err) { 43 | console.log(stdout) 44 | console.log(`switch account successfully`); 45 | cb(); 46 | } else { 47 | console.log('failed to switch account', err); 48 | } 49 | }); 50 | } else { 51 | console.error(err) 52 | } 53 | }) 54 | } else { 55 | cb(); 56 | } 57 | }, 58 | switchAccount: () => { 59 | if(account) { 60 | build.getEnvVar(); 61 | build.switchTarget(() => { 62 | console.log('done'); 63 | }); 64 | } else { 65 | console.log('specify an acount to switch to.') 66 | } 67 | } 68 | } 69 | 70 | build[task](); 71 | -------------------------------------------------------------------------------- /code-engine/ieam-service/common/utils.ts: -------------------------------------------------------------------------------- 1 | import * as https from 'https'; 2 | import { Observable } from 'rxjs'; 3 | 4 | import { HznParams } from './params/hzn-params'; 5 | 6 | const cp = require('child_process'), 7 | exec = cp.exec; 8 | 9 | export class Utils { 10 | homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; 11 | mmsPath = '/mms-shared'; 12 | localPath = './local-shared'; 13 | assets = './assets'; 14 | sharedPath = ''; 15 | intervalMS = 10000; 16 | timer: NodeJS.Timer = null; 17 | timestamp = Date.now(); 18 | logTime = Date.now(); 19 | 20 | constructor() { 21 | this.init() 22 | } 23 | init() { 24 | console.log(`initializng...`) 25 | } 26 | 27 | httpGet(url) { 28 | return new Observable((observer) => { 29 | https.get(url, (resp) => { 30 | let data = ''; 31 | 32 | // A chunk of data has been recieved. 33 | resp.on('data', (chunk) => { 34 | data += chunk; 35 | }); 36 | // The whole response has been received. Print out the result. 37 | resp.on('end', () => { 38 | observer.next(JSON.parse(data)); 39 | observer.complete(); 40 | }); 41 | }).on("error", (err) => { 42 | console.log("Error: " + err.message); 43 | observer.error(err); 44 | }); 45 | }); 46 | } 47 | unregister(params: HznParams) { 48 | return this.shell(`oh deploy autoUnregister`) 49 | } 50 | registerWithPolicy(params: HznParams) { 51 | return this.shell(`oh deploy autoRegisterWithPolicy`) 52 | } 53 | registerWithPattern(params: HznParams) { 54 | return this.shell(`oh deploy autoRegisterWithPattern`) 55 | } 56 | updatePolicy(params: HznParams) { 57 | return this.shell(`oh deploy autoAddpolicy`) 58 | } 59 | shell(arg: string, success='command executed successfully', error='command failed', prnStdout=true, options={maxBuffer: 1024 * 2000}) { 60 | return new Observable((observer) => { 61 | console.log(arg); 62 | if(!prnStdout) { 63 | options = Object.assign(options, {stdio: 'pipe', encoding: 'utf8'}) 64 | } 65 | exec(arg, options, (err: any, stdout: any, stderr: any) => { 66 | if(!err) { 67 | if(prnStdout) { 68 | console.log(stdout); 69 | } 70 | console.log(success); 71 | observer.next(stdout); 72 | observer.complete(); 73 | } else { 74 | console.log(`${error}: ${err}`); 75 | observer.error(err); 76 | } 77 | }) 78 | }); 79 | } 80 | } -------------------------------------------------------------------------------- /code-engine/hello-ce/src/server.ts: -------------------------------------------------------------------------------- 1 | import * as http from 'http'; 2 | import { Observable, of, from } from 'rxjs'; 3 | import { Params } from '@common/params/params'; 4 | 5 | declare const process: any; 6 | http.createServer(function (request: any, response: { writeHead: (arg0: number, arg1: { 'Content-Type': string; }) => void; end: (arg0: any) => void; }) { 7 | const target = process.env.TARGET ? process.env.TARGET : 'World' ; 8 | const msg = process.env.MSG ? process.env.MSG : 'Hello ' + target + '\n'; 9 | // const params = action.params(request); 10 | let result: any; 11 | return new Promise((resolve, reject) => { 12 | action.exec(request) 13 | .subscribe((data: any) => { 14 | result = data; 15 | console.log('$data', result); 16 | }, (err: any) => { 17 | console.log(err); 18 | response.writeHead(400, {'Content-Type': 'application/json'}); 19 | resolve(response.end(`something went wrong...${err}\n`)); 20 | }, () => { 21 | response.writeHead(200, {'Content-Type': 'application/json'}); 22 | resolve(response.end(JSON.stringify(result) + '\n')); 23 | }); 24 | }); 25 | 26 | // response.writeHead(200, {'Content-Type': 'application/json'}); 27 | // response.end(JSON.stringify(request.url + ' : ' + request.method + ' : ' + request.body) + '\n'); 28 | }).listen(8080); 29 | 30 | let action: any = { 31 | params: (req: any) => { 32 | let q=req.url.split('?'),result: any={}; 33 | if(q.length>=2){ 34 | q[1].split('&').forEach((item: string)=>{ 35 | try { 36 | result[item.split('=')[0]]=item.split('=')[1]; 37 | } catch (e) { 38 | result[item.split('=')[0]]=''; 39 | } 40 | }) 41 | } 42 | return result; 43 | }, 44 | exec: (request: any): any => { 45 | if(request.method == 'GET') { 46 | let params = action.params(request); 47 | return (action[params.action] || action.default)(params) 48 | } else { 49 | return (action['list'] || action.default)(request.body) 50 | } 51 | }, 52 | hello: (params: Params) => { 53 | return of('hello') 54 | }, 55 | list: (params: Params) => { 56 | return of('listing') 57 | }, 58 | error: (msg: string) => { 59 | return new Observable((observer: any) => { 60 | observer.next(msg); 61 | observer.complete(); 62 | }); 63 | }, 64 | default: (params: Params) => { 65 | return new Observable((observer: any) => { 66 | observer.next(`Method ${params.method} not found.`); 67 | observer.complete(); 68 | }); 69 | } 70 | } 71 | 72 | console.log('Server running at http://0.0.0.0:8080/'); -------------------------------------------------------------------------------- /open-horizon/common/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { Observable, of } from 'rxjs'; 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | 5 | const env = process.env.npm_config_env || 'biz'; 6 | 7 | export class Utils { 8 | constructor() {} 9 | init() { 10 | } 11 | listService() { 12 | let name = process.env.npm_config_name; 13 | name = name ? `hzn exchange service list ${name}` : 'hzn exchange service list'; 14 | return this.shell(name); 15 | } 16 | listPattern() { 17 | let name = process.env.npm_config_name; 18 | name = name ? `hzn exchange pattern list ${name}` : 'hzn exchange pattern list'; 19 | return this.shell(name); 20 | } 21 | listNode() { 22 | let name = process.env.npm_config_name; 23 | name = name ? `hzn exchange node list ${name}` : 'hzn exchange node list'; 24 | return this.shell(name); 25 | } 26 | listObject() { 27 | let name = process.env.npm_config_name; 28 | name = name ? `hzn mms object list ${name}` : 'hzn mms object list'; 29 | return this.shell(name); 30 | } 31 | listDeploymentPolicy() { 32 | let name = process.env.npm_config_name; 33 | name = name ? `hzn exchange deployment listpolicy ${name}` : 'hzn exchange deployment listpolicy'; 34 | return this.shell(name); 35 | } 36 | createHznKey() { 37 | let org = process.env.npm_config_org; 38 | let email = process.env.npm_config_email; 39 | if(org && email) { 40 | return this.shell(`hzn key creat ${org} ${email}`); 41 | } else { 42 | console.log('please provide both org and email: --org= --email=.') 43 | return of(); 44 | } 45 | } 46 | checkConfigState() { 47 | return this.shell(`hzn node list | jq .configstate.state`); 48 | } 49 | listNodePattern() { 50 | return this.shell(`hzn node list | jq .pattern`); 51 | } 52 | getDeviceArch() { 53 | return this.shell(`hzn architecture`); 54 | } 55 | installHznCli() { 56 | return this.shell(`curl -u "$HZN_ORG_ID/$HZN_EXCHANGE_USER_AUTH" -k -o agent-install.sh $HZN_FSS_CSSURL/api/v1/objects/IBM/agent_files/agent-install.sh/data && chmod +x agent-install.sh && sudo -s -E ./agent-install.sh -i 'css:'`) 57 | } 58 | shell(arg: string) { 59 | return new Observable((observer) => { 60 | exec(arg, {maxBuffer: 1024 * 2000}, (err: any, stdout: any, stderr: any) => { 61 | if(!err) { 62 | console.log(stdout); 63 | observer.next(stdout); 64 | observer.complete(); 65 | } else { 66 | console.log(`shell command failed: ${err}`); 67 | observer.error(err); 68 | } 69 | }); 70 | }); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /code-engine/hello-ce/bin/deploy.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | const fs = require('fs'); 5 | const { Observable } = require('rxjs'); 6 | var dotenv = require('dotenv'); 7 | 8 | if(fs.existsSync('../.env-local')) { 9 | const localEnv = dotenv.parse(fs.readFileSync('../.env-local')); 10 | for(var i in localEnv) { 11 | process.env[i] = localEnv[i]; 12 | } 13 | } 14 | 15 | const name = process.env.npm_config_name; 16 | const task = process.env.npm_config_task; 17 | let image = process.env.npm_config_image; 18 | 19 | if(!task) { 20 | console.log(`specify --task taskname...`) 21 | process.exit(0) 22 | } 23 | if(task == 'deploy' && !name) { 24 | console.log(`name is required: specify --name appname...`) 25 | process.exit(0) 26 | } 27 | if((task == 'deploy' || task == 'push' || task == 'build') && !image) { 28 | console.log(`image name is required: specify --image imagename...`) 29 | process.exit(0) 30 | } 31 | console.log(image, image.match(/([^/]+$)/)[0]) 32 | image = image.match(/([^/]+$)/)[0]; 33 | 34 | let build = { 35 | build: () => { 36 | let imageName = `${process.env.REGISTRY}${image}` 37 | let arg = `docker build --no-cache -t ${imageName} . ` 38 | build.shell(arg,`done building ${imageName} image`, `failed to build ${imageName} image`) 39 | .subscribe(() => { 40 | process.exit(0) 41 | }) 42 | }, 43 | push: () => { 44 | let imageName = `${process.env.REGISTRY}${image}` 45 | let arg = `docker push ${process.env.REGISTRY}${image}` 46 | build.shell(arg,`done pushing ${imageName} image`, `failed to push ${imageName} image`) 47 | .subscribe(() => { 48 | process.exit(0) 49 | }) 50 | }, 51 | deploy: () => { 52 | let arg = `ibmcloud ce app update -n ${name} --image ${process.env.REGISTRY}${image}` 53 | console.log('deploying...') 54 | build.shell(arg,`done add/update ${name}`, `failed to add/update ${name}`) 55 | .subscribe(() => { 56 | process.exit(0) 57 | }) 58 | }, 59 | shell: (arg, success='command executed successfully', error='command failed', prnStdout=true, options={maxBuffer: 1024 * 2000}) => { 60 | return new Observable((observer) => { 61 | console.log(arg); 62 | let child = exec(arg, options, (err, stdout, stderr) => { 63 | if(!err) { 64 | // console.log(stdout); 65 | console.log(success); 66 | observer.next(prnStdout ? stdout : ''); 67 | observer.complete(); 68 | } else { 69 | console.log(`${error}: ${err}`); 70 | observer.error(err); 71 | } 72 | }); 73 | child.stdout.pipe(process.stdout); 74 | child.on('data', (data) => { 75 | console.log(data) 76 | }) 77 | }); 78 | } 79 | } 80 | 81 | build[task](); -------------------------------------------------------------------------------- /open-horizon/src/service/deploy.ts: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | import { Observable, forkJoin } from 'rxjs'; 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | import { readFileSync, writeFileSync } from 'fs'; 6 | import { Env } from './env'; 7 | const prompt = require('prompt'); 8 | 9 | const task = process.env.npm_config_task || 'test'; 10 | const envVar = new Env(); 11 | let serviceJson: any; 12 | let patternJson: any; 13 | let policyJson: any; 14 | 15 | let hzn = { 16 | setup: () => { 17 | return new Observable((observer) => { 18 | patternJson = process.env.npm_config_patternjson || 'config/service/pattern.json'; 19 | serviceJson = process.env.npm_config_servicejson || 'config/service/service.json'; 20 | policyJson = process.env.npm_config_policyjson || 'config/service/policy.json'; 21 | observer.complete(); 22 | }); 23 | }, 24 | test: () => { 25 | return new Observable((observer) => { 26 | console.log('it works...') 27 | observer.complete(); 28 | }); 29 | }, 30 | publishService: () => { 31 | return new Observable((observer) => { 32 | let arg = `hzn exchange service publish -O ${envVar.getContainerCreds()} -f ${serviceJson} --pull-image`; 33 | console.log(arg) 34 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 35 | if(!err) { 36 | console.log(stdout) 37 | console.log(`done publishing ${envVar.getMyServiceName()} service`); 38 | observer.next(); 39 | observer.complete(); 40 | } else { 41 | console.log('failed to publish service', err); 42 | observer.error(err); 43 | } 44 | }); 45 | }) 46 | }, 47 | publishPattern: () => { 48 | return new Observable((observer) => { 49 | let arg = `hzn exchange pattern publish -f ${patternJson}`; 50 | console.log(arg) 51 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 52 | if(!err) { 53 | console.log(stdout) 54 | console.log(`done publishing ${envVar.getPatterName()} pattern`); 55 | observer.next(); 56 | observer.complete(); 57 | } else { 58 | console.log('failed to publish mms pattern', err); 59 | observer.error(err); 60 | } 61 | }); 62 | }) 63 | } 64 | } 65 | 66 | envVar.init() 67 | .subscribe({ 68 | next: () => { 69 | hzn.setup() 70 | .subscribe({ 71 | complete: () => { 72 | hzn[task]() 73 | .subscribe(() => { 74 | console.log('process completed.'); 75 | process.exit(0) 76 | }) 77 | }, error: (err) => { 78 | console.log('something went wrong. ', err); 79 | } 80 | }) 81 | }, error: (err) => { 82 | console.log('something went wrong. ', err); 83 | } 84 | }) 85 | -------------------------------------------------------------------------------- /open-horizon/services/scripts/env.js: -------------------------------------------------------------------------------- 1 | const { Observable } = require('rxjs'); 2 | const hznJson = require('../config/.env-hzn.json'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | 6 | const env = process.env.npm_config_env || 'biz'; 7 | const envVars = hznJson[env]['envVars']; 8 | let metaVars = hznJson[env]['metaVars']; 9 | const pEnv = process.env; 10 | 11 | class Env { 12 | static init() { 13 | return new Observable((observer) => { 14 | for(const [key, value] of Object.entries(envVars)) { 15 | process.env[key] = value.replace(/\r?\n|\r/g, ''); 16 | console.log(`${key}: ${process.env[key]}`); 17 | } 18 | if(!envVars.ARCH || envVars.ARCH === undefined) { 19 | let arg = `hzn architecture` 20 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 21 | if(!err) { 22 | pEnv.ARCH = envVars.ARCH = stdout.replace(/\r?\n|\r/g, ''); 23 | this.setAdditionalEnv(); 24 | observer.next(); 25 | observer.complete(); 26 | } else { 27 | console.log('failed to identify arch', err); 28 | observer.error(err); 29 | } 30 | }); 31 | } else { 32 | this.setAdditionalEnv(); 33 | console.log(envVars.ARCH) 34 | observer.next(); 35 | observer.complete(); 36 | } 37 | }); 38 | } 39 | static setAdditionalEnv() { 40 | pEnv.PATTERN_NAME = `pattern-${pEnv.SERVICE_NAME}`; 41 | pEnv.SERVICE_CONTAINER = `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.SERVICE_NAME}:${pEnv.SERVICE_VERSION}`.replace(/\r?\n|\r/g, '') 42 | } 43 | static getEnv() { 44 | return env; 45 | } 46 | static getOrgId() { 47 | console.log(pEnv.HZN_ORG_ID) 48 | return pEnv.HZN_ORG_ID; 49 | } 50 | static getExchangeUserAuth() { 51 | return pEnv.HZN_EXCHANGE_USER_AUTH; 52 | } 53 | static getExchangeUrl() { 54 | return pEnv.HZN_EXCHANGE_URL; 55 | } 56 | static getFSSCSSUrl() { 57 | return pEnv.HZN_FSS_CSSURL; 58 | } 59 | static getMyServiceName() { 60 | return pEnv.SERVICE_NAME; 61 | } 62 | static getMyServiceVersion() { 63 | return pEnv.SERVICE_VERSION; 64 | } 65 | static getMMSSharedVolume() { 66 | return pEnv.MMS_SHARED_VOLUME; 67 | } 68 | static getVolumeMount() { 69 | return pEnv.VOLUME_MOUNT; 70 | } 71 | static getMyDockerHubId() { 72 | return pEnv.YOUR_DOCKERHUB_ID; 73 | } 74 | static getDockerImageBase() { 75 | return `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.SERVICE_NAME}`; 76 | } 77 | static getContainerCreds() { 78 | return pEnv.CONTAINER_CREDS; 79 | } 80 | static getPatterName() { 81 | return pEnv.PATTERN_NAME; 82 | } 83 | static getServiceContainer() { 84 | return pEnv.SERVICE_CONTAINER; 85 | } 86 | static getArch() { 87 | return pEnv.ARCH; 88 | } 89 | } 90 | 91 | module.exports.Env = Env; -------------------------------------------------------------------------------- /open-horizon/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "open-horizon", 3 | "version": "1.0.0", 4 | "description": "Open Horizon toolkit help streamline the process of preparing node agents and perform tasks between orgs environments", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "npm run tsc", 8 | "tsc": "tsc", 9 | "bundle": "webpack --config webpack.config.js && chmod +x lib/*.js", 10 | "build-bundle": "npm run build && npm run bundle", 11 | "deploy": "lib/mms-deploy.js", 12 | "build-image": "npm run deploy --task=build", 13 | "push-image": "npm run deploy --task=push", 14 | "publish-mms-service": "npm run deploy --task=publishService", 15 | "publish-mms-pattern": "npm run deploy --task=publishPattern", 16 | "agent-run": "npm run deploy --task=agentRun", 17 | "publish-object": "npm run deploy --task=publishObject", 18 | "register-agent": "npm run deploy --task=registerAgent", 19 | "unregister-agent": "npm run deploy --task=unregisterAgent", 20 | "show-horizon-info": "npm run deploy --task=showHorizonInfo", 21 | "update-horizon-info": "npm run deploy --task=updateHorizonInfo", 22 | "list-service": "npm run deploy --task=listService", 23 | "list-pattern": "npm run deploy --task=listPattern", 24 | "list-node": "npm run deploy --task=listNode", 25 | "list-object": "npm run deploy --task=listObject", 26 | "create-hzn-key": "npm run deploy --task=createHznKey", 27 | "list-deployment-policy": "npm run deploy --task=listDeploymentPolicy", 28 | "check-config-state": "npm run deploy --task=checkConfigState", 29 | "list-node-pattern": "npm run deploy --task=listNodePattern", 30 | "get-device-arch": "npm run deploy --task=getDeviceArch", 31 | "install-hzn-cli": "npm run deploy --task=installHznCli", 32 | "test": "npm run deploy --task=test", 33 | "deploy-service": "lib/service-deploy.js", 34 | "publish-service": "npm run deploy-service --task=publishService", 35 | "publish-pattern": "npm run deploy-service --task=publishPattern", 36 | "test-service": "npm run deploy-service --task=test" 37 | }, 38 | "keywords": [ 39 | "IEAM", 40 | "Open", 41 | "Horizon", 42 | "edge", 43 | "computing", 44 | "MMS", 45 | "Model", 46 | "Management", 47 | "Service" 48 | ], 49 | "author": "ljeff@us.ibm.com", 50 | "license": "ISC", 51 | "devDependencies": { 52 | "@types/node": "^16.7.10", 53 | "@typescript-eslint/parser": "^4.30.0", 54 | "copy-webpack-plugin": "^9.0.1", 55 | "nodemon": "^2.0.12", 56 | "ts-loader": "^9.2.5", 57 | "ts-node": "^10.2.1", 58 | "tsconfig-paths-webpack-plugin": "^3.5.1", 59 | "typescript": "^4.4.2", 60 | "webpack": "^5.51.2", 61 | "webpack-cli": "^4.8.0", 62 | "webpack-node-externals": "^3.0.0" 63 | }, 64 | "dependencies": { 65 | "prompt": "^1.2.0", 66 | "rxjs": "^7.3.0" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /code-engine/example/example.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | /* eslint-disable require-jsdoc */ 3 | /* eslint-disable node/no-unpublished-require */ 4 | const CodeEngineV1 = require('../dist/ibm-cloud-code-engine/v1'); // require('ibm-code-engine-sdk/ibm-cloud-code-engine/v1'); 5 | const { IamAuthenticator } = require('../dist/auth'); // require('ibm-code-engine-sdk/auth'); 6 | const k8s = require('@kubernetes/client-node'); 7 | const axios = require('axios'); 8 | const querystring = require('querystring'); 9 | 10 | if (!process.env.CE_API_KEY || !process.env.CE_PROJECT_ID || !process.env.CE_PROJECT_REGION) { 11 | throw new Error( 12 | 'You must set the envrionment variables CE_API_KEY, CE_PROJECT_REGION and CE_PROJECT_ID before using the example.' 13 | ); 14 | } 15 | 16 | // Create an IAM authenticator. 17 | const authenticator = new IamAuthenticator({ 18 | apikey: process.env.CE_API_KEY, 19 | clientId: 'bx', 20 | clientSecret: 'bx', 21 | }); 22 | 23 | // Construct the Code Engine client using the IAM authenticator. 24 | const ceClient = new CodeEngineV1({ 25 | authenticator, 26 | serviceUrl: `https://api.${process.env.CE_PROJECT_REGION}.codeengine.cloud.ibm.com/api/v1`, 27 | }); 28 | 29 | async function main() { 30 | // Use the http library to get an IAM Delegated Refresh Token 31 | let iamResponse; 32 | let delegatedRefreshToken; 33 | try { 34 | iamResponse = await axios.post( 35 | 'https://iam.cloud.ibm.com/identity/token', 36 | querystring.stringify({ 37 | 'grant_type': 'urn:ibm:params:oauth:grant-type:apikey', 38 | 'apikey': process.env.CE_API_KEY, 39 | 'response_type': 'delegated_refresh_token', 40 | 'receiver_client_ids': 'ce', 41 | 'delegated_refresh_token_expiry': '3600', 42 | }), 43 | { 44 | 'headers': { 45 | 'Content-Type': 'application/x-www-form-urlencoded', 46 | }, 47 | } 48 | ); 49 | delegatedRefreshToken = iamResponse.data.delegated_refresh_token; 50 | } catch (err) { 51 | throw err; 52 | } 53 | 54 | // Get Code Engine project config using the Code Engine client. 55 | let configResponse; 56 | try { 57 | configResponse = await ceClient.getKubeconfig({ 58 | xDelegatedRefreshToken: delegatedRefreshToken, 59 | id: process.env.CE_PROJECT_ID, 60 | }); 61 | } catch (err) { 62 | throw err; 63 | } 64 | 65 | // Setup Kubernetes client. 66 | const kubeConfig = new k8s.KubeConfig(); 67 | kubeConfig.loadFromString(configResponse.result); 68 | const kubeClient = kubeConfig.makeApiClient(k8s.CoreV1Api); 69 | const { namespace } = kubeConfig.getCurrentContextObject(); 70 | 71 | // Get something from project. 72 | try { 73 | const configMapList = await kubeClient.listNamespacedConfigMap(namespace); 74 | console.log( 75 | `Project ${process.env.CE_PROJECT_ID} has ${configMapList.body.items.length} configmaps.` 76 | ); 77 | } catch (err) { 78 | throw err; 79 | } 80 | } 81 | 82 | main(); 83 | -------------------------------------------------------------------------------- /ieam-rhel-edge/README.md: -------------------------------------------------------------------------------- 1 | # Edge Computing, Setup IEAM to run on RHEL for Edge 2 | 3 | * Install RHEL 8.4 in a vm(edge-server), use ImageBuilder to build the initial rhel-edge-commit 4 | * A few things you will need to do to get rhel and imageBuilder dashboard ruunning 5 | * Get started with RHEL for Edge https://www.redhat.com/en/blog/get-started-rhel-edge 6 | * Subscribe to redhat 7 | subscription-manager register --username --password --auto-attach 8 | * systemctl stop libvirtd.service 9 | * systemctl disable libvirtd.service 10 | * systemctl status libvirtd.service 11 | * systemctl enable --now cockpit.socket or systemctl enablle –now osbuild-composer.socket 12 | * Ensure BOOT is set to yes 13 | vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 14 | * sudo nmcli connection down enp1s0 && sudo nmcli connection up enp1s0 15 | * Access imageBuilder dashboard https://\:9090/ 16 | * Create a RHEL for Edge Commit (.tar) 17 | 18 | * Download rhel-edge-commit tar file 19 | * Tar –xvf rhel-edge-commit tar 20 | * Create Dockerfile and kickstart(edge.ks) file (NOTE: available in setup folder) 21 | * Build docker image 22 | * podman run --name rhel-edge-ieam -d -p 8080:80 rhel-edge-ieam 23 | 24 | * In a second vm(edge-node) RHEL 8.4 25 | * Boot up with rhel for the first time, specify inst-ks=:8080/edge.ks 26 | * Install complete, reboot 27 | 28 | * Since Podman is included in the base OS and ImageBuilder does provide a way to remove podman packages nor does it provide docker packages, we will have run the following commands to remove podman packages and install docker 29 | (NOTE: rpm packages are in setup folder) 30 | * rpm-ostree override remove runc podman containers-common podman-catatonit skopeo 31 | * rpm-ostree install containerd.io-1.4.9-3.1.el8.x86_64.rpm docker-ce-20.10.9-3.el8.x86_64.rpm docker-ce-cli-20.10.9-3.el8.x86_64.rpm docker-ce-rootless-extras-20.10.9-3.el8.x86_64.rpm docker-scan-plugin-0.9.0-3.el8.x86_64.rpm libcgroup-0.41-19.el8.x86_64.rpm 32 | * rpm-ostree install net-tools-2.0-0.52.20160912git.el8.x86_64.rpm 33 | * rpm-ostree install nodejs-14.16.0-2.module_el8.4.0+716+f63d6d3d.x86_64.rpm npm-6.14.11-1.14.16.0.2.module_el8.4.0+716+f63d6d3d.x86_64.rpm 34 | 35 | * systemctl reboot to pickup the changes. 36 | 37 | * After reboot, run the following commands to setup environment and register agent 38 | * sudo ostree admin unlock --hotfix 39 | * sudo npm i –g hzn-cli 40 | * export SUPPORTED_REDHAT_VERSION_APPEND=8.4 41 | * oh deploy setup 42 | * oh deploy registerAgent 43 | 44 | * NOTE: refer to https://github.com/playground/hzn-cli for more info on "oh' or type "oh deploy -h" for help 45 | 46 | [![Watch the video](https://i9.ytimg.com/vi/5UaxlHa1P2U/mq3.jpg?sqp=CJiKmo0G&rs=AOn4CLBcddkPtX-9UXKiec9kp_Z-a3i6dA)](https://youtu.be/5UaxlHa1P2U) -------------------------------------------------------------------------------- /open-horizon/src/service/env.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | import { readFileSync } from 'fs'; 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | 6 | const pEnv = process.env; 7 | 8 | export class Env { 9 | env: string; 10 | envVars: any; 11 | hznJson: any; 12 | hznEnv: any; 13 | constructor() { 14 | this.env = pEnv.npm_config_env || 'biz'; 15 | } 16 | init() { 17 | return new Observable((observer) => { 18 | this.hznEnv = pEnv.npm_config_hznEnv || './config/service/.env-hzn.json'; 19 | this.hznJson = JSON.parse(readFileSync(this.hznEnv).toString()); 20 | console.log(process.cwd(), this.env, this.hznJson) 21 | this.envVars = this.hznJson[this.env]['envVars']; 22 | for(const [key, value] of Object.entries(this.envVars)) { 23 | // @ts-ignore 24 | pEnv[key] = value.replace(/\r?\n|\r/g, ''); 25 | console.log(`${key}: ${pEnv[key]}`); 26 | } 27 | if(!this.envVars.ARCH || this.envVars.ARCH === undefined) { 28 | let arg = `hzn architecture` 29 | exec(arg, {maxBuffer: 1024 * 2000}, (err: any, stdout: any, stderr: any) => { 30 | if(!err) { 31 | pEnv.ARCH = this.envVars.ARCH = stdout.replace(/\r?\n|\r/g, ''); 32 | this.setAdditionalEnv(); 33 | observer.next(); 34 | observer.complete(); 35 | } else { 36 | console.log('failed to identify arch', err); 37 | observer.error(err); 38 | } 39 | }); 40 | } else { 41 | this.setAdditionalEnv(); 42 | console.log(this.envVars.ARCH) 43 | observer.next(); 44 | observer.complete(); 45 | } 46 | }); 47 | } 48 | setAdditionalEnv() { 49 | pEnv.PATTERN_NAME = `pattern-${pEnv.SERVICE_NAME}`; 50 | pEnv.SERVICE_CONTAINER = `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.SERVICE_NAME}_${pEnv.ARCH}:${pEnv.SERVICE_VERSION}`.replace(/\r?\n|\r/g, '') 51 | } 52 | getEnv() { 53 | return this.env; 54 | } 55 | getOrgId() { 56 | console.log(pEnv.HZN_ORG_ID) 57 | return pEnv.HZN_ORG_ID; 58 | } 59 | getExchangeUserAuth() { 60 | return pEnv.HZN_EXCHANGE_USER_AUTH; 61 | } 62 | getExchangeUrl() { 63 | return pEnv.HZN_EXCHANGE_URL; 64 | } 65 | getFSSCSSUrl() { 66 | return pEnv.HZN_FSS_CSSURL; 67 | } 68 | getMyServiceName() { 69 | return pEnv.SERVICE_NAME; 70 | } 71 | getMyServiceVersion() { 72 | return pEnv.SERVICE_VERSION; 73 | } 74 | getMMSSharedVolume() { 75 | return pEnv.MMS_SHARED_VOLUME; 76 | } 77 | getVolumeMount() { 78 | return pEnv.VOLUME_MOUNT; 79 | } 80 | getMyDockerHubId() { 81 | return pEnv.YOUR_DOCKERHUB_ID; 82 | } 83 | getDockerImageBase() { 84 | return `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.SERVICE_NAME}`; 85 | } 86 | getContainerCreds() { 87 | return pEnv.CONTAINER_CREDS; 88 | } 89 | getPatterName() { 90 | return pEnv.PATTERN_NAME; 91 | } 92 | getServiceContainer() { 93 | return pEnv.SERVICE_CONTAINER; 94 | } 95 | getArch() { 96 | return pEnv.ARCH; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /code-engine/edge-slack-bot/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "edge-slack-bot", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "bundle": "npm run build && webpack --config webpack.config.js", 9 | "build:doall": "npm run code-engine --task=doall", 10 | "build:image": "npm run build && npm run bundle && npm run code-engine --task=build --name=edge-slack-bot", 11 | "deploy:prod:all": "npm run build:doall --name=edge-slack-bot --env=prod", 12 | "deploy:stage:all": "npm run build:doall --name=edge-slack-bot --env=stage", 13 | "deploy:dev:all": "npm run build:doall --name=edge-slack-bot --env=dev", 14 | "deploy:prod": "npm run code-engine --task=deploy --name=edge-slack-bot --env=prod", 15 | "deploy:stage": "npm run code-engine --task=deploy --name=edge-slack-bot --env=stage", 16 | "deploy:dev": "npm run code-engine --task=deploy --name=edge-slack-bot --env=dev", 17 | "image:tag": "npm run code-engine --task=tag --name=edge-slack-bot", 18 | "image:push": "npm run code-engine --task=push --name=edge-slack-bot", 19 | "start": "node dist/index.js", 20 | "watch:build": "webpack --watch", 21 | "watch:server": "tsc -w & nodemon -w dist dist/index.js", 22 | "watch:start": "npm-run-all --parallel watch:server watch:build", 23 | "ibm-login": "ibmcloud login --sso && npm run select-target && npm run select-project", 24 | "select-project": "ibmcloud ce project select -n ieam", 25 | "select-target": "ibmcloud target -g Default", 26 | "app-list": "ibmcloud ce app list", 27 | "get-app": "ibmcloud ce application get -n edge-slack-bot-prod", 28 | "get-logs": "ibmcloud ce application logs -f -n edge-slack-bot-prod", 29 | "get-app-url": "npm run code-engine --task=appUrl", 30 | "get-app-info": "npm run code-engine --task=appInfo", 31 | "get-app-logs": "npm run code-engine --task=appLogs", 32 | "switch-region": "npm run code-engine --task=switchRegion", 33 | "code-engine": "bin/deploy.js", 34 | "test": "echo \"Error: no test specified\" && exit 1" 35 | }, 36 | "repository": { 37 | "type": "git", 38 | "url": "https://github.com/playground/open-labs/code-engine/edge-slack-bot" 39 | }, 40 | "author": "ljeff@us.ibm.com", 41 | "license": "ISC", 42 | "dependencies": { 43 | "@slack/bolt": "^3.13.0", 44 | "body-parser": "^1.20.2", 45 | "cors": "^2.8.5", 46 | "express": "^4.18.2", 47 | "jsonfile": "^6.1.0", 48 | "openai": "^3.2.1", 49 | "request": "^2.88.2", 50 | "rxjs": "^7.8.0" 51 | }, 52 | "devDependencies": { 53 | "@types/jest": "^29.5.0", 54 | "@types/node": "^18.15.11", 55 | "@typescript-eslint/parser": "^5.57.1", 56 | "jest": "^29.5.0", 57 | "nodemon": "^2.0.22", 58 | "npm-run-all": "^4.1.5", 59 | "ts-loader": "^9.4.2", 60 | "ts-node": "^10.9.1", 61 | "tsconfig-paths-webpack-plugin": "^4.0.1", 62 | "typescript": "^5.0.3", 63 | "webpack": "^5.77.0", 64 | "webpack-cli": "^5.0.1", 65 | "webpack-node-externals": "^3.0.0" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /code-engine/ieam-service/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ieam-service", 3 | "version": "1.0.1", 4 | "description": "IEAM Backend Services with Code Engine", 5 | "main": "index.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "bundle": "npm run build && webpack --config webpack.config.js", 9 | "build:doall": "npm run code-engine --task=doall", 10 | "build:image": "npm run build && npm run bundle && npm run code-engine --task=build", 11 | "deploy:prod:all": "npm run build:doall --name=ieam-service --env=prod", 12 | "deploy:stage:all": "npm run build:doall --name=ieam-service --env=stage", 13 | "deploy:dev:all": "npm run build:doall --name=ieam-service --env=dev", 14 | "deploy:prod": "npm run code-engine --task=deploy --name=ieam-service --env=prod", 15 | "deploy:stage": "npm run code-engine --task=deploy --name=ieam-service --env=stage", 16 | "deploy:dev": "npm run code-engine --task=deploy --name=ieam-service --env=dev", 17 | "image:tag": "npm run code-engine --task=tag --name=ieam-service", 18 | "image:push": "npm run code-engine --task=push --name=ieam-service", 19 | "start": "node dist/src/index.js", 20 | "watch:build": "webpack --watch", 21 | "watch:server": "tsc -w & nodemon -w dist dist/src/index.js", 22 | "watch:start": "npm-run-all --parallel watch:server watch:build", 23 | "ibm-login": "ibmcloud login --sso && npm run select-target && npm run select-project", 24 | "select-project": "ibmcloud ce project select -n ieam", 25 | "select-target": "ibmcloud target -g Default", 26 | "app-list": "ibmcloud ce app list", 27 | "get-app": "ibmcloud ce application get -n ieam-service-prod", 28 | "get-logs": "ibmcloud ce application logs -f -n ieam-service-prod", 29 | "get-app-url": "npm run code-engine --task=appUrl", 30 | "get-app-info": "npm run code-engine --task=appInfo", 31 | "get-app-logs": "npm run code-engine --task=appLogs", 32 | "switch-region": "npm run code-engine --task=switchRegion", 33 | "code-engine": "bin/deploy.js", 34 | "test": "echo \"Error: no test specified\" && exit 1" 35 | }, 36 | "repository": { 37 | "type": "git", 38 | "url": "https://github.com/playground/open-labs/blob/main/code-engine/ieam-service" 39 | }, 40 | "author": "ljeff@us.ibm.com", 41 | "license": "ISC", 42 | "dependencies": { 43 | "body-parser": "^1.20.2", 44 | "cors": "^2.8.5", 45 | "express": "^4.18.2", 46 | "jsonfile": "^6.1.0", 47 | "ldapjs": "^3.0.2", 48 | "node-ssha256": "^0.1.1", 49 | "request": "^2.88.2", 50 | "rxjs": "^7.8.0" 51 | }, 52 | "devDependencies": { 53 | "@types/jest": "^29.5.0", 54 | "@types/node": "^18.15.7", 55 | "@typescript-eslint/parser": "^5.56.0", 56 | "dotenv": "^16.0.3", 57 | "jest": "^29.5.0", 58 | "nodemon": "^2.0.22", 59 | "npm-run-all": "^4.1.5", 60 | "ts-loader": "^9.4.2", 61 | "ts-node": "^10.9.1", 62 | "tsconfig-paths-webpack-plugin": "^4.0.1", 63 | "typescript": "^5.0.2", 64 | "webpack": "^5.76.3", 65 | "webpack-cli": "^5.0.1", 66 | "webpack-node-externals": "^3.0.0" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /open-horizon/README.md: -------------------------------------------------------------------------------- 1 | # IEAM / Open Horizon Toolkit 2 | Open Horizon toolkit help streamline the process of preparing node agents and performing various tasks across orgs environments. 3 | 4 | Build-bundle will generate two executables under lib directory 5 | - lib/mms-deploy 6 | - lib/service-deploy 7 | 8 | ***For now, to try out this toolkit, clone https://github.com/playground/open-lab, cd into open-horizon, run any of the following commands. 9 | 10 | ### Note: Make a copy of env-hzn.json and name it as .env-hzn.json on your local machine and fill in all the required values in the .env-hzn.json file for each organization 11 | 12 | ### This toolkit comes with the following convenient commnands 13 | 14 | - build: compiles typescript source files 15 | - bundle: generate executables 16 | - build-bundle: compile & bundle 17 | - build-image: builds MMS docker image 18 | - push-image: push MMS docker image 19 | - publish-service: publish MMS service 20 | - publish-pattern: publish MMS pattern 21 | - agent-run: register agent 22 | - register-agent: single command will perform the above tasks sequentially 23 | - publish-object: publish update object file via MMS 24 | - unregister-agent: unregister agent 25 | - show-horizon-info: display Horizon Info on device 26 | - update-horizon-info: prompt to update Horizon Info for device 27 | - list-service: list available services or list service by name and by org 28 | - list-pattern: list available patterns or list pattern by name and by org 29 | - list-node: list available nodes or list node by name and by org 30 | - list-object: list available MMS object files and by org 31 | - create-hzn-key: generate Horizon Keys 32 | - list-deployment-policy: list available deployment policies or list policy by name and by org 33 | - check-config-state: check node config state 34 | - list-node-pattern: list node patterns or list node pattern by name 35 | - get-device-arch: get device architecture 36 | - test: simple toolkit test 37 | 38 | ### Note: Make a copy of env-hzn.json and name it as .env-hzn.json on your local machine and fill in all the required values in the .env-hzn.json file 39 | 40 | 41 | ## NPM command examples 42 | 43 | ### npm run list-deployment-policy --env=demo --name=demo/policy-ibm.cpu2evtstreams_1.4.3 44 | - To list deployment policy by name and by organization 45 | 46 | ### npm run register-agent or npm run register-agent --env=demo 47 | - Will perform all of the following commands for the specified organization, default is biz 48 | 49 | ### npm run builld 50 | - Builds the docker image 51 | 52 | ### npm run push 53 | - Pushes the docker image to Docker Hub 54 | 55 | ### npm run publish-service 56 | - Publishes MMS Service 57 | 58 | ### npm run publish-pattern 59 | - Publishes MMS Pattern 60 | 61 | ### npm run agent-run 62 | - Registers agent with Management Hub 63 | 64 | ### npm run unregister-agent 65 | - Unregisgers agent 66 | 67 | ### Publish new/update model 68 | - hzn mms object publish --type=object_detection --id=config.json --object=/demo-model/demo/version1/model.zip --pattern=pattern-pi-mms-service-arm 69 | -------------------------------------------------------------------------------- /open-horizon/mms/scripts/env.js: -------------------------------------------------------------------------------- 1 | const { Observable } = require('rxjs'); 2 | const hznJson = require('../config/.env-hzn.json'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | 6 | const env = process.env.npm_config_env || 'biz'; 7 | const envVars = hznJson[env]['envVars']; 8 | let metaVars = hznJson[env]['metaVars']; 9 | const pEnv = process.env; 10 | 11 | class Env { 12 | static init() { 13 | return new Observable((observer) => { 14 | for(const [key, value] of Object.entries(envVars)) { 15 | process.env[key] = value.replace(/\r?\n|\r/g, ''); 16 | console.log(`${key}: ${process.env[key]}`); 17 | } 18 | if(!envVars.ARCH || envVars.ARCH === undefined) { 19 | let arg = `hzn architecture` 20 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 21 | if(!err) { 22 | pEnv.ARCH = envVars.ARCH = stdout.replace(/\r?\n|\r/g, ''); 23 | this.setAdditionalEnv(); 24 | observer.next(); 25 | observer.complete(); 26 | } else { 27 | console.log('failed to identify arch', err); 28 | observer.error(err); 29 | } 30 | }); 31 | } else { 32 | this.setAdditionalEnv(); 33 | console.log(envVars.ARCH) 34 | observer.next(); 35 | observer.complete(); 36 | } 37 | }); 38 | } 39 | static setAdditionalEnv() { 40 | pEnv.MMS_PATTERN_NAME = `pattern-${pEnv.MMS_SERVICE_NAME}-${pEnv.ARCH}`; 41 | pEnv.MMS_CONTAINER = `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.MMS_SERVICE_NAME}_${pEnv.ARCH}:${pEnv.MMS_SERVICE_VERSION}`.replace(/\r?\n|\r/g, '') 42 | } 43 | static getEnv() { 44 | return env; 45 | } 46 | static getOrgId() { 47 | console.log(pEnv.HZN_ORG_ID) 48 | return pEnv.HZN_ORG_ID; 49 | } 50 | static getExchangeUserAuth() { 51 | return pEnv.HZN_EXCHANGE_USER_AUTH; 52 | } 53 | static getExchangeUrl() { 54 | return pEnv.HZN_EXCHANGE_URL; 55 | } 56 | static getFSSCSSUrl() { 57 | return pEnv.HZN_FSS_CSSURL; 58 | } 59 | static getMyServiceName() { 60 | return pEnv.YOUR_SERVICE_NAME; 61 | } 62 | static getMyServiceVersion() { 63 | return pEnv.YOUR_SERVICE_VERSION; 64 | } 65 | static getMMSSharedVolume() { 66 | return pEnv.MMS_SHARED_VOLUME; 67 | } 68 | static getMyDockerHubId() { 69 | return pEnv.YOUR_DOCKERHUB_ID; 70 | } 71 | static getDockerImageBase() { 72 | return `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.MMS_SERVICE_NAME}`; 73 | } 74 | static getMMSContainerCreds() { 75 | return pEnv.MMS_CONTAINER_CREDS; 76 | } 77 | static getMMSPatterName() { 78 | return pEnv.MMS_PATTERN_NAME; 79 | } 80 | static getMMSServiceName() { 81 | return pEnv.MMS_SERVICE_NAME; 82 | } 83 | static getMMSServiceVersion() { 84 | return pEnv.MMS_SERVICE_VERSION; 85 | } 86 | static getMMSContainer() { 87 | return pEnv.MMS_CONTAINER; 88 | } 89 | static getArch() { 90 | return pEnv.ARCH; 91 | } 92 | static getMMSObjectType() { 93 | return pEnv.MMS_OBJECT_TYPE; 94 | } 95 | static getMMSObjectId() { 96 | return pEnv.MMS_OBJECT_ID 97 | } 98 | static getMMSObjectFile() { 99 | return pEnv.MMS_OBJECT_FILE 100 | } 101 | } 102 | 103 | module.exports.Env = Env; -------------------------------------------------------------------------------- /open-horizon/src/mms/env.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | import { readFileSync } from 'fs'; 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | 6 | const pEnv = process.env; 7 | 8 | export class Env { 9 | env: string; 10 | envVars: any; 11 | hznJson: any; 12 | hznEnv: any; 13 | constructor() { 14 | this.env = pEnv.npm_config_env || 'biz'; 15 | } 16 | init() { 17 | return new Observable((observer) => { 18 | this.hznEnv = pEnv.npm_config_hznEnv || './config/mms/.env-hzn.json'; 19 | this.hznJson = JSON.parse(readFileSync(this.hznEnv).toString()); 20 | console.log(process.cwd(), this.env, this.hznJson) 21 | this.envVars = this.hznJson[this.env]['envVars']; 22 | for(const [key, value] of Object.entries(this.envVars)) { 23 | // @ts-ignore 24 | pEnv[key] = value.replace(/\r?\n|\r/g, ''); 25 | console.log(`${key}: ${pEnv[key]}`); 26 | } 27 | if(!this.envVars.ARCH || this.envVars.ARCH === undefined) { 28 | let arg = `hzn architecture` 29 | exec(arg, {maxBuffer: 1024 * 2000}, (err: any, stdout: any, stderr: any) => { 30 | if(!err) { 31 | pEnv.ARCH = this.envVars.ARCH = stdout.replace(/\r?\n|\r/g, ''); 32 | this.setAdditionalEnv(); 33 | observer.next(); 34 | observer.complete(); 35 | } else { 36 | console.log('failed to identify arch', err); 37 | observer.error(err); 38 | } 39 | }); 40 | } else { 41 | this.setAdditionalEnv(); 42 | console.log(this.envVars.ARCH) 43 | observer.next(); 44 | observer.complete(); 45 | } 46 | }); 47 | } 48 | setAdditionalEnv() { 49 | pEnv.MMS_PATTERN_NAME = `pattern-${pEnv.MMS_SERVICE_NAME}-${pEnv.ARCH}`; 50 | pEnv.MMS_CONTAINER = `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.MMS_SERVICE_NAME}_${pEnv.ARCH}:${pEnv.MMS_SERVICE_VERSION}`.replace(/\r?\n|\r/g, '') 51 | } 52 | getEnv() { 53 | return this.env; 54 | } 55 | getOrgId() { 56 | console.log(pEnv.HZN_ORG_ID) 57 | return pEnv.HZN_ORG_ID; 58 | } 59 | getExchangeUserAuth() { 60 | return pEnv.HZN_EXCHANGE_USER_AUTH; 61 | } 62 | getExchangeUrl() { 63 | return pEnv.HZN_EXCHANGE_URL; 64 | } 65 | getFSSCSSUrl() { 66 | return pEnv.HZN_FSS_CSSURL; 67 | } 68 | getMyServiceName() { 69 | return pEnv.YOUR_SERVICE_NAME; 70 | } 71 | getMyServiceVersion() { 72 | return pEnv.YOUR_SERVICE_VERSION; 73 | } 74 | getMMSSharedVolume() { 75 | return pEnv.MMS_SHARED_VOLUME; 76 | } 77 | getMyDockerHubId() { 78 | return pEnv.YOUR_DOCKERHUB_ID; 79 | } 80 | getDockerImageBase() { 81 | return `${pEnv.YOUR_DOCKERHUB_ID}/${pEnv.MMS_SERVICE_NAME}`; 82 | } 83 | getMMSContainerCreds() { 84 | return pEnv.MMS_CONTAINER_CREDS; 85 | } 86 | getMMSPatterName() { 87 | return pEnv.MMS_PATTERN_NAME; 88 | } 89 | getMMSServiceName() { 90 | return pEnv.MMS_SERVICE_NAME; 91 | } 92 | getMMSServiceVersion() { 93 | return pEnv.MMS_SERVICE_VERSION; 94 | } 95 | getMMSContainer() { 96 | return pEnv.MMS_CONTAINER; 97 | } 98 | getArch() { 99 | return pEnv.ARCH; 100 | } 101 | getMMSObjectType() { 102 | return pEnv.MMS_OBJECT_TYPE; 103 | } 104 | getMMSObjectId() { 105 | return pEnv.MMS_OBJECT_ID 106 | } 107 | getMMSObjectFile() { 108 | return pEnv.MMS_OBJECT_FILE 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /code-engine/common/interface/model.ts: -------------------------------------------------------------------------------- 1 | export interface IPayload { 2 | hello: string; 3 | events: IEAMEvent[]; 4 | } 5 | export class LastRun { 6 | timestamp: number; 7 | succeeded: boolean; 8 | 9 | constructor(timestamp = 0, succeeded = false) { 10 | this.succeeded =succeeded; 11 | this.timestamp = timestamp; 12 | } 13 | } 14 | export class IEAMEvent { 15 | title: string = ''; 16 | type: string = ''; 17 | id: string = ''; 18 | action: string = ''; 19 | meta: any = {}; 20 | start: string = ''; 21 | end: string = ''; 22 | frequency: number = 60000; 23 | lastRun: LastRun; 24 | 25 | constructor(event: IEAMEvent) { 26 | this.lastRun = new LastRun(); 27 | Object.assign(this, event) 28 | } 29 | 30 | isValidDate(date: string) { 31 | return !isNaN(Date.parse(date)) 32 | } 33 | getStartTime() { 34 | return new Date(this.start) 35 | } 36 | getEndTime() { 37 | return new Date(this.end) 38 | } 39 | isWithinDateRange() { 40 | if(this.isValidDate(this.start) && this.isValidDate(this.end)) { 41 | const date = new Date() 42 | const start = new Date(this.start) 43 | const end = new Date(this.end) 44 | return date >= start && date <= end 45 | } else { 46 | return false 47 | } 48 | } 49 | isWithinTimeRange() { 50 | if(this.isWithinDateRange()) { 51 | const now = Date.now(); 52 | const start = new Date(this.start).getTime(); 53 | const end = new Date(this.end).getTime(); 54 | return now >= start && now <= end 55 | } else { 56 | return false 57 | } 58 | } 59 | isTimeToRun() { 60 | if(this.isWithinDateRange()) { 61 | return Date.now() - this.lastRun.timestamp > this.frequency 62 | } else { 63 | return false 64 | } 65 | } 66 | isActionAllow() { 67 | return AllowableActions.indexOf(this.action) >= 0 68 | } 69 | isClearToRun() { 70 | return this.isActionAllow() && this.isWithinTimeRange() && this.isTimeToRun() 71 | } 72 | } 73 | 74 | export class EnumClass { 75 | private enum: any = {}; 76 | constructor(private eArray: any[] = []) { 77 | eArray.map((el, idx) => { 78 | this.enum[el] = idx; 79 | }); 80 | } 81 | 82 | getEnum(key: string) { 83 | return this.enum[key]; 84 | } 85 | } 86 | 87 | export const AllowableActions = [ 88 | 'autoRegisterWithPolicy', 'autoRegisterWithPattern', 'autoUnregister', 'autoUpdateNodePolicy' 89 | ] 90 | 91 | export enum Action { 92 | autoUpdateNodePolicy = 0, 93 | autoRegisterWithPolicy = 1, 94 | autoRegisterWithPattern = 2, 95 | autoUnregister = 3 96 | } 97 | 98 | export class EventTime { 99 | hour: number; 100 | minute: number; 101 | second: number; 102 | meriden: 'PM' | 'AM'; 103 | format: 12 | 24; 104 | } 105 | 106 | export interface IProperty { 107 | name: string; 108 | value: string; 109 | } 110 | export interface IConstraint { 111 | constraints: string[] | null; 112 | } 113 | export class PolicyClass { 114 | properties: IProperty[] | null = null; 115 | constraints: IConstraint = null; 116 | } 117 | export class IEAMPolicy { 118 | properties: IProperty[]; 119 | constraints: IConstraint; 120 | deployment: PolicyClass = new PolicyClass(); 121 | managment: PolicyClass = new PolicyClass(); 122 | 123 | constructor(policy: IEAMPolicy) { 124 | Object.assign(this, policy) 125 | } 126 | } 127 | 128 | export const TopLevelDefaultProperties = [ 129 | 'openhorizon.hardwareId', 'openhorizon.operatingSystem', 'openhorizon.containerized', 'openhorizon.cpu', 'openhorizon.arch', 'openhorizon.memory' 130 | ] -------------------------------------------------------------------------------- /code-engine/ieam-service/common/interface/model.ts: -------------------------------------------------------------------------------- 1 | export interface IPayload { 2 | hello: string; 3 | events: IEAMEvent[]; 4 | } 5 | export class LastRun { 6 | timestamp: number; 7 | succeeded: boolean; 8 | 9 | constructor(timestamp = 0, succeeded = false) { 10 | this.succeeded =succeeded; 11 | this.timestamp = timestamp; 12 | } 13 | } 14 | export class IEAMEvent { 15 | title: string = ''; 16 | type: string = ''; 17 | id: string = ''; 18 | action: string = ''; 19 | meta: any = {}; 20 | start: string = ''; 21 | end: string = ''; 22 | frequency: number = 60000; 23 | lastRun: LastRun; 24 | 25 | constructor(event: IEAMEvent) { 26 | this.lastRun = new LastRun(); 27 | Object.assign(this, event) 28 | } 29 | 30 | isValidDate(date: string) { 31 | return !isNaN(Date.parse(date)) 32 | } 33 | getStartTime() { 34 | return new Date(this.start) 35 | } 36 | getEndTime() { 37 | return new Date(this.end) 38 | } 39 | isWithinDateRange() { 40 | if(this.isValidDate(this.start) && this.isValidDate(this.end)) { 41 | const date = new Date() 42 | const start = new Date(this.start) 43 | const end = new Date(this.end) 44 | return date >= start && date <= end 45 | } else { 46 | return false 47 | } 48 | } 49 | isWithinTimeRange() { 50 | if(this.isWithinDateRange()) { 51 | const now = Date.now(); 52 | const start = new Date(this.start).getTime(); 53 | const end = new Date(this.end).getTime(); 54 | return now >= start && now <= end 55 | } else { 56 | return false 57 | } 58 | } 59 | isTimeToRun() { 60 | if(this.isWithinDateRange()) { 61 | return Date.now() - this.lastRun.timestamp > this.frequency 62 | } else { 63 | return false 64 | } 65 | } 66 | isActionAllow() { 67 | return AllowableActions.indexOf(this.action) >= 0 68 | } 69 | isClearToRun() { 70 | return this.isActionAllow() && this.isWithinTimeRange() && this.isTimeToRun() 71 | } 72 | } 73 | 74 | export class EnumClass { 75 | private enum: any = {}; 76 | constructor(private eArray: any[] = []) { 77 | eArray.map((el, idx) => { 78 | this.enum[el] = idx; 79 | }); 80 | } 81 | 82 | getEnum(key: string) { 83 | return this.enum[key]; 84 | } 85 | } 86 | 87 | export const AllowableActions = [ 88 | 'autoRegisterWithPolicy', 'autoRegisterWithPattern', 'autoUnregister', 'autoUpdateNodePolicy' 89 | ] 90 | 91 | export enum Action { 92 | autoUpdateNodePolicy = 0, 93 | autoRegisterWithPolicy = 1, 94 | autoRegisterWithPattern = 2, 95 | autoUnregister = 3 96 | } 97 | 98 | export class EventTime { 99 | hour: number; 100 | minute: number; 101 | second: number; 102 | meriden: 'PM' | 'AM'; 103 | format: 12 | 24; 104 | } 105 | 106 | export interface IProperty { 107 | name: string; 108 | value: string; 109 | } 110 | export interface IConstraint { 111 | constraints: string[] | null; 112 | } 113 | export class PolicyClass { 114 | properties: IProperty[] | null = null; 115 | constraints: IConstraint = null; 116 | } 117 | export class IEAMPolicy { 118 | properties: IProperty[]; 119 | constraints: IConstraint; 120 | deployment: PolicyClass = new PolicyClass(); 121 | managment: PolicyClass = new PolicyClass(); 122 | 123 | constructor(policy: IEAMPolicy) { 124 | Object.assign(this, policy) 125 | } 126 | } 127 | 128 | export const TopLevelDefaultProperties = [ 129 | 'openhorizon.hardwareId', 'openhorizon.operatingSystem', 'openhorizon.containerized', 'openhorizon.cpu', 'openhorizon.arch', 'openhorizon.memory' 130 | ] -------------------------------------------------------------------------------- /code-engine/ieam-action/bin/deploy.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | const fs = require('fs'); 5 | const { Observable } = require('rxjs'); 6 | const dotenv = require('dotenv'); 7 | const cosAccess = require('../../.env-local.json'); 8 | 9 | if(fs.existsSync('../.env-local')) { 10 | const localEnv = dotenv.parse(fs.readFileSync('../.env-local')); 11 | for(var i in localEnv) { 12 | process.env[i] = localEnv[i]; 13 | } 14 | } 15 | 16 | const env = process.env.npm_config_env || 'prod'; 17 | const package = process.env.npm_config_package || 'ieam-admin'; 18 | const name = process.env.npm_config_name; 19 | const task = process.env.npm_config_task; 20 | const update = process.env.npm_config_create ? 'create' : 'update'; 21 | const version = process.env.npm_config_image_version; 22 | 23 | console.log(task) 24 | if(!task) { 25 | console.log(`specify --task taskname...`) 26 | process.exit(0) 27 | } 28 | if(!name) { 29 | console.log(`name is required: specify --name appname...`) 30 | process.exit(0) 31 | } 32 | if(!version) { 33 | console.log(`version is required: specify --image-version x.x.x`) 34 | process.exit(0) 35 | } 36 | let imageName = `${process.env.REGISTRY}${name}-${env}:${version}`; 37 | let appName = `${name}-${env}`; 38 | console.log(appName, imageName) 39 | 40 | let build = { 41 | doall: () => { 42 | let arg = 'npm run build && npm run bundle' 43 | build.shell(arg) 44 | .subscribe(() => { 45 | arg = `docker build --no-cache -t ${imageName} . ` 46 | build.shell(arg,`done building ${imageName} image`, `failed to build ${imageName} image`) 47 | .subscribe(() => { 48 | let arg = `docker push ${imageName}` 49 | build.shell(arg,`done pushing ${imageName} image`, `failed to push ${imageName} image`) 50 | .subscribe(() => { 51 | build.deploy() 52 | }) 53 | }) 54 | }) 55 | }, 56 | build: () => { 57 | let arg = `docker build --no-cache -t ${imageName} . ` 58 | build.shell(arg,`done building ${imageName} image`, `failed to build ${imageName} image`) 59 | .subscribe(() => { 60 | process.exit(0) 61 | }) 62 | }, 63 | push: () => { 64 | let arg = `docker push ${imageName}` 65 | build.shell(arg,`done pushing ${imageName} image`, `failed to push ${imageName} image`) 66 | .subscribe(() => { 67 | process.exit(0) 68 | }) 69 | }, 70 | deploy: () => { 71 | build.getEnvVar(); 72 | let pEnv = process.env; 73 | let arg = `ibmcloud ce app ${update} -n ${appName} --image ${imageName}` 74 | arg += ` --env bucket=${pEnv.BUCKET} --env accessKeyId=${pEnv.ACCESSKEYID}`; 75 | arg += ` --env secretAccessKey=${pEnv.SECRETACCESSKEY} --env endpoint=${pEnv.COS_ENDPOINT}`; 76 | arg += ` --env ibmAuthEndpoint=${pEnv.COS_IBMAUTHENDPOINT} --env region=${pEnv.REGION}`; 77 | arg += ` --env serviceInstanceId=${pEnv.SERVICEINSTANCEID}`; 78 | console.log('deploying...') 79 | build.shell(arg,`done add/update ${appName}`, `failed to add/update ${appName}`, false) 80 | .subscribe({ 81 | complete: () => process.exit(0), 82 | error: (err) => { 83 | console.log('specify --create if this is a new service.') 84 | process.exit(0) 85 | } 86 | }) 87 | }, 88 | getEnvVar: () => { 89 | let pEnv = process.env; 90 | pEnv.PACKAGE = package; 91 | pEnv.ACCESSKEYID = cosAccess[env]['access_key_id']; 92 | pEnv.SECRETACCESSKEY = cosAccess[env]['secret_access_key']; 93 | pEnv.APIKEYID = cosAccess[env]['apikey']; 94 | pEnv.SERVICEINSTANCEID = cosAccess[env]['resource_instance_id']; 95 | pEnv.BUCKET = cosAccess[env]['bucket']; 96 | pEnv.COS_IBMAUTHENDPOINT = cosAccess[env]['ibmAuthEndpoint']; 97 | pEnv.COS_ENDPOINT = cosAccess[env]['endpoint']; 98 | pEnv.REGION = cosAccess[env]['region']; 99 | }, 100 | shell: (arg, success='command executed successfully', error='command failed', prnStdout=true, options={maxBuffer: 1024 * 2000}) => { 101 | return new Observable((observer) => { 102 | console.log(arg); 103 | let child = exec(arg, options, (err, stdout, stderr) => { 104 | if(!err) { 105 | // console.log(stdout); 106 | console.log(success); 107 | observer.next(prnStdout ? stdout : ''); 108 | observer.complete(); 109 | } else { 110 | console.log(`${error}: ${err}`); 111 | observer.error(err); 112 | } 113 | }); 114 | child.stdout.pipe(process.stdout); 115 | child.on('data', (data) => { 116 | console.log(data) 117 | }) 118 | }); 119 | } 120 | } 121 | 122 | build[task](); -------------------------------------------------------------------------------- /code-engine/ieam-action/src/utility.ts: -------------------------------------------------------------------------------- 1 | import { Observable, of, forkJoin } from 'rxjs'; 2 | import { existsSync, accessSync, chmod, constants, renameSync, copyFileSync, unlinkSync, readFileSync, readdirSync, writeFileSync, mkdirSync } from 'fs'; 3 | import { Params } from '@common/params/params'; 4 | import * as http from 'http'; 5 | import * as os from 'os'; 6 | import * as cryptoJS from 'crypto-js'; 7 | import * as ethers from 'ethers'; 8 | const ifs: any = os.networkInterfaces(); 9 | import * as jsonfile from 'jsonfile'; 10 | 11 | export const util = { 12 | passPhrase: 'iEAM&openHoriZon', 13 | sessionToken: 'geTSesSiontOkEnfOrvAliDation', 14 | encrypt: (text: string) => { 15 | return cryptoJS.enc.Base64.stringify(cryptoJS.enc.Utf8.parse(text)); 16 | }, 17 | decrypt: (data: string) => { 18 | return cryptoJS.enc.Base64.parse(data).toString(cryptoJS.enc.Utf8); 19 | }, 20 | encryptAES: (text: string = util.sessionToken + Date.now()) => { 21 | const ciphertext = cryptoJS.AES.encrypt(text, util.passPhrase).toString() 22 | return ciphertext; 23 | }, 24 | decryptAES: (cipherText: string) => { 25 | const decrypted = cryptoJS.AES.decrypt(cipherText, util.passPhrase) 26 | let originalText = '' 27 | if(decrypted) { 28 | originalText = decrypted.toString(cryptoJS.enc.Utf8); 29 | } 30 | return originalText; 31 | }, 32 | validateSession: (sessionId: string) => { 33 | const seed = util.decryptAES(sessionId, util.passPhrase) 34 | return Date.now() - parseInt(seed.substring(util.sessionToken.length)) < 300000; 35 | }, 36 | signature: (params: Params) => { 37 | return new Observable((observer) => { 38 | const claimedAddr = params.addr 39 | let error = "", realAddr = "" 40 | try { 41 | const seed = util.decryptAES(params.sessionId, util.passPhrase) 42 | // console.log('sessionId: ', queryString.sessionId) 43 | // console.log('seed', seed, util.sessionToken, seed.indexOf(util.sessionToken)) 44 | if(seed.indexOf(util.sessionToken) == 0) { 45 | const expectedMsg = `My session ID: ${params.sessionId}` 46 | const hash = ethers.utils.id(`\x19Ethereum Signed Message:\n${expectedMsg.length}${expectedMsg}`) 47 | realAddr = ethers.utils.recoverAddress(hash, params.sig) 48 | } else { 49 | error = `Invalid sessionId: ${params.sessionId}` 50 | } 51 | } catch (err) { 52 | error = err.reason 53 | } 54 | 55 | if (error) { 56 | observer.error({msg: error}) 57 | } else { 58 | if (realAddr.toLowerCase() === claimedAddr.toLowerCase()) { 59 | observer.next({msg: `Legitimate, welcome ${realAddr}`, valid: true}) 60 | observer.complete() 61 | } else { 62 | observer.error({msg: `Fraud!!! You are not ${claimedAddr}, you are ${realAddr}!`}) 63 | } 64 | } 65 | }); 66 | }, 67 | checkLeapYear: (year: number) => { 68 | //three conditions to find out the leap year 69 | if ((0 == year % 4) && (0 != year % 100) || (0 == year % 400)) { 70 | console.log(year + ' is a leap year'); 71 | return true; 72 | } else { 73 | console.log(year + ' is not a leap year'); 74 | return false; 75 | } 76 | }, 77 | timeDifference: (date1: Date, date2: Date) => { 78 | let difference = date1.getTime() - date2.getTime(); 79 | let daysDifference = Math.floor(difference/1000/60/60/24); 80 | 81 | difference -= daysDifference*1000*60*60*24 82 | let hoursDifference = Math.floor(difference/1000/60/60); 83 | 84 | difference -= hoursDifference*1000*60*60 85 | let minutesDifference = Math.floor(difference/1000/60); 86 | 87 | difference -= minutesDifference*1000*60 88 | let secondsDifference = Math.floor(difference/1000); 89 | 90 | // NOTE for debugging 91 | // console.log('difference = ' + 92 | // daysDifference + ' day/s ' + 93 | // hoursDifference + ' hour/s ' + 94 | // minutesDifference + ' minute/s ' + 95 | // secondsDifference + ' second/s '); 96 | return {days: daysDifference, hours: hoursDifference, minutes: minutesDifference, seconds: secondsDifference} 97 | }, 98 | shallowEqual: (obj1: any, obj2: any) => { 99 | const keys1 = Object.keys(obj1); 100 | const keys2 = Object.keys(obj2); 101 | if (keys1.length !== keys2.length) { 102 | return false; 103 | } 104 | let diff = false 105 | keys1.some((key) => { 106 | diff = obj1[key] !== obj2[key] 107 | return diff 108 | }) 109 | return !diff; 110 | }, 111 | getIpAddress: () => { 112 | return Object.keys(ifs) 113 | .map(x => [x, ifs[x].filter(x => x.family === 'IPv4')[0]]) 114 | .filter(x => x[1]) 115 | .map(x => x[1].address); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /cloud-function/demo/bin/build.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const path = require('path'); 3 | const cp = require('child_process'), 4 | exec = cp.exec; 5 | const fs = require('fs'); 6 | var dotenv = require('dotenv'); 7 | 8 | if(fs.existsSync('.env-local')) { 9 | const localEnv = dotenv.parse(fs.readFileSync('.env-local')); 10 | for(var i in localEnv) { 11 | process.env[i] = localEnv[i]; 12 | } 13 | } 14 | const task = process.env.npm_config_task || 'createAction'; 15 | const package = process.env.npm_config_package || 'labs'; 16 | process.chdir('intellicast-action'); 17 | 18 | let build = { 19 | createAction: () => { 20 | process.chdir('../intellicast-action'); 21 | console.log(process.cwd(), `${package}`); 22 | if(fs.existsSync('intellicast-action.zip')) { 23 | fs.unlinkSync('intellicast-action.zip'); 24 | } 25 | exec(`zip -r intellicast-action.zip *`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 26 | if(!err) { 27 | console.log('done zipping intellicast action...'); 28 | let arg = `bx wsk action update ${package}/intellicast-action --kind nodejs:8 --timeout 280000 intellicast-action.zip`; 29 | arg += ` --param AWS_PROD_ACCESS_KEY ${process.env['AWS_PROD_ACCESS_KEY']} --param AWS_PROD_SECRET_ACCESS_KEY ${process.env['AWS_PROD_SECRET_ACCESS_KEY']}`; 30 | arg += ` --param AWS_STAGE_ACCESS_KEY ${process.env['AWS_STAGE_ACCESS_KEY']} --param AWS_STAGE_SECRET_ACCESS_KEY ${process.env['AWS_STAGE_SECRET_ACCESS_KEY']}`; 31 | arg += ` --param AWS_DEV_ACCESS_KEY ${process.env['AWS_DEV_ACCESS_KEY']} --param AWS_DEV_SECRET_ACCESS_KEY ${process.env['AWS_DEV_SECRET_ACCESS_KEY']}`; 32 | // arg += ` --web true`; 33 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 34 | if(!err) { 35 | console.log(`done add/update ${package}/intellicast-action`); 36 | build.createAnimateAction(); 37 | } else { 38 | console.log('failed to add/update intellicast action', err); 39 | } 40 | }); 41 | } else { 42 | console.log(err); 43 | } 44 | }); 45 | }, 46 | createAnimateAction: () => { 47 | process.chdir('../intellicast-animate-action'); 48 | if(fs.existsSync('intellicast-animate-action.zip')) { 49 | fs.unlinkSync('intellicast-animate-action.zip'); 50 | } 51 | console.log(process.cwd()); 52 | exec(`zip -r intellicast-animate-action.zip *`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 53 | if(!err) { 54 | console.log('done zipping intellicast animate action...'); 55 | arg = `bx wsk action update ${package}/intellicast-animate-action --kind nodejs:8 --memory 2048 --timeout 280000 intellicast-animate-action.zip`; 56 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 57 | if(!err) { 58 | console.log(`done add/update ${package}/intellicast-animate-action`); 59 | build.createBetaComposer(); 60 | } else { 61 | console.log('failed to add/update intellicast action', err); 62 | } 63 | }); 64 | } else { 65 | console.log(err); 66 | } 67 | }); 68 | }, 69 | createBetaComposer: () => { 70 | process.chdir('../intellicast-composer'); 71 | console.log(process.cwd()); 72 | exec(`compose index-${package}.js > index-${package}.json`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 73 | if(!err) { 74 | console.log('done composing intellicast-composer...'); 75 | exec(`deploy ${package}/intellicast-composer index-${package}.json -w`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 76 | if(!err) { 77 | console.log(`done deploying ${package}/intellicast-composer...`); 78 | } else { 79 | console.log(err); 80 | } 81 | }); 82 | } else { 83 | console.log('failed to add/update intellicast-composer', err); 84 | } 85 | }); 86 | }, 87 | createComposer: () => { 88 | process.chdir('../intellicast-composer'); 89 | console.log(process.cwd()); 90 | exec(`bx wsk action update ${package}/intellicast-animate-while --kind nodejs:8 ./intellicast-animate-while.js`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 91 | if(!err) { 92 | console.log('done composing intellicast-animate-while...'); 93 | exec(`fsh app update ${package}/intellicast-composer --kind nodejs:8 --timeout 280000 ./index-${package}.js`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 94 | if(!err) { 95 | console.log('done composing intellicast-composer...'); 96 | } else { 97 | console.log(err); 98 | } 99 | }); 100 | } else { 101 | console.log('failed to add/update intellicast-composer', err); 102 | } 103 | }); 104 | } 105 | } 106 | 107 | build[task](); 108 | 109 | // fsh app invoke tools/cms-composer --param env prod -------------------------------------------------------------------------------- /cloud-function/demo/bin/deploy.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | const fs = require('fs'); 5 | var dotenv = require('dotenv'); 6 | 7 | if(fs.existsSync('.env-local')) { 8 | const localEnv = dotenv.parse(fs.readFileSync('.env-local')); 9 | for(var i in localEnv) { 10 | process.env[i] = localEnv[i]; 11 | } 12 | } 13 | 14 | const env = process.env.npm_config_env || 'dev'; 15 | const task = process.env.npm_config_task || 'deploy'; 16 | const package = process.env.npm_config_package || 'wx-labs'; 17 | const yaml = process.env.npm_config_api ? 'manifest-api.yaml' : 'manifest.yaml'; 18 | 19 | let build = { 20 | deploy: () => { 21 | build.getEnvVar(); 22 | let arg = `BUCKET=${process.env.BUCKET} ACCESSKEYID=${process.env.ACCESSKEYID} `; 23 | arg += `SECRETACCESSKEY=${process.env.SECRETACCESSKEY} COS_ENDPOINT=${process.env.COS_ENDPOINT} `; 24 | arg += ` COS_IBMAUTHENDPOINT=${process.env.COS_IBMAUTHENDPOINT} REGION=${process.env.REGION} `; 25 | arg += ` SERVICEINSTANCEID=${process.env.SERVICEINSTANCEID} wskdeploy -m ${yaml}`; 26 | console.log('deploying...') 27 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 28 | if(!err) { 29 | console.log(stdout) 30 | console.log(`done deploying ${package}`); 31 | } else { 32 | console.log('failed to deploy', err); 33 | } 34 | }); 35 | }, 36 | deployJS: () => { 37 | if(fs.existsSync('demo-action.zip')) { 38 | fs.unlinkSync('demo-action.zip'); 39 | } 40 | exec(`zip -r demo-action.zip *`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 41 | if(!err) { 42 | console.log('done zipping demo action...'); 43 | build.getEnvVar(); 44 | let arg = `ibmcloud fn action update ${package}/demo-action --kind nodejs:12 --memory 2048 --timeout 280000 demo-action.zip`; 45 | arg += ` --param bucket ${process.env.BUCKET} --param accessKeyId ${process.env.ACCESSKEYID}`; 46 | arg += ` --param secretAccessKey ${process.env.SECRETACCESSKEY} --param endpoint ${process.env.COS_ENDPOINT}`; 47 | arg += ` --param ibmAuthEndpoint ${process.env.COS_IBMAUTHENDPOINT} --param region ${process.env.REGION}`; 48 | arg += ` --param serviceInstanceId ${process.env.SERVICEINSTANCEID}`; 49 | console.log('deploying...') 50 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 51 | if(!err) { 52 | console.log(stdout) 53 | console.log(`done add/update ${package}/demo-action`); 54 | } else { 55 | console.log('failed to add/update demo-action', err); 56 | } 57 | }); 58 | } else { 59 | console.log(err); 60 | } 61 | }); 62 | }, 63 | getEnvVar: () => { 64 | const cosAccess = JSON.parse(process.env.COS_ACCESS); 65 | let pEnv = process.env; 66 | pEnv.PACKAGE = package; 67 | pEnv.ACCESSKEYID = cosAccess[env]['access_key_id']; 68 | pEnv.SECRETACCESSKEY = cosAccess[env]['secret_access_key']; 69 | pEnv.APIKEYID = cosAccess[env]['apikey']; 70 | pEnv.SERVICEINSTANCEID = cosAccess[env]['resource_instance_id']; 71 | pEnv.BUCKET = cosAccess[env]['bucket']; 72 | }, 73 | createComposer: () => { 74 | console.log(process.cwd()); 75 | build.generateComposerJson(); 76 | exec(`compose ./dist/watson-services/src/watson-composer-${package}.js > ./dist/watson-services/src/watson-composer-${package}.json`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 77 | if(!err) { 78 | console.log('done composing watson-composer...'); 79 | exec(`deploy ${package}/watson-composer ./dist/watson-services/src/watson-composer-${package}.json -w`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 80 | if(!err) { 81 | console.log(`done deploying ${package}/watson-composer...`); 82 | } else { 83 | console.log(err); 84 | } 85 | }); 86 | } else { 87 | console.log('failed to add/update watson-composer', err); 88 | } 89 | }); 90 | }, 91 | generateComposerJson: () => { 92 | if(fs.existsSync('./dist/watson-services/src/watson-composer.js')) { 93 | const file = fs.readFileSync('./dist/watson-services/src/watson-composer.js').toString().split('\n'); 94 | let output = []; 95 | let match; 96 | file.forEach((line, i) => { 97 | if(line.indexOf('${package}') > 0) { 98 | line = line.replace('${package}', package); 99 | console.log('package', line); 100 | output.push(line); 101 | } else { 102 | output.push(line); 103 | } 104 | }); 105 | let text = output.join('\n'); 106 | fs.writeFileSync(`./dist/watson-services/src/watson-composer-${package}.js`, text, function (err) { 107 | if (err) { 108 | console.log(err); 109 | process.exit(1); 110 | } else { 111 | console.log(`generated ./dist/watson-services/src/watson-composer-${package}.js`); 112 | } 113 | }); 114 | } 115 | } 116 | } 117 | 118 | build[task](); -------------------------------------------------------------------------------- /cloud-function/hzn-action/bin/deploy.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | const cp = require('child_process'), 3 | exec = cp.exec; 4 | const fs = require('fs'); 5 | var dotenv = require('dotenv'); 6 | const cosAccess = require('../.env-cos.json'); 7 | 8 | if(fs.existsSync('.env-local')) { 9 | const localEnv = dotenv.parse(fs.readFileSync('.env-local')); 10 | for(var i in localEnv) { 11 | process.env[i] = localEnv[i]; 12 | } 13 | } 14 | 15 | const env = process.env.npm_config_env || 'dev'; 16 | const task = process.env.npm_config_task || 'deploy'; 17 | const package = process.env.npm_config_package || 'wx-labs'; 18 | const yaml = process.env.npm_config_api ? 'manifest-api.yaml' : 'manifest.yaml'; 19 | 20 | let build = { 21 | deployTS: () => { 22 | build.getEnvVar(); 23 | let arg = `ibmcloud fn action update ${package}/hzn-action dist/hzn-action.js --memory 2048 --timeout 20000 --docker playbox21/hzn-action `; 24 | arg += ` --param bucket ${process.env.BUCKET} --param accessKeyId ${process.env.ACCESSKEYID}`; 25 | arg += ` --param secretAccessKey ${process.env.SECRETACCESSKEY} --param endpoint ${process.env.COS_ENDPOINT}`; 26 | arg += ` --param ibmAuthEndpoint ${process.env.COS_IBMAUTHENDPOINT} --param region ${process.env.REGION}`; 27 | arg += ` --param serviceInstanceId ${process.env.SERVICEINSTANCEID}`; 28 | console.log('deploying...') 29 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 30 | if(!err) { 31 | console.log(stdout) 32 | console.log(`done add/update ${package}/hzn-action`); 33 | } else { 34 | console.log('failed to add/update hzn-action', err); 35 | } 36 | }); 37 | }, 38 | deploy: () => { 39 | build.getEnvVar(); 40 | let arg = `BUCKET=${process.env.BUCKET} ACCESSKEYID=${process.env.ACCESSKEYID} `; 41 | arg += `SECRETACCESSKEY=${process.env.SECRETACCESSKEY} COS_ENDPOINT=${process.env.COS_ENDPOINT} `; 42 | arg += ` COS_IBMAUTHENDPOINT=${process.env.COS_IBMAUTHENDPOINT} REGION=${process.env.REGION} `; 43 | arg += ` SERVICEINSTANCEID=${process.env.SERVICEINSTANCEID} wskdeploy -m ${yaml}`; 44 | console.log('deploying...') 45 | exec(arg, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 46 | if(!err) { 47 | console.log(stdout) 48 | console.log(`done deploying ${package}`); 49 | } else { 50 | console.log('failed to deploy', err); 51 | } 52 | }); 53 | }, 54 | getEnvVar: () => { 55 | let pEnv = process.env; 56 | pEnv.PACKAGE = package; 57 | pEnv.ACCESSKEYID = cosAccess[env]['access_key_id']; 58 | pEnv.SECRETACCESSKEY = cosAccess[env]['secret_access_key']; 59 | pEnv.APIKEYID = cosAccess[env]['apikey']; 60 | pEnv.SERVICEINSTANCEID = cosAccess[env]['resource_instance_id']; 61 | pEnv.BUCKET = cosAccess[env]['bucket']; 62 | }, 63 | getEnvVar2: () => { 64 | const cosAccess = JSON.parse(process.env.COS_ACCESS); 65 | let pEnv = process.env; 66 | pEnv.PACKAGE = package; 67 | pEnv.ACCESSKEYID = cosAccess[env]['access_key_id']; 68 | pEnv.SECRETACCESSKEY = cosAccess[env]['secret_access_key']; 69 | pEnv.APIKEYID = cosAccess[env]['apikey']; 70 | pEnv.SERVICEINSTANCEID = cosAccess[env]['resource_instance_id']; 71 | pEnv.BUCKET = cosAccess[env]['bucket']; 72 | }, 73 | createComposer: () => { 74 | console.log(process.cwd()); 75 | build.generateComposerJson(); 76 | exec(`compose ./dist/watson-services/src/watson-composer-${package}.js > ./dist/watson-services/src/watson-composer-${package}.json`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 77 | if(!err) { 78 | console.log('done composing watson-composer...'); 79 | exec(`deploy ${package}/watson-composer ./dist/watson-services/src/watson-composer-${package}.json -w`, {maxBuffer: 1024 * 2000}, (err, stdout, stderr) => { 80 | if(!err) { 81 | console.log(`done deploying ${package}/watson-composer...`); 82 | } else { 83 | console.log(err); 84 | } 85 | }); 86 | } else { 87 | console.log('failed to add/update watson-composer', err); 88 | } 89 | }); 90 | }, 91 | generateComposerJson: () => { 92 | if(fs.existsSync('./dist/watson-services/src/watson-composer.js')) { 93 | const file = fs.readFileSync('./dist/watson-services/src/watson-composer.js').toString().split('\n'); 94 | let output = []; 95 | let match; 96 | file.forEach((line, i) => { 97 | if(line.indexOf('${package}') > 0) { 98 | line = line.replace('${package}', package); 99 | console.log('package', line); 100 | output.push(line); 101 | } else { 102 | output.push(line); 103 | } 104 | }); 105 | let text = output.join('\n'); 106 | fs.writeFileSync(`./dist/watson-services/src/watson-composer-${package}.js`, text, function (err) { 107 | if (err) { 108 | console.log(err); 109 | process.exit(1); 110 | } else { 111 | console.log(`generated ./dist/watson-services/src/watson-composer-${package}.js`); 112 | } 113 | }); 114 | } 115 | } 116 | } 117 | 118 | build[task](); -------------------------------------------------------------------------------- /cloud-function/common/src/utils/utility.ts: -------------------------------------------------------------------------------- 1 | import * as https from 'https'; 2 | import * as NodeUuid from 'node-uuid'; 3 | import { Observable } from 'rxjs'; 4 | 5 | import { ApiParams } from '../params'; 6 | 7 | const util = { 8 | path: 'https://api.weather.com', 9 | httpGet: (url) => { 10 | return new Observable((observer) => { 11 | https.get(url, (resp) => { 12 | let data = ''; 13 | 14 | // A chunk of data has been recieved. 15 | resp.on('data', (chunk) => { 16 | data += chunk; 17 | }); 18 | // The whole response has been received. Print out the result. 19 | resp.on('end', () => { 20 | observer.next(JSON.parse(data)); 21 | observer.complete(); 22 | }); 23 | }).on("error", (err) => { 24 | console.log("Error: " + err.message); 25 | observer.error(err); 26 | }); 27 | }); 28 | }, 29 | getDate: (date = null) => { 30 | let theDate = !date ? new Date() : new Date(date) || new Date(); 31 | let locale = theDate.toLocaleString('en-US', {timeZone: 'America/New_York'}); 32 | return new Date(locale); 33 | }, 34 | formatMD: (date, UTC='') => { 35 | let dayOfMonth = UTC === 'UTC' ? date.getUTCDate() : date.getDate(); 36 | let monthOfYear = UTC === 'UTC' ? date.getUTCMonth() + 1 : date.getMonth() + 1; 37 | dayOfMonth = dayOfMonth > 9 ? dayOfMonth : `0${dayOfMonth}`; 38 | monthOfYear = monthOfYear > 9 ? monthOfYear : `0${monthOfYear}`; 39 | return {day: dayOfMonth, month: monthOfYear, year: date.getFullYear()}; 40 | }, 41 | defaultLocation: (params: ApiParams) => { 42 | params.lat = params.triggerFields && params.triggerFields.location ? params.triggerFields.location.lat.toFixed(2) : 33.96; 43 | params.lng = params.triggerFields && params.triggerFields.location ? params.triggerFields.location.lng.toFixed(2) : -84.41; 44 | }, 45 | uuid: () => { 46 | return NodeUuid.v4(); 47 | }, 48 | timeOffset: (tf: any) => { 49 | let date = new Date(); 50 | let locale = new Date(date.toLocaleString('en-US', {timeZone: tf.tz})); 51 | let offset = date.getHours() - locale.getHours(); 52 | tf.time = (parseInt(tf.hour)+offset)*60 + parseInt(tf.minutes); 53 | console.log(`tf.time$$: ${tf.time}, ${offset}, ${date.getHours()}, ${locale.getHours()}`) 54 | return tf; 55 | }, 56 | updateDB: (couchDB: any, params: ApiParams) => { 57 | return new Observable((observer) => { 58 | let _id = `wu:${params.trigger_identity}`; 59 | couchDB.db.get(_id, (err, doc) => { 60 | if(!err || err.statusCode === 404) { 61 | if(doc) { 62 | doc.active = false; 63 | } 64 | couchDB.db.insert(doc, function (err, result) { 65 | if (err) { 66 | console.log(err); 67 | observer.error(`db insert failed... ${err}`) 68 | } else { 69 | observer.next([]); 70 | observer.complete(); 71 | } 72 | }); 73 | } else { 74 | console.log('db get', err); 75 | observer.error(`db get failed... ${err}`) 76 | } 77 | }) 78 | }); 79 | }, 80 | dbUpdate: (couchDB: any, body: any) => { 81 | return new Observable((observer) => { 82 | couchDB.db.get(body._id, (err, doc) => { 83 | if(!err || err.statusCode === 404) { 84 | if(doc) { 85 | console.log('doc', doc); 86 | body = Object.assign(doc, body); 87 | } 88 | couchDB.db.insert(body, function (err, result) { 89 | if (err) { 90 | console.log(err); 91 | observer.error(`db insert failed... ${err}`) 92 | } else { 93 | observer.next([]); 94 | observer.complete(); 95 | } 96 | }); 97 | } else { 98 | console.log('db get', err); 99 | observer.error(`db get failed... ${err}`) 100 | } 101 | }) 102 | }); 103 | }, 104 | dbFind: (couchDB: any, query: any) => { 105 | return new Observable((observer) => { 106 | couchDB.db.find(query, (err, doc:any) => { 107 | if(doc) { 108 | console.log('$doc', doc); 109 | observer.next(doc); 110 | observer.complete(); 111 | } else { 112 | console.log('db get', err); 113 | observer.error(`db get failed... ${err}`) 114 | } 115 | }) 116 | }); 117 | }, 118 | dbRemove: (couchDB: any, id: string) => { 119 | return new Observable((observer) => { 120 | let query = { 121 | "selector": { 122 | "_id": id 123 | }, 124 | "fields": ["_id", "_rev"], 125 | "skip": 0, 126 | "execution_stats": true 127 | }; 128 | util.dbFind(couchDB, query).subscribe((data: any) => { 129 | let docs = data.docs; 130 | if(docs) { 131 | couchDB.db.destroy(id, docs[0]._rev, (err, doc:any) => { 132 | if(doc) { 133 | console.log('removed doc', doc._id); 134 | observer.next(`${doc._id} removed`); 135 | observer.complete(); 136 | } else { 137 | console.log('db remove', err); 138 | observer.error(`Remove failed... ${err}`) 139 | } 140 | }) 141 | } 142 | }) 143 | }); 144 | 145 | } 146 | } 147 | 148 | export { util }; --------------------------------------------------------------------------------