new file: anvilssh.go
Testing Anvil ssh struct modified: go.mod modified: go.sum modified: main.go modified: models.go Challenge: storing AuthorizedKey record as ssh datatype
This commit is contained in:
parent
5bbe08ded5
commit
2f095a8928
11
anvilssh.go
Normal file
11
anvilssh.go
Normal file
@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
type AnvilSSHConnection struct {
|
||||
thing ssh.Client
|
||||
otherthing term.Terminal
|
||||
}
|
4
go.mod
4
go.mod
@ -3,10 +3,13 @@ module anvil-client
|
||||
go 1.21.10
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/uptrace/bun v1.2.1
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.2.1
|
||||
github.com/uptrace/bun/driver/pgdriver v1.2.1
|
||||
github.com/uptrace/bun/extra/bundebug v1.2.1
|
||||
golang.org/x/crypto v0.21.0
|
||||
golang.org/x/term v0.18.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -17,7 +20,6 @@ require (
|
||||
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
golang.org/x/crypto v0.21.0 // indirect
|
||||
golang.org/x/sys v0.18.0 // indirect
|
||||
mellium.im/sasl v0.3.1 // indirect
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
@ -33,6 +35,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
|
||||
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
mellium.im/sasl v0.3.1 h1:wE0LW6g7U83vhvxjC1IY8DnXM+EU095yeo8XClvCdfo=
|
||||
|
80
main.go
80
main.go
@ -3,70 +3,50 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var feeds []Feed
|
||||
var categories []Category
|
||||
var entries []Entry
|
||||
var users []User
|
||||
var ssh_keys []SSHKey
|
||||
|
||||
//var servers []Server
|
||||
//var server_definitions []ServerDefinition
|
||||
//var manifests []Manifest
|
||||
//var jobs []Job
|
||||
//var hosts []Host
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
dsn := "postgres://apache:@localhost:5432/miniflux?sslmode=disable"
|
||||
dsn := "postgres://postgres:Initial1@localhost:15432/anvil?sslmode=disable"
|
||||
// dsn := "unix://user:pass@dbname/var/run/postgresql/.s.PGSQL.5432"
|
||||
|
||||
anvildb := ConnectAnvilDB(dsn)
|
||||
// Turn these into funcs with error handling, logging, return vals etc.
|
||||
feederr := anvildb.NewSelect().
|
||||
Model(&Feed{}).
|
||||
OrderExpr("title ASC").
|
||||
Limit(10).
|
||||
Scan(ctx, &feeds)
|
||||
|
||||
if feederr != nil {
|
||||
errors.Join(feederr, err)
|
||||
}
|
||||
categoryerr := anvildb.NewSelect().
|
||||
Model(&Category{}).
|
||||
OrderExpr("title ASC").
|
||||
Scan(ctx, &categories)
|
||||
if categoryerr != nil {
|
||||
errors.Join(categoryerr, err)
|
||||
}
|
||||
entryerr := anvildb.NewSelect().
|
||||
Model(&Entry{}).
|
||||
OrderExpr("published_at ASC").
|
||||
Limit(10).
|
||||
Scan(ctx, &entries)
|
||||
if entryerr != nil {
|
||||
errors.Join(entryerr, err)
|
||||
}
|
||||
usererr := anvildb.NewSelect().
|
||||
if usererr := anvildb.NewSelect().
|
||||
// Turning *Feed into an interface &Feed{}
|
||||
Model(&User{}).
|
||||
OrderExpr("id ASC").
|
||||
Scan(ctx, &users)
|
||||
if usererr != nil {
|
||||
OrderExpr("user_uuid ASC").
|
||||
Limit(10).
|
||||
Scan(ctx, &users); usererr != nil {
|
||||
errors.Join(usererr, err)
|
||||
}
|
||||
|
||||
for _, val := range entries {
|
||||
fmt.Printf("val = %s\n", val)
|
||||
if sshkeyerr := anvildb.NewSelect().
|
||||
Model(&SSHKey{}).
|
||||
OrderExpr("ssh_key_user_name ASC").
|
||||
Scan(ctx, &ssh_keys); sshkeyerr != nil {
|
||||
errors.Join(sshkeyerr, err)
|
||||
}
|
||||
for _, val := range categories {
|
||||
|
||||
fmt.Printf("val = %s\n", val)
|
||||
}
|
||||
for _, val := range feeds {
|
||||
fmt.Printf("val = %s\n", val)
|
||||
}
|
||||
for _, val := range users {
|
||||
fmt.Printf("val = %s\n", val)
|
||||
}
|
||||
|
||||
// fmt.Printf("%+v\n", entries)
|
||||
// fmt.Printf("%+v\n", categories)
|
||||
// fmt.Printf("%+v\n", feeds)
|
||||
// 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)
|
||||
}
|
||||
|
76
models.go
76
models.go
@ -1,37 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
bun.BaseModel `bun:"table:users"`
|
||||
|
||||
ID int64 `bun:"id,pk,autoincrement"`
|
||||
Username string `bun:"username"`
|
||||
UUID uuid.UUID `bun:"user_uuid,pk"`
|
||||
Username string `bun:"user_name"`
|
||||
IsExperienced bool `bun:"user_is_experienced"`
|
||||
IsTrusted bool `bun:"user_is_trusted"`
|
||||
// https://pkg.go.dev/github.com/google/uuid#UUID
|
||||
// SELECT user_uuid,user_name,user_is_experienced,user_is_trusted FROM \
|
||||
// users ORDER BY user_uuid;
|
||||
}
|
||||
|
||||
type Feed struct {
|
||||
bun.BaseModel `bun:"table:feeds"`
|
||||
type SSHKey struct {
|
||||
bun.BaseModel `bun:"table:ssh_keys"`
|
||||
|
||||
ID int64 `bun:"id,pk,autoincrement"`
|
||||
CategoryID int64 `bun:"category_id"`
|
||||
Title string `bun:"title"`
|
||||
// SELECT id,category_id,title FROM feeds ORDER BY id;
|
||||
UUID uuid.UUID `bun:"ssh_key_uuid,pk"`
|
||||
Username string `bun:"ssh_key_user_name"`
|
||||
PublicKey []byte `bun:"ssh_key_public_key"`
|
||||
// https://pkg.go.dev/golang.org/x/crypto/ssh#PublicKey
|
||||
// SELECT ssh_key_uuid,ssh_key_user_name FROM ssh_keys ORDER BY ssh_key_user_name;
|
||||
}
|
||||
type Entry struct {
|
||||
bun.BaseModel `bun:"table:entries"`
|
||||
|
||||
ID int64 `bun:"id,pk,autoincrement"`
|
||||
Title string `bun:"title"`
|
||||
Author string `bun:"author"`
|
||||
// SELECT id,title,author FROM entries ORDER BY published_at LIMIT 10;
|
||||
type Server struct {
|
||||
}
|
||||
type Category struct {
|
||||
bun.BaseModel `bun:"table:categories"`
|
||||
|
||||
ID int64 `bun:"id,pk,autoincrement"`
|
||||
Title string `bun:"title"`
|
||||
//SELECT id,title from categories;
|
||||
|
||||
type ServerDefinition struct {
|
||||
}
|
||||
|
||||
type Manifest struct {
|
||||
bun.BaseModel `bun:"table:manifests"`
|
||||
|
||||
UUID uuid.UUID `bun:"mainifest_uuid,pk"`
|
||||
Name string `bun:"manifest_name"`
|
||||
LastRan string `bun:"manifest_last_ran"`
|
||||
XML string `bun:"manifest_xml"`
|
||||
Note string `bun:"manifest_note"`
|
||||
// https://pkg.go.dev/encoding/xml#CharData
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
bun.BaseModel `bun:"table:jobs"`
|
||||
|
||||
UUID uuid.UUID `bun:"job_uuid,pk"`
|
||||
HostUUID uuid.UUID `bun:"host_uuid"`
|
||||
Command string `bun:"job_command"`
|
||||
Data string `bun:"job_data"`
|
||||
PickedUpBy string `bun:"job_picked_up_by"`
|
||||
PickedUpAt string `bun:"job_picked_up_at"`
|
||||
Updated string `bun:"job_updated"`
|
||||
Name string `bun:"job_name"`
|
||||
Progress int64 `bun:"job_progress"`
|
||||
Title string `bun:"job_title"`
|
||||
Description string `bun:"job_description"`
|
||||
Status string `bun:"job_status"`
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
bun.BaseModel `bun:"table:hosts"`
|
||||
|
||||
UUID uuid.UUID `bun:"host_uuid,pk"`
|
||||
HostName string `bun:"host_name"`
|
||||
HostType string `bun:"host_type"`
|
||||
HostKey string `bun:"host_key"`
|
||||
HostIPMI string `bun:"host_ipmi"`
|
||||
HostStatus string `bun:"host_status"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user