File tree 3 files changed +78
-3
lines changed
components/installation-telemetry 3 files changed +78
-3
lines changed Original file line number Diff line number Diff line change 9
9
"os"
10
10
11
11
"github.com/gitpod-io/gitpod/common-go/log"
12
+ "github.com/gitpod-io/gitpod/installation-telemetry/pkg/common"
13
+ "github.com/gitpod-io/gitpod/installation-telemetry/pkg/server"
12
14
"github.com/spf13/cobra"
13
15
"gopkg.in/segmentio/analytics-go.v3"
14
16
)
@@ -19,9 +21,17 @@ var sendCmd = &cobra.Command{
19
21
Use : "send" ,
20
22
Short : "Sends telemetry data" ,
21
23
RunE : func (cmd * cobra.Command , args []string ) (err error ) {
22
- // @todo(sje): replace with a database call to get status
23
- canSendData := false
24
- if ! canSendData {
24
+ config , err := common .NewConfig ()
25
+ if err != nil {
26
+ return err
27
+ }
28
+
29
+ data , err := server .GetInstallationAdminData (* config )
30
+ if err != nil {
31
+ return err
32
+ }
33
+
34
+ if ! data .SendTelemetry {
25
35
log .Info ("installation-telemetry is not permitted to send - exiting" )
26
36
return nil
27
37
}
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
+ // Licensed under the GNU Affero General Public License (AGPL).
3
+ // See License-AGPL.txt in the project root for license information.
4
+
5
+ package common
6
+
7
+ import (
8
+ "fmt"
9
+ "os"
10
+ )
11
+
12
+ type Config struct {
13
+ Server string
14
+ }
15
+
16
+ func NewConfig () (* Config , error ) {
17
+ config := Config {
18
+ Server : os .Getenv ("SERVER_URL" ),
19
+ }
20
+
21
+ if config .Server == "" {
22
+ return nil , fmt .Errorf ("SERVER_URL required" )
23
+ }
24
+
25
+ return & config , nil
26
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
+ // Licensed under the GNU Affero General Public License (AGPL).
3
+ // See License-AGPL.txt in the project root for license information.
4
+
5
+ package server
6
+
7
+ import (
8
+ "encoding/json"
9
+ "fmt"
10
+ "io/ioutil"
11
+ "net/http"
12
+
13
+ "github.com/gitpod-io/gitpod/installation-telemetry/pkg/common"
14
+ )
15
+
16
+ type InstallationAdminData struct {
17
+ SendTelemetry bool `json:"sendTelemetry"`
18
+ }
19
+
20
+ func GetInstallationAdminData (config common.Config ) (* InstallationAdminData , error ) {
21
+ resp , err := http .Get (fmt .Sprintf ("%s/installation-admin/data" , config .Server ))
22
+ if err != nil {
23
+ return nil , err
24
+ }
25
+
26
+ defer resp .Body .Close ()
27
+
28
+ body , err := ioutil .ReadAll (resp .Body )
29
+ if err != nil {
30
+ return nil , err
31
+ }
32
+
33
+ var data InstallationAdminData
34
+ if err := json .Unmarshal (body , & data ); err != nil {
35
+ return nil , err
36
+ }
37
+
38
+ return & data , nil
39
+ }
You can’t perform that action at this time.
0 commit comments