mirror of
https://github.com/openziti/zrok.git
synced 2025-08-14 10:08:26 +02:00
record service activate/deactivate (#10)
This commit is contained in:
@ -9,10 +9,11 @@ type Identity struct {
|
||||
Model
|
||||
AccountId int
|
||||
ZitiId string
|
||||
Active bool
|
||||
}
|
||||
|
||||
func (self *Store) CreateIdentity(accountId int, i *Identity, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into identities (account_id, ziti_id) values (?, ?)")
|
||||
stmt, err := tx.Prepare("insert into identities (account_id, ziti_id, active) values (?, ?, true)")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing identities insert statement")
|
||||
}
|
||||
|
@ -10,10 +10,11 @@ type Service struct {
|
||||
AccountId int
|
||||
ZitiId string
|
||||
Endpoint string
|
||||
Active bool
|
||||
}
|
||||
|
||||
func (self *Store) CreateService(accountId int, svc *Service, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into services (account_id, ziti_id, endpoint) values (?, ?, ?)")
|
||||
stmt, err := tx.Prepare("insert into services (account_id, ziti_id, endpoint, active) values (?, ?, ?, true)")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing services insert statement")
|
||||
}
|
||||
@ -52,6 +53,18 @@ func (self *Store) FindServicesForAccount(accountId int, tx *sqlx.Tx) ([]*Servic
|
||||
return svcs, nil
|
||||
}
|
||||
|
||||
func (self *Store) DeactivateService(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("update services set active=false where id = ?")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing services deactivate statement")
|
||||
}
|
||||
_, err = stmt.Exec(id)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing services deactivate statement")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *Store) DeleteService(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("delete from services where id = ?")
|
||||
if err != nil {
|
||||
|
@ -23,8 +23,9 @@ create table identities (
|
||||
id integer primary key,
|
||||
account_id integer constraint fk_accounts_identities references accounts on delete cascade,
|
||||
ziti_id string not null unique,
|
||||
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
active boolean not null,
|
||||
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
|
||||
constraint chk_ziti_id check (ziti_id <> '')
|
||||
);
|
||||
@ -37,6 +38,7 @@ create table services (
|
||||
account_id integer constraint fk_accounts_services references accounts on delete cascade,
|
||||
ziti_id string not null unique,
|
||||
endpoint string,
|
||||
active boolean not null,
|
||||
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
|
||||
|
Reference in New Issue
Block a user