Compare commits
No commits in common. "main" and "data-work" have entirely different histories.
30
functions.go
30
functions.go
@ -2,40 +2,14 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/uptrace/bun"
|
"github.com/uptrace/bun"
|
||||||
"github.com/uptrace/bun/dialect/pgdialect"
|
"github.com/uptrace/bun/dialect/pgdialect"
|
||||||
"github.com/uptrace/bun/driver/pgdriver"
|
"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)))
|
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn)))
|
||||||
r := bun.NewDB(sqldb, pgdialect.New())
|
r := PostgresClient{bun.NewDB(sqldb, pgdialect.New())}
|
||||||
return r
|
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
|
|
||||||
}
|
|
||||||
|
22
main.go
22
main.go
@ -1,7 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/uptrace/bun"
|
||||||
|
"github.com/uptrace/bun/dialect/pgdialect"
|
||||||
|
"github.com/uptrace/bun/driver/pgdriver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tofu Provider is the goal
|
// Tofu Provider is the goal
|
||||||
@ -18,25 +23,14 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
pgdsn = "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
|
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 := new(Anvil)
|
||||||
anvil.AddStriker(Striker{})
|
anvil.AddStriker(Striker{})
|
||||||
// anvil.Strikers[0].SetFQDN("mh-striker01.libre.audio")
|
// anvil.Strikers[0].SetFQDN("mh-striker01.libre.audio")
|
||||||
pge := &PostgresClient{OpenDB(pgdsn)}
|
e := &PostgresClient{bun.NewDB(sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(pgdsn))), pgdialect.New())}
|
||||||
anvil.Strikers[0].AddEndpoint(pge)
|
|
||||||
|
|
||||||
webe := &WebClient{OpenHTTP()}
|
|
||||||
anvil.Strikers[0].AddEndpoint(webe)
|
|
||||||
|
|
||||||
sshe := &SSHClient{OpenSSH(sshdsn)}
|
|
||||||
anvil.Strikers[0].AddEndpoint(sshe)
|
|
||||||
|
|
||||||
|
anvil.Strikers[0].AddEndpoint(e)
|
||||||
fmt.Printf("Strikers[0].Endpoints.PostgresClient = %s.\n", anvil.Strikers[0].Endpoints.PostgresClient)
|
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)
|
// fmt.Printf("Strikers[0].FQDN = %s.\n", anvil.Strikers[0].FQDN)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user