@@ -12,9 +12,6 @@ import (
1212 "github.com/charmbracelet/bubbles/help"
1313 tea "github.com/charmbracelet/bubbletea"
1414 "github.com/toeirei/keymaster/client"
15- "github.com/toeirei/keymaster/client/mock"
16- "github.com/toeirei/keymaster/client/testui"
17- "github.com/toeirei/keymaster/tags"
1815 "github.com/toeirei/keymaster/ui/tui/components/menu"
1916 "github.com/toeirei/keymaster/ui/tui/components/router"
2017 "github.com/toeirei/keymaster/ui/tui/components/stack"
@@ -35,48 +32,16 @@ type Model struct {
3532 router * util.Model
3633 routerControll router.Controll
3734 client client.Client
38- store interface {}
3935}
4036
41- func New (storeParam interface {} ) * Model {
37+ func New (c client. Client ) * Model {
4238 // stack {
4339 // menu
4440 // router {
4541 // dashboard
4642 // }
4743 // }
4844
49- c := client .Client (testui .NewClient ())
50-
51- // test accounts
52- _ , _ = c .CreateAccount (context .Background (), "root" , "1.2.3.4" , 22 , "ssh" , "password123" )
53- _ , _ = c .CreateAccount (context .Background (), "user" , "1.2.3.4" , 22 , "ssh" , "password123" )
54- _ , _ = c .CreateAccount (context .Background (), "srv" , "10.0.0.1" , 22 , "ssh" , "password123" )
55- _ , _ = c .CreateAccount (context .Background (), "mark" , "1.2.3.4" , 22 , "ssh" , "password123" )
56- _ , _ = c .CreateAccount (context .Background (), "admin" , "10.20.0.1" , 222 , "cisco" , "password123" )
57- // test publicKeys
58- _ , _ = c .CreatePublicKey (context .Background (), "Sha-your-mom ashtdjhk-fbaskjdfhal_sdvkhaösdljhask-zdpjwb" , "my-key" , tags.Tags {"user:jannes" , "company:work" , "server-ci" })
59- _ , _ = c .CreatePublicKey (context .Background (), "Sha-your-mom ashtdjhk-fbaskjdfhal_sdvkhaösdljhask-öutyfb" , "my-key" , tags.Tags {"user:jannes" , "company:none" })
60- _ , _ = c .CreatePublicKey (context .Background (), "Sha-420 asdjhk-fbaskdasral_jklkhathrösdljhask-fdjfb" , "419" , tags.Tags {"user:toeirei" , "company:big_money" })
61- _ , _ = c .CreatePublicKey (context .Background (), "Sha-420 asdjhk-fbaskjdfhal_sdvtzuthrösdljhaha-ögjfb" , "420" , tags.Tags {"user:toeirei" , "company:work" , "server-ci" })
62- _ , _ = c .CreatePublicKey (context .Background (), "Sha-420 asdjhk-fbaskjterhl_sdvkhaghdjfdljhask-ödhfb" , "421" , tags.Tags {"user:toeirei" , "company:none" })
63- _ , _ = c .CreatePublicKey (context .Background (), "Sha-69 asdjkhk-fbdfhtdftrhhal_sdvkhaösu656zsk-ödjhtfb" , "69" , tags.Tags {"user:somebodyelse" , "company:evilgoogle" , "server-ci" })
64- // test links
65- _ , _ = c .CreateLink (context .Background (), 1 , "(user:jannes | user:toeirei) & !company:work" , time .Now ().Add (time .Hour ))
66- _ , _ = c .CreateLink (context .Background (), 2 , "!user:somebodyelse" , time .Now ().Add (time .Hour ))
67- _ , _ = c .CreateLink (context .Background (), 3 , "server-ci" , time .Now ().Add (time .Hour ))
68- _ , _ = c .CreateLink (context .Background (), 4 , "company:evilgoogle" , time .Now ().Add (time .Hour ))
69- _ , _ = c .CreateLink (context .Background (), 5 , "company:work" , time .Now ().Add (time .Hour ))
70- _ , _ = c .CreateLink (context .Background (), 5 , "company:big_money" , time .Now ())
71-
72- c = mock .NewClient (mock .WitchBaseClient (c ), mock .WitchPre (func (method string , args map [string ]any ) error {
73- time .Sleep (time .Millisecond * 100 )
74- if ctx , ok := args ["ctx" ].(context.Context ); ok {
75- return ctx .Err ()
76- }
77- return nil
78- }))
79-
8045 menuPtr := util .ModelPointer (menu .New (
8146 menu .WithItem ("dashboard.show" , "Dashboard" ),
8247 menu .WithItem ("publickey.list" , "Public Keys" ),
@@ -95,7 +60,7 @@ func New(storeParam interface{}) *Model {
9560 ),
9661 ),
9762 ))
98- dashboardPtr := util .ModelPointer (dashboard .New (storeParam ))
63+ dashboardPtr := util .ModelPointer (dashboard .New (c ))
9964 routerModel , routerControll := router .New (dashboardPtr )
10065 routerPtr := util .ModelPointer (routerModel )
10166 stackModel := stack .New (
@@ -110,7 +75,6 @@ func New(storeParam interface{}) *Model {
11075 router : routerPtr ,
11176 routerControll : routerControll ,
11277 client : c ,
113- store : storeParam ,
11478 }
11579}
11680
@@ -123,7 +87,7 @@ func (m *Model) Update(msg tea.Msg) tea.Cmd {
12387 if msg , ok := msg .(menu.ItemSelected ); ok {
12488 switch msg .Id {
12589 case "dashboard.show" :
126- return m .routerControll .Change (util .ModelPointer (dashboard .New (m .store )))
90+ return m .routerControll .Change (util .ModelPointer (dashboard .New (m .client )))
12791
12892 case "publickey.list" :
12993 return publickey .NewCrud (m .client , m .routerControll ).OpenList ()
0 commit comments