Scope adustments

data-work
Mike Holloway 3 months ago
parent 2f56639f5b
commit 09c1bd44c9
  1. 3
      anvildb.go
  2. 0
      db.go
  3. 14
      functions.go
  4. 39
      main.go
  5. 0
      ssh.go
  6. 24
      types.go

@ -1,3 +0,0 @@
package main
//anvildb.NewSelect().Model(&SSHKey{}).OrderExpr("ssh_key_user_name ASC").

@ -0,0 +1,14 @@
package main
import (
"database/sql"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
)
func OpenDB(dsn string) *sql.DB {
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
return bun.NewDB(sqldb, pgdialect.New())
}

@ -2,17 +2,15 @@ package main
import (
"context"
"database/sql"
"github.com/uptrace/bun/driver/pgdriver"
)
// Tofu Provider is the goal
// Data Sources first
// Resources later
//var users []UserModel
//var ssh_keys []SSHKeyModel
var users []UserModel
var ssh_keys []SSHKeyModel
//var servers []Server
//var server_definitions []ServerDefinition
//var manifests []Manifest
@ -21,48 +19,25 @@ import (
func main() {
var (
err error
ctx = context.Background()
dsn = "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
)
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
anvil := &Anvil{
Strikers: []Striker{
Striker{
FQDN: "mh-striker01.libre.audio",
},
},
}
anvil.Strikers[0].Endpoints.Postgresql = &sqldb
// Calling PostgresClient as an instance method as per:
// https://stackoverflow.com/questions/38666404/not-enough-arguments-in-call-to-method-expression
anvildb := OpenDB(dsn)
// Turn these into funcs with error handling, logging, return vals etc.
// if usererr := anvildb.NewSelect().
// // Turning *User into an interface &User{}
// Model(&User{}).
// Model(&UserModel{}).
// OrderExpr("user_uuid ASC").
// Limit(10).
// Scan(ctx, &users); usererr != nil {
// errors.Join(usererr, err)
// }
// if sshkeyerr := anvildb.NewSelect().
// Model(&SSHKey{}).
// OrderExpr("ssh_key_user_name ASC").
// Scan(ctx, &ssh_keys); sshkeyerr != nil {
// errors.Join(sshkeyerr, err)
// }
// fmt.Printf("##\n## Users\n###\n\n")
// for _, val := range users {
// fmt.Printf("%s\n", val.Username)
// }
// fmt.Printf("##\n## SSH Keys\n##\n\n")
// for _, val := range ssh_keys {
// fmt.Printf("UUID :\n%s\n", val.UUID.String())
// fmt.Printf("Username :\n%s\n", val.Username)
// fmt.Printf("PublicKey :\n%s\n", val.PublicKey)
// fmt.Printf("####\n\n")
// }
//
// fmt.Printf("%+v\n", users)
}

@ -16,20 +16,24 @@ type Anvil struct {
UPSes []UPS
}
type WebClient struct {
*http.Client
}
type SSHClient struct {
*ssh.Client
}
type PostgresClient struct {
*sql.DB
}
type Striker struct {
FQDN string
Endpoints struct {
StrikerWebUI *http.Client
Postgresql *sql.DB
SecureShell *ssh.Client
}
}
type Host struct {
FQDN string
Endpoints struct {
SecureShell *ssh.Client
}
}
type BMC struct {
@ -43,7 +47,3 @@ type PDU struct {
type UPS struct {
}
//func (d *DB) GetManifests() *SelectQuery {
//
//}

Loading…
Cancel
Save