File: responder.go

package info (click to toggle)
acmetool 0.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 792 kB
  • sloc: sh: 349; makefile: 105
file content (34 lines) | stat: -rw-r--r-- 828 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package interaction

import "fmt"

type responder struct{}

var responses = map[string]*Response{}

// Auto-responder. Provides canned responses if they have been set. Otherwise,
// fails.
var Responder Interactor = responder{}

func (responder) Status(c *StatusInfo) (StatusSink, error) {
	return nil, fmt.Errorf("not supported")
}

func (responder) Prompt(c *Challenge) (*Response, error) {
	if c.UniqueID == "" {
		return nil, fmt.Errorf("cannot auto-respond to a challenge without a unique ID")
	}

	res := responses[c.UniqueID]
	if res == nil {
		return nil, fmt.Errorf("unknown unique ID, cannot respond: %#v", c.UniqueID)
	}

	return res, nil
}

// Configures a canned response for the given interaction UniqueID.
func SetResponse(uniqueID string, res *Response) {
	res.Noninteractive = true
	responses[uniqueID] = res
}