| index 275cf7436..bff9a5e13 100644 |
| --- a/internal/grouprollaws/group.go |
| +++ b/internal/grouprollaws/group.go |
| @@ -36,13 +36,22 @@ var _ grouproll.Caller = (*Adapter)(nil) |
| // Adapter is the AWS side of grouproll.Group: the script's AWS.request for |
| // the group, target, hook, session-online, activity, membership, instance, |
| // template and write operations. |
| +// |
| +// The Auto Scaling, ELB, EC2 and SSM operations are held as method values |
| +// (the *Ops structs below), never as the SDK clients. The Adapter is |
| +// converted to interfaces, so every type reachable from its fields counts |
| +// as used in an interface, and the program reflects on methods elsewhere: |
| +// the linker then keeps every exported method of such a type. Holding the |
| +// four clients kept every one of their operations (EC2 alone has about |
| +// 800) and took the linux/amd64 release binary from 70 MB to 108 MB, past |
| +// execsandbox.BinaryLimit (96 MiB). |
| type Adapter struct { |
| c grouproll.Config |
| cfg aws.Config |
| - autoscaling *autoscaling.Client |
| - elb *elbv2.Client |
| - ec2 *ec2.Client |
| - ssm *ssm.Client |
| + autoscaling autoscalingOps |
| + elb elbOps |
| + ec2 ec2Ops |
| + ssm ssmOps |
| sts *sts.Client |
| s3 *s3.Client // objects.go: edges files, locks, release pointers |
| plugin pluginCheck // session.go: the plugin's path and version, once |
| @@ -59,15 +68,76 @@ func newAdapter(cfg aws.Config, c grouproll.Config) *Adapter { |
| return &Adapter{ |
| c: c, |
| cfg: cfg, |
| - autoscaling: autoscaling.NewFromConfig(cfg, func(o *autoscaling.Options) { o.BaseEndpoint = nil }), |
| - elb: elbv2.NewFromConfig(cfg, func(o *elbv2.Options) { o.BaseEndpoint = nil }), |
| - ec2: ec2.NewFromConfig(cfg, func(o *ec2.Options) { o.BaseEndpoint = nil }), |
| - ssm: ssm.NewFromConfig(cfg, func(o *ssm.Options) { o.BaseEndpoint = nil }), |
| + autoscaling: newAutoscalingOps(autoscaling.NewFromConfig(cfg, func(o *autoscaling.Options) { o.BaseEndpoint = nil })), |
| + elb: newELBOps(elbv2.NewFromConfig(cfg, func(o *elbv2.Options) { o.BaseEndpoint = nil })), |
| + ec2: newEC2Ops(ec2.NewFromConfig(cfg, func(o *ec2.Options) { o.BaseEndpoint = nil })), |
| + ssm: newSSMOps(ssm.NewFromConfig(cfg, func(o *ssm.Options) { o.BaseEndpoint = nil })), |
| sts: sts.NewFromConfig(cfg, func(o *sts.Options) { o.BaseEndpoint = nil }), |
| s3: newS3(cfg), |
| } |
| } |
| |
| +// The operations the adapter calls, one method value each (see Adapter). |
| +// Options is the client's configuration, for the plugin's endpoint and the |
| +// transport tests. |
| +type autoscalingOps struct { |
| + DescribeAutoScalingGroups func(context.Context, *autoscaling.DescribeAutoScalingGroupsInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingGroupsOutput, error) |
| + DescribeLifecycleHooks func(context.Context, *autoscaling.DescribeLifecycleHooksInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeLifecycleHooksOutput, error) |
| + DescribeScalingActivities func(context.Context, *autoscaling.DescribeScalingActivitiesInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeScalingActivitiesOutput, error) |
| + DescribeAutoScalingInstances func(context.Context, *autoscaling.DescribeAutoScalingInstancesInput, ...func(*autoscaling.Options)) (*autoscaling.DescribeAutoScalingInstancesOutput, error) |
| + UpdateAutoScalingGroup func(context.Context, *autoscaling.UpdateAutoScalingGroupInput, ...func(*autoscaling.Options)) (*autoscaling.UpdateAutoScalingGroupOutput, error) |
| + EnterStandby func(context.Context, *autoscaling.EnterStandbyInput, ...func(*autoscaling.Options)) (*autoscaling.EnterStandbyOutput, error) |
| + ExitStandby func(context.Context, *autoscaling.ExitStandbyInput, ...func(*autoscaling.Options)) (*autoscaling.ExitStandbyOutput, error) |
| + TerminateInstanceInAutoScalingGroup func(context.Context, *autoscaling.TerminateInstanceInAutoScalingGroupInput, ...func(*autoscaling.Options)) (*autoscaling.TerminateInstanceInAutoScalingGroupOutput, error) |
| + Options func() autoscaling.Options |
| +} |
| + |
| +func newAutoscalingOps(c *autoscaling.Client) autoscalingOps { |
| + return autoscalingOps{ |
| + DescribeAutoScalingGroups: c.DescribeAutoScalingGroups, |
| + DescribeLifecycleHooks: c.DescribeLifecycleHooks, |
| + DescribeScalingActivities: c.DescribeScalingActivities, |
| + DescribeAutoScalingInstances: c.DescribeAutoScalingInstances, |
| + UpdateAutoScalingGroup: c.UpdateAutoScalingGroup, |
| + EnterStandby: c.EnterStandby, |
| + ExitStandby: c.ExitStandby, |
| + TerminateInstanceInAutoScalingGroup: c.TerminateInstanceInAutoScalingGroup, |
| + Options: c.Options, |
| + } |
| +} |
| + |
| +type elbOps struct { |
| + DescribeTargetHealth func(context.Context, *elbv2.DescribeTargetHealthInput, ...func(*elbv2.Options)) (*elbv2.DescribeTargetHealthOutput, error) |
| + Options func() elbv2.Options |
| +} |
| + |
| +func newELBOps(c *elbv2.Client) elbOps { |
| + return elbOps{DescribeTargetHealth: c.DescribeTargetHealth, Options: c.Options} |
| +} |
| + |
| +type ec2Ops struct { |
| + DescribeInstances func(context.Context, *ec2.DescribeInstancesInput, ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error) |
| + DescribeLaunchTemplateVersions func(context.Context, *ec2.DescribeLaunchTemplateVersionsInput, ...func(*ec2.Options)) (*ec2.DescribeLaunchTemplateVersionsOutput, error) |
| + Options func() ec2.Options |
| +} |
| + |
| +func newEC2Ops(c *ec2.Client) ec2Ops { |
| + return ec2Ops{DescribeInstances: c.DescribeInstances, |
| + DescribeLaunchTemplateVersions: c.DescribeLaunchTemplateVersions, Options: c.Options} |
| +} |
| + |
| +type ssmOps struct { |
| + DescribeInstanceInformation func(context.Context, *ssm.DescribeInstanceInformationInput, ...func(*ssm.Options)) (*ssm.DescribeInstanceInformationOutput, error) |
| + StartSession func(context.Context, *ssm.StartSessionInput, ...func(*ssm.Options)) (*ssm.StartSessionOutput, error) |
| + TerminateSession func(context.Context, *ssm.TerminateSessionInput, ...func(*ssm.Options)) (*ssm.TerminateSessionOutput, error) |
| + Options func() ssm.Options |
| +} |
| + |
| +func newSSMOps(c *ssm.Client) ssmOps { |
| + return ssmOps{DescribeInstanceInformation: c.DescribeInstanceInformation, StartSession: c.StartSession, |
| + TerminateSession: c.TerminateSession, Options: c.Options} |
| +} |
| + |
| // call runs one provider call under the script's 15-second process bound |
| // and turns every failure into Uncertain(api), as the script's invoke does: |
| // a call past the bound or a stalled read is Uncertain{Timeout: true}, an |