2020-04-29 06:39:23 +08:00
|
|
|
// Copyright (c) Mainflux
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package provision
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
|
2020-06-03 21:16:19 +08:00
|
|
|
"github.com/mainflux/mainflux/pkg/errors"
|
2020-04-29 06:39:23 +08:00
|
|
|
"github.com/pelletier/go-toml"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Service represents service config.
|
|
|
|
type ServiceConf struct {
|
|
|
|
Port string `toml:"port"`
|
|
|
|
LogLevel string `toml:"log_level"`
|
|
|
|
TLS bool `toml:"tls"`
|
|
|
|
ServerCert string `toml:"server_cert"`
|
|
|
|
ServerKey string `toml:"server_key"`
|
|
|
|
ThingsLocation string `toml:"things_location"`
|
|
|
|
UsersLocation string `toml:"users_location"`
|
|
|
|
MQTTURL string `toml:"mqtt_url"`
|
|
|
|
HTTPPort string `toml:"http_port"`
|
|
|
|
MfUser string `toml:"mf_user"`
|
|
|
|
MfPass string `toml:"mf_pass"`
|
|
|
|
MfAPIKey string `toml:"mf_api_key"`
|
|
|
|
MfBSURL string `toml:"mf_bs_url"`
|
|
|
|
MfWhiteListURL string `toml:"mf_whit_list"`
|
|
|
|
MfCertsURL string `toml:"mf_certs_url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Bootstrap struct {
|
|
|
|
X509Provision bool `toml:"x509_provision"`
|
|
|
|
Provision bool `toml:"provision"`
|
|
|
|
AutoWhiteList bool `toml:"autowhite_list"`
|
|
|
|
Content string `toml:"content"`
|
|
|
|
}
|
|
|
|
type Channel struct {
|
|
|
|
Name string `toml:"name"`
|
|
|
|
Metadata map[string]interface{} `toml:"metadata" mapstructure:"metadata"`
|
|
|
|
}
|
|
|
|
type Thing struct {
|
|
|
|
Name string `toml:"name"`
|
|
|
|
Metadata map[string]interface{} `toml:"metadata" mapstructure:"metadata"`
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:53:32 +08:00
|
|
|
type Gateway struct {
|
|
|
|
Type string `toml:"type" json:"type"`
|
|
|
|
ExternalID string `toml:"external_id" json:"external_id"`
|
|
|
|
ExternalKey string `toml:"external_key" json:"external_key"`
|
|
|
|
CtrlChannelID string `toml:"ctrl_channel_id" json:"ctrl_channel_id"`
|
|
|
|
DataChannelID string `toml:"data_channel_id" json:"data_channel_id"`
|
|
|
|
ExportChannelID string `toml:"export_channel_id" json:"export_channel_id"`
|
|
|
|
CfgID string `toml:"cfg_id" json:"cfg_id"`
|
|
|
|
}
|
|
|
|
|
MF-1179 - Add a certificate service and certs endpoint to SDK (#1188)
* adding certificate issuing
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* adding cert endpoint
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update envs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update envs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* move certs creation to sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* move certs creation to sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* move certs creation to sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix env vars
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add comment
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix vars
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add volumes
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix merge config for int
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove env
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix error handling
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cert test, change receiver to pointer
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add docs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix var naming
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* correct error naming
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* adding certs service
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* change func receiever
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add default cert issue method
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add config
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* small fix
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove some testing code
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cert issue
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add vault api client
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* additional endpoints
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add swagger for certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove certs from provision
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* clean provision from certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add list certificates endpoint
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add vault api in vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add revoke, fix bugs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix sdk for certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor changes, add env, doc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor changes, add env, doc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor changes, add env, doc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* small changes
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove CA for signing from provision
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add docker file for certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix mock sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add line
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix RevokeCert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* renam ENV
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove tests temporarily
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix naming
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* renam vars
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove not needed envs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix linter errors, add cli
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix linter errors, add cli, var rename
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix reviews, add viewcert, fix view all certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove view cert, as it will be retrieved from PKI
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* change endpoints
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add default env val
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove some errors
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix revoking
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comment
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add comments
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove unused
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove unused field
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki, update vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comment
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor fix
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove methods, use fields
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comments and package desc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comments and package desc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2020-07-21 18:53:21 +08:00
|
|
|
type Certs struct {
|
|
|
|
HoursValid string `json:"days_valid" toml:"days_valid"`
|
|
|
|
KeyBits int `json:"key_bits" toml:"key_bits"`
|
|
|
|
KeyType string `json:"key_type"`
|
|
|
|
}
|
|
|
|
|
2020-04-29 06:39:23 +08:00
|
|
|
// Config struct of Provision
|
|
|
|
type Config struct {
|
|
|
|
File string `toml:"file"`
|
|
|
|
Server ServiceConf `toml:"server" mapstructure:"server"`
|
2020-05-06 22:53:32 +08:00
|
|
|
Bootstrap Bootstrap `toml:"bootstrap" mapstructure:"bootstrap"`
|
2020-04-29 06:39:23 +08:00
|
|
|
Things []Thing `toml:"things" mapstructure:"things"`
|
|
|
|
Channels []Channel `toml:"channels" mapstructure:"channels"`
|
MF-1179 - Add a certificate service and certs endpoint to SDK (#1188)
* adding certificate issuing
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* adding cert endpoint
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update envs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update envs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* move certs creation to sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* move certs creation to sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* move certs creation to sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix env vars
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add comment
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix vars
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add volumes
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix merge config for int
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove env
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix error handling
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cert test, change receiver to pointer
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add docs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix var naming
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* correct error naming
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* adding certs service
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* change func receiever
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add default cert issue method
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add config
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* small fix
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove some testing code
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cert issue
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add vault api client
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* additional endpoints
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add swagger for certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove certs from provision
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* clean provision from certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add list certificates endpoint
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add vault api in vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add revoke, fix bugs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix sdk for certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor changes, add env, doc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor changes, add env, doc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor changes, add env, doc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* small changes
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove CA for signing from provision
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add docker file for certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix mock sdk
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add line
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix RevokeCert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* renam ENV
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove tests temporarily
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix naming
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* renam vars
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add cli for issue cert
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove not needed envs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix linter errors, add cli
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix linter errors, add cli, var rename
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix reviews, add viewcert, fix view all certs
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove view cert, as it will be retrieved from PKI
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* change endpoints
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add default env val
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove some errors
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix revoking
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor, make wrapper lib for vault
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comment
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* add comments
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove unused
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove unused field
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* update vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki, update vendor
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* refactor pki
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comment
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* minor fix
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* remove methods, use fields
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comments and package desc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
* fix comments and package desc
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
2020-07-21 18:53:21 +08:00
|
|
|
Certs Certs `toml:"certs" mapstructure:"certs"`
|
2020-04-29 06:39:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save - store config in a file
|
|
|
|
func Save(c Config, file string) error {
|
|
|
|
b, err := toml.Marshal(c)
|
|
|
|
if err != nil {
|
|
|
|
return errors.New(fmt.Sprintf("Error reading config file: %s", err))
|
|
|
|
}
|
|
|
|
if err := ioutil.WriteFile(file, b, 0644); err != nil {
|
|
|
|
return errors.New(fmt.Sprintf("Error writing toml: %s", err))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read - retrieve config from a file
|
|
|
|
func Read(file string) (Config, error) {
|
|
|
|
data, err := ioutil.ReadFile(file)
|
|
|
|
c := Config{}
|
|
|
|
if err != nil {
|
|
|
|
return c, errors.New(fmt.Sprintf("Error reading config file: %s", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := toml.Unmarshal(data, &c); err != nil {
|
|
|
|
return Config{}, errors.New(fmt.Sprintf("Error unmarshaling toml: %s", err))
|
|
|
|
}
|
|
|
|
return c, nil
|
|
|
|
}
|