presidium 0.15.35 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AutoScaling.js ADDED
@@ -0,0 +1,117 @@
1
+ const rubico = require('rubico')
2
+ const AWSAutoscaling = require('aws-sdk/clients/autoscaling')
3
+ const AWSAutoScalingDescribeAutoScalingGroupsFilters =
4
+ require('./internal/AWSAutoScalingDescribeAutoScalingGroupsFilters')
5
+ const filterExistsAndNotEmpty = require('./internal/filterExistsAndNotEmpty')
6
+ const filterExists = require('./internal/filterExists')
7
+
8
+ const {
9
+ pipe, tap,
10
+ switchCase, tryCatch,
11
+ fork, assign, get, set, pick, omit,
12
+ map, filter, reduce, transform, flatMap,
13
+ and, or, not, any, all,
14
+ eq, gt, lt, gte, lte,
15
+ thunkify, always,
16
+ curry, __,
17
+ } = rubico
18
+
19
+ /**
20
+ * @name AutoScaling
21
+ *
22
+ * @synopsis
23
+ * ```coffeescript [specscript]
24
+ * new AutoScaling(options {
25
+ * ...({
26
+ * accessKeyId: string,
27
+ * secretAccessKey: string,
28
+ * region: string,
29
+ * })|({
30
+ * endpoint: string,
31
+ * region: string,
32
+ * })
33
+ * }) -> AutoScaling object
34
+ * ```
35
+ */
36
+ const AutoScaling = function (options) {
37
+ this.awsAutoScaling = new AWSAutoscaling({
38
+ apiVersion: '2011-01-01',
39
+ ...pick([
40
+ 'accessKeyId',
41
+ 'secretAccessKey',
42
+ 'region',
43
+ 'endpoint',
44
+ ])(options),
45
+ })
46
+ return this
47
+ }
48
+
49
+ /**
50
+ * @name AutoScaling.prototype.listAutoScalingGroups
51
+ *
52
+ * @synopsis
53
+ * ```coffeescript [specscript]
54
+ * import AutoScalingListGroupsDescribeFilterOptions
55
+ * from './internal/AutoScalingListGroupsDescribeFilterOptions.ss'
56
+ *
57
+ * new AutoScaling(...).listAutoScalingGroups(options? {
58
+ * ...AutoScalingListGroupsDescribeFilterOptions.map(value => value|Array<value>),
59
+ * limit?: 5-100, // default 100
60
+ * nextToken?: string, // last result's NextToken
61
+ * }) -> Promise<{
62
+ * AutoScalingGroups: Array<{
63
+ * AutoScalingGroupName: string, // 'presidium-test'
64
+ * AutoScalingGroupARN: string, // 'arn:aws:autoscaling:us-west-1:095798571722:autoScalingGroup:934690c8-d95d-46be-ac49-54950de41ef5:autoScalingGroupName/presidium-test'
65
+ * LaunchTemplate: Object,
66
+ * MinSize: number, // 1
67
+ * MaxSize: number, // 1
68
+ * DesiredCapacity: number, // 1
69
+ * DefaultCooldown: number, // 300
70
+ * AvailabilityZones: Array,
71
+ * LoadBalancerNames: Array,
72
+ * TargetGroupARNs: Array,
73
+ * HealthCheckType: string, // 'EC2'
74
+ * HealthCheckGracePeriod: number, // 300
75
+ * Instances: Array,
76
+ * CreatedTime: Date, // 2022-04-28T20:26:13.289Z
77
+ * SuspendedProcesses: Array,
78
+ * VPCZoneIdentifier: string, // 'subnet-916bb8f7,subnet-677c933d'
79
+ * EnabledMetrics: Array,
80
+ * Tags: Array,
81
+ * TerminationPolicies: Array,
82
+ * NewInstancesProtectedFromScaleIn: boolean,
83
+ * ServiceLinkedRoleARN: string, // 'arn:aws:iam::095798571722:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling'
84
+ * }>,
85
+ * NextToken: string|null,
86
+ * }>
87
+ * ```
88
+ */
89
+ AutoScaling.prototype.listAutoScalingGroups = function (options = {}) {
90
+ return this.awsAutoScaling.describeAutoScalingGroups(filterExistsAndNotEmpty({
91
+ Filters: AWSAutoScalingDescribeAutoScalingGroupsFilters(options),
92
+ MaxRecords: options.limit ?? 100,
93
+ NextToken: options.nextToken,
94
+ })).promise()
95
+ }
96
+
97
+ /**
98
+ * @name AutoScaling.prototype.setDesiredCapacity
99
+ *
100
+ * @synopsis
101
+ * ```coffeescript [specscript]
102
+ * new AutoScaling(...).setDesiredCapacity(options {
103
+ * autoScalingGroupName: string,
104
+ * desiredCapacity: number,
105
+ * honorCooldown?: boolean, // whether Amazon EC2 Auto Scaling waits for the cooldown period to complete before initializing a scaling activity to set your Auto Scaling group to its new capacity, default false
106
+ * }) -> Promise<{}>
107
+ * ```
108
+ */
109
+ AutoScaling.prototype.setDesiredCapacity = function (options) {
110
+ return this.awsAutoScaling.setDesiredCapacity(filterExists({
111
+ AutoScalingGroupName: options.autoScalingGroupName,
112
+ DesiredCapacity: options.desiredCapacity,
113
+ HonorCooldown: options.honorCooldown,
114
+ })).promise()
115
+ }
116
+
117
+ module.exports = AutoScaling
@@ -0,0 +1,57 @@
1
+ const Test = require('thunk-test')
2
+ const assert = require('assert')
3
+ const AwsCredentials = require('./internal/AwsCredentials')
4
+ const AutoScaling = require('./AutoScaling')
5
+
6
+ const test = new Test('AutoScaling', async function () {
7
+ const awsCreds = await AwsCredentials('default').catch(error => {
8
+ if (error.code == 'ENOENT') {
9
+ const accessKeyId = process.env.AWS_ACCESS_KEY_ID
10
+ const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
11
+ if (accessKeyId == null || secretAccessKey == null) {
12
+ throw new Error('No AWS credential file or environment variables')
13
+ }
14
+ return { accessKeyId, secretAccessKey }
15
+ }
16
+ throw error
17
+ })
18
+ awsCreds.region = 'us-west-1'
19
+
20
+ const autoScaling = new AutoScaling({
21
+ ...awsCreds,
22
+ })
23
+
24
+ // there is one auto scaling group named presidium-test with one ec2 instance in this region
25
+
26
+ { // listInstances all instances
27
+ const response = await autoScaling.listAutoScalingGroups()
28
+ assert(
29
+ response.AutoScalingGroups.map(group => group.AutoScalingGroupName).includes('presidium-test'),
30
+ 'There is no presidium-test autoscaling group, check the aws account'
31
+ )
32
+ assert.equal(response.NextToken, null)
33
+ }
34
+
35
+ { // listAutoScalingGroups with tag
36
+ const response = await autoScaling.listAutoScalingGroups({
37
+ 'tag:Env': 'test',
38
+ })
39
+ assert(
40
+ response.AutoScalingGroups.map(group => group.AutoScalingGroupName).includes('presidium-test'),
41
+ 'There is no presidium-test autoscaling group, check the aws account'
42
+ )
43
+ assert.equal(response.NextToken, null)
44
+ }
45
+
46
+ // setDesiredCapacity (errors if not auto scaling group not found)
47
+ await autoScaling.setDesiredCapacity({
48
+ autoScalingGroupName: 'presidium-test',
49
+ desiredCapacity: 1,
50
+ })
51
+ }).case()
52
+
53
+ if (process.argv[1] == __filename) {
54
+ test()
55
+ }
56
+
57
+ module.exports = test
package/Docker.js CHANGED
@@ -1136,6 +1136,18 @@ Docker.prototype.updateService = function dockerUpdateService(service, options)
1136
1136
  })
1137
1137
  }
1138
1138
 
1139
+ /**
1140
+ * @name Docker.prototype.deleteService
1141
+ *
1142
+ * @synopsis
1143
+ * ```coffeescript [specscript]
1144
+ * new Docker().deleteService(id string) -> Promise<HttpResponse>
1145
+ * ```
1146
+ */
1147
+ Docker.prototype.deleteService = function deleteService(id) {
1148
+ return this.http.delete(`/services/${id}`)
1149
+ }
1150
+
1139
1151
  /**
1140
1152
  * @name Docker.prototype.listServices
1141
1153
  *
@@ -1189,6 +1201,23 @@ Docker.prototype.getServiceLogs = async function getServiceLogs(serviceId, optio
1189
1201
  }`)
1190
1202
  }
1191
1203
 
1204
+ /**
1205
+ * @name Docker.prototype.listTasks
1206
+ *
1207
+ * @synopsis
1208
+ * ```coffeescript [specscript]
1209
+ * new Docker().listTasks(options {
1210
+ * service?: string,
1211
+ * node?: string,
1212
+ * }) -> Promise<HttpResponse>
1213
+ * ```
1214
+ */
1215
+ Docker.prototype.listTasks = async function listTasks(options) {
1216
+ return this.http.get(`/tasks?${
1217
+ querystring.stringify(pick(['service', 'node'])(options))
1218
+ }`)
1219
+ }
1220
+
1192
1221
  /**
1193
1222
  * @name Docker.prototype.pruneImages
1194
1223
  *