Skip to content

Commit

Permalink
no more machine ID (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealpaulgg authored Nov 13, 2024
1 parent a7ae1e9 commit 210fd68
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
1 change: 0 additions & 1 deletion pkg/database/models/ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
10 changes: 5 additions & 5 deletions pkg/database/repository/ssh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/web/router/routes/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 210fd68

Please sign in to comment.