Skip to content

Commit

Permalink
Merge pull request #155 from Microsoft/change-accesskey-add
Browse files Browse the repository at this point in the history
Change the SDK's addAccessKey() method to be more consumable
  • Loading branch information
Richard Hua committed Mar 8, 2016
2 parents 2e41c0b + 4538687 commit a4f9e3c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
13 changes: 6 additions & 7 deletions cli/script/command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ export var confirm = (): Promise<boolean> => {
}

function accessKeyAdd(command: cli.IAccessKeyAddCommand): Promise<void> {
var hostname: string = os.hostname();
return sdk.addAccessKey(hostname, command.description)
return sdk.addAccessKey(command.description)
.then((accessKey: AccessKey) => {
log("Successfully created a new access key" + (command.description ? (" \"" + command.description + "\"") : "") + ": " + accessKey.name);
});
Expand Down Expand Up @@ -844,8 +843,8 @@ function promote(command: cli.IPromoteCommand): Promise<void> {
export var release = (command: cli.IReleaseCommand): Promise<void> => {
if (isBinaryOrZip(command.package)) {
throw new Error("It is unnecessary to package releases in a .zip or binary file. Please specify the direct path to the update content's directory (e.g. /platforms/ios/www) or file (e.g. main.jsbundle).");
}
}

throwForInvalidSemverRange(command.appStoreVersion);
var filePath: string = command.package;
var getPackageFilePromise: Promise<IPackageFile>;
Expand Down Expand Up @@ -968,11 +967,11 @@ export var releaseReact = (command: cli.IReleaseReactCommand): Promise<void> =>
throw new Error(`Entry file "${entryFile}" does not exist.`);
}
}

if (command.appStoreVersion) {
throwForInvalidSemverRange(command.appStoreVersion);
}

var appVersionPromise: Promise<string> = command.appStoreVersion
? Q(command.appStoreVersion)
: getReactNativeProjectAppVersion(platform, projectName);
Expand Down Expand Up @@ -1100,7 +1099,7 @@ function throwForInvalidSemverRange(semverRange: string): void {
if (semver.validRange(semverRange) === null) {
throw new Error("Please use a semver-compliant target binary version range, for example \"1.0.0\", \"*\" or \"^1.2.3\".");
}
}
}

function throwForInvalidOutputFormat(format: string): void {
switch (format) {
Expand Down
2 changes: 1 addition & 1 deletion cli/test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class SdkStub {
});
}

public addAccessKey(machine: string, description?: string): Promise<codePush.AccessKey> {
public addAccessKey(description: string): Promise<codePush.AccessKey> {
return Q(<codePush.AccessKey>{
name: "key123",
createdTime: new Date().getTime(),
Expand Down
15 changes: 11 additions & 4 deletions sdk/script/management-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as base64 from "base-64";
import Q = require("q");
import crypto = require("crypto");
import Promise = Q.Promise;
import * as os from "os";
import Q = require("q");
import superagent = require("superagent");

import Promise = Q.Promise;

import { AccessKey, Account, App, CodePushError, CollaboratorMap, CollaboratorProperties, Deployment, DeploymentMetrics, Headers, Package, UpdateMetrics } from "./types";

var packageJson = require("../package.json");
Expand Down Expand Up @@ -88,8 +90,13 @@ class AccountManager {
});
}

public addAccessKey(machine: string, description?: string): Promise<AccessKey> {
var accessKeyRequest: AccessKey = { createdBy: machine, description: description };
public addAccessKey(description: string): Promise<AccessKey> {
if (!description) {
throw new Error("A description must be specified when adding an access key.");
}

var hostname: string = os.hostname();
var accessKeyRequest: AccessKey = { createdBy: hostname, description: description };
return this.post(urlEncode `/accessKeys/`, JSON.stringify(accessKeyRequest), /*expectResponseBody=*/ true)
.then((response: JsonResponse) => response.body.accessKey);
}
Expand Down

0 comments on commit a4f9e3c

Please sign in to comment.