cbe4f0f7bc | ||
---|---|---|
.. | ||
.github | ||
.vscode | ||
Services | ||
Services.Test | ||
WebService | ||
WebService.Test | ||
scripts | ||
.gitattributes | ||
.gitconfig | ||
.gitignore | ||
CONTRIBUTING.md | ||
DEVELOPMENT.md | ||
LICENSE | ||
README.md | ||
config.sln | ||
config.sln.DotSettings |
README.md
Config Service Overview
This service handles communication with the Storage Adapter microservice to complete tasks.
The microservice provides a RESTful endpoint to make CRUD operations for "devicegroups", "solution-settings", and "user-settings". The data will be stored by the Storage Adapter microservice.
Why?
This microservice was built as part of the Azure IoT Remote Monitoring project to provide a generic implementation for an end-to-end IoT solution. More information here.
Features
- Create or update device groups
- Get all or a single device group
- Get or upload logo
- Get or set overall solution settings
- Get or set individual user settings
- Create or delete a package
- Get all or a single uploaded package.
Documentation
- View the API documentation in the Wiki
How to Use
Running the Service with Docker
You can run the microservice and its dependencies using Docker with the instructions here.
Running the Service Locally
Prerequisites
1. Deploy Azure Services
This service has a dependency on the following Azure resources. Follow the instructions for Deploy the Azure services.
- Cosmos DB
- Iot Hub
- Maps (optional)
2. Setup Dependencies
This service depends on the following repositories. Run those services from the instructions in their READMEs in the following order.
- Storage Adapter Dotnet Microservice
- Telemetry Dotnet Microservice
- Device Simulation Dotnet Microservice
- Authentication Microservice
3. Environment variables required to run the service
In order to run the service, some environment variables need to be created at least once. See specific instructions for IDE or command line setup below for more information. More information on environment variables here.
PCS_AAD_APPID
= { Azure service principal id }PCS_AAD_APPSECRET
= { Azure service principal secret }PCS_KEYVAULT_NAME
= { Name of Key Vault resource that stores settings and configuration }
Configuration values used from Key Vault
Some of the configuration needed by the microservice is stored in an instance of Key Vault that was created on initial deployment. The config microservice uses:
aadTenantId
= GUID representing your active directory tenantarmEndpointUrl
= The endpoint for the Azure Resource Manager APIauthIssuer
= Identifies the security token service (STS) i.e. https://sts.windows.net/tenantId/authRequired
= Whether or not authentication is needed for calls to microservices i.e. from the web ui or postmanauthWebServiceUrl
= Endpoint for the remote monitoring auth microserviceazureMapsKey
= Key needed for Azure Maps AccountcorsWhitelist
= Specifies where requests are allowed from "{ 'origins': ['*'], 'methods': ['*'], 'headers': ['*'] }" to allow everything. Empty to disable CORSdeviceSimulationWebServiceUrl
= Endpoint for device simulation microserviceoffice365ConnectionUrl
= Office 365 url used for enabling e-mail actions when alerting on rulesseedTemplate
= The template used by device simulation when seeding devices. This is typically DEFAULTsolutionName
= The name of the RM solution that was created. This is typically the same as your Resource Group namesolutionType
= Type of solution. remotemonitoring or device-simulationstorageAdapterWebServiceUrl
= Endpoint for storage adapter microservicesubscriptionId
= GUID that uniquely identifies your subscription to use Azure servicestelemetryWebServiceUrl
= Endpoint for telemetry microservice
Running the service with Visual Studio or VS Code
- Make sure the Prerequisites are set up.
- Install .NET Core 2.x
- Install any recent edition of Visual Studio (Windows/MacOS) or Visual
Studio Code (Windows/MacOS/Linux).
- If you already have Visual Studio installed, then ensure you have .NET Core Tools for Visual Studio 2017 installed (Windows only).
- If you already have VS Code installed, then ensure you have the C# for Visual Studio Code (powered by OmniSharp) extension installed.
- Open the solution in Visual Studio or VS Code.
- Define the following environment variables. See Configuration and Environment variables for detailed information for setting these for your enviroment.
PCS_AAD_APPID
= { Azure service principal id }PCS_AAD_APPSECRET
= { Azure service principal secret }PCS_KEYVAULT_NAME
= { Name of Key Vault resource that stores settings and configuration }
- Start the WebService project (e.g. press F5).
- Use an HTTP client such as Postman, to exercise the RESTful API.
Running the service from the command line
- Make sure the Prerequisites are set up.
- Set the following environment variables in your system.
More information on environment variables
here.
PCS_AAD_APPID
= { Azure service principal id }PCS_AAD_APPSECRET
= { Azure service principal secret }PCS_KEYVAULT_NAME
= { Name of Key Vault resource that stores settings and configuration values }
- Use the scripts in the scripts folder for many frequent tasks:
build
: compile all the projects and run the tests.compile
: compile all the projects.run
: compile the projects and run the service. This will prompt for elevated privileges in Windows to run the web service.
Project Structure
This microservice contains the following projects:
- WebService.csproj - C# web service exposing REST interface for config functionality
- WebService.Test.csproj - Unit tests for web services functionality
- Services.csproj - C# assembly containining business logic for interacting with storage microserivce, telemetry microservice and device simulation microservice
- Services.Test.csproj - Unit tests for services functionality
- Solution/scripts - Contains build scripts, docker container creation scripts, and scripts for running the microservice from the command line
Updating the Docker image
The scripts
folder includes a docker subfolder with the files
required to package the service into a Docker image:
Dockerfile
: docker images specificationsbuild
: build a Docker container and store the image in the local registryrun
: run the Docker container from the image stored in the local registrycontent
: a folder with files copied into the image, including the entry point script
Configuration and Environment variables
The service configuration is stored using ASP.NET Core configuration adapters, in appsettings.ini. The INI format allows to store values in a readable format, with comments.
Configuration in appsettings.ini are typically set in 3 different ways:
- Environment variables as is the case with ${PCS_AAD_APPID}. This is typically only done with the 3 variables described above as these are needed to access Key Vault. More details about setting environment variables are located below.
- Key Vault: A number of the settings in this file will be blank as they are expecting to get their value from a Key Vault secret of the same name.
- Direct Value: For some values that aren't typically changed or for local development you can set the value directly in the file.
Depending on the OS and the IDE used, there are several ways to manage environment variables.
- If you're using Visual Studio or Visual Studio for Mac, the environment variables are loaded from the project settings. Right click on WebService, and select Options/Properties, and find the section with the list of env vars. See WebService/Properties/launchSettings.json.
- Visual Studio Code loads the environment variables from .vscode/launch.json
- When running the service with Docker or from the command line, the
application will inherit environment variables values from the system.
- Depending on OS and terminal, there are different ways to persist values globally, for more information these pages should help:
- IntelliJ Rider: env. vars can be set in each Run Configuration, similarly to IntelliJ IDEA (https://www.jetbrains.com/help/idea/run-debug-configuration-application.html)
Contributing to the solution
Please follow our contribution guildelines and code style conventions.
Feedback
Please enter issues, bugs, or suggestions as GitHub Issues.
License
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.