Skip to content

Commit

Permalink
logout local
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Goh committed Nov 4, 2015
1 parent 11028bb commit edbc7ee
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
4 changes: 4 additions & 0 deletions cli/definitions/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export interface ILoginCommand extends ICommand {
accessKey: string;
}

export interface ILogoutCommand extends ICommand {
isLocal: boolean;
}

export interface IPromoteCommand extends ICommand {
appName: string;
sourceDeploymentName: string;
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "code-push-cli",
"version": "1.1.1-beta",
"version": "1.1.2-beta",
"description": "Management CLI for the CodePush service",
"main": "script/cli.js",
"scripts": {
Expand Down
40 changes: 27 additions & 13 deletions cli/script/command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export function execute(command: cli.ICommand): Promise<void> {
return login(<cli.ILoginCommand>command);

case cli.CommandType.logout:
return logout();
return logout(<cli.ILogoutCommand>command);

case cli.CommandType.register:
return register(<cli.IRegisterCommand>command);
Expand Down Expand Up @@ -505,19 +505,33 @@ function loginWithAccessTokenInternal(serverUrl: string): Promise<void> {
});
}

function logout(): Promise<void> {
function logout(command: cli.ILogoutCommand): Promise<void> {
if (connectionInfo) {
return loginWithAccessToken()
.then((): Promise<string> => {
var standardLoginConnectionInfo: IStandardLoginConnectionInfo = <IStandardLoginConnectionInfo>connectionInfo;
var accessKeyLoginConnectionInfo: IAccessKeyLoginConnectionInfo = <IAccessKeyLoginConnectionInfo>connectionInfo;

if (standardLoginConnectionInfo.accessKeyName) return getAccessKeyId(standardLoginConnectionInfo.accessKeyName);
else return getAccessKeyId(accessKeyLoginConnectionInfo.accessKey);
})
.then((accessKeyId: string): Promise<void> => {
return sdk.removeAccessKey(accessKeyId);
})
var setupPromise: Promise<void> = loginWithAccessToken();
if (!command.isLocal) {
var accessKeyName: string;
setupPromise = setupPromise
.then((): Promise<string> => {
var standardLoginConnectionInfo: IStandardLoginConnectionInfo = <IStandardLoginConnectionInfo>connectionInfo;
var accessKeyLoginConnectionInfo: IAccessKeyLoginConnectionInfo = <IAccessKeyLoginConnectionInfo>connectionInfo;

if (standardLoginConnectionInfo.accessKeyName) {
accessKeyName = standardLoginConnectionInfo.accessKeyName;
return getAccessKeyId(standardLoginConnectionInfo.accessKeyName);
} else {
accessKeyName = accessKeyLoginConnectionInfo.accessKey;
return getAccessKeyId(accessKeyLoginConnectionInfo.accessKey);
}
})
.then((accessKeyId: string): Promise<void> => {
return sdk.removeAccessKey(accessKeyId);
})
.then((): void => {
log("Removed access key " + accessKeyName + ".");
});
}

return setupPromise
.then((): Promise<void> => sdk.logout(), (): Promise<void> => sdk.logout())
.then((): void => deleteConnectionInfoCache(), (): void => deleteConnectionInfoCache())
.then((): void => {
Expand Down
10 changes: 10 additions & 0 deletions cli/script/command-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ var argv = yargs.usage(USAGE_PREFIX + " <command>")
.command("logout", "Log out of the current session", (yargs: yargs.Argv) => {
isValidCommandCategory = true;
isValidCommand = true;
yargs.usage(USAGE_PREFIX + " logout [--local <true|false>]")
.demand(/*count*/ 1, /*max*/ 1) // Require exactly one non-option argument.
.example("logout", "Log out and also remove the access key used for the current session.")
.example("logout --local", "Log out but still allow the use of the same access key for future logins.")
.option("local", { demand: false, description: "Whether to delete the current session's access key on the server", type: "boolean" })
addCommonConfiguration(yargs);
})
// Disabling this for closed beta
//.command("register", "Register a new account with a specific CodePush server", (yargs: yargs.Argv) => {
Expand Down Expand Up @@ -373,6 +379,10 @@ function createCommand(): cli.ICommand {

case "logout":
cmd = { type: cli.CommandType.logout };

var logoutCommand = <cli.ILogoutCommand>cmd;

logoutCommand.isLocal = argv["local"];
break;

case "promote":
Expand Down

0 comments on commit edbc7ee

Please sign in to comment.