Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Appstream connection updates #578

Merged
merged 13 commits into from
Jul 15, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Service = require('@aws-ee/base-services-container/lib/service');

const settingKeys = {
appStreamImageName: 'appStreamImageName',
isAppStreamEnabled: 'isAppStreamEnabled',
};

class AppStreamScService extends Service {
Expand Down Expand Up @@ -76,6 +77,7 @@ class AppStreamScService extends Service {
if (!stackName) {
throw this.boom.badRequest(
`Expected stack ${stackName} to be associated with the account ${accountId} but found`,
true,
);
}

Expand All @@ -88,7 +90,10 @@ class AppStreamScService extends Service {
const { Names: fleetNames } = await appStream.listAssociatedFleets({ StackName: stackName }).promise();

if (!_.includes(fleetNames, fleetName)) {
throw this.boom.badRequest(`Expected fleet ${fleetName} to be associated with the AppStream stack but found`);
throw this.boom.badRequest(
`Expected fleet ${fleetName} to be associated with the AppStream stack but found`,
true,
);
}

return { stackName, fleetName };
Expand All @@ -110,7 +115,10 @@ class AppStreamScService extends Service {
return `${uid}-${sessionSuffix}`.replace(/[^\w+=,.@-]+/g, '').slice(0, 32);
}

async urlForFirefox(requestContext, { environmentId }) {
async getStreamingUrl(requestContext, { environmentId, applicationId }) {
const isAppStreamEnabled = this.settings.get(settingKeys.isAppStreamEnabled);
if (isAppStreamEnabled !== 'true') return undefined;

const environmentScService = await this.service('environmentScService');

const appStream = await environmentScService.getClientSdkWithEnvMgmtRole(
Expand All @@ -131,7 +139,7 @@ class AppStreamScService extends Service {
FleetName: fleetName,
StackName: stackName,
UserId: this.generateUserId(requestContext, environment),
ApplicationId: 'Firefox',
ApplicationId: applicationId,
})
.promise();

Expand All @@ -142,8 +150,10 @@ class AppStreamScService extends Service {
}

async urlForRemoteDesktop(requestContext, { environmentId, instanceId }) {
const environmentScService = await this.service('environmentScService');
const isAppStreamEnabled = this.settings.get(settingKeys.isAppStreamEnabled);
if (isAppStreamEnabled !== 'true') return undefined;

const environmentScService = await this.service('environmentScService');
const environment = await environmentScService.mustFind(requestContext, { id: environmentId });

// Get stack and fleet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ async function createConnectionUrl({ envId, connection }, { requestContext, cont
const log = await container.find('log');
// Only wraps web urls via app stream (i.e., scheme = 'http' or 'https' or no scheme)
const isHttp = connection.scheme === 'http' || connection.scheme === 'https' || _.isEmpty(connection.scheme);
const appStreamScService = await container.find('appStreamScService');

// Only wrap via AppStream if the connection.url exists
let appStreamUrl;
if (isHttp && connection.url) {
log.debug({
msg: `Target connection URL ${connection.url} will be made available for pasting into AppStream`,
msg: `Target connection URL ${connection.url} will be accessible via AppStream URL`,
connection,
});
const appStreamScService = await container.find('appStreamScService');
appStreamUrl = await appStreamScService.urlForFirefox(requestContext, {
appStreamUrl = await appStreamScService.getStreamingUrl(requestContext, {
environmentId: envId,
applicationId: 'Firefox',
});
} else if (connection.scheme === 'ssh') {
log.debug({
msg: `Target instance ${connection.instanceId} will be available for SSH connection via AppStream URL`,
connection,
});
appStreamUrl = await appStreamScService.getStreamingUrl(requestContext, {
environmentId: envId,
applicationId: 'EC2Linux',
});
} else if (connection.scheme === 'rdp') {
log.debug({
msg: `Will stream target RDP connection for instance ${connection.instanceId} via AppStream`,
connection,
});
const appStreamScService = await container.find('appStreamScService');
appStreamUrl = await appStreamScService.urlForRemoteDesktop(requestContext, {
environmentId: envId,
instanceId: connection.instanceId,
Expand All @@ -47,7 +56,7 @@ async function createConnectionUrl({ envId, connection }, { requestContext, cont
// Retain the original destination URL so we don't have to trigger another API call
connection.appstreamDestinationUrl = connection.url;

// Now rewrite connection.url to the AppStream streaming URL so it can opened in a new tab
// Now rewrite connection.url to the AppStream streaming URL so it can be opened in a new tab
connection.url = appStreamUrl;
log.debug({ msg: `Modified connection to use AppStream streaming URL ${connection.url}`, connection });
}
Expand Down

This file was deleted.

Loading