Skip to content

Commit 9c55766

Browse files
author
Daniel Borkan
committed
Cleanup cloud invite code to not require SSH access
1 parent 2718645 commit 9c55766

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/cloud/social/provider.ts

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ interface Invite {
4343
pass?: string;
4444
// Private key, base64-encoded.
4545
key?: string;
46+
// Is Admin.
47+
isAdmin?: boolean;
4648
}
4749

4850
// Type of the object placed, in serialised form, in storage
@@ -130,11 +132,9 @@ function makeClientState(address: string): freedom.Social.ClientState {
130132
// the status field since remote-user.ts#update will use FRIEND as a default.
131133
function makeUserProfile(
132134
address: string,
133-
username :string): freedom.Social.UserProfile {
134-
var status = UserStatus.CLOUD_INSTANCE_SHARED_WITH_LOCAL;
135-
if (username === ADMIN_USERNAME) {
136-
status = UserStatus.CLOUD_INSTANCE_CREATED_BY_LOCAL;
137-
}
135+
isAdmin :boolean): freedom.Social.UserProfile {
136+
var status = isAdmin ? UserStatus.CLOUD_INSTANCE_CREATED_BY_LOCAL :
137+
UserStatus.CLOUD_INSTANCE_SHARED_WITH_LOCAL;
138138
return {
139139
userId: address,
140140
name: address,
@@ -180,7 +180,7 @@ export class CloudSocialProvider {
180180
// in the contacts list.
181181
private notifyOfUser_ = (invite: Invite, description?: string) => {
182182
this.dispatchEvent_('onUserProfile',
183-
makeUserProfile(invite.host, invite.user));
183+
makeUserProfile(invite.host, invite.isAdmin));
184184

185185
var clientState = makeClientState(invite.host);
186186
this.dispatchEvent_('onClientState', clientState);
@@ -363,26 +363,18 @@ export class CloudSocialProvider {
363363
// social2
364364
////
365365

366-
// Returns a new invite code for the specified server.
367-
// Rejects if the user is not logged in as an admin or there
368-
// is any error executing the command.
369-
// TODO: typings for invite codes
370-
public inviteUser = (clientId: string): Promise<Object> => {
366+
// Returns the invite code for the specified server.
367+
public inviteUser = (host: string): Promise<Object> => {
371368
log.debug('inviteUser');
372-
if (!(clientId in this.savedContacts_)) {
373-
return Promise.reject({
374-
message: 'unknown cloud instance ' + clientId
375-
});
369+
if (!(host in this.savedContacts_)) {
370+
return Promise.reject({message: 'unknown cloud instance ' + host});
376371
}
377-
if (this.savedContacts_[clientId].invite.user !== ADMIN_USERNAME) {
378-
return Promise.reject({
379-
message: 'user is logged in as non-admin user ' +
380-
this.savedContacts_[clientId].invite.user
381-
});
382-
}
383-
return this.reconnect_(this.savedContacts_[clientId].invite).then(
384-
(connection: Connection) => {
385-
return connection.issueInvite();
372+
const invite = this.savedContacts_[host].invite;
373+
return Promise.resolve({
374+
host: invite.host,
375+
user: invite.user,
376+
key: invite.key,
377+
isAdmin: false
386378
});
387379
}
388380

@@ -564,13 +556,6 @@ class Connection {
564556
return this.exec_('cat /banner');
565557
}
566558

567-
// Returns a base64-decoded, deserialised invite code.
568-
public issueInvite = (): Promise<Object> => {
569-
return this.exec_('sudo /issue_invite.sh').then((inviteCode: string) => {
570-
return JSON.parse(new Buffer(inviteCode, 'base64').toString());
571-
});
572-
}
573-
574559
// Executes a command, fulfilling with the command's stdout
575560
// or rejecting if output is received on stderr.
576561
private exec_ = (command:string): Promise<string> => {

0 commit comments

Comments
 (0)