2020-09-18 10:59:07 -04:00
|
|
|
import GeneratedSessionModel from '../generated/models/session';
|
2020-10-05 16:09:34 -04:00
|
|
|
import { computed } from '@ember/object';
|
2021-02-05 16:57:06 -05:00
|
|
|
import { equal } from '@ember/object/computed';
|
2021-06-04 11:31:29 -07:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2021-06-23 16:36:05 -04:00
|
|
|
import { A } from '@ember/array';
|
|
|
|
|
|
|
|
|
|
class SessionCredential {
|
|
|
|
|
// =attributes
|
|
|
|
|
rawCredential;
|
|
|
|
|
credential_library_id;
|
|
|
|
|
credential_library_name;
|
|
|
|
|
credential_library_description;
|
|
|
|
|
credential_library_type;
|
|
|
|
|
purpose;
|
|
|
|
|
#secret;
|
|
|
|
|
|
|
|
|
|
get secret() {
|
|
|
|
|
return atob(this.#secret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
|
|
|
|
|
constructor(cred) {
|
|
|
|
|
this.rawCredential = cred;
|
|
|
|
|
this.credential_library_id = cred.credential_library.id;
|
|
|
|
|
this.credential_library_name = cred.credential_library.name;
|
|
|
|
|
this.credential_library_description = cred.credential_library.description;
|
|
|
|
|
this.credential_library_type = cred.credential_library.type;
|
|
|
|
|
this.purpose = cred.purpose;
|
|
|
|
|
this.#secret = cred.secret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-18 10:16:40 -04:00
|
|
|
|
2020-09-18 10:59:07 -04:00
|
|
|
export default class SessionModel extends GeneratedSessionModel {
|
2020-10-05 16:09:34 -04:00
|
|
|
// =attributes
|
|
|
|
|
|
2021-06-23 16:36:05 -04:00
|
|
|
// These transient attributes are used for values that come from the CLI
|
|
|
|
|
// `connect` command as triggered by Desktop. These attributes represent
|
|
|
|
|
// transient read-only values.
|
2021-06-04 11:31:29 -07:00
|
|
|
@tracked acknowledged;
|
|
|
|
|
@tracked started_desktop_client;
|
2021-06-14 17:08:48 -04:00
|
|
|
@tracked proxy_address;
|
|
|
|
|
@tracked proxy_port;
|
2021-06-23 16:36:05 -04:00
|
|
|
credentials = A();
|
2021-02-03 14:29:13 -05:00
|
|
|
|
2021-02-05 16:57:06 -05:00
|
|
|
@equal('status', 'active') isActive;
|
|
|
|
|
@equal('status', 'pending') isPending;
|
|
|
|
|
|
2020-10-05 16:09:34 -04:00
|
|
|
/**
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
2021-02-05 16:57:06 -05:00
|
|
|
@computed('isActive', 'isPending')
|
2020-10-05 16:09:34 -04:00
|
|
|
get isCancelable() {
|
2021-02-05 16:57:06 -05:00
|
|
|
return this.isActive || this.isPending;
|
2020-10-05 16:09:34 -04:00
|
|
|
}
|
|
|
|
|
|
2021-02-03 14:29:13 -05:00
|
|
|
/**
|
|
|
|
|
* The full proxy address and port if address exists, otherwise null.
|
|
|
|
|
* @type {?string}
|
|
|
|
|
*/
|
|
|
|
|
@computed('proxy_address', 'proxy_port')
|
|
|
|
|
get proxy() {
|
|
|
|
|
return this.proxy_address
|
|
|
|
|
? `${this.proxy_address}:${this.proxy_port}`
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-10 13:19:24 -05:00
|
|
|
/**
|
|
|
|
|
* The target associated with this session (if loaded).
|
|
|
|
|
* @type {TargetModel}
|
|
|
|
|
*/
|
|
|
|
|
get target() {
|
|
|
|
|
return this.store.peekRecord('target', this.target_id);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 10:59:07 -04:00
|
|
|
// =methods
|
|
|
|
|
|
2021-06-23 16:36:05 -04:00
|
|
|
addCredential(cred) {
|
|
|
|
|
this.credentials.pushObject(new SessionCredential(cred));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 10:59:07 -04:00
|
|
|
/**
|
|
|
|
|
* Cancels the session via the `cancel` method.
|
|
|
|
|
* See serializer and adapter for more information.
|
|
|
|
|
* @param {object} options
|
|
|
|
|
* @param {object} options.adapterOptions
|
|
|
|
|
* @return {Promise}
|
|
|
|
|
*/
|
|
|
|
|
cancelSession(options = { adapterOptions: {} }) {
|
|
|
|
|
const defaultAdapterOptions = {
|
|
|
|
|
method: 'cancel',
|
|
|
|
|
};
|
|
|
|
|
return this.save({
|
|
|
|
|
...options,
|
|
|
|
|
adapterOptions: {
|
|
|
|
|
...defaultAdapterOptions,
|
|
|
|
|
...options.adapterOptions,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|