Skip to content

Commit c569ee6

Browse files
author
Roberto Sora
committed
Cosmetics
1 parent 4f9faa5 commit c569ee6

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

repertory/repertory.go

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,71 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
116
package repertory
217

318
import (
19+
"path/filepath"
20+
421
"github.com/arduino/arduino-cli/cli/feedback"
522
"github.com/arduino/arduino-cli/configuration"
623
"github.com/gofrs/uuid"
724
"github.com/spf13/viper"
8-
"os"
925
)
1026

1127
// Store is the Read Only config storage
1228
var Store = viper.New()
1329

30+
var (
31+
Type = "yaml"
32+
Name = "repertory" + "." + Type
33+
)
34+
1435
// Configure configures the Read Only config storage
1536
func Init() {
1637
configPath := configuration.GetDefaultArduinoDataDir()
17-
Store.SetConfigType("yaml")
18-
Store.SetConfigName("repertory.yaml")
38+
Store.SetConfigName(Name)
39+
Store.SetConfigType(Type)
1940
Store.AddConfigPath(configPath)
41+
configFilePath := filepath.Join(configPath, Name)
2042
// Attempt to read config file
2143
if err := Store.ReadInConfig(); err != nil {
2244
// ConfigFileNotFoundError is acceptable, anything else
2345
// should be reported to the user
2446
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
25-
// FIXME: how should I treat this error?
26-
installationID, _ := uuid.NewV4()
27-
Store.SetDefault("installation.id", installationID.String())
28-
installationSecret, _ := uuid.NewV4()
29-
Store.SetDefault("installation.secret", installationSecret.String())
30-
if err = Store.SafeWriteConfigAs(configPath); err != nil {
31-
if os.IsNotExist(err) {
32-
err = Store.WriteConfigAs(configPath)
33-
}
47+
generateInstallationData()
48+
err := Store.WriteConfigAs(configFilePath)
49+
if err != nil {
50+
feedback.Errorf("Error writing repertory file: %v", err)
3451
}
3552
} else {
3653
feedback.Errorf("Error reading repertory file: %v", err)
37-
3854
}
3955
}
4056
}
57+
58+
func generateInstallationData() {
59+
60+
installationID, err := uuid.NewV4()
61+
if err != nil {
62+
feedback.Errorf("Error generating installation.id: %v", err)
63+
}
64+
Store.Set("installation.id", installationID.String())
65+
66+
installationSecret, err := uuid.NewV4()
67+
if err != nil {
68+
feedback.Errorf("Error generating installation.secret: %v", err)
69+
}
70+
Store.Set("installation.secret", installationSecret.String())
71+
}

telemetry/telemetry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import (
1919
"crypto/hmac"
2020
"crypto/sha256"
2121
"encoding/hex"
22-
"github.com/arduino/arduino-cli/repertory"
2322
"net/http"
2423
"path/filepath"
2524

25+
"github.com/arduino/arduino-cli/repertory"
2626
"github.com/segmentio/stats/v4"
2727
"github.com/segmentio/stats/v4/prometheus"
2828
"github.com/sirupsen/logrus"
@@ -51,8 +51,8 @@ func Activate(metricPrefix string) {
5151

5252
}
5353

54-
// SanitizeSketchPath uses config generated UUID (installation.secret) as an HMAC secret to sanitize and anonymize the sketch
55-
// name maintaining it distinguishable from a different sketch from the same Installation
54+
// SanitizeSketchPath uses config generated UUID (installation.secret) as an HMAC secret to sanitize and anonymize
55+
// the sketch name maintaining it distinguishable from a different sketch from the same Installation
5656
func SanitizeSketchPath(sketchPath string) string {
5757
logrus.Infof("repertory.Store.ConfigFileUsed() %s", repertory.Store.ConfigFileUsed())
5858
installationSecret := repertory.Store.GetString("installation.secret")

0 commit comments

Comments
 (0)