Compare commits

...

6 Commits

Author SHA1 Message Date
5793f03357 os.getLastModified
Change-type: patch
2024-12-05 10:21:20 -05:00
f1e957f60f PineOptions Release
Change-type: patch
2024-12-05 10:21:20 -05:00
7dad523934 contains__image
Change-type: patch
2024-12-05 10:21:19 -05:00
0f53ab3b4e generateApiKey
Change-type: patch
2024-12-05 10:21:19 -05:00
0c0e44a285 contains_image
Change-type: patch
2024-12-05 10:21:19 -05:00
8dea1333ca api key expiry date
Change-type: patch
2024-12-05 10:21:19 -05:00
9 changed files with 24 additions and 79 deletions

View File

@ -333,6 +333,10 @@ Examples:
the API key name
#### EXPIRYDATE
the API key expiry date
## api-key list
### Aliases

View File

@ -48,6 +48,10 @@ export default class GenerateCmd extends Command {
description: 'the API key name',
required: true,
}),
expiryDate: Args.string({
description: 'the API key expiry date',
required: true,
}),
};
public static authenticated = true;
@ -57,7 +61,10 @@ export default class GenerateCmd extends Command {
let key;
try {
key = await getBalenaSdk().models.apiKey.create(params.name);
key = await getBalenaSdk().models.apiKey.create(
params.name,
params.expiryDate,
);
} catch (e) {
if (e.name === 'BalenaNotLoggedIn') {
if (await isLoggedInWithJwt()) {

View File

@ -295,7 +295,7 @@ Can be repeated to add multiple certificates.\
owns__release: {
$select: ['id', 'commit', 'end_timestamp', 'composition'],
$expand: {
contains__image: {
release_image: {
$select: ['image'],
$expand: {
image: {

View File

@ -86,7 +86,7 @@ export default class ReleaseCmd extends Command {
balena: BalenaSdk.BalenaSDK,
options: FlagsDef,
) {
const fields: Array<keyof BalenaSdk.Release> = [
const fields = [
'id',
'commit',
'created_at',
@ -96,7 +96,7 @@ export default class ReleaseCmd extends Command {
'build_log',
'start_timestamp',
'end_timestamp',
];
] satisfies BalenaSdk.PineOptions<BalenaSdk.Release>['$select'];
const release = await balena.models.release.get(commitOrId, {
...(!options.json && { $select: fields }),

View File

@ -56,14 +56,14 @@ export default class ReleaseListCmd extends Command {
public async run() {
const { args: params, flags: options } = await this.parse(ReleaseListCmd);
const fields: Array<keyof BalenaSdk.Release> = [
const fields = [
'id',
'commit',
'created_at',
'status',
'semver',
'is_final',
];
] satisfies BalenaSdk.PineOptions<BalenaSdk.Release>['$select'];
const balena = getBalenaSdk();
const { getFleetSlug } = await import('../../utils/sdk');

View File

@ -240,7 +240,7 @@ export const getPreviousRepos = (
status: 'success',
},
$expand: {
contains__image: {
release_image: {
$select: 'image',
$expand: { image: { $select: 'is_stored_at__image_location' } },
},
@ -252,7 +252,7 @@ export const getPreviousRepos = (
.then(function (release) {
// grab all images from the latest release, return all image locations in the registry
if (release.length > 0) {
const images = release[0].contains__image as Array<{
const images = release[0].release_image as Array<{
image: [SDK.Image];
}>;
const { getRegistryAndName } =

View File

@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import type * as BalenaSdk from 'balena-sdk';
import * as semver from 'balena-semver';
import { getBalenaSdk, stripIndent } from './lazy';
export interface ImgConfig {
@ -122,16 +121,10 @@ export function generateDeviceConfig(
// os.getConfig always returns a config for an app
delete config.apiKey;
if (deviceApiKey == null && semver.satisfies(options.version, '<2.0.3')) {
config.apiKey = await sdk.models.application.generateApiKey(
application.id,
);
} else {
config.deviceApiKey =
typeof deviceApiKey === 'string' && deviceApiKey
? deviceApiKey
: await sdk.models.device.generateDeviceKey(device.uuid);
}
config.deviceApiKey =
typeof deviceApiKey === 'string' && deviceApiKey
? deviceApiKey
: await sdk.models.device.generateDeviceKey(device.uuid);
return config;
})

View File

@ -102,12 +102,7 @@ export const isImageFresh = async (deviceType: string, version: string) => {
return false;
}
const balena = getBalenaSdk();
const lastModifiedDate = await balena.models.os.getLastModified(
deviceType,
version,
);
return lastModifiedDate < createdDate;
return true;
};
/**

View File

@ -343,60 +343,6 @@ describe('image-manager', function () {
afterEach(function () {
this.utilsGetFileCreatedDate.restore();
});
describe('given the file was created before the os last modified time', function () {
beforeEach(function () {
this.osGetLastModified = stub(balena.models.os, 'getLastModified');
this.osGetLastModified.returns(
Promise.resolve(new Date('2014-02-01T00:00:00.000Z')),
);
});
afterEach(function () {
this.osGetLastModified.restore();
});
it('should return false', function () {
const promise = imageManager.isImageFresh('raspberry-pi', '1.2.3');
return expect(promise).to.eventually.be.false;
});
});
describe('given the file was created after the os last modified time', function () {
beforeEach(function () {
this.osGetLastModified = stub(balena.models.os, 'getLastModified');
this.osGetLastModified.returns(
Promise.resolve(new Date('2013-01-01T00:00:00.000Z')),
);
});
afterEach(function () {
this.osGetLastModified.restore();
});
it('should return true', function () {
const promise = imageManager.isImageFresh('raspberry-pi', '1.2.3');
return expect(promise).to.eventually.be.true;
});
});
describe('given the file was created just at the os last modified time', function () {
beforeEach(function () {
this.osGetLastModified = stub(balena.models.os, 'getLastModified');
this.osGetLastModified.returns(
Promise.resolve(new Date('2014-00-01T00:00:00.000Z')),
);
});
afterEach(function () {
this.osGetLastModified.restore();
});
it('should return false', function () {
const promise = imageManager.isImageFresh('raspberry-pi', '1.2.3');
return expect(promise).to.eventually.be.false;
});
});
});
});
});