Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/python-test-gefyra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:
- name: Install k3d
shell: bash
run: "curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash"
- name: Set Getdeck to no tracking
shell: bash
run: |
mkdir -p ~/.deck
cd ~/.deck
touch config.ini
echo "[telemetry]" >> config.ini
echo "track = False" >> config.ini
- name: Create a cluster using getdeck
run: |
poetry run coverage run -a -m getdeck get --name oauth2-demo --wait --timeout 180 https://github.com/gefyrahq/gefyra-demos.git
Expand Down
24 changes: 24 additions & 0 deletions getdeck/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import traceback
from getdeck.telemetry.telemetry import CliTelemetry


os.environ["PYOXIDIZER"] = "1"
Expand Down Expand Up @@ -108,6 +109,27 @@ def check_positive(value):
"--name", help="the Deck whose hosts will be considered", required=False
)

telemetry_parser = action.add_parser("telemetry")
telemetry_parser.add_argument("--off", help="Turn off telemetry", action="store_true")
telemetry_parser.add_argument("--on", help="Turn on telemetry", action="store_true")

try:
telemetry = CliTelemetry()
except Exception:
telemetry = False


def telemetry_command(on, off):
if not telemetry:
logger.info("Telemetry in not working on your machine. No action taken.")
return
if off and not on:
telemetry.off()
elif on and not off:
telemetry.on()
else:
logger.info("Invalid flags. Please use either --off or --on.")


def main():
from getdeck import configuration
Expand Down Expand Up @@ -162,6 +184,8 @@ def main():
args.host_action,
deck_name=args.name,
)
elif args.action == "telemetry":
telemetry_command(on=args.on, off=args.off)
else:
parser.print_help()
exit(0)
Expand Down
Empty file added getdeck/telemetry/__init__.py
Empty file.
90 changes: 90 additions & 0 deletions getdeck/telemetry/telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import configparser
import logging
from pathlib import Path

from cli_tracker.sdk import CliTracker
from getdeck.configuration import __VERSION__

logger = logging.getLogger("deck")

#########################################################################################
# Telemetry information
# We are collecting anonymous data about the usage of Getdeck as CLI
# All the data we collect is published here: ``
# This data is supposed to help us develop Getdeck and make it a better tool, prioritize
# issues and work on bugs, features and review of pull requests.
# If you do not which to send telemetry data this is totally fine.
# Just opt out via `deck telemetry --off`.
#########################################################################################

SENTRY_DSN = "https://9d578ce0b91548f28af4c1ee90197768@sentry.unikube.io/4"


class CliTelemetry:
dir_name = ".deck"
file_name = "config.ini"

def __init__(self):
# We're loading / creating a settings file in the home directory.
home = Path.home()
deck_dir = home / self.dir_name
if deck_dir.exists():
deck_settings_path = deck_dir / self.file_name
if deck_settings_path.exists():
config = self.load_config(str(deck_settings_path))
else:
config = self.create_config(deck_settings_path)
else:
config = self.create_config(deck_dir / self.file_name)
try:
config["telemetry"].getboolean("track")
except KeyError:
config = self.create_config(deck_dir / self.file_name)

if config["telemetry"].getboolean("track"):
self._init_tracker()

def _init_tracker(self):
self.tracker = CliTracker(
application="getdeck",
dsn=SENTRY_DSN,
release=__VERSION__,
)

def load_config(self, path):
config = configparser.ConfigParser()
config.read(path)
self.path = path
return config

def create_config(self, path):
config = configparser.ConfigParser()
config["telemetry"] = {"track": "True"}

output_file = Path(path)
output_file.parent.mkdir(exist_ok=True, parents=True)

with open(str(output_file), "w") as config_file:
config.write(config_file)
self.path = path
return config

def off(self):
config = configparser.ConfigParser()
config.read(self.path)
config["telemetry"]["track"] = "False"
with open(str(self.path), "w") as config_file:
config.write(config_file)
if hasattr(self, "tracker"):
self.tracker.report_opt_out()
logger.info("Disabled telemetry.")

def on(self):
config = configparser.ConfigParser()
config.read(self.path)
config["telemetry"]["track"] = "True"
with open(str(self.path), "w") as config_file:
config.write(config_file)
self._init_tracker()
self.tracker.report_opt_in()
logger.info("Enabled telemetry.")
Loading