Compare commits

..

No commits in common. 'main' and 'data-work' have entirely different histories.

  1. 30
      functions.go
  2. 20
      main.go
  3. 1
      types.go

@ -2,40 +2,14 @@ package main
import (
"database/sql"
"log"
"net/http"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
)
func OpenDB(dsn string) *bun.DB {
func OpenDB(dsn string) PostgresClient {
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
r := bun.NewDB(sqldb, pgdialect.New())
r := PostgresClient{bun.NewDB(sqldb, pgdialect.New())}
return r
}
func OpenHTTP() *http.Client {
var cli *http.Client
return cli
}
func OpenSSH(dsn string) *ssh.Client {
knownHosts, _ := knownhosts.New("/home/m00t/.ssh/known_hosts")
config := &ssh.ClientConfig{
User: "admin",
Auth: []ssh.AuthMethod{
ssh.Password("Initial1"),
},
HostKeyCallback: knownHosts,
}
client, err := ssh.Dial("tcp", dsn, config)
if err != nil {
log.Fatal("Failed to dial: ", err)
}
defer client.Close()
return client
}

@ -1,7 +1,12 @@
package main
import (
"database/sql"
"fmt"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
)
// Tofu Provider is the goal
@ -19,24 +24,13 @@ import (
func main() {
var (
pgdsn = "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
sshdsn = "192.168.1.165:22"
// webdsn = "http://192.168.1.165"
)
anvil := new(Anvil)
anvil.AddStriker(Striker{})
// anvil.Strikers[0].SetFQDN("mh-striker01.libre.audio")
pge := &PostgresClient{OpenDB(pgdsn)}
anvil.Strikers[0].AddEndpoint(pge)
webe := &WebClient{OpenHTTP()}
anvil.Strikers[0].AddEndpoint(webe)
sshe := &SSHClient{OpenSSH(sshdsn)}
anvil.Strikers[0].AddEndpoint(sshe)
e := &PostgresClient{bun.NewDB(sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(pgdsn))), pgdialect.New())}
anvil.Strikers[0].AddEndpoint(e)
fmt.Printf("Strikers[0].Endpoints.PostgresClient = %s.\n", anvil.Strikers[0].Endpoints.PostgresClient)
fmt.Printf("Strikers[0].Endpoints.WebClient = %s.\n", anvil.Strikers[0].Endpoints.WebClient)
fmt.Printf("Strikers[0].Endpoints.SSHClient = %s.\n", anvil.Strikers[0].Endpoints.SSHClient)
// fmt.Printf("Strikers[0].FQDN = %s.\n", anvil.Strikers[0].FQDN)
}

@ -41,7 +41,6 @@ type Striker struct {
type Host struct {
FQDN string
Endpoints Endpoints
}
type BMC struct {

Loading…
Cancel
Save