Add functionality to upload images to S3
This change adds the following functionality:
- Add the motion detection image to a S3 bucket.
- Pass a presigned URL linking to the image in the JSON payload of the
MQTT event message.
- Add the possibility of customizing whether images are uploaded to a S3
bucket or not.
Change-Id: Id82401839e92dbc62f3bbd1e7e7f0adeeb5718a6
diff --git a/cmd/hichipbridge/Dockerfile b/cmd/hichipbridge/Dockerfile
index f303928..403ae14 100644
--- a/cmd/hichipbridge/Dockerfile
+++ b/cmd/hichipbridge/Dockerfile
@@ -17,6 +17,7 @@
RUN go install github.com/eclipse/paho.mqtt.golang
RUN go install github.com/flashmob/go-guerrilla
RUN go install github.com/go-sql-driver/mysql
+RUN go install github.com/minio/minio-go/v7
RUN go install github.com/sirupsen/logrus
RUN go install github.com/spf13/cobra
RUN go install gomodules.avm99963.com/forks/parsemail
diff --git a/cmd/hichipbridge/env.sample b/cmd/hichipbridge/env.sample
index ae7017f..6b79851 100644
--- a/cmd/hichipbridge/env.sample
+++ b/cmd/hichipbridge/env.sample
@@ -12,3 +12,15 @@
HICHIPBRIDGE_MQTT_TOPIC=hichipbridge
# Token for the email notifications
HICHIPBRIDGE_EMAIL_TOKEN=superconfidentialtoken;)
+# Whether images should be saved in a S3 storage bucket (true/false)
+HICHIPBRIDGE_S3_ENABLED=false
+# The S3 storage endpoint
+HICHIPBRIDGE_S3_ENDPOINT=s3.example.com
+# The S3 access key ID
+HICHIPBRIDGE_S3_ACCESS_KEY=username
+# The S3 secret access key
+HICHIPBRIDGE_S3_SECRET_KEY=password
+# Whether S3 uses SSL (true/false)
+HICHIPBRIDGE_S3_USE_SSL=true
+# The S3 bucket name
+HICHIPBRIDGE_S3_BUCKET=hichipbridge
diff --git a/cmd/hichipbridge/serve.go b/cmd/hichipbridge/serve.go
index 17b944e..05c3048 100644
--- a/cmd/hichipbridge/serve.go
+++ b/cmd/hichipbridge/serve.go
@@ -146,6 +146,12 @@
"MQTT_PASSWORD",
"MQTT_TOPIC",
"EMAIL_TOKEN",
+ "S3_ENABLED",
+ "S3_ENDPOINT",
+ "S3_ACCESS_KEY",
+ "S3_SECRET_KEY",
+ "S3_USE_SSL",
+ "S3_BUCKET",
}
// Load in the config.
@@ -185,6 +191,12 @@
"mqtt_password": envs["MQTT_PASSWORD"],
"mqtt_topic": envs["MQTT_TOPIC"],
"mqtt_email_token": envs["EMAIL_TOKEN"],
+ "s3_enabled": envs["S3_ENABLED"],
+ "s3_endpoint": envs["S3_ENDPOINT"],
+ "s3_access_key": envs["S3_ACCESS_KEY"],
+ "s3_secret_key": envs["S3_SECRET_KEY"],
+ "s3_use_ssl": envs["S3_USE_SSL"],
+ "s3_bucket": envs["S3_BUCKET"],
}
for i, _ := range appConfig.Servers {