Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
> v0.2.14 ~ "RELEASE_NOTES_PLACEHOLDER — replace this line with the release title"
> v0.2.15 ~ "API key expiry actually persists"

---
## Highlights

RELEASE_NOTES_PLACEHOLDER

Describe what changed in this release. The first line above must name the version
being released, and both placeholder markers must be gone, or the release workflow
refuses to tag.
- **API key expiration works again.** Selecting an expiry in the developers console (`immediately`, `in 1 hour`, `in 24 hours`, …) silently saved `NULL` — Ember Data's `date` transform discarded the relative expiration strings before they reached the API. A new `expiration` transform passes them through for the server to resolve, so `expires_at` is persisted for every option. Pair with fleetbase/core-api#246 for `immediately` to revoke a key reliably at the boundary instant. ([#43](https://github.com/fleetbase/dev-engine/pull/43))
- **The engine's test suite is runnable.** `ember test` previously crashed before executing a single test; the engine now eager-loads for its own test runs (hosts still get the lazy engine), and regression tests cover the expiration serialization path.

---
## Need help?
Expand Down
2 changes: 1 addition & 1 deletion addon/models/api-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ApiCredentialModel extends Model {

/** @dates */
@attr('date') last_used_at;
@attr('date') expires_at;
@attr('expiration') expires_at;
@attr('date') deleted_at;
@attr('date') created_at;
@attr('date') updated_at;
Expand Down
50 changes: 50 additions & 0 deletions addon/transforms/expiration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Transform from '@ember-data/serializer/transform';

/**
* Transform for expiration attributes which the API accepts as either a
* datetime or a relative expiration string ('never', 'immediately',
* 'in 1 hour', 'in 24 hours', ...) resolved server side.
*
* Deserializes like the standard `date` transform so date reads keep
* returning `Date` instances, but serializes strings untouched — the
* `date` transform serializes any non-Date value to `null`, which
* silently discards a selected relative expiration.
*/
export default class ExpirationTransform extends Transform {
deserialize(serialized) {
const type = typeof serialized;

if (type === 'string') {
let offset = serialized.indexOf('+');

if (offset !== -1 && serialized.length - 5 === offset) {
offset += 3;
return new Date(serialized.slice(0, offset) + ':' + serialized.slice(offset));
}

return new Date(serialized);
}

if (type === 'number') {
return new Date(serialized);
}

if (serialized === null || serialized === undefined) {
return serialized;
}

return null;
}

serialize(deserialized) {
if (typeof deserialized === 'string') {
return deserialized;
}

if (deserialized instanceof Date && !isNaN(deserialized)) {
return deserialized.toISOString();
}

return null;
}
}
1 change: 1 addition & 0 deletions app/transforms/expiration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/dev-engine/transforms/expiration';
23 changes: 16 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@
const { buildEngine } = require('ember-engines/lib/engine-addon');
const { name } = require('./package');

// The engine's own test suite (`ember test` run from this package) needs the
// engine modules loaded eagerly so the dummy app can resolve them; hosts always
// get the lazy engine. Same pattern as the fleetops engine.
const isRunningOwnTests = process.argv.includes('test') && process.cwd() === __dirname;

module.exports = buildEngine({
name,

lazyLoading: {
enabled: true,
enabled: !isRunningOwnTests,
},

included(app) {
this._super.included.apply(this, arguments);

// Configure ember-prism for the addon
app.options = app.options || {};
app.options['ember-prism'] = {
components: ['json', 'javascript'],
plugins: ['line-highlight', 'line-numbers'],
};
// Configure ember-prism for the addon; skipped for the eager dummy-app
// test build, where ember-cli-node-assets registers the component and
// plugin imports without funneling the files in and the vendor concat fails
if (!isRunningOwnTests) {
app.options = app.options || {};
app.options['ember-prism'] = {
components: ['json', 'javascript'],
plugins: ['line-highlight', 'line-numbers'],
};
}
},

isDevelopingAddon() {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/dev-engine",
"version": "0.2.14",
"version": "0.2.15",
"description": "Fleetbase Developers extension provides a module for managing developer resources such as API keys, webhooks, sockets, events and logs.",
"fleetbase": {
"route": "developers"
Expand Down Expand Up @@ -59,6 +59,7 @@
"devDependencies": {
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-proposal-decorators": "^7.23.2",
"@ember/legacy-built-in-components": "^0.4.2",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^3.2.0",
"@embroider/test-setup": "^3.0.2",
Expand Down Expand Up @@ -91,6 +92,7 @@
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-qunit": "^8.0.1",
"loader.js": "^4.7.0",
"prismjs": "^1.29.0",
"prettier": "^3.0.3",
"qunit": "^2.20.0",
"qunit-dom": "^2.0.0",
Expand Down
77 changes: 51 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading