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