|
|
|
@ -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)
|
|
|
|
|
} |
|
|
|
|