This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rejection.go
81 lines (65 loc) · 1.77 KB
/
rejection.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package sshserver
import (
"fmt"
"github.com/containerssh/log"
"golang.org/x/crypto/ssh"
)
//region Factories
// NewChannelRejection constructs a Message that rejects a channel.
//
// - Reason is the SSH rejection reason.
// - Code is an error code allowing an administrator to identify the error that happened.
// - UserMessage is the message that can be printed to the user if needed.
// - Explanation is the explanation string to the system administrator. This is an fmt.Sprintf-compatible string
// - Args are the arguments to Explanation to create a formatted message. It is recommended that these arguments also
// be added as labels to allow system administrators to index the error properly.
func NewChannelRejection(
Reason ssh.RejectionReason,
Code string,
UserMessage string,
Explanation string,
Args ...interface{},
) ChannelRejection {
return &message{
reason: Reason,
code: Code,
userMessage: UserMessage,
explanation: fmt.Sprintf(Explanation, Args...),
labels: map[log.LabelName]log.LabelValue{},
}
}
//endregion
//region Message implementation
type message struct {
code string
userMessage string
explanation string
labels log.Labels
reason ssh.RejectionReason
}
func (m *message) Reason() ssh.RejectionReason {
return m.reason
}
func (m *message) Code() string {
return m.code
}
func (m *message) UserMessage() string {
return m.userMessage
}
func (m *message) Explanation() string {
return m.explanation
}
func (m *message) Labels() log.Labels {
return m.labels
}
func (m *message) String() string {
return m.userMessage
}
func (m *message) Label(name log.LabelName, value log.LabelValue) log.Message {
m.labels[name] = value
return m
}
func (m *message) Error() string {
return m.explanation
}
//endregion