Skip to content

Commit

Permalink
dtaas cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Astitva committed Mar 23, 2024
1 parent 363dfd8 commit 6739fbc
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 199 deletions.
28 changes: 28 additions & 0 deletions cli/dtaas.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is the config for DTaaS CLI

name = "Digital Twin as a Service (DTaaS)"
version = "0.1"
owner = "The INTO-CPS-Association"
git-repo = "https://github.com/into-cps-association/DTaaS.git"

[common]
# absolute path to the DTaaS application directory
server-dns = "domain.com"
path = "/home/astitva/Desktop/yamlstuff"

[users]
# matching user info must present in this config file
add = ["astitvasehgal05","astitvasehgal19", "prasad"]
delete = ["astitvasehgal19", "prasad"]

[users.astitvasehgal05]
email = "[email protected]"

[users.astitvasehgal19]
email = "[email protected]"

[users.prasad]
email = "[email protected]"

[client.web]
config = "/home/astitva/Desktop/yamlstuff/env.local.js"
61 changes: 0 additions & 61 deletions cli/dtaas_cli/cmd.py

This file was deleted.

23 changes: 0 additions & 23 deletions cli/dtaas_cli/pkg/dtaas.py

This file was deleted.

21 changes: 0 additions & 21 deletions cli/dtaas_cli/pkg/helper.py

This file was deleted.

92 changes: 0 additions & 92 deletions cli/dtaas_cli/pkg/users.py

This file was deleted.

4 changes: 2 additions & 2 deletions cli/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(
name='dtaas_cli',
name='src',
version='0.1.0',
packages=find_packages(),
include_package_data=True,
Expand All @@ -10,7 +10,7 @@
],
entry_points={
'console_scripts': [
'dtaas = dtaas_cli.cmd:dtaas',
'dtaas = src.cmd:dtaas',
],
},
)
File renamed without changes.
52 changes: 52 additions & 0 deletions cli/src/cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import click
#from . import service
from .pkg import dtaas as dtaasPkg
from .pkg import users as userPkg
from .pkg import utils



### Groups
@click.group()
def dtaas():
"""all commands to help with Digital Twins as a Service"""
pass

@dtaas.group()
def admin():
"administrative commands for DTaaS"
pass

@admin.group()
def user():
"""user management commands"""
pass

#### user group commands
@user.command()
def add():
"""
add a list of users to DTaaS at once\n
Specify the list in dtaas.toml [users].add\n
"""

configObj = dtaasPkg.Config()

err = userPkg.addUsers(configObj)
if err!=None:
raise click.ClickException("Error while adding users: " + str(err))
click.echo("Users added successfully")

@user.command()
def delete():
"""
removes the USERNAME user from DTaaS\n
Specify the users in dtaas.toml [users].delete\n
"""

configObj = dtaasPkg.Config()

err = userPkg.deleteUser(configObj)
if err!=None:
raise click.ClickException("Error while deleting users: " + str(err))
click.echo("User deleted successfully")
72 changes: 72 additions & 0 deletions cli/src/pkg/dtaas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import click
from . import utils

class Config:
def __init__(self):
config, err = utils.importToml('dtaas.toml')
if err!=None:
raise click.ClickException("config initialisation failed: "+str(err))
self.data = config

def getConfig(self):
if self.data!=None:
return self.data,None
return None, Exception("Config not initialised")

def getCommon(self):
conf, err = self.getConfig()
if err!=None:
return None, err

if 'common' not in conf:
return None, Exception("Config file error: Missing 'common' tag")
return conf['common'], None

def getUsers(self):
conf, err = self.getConfig()
if err!=None:
return None, err

if 'users' not in conf:
return None, Exception("Config file error: Missing 'users' tag")
return conf['users'], None


def getPath(self):
confCommon, err = self.getCommon()
if err!=None:
return None, err

if 'path' not in confCommon or confCommon['path']=="":
return None, Exception("Config file error: The path for DTaaS directory isn't set in TOML")
return str(confCommon['path']), None

def getServerDNS(self):
confCommon, err = self.getCommon()
if err!=None:
return None, err

if 'server-dns' not in confCommon and confCommon['server-dns']=="":
return None, Exception("Config file error: The server dns isn't set in TOML")
return str(confCommon['server-dns']), None

def getAddUsersList(self):
confUsers, err = self.getUsers()
if err!=None:
return None, err

if 'add' not in confUsers:
return None, Exception("Config file error: No 'add' list in 'users' tag")
addUsersList = [ str(username) for username in confUsers['add']]
return addUsersList, None

def getDeleteUsersList(self):
confUsers, err = self.getUsers()
if err!=None:
return None, err

if 'delete' not in confUsers:
return None, Exception("Config file error: No 'delete' list in 'users' tag")
deleteUsersList = [str(username) for username in confUsers['delete']]
return deleteUsersList, None

Loading

0 comments on commit 6739fbc

Please sign in to comment.