summaryrefslogtreecommitdiff
path: root/dryad/conf/conf.go
blob: 3c32c1df45e7a951cf3a05f8d91b98cf5e20daea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 *  Copyright (c) 2017-2018 Samsung Electronics Co., Ltd All Rights Reserved
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License
 */

// Package conf manages Dryad's configuration.
package conf

import (
	"fmt"
	"io"
	"io/ioutil"

	"github.com/BurntSushi/toml"

	"git.tizen.org/tools/boruta"
)

// DefaultRPCPort is a port that should be used as default parameter
// for Dryad's RPC client and server.
const DefaultRPCPort = 7175

// DefaultSSHPort is a default port off SSH daemon.
const DefaultSSHPort = 22

// NewConf returns a new instance of General configuration with default values set.
func NewConf() *General {
	return &General{
		Address:   fmt.Sprintf(":%d", DefaultRPCPort),
		SSHAdress: fmt.Sprintf(":%d", DefaultSSHPort),
		Caps:      boruta.Capabilities(map[string]string{}),
		User: &User{
			Name:   "boruta-user",
			Groups: []string{},
		},
		SDcard:    "/dev/sdX",
		STMsocket: "/run/stm.socket",
	}
}

// User is a section in a configuration used for user manipulation.
type User struct {
	// Name is a username of a local account. It should be used to establish SSH session
	// to the system Dryad is running on.
	Name string `toml:"name"`
	// Groups is a list of local Unix groups the username belongs to.
	Groups []string `toml:"groups"`
}

// General is a base struct of configuration.
type General struct {
	// Address is used to listen for connection from Boruta.
	Address string `toml:"listen_address"`
	// BorutaAddress is used to connect to Boruta server.
	BorutaAddress string `toml:"boruta_address"`
	// SSHAdress is a ssh daemon listen address.
	SSHAdress string `toml:"ssh_address"`
	// Caps are necessary information to register in Boruta.
	//
	// TODO(amistewicz): This field should be removed when
	// it will be possible to read it from hardware.
	Caps boruta.Capabilities `toml:"caps"`
	// User refers information necessary to create the user.
	User *User `toml:"user"`
	// SDcard is a base path to block device of sdcard.
	SDcard string `toml:"sdcard"`
	// STMsocket is a path to the socket on which Go RPC service of stm.Interface is available.
	STMsocket string `toml:"stm_path"`
}

// Marshal writes TOML representation of g to w.
func (g *General) Marshal(w io.Writer) error {
	return toml.NewEncoder(w).Encode(g)
}

// Unmarshal reads TOML representation from r and parses it into g.
func (g *General) Unmarshal(r io.Reader) error {
	b, err := ioutil.ReadAll(r)
	if err != nil {
		return err
	}
	return toml.Unmarshal(b, g)
}