Skip to content

Commit 0e228d0

Browse files
kaberovnikitalykinsbd
authored andcommitted
refactor func names
1 parent b36cfb7 commit 0e228d0

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

fakedevices/genericFakeDevice.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ func readFile(filename string) (string, error) {
6161

6262
// InitScenario builds a FakeDevice for a named scenario, loading the base platform
6363
// and returning the pre-loaded sequence steps alongside the device.
64-
func InitScenario(scenarioName string, tm transcript.Map, baseDir string) (*FakeDevice, []transcript.SequenceStep, error) {
65-
s, ok := tm.Scenarios[scenarioName]
64+
func InitScenario(name string, tm transcript.Map, baseDir string) (*FakeDevice, []transcript.SequenceStep, error) {
65+
s, ok := tm.Scenarios[name]
6666
if !ok {
67-
return nil, nil, fmt.Errorf("scenario %q not found in transcript map", scenarioName)
67+
return nil, nil, fmt.Errorf("scenario %q not found in transcript map", name)
6868
}
6969
fd, err := InitGeneric(s.Platform, tm, baseDir)
7070
if err != nil {
7171
return nil, nil, err
7272
}
73-
fd.ScenarioName = scenarioName
73+
fd.ScenarioName = name
7474
steps := make([]transcript.SequenceStep, len(s.Sequence))
7575
for i, step := range s.Sequence {
7676
path := step.Transcript
@@ -89,8 +89,8 @@ func InitScenario(scenarioName string, tm transcript.Map, baseDir string) (*Fake
8989
// InitGeneric builds a FakeDevice struct for use with cisshgo.
9090
// baseDir is the directory from which transcript paths are resolved (typically
9191
// the directory containing the transcript map file).
92-
func InitGeneric(platform string, myTranscriptMap transcript.Map, baseDir string) (*FakeDevice, error) {
93-
p, ok := myTranscriptMap.Platforms[platform]
92+
func InitGeneric(platform string, tm transcript.Map, baseDir string) (*FakeDevice, error) {
93+
p, ok := tm.Platforms[platform]
9494
if !ok {
9595
return nil, fmt.Errorf("platform %q not found in transcript map", platform)
9696
}

fakedevices/transcriptReader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
// TranscriptReader parses a transcript file and populates any variables that may exist in it
11-
func TranscriptReader(transcript string, fakeDevice *FakeDevice) (string, error) {
11+
func TranscriptReader(transcript string, fd *FakeDevice) (string, error) {
1212

1313
// Setup a template with our transcript
1414
tmpl, err := template.New("fakeDeviceTemplate").Parse(transcript)
@@ -20,7 +20,7 @@ func TranscriptReader(transcript string, fakeDevice *FakeDevice) (string, error)
2020
var renderedTemplate bytes.Buffer
2121

2222
// Render (Execute) the template with our input
23-
if err := tmpl.Execute(&renderedTemplate, fakeDevice); err != nil {
23+
if err := tmpl.Execute(&renderedTemplate, fd); err != nil {
2424
return "", err
2525
}
2626

ssh_server/handlers/ciscohandlers.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ import (
1616
)
1717

1818
// GenericCiscoHandler function handles generic Cisco style sessions
19-
func GenericCiscoHandler(myFakeDevice *fakedevices.FakeDevice) ssh.Handler {
20-
return genericCiscoSession(myFakeDevice, nil)
19+
func GenericCiscoHandler(fd *fakedevices.FakeDevice) ssh.Handler {
20+
return genericCiscoSession(fd, nil)
2121
}
2222

2323
// GenericCiscoScenarioHandler returns an ssh.Handler that plays back a scenario sequence.
24-
func GenericCiscoScenarioHandler(myFakeDevice *fakedevices.FakeDevice, sequence []transcript.SequenceStep) ssh.Handler {
25-
return genericCiscoSession(myFakeDevice, sequence)
24+
func GenericCiscoScenarioHandler(fd *fakedevices.FakeDevice, sequence []transcript.SequenceStep) ssh.Handler {
25+
return genericCiscoSession(fd, sequence)
2626
}
2727

28-
func genericCiscoSession(myFakeDevice *fakedevices.FakeDevice, sequence []transcript.SequenceStep) ssh.Handler {
28+
func genericCiscoSession(fd *fakedevices.FakeDevice, sequence []transcript.SequenceStep) ssh.Handler {
2929
return func(s ssh.Session) {
3030

3131
// Exec mode: client sent a command directly (e.g., ssh host "show version")
3232
if cmd := s.RawCommand(); cmd != "" {
3333
log.Printf("exec: %s", cmd)
34-
match, matchedCommand, multipleMatches := cmdmatch.Match(cmd, myFakeDevice.SupportedCommands)
34+
match, matchedCommand, multipleMatches := cmdmatch.Match(cmd, fd.SupportedCommands)
3535
if match && !multipleMatches {
3636
output, err := fakedevices.TranscriptReader(
37-
myFakeDevice.SupportedCommands[matchedCommand], myFakeDevice,
37+
fd.SupportedCommands[matchedCommand], fd,
3838
)
3939
if err == nil {
4040
io.WriteString(s, output)
@@ -46,8 +46,8 @@ func genericCiscoSession(myFakeDevice *fakedevices.FakeDevice, sequence []transc
4646

4747
// Interactive shell mode — sequence pointer resets per session
4848
seqIdx := 0
49-
contextState := myFakeDevice.ContextSearch["base"]
50-
t := term.NewTerminal(s, devicePrompt(myFakeDevice, contextState))
49+
contextState := fd.ContextSearch["base"]
50+
t := term.NewTerminal(s, devicePrompt(fd, contextState))
5151

5252
for {
5353
userInput, err := t.ReadLine()
@@ -56,7 +56,7 @@ func genericCiscoSession(myFakeDevice *fakedevices.FakeDevice, sequence []transc
5656
}
5757
log.Println(userInput)
5858

59-
done := handleShellInput(t, userInput, myFakeDevice, &contextState, sequence, &seqIdx)
59+
done := handleShellInput(t, userInput, fd, &contextState, sequence, &seqIdx)
6060
if done {
6161
break
6262
}

ssh_server/sshlisteners/sshlisteners.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@ import (
1818
// GenericListener starts an SSH server on the given port and blocks until ctx is cancelled.
1919
func GenericListener(
2020
ctx context.Context,
21-
myFakeDevice *fakedevices.FakeDevice,
22-
portNumber int,
21+
fd *fakedevices.FakeDevice,
22+
port int,
2323
myHandler handlers.PlatformHandler,
2424
) error {
25-
return listen(ctx, myFakeDevice, portNumber, myHandler(myFakeDevice.Copy()))
25+
return listen(ctx, fd, port, myHandler(fd.Copy()))
2626
}
2727

2828
// ScenarioListener starts an SSH server that plays back a scenario sequence.
2929
func ScenarioListener(
3030
ctx context.Context,
31-
myFakeDevice *fakedevices.FakeDevice,
31+
fd *fakedevices.FakeDevice,
3232
sequence []transcript.SequenceStep,
33-
portNumber int,
33+
port int,
3434
) error {
35-
return listen(ctx, myFakeDevice, portNumber, handlers.GenericCiscoScenarioHandler(myFakeDevice.Copy(), sequence))
35+
return listen(ctx, fd, port, handlers.GenericCiscoScenarioHandler(fd.Copy(), sequence))
3636
}
3737

38-
func listen(ctx context.Context, myFakeDevice *fakedevices.FakeDevice, portNumber int, handler ssh.Handler) error {
39-
portString := ":" + strconv.Itoa(portNumber)
40-
if myFakeDevice.ScenarioName != "" {
38+
func listen(ctx context.Context, fd *fakedevices.FakeDevice, port int, handler ssh.Handler) error {
39+
portString := ":" + strconv.Itoa(port)
40+
if fd.ScenarioName != "" {
4141
log.Printf("Starting listener on %s [scenario=%s hostname=%s user=%s]",
42-
portString, myFakeDevice.ScenarioName, myFakeDevice.Hostname, myFakeDevice.Username)
42+
portString, fd.ScenarioName, fd.Hostname, fd.Username)
4343
} else {
4444
log.Printf("Starting listener on %s [platform=%s hostname=%s user=%s]",
45-
portString, myFakeDevice.Platform, myFakeDevice.Hostname, myFakeDevice.Username)
45+
portString, fd.Platform, fd.Hostname, fd.Username)
4646
}
4747

4848
srv := &ssh.Server{
4949
Addr: portString,
5050
Handler: handler,
5151
PasswordHandler: func(sshCtx ssh.Context, pass string) bool {
52-
return sshCtx.User() == myFakeDevice.Username && pass == myFakeDevice.Password
52+
return sshCtx.User() == fd.Username && pass == fd.Password
5353
},
5454
}
5555

0 commit comments

Comments
 (0)