Skip to content

Commit 277d1be

Browse files
committed
Playing with comments
Just some copyediting.
1 parent 56adb91 commit 277d1be

File tree

8 files changed

+49
-66
lines changed

8 files changed

+49
-66
lines changed

internal/awsconfig/awsconfig.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Package awsconfig generates AWS client configurations optimized for use by
2-
// the randomizer.
1+
// Package awsconfig provides a randomizer-optimized AWS SDK configuration.
32
package awsconfig
43

54
import (
@@ -37,10 +36,9 @@ type Option = func(*config.LoadOptions) error
3736
func New(ctx context.Context) (aws.Config, error) {
3837
transport := http.DefaultTransport
3938

40-
// This option is recommended in AWS Lambda deployments due to the
41-
// significant reduction in cold start latency (see getEmbeddedCertPool).
42-
// It can be enabled for standard server deployments if desired, but is far
43-
// less beneficial.
39+
// This option is recommended in AWS Lambda to significantly reduce cold
40+
// start latency (see [getEmbeddedCertTransport]). It can be enabled for
41+
// standard server deployments if desired, but is far less beneficial.
4442
if os.Getenv("AWS_CLIENT_EMBEDDED_TLS_ROOTS") == "1" {
4543
transport = getEmbeddedCertTransport()
4644
}
@@ -60,10 +58,9 @@ func New(ctx context.Context) (aws.Config, error) {
6058
return aws.Config{}, fmt.Errorf("loading AWS config: %w", err)
6159
}
6260

63-
// WARNING: X-Ray tracing will panic if the context passed to AWS operations
64-
// is not already associated with an open X-Ray segment. That means that as of
65-
// this writing this option is only safe to use on AWS Lambda. Standard server
66-
// deployments should avoid setting it.
61+
// NOTE: X-Ray tracing panics if the context for an AWS call is not already
62+
// associated with an open X-Ray segment. As of writing, this option is only
63+
// safe to use on AWS Lambda. Standard server deployments should avoid it.
6764
if useXRay := os.Getenv("AWS_CLIENT_XRAY_TRACING"); useXRay == "1" {
6865
xrayawsv2.AWSV2Instrumentor(&cfg.APIOptions)
6966
}
@@ -75,12 +72,11 @@ func New(ctx context.Context) (aws.Config, error) {
7572
// CAs operated by Amazon Trust Services, which all AWS service endpoints chain
7673
// from.
7774
//
78-
// When the randomizer runs on AWS Lambda in the recommended configuration, this
79-
// limited set of roots is so much cheaper to parse than a typical set of system
80-
// roots that it cuts cold start invocation time roughly in half (by around
81-
// 500ms). This is a large enough difference for a human to notice, and accounts
82-
// for about 15% of the 3 second response time limit that Slack imposes on slash
83-
// commands.
75+
// When the randomizer runs on AWS Lambda with recommended resource settings,
76+
// this limited set of roots is substantially cheaper to parse than a typical
77+
// root store, which removes ~500ms of cold-start response latency. That's
78+
// large enough for a human to notice, and accounts for ~15% of the 3-second
79+
// response time limit Slack imposes on slash commands.
8480
var getEmbeddedCertTransport = sync.OnceValue(func() *http.Transport {
8581
transport := http.DefaultTransport.(*http.Transport).Clone()
8682
transport.TLSClientConfig = &tls.Config{RootCAs: loadEmbeddedCertPool()}

internal/randomizer/app.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import (
55
"math/rand/v2"
66
)
77

8-
// Store represents an object that provides persistence for "groups" of
9-
// options.
8+
// Store enables persistence for named groups of options.
109
type Store interface {
1110
// List returns the names of all available groups. If no groups have been
1211
// saved, it returns an empty list with a nil error.
@@ -20,20 +19,18 @@ type Store interface {
2019
// group with that name.
2120
Put(ctx context.Context, group string, options []string) error
2221

23-
// Delete ensures that the named group no longer exists, returning true or
24-
// false to indicate whether the group existed prior to this deletion
25-
// attempt.
26-
Delete(ctx context.Context, group string) (bool, error)
22+
// Delete ensures that the named group no longer exists, and indicates
23+
// whether the group existed prior to this deletion attempt.
24+
Delete(ctx context.Context, group string) (existed bool, err error)
2725
}
2826

29-
// App represents a randomizer app that can accept commands.
27+
// App represents a randomizer instance that can accept commands.
3028
type App struct {
3129
name string
3230
store Store
3331
shuffle func([]string) // Overridden in tests for predictable behavior
3432
}
3533

36-
// NewApp returns an App.
3734
func NewApp(name string, store Store) App {
3835
return App{
3936
name: name,
@@ -48,11 +45,10 @@ func shuffle(options []string) {
4845
})
4946
}
5047

51-
// Main is the entrypoint to the randomizer tool.
48+
// Main is the entrypoint to the randomizer.
5249
//
53-
// Note that all errors returned from this function will be of this package's
54-
// Error type. This provides the HelpText method for user-friendly output
55-
// formatting.
50+
// All errors returned from Main are of type [Error], and support
51+
// [Error.HelpText] for user-friendly formatting.
5652
func (a App) Main(ctx context.Context, args []string) (Result, error) {
5753
request, err := a.newRequest(ctx, args)
5854
if err != nil {

internal/randomizer/app_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,10 @@ func isResult(expectedType ResultType, contains ...string) validator {
260260
message := res.Message()
261261
for _, c := range contains {
262262
i := strings.Index(message, c)
263-
264263
if i < 0 {
265264
t.Errorf("result missing %q in expected position\n%v", c, res.Message())
266265
continue
267266
}
268-
269267
message = message[i+len(c):]
270268
}
271269
}
@@ -276,14 +274,9 @@ func isError(contains string) validator {
276274
if err == nil {
277275
t.Fatalf("unexpected result %v", res)
278276
}
279-
280-
if _, ok := err.(Error); !ok {
281-
t.Fatalf("unexpected error type %T", err)
282-
}
283-
284-
rerr := err.(Error)
285-
286-
if !strings.Contains(rerr.HelpText(), contains) {
277+
if rerr, ok := err.(Error); !ok {
278+
t.Errorf("unexpected error type %T", err)
279+
} else if !strings.Contains(rerr.HelpText(), contains) {
287280
t.Errorf("error help text missing substring %q", contains)
288281
}
289282
}

internal/randomizer/request.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@ func (a App) newRequest(ctx context.Context, args []string) (req request, err er
3232
}
3333

3434
func parseArgs(args []string) (op operation, operand string, opargs []string, err error) {
35-
// We accept the standard flag syntax for help, but strongly expect that users
36-
// won't know that syntax in advance. Logic elsewhere in the randomizer
37-
// prevents the use of "help" as a group name to avoid conflicts with this
38-
// special case.
35+
// We accept the standard flag syntax for help, but expect that users won't
36+
// know that syntax in advance. Logic elsewhere in the randomizer blocks
37+
// using "help" as a group name to avoid conflicts with this special case.
3938
if len(args) == 0 || args[0] == "/help" || len(args) == 1 && args[0] == "help" {
4039
return showHelp, "", args, nil
4140
}
4241

4342
switch args[0] {
44-
// Arguments without an explicitly known flag always trigger a randomization,
45-
// even if the first argument starts with a slash, simply because it's less
46-
// work to implement and unlikely to cause big problems in practice. Logic
47-
// elsewhere in the randomizer prevents the use of flag-like group names, so
48-
// that new flags can't make existing groups inaccessible.
43+
// Arguments without an explicitly known flag trigger randomization, even if
44+
// the first argument starts with a slash, because it's easier to implement
45+
// and unlikely to cause problems in practice. Logic elsewhere in the
46+
// randomizer blocks using flag-like group names, so new flags can't make
47+
// existing groups inaccessible.
4948
default:
5049
return makeSelection, "", args, nil
5150

internal/randomizer/rndtest/rndtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
// Store implements randomizer.Store by mapping group names to sorted lists of
12-
// strings. A nil Store will return errors for every operation.
12+
// strings. A nil Store returns errors for every operation.
1313
type Store map[string][]string
1414

1515
// Clone returns a deep copy of the original store.

internal/slack/slack.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import (
1313
"github.com/featherbread/randomizer/internal/randomizer"
1414
)
1515

16-
// App provides HTTP handling logic that allows the randomizer to be integrated
17-
// as a slash command in a Slack workspace.
16+
// App serves the randomizer through the Slack slash command API.
1817
//
19-
// Note that App currently only supports static verification tokens to check
20-
// that a request legitimately originated from Slack, and does not support the
21-
// newer signed secrets functionality.
18+
// App supports legacy static verification tokens to confirm the legitimacy of
19+
// requests from Slack; it does not support the newer signed secrets strategy.
20+
//
21+
// App supports only HTTP POST requests; it does not support the GET requests
22+
// allowed by the deprecated legacy slash command integration.
2223
type App struct {
2324
// TokenProvider provides the expected value of the slash command verification
2425
// token generated by Slack. This can be obtained from the slash command
@@ -27,13 +28,11 @@ type App struct {
2728
// StoreFactory provides a Store for the Slack channel in which the request
2829
// was made.
2930
StoreFactory func(partition string) randomizer.Store
30-
// Logger, if non-nil, will be used to report information about errors that
31-
// occur while handling each request.
31+
// Logger, if non-nil, logs errors encountered during request handling.
3232
Logger *slog.Logger
3333
}
3434

35-
// ServeHTTP handles the POST request that Slack makes to invoke the randomizer
36-
// slash command.
35+
// ServeHTTP serves POST requests from Slack.
3736
func (a App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
3837
if r.Method != http.MethodPost {
3938
w.Header().Add("Allow", http.MethodPost)

internal/slack/token.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ import (
1616

1717
const DefaultAWSParameterTTL = 2 * time.Minute
1818

19-
// TokenProvider provides the value of the slash command verification token
20-
// generated by Slack.
19+
// TokenProvider provides the expected value of the slash command verification
20+
// token that Slack includes in its requests.
2121
type TokenProvider func(ctx context.Context) (string, error)
2222

2323
// TokenProviderFromEnv returns a TokenProvider based on available environment
2424
// variables.
2525
//
26-
// If SLACK_TOKEN is set, it will return a static token provider.
26+
// If SLACK_TOKEN is set, it returns a static token provider.
2727
//
28-
// If SLACK_TOKEN_SSM_NAME is set, it will return an AWS SSM token provider,
28+
// If SLACK_TOKEN_SSM_NAME is set, it returns an AWS SSM token provider,
2929
// with the TTL optionally set by SLACK_TOKEN_SSM_TTL.
3030
//
31-
// Otherwise, it will return an error.
31+
// Otherwise, it returns an error.
3232
func TokenProviderFromEnv() (TokenProvider, error) {
3333
if token, ok := os.LookupEnv("SLACK_TOKEN"); ok {
3434
return StaticToken(token), nil

internal/store/registry/registry.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ var Registry = map[string]Entry{}
1515

1616
// Entry represents a single store backend.
1717
type Entry struct {
18-
// EnvironmentKeys is the list of environment variables that this store's
19-
// factory checks for configuration. If any one of these keys is set in the
20-
// environment (and no conflicting keys are set), this store will be selected
21-
// as the backend for this randomizer instance.
18+
// EnvironmentKeys lists the names of environment variables that this store's
19+
// factory checks for configuration. If the environment contains any of these
20+
// keys, and contains no keys for other factories, the randomizer selects this
21+
// store as its backend.
2222
EnvironmentKeys []string
2323

2424
// FactoryFromEnv creates a factory for this backend based on its environment

0 commit comments

Comments
 (0)