@@ -27,9 +27,10 @@ const (
27
27
type State uint8
28
28
29
29
/*
30
- /---> StateExpired
31
- StateReserved ---> StateCreated ---
32
- \---> StateRevoked
30
+
31
+ --> ------------------\ /---> StateExpired
32
+ --> StateReserved ---> StateCreated ---
33
+ \---> StateRevoked
33
34
*/
34
35
35
36
const (
@@ -102,7 +103,12 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
102
103
created , expiry time.Time , serverAddr string , devServer bool ,
103
104
perms []bakery.Op , caveats []macaroon.Caveat ,
104
105
featureConfig FeaturesConfig , privacy bool , linkedGroupID * ID ,
105
- flags PrivacyFlags ) (* Session , error ) {
106
+ flags PrivacyFlags , options ... Option ) (* Session , error ) {
107
+
108
+ opts := defaultSessionOptions ()
109
+ for _ , o := range options {
110
+ o (opts )
111
+ }
106
112
107
113
_ , pairingSecret , err := mailbox .NewPassphraseEntropy ()
108
114
if err != nil {
@@ -139,6 +145,10 @@ func buildSession(id ID, localPrivKey *btcec.PrivateKey, label string, typ Type,
139
145
GroupID : groupID ,
140
146
}
141
147
148
+ if opts .immediateActivation {
149
+ sess .State = StateCreated
150
+ }
151
+
142
152
if perms != nil || caveats != nil {
143
153
sess .MacaroonRecipe = & MacaroonRecipe {
144
154
Permissions : perms ,
@@ -163,6 +173,34 @@ type IDToGroupIndex interface {
163
173
GetSessionIDs (groupID ID ) ([]ID , error )
164
174
}
165
175
176
+ // sessionOptions defines various options that can be tweaked via functional
177
+ // parameters for session creation.
178
+ type sessionOptions struct {
179
+ // immediateActivation can be used to immediately move a session to
180
+ // the StateCreated state on creation.
181
+ immediateActivation bool
182
+ }
183
+
184
+ // defaultSessionOptions returns a new sessionOptions struct with default
185
+ // values set.
186
+ func defaultSessionOptions () * sessionOptions {
187
+ return & sessionOptions {
188
+ immediateActivation : false ,
189
+ }
190
+ }
191
+
192
+ // Option defines the signature of a functional option that can be used to
193
+ // tweak various session creation options.
194
+ type Option func (* sessionOptions )
195
+
196
+ // WithImmediateActivation can be used to immediately move a session to the
197
+ // StateCreated state on creation.
198
+ func WithImmediateActivation () Option {
199
+ return func (o * sessionOptions ) {
200
+ o .immediateActivation = true
201
+ }
202
+ }
203
+
166
204
// Store is the interface a persistent storage must implement for storing and
167
205
// retrieving Terminal Connect sessions.
168
206
type Store interface {
@@ -172,7 +210,7 @@ type Store interface {
172
210
NewSession (label string , typ Type , expiry time.Time , serverAddr string ,
173
211
devServer bool , perms []bakery.Op , caveats []macaroon.Caveat ,
174
212
featureConfig FeaturesConfig , privacy bool , linkedGroupID * ID ,
175
- flags PrivacyFlags ) (* Session , error )
213
+ flags PrivacyFlags , opts ... Option ) (* Session , error )
176
214
177
215
// CreateSession moves the given session from the StateReserved state to
178
216
// the StateCreated state.
0 commit comments