@jcoreio/aws-ecr-utils 1.3.0 → 2.0.0
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/checkECRImageAccess.d.ts +4 -4
- package/checkECRImageAccess.js +38 -29
- package/checkECRImageAccess.mjs +22 -16
- package/checkECRRepositoryPolicy.d.ts +3 -3
- package/checkECRRepositoryPolicy.js +9 -9
- package/checkECRRepositoryPolicy.mjs +8 -6
- package/copyECRImage.d.ts +5 -5
- package/ecrImageExists.d.ts +3 -3
- package/ecrImageExists.js +4 -4
- package/ecrImageExists.mjs +4 -4
- package/formatECRImageUri.d.ts +3 -3
- package/formatECRRepositoryHostname.d.ts +2 -2
- package/loginToECR.d.ts +3 -6
- package/loginToECR.js +9 -7
- package/loginToECR.mjs +5 -3
- package/package.json +4 -3
- package/parseECRImageUri.d.ts +2 -3
- package/parseECRRepositoryHostname.d.ts +2 -3
- package/tagECRImage.d.ts +3 -3
- package/tagECRImage.js +6 -6
- package/tagECRImage.mjs +6 -6
- package/upsertECRRepository.d.ts +4 -4
- package/upsertECRRepository.js +14 -12
- package/upsertECRRepository.mjs +8 -6
- package/copyECRImage.js.flow +0 -14
- package/copyECRImage.mjs.flow +0 -14
- package/ecrImageExists.js.flow +0 -10
- package/ecrImageExists.mjs.flow +0 -10
- package/index.js.flow +0 -8
- package/index.mjs.flow +0 -8
- package/loginToECR.js.flow +0 -6
- package/loginToECR.mjs.flow +0 -6
- package/parseECRImageUri.js.flow +0 -8
- package/parseECRImageUri.mjs.flow +0 -8
- package/tagECRImage.js.flow +0 -8
- package/tagECRImage.mjs.flow +0 -8
- package/upsertECRRepository.js.flow +0 -7
- package/upsertECRRepository.mjs.flow +0 -7
package/checkECRImageAccess.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECRClient, ECRClientConfig } from '@aws-sdk/client-ecr';
|
|
2
2
|
export default function checkECRImageAccess({ ecr, awsConfig, repoAccountAwsConfig, imageUri, log, }: {
|
|
3
|
-
ecr?:
|
|
4
|
-
awsConfig?:
|
|
3
|
+
ecr?: ECRClient;
|
|
4
|
+
awsConfig?: ECRClientConfig;
|
|
5
5
|
/**
|
|
6
6
|
* Config for the AWS account containing the ECR repository.
|
|
7
7
|
* Optional; if given, will prompt to add/update the policy on the
|
|
8
8
|
* ECR repository, if access checks failed and the terminal is
|
|
9
9
|
* interactive.
|
|
10
10
|
*/
|
|
11
|
-
repoAccountAwsConfig?:
|
|
11
|
+
repoAccountAwsConfig?: ECRClientConfig;
|
|
12
12
|
imageUri: string;
|
|
13
13
|
log?: {
|
|
14
14
|
info: (...args: any[]) => void;
|
package/checkECRImageAccess.js
CHANGED
|
@@ -10,7 +10,8 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
var
|
|
13
|
+
var _clientEcr = require("@aws-sdk/client-ecr");
|
|
14
|
+
var _clientSts = require("@aws-sdk/client-sts");
|
|
14
15
|
var _parseECRImageUri2 = _interopRequireDefault(require("./parseECRImageUri.js"));
|
|
15
16
|
var _ImageManifestSchema = require("./ImageManifestSchema.js");
|
|
16
17
|
var _isInteractive = _interopRequireDefault(require("is-interactive"));
|
|
@@ -23,31 +24,31 @@ function checkECRImageAccess(_x) {
|
|
|
23
24
|
}
|
|
24
25
|
function _checkECRImageAccess() {
|
|
25
26
|
_checkECRImageAccess = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
26
|
-
var ecr, awsConfig, repoAccountAwsConfig, imageUri, _ref$log, log, _parseECRImageUri, registryId, region, repositoryName, imageTag, _yield$ecr$
|
|
27
|
+
var ecr, awsConfig, repoAccountAwsConfig, imageUri, _ref$log, log, _parseECRImageUri, registryId, region, repositoryName, imageTag, _yield$ecr$send, _yield$ecr$send$image, _yield$ecr$send$image2, _yield$ecr$send$image3, image, imageManifest, _ImageManifestSchema$, config, layers, Action, _yield$STSClient$send, Account, _yield$inquirer$promp, update, srcEcr, _yield$srcEcr$send$ca, policyText, policy;
|
|
27
28
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
28
29
|
while (1) switch (_context.prev = _context.next) {
|
|
29
30
|
case 0:
|
|
30
31
|
ecr = _ref.ecr, awsConfig = _ref.awsConfig, repoAccountAwsConfig = _ref.repoAccountAwsConfig, imageUri = _ref.imageUri, _ref$log = _ref.log, log = _ref$log === void 0 ? console : _ref$log;
|
|
31
32
|
log.error('checking access to ECR image:', imageUri, '...');
|
|
32
33
|
_parseECRImageUri = (0, _parseECRImageUri2["default"])(imageUri), registryId = _parseECRImageUri.registryId, region = _parseECRImageUri.region, repositoryName = _parseECRImageUri.repositoryName, imageTag = _parseECRImageUri.imageTag;
|
|
33
|
-
if (!ecr) ecr = new
|
|
34
|
+
if (!ecr) ecr = new _clientEcr.ECRClient(_objectSpread(_objectSpread({}, awsConfig), {}, {
|
|
34
35
|
region: region
|
|
35
36
|
}));
|
|
36
37
|
_context.prev = 4;
|
|
37
38
|
_context.next = 7;
|
|
38
|
-
return ecr.
|
|
39
|
+
return ecr.send(new _clientEcr.BatchGetImageCommand({
|
|
39
40
|
registryId: registryId,
|
|
40
41
|
repositoryName: repositoryName,
|
|
41
42
|
imageIds: [{
|
|
42
43
|
imageTag: imageTag
|
|
43
44
|
}]
|
|
44
|
-
})
|
|
45
|
+
}));
|
|
45
46
|
case 7:
|
|
46
|
-
_yield$ecr$
|
|
47
|
-
_yield$ecr$
|
|
48
|
-
_yield$ecr$
|
|
49
|
-
_yield$ecr$
|
|
50
|
-
image = _yield$ecr$
|
|
47
|
+
_yield$ecr$send = _context.sent;
|
|
48
|
+
_yield$ecr$send$image = _yield$ecr$send.images;
|
|
49
|
+
_yield$ecr$send$image2 = _yield$ecr$send$image === void 0 ? [] : _yield$ecr$send$image;
|
|
50
|
+
_yield$ecr$send$image3 = (0, _slicedToArray2["default"])(_yield$ecr$send$image2, 1);
|
|
51
|
+
image = _yield$ecr$send$image3[0];
|
|
51
52
|
imageManifest = image === null || image === void 0 ? void 0 : image.imageManifest;
|
|
52
53
|
if (imageManifest) {
|
|
53
54
|
_context.next = 15;
|
|
@@ -57,20 +58,20 @@ function _checkECRImageAccess() {
|
|
|
57
58
|
case 15:
|
|
58
59
|
_ImageManifestSchema$ = _ImageManifestSchema.ImageManifestSchema.parse(JSON.parse(imageManifest)), config = _ImageManifestSchema$.config, layers = _ImageManifestSchema$.layers;
|
|
59
60
|
_context.next = 18;
|
|
60
|
-
return ecr.
|
|
61
|
+
return ecr.send(new _clientEcr.BatchCheckLayerAvailabilityCommand({
|
|
61
62
|
registryId: registryId,
|
|
62
63
|
repositoryName: repositoryName,
|
|
63
64
|
layerDigests: [config.digest].concat((0, _toConsumableArray2["default"])(layers.map(function (l) {
|
|
64
65
|
return l.digest;
|
|
65
66
|
})))
|
|
66
|
-
})
|
|
67
|
+
}));
|
|
67
68
|
case 18:
|
|
68
69
|
_context.next = 20;
|
|
69
|
-
return ecr.
|
|
70
|
+
return ecr.send(new _clientEcr.GetDownloadUrlForLayerCommand({
|
|
70
71
|
registryId: registryId,
|
|
71
72
|
repositoryName: repositoryName,
|
|
72
73
|
layerDigest: layers[0].digest
|
|
73
|
-
})
|
|
74
|
+
}));
|
|
74
75
|
case 20:
|
|
75
76
|
log.error("ECR image is accessible: ".concat(imageUri));
|
|
76
77
|
return _context.abrupt("return", true);
|
|
@@ -96,17 +97,17 @@ function _checkECRImageAccess() {
|
|
|
96
97
|
}]
|
|
97
98
|
}, null, 2).replace(/\n/gm, '\n '), "\n"));
|
|
98
99
|
if (!(repoAccountAwsConfig && (0, _isInteractive["default"])())) {
|
|
99
|
-
_context.next =
|
|
100
|
+
_context.next = 57;
|
|
100
101
|
break;
|
|
101
102
|
}
|
|
102
103
|
_context.next = 34;
|
|
103
|
-
return new
|
|
104
|
+
return new _clientSts.STSClient({
|
|
104
105
|
credentials: ecr.config.credentials,
|
|
105
106
|
region: region
|
|
106
|
-
}).
|
|
107
|
+
}).send(new _clientSts.GetCallerIdentityCommand());
|
|
107
108
|
case 34:
|
|
108
|
-
_yield$
|
|
109
|
-
Account = _yield$
|
|
109
|
+
_yield$STSClient$send = _context.sent;
|
|
110
|
+
Account = _yield$STSClient$send.Account;
|
|
110
111
|
if (Account) {
|
|
111
112
|
_context.next = 39;
|
|
112
113
|
break;
|
|
@@ -130,23 +131,23 @@ function _checkECRImageAccess() {
|
|
|
130
131
|
}
|
|
131
132
|
return _context.abrupt("return", false);
|
|
132
133
|
case 45:
|
|
133
|
-
srcEcr = new
|
|
134
|
+
srcEcr = new _clientEcr.ECRClient(_objectSpread(_objectSpread({}, repoAccountAwsConfig), {}, {
|
|
134
135
|
region: region
|
|
135
136
|
}));
|
|
136
137
|
_context.next = 48;
|
|
137
|
-
return srcEcr.
|
|
138
|
+
return srcEcr.send(new _clientEcr.GetRepositoryPolicyCommand({
|
|
138
139
|
registryId: registryId,
|
|
139
140
|
repositoryName: repositoryName
|
|
140
|
-
})
|
|
141
|
+
}))["catch"](function (error) {
|
|
141
142
|
if (error.name === 'RepositoryPolicyNotFoundException') return {};
|
|
142
143
|
throw error;
|
|
143
144
|
});
|
|
144
145
|
case 48:
|
|
145
|
-
_yield$srcEcr$
|
|
146
|
-
policyText = _yield$srcEcr$
|
|
146
|
+
_yield$srcEcr$send$ca = _context.sent;
|
|
147
|
+
policyText = _yield$srcEcr$send$ca.policyText;
|
|
147
148
|
policy = JSON.parse(policyText || '{}');
|
|
148
149
|
_context.next = 53;
|
|
149
|
-
return srcEcr.
|
|
150
|
+
return srcEcr.send(new _clientEcr.SetRepositoryPolicyCommand({
|
|
150
151
|
repositoryName: repositoryName,
|
|
151
152
|
policyText: JSON.stringify(_objectSpread(_objectSpread({
|
|
152
153
|
Version: '2012-10-17'
|
|
@@ -159,17 +160,25 @@ function _checkECRImageAccess() {
|
|
|
159
160
|
Action: Action
|
|
160
161
|
}])
|
|
161
162
|
}), null, 2)
|
|
162
|
-
})
|
|
163
|
+
}));
|
|
163
164
|
case 53:
|
|
164
165
|
log.info("updated policy on ECR repository ".concat((0, _formatECRRepositoryHostname["default"])({
|
|
165
166
|
registryId: registryId,
|
|
166
167
|
region: region,
|
|
167
168
|
repositoryName: repositoryName
|
|
168
169
|
})));
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
_context.next = 56;
|
|
171
|
+
return checkECRImageAccess({
|
|
172
|
+
awsConfig: awsConfig,
|
|
173
|
+
imageUri: imageUri,
|
|
174
|
+
log: log,
|
|
175
|
+
ecr: ecr
|
|
176
|
+
});
|
|
172
177
|
case 56:
|
|
178
|
+
return _context.abrupt("return", _context.sent);
|
|
179
|
+
case 57:
|
|
180
|
+
return _context.abrupt("return", false);
|
|
181
|
+
case 58:
|
|
173
182
|
case "end":
|
|
174
183
|
return _context.stop();
|
|
175
184
|
}
|
package/checkECRImageAccess.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { BatchCheckLayerAvailabilityCommand, BatchGetImageCommand, ECRClient, GetDownloadUrlForLayerCommand, GetRepositoryPolicyCommand, SetRepositoryPolicyCommand } from '@aws-sdk/client-ecr';
|
|
2
|
+
import { STSClient, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
|
|
2
3
|
import parseECRImageUri from "./parseECRImageUri.mjs";
|
|
3
4
|
import { ImageManifestSchema } from "./ImageManifestSchema.mjs";
|
|
4
5
|
import isInteractive from 'is-interactive';
|
|
@@ -18,20 +19,20 @@ export default async function checkECRImageAccess({
|
|
|
18
19
|
repositoryName,
|
|
19
20
|
imageTag
|
|
20
21
|
} = parseECRImageUri(imageUri);
|
|
21
|
-
if (!ecr) ecr = new
|
|
22
|
+
if (!ecr) ecr = new ECRClient({
|
|
22
23
|
...awsConfig,
|
|
23
24
|
region
|
|
24
25
|
});
|
|
25
26
|
try {
|
|
26
27
|
const {
|
|
27
28
|
images: [image] = []
|
|
28
|
-
} = await ecr.
|
|
29
|
+
} = await ecr.send(new BatchGetImageCommand({
|
|
29
30
|
registryId,
|
|
30
31
|
repositoryName,
|
|
31
32
|
imageIds: [{
|
|
32
33
|
imageTag
|
|
33
34
|
}]
|
|
34
|
-
})
|
|
35
|
+
}));
|
|
35
36
|
const imageManifest = image === null || image === void 0 ? void 0 : image.imageManifest;
|
|
36
37
|
if (!imageManifest) {
|
|
37
38
|
throw new Error(`imageManifest not found for: ${imageUri}`);
|
|
@@ -40,16 +41,16 @@ export default async function checkECRImageAccess({
|
|
|
40
41
|
config,
|
|
41
42
|
layers
|
|
42
43
|
} = ImageManifestSchema.parse(JSON.parse(imageManifest));
|
|
43
|
-
await ecr.
|
|
44
|
+
await ecr.send(new BatchCheckLayerAvailabilityCommand({
|
|
44
45
|
registryId,
|
|
45
46
|
repositoryName,
|
|
46
47
|
layerDigests: [config.digest, ...layers.map(l => l.digest)]
|
|
47
|
-
})
|
|
48
|
-
await ecr.
|
|
48
|
+
}));
|
|
49
|
+
await ecr.send(new GetDownloadUrlForLayerCommand({
|
|
49
50
|
registryId,
|
|
50
51
|
repositoryName,
|
|
51
52
|
layerDigest: layers[0].digest
|
|
52
|
-
})
|
|
53
|
+
}));
|
|
53
54
|
log.error(`ECR image is accessible: ${imageUri}`);
|
|
54
55
|
return true;
|
|
55
56
|
} catch (error) {
|
|
@@ -77,10 +78,10 @@ The policy should include:
|
|
|
77
78
|
if (repoAccountAwsConfig && isInteractive()) {
|
|
78
79
|
const {
|
|
79
80
|
Account
|
|
80
|
-
} = await new
|
|
81
|
+
} = await new STSClient({
|
|
81
82
|
credentials: ecr.config.credentials,
|
|
82
83
|
region
|
|
83
|
-
}).
|
|
84
|
+
}).send(new GetCallerIdentityCommand());
|
|
84
85
|
if (!Account) {
|
|
85
86
|
log.error(`failed to determine AWS account`);
|
|
86
87
|
return false;
|
|
@@ -94,21 +95,21 @@ The policy should include:
|
|
|
94
95
|
default: false
|
|
95
96
|
}]);
|
|
96
97
|
if (!update) return false;
|
|
97
|
-
const srcEcr = new
|
|
98
|
+
const srcEcr = new ECRClient({
|
|
98
99
|
...repoAccountAwsConfig,
|
|
99
100
|
region
|
|
100
101
|
});
|
|
101
102
|
const {
|
|
102
103
|
policyText
|
|
103
|
-
} = await srcEcr.
|
|
104
|
+
} = await srcEcr.send(new GetRepositoryPolicyCommand({
|
|
104
105
|
registryId,
|
|
105
106
|
repositoryName
|
|
106
|
-
})
|
|
107
|
+
})).catch(error => {
|
|
107
108
|
if (error.name === 'RepositoryPolicyNotFoundException') return {};
|
|
108
109
|
throw error;
|
|
109
110
|
});
|
|
110
111
|
const policy = JSON.parse(policyText || '{}');
|
|
111
|
-
await srcEcr.
|
|
112
|
+
await srcEcr.send(new SetRepositoryPolicyCommand({
|
|
112
113
|
repositoryName,
|
|
113
114
|
policyText: JSON.stringify({
|
|
114
115
|
Version: '2012-10-17',
|
|
@@ -121,13 +122,18 @@ The policy should include:
|
|
|
121
122
|
Action
|
|
122
123
|
}]
|
|
123
124
|
}, null, 2)
|
|
124
|
-
})
|
|
125
|
+
}));
|
|
125
126
|
log.info(`updated policy on ECR repository ${formatECRRepositoryHostname({
|
|
126
127
|
registryId,
|
|
127
128
|
region,
|
|
128
129
|
repositoryName
|
|
129
130
|
})}`);
|
|
130
|
-
return
|
|
131
|
+
return await checkECRImageAccess({
|
|
132
|
+
awsConfig,
|
|
133
|
+
imageUri,
|
|
134
|
+
log,
|
|
135
|
+
ecr
|
|
136
|
+
});
|
|
131
137
|
}
|
|
132
138
|
return false;
|
|
133
139
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECRClient, ECRClientConfig } from '@aws-sdk/client-ecr';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if the given ECR repository has a sufficient repository
|
|
4
4
|
* policy to allow the given AWS principal to access docker images.
|
|
@@ -7,8 +7,8 @@ import AWS from 'aws-sdk';
|
|
|
7
7
|
* would like to add/update the repository policy.
|
|
8
8
|
*/
|
|
9
9
|
export default function checkECRRepositoryPolicy({ ecr, awsConfig, repositoryName, awsPrincipal, Action, log, }: {
|
|
10
|
-
ecr?:
|
|
11
|
-
awsConfig?:
|
|
10
|
+
ecr?: ECRClient;
|
|
11
|
+
awsConfig?: ECRClientConfig;
|
|
12
12
|
repositoryName: string;
|
|
13
13
|
awsPrincipal: string;
|
|
14
14
|
Action?: string[];
|
|
@@ -9,7 +9,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var
|
|
12
|
+
var _clientEcr = require("@aws-sdk/client-ecr");
|
|
13
13
|
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
14
14
|
var _isInteractive = _interopRequireDefault(require("is-interactive"));
|
|
15
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -27,7 +27,7 @@ function checkECRRepositoryPolicy(_x) {
|
|
|
27
27
|
function _checkECRRepositoryPolicy() {
|
|
28
28
|
_checkECRRepositoryPolicy = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
29
29
|
var _policy$Statement, _statementForAction$P;
|
|
30
|
-
var ecr, awsConfig, repositoryName, awsPrincipal, _ref$Action, Action, _ref$log, log, rootUserMatch, principalAliases, _yield$ecr$
|
|
30
|
+
var ecr, awsConfig, repositoryName, awsPrincipal, _ref$Action, Action, _ref$log, log, rootUserMatch, principalAliases, _yield$ecr$send$catch, policyText, policy, statementForAction, statementPrincipal, _yield$inquirer$promp, update, _statementForAction$A, finalPolicy;
|
|
31
31
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
32
32
|
while (1) switch (_context.prev = _context.next) {
|
|
33
33
|
case 0:
|
|
@@ -35,17 +35,17 @@ function _checkECRRepositoryPolicy() {
|
|
|
35
35
|
rootUserMatch = /^arn:aws:iam::(\d+):root$/.exec(awsPrincipal);
|
|
36
36
|
if (rootUserMatch) awsPrincipal = rootUserMatch[1];
|
|
37
37
|
principalAliases = /^(\d+)$/.test(awsPrincipal) ? [awsPrincipal, "arn:aws:iam::".concat(awsPrincipal, ":root")] : [awsPrincipal];
|
|
38
|
-
if (!ecr) ecr = new
|
|
38
|
+
if (!ecr) ecr = new _clientEcr.ECRClient(_objectSpread({}, awsConfig));
|
|
39
39
|
_context.next = 7;
|
|
40
|
-
return ecr.
|
|
40
|
+
return ecr.send(new _clientEcr.GetRepositoryPolicyCommand({
|
|
41
41
|
repositoryName: repositoryName
|
|
42
|
-
})
|
|
42
|
+
}))["catch"](function (error) {
|
|
43
43
|
if (error.name === 'RepositoryPolicyNotFoundException') return {};
|
|
44
44
|
throw error;
|
|
45
45
|
});
|
|
46
46
|
case 7:
|
|
47
|
-
_yield$ecr$
|
|
48
|
-
policyText = _yield$ecr$
|
|
47
|
+
_yield$ecr$send$catch = _context.sent;
|
|
48
|
+
policyText = _yield$ecr$send$catch.policyText;
|
|
49
49
|
policy = JSON.parse(policyText || '{}');
|
|
50
50
|
statementForAction = (_policy$Statement = policy.Statement) === null || _policy$Statement === void 0 ? void 0 : _policy$Statement.find(function (s) {
|
|
51
51
|
return s.Effect === 'Allow' && Array.isArray(Action) && Action.every(function (a) {
|
|
@@ -112,10 +112,10 @@ function _checkECRRepositoryPolicy() {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
_context.next = 26;
|
|
115
|
-
return ecr.
|
|
115
|
+
return ecr.send(new _clientEcr.SetRepositoryPolicyCommand({
|
|
116
116
|
repositoryName: repositoryName,
|
|
117
117
|
policyText: JSON.stringify(finalPolicy, null, 2)
|
|
118
|
-
})
|
|
118
|
+
}));
|
|
119
119
|
case 26:
|
|
120
120
|
log.info("updated policy on ECR repository ".concat(repositoryName));
|
|
121
121
|
return _context.abrupt("return", true);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECRClient, GetRepositoryPolicyCommand, SetRepositoryPolicyCommand } from '@aws-sdk/client-ecr';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import isInteractive from 'is-interactive';
|
|
4
4
|
|
|
@@ -21,12 +21,14 @@ export default async function checkECRRepositoryPolicy({
|
|
|
21
21
|
const rootUserMatch = /^arn:aws:iam::(\d+):root$/.exec(awsPrincipal);
|
|
22
22
|
if (rootUserMatch) awsPrincipal = rootUserMatch[1];
|
|
23
23
|
const principalAliases = /^(\d+)$/.test(awsPrincipal) ? [awsPrincipal, `arn:aws:iam::${awsPrincipal}:root`] : [awsPrincipal];
|
|
24
|
-
if (!ecr) ecr = new
|
|
24
|
+
if (!ecr) ecr = new ECRClient({
|
|
25
|
+
...awsConfig
|
|
26
|
+
});
|
|
25
27
|
const {
|
|
26
28
|
policyText
|
|
27
|
-
} = await ecr.
|
|
29
|
+
} = await ecr.send(new GetRepositoryPolicyCommand({
|
|
28
30
|
repositoryName
|
|
29
|
-
})
|
|
31
|
+
})).catch(error => {
|
|
30
32
|
if (error.name === 'RepositoryPolicyNotFoundException') return {};
|
|
31
33
|
throw error;
|
|
32
34
|
});
|
|
@@ -88,10 +90,10 @@ The policy should include:
|
|
|
88
90
|
}]
|
|
89
91
|
};
|
|
90
92
|
}
|
|
91
|
-
await ecr.
|
|
93
|
+
await ecr.send(new SetRepositoryPolicyCommand({
|
|
92
94
|
repositoryName,
|
|
93
95
|
policyText: JSON.stringify(finalPolicy, null, 2)
|
|
94
|
-
})
|
|
96
|
+
}));
|
|
95
97
|
log.info(`updated policy on ECR repository ${repositoryName}`);
|
|
96
98
|
return true;
|
|
97
99
|
}
|
package/copyECRImage.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECRClient, ECRClientConfig } from '@aws-sdk/client-ecr';
|
|
2
2
|
export default function copyECRImage({ from, to, }: {
|
|
3
3
|
from: {
|
|
4
4
|
imageUri: string;
|
|
5
|
-
ecr?:
|
|
6
|
-
awsConfig?:
|
|
5
|
+
ecr?: ECRClient;
|
|
6
|
+
awsConfig?: ECRClientConfig;
|
|
7
7
|
};
|
|
8
8
|
to: {
|
|
9
9
|
imageUri: string;
|
|
10
|
-
ecr?:
|
|
11
|
-
awsConfig?:
|
|
10
|
+
ecr?: ECRClient;
|
|
11
|
+
awsConfig?: ECRClientConfig;
|
|
12
12
|
};
|
|
13
13
|
}): Promise<void>;
|
package/ecrImageExists.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECRClient, ECRClientConfig } from '@aws-sdk/client-ecr';
|
|
2
2
|
export default function ecrImageExists({ ecr, awsConfig, imageUri, registryId, repositoryName, imageTag, }: {
|
|
3
|
-
ecr?:
|
|
4
|
-
awsConfig?:
|
|
3
|
+
ecr?: ECRClient;
|
|
4
|
+
awsConfig?: ECRClientConfig;
|
|
5
5
|
imageUri?: string;
|
|
6
6
|
registryId?: string;
|
|
7
7
|
repositoryName?: string;
|
package/ecrImageExists.js
CHANGED
|
@@ -9,7 +9,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
|
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
-
var
|
|
12
|
+
var _clientEcr = require("@aws-sdk/client-ecr");
|
|
13
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
15
|
function ecrImageExists(_x) {
|
|
@@ -40,7 +40,7 @@ function _ecrImageExists() {
|
|
|
40
40
|
imageTag = _match[4];
|
|
41
41
|
case 10:
|
|
42
42
|
if (!region) region = awsConfig === null || awsConfig === void 0 ? void 0 : awsConfig.region;
|
|
43
|
-
if (!ecr) ecr = new
|
|
43
|
+
if (!ecr) ecr = new _clientEcr.ECRClient(_objectSpread(_objectSpread({}, awsConfig), {}, {
|
|
44
44
|
region: region
|
|
45
45
|
}));
|
|
46
46
|
if (!(!repositoryName || !imageTag)) {
|
|
@@ -50,13 +50,13 @@ function _ecrImageExists() {
|
|
|
50
50
|
throw new Error("missing repositoryName/imageTag or imageUri");
|
|
51
51
|
case 14:
|
|
52
52
|
_context.next = 16;
|
|
53
|
-
return ecr.
|
|
53
|
+
return ecr.send(new _clientEcr.DescribeImagesCommand({
|
|
54
54
|
registryId: registryId,
|
|
55
55
|
repositoryName: repositoryName,
|
|
56
56
|
imageIds: [{
|
|
57
57
|
imageTag: imageTag
|
|
58
58
|
}]
|
|
59
|
-
})
|
|
59
|
+
})).then(function () {
|
|
60
60
|
return true;
|
|
61
61
|
}, function () {
|
|
62
62
|
return false;
|
package/ecrImageExists.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DescribeImagesCommand, ECRClient } from '@aws-sdk/client-ecr';
|
|
2
2
|
export default async function ecrImageExists({
|
|
3
3
|
ecr,
|
|
4
4
|
awsConfig,
|
|
@@ -14,18 +14,18 @@ export default async function ecrImageExists({
|
|
|
14
14
|
[, registryId, region, repositoryName, imageTag] = match;
|
|
15
15
|
}
|
|
16
16
|
if (!region) region = awsConfig === null || awsConfig === void 0 ? void 0 : awsConfig.region;
|
|
17
|
-
if (!ecr) ecr = new
|
|
17
|
+
if (!ecr) ecr = new ECRClient({
|
|
18
18
|
...awsConfig,
|
|
19
19
|
region
|
|
20
20
|
});
|
|
21
21
|
if (!repositoryName || !imageTag) {
|
|
22
22
|
throw new Error(`missing repositoryName/imageTag or imageUri`);
|
|
23
23
|
}
|
|
24
|
-
return await ecr.
|
|
24
|
+
return await ecr.send(new DescribeImagesCommand({
|
|
25
25
|
registryId,
|
|
26
26
|
repositoryName,
|
|
27
27
|
imageIds: [{
|
|
28
28
|
imageTag
|
|
29
29
|
}]
|
|
30
|
-
})
|
|
30
|
+
})).then(() => true, () => false);
|
|
31
31
|
}
|
package/formatECRImageUri.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function formatECRImageUri({ registryId, region, repositoryName, imageTag, }: {
|
|
2
|
-
registryId:
|
|
2
|
+
registryId: string;
|
|
3
3
|
region: string;
|
|
4
|
-
repositoryName:
|
|
5
|
-
imageTag:
|
|
4
|
+
repositoryName: string;
|
|
5
|
+
imageTag: string;
|
|
6
6
|
}): string;
|
package/loginToECR.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
* @prettier
|
|
3
|
-
*/
|
|
4
|
-
import AWS from 'aws-sdk';
|
|
1
|
+
import { ECRClient, ECRClientConfig } from '@aws-sdk/client-ecr';
|
|
5
2
|
export default function loginToECR({ ecr, awsConfig, }: {
|
|
6
|
-
ecr?:
|
|
7
|
-
awsConfig?:
|
|
3
|
+
ecr?: ECRClient;
|
|
4
|
+
awsConfig?: ECRClientConfig;
|
|
8
5
|
}): Promise<void>;
|
package/loginToECR.js
CHANGED
|
@@ -7,11 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = loginToECR;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
12
12
|
var _promisifyChildProcess = require("promisify-child-process");
|
|
13
13
|
var _base64Js = _interopRequireDefault(require("base64-js"));
|
|
14
|
-
|
|
14
|
+
var _clientEcr = require("@aws-sdk/client-ecr");
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
|
15
17
|
* @prettier
|
|
16
18
|
*/
|
|
17
19
|
function loginToECR(_x) {
|
|
@@ -19,17 +21,17 @@ function loginToECR(_x) {
|
|
|
19
21
|
}
|
|
20
22
|
function _loginToECR() {
|
|
21
23
|
_loginToECR = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
22
|
-
var ecr, awsConfig, _yield$ecr$
|
|
24
|
+
var ecr, awsConfig, _yield$ecr$send, authorizationData, _ref2, authorizationToken, proxyEndpoint, decoded, _decoded$split, _decoded$split2, user, password, child;
|
|
23
25
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
24
26
|
while (1) switch (_context.prev = _context.next) {
|
|
25
27
|
case 0:
|
|
26
28
|
ecr = _ref.ecr, awsConfig = _ref.awsConfig;
|
|
27
|
-
if (!ecr) ecr = new
|
|
29
|
+
if (!ecr) ecr = new _clientEcr.ECRClient(_objectSpread({}, awsConfig));
|
|
28
30
|
_context.next = 4;
|
|
29
|
-
return ecr.
|
|
31
|
+
return ecr.send(new _clientEcr.GetAuthorizationTokenCommand());
|
|
30
32
|
case 4:
|
|
31
|
-
_yield$ecr$
|
|
32
|
-
authorizationData = _yield$ecr$
|
|
33
|
+
_yield$ecr$send = _context.sent;
|
|
34
|
+
authorizationData = _yield$ecr$send.authorizationData;
|
|
33
35
|
_ref2 = (authorizationData === null || authorizationData === void 0 ? void 0 : authorizationData[0]) || {}, authorizationToken = _ref2.authorizationToken, proxyEndpoint = _ref2.proxyEndpoint;
|
|
34
36
|
if (authorizationToken) {
|
|
35
37
|
_context.next = 9;
|
package/loginToECR.mjs
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @prettier
|
|
3
3
|
*/
|
|
4
|
-
import AWS from 'aws-sdk';
|
|
5
4
|
import { spawn } from 'promisify-child-process';
|
|
6
5
|
import base64 from 'base64-js';
|
|
6
|
+
import { ECRClient, GetAuthorizationTokenCommand } from '@aws-sdk/client-ecr';
|
|
7
7
|
export default async function loginToECR({
|
|
8
8
|
ecr,
|
|
9
9
|
awsConfig
|
|
10
10
|
}) {
|
|
11
|
-
if (!ecr) ecr = new
|
|
11
|
+
if (!ecr) ecr = new ECRClient({
|
|
12
|
+
...awsConfig
|
|
13
|
+
});
|
|
12
14
|
const {
|
|
13
15
|
authorizationData
|
|
14
|
-
} = await ecr.
|
|
16
|
+
} = await ecr.send(new GetAuthorizationTokenCommand());
|
|
15
17
|
const {
|
|
16
18
|
authorizationToken,
|
|
17
19
|
proxyEndpoint
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/aws-ecr-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "utilities for working with AWS Elastic Container Registry",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"repository": {
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"homepage": "https://github.com/jcoreio/aws-ecr-utils#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@aws-sdk/client-ecr": "^3.577.0",
|
|
23
|
+
"@aws-sdk/client-sts": "^3.577.0",
|
|
22
24
|
"@babel/runtime": "^7.18.6",
|
|
23
|
-
"aws-sdk": "^2.1070.0",
|
|
24
25
|
"base64-js": "^1.5.1",
|
|
25
26
|
"inquirer": "^8.2.6",
|
|
26
27
|
"is-interactive": "^1.0.0",
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"engines": {
|
|
47
48
|
"node": ">=16"
|
|
48
49
|
},
|
|
49
|
-
"packageManager": "pnpm@8.
|
|
50
|
+
"packageManager": "pnpm@8.11.0"
|
|
50
51
|
}
|
package/parseECRImageUri.d.ts
CHANGED
package/tagECRImage.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @prettier
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { ECRClient, ECRClientConfig } from '@aws-sdk/client-ecr';
|
|
5
5
|
export default function tagECRImage({ ecr, awsConfig, imageUri, tags, }: {
|
|
6
|
-
ecr?:
|
|
7
|
-
awsConfig?:
|
|
6
|
+
ecr?: ECRClient;
|
|
7
|
+
awsConfig?: ECRClientConfig;
|
|
8
8
|
imageUri: string;
|
|
9
9
|
tags: string[];
|
|
10
10
|
}): Promise<void>;
|
package/tagECRImage.js
CHANGED
|
@@ -8,7 +8,7 @@ exports["default"] = tagECRImage;
|
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var
|
|
11
|
+
var _clientEcr = require("@aws-sdk/client-ecr");
|
|
12
12
|
var _parseECRImageUri2 = _interopRequireDefault(require("./parseECRImageUri.js"));
|
|
13
13
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
14
14
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -28,16 +28,16 @@ function _tagECRImage() {
|
|
|
28
28
|
case 0:
|
|
29
29
|
ecr = _ref.ecr, awsConfig = _ref.awsConfig, imageUri = _ref.imageUri, tags = _ref.tags;
|
|
30
30
|
_parseECRImageUri = (0, _parseECRImageUri2["default"])(imageUri), region = _parseECRImageUri.region, repositoryName = _parseECRImageUri.repositoryName, imageTag = _parseECRImageUri.imageTag;
|
|
31
|
-
if (!ecr) ecr = new
|
|
31
|
+
if (!ecr) ecr = new _clientEcr.ECRClient(_objectSpread(_objectSpread({}, awsConfig), {}, {
|
|
32
32
|
region: region
|
|
33
33
|
}));
|
|
34
34
|
_context.next = 5;
|
|
35
|
-
return ecr.
|
|
35
|
+
return ecr.send(new _clientEcr.BatchGetImageCommand({
|
|
36
36
|
repositoryName: repositoryName,
|
|
37
37
|
imageIds: [{
|
|
38
38
|
imageTag: imageTag
|
|
39
39
|
}]
|
|
40
|
-
})
|
|
40
|
+
})).then(function (r) {
|
|
41
41
|
var _r$images;
|
|
42
42
|
return r === null || r === void 0 || (_r$images = r.images) === null || _r$images === void 0 || (_r$images = _r$images[0]) === null || _r$images === void 0 ? void 0 : _r$images.imageManifest;
|
|
43
43
|
});
|
|
@@ -67,11 +67,11 @@ function _tagECRImage() {
|
|
|
67
67
|
console.error("Adding tag ".concat(repositoryName, ":").concat(tag));
|
|
68
68
|
_context.prev = 15;
|
|
69
69
|
_context.next = 18;
|
|
70
|
-
return ecr.
|
|
70
|
+
return ecr.send(new _clientEcr.PutImageCommand({
|
|
71
71
|
repositoryName: repositoryName,
|
|
72
72
|
imageManifest: imageManifest,
|
|
73
73
|
imageTag: tag.substring(tag.indexOf(':') + 1)
|
|
74
|
-
})
|
|
74
|
+
}));
|
|
75
75
|
case 18:
|
|
76
76
|
_context.next = 24;
|
|
77
77
|
break;
|
package/tagECRImage.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @prettier
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { BatchGetImageCommand, ECRClient, PutImageCommand } from '@aws-sdk/client-ecr';
|
|
5
5
|
import parseECRImageUri from "./parseECRImageUri.mjs";
|
|
6
6
|
export default async function tagECRImage({
|
|
7
7
|
ecr,
|
|
@@ -14,16 +14,16 @@ export default async function tagECRImage({
|
|
|
14
14
|
repositoryName,
|
|
15
15
|
imageTag
|
|
16
16
|
} = parseECRImageUri(imageUri);
|
|
17
|
-
if (!ecr) ecr = new
|
|
17
|
+
if (!ecr) ecr = new ECRClient({
|
|
18
18
|
...awsConfig,
|
|
19
19
|
region
|
|
20
20
|
});
|
|
21
|
-
const imageManifest = await ecr.
|
|
21
|
+
const imageManifest = await ecr.send(new BatchGetImageCommand({
|
|
22
22
|
repositoryName,
|
|
23
23
|
imageIds: [{
|
|
24
24
|
imageTag
|
|
25
25
|
}]
|
|
26
|
-
})
|
|
26
|
+
})).then(r => {
|
|
27
27
|
var _r$images;
|
|
28
28
|
return r === null || r === void 0 || (_r$images = r.images) === null || _r$images === void 0 || (_r$images = _r$images[0]) === null || _r$images === void 0 ? void 0 : _r$images.imageManifest;
|
|
29
29
|
});
|
|
@@ -36,11 +36,11 @@ export default async function tagECRImage({
|
|
|
36
36
|
// eslint-disable-next-line no-console
|
|
37
37
|
console.error(`Adding tag ${repositoryName}:${tag}`);
|
|
38
38
|
try {
|
|
39
|
-
await ecr.
|
|
39
|
+
await ecr.send(new PutImageCommand({
|
|
40
40
|
repositoryName,
|
|
41
41
|
imageManifest,
|
|
42
42
|
imageTag: tag.substring(tag.indexOf(':') + 1)
|
|
43
|
-
})
|
|
43
|
+
}));
|
|
44
44
|
} catch (error) {
|
|
45
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
46
|
if ((error === null || error === void 0 ? void 0 : error.code) !== 'ImageAlreadyExistsException') throw error;
|
package/upsertECRRepository.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ECRClient, ECRClientConfig, Repository } from '@aws-sdk/client-ecr';
|
|
2
2
|
export default function upsertECRRepository({ ecr, awsConfig, repositoryName, }: {
|
|
3
|
-
ecr?:
|
|
4
|
-
awsConfig?:
|
|
3
|
+
ecr?: ECRClient;
|
|
4
|
+
awsConfig?: ECRClientConfig;
|
|
5
5
|
repositoryName: string;
|
|
6
|
-
}): Promise<
|
|
6
|
+
}): Promise<Repository>;
|
package/upsertECRRepository.js
CHANGED
|
@@ -6,28 +6,30 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = upsertECRRepository;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var
|
|
11
|
-
|
|
11
|
+
var _clientEcr = require("@aws-sdk/client-ecr");
|
|
12
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // @flow
|
|
12
14
|
function upsertECRRepository(_x) {
|
|
13
15
|
return _upsertECRRepository.apply(this, arguments);
|
|
14
16
|
}
|
|
15
17
|
function _upsertECRRepository() {
|
|
16
18
|
_upsertECRRepository = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
17
|
-
var ecr, awsConfig, repositoryName, _yield$ecr$
|
|
19
|
+
var ecr, awsConfig, repositoryName, _yield$ecr$send, repositories, _repository, _yield$ecr$send2, repository;
|
|
18
20
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
19
21
|
while (1) switch (_context.prev = _context.next) {
|
|
20
22
|
case 0:
|
|
21
23
|
ecr = _ref.ecr, awsConfig = _ref.awsConfig, repositoryName = _ref.repositoryName;
|
|
22
|
-
if (!ecr) ecr = new
|
|
24
|
+
if (!ecr) ecr = new _clientEcr.ECRClient(_objectSpread({}, awsConfig));
|
|
23
25
|
_context.prev = 2;
|
|
24
26
|
_context.next = 5;
|
|
25
|
-
return ecr.
|
|
27
|
+
return ecr.send(new _clientEcr.DescribeRepositoriesCommand({
|
|
26
28
|
repositoryNames: [repositoryName]
|
|
27
|
-
})
|
|
29
|
+
}));
|
|
28
30
|
case 5:
|
|
29
|
-
_yield$ecr$
|
|
30
|
-
repositories = _yield$ecr$
|
|
31
|
+
_yield$ecr$send = _context.sent;
|
|
32
|
+
repositories = _yield$ecr$send.repositories;
|
|
31
33
|
_repository = repositories === null || repositories === void 0 ? void 0 : repositories[0];
|
|
32
34
|
if (!_repository) {
|
|
33
35
|
_context.next = 10;
|
|
@@ -44,12 +46,12 @@ function _upsertECRRepository() {
|
|
|
44
46
|
// eslint-disable-next-line no-console
|
|
45
47
|
console.error("Creating ECR repository {bold ".concat(repositoryName, "}..."));
|
|
46
48
|
_context.next = 17;
|
|
47
|
-
return ecr.
|
|
49
|
+
return ecr.send(new _clientEcr.CreateRepositoryCommand({
|
|
48
50
|
repositoryName: repositoryName
|
|
49
|
-
})
|
|
51
|
+
}));
|
|
50
52
|
case 17:
|
|
51
|
-
_yield$ecr$
|
|
52
|
-
repository = _yield$ecr$
|
|
53
|
+
_yield$ecr$send2 = _context.sent;
|
|
54
|
+
repository = _yield$ecr$send2.repository;
|
|
53
55
|
if (repository) {
|
|
54
56
|
_context.next = 21;
|
|
55
57
|
break;
|
package/upsertECRRepository.mjs
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { CreateRepositoryCommand, DescribeRepositoriesCommand, ECRClient } from '@aws-sdk/client-ecr';
|
|
4
4
|
export default async function upsertECRRepository({
|
|
5
5
|
ecr,
|
|
6
6
|
awsConfig,
|
|
7
7
|
repositoryName
|
|
8
8
|
}) {
|
|
9
|
-
if (!ecr) ecr = new
|
|
9
|
+
if (!ecr) ecr = new ECRClient({
|
|
10
|
+
...awsConfig
|
|
11
|
+
});
|
|
10
12
|
try {
|
|
11
13
|
const {
|
|
12
14
|
repositories
|
|
13
|
-
} = await ecr.
|
|
15
|
+
} = await ecr.send(new DescribeRepositoriesCommand({
|
|
14
16
|
repositoryNames: [repositoryName]
|
|
15
|
-
})
|
|
17
|
+
}));
|
|
16
18
|
const repository = repositories === null || repositories === void 0 ? void 0 : repositories[0];
|
|
17
19
|
if (repository) return repository;
|
|
18
20
|
} catch (error) {
|
|
@@ -23,9 +25,9 @@ export default async function upsertECRRepository({
|
|
|
23
25
|
console.error(`Creating ECR repository {bold ${repositoryName}}...`);
|
|
24
26
|
const {
|
|
25
27
|
repository
|
|
26
|
-
} = await ecr.
|
|
28
|
+
} = await ecr.send(new CreateRepositoryCommand({
|
|
27
29
|
repositoryName
|
|
28
|
-
})
|
|
30
|
+
}));
|
|
29
31
|
if (!repository) {
|
|
30
32
|
throw new Error(`repository is missing from createRepository response`);
|
|
31
33
|
}
|
package/copyECRImage.js.flow
DELETED
package/copyECRImage.mjs.flow
DELETED
package/ecrImageExists.js.flow
DELETED
package/ecrImageExists.mjs.flow
DELETED
package/index.js.flow
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
export { default as copyECRImage } from './copyECRImage'
|
|
4
|
-
export { default as ecrImageExists } from './ecrImageExists'
|
|
5
|
-
export { default as loginToECR } from './loginToECR'
|
|
6
|
-
export { default as tagECRImage } from './tagECRImage'
|
|
7
|
-
export { default as parseECRImageUri } from './parseECRImageUri'
|
|
8
|
-
export { default as upsertECRRepository } from './upsertECRRepository'
|
package/index.mjs.flow
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
export { default as copyECRImage } from './copyECRImage'
|
|
4
|
-
export { default as ecrImageExists } from './ecrImageExists'
|
|
5
|
-
export { default as loginToECR } from './loginToECR'
|
|
6
|
-
export { default as tagECRImage } from './tagECRImage'
|
|
7
|
-
export { default as parseECRImageUri } from './parseECRImageUri'
|
|
8
|
-
export { default as upsertECRRepository } from './upsertECRRepository'
|
package/loginToECR.js.flow
DELETED
package/loginToECR.mjs.flow
DELETED
package/parseECRImageUri.js.flow
DELETED
package/tagECRImage.js.flow
DELETED
package/tagECRImage.mjs.flow
DELETED