Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* [Install thin-edge.io on your device](docs/src/howto-guides/002_installation.md)
* [Connect your device to Cumulocity](docs/src/tutorials/connect-c8y.md)
* [Connect your device to Azure](docs/src/tutorials/connect-azure.md)
* [Connect your device to AWS](docs/src/tutorials/connect-aws.md)
* [Find some projects that work together with thin-edge.io](https://github.com/thin-edge/thin-edge.io_examples)
* [**Explore the Docs**](https://thin-edge.github.io/thin-edge.io/html/)
<br/>
Expand Down
4 changes: 4 additions & 0 deletions configuration/contrib/tedge_upgrade/upgrade_tedge_0.6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if [ -f "/run/lock/tedge-mapper-az.lock" ]; then
sudo chown tedge:tedge /run/lock/tedge-mapper-az.lock
fi

if [ -f "/run/lock/tedge-mapper-aws.lock" ]; then
sudo chown tedge:tedge /run/lock/tedge-mapper-aws.lock
fi

if [ -f "/run/lock/tedge-mapper-collectd.lock" ]; then
sudo chown tedge:tedge /run/lock/tedge-mapper-collectd.lock
fi
6 changes: 6 additions & 0 deletions configuration/debian/tedge-mapper/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fi
### Initialize the mapper
sudo -u tedge -- tedge-mapper --init c8y
sudo -u tedge -- tedge-mapper --init az
sudo -u tedge -- tedge-mapper --init aws

#DEBHELPER#

Expand All @@ -25,6 +26,11 @@ if command -v systemctl >/dev/null; then
systemctl start tedge-mapper-az.service
systemctl enable tedge-mapper-az.service
fi
### Enable the service if the device is connected to aws cloud
if [ -f "/etc/tedge/mosquitto-conf/aws-bridge.conf" ]; then
systemctl start tedge-mapper-aws.service
systemctl enable tedge-mapper-aws.service
fi
### Enable the service if the collectd is running on the device
if systemctl is-active --quiet collectd.service; then
systemctl start tedge-mapper-collectd.service
Expand Down
4 changes: 4 additions & 0 deletions configuration/debian/tedge-mapper/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ purge_mapper_lock() {
rm -rf /run/lock/tedge-mapper-az.lock
fi

if [ -f "/run/lock/tedge-mapper-aws.lock" ]; then
rm -rf /run/lock/tedge-mapper-aws.lock
fi

if [ -f "/run/lock/tedge-mapper-collectd.lock" ]; then
rm -rf /run/lock/tedge-mapper-collectd.lock
fi
Expand Down
4 changes: 4 additions & 0 deletions configuration/debian/tedge-mapper/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ if command -v systemctl >/dev/null; then
if systemctl is-active --quiet tedge-mapper-az; then
systemctl stop tedge-mapper-az.service
fi

if systemctl is-active --quiet tedge-mapper-aws; then
systemctl stop tedge-mapper-aws.service
fi
fi

# Deprecate: Remove symlink in 1.x release
Expand Down
8 changes: 8 additions & 0 deletions configuration/debian/tedge/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if [ -d "/etc/tedge/operations/az" ]; then
sudo chown tedge:tedge /etc/tedge/operations/az
fi

if [ -d "/etc/tedge/operations/aws" ]; then
sudo chown tedge:tedge /etc/tedge/operations/aws
fi

if [ -d "/etc/tedge/.agent/" ]; then
sudo chown tedge:tedge /etc/tedge/.agent
fi
Expand All @@ -56,6 +60,10 @@ if [ -f "/run/lock/tedge-mapper-az.lock" ]; then
sudo chown tedge:tedge /run/lock/tedge-mapper-az.lock
fi

if [ -f "/run/lock/tedge-mapper-aws.lock" ]; then
sudo chown tedge:tedge /run/lock/tedge-mapper-aws.lock
fi

if [ -f "/run/lock/tedge-mapper-collectd.lock" ]; then
sudo chown tedge:tedge /run/lock/tedge-mapper-collectd.lock
fi
12 changes: 12 additions & 0 deletions configuration/init/systemd/tedge-mapper-aws.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Hub.
After=syslog.target network.target mosquitto.service

[Service]
User=tedge
ExecStart=/usr/bin/tedge_mapper aws
Restart=on-failure
RestartPreventExitStatus=255

[Install]
WantedBy=multi-user.target
4 changes: 4 additions & 0 deletions crates/common/tedge_config/src/system_services/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub enum SystemService {
Mosquitto,
/// Azure TEdge mapper
TEdgeMapperAz,
/// AWS TEdge mapper
TEdgeMapperAws,
/// Cumulocity TEdge mapper
TEdgeMapperC8y,
/// TEdge SM agent
Expand All @@ -16,6 +18,7 @@ impl std::fmt::Display for SystemService {
let s = match self {
Self::Mosquitto => "mosquitto",
Self::TEdgeMapperAz => "tedge-mapper-az",
Self::TEdgeMapperAws => "tedge-mapper-aws",
Self::TEdgeMapperC8y => "tedge-mapper-c8y",
Self::TEdgeSMAgent => "tedge-agent",
};
Expand All @@ -28,6 +31,7 @@ impl SystemService {
match service {
SystemService::Mosquitto => "mosquitto",
SystemService::TEdgeMapperAz => "tedge-mapper-az",
SystemService::TEdgeMapperAws => "tedge-mapper-aws",
SystemService::TEdgeMapperC8y => "tedge-mapper-c8y",
SystemService::TEdgeSMAgent => "tedge-agent",
}
Expand Down
54 changes: 54 additions & 0 deletions crates/common/tedge_config/src/tedge_config_cli/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,60 @@ impl ConfigSetting for AzureMapperTimestamp {
type Value = Flag;
}

///
/// Boolean whether AWS mapper should add timestamp if timestamp is not added in the incoming payload.
///
/// Example: true
///
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct AwsMapperTimestamp;

impl ConfigSetting for AwsMapperTimestamp {
const KEY: &'static str = "aws.mapper.timestamp";

const DESCRIPTION: &'static str = concat!(
"Boolean whether AWS mapper should add timestamp or not. ",
"Example: true"
);

type Value = Flag;
}

///
/// Endpoint URL of AWS instance.
///
/// Example: your-endpoint.amazonaws.com
///
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct AwsUrlSetting;

impl ConfigSetting for AwsUrlSetting {
const KEY: &'static str = "aws.url";

const DESCRIPTION: &'static str =
"Endpoint URL of AWS instance. Example: your-endpoint.amazonaws.com";
type Value = ConnectUrl;
}

///
/// Path where AWS IoT root certificate(s) are located.
///
/// Example: /home/user/.tedge/aws-trusted-root-certificates.pem
///
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct AwsRootCertPathSetting;

impl ConfigSetting for AwsRootCertPathSetting {
const KEY: &'static str = "aws.root.cert.path";

const DESCRIPTION: &'static str = concat!(
"Path where AWS IoT root certificate(s) are located. ",
"Example: /home/user/.tedge/aws-trusted-root-certificates.pem"
);

type Value = FilePath;
}

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub struct MqttPortSetting;

Expand Down
68 changes: 68 additions & 0 deletions crates/common/tedge_config/src/tedge_config_cli/tedge_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ impl ConfigSettingAccessor<AzureUrlSetting> for TEdgeConfig {
}
}

impl ConfigSettingAccessor<AwsUrlSetting> for TEdgeConfig {
fn query(&self, _setting: AwsUrlSetting) -> ConfigSettingResult<ConnectUrl> {
self.data
.aws
.url
.clone()
.ok_or(ConfigSettingError::ConfigNotSet {
key: AwsUrlSetting::KEY,
})
}

fn update(&mut self, _setting: AwsUrlSetting, value: ConnectUrl) -> ConfigSettingResult<()> {
self.data.aws.url = Some(value);
Ok(())
}

fn unset(&mut self, _setting: AwsUrlSetting) -> ConfigSettingResult<()> {
self.data.aws.url = None;
Ok(())
}
}

impl ConfigSettingAccessor<C8yUrlSetting> for TEdgeConfig {
fn query(&self, _setting: C8yUrlSetting) -> ConfigSettingResult<ConnectUrl> {
self.data
Expand Down Expand Up @@ -249,6 +271,31 @@ impl ConfigSettingAccessor<AzureRootCertPathSetting> for TEdgeConfig {
}
}

impl ConfigSettingAccessor<AwsRootCertPathSetting> for TEdgeConfig {
fn query(&self, _setting: AwsRootCertPathSetting) -> ConfigSettingResult<FilePath> {
Ok(self
.data
.aws
.root_cert_path
.clone()
.unwrap_or_else(|| self.config_defaults.default_aws_root_cert_path.clone()))
}

fn update(
&mut self,
_setting: AwsRootCertPathSetting,
value: FilePath,
) -> ConfigSettingResult<()> {
self.data.aws.root_cert_path = Some(value);
Ok(())
}

fn unset(&mut self, _setting: AwsRootCertPathSetting) -> ConfigSettingResult<()> {
self.data.aws.root_cert_path = None;
Ok(())
}
}

impl ConfigSettingAccessor<AzureMapperTimestamp> for TEdgeConfig {
fn query(&self, _setting: AzureMapperTimestamp) -> ConfigSettingResult<Flag> {
Ok(self
Expand All @@ -270,6 +317,27 @@ impl ConfigSettingAccessor<AzureMapperTimestamp> for TEdgeConfig {
}
}

impl ConfigSettingAccessor<AwsMapperTimestamp> for TEdgeConfig {
fn query(&self, _setting: AwsMapperTimestamp) -> ConfigSettingResult<Flag> {
Ok(self
.data
.aws
.mapper_timestamp
.map(Flag)
.unwrap_or_else(|| self.config_defaults.default_mapper_timestamp.clone()))
}

fn update(&mut self, _setting: AwsMapperTimestamp, value: Flag) -> ConfigSettingResult<()> {
self.data.aws.mapper_timestamp = Some(value.into());
Ok(())
}

fn unset(&mut self, _setting: AwsMapperTimestamp) -> ConfigSettingResult<()> {
self.data.aws.mapper_timestamp = None;
Ok(())
}
}

impl ConfigSettingAccessor<C8yRootCertPathSetting> for TEdgeConfig {
fn query(&self, _setting: C8yRootCertPathSetting) -> ConfigSettingResult<FilePath> {
Ok(self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub struct TEdgeConfigDefaults {
/// Default path for azure root certificates
pub default_azure_root_cert_path: FilePath,

/// Default path for AWS root certificates
pub default_aws_root_cert_path: FilePath,

/// Default path for c8y root certificates
pub default_c8y_root_cert_path: FilePath,

Expand Down Expand Up @@ -91,6 +94,7 @@ impl From<&TEdgeConfigLocation> for TEdgeConfigDefaults {
.join("tedge-private-key.pem")
.into(),
default_azure_root_cert_path: system_cert_path.clone().into(),
default_aws_root_cert_path: system_cert_path.clone().into(),
default_c8y_root_cert_path: system_cert_path.into(),
default_mapper_timestamp: Flag(true),
default_mqtt_port: Port(DEFAULT_MQTT_PORT),
Expand Down Expand Up @@ -121,6 +125,7 @@ fn test_from_tedge_config_location() {
"/opt/etc/_tedge/device-certs/tedge-private-key.pem"
),
default_azure_root_cert_path: FilePath::from("/etc/ssl/certs"),
default_aws_root_cert_path: FilePath::from("/etc/ssl/certs"),
default_c8y_root_cert_path: FilePath::from("/etc/ssl/certs"),
default_mapper_timestamp: Flag(true),
default_mqtt_port: Port(DEFAULT_MQTT_PORT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub(crate) struct TEdgeConfigDto {
#[serde(default, alias = "azure")] // for version 0.1.0 compatibility
pub(crate) az: AzureConfigDto,

#[serde(default, alias = "aws")] // for version 0.1.0 compatibility
pub(crate) aws: AwsConfigDto,

#[serde(default)]
pub(crate) mqtt: MqttConfigDto,

Expand Down Expand Up @@ -93,6 +96,17 @@ pub(crate) struct AzureConfigDto {

#[tedge_derive::serde_other]
#[derive(Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct AwsConfigDto {
pub(crate) connect: Option<String>,
pub(crate) url: Option<ConnectUrl>,
pub(crate) root_cert_path: Option<FilePath>,
pub(crate) mapper_timestamp: Option<bool>,
}

#[tedge_derive::serde_other]
#[derive(Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub(crate) struct MqttConfigDto {
pub(crate) port: Option<u16>,
pub(crate) bind_address: Option<IpAddress>,
Expand Down
2 changes: 2 additions & 0 deletions crates/common/tedge_config/tests/test_tedge_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ bind_address = "0.0.0.0"
let config_defaults = TEdgeConfigDefaults {
default_c8y_root_cert_path: FilePath::from("default_c8y_root_cert_path"),
default_azure_root_cert_path: FilePath::from("default_azure_root_cert_path"),
default_aws_root_cert_path: FilePath::from("default_aws_root_cert_path"),
..dummy_tedge_config_defaults()
};

Expand Down Expand Up @@ -873,6 +874,7 @@ fn dummy_tedge_config_defaults() -> TEdgeConfigDefaults {
default_device_key_path: FilePath::from("/dev/null"),
default_c8y_root_cert_path: FilePath::from("/dev/null"),
default_azure_root_cert_path: FilePath::from("/dev/null"),
default_aws_root_cert_path: FilePath::from("/dev/null"),
default_mapper_timestamp: Flag(true),
default_mqtt_port: Port(1883),
default_http_port: Port(8000),
Expand Down
4 changes: 4 additions & 0 deletions crates/core/tedge/src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ use tedge_config::system_services::SystemService;
pub enum Cloud {
C8y,
Azure,
Aws,
}

impl Cloud {
pub fn mapper_service(&self) -> SystemService {
match self {
Cloud::Aws => SystemService::TEdgeMapperAws,
Cloud::Azure => SystemService::TEdgeMapperAz,
Cloud::C8y => SystemService::TEdgeMapperC8y,
}
}
pub fn as_str(&self) -> &'static str {
match self {
Self::Aws => "Aws",
Self::Azure => "Azure",
Self::C8y => "Cumulocity",
}
Expand All @@ -28,6 +31,7 @@ impl fmt::Display for Cloud {
match self {
Cloud::C8y => write!(f, "Cumulocity"),
Cloud::Azure => write!(f, "Azure"),
Cloud::Aws => write!(f, "Aws"),
}
}
}
3 changes: 3 additions & 0 deletions crates/core/tedge/src/cli/config/config_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ impl ConfigKey {
config_key!(C8ySmartRestTemplates),
config_key!(AzureUrlSetting),
config_key!(AzureRootCertPathSetting),
config_key!(AwsUrlSetting),
config_key!(AwsRootCertPathSetting),
config_key!(AwsMapperTimestamp),
config_key!(AzureMapperTimestamp),
config_key!(MqttBindAddressSetting),
config_key!(HttpBindAddressSetting),
Expand Down
Loading