From 7f290bd7f1e81695114bdc5150f50deb77a2606d Mon Sep 17 00:00:00 2001 From: Paul Gellai Date: Tue, 12 Nov 2024 17:24:34 -0700 Subject: [PATCH] no more machine ID --- pkg/database/models/ssh_config.go | 1 - pkg/database/repository/ssh_config.go | 10 +++++----- pkg/web/router/routes/data.go | 7 ------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pkg/database/models/ssh_config.go b/pkg/database/models/ssh_config.go index a02331d..477d5cd 100644 --- a/pkg/database/models/ssh_config.go +++ b/pkg/database/models/ssh_config.go @@ -7,7 +7,6 @@ import ( type SshConfig struct { ID uuid.UUID `json:"id" db:"id"` UserID uuid.UUID `json:"user_id" db:"user_id"` - MachineID uuid.UUID `json:"machine_id" db:"machine_id"` Host string `json:"host" db:"host"` Values map[string][]string `json:"values" db:"values"` IdentityFiles []string `json:"identity_files" db:"identity_files"` diff --git a/pkg/database/repository/ssh_config.go b/pkg/database/repository/ssh_config.go index b036aa6..5ee2cb2 100644 --- a/pkg/database/repository/ssh_config.go +++ b/pkg/database/repository/ssh_config.go @@ -11,7 +11,7 @@ import ( ) type SshConfigRepository interface { - GetSshConfig(machineID uuid.UUID, userID uuid.UUID) (*models.SshConfig, error) + GetSshConfig(userID uuid.UUID) (*models.SshConfig, error) UpsertSshConfig(config *models.SshConfig) (*models.SshConfig, error) UpsertSshConfigTx(config *models.SshConfig, tx pgx.Tx) (*models.SshConfig, error) } @@ -20,9 +20,9 @@ type SshConfigRepo struct { Injector *do.Injector } -func (repo *SshConfigRepo) GetSshConfig(machineID uuid.UUID, userID uuid.UUID) (*models.SshConfig, error) { +func (repo *SshConfigRepo) GetSshConfig(userID uuid.UUID) (*models.SshConfig, error) { q := do.MustInvoke[query.QueryService[models.SshConfig]](repo.Injector) - sshConfig, err := q.QueryOne("select * from ssh_configs where machine_id = $1 and user_id = $2", machineID, userID) + sshConfig, err := q.QueryOne("select * from ssh_configs where user_id = $1", userID) if err != nil { return nil, err } @@ -34,7 +34,7 @@ func (repo *SshConfigRepo) GetSshConfig(machineID uuid.UUID, userID uuid.UUID) ( func (repo *SshConfigRepo) UpsertSshConfig(config *models.SshConfig) (*models.SshConfig, error) { q := do.MustInvoke[query.QueryService[models.SshConfig]](repo.Injector) - sshConfig, err := q.QueryOne("insert into ssh_configs (user_id, machine_id, host, values, identity_files) values ($1, $2, $3, $4, $5) on conflict (user_id, machine_id, host) do update set host = $3, values = $4, identity_files = $5 returning *", config.UserID, config.MachineID, config.Host, config.Values, config.IdentityFiles) + sshConfig, err := q.QueryOne("insert into ssh_configs (user_id, host, values, identity_files) values ($1, $2, $3, $4, $5) on conflict (user_id, host) do update set host = $3, values = $4, identity_files = $5 returning *", config.UserID, config.Host, config.Values, config.IdentityFiles) if err != nil { return nil, err } @@ -46,7 +46,7 @@ func (repo *SshConfigRepo) UpsertSshConfig(config *models.SshConfig) (*models.Ss func (repo *SshConfigRepo) UpsertSshConfigTx(config *models.SshConfig, tx pgx.Tx) (*models.SshConfig, error) { q := do.MustInvoke[query.QueryServiceTx[models.SshConfig]](repo.Injector) - sshConfig, err := q.QueryOne(tx, "insert into ssh_configs (user_id, machine_id, host, values, identity_files) values ($1, $2, $3, $4, $5) on conflict (user_id, machine_id, host) do update set host = $3, values = $4, identity_files = $5 returning *", config.UserID, config.MachineID, config.Host, config.Values, config.IdentityFiles) + sshConfig, err := q.QueryOne(tx, "insert into ssh_configs (user_id, host, values, identity_files) values ($1, $2, $3, $4, $5) on conflict (user_id, host) do update set host = $3, values = $4, identity_files = $5 returning *", config.UserID, config.Host, config.Values, config.IdentityFiles) if err != nil { return nil, err } diff --git a/pkg/web/router/routes/data.go b/pkg/web/router/routes/data.go index fc80f6a..64e709c 100644 --- a/pkg/web/router/routes/data.go +++ b/pkg/web/router/routes/data.go @@ -73,12 +73,6 @@ func addData(i *do.Injector) http.HandlerFunc { w.WriteHeader(http.StatusInternalServerError) return } - machine, ok := r.Context().Value(context_keys.MachineContextKey).(*models.Machine) - if !ok { - log.Err(errors.New("could not get machine from context")) - w.WriteHeader(http.StatusInternalServerError) - return - } userRepo := do.MustInvoke[repository.UserRepository](i) err := r.ParseMultipartForm(32 << 20) if err != nil { @@ -102,7 +96,6 @@ func addData(i *do.Injector) http.HandlerFunc { sshConfigData := lo.Map(sshConfig, func(conf dto.SshConfigDto, i int) models.SshConfig { return models.SshConfig{ UserID: user.ID, - MachineID: machine.ID, Host: conf.Host, Values: conf.Values, IdentityFiles: conf.IdentityFiles,