Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated Device Configuration with Event-Driven Filters #1309

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/workflows/build-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ jobs:
- name: cert-tool
directory: tools/cert-tool
file: tools/cert-tool/Dockerfile
- name: snippet-service
directory: snippet-service
file: .tmp/docker/snippet-service/Dockerfile
template-file: tools/docker/Dockerfile.in
- name: mongodb-standby-tool
directory: tools/mongodb/standby-tool
file: tools/mongodb/standby-tool/Dockerfile
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
log:
level: "debug"
dumpBody: "true"

- name: test/cqldb
cmd: test
checkRace: "true"
Expand All @@ -43,7 +43,6 @@ jobs:
log:
level: "debug"
dumpBody: "true"


# test without check race
- name: test/norace
Expand All @@ -52,7 +51,7 @@ jobs:
log:
level: "debug"
dumpBody: "true"

- name: test/norace/cqldb
cmd: test
database: "cqldb"
Expand Down Expand Up @@ -85,6 +84,10 @@ jobs:
log:
level: "debug"
dumpBody: "true"
snippetService:
log:
level: "debug"
dumpBody: "true"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -113,6 +116,7 @@ jobs:
TEST_RESOURCE_AGGREGATE_LOG_LEVEL=${{ matrix.resourceAggregate.log.level }} TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=${{ matrix.resourceAggregate.log.dumpBody }} \
TEST_GRPC_GATEWAY_LOG_LEVEL=${{ matrix.grpcGateway.log.level }} TEST_GRPC_GATEWAY_LOG_DUMP_BODY=${{ matrix.grpcGateway.log.dumpBody }} \
TEST_IDENTITY_STORE_LOG_LEVEL=${{ matrix.identityStore.log.level }} TEST_IDENTITY_STORE_LOG_DUMP_BODY=${{ matrix.identityStore.log.dumpBody }} \
TEST_SNIPPET_SERVICE_LOG_LEVEL=${{ matrix.snippetService.log.level }} TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=${{ matrix.snippetService.log.dumpBody }} \
TEST_DATABASE=${{ matrix.database }} \
${{ matrix.args }}

Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"TEST_GRPC_GATEWAY_LOG_DUMP_BODY": "false",
"TEST_IDENTITY_STORE_LOG_LEVEL": "info",
"TEST_IDENTITY_STORE_LOG_DUMP_BODY": "false",
"TEST_SNIPPET_SERVICE_LOG_LEVEL": "info",
"TEST_SNIPPET_SERVICE_LOG_DUMP_BODY": "false",
"TEST_DATABASE": "mongoDB",
"TEST_BRIDGE_DEVICE_CONFIG": "${workspaceFolder}/.tmp/bridge/config-test.yaml",
// "TEST_DEVICE_NAME": "bridged-device-0",
Expand Down
21 changes: 17 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ TEST_GRPC_GATEWAY_LOG_LEVEL ?= info
TEST_GRPC_GATEWAY_LOG_DUMP_BODY ?= false
TEST_IDENTITY_STORE_LOG_LEVEL ?= info
TEST_IDENTITY_STORE_LOG_DUMP_BODY ?= false
TEST_SNIPPET_SERVICE_LOG_LEVEL ?= info
TEST_SNIPPET_SERVICE_LOG_DUMP_BODY ?= false
TEST_MEMORY_COAP_GATEWAY_NUM_DEVICES ?= 1
TEST_MEMORY_COAP_GATEWAY_NUM_RESOURCES ?= 1
TEST_MEMORY_COAP_GATEWAY_EXPECTED_RSS_IN_MB ?= 50
Expand All @@ -42,7 +44,7 @@ CERT_TOOL_SIGN_ALG ?= ECDSA-SHA256
CERT_TOOL_ELLIPTIC_CURVE ?= P256
CERT_TOOL_IMAGE = ghcr.io/plgd-dev/hub/cert-tool:vnext

SUBDIRS := bundle certificate-authority cloud2cloud-connector cloud2cloud-gateway coap-gateway grpc-gateway resource-aggregate resource-directory http-gateway identity-store test/oauth-server tools/cert-tool
SUBDIRS := bundle certificate-authority cloud2cloud-connector cloud2cloud-gateway coap-gateway grpc-gateway resource-aggregate resource-directory http-gateway identity-store snippet-service test/oauth-server tools/cert-tool
.PHONY: $(SUBDIRS) push proto/generate clean build test env mongo nats certificates hub-build http-gateway-www simulators

default: build
Expand Down Expand Up @@ -327,9 +329,9 @@ define RUN-TESTS-IN-DIRECTORY
COVERAGE_FILE=/coverage/$$(echo $(1) | sed -e "s/[\.\/]//g").coverage.txt ; \
JSON_REPORT_FILE=$(WORKING_DIRECTORY)/.tmp/report/$$(echo $(1) | sed -e "s/[\.\/]//g").report.json ; \
if [ -n "$${JSON_REPORT}" ]; then \
$(call RUN-DOCKER, go test -timeout=45m -race -p 1 -v $(1)... -covermode=atomic -coverprofile=$${COVERAGE_FILE} -json > "$${JSON_REPORT_FILE}") \
$(call RUN-DOCKER, /bin/sh -c "$(2) go test -timeout=45m -race -p 1 -v $(1)... -covermode=atomic -coverprofile=$${COVERAGE_FILE} -json > $${JSON_REPORT_FILE}") \
else \
$(call RUN-DOCKER, go test -timeout=45m -race -p 1 -v $(1)... -covermode=atomic -coverprofile=$${COVERAGE_FILE}) \
$(call RUN-DOCKER, /bin/sh -c "$(2) go test -timeout=45m -race -p 1 -v $(1)... -covermode=atomic -coverprofile=$${COVERAGE_FILE}") \
fi ; \
EXIT_STATUS=$$? ; \
if [ $${EXIT_STATUS} -ne 0 ]; then \
Expand Down Expand Up @@ -372,13 +374,15 @@ define RUN-TESTS-UDP
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY) \
TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \
TEST_DATABASE=$(TEST_DATABASE))
$(call RUN-TESTS,iotivity-lite-dtls,./test/iotivity-lite/service,-timeout=$(TEST_TIMEOUT) $(GO_BUILD_ARG) -p 1 -v -tags=test,\
TEST_COAP_GATEWAY_UDP_ENABLED=$(TEST_COAP_GATEWAY_UDP_ENABLED) \
TEST_COAP_GATEWAY_LOG_LEVEL=$(TEST_COAP_GATEWAY_LOG_LEVEL) TEST_COAP_GATEWAY_LOG_DUMP_BODY=$(TEST_COAP_GATEWAY_LOG_DUMP_BODY) \
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY) \
TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \
TEST_DATABASE=$(TEST_DATABASE))
endef

Expand All @@ -391,6 +395,7 @@ test: env hub-test
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY) \
TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \
TEST_DATABASE=$(TEST_DATABASE))
ifeq ($(TEST_COAP_GATEWAY_UDP_ENABLED),true)
@$(call RUN-TESTS-UDP)
Expand All @@ -411,6 +416,7 @@ test/mem: env/test/mem hub-test
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY)\
TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \
TEST_DATABASE=$(TEST_DATABASE))
.PHONY: test/mem

Expand All @@ -428,7 +434,14 @@ $(test-targets): %: env hub-test
echo "No golang files detected, directory $$TARGET_DIRECTORY skipped"; \
exit 0; \
fi ; \
$(call RUN-TESTS-IN-DIRECTORY,$(patsubst test-%,./%/,$@))
$(call RUN-TESTS-IN-DIRECTORY,$(patsubst test-%,./%/,$@),\
TEST_COAP_GATEWAY_UDP_ENABLED=$(TEST_COAP_GATEWAY_UDP_ENABLED) \
TEST_COAP_GATEWAY_LOG_LEVEL=$(TEST_COAP_GATEWAY_LOG_LEVEL) TEST_COAP_GATEWAY_LOG_DUMP_BODY=$(TEST_COAP_GATEWAY_LOG_DUMP_BODY) \
TEST_RESOURCE_AGGREGATE_LEVEL=$(TEST_RESOURCE_AGGREGATE_LEVEL) TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY=$(TEST_RESOURCE_AGGREGATE_LOG_DUMP_BODY) \
TEST_GRPC_GATEWAY_LOG_LEVEL=$(TEST_GRPC_GATEWAY_LOG_LEVEL) TEST_GRPC_GATEWAY_LOG_DUMP_BODY=$(TEST_GRPC_GATEWAY_LOG_DUMP_BODY) \
TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY) \
TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \
TEST_DATABASE=$(TEST_DATABASE))

.PHONY: $(test-targets)

Expand Down
11 changes: 11 additions & 0 deletions bundle/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ RUN go build \
-o "/go/bin/$tool" \
./

#snippet-service
ARG service=snippet-service
WORKDIR $root_directory/$service
RUN go build -ldflags "-linkmode external -extldflags -static -X github.com/plgd-dev/hub/v2/pkg/build.CommitDate=$COMMIT_DATE -X github.com/plgd-dev/hub/v2/pkg/build.CommitHash=$SHORT_COMMIT -X github.com/plgd-dev/hub/v2/pkg/build.BuildDate=$DATE -X github.com/plgd-dev/hub/v2/pkg/build.Version=$VERSION -X github.com/plgd-dev/hub/v2/pkg/build.ReleaseURL=$RELEASE_URL" \
-o "/go/bin/$service" \
./cmd/service

#nats
WORKDIR $root_directory
RUN apkArch="$(apk --print-arch)"; \
Expand Down Expand Up @@ -178,6 +185,8 @@ COPY --from=build /go/bin/cloud2cloud-connector /usr/local/bin/cloud2cloud-conne
COPY --from=build /go/src/github.com/plgd-dev/hub/cloud2cloud-connector/config.yaml /configs/cloud2cloud-connector.yaml
COPY --from=build /go/src/github.com/plgd-dev/hub/bundle/run.sh /usr/local/bin/run.sh
COPY --from=build /go/src/github.com/plgd-dev/hub/bundle/nginx /nginx
COPY --from=build /go/bin/snippet-service /usr/local/bin/snippet-service
COPY --from=build /go/src/github.com/plgd-dev/hub/snippet-service/config.yaml /configs/snippet-service.yaml

# install scylla
RUN curl -sSf get.scylladb.com/server | sudo bash -s -- --scylla-version 5.2
coderabbitai[bot] marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -232,6 +241,8 @@ ENV NATS_PORT=10001
ENV SCYLLA_SMP=1
ENV SCYLLA_DEVELOPER_MODE=true
ENV SCYLLA_PORT=29142
ENV SNIPPET_SERVICE_PORT=9091
ENV HTTP_SNIPPET_SERVICE_PORT=9092
ENV M2M_OAUTH_SERVER_PORT=9080

# OAuth
Expand Down
14 changes: 14 additions & 0 deletions bundle/nginx/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ http {
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
location ~ ^(/snippet-service) {
set $upstream_snippet_service https://127.0.0.1:REPLACE_HTTP_SNIPPET_SERVICE_PORT;
proxy_pass $upstream_snippet_service;
proxy_ssl_certificate /data/certs/internal/endpoint.crt;
proxy_ssl_certificate_key /data/certs/internal/endpoint.key;
proxy_ssl_trusted_certificate /data/certs/root_ca.crt;
proxy_ssl_verify on;
set $cors_headers 'Authority,Method,Path,Scheme,Accept,Accept-Encoding,Accept-Language,Content-Type,Origin,Refer,Sec-Fetch-Dest,Sec-Fetch-Mode,Sec-Fetch-Site,Authorization,DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,correlation-id';
include /nginx/cors.conf;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
location ~ ^/ {
set $upstream_http_gateway https://127.0.0.1:REPLACE_HTTP_GATEWAY_PORT;
proxy_pass $upstream_http_gateway;
Expand Down
56 changes: 56 additions & 0 deletions bundle/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export NGINX_PATH="/data/nginx"
export JETSTREAM_PATH="/data/jetstream"

export CERTIFICATE_AUTHORITY_ADDRESS="localhost:${CERTIFICATE_AUTHORITY_PORT}"
export CERTIFICATE_AUTHORITY_HTTP_ADDRESS="localhost:${HTTP_CERTIFICATE_AUTHORITY_PORT}"
export MOCK_OAUTH_SERVER_ADDRESS="localhost:${MOCK_OAUTH_SERVER_PORT}"
export RESOURCE_AGGREGATE_ADDRESS="localhost:${RESOURCE_AGGREGATE_PORT}"
export RESOURCE_DIRECTORY_ADDRESS="localhost:${RESOURCE_DIRECTORY_PORT}"
Expand All @@ -23,6 +24,8 @@ export GRPC_GATEWAY_ADDRESS="localhost:${GRPC_GATEWAY_PORT}"
export HTTP_GATEWAY_ADDRESS="localhost:${HTTP_GATEWAY_PORT}"
export CLOUD2CLOUD_GATEWAY_ADDRESS="localhost:${CLOUD2CLOUD_GATEWAY_PORT}"
export CLOUD2CLOUD_CONNECTOR_ADDRESS="localhost:${CLOUD2CLOUD_CONNECTOR_PORT}"
export SNIPPET_SERVICE_ADDRESS="localhost:${SNIPPET_SERVICE_PORT}"
export SNIPPET_SERVICE_HTTP_ADDRESS="localhost:${HTTP_SNIPPET_SERVICE_PORT}"
export M2M_OAUTH_SERVER_ADDRESS="localhost:${M2M_OAUTH_SERVER_PORT}"

export INTERNAL_CERT_DIR_PATH="$CERTIFICATES_PATH/internal"
Expand Down Expand Up @@ -484,6 +487,7 @@ if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${NGINX_PATH}/nginx.conf" ]; then
sed -i "s/REPLACE_CLOUD2CLOUD_GATEWAY_PORT/$CLOUD2CLOUD_GATEWAY_PORT/g" ${NGINX_PATH}/nginx.conf
sed -i "s/REPLACE_CLOUD2CLOUD_CONNECTOR_PORT/$CLOUD2CLOUD_CONNECTOR_PORT/g" ${NGINX_PATH}/nginx.conf
sed -i "s/REPLACE_HTTP_CERTIFICATE_AUTHORITY_PORT/$HTTP_CERTIFICATE_AUTHORITY_PORT/g" ${NGINX_PATH}/nginx.conf
sed -i "s/REPLACE_HTTP_SNIPPET_SERVICE_PORT/$HTTP_SNIPPET_SERVICE_PORT/g" ${NGINX_PATH}/nginx.conf
sed -i "s/REPLACE_M2M_OAUTH_SERVER_PORT/$M2M_OAUTH_SERVER_PORT/g" ${NGINX_PATH}/nginx.conf
fi

Expand Down Expand Up @@ -1009,6 +1013,7 @@ cat /configs/certificate-authority.yaml | yq e "\
.apis.grpc.authorization.http.tls.useSystemCAPool = true |
.apis.grpc.authorization.authority = \"https://${OAUTH_ENDPOINT}\" |
.apis.grpc.authorization.ownerClaim = \"${OWNER_CLAIM}\" |
.apis.http.address = \"${CERTIFICATE_AUTHORITY_HTTP_ADDRESS}\" |
.clients.storage.use = \"${DATABASE_USE}\" |
.clients.storage.mongoDB.uri = \"${MONGODB_URI}\" |
.clients.storage.cqlDB.hosts = [ \"${SCYLLA_HOSTNAME}\" ] |
Expand Down Expand Up @@ -1241,7 +1246,51 @@ while true; do
sleep 1
done

# snippet-service
echo "starting snippet-service"
## configuration
if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "/data/snippet-service.yaml" ]; then
cat /configs/snippet-service.yaml | yq e "\
.hubID = \"${HUB_ID}\" |
.log.level = \"${LOG_LEVEL}\" |
.apis.grpc.address = \"${SNIPPET_SERVICE_ADDRESS}\" |
.apis.grpc.authorization.audience = \"${SERVICE_OAUTH_AUDIENCE}\" |
.apis.grpc.authorization.http.tls.useSystemCAPool = true |
.apis.grpc.authorization.authority = \"https://${OAUTH_ENDPOINT}\" |
.apis.grpc.authorization.ownerClaim = \"${OWNER_CLAIM}\" |
.apis.http.address = \"${SNIPPET_SERVICE_HTTP_ADDRESS}\" |
.clients.storage.use = \"${DATABASE_USE}\" |
.clients.storage.mongoDB.uri = \"${MONGODB_URI}\" |
.clients.storage.cqlDB.hosts = [ \"${SCYLLA_HOSTNAME}\" ] |
.clients.storage.cqlDB.port = ${SCYLLA_PORT} |
.clients.openTelemetryCollector.grpc.enabled = ${OPEN_TELEMETRY_EXPORTER_ENABLED} |
.clients.openTelemetryCollector.grpc.address = \"${OPEN_TELEMETRY_EXPORTER_ADDRESS}\" |
.clients.openTelemetryCollector.grpc.tls.caPool = \"${OPEN_TELEMETRY_EXPORTER_CA_POOL}\" |
.clients.openTelemetryCollector.grpc.tls.keyFile = \"${OPEN_TELEMETRY_EXPORTER_KEY_FILE}\" |
.clients.openTelemetryCollector.grpc.tls.certFile = \"${OPEN_TELEMETRY_EXPORTER_CERT_FILE}\" |
.clients.openTelemetryCollector.grpc.tls.useSystemCAPool = true
" - > /data/snippet-service.yaml
fi
snippet-service --config /data/snippet-service.yaml >$LOGS_PATH/snippet-service.log 2>&1 &
status=$?
snippet_service_pid=$!
if [ $status -ne 0 ]; then
echo "Failed to start snippet-service: $status"
sync
cat $LOGS_PATH/snippet-service.log
exit $status
fi

# waiting for ca. Without wait, sometimes the service didn't connect.
i=0
while true; do
i=$((i+1))
if openssl s_client -connect ${SNIPPET_SERVICE_ADDRESS} -cert ${INTERNAL_CERT_DIR_PATH}/${GRPC_INTERNAL_CERT_NAME} -key ${INTERNAL_CERT_DIR_PATH}/${GRPC_INTERNAL_CERT_KEY_NAME} <<< "Q" 2>/dev/null > /dev/null; then
break
fi
echo "Try to reconnect to snippet-service(${SNIPPET_SERVICE_ADDRESS}) $i"
sleep 1
done

echo "Open browser at https://${DOMAIN}"

Expand Down Expand Up @@ -1367,4 +1416,11 @@ while sleep 10; do
exit 1
fi
fi
ps aux |grep $snippet_service_pid |grep -q -v grep
if [ $? -ne 0 ]; then
echo "snippet-service has already exited."
sync
cat $LOGS_PATH/snippet-service.log
exit 1
fi
done
14 changes: 14 additions & 0 deletions charts/plgd-hub/templates/http-gateway/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@
{{- end }}
{{- end }}

{{- define "plgd-hub.httpgateway.snippetServiceApiDomain" -}}
{{- $domain := "" }}
{{- if .Values.snippetservice }}
{{- if .Values.snippetservice.enabled }}
{{- if .Values.snippetservice.domain }}
{{- $domain = printf "https://%s" .Values.snippetservice.domain }}
{{- else }}
{{- $domain = printf "https://api.%s" .Values.global.domain }}
{{- end }}
{{- end }}
{{- end }}
{{- printf $domain }}
{{- end }}

{{- define "plgd-hub.httpgateway.uiDomain" -}}
{{- if .Values.httpgateway.uiDomain }}
{{- printf "%s" .Values.httpgateway.uiDomain }}
Expand Down
1 change: 1 addition & 0 deletions charts/plgd-hub/templates/http-gateway/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ data:
webConfiguration:
httpGatewayAddress: {{ .ui.webConfiguration.httpGatewayAddress | default ( printf "https://%s" ( include "plgd-hub.httpgateway.apiDomain" $)) | quote }}
deviceProvisioningService: {{ .ui.webConfiguration.deviceProvisioningService | default ( include "plgd-hub.httpgateway.dpsApiDomain" $) | quote }}
snippetService: {{ .ui.webConfiguration.snippetService | default ( include "plgd-hub.httpgateway.snippetServiceApiDomain" $) | quote }}
{{- if not $.Values.mockoauthserver.enabled }}
webOAuthClient:
authority: {{ required ".ui.webConfiguration.webOAuthClient.authority or global.authority is required" ( .ui.webConfiguration.webOAuthClient.authority | default $.Values.global.authority ) | quote }}
Expand Down
53 changes: 53 additions & 0 deletions charts/plgd-hub/templates/snippet-service/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{- define "plgd-hub.snippetservice.fullname" -}}
{{- if .Values.snippetservice.fullnameOverride }}
{{- .Values.snippetservice.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Values.snippetservice.name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s-%s" .Release.Name $name .Values.snippetservice.name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{- define "plgd-hub.snippetservice.configName" -}}
{{- $fullName := include "plgd-hub.snippetservice.fullname" . -}}
{{- printf "%s-cfg" $fullName }}
{{- end -}}

{{- define "plgd-hub.snippetservice.createServiceCertByCm" }}
{{- $serviceTls := .Values.snippetservice.apis.grpc.tls.certFile }}
{{- if $serviceTls }}
{{- printf "" -}}
{{- else }}
{{- printf "true" -}}
{{- end }}
{{- end }}

{{- define "plgd-hub.snippetservice.domain" -}}
{{- if .Values.snippetservice.domain }}
{{- printf "%s" .Values.snippetservice.domain }}
{{- else }}
{{- printf "api.%s" .Values.global.domain }}
{{- end }}
{{- end }}

{{- define "plgd-hub.snippetservice.serviceCertName" -}}
{{- $fullName := include "plgd-hub.snippetservice.fullname" . -}}
{{- printf "%s-crt" $fullName -}}
{{- end }}

{{- define "plgd-hub.snippetservice.domainCertName" -}}
{{- if .Values.snippetservice.ingress.secretName }}
{{- printf "%s" .Values.snippetservice.ingress.secretName -}}
{{- else }}
{{- $fullName := include "plgd-hub.snippetservice.fullname" . -}}
{{- printf "%s-domain-crt" $fullName -}}
{{- end }}
{{- end }}

{{- define "plgd-hub.snippetservice.selectorLabels" -}}
app.kubernetes.io/name: {{ .Values.snippetservice.name }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
Loading
Loading