2
Copyright 2013-2014 Canonical Ltd.
4
This program is free software: you can redistribute it and/or modify it
5
under the terms of the GNU General Public License version 3, as published
6
by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranties of
10
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program. If not, see <http://www.gnu.org/licenses/>.
17
// Package identifier is the source of an anonymous and stable
18
// system id (from /var/lib/dbus/machine-id) used by the Ubuntu
19
// push notifications service.
27
var machineIdPath = "/var/lib/dbus/machine-id"
29
// an Id knows how to generate itself, and how to stringify itself.
34
// Identifier is the default Id implementation.
35
type Identifier struct {
39
func readMachineId() (string, error) {
40
value, err := ioutil.ReadFile(machineIdPath)
44
return string(value)[:len(value)-1], nil
47
// New creates an Identifier
48
func New() (Id, error) {
49
value, err := readMachineId()
51
return &Identifier{value: ""}, fmt.Errorf("Failed to read the machine id: %s", err)
53
return &Identifier{value: value}, nil
56
// String returns the system identifier as a string.
57
func (id *Identifier) String() string {