Permalink
Browse files

Merge pull request #14 from andrerod/appconfig

#322: Setting up config vars for a Website [app settings]
  • Loading branch information...
André Rodrigues
André Rodrigues committed Oct 24, 2012
2 parents 25a69de + c446e9f commit ff447c283bc3c8e4b3e6ee1271ce40ba51442e8e
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -26,6 +26,7 @@ var child_process = require('child_process');
var utils = require('../utils');
var constants = require('../constants');
var cacheUtils = require('../cacheUtils');
+var js2xml = require('../../util/js2xml');
var linkedRevisionControl = require('../linkedrevisioncontrol');
@@ -998,6 +999,28 @@ exports.init = function (cli) {
});
};
+ site.doSiteConfigPUT = function (config, options, _) {
+ var progress = cli.progress('Updating site config information');
+
+ if (!config.SiteConfig) {
+ config = { SiteConfig: config };
+ }
+
+ var xmlConfig = js2xml.serialize(config);
+ getChannel()
+ .path(options.subscription)
+ .path('services')
+ .path('webspaces')
+ .path(options.site.webspace)
+ .path('sites')
+ .path(options.site.name)
+ .path('config')
+ .PUT(function (req) {
+ req.write(xmlConfig);
+ req.end();
+ }, _);
+ };
+
site.doRepositoryGet = function (options, _) {
var siteData = site.doSiteGet(options, _);
return getRepositoryUri(siteData);
@@ -0,0 +1,176 @@
+/*** Generated by streamline 0.4.5 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename),__func=__rt.__func,__cb=__rt.__cb; var connectionStringParser = require("../../services/core/connectionstringparser");
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+var linkedRevisionControl = require("../linkedrevisioncontrol");
+
+exports.init = function(cli) {
+
+ var log = cli.output;
+ var site = cli.category("site");
+ var siteConfig = site.category("config").description("Commands to manage your site configurations");
+
+
+ siteConfig.command("list [name]").usage("[options] [name]").description("Show your site application settings").option("-s, --subscription <id>", "use the subscription id").execute(function __1(name, options, _) { var context, siteConfigurations; var __frame = { name: "__1", line: 30 }; return __func(_, this, arguments, __1, 2, __frame, function __$__1() {
+
+
+
+
+ context = {
+ subscription: cli.category("account").lookupSubscriptionId(options.subscription),
+ site: {
+ name: name } };
+
+
+
+ return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 8, 6, function __$__1() {
+
+ return site.doSiteConfigGet(context, __cb(_, __frame, 10, 31, function ___(__0, __1) { siteConfigurations = __1;
+ if (siteConfigurations.AppSettings.NameValuePair) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ log.table(siteConfigurations.AppSettings.NameValuePair, function(row, item) {
+ row.cell("Name", item.Name);
+ row.cell("Value", item.Value); }); }
+
+ else {
+ log.info("No app settings defined yet. You can define app settings using \"azure site config set <name>=<value>."); } ; _(); }, true)); }, true)); }); });
+
+
+
+ siteConfig.command("add <keyvaluepair> [name]").usage("[options] <keyvaluepair> [name]").description("Adds an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __2(keyvaluepair, name, options, _) { var context, settings, siteConfigurations, setting; var __frame = { name: "__2", line: 57 }; return __func(_, this, arguments, __2, 3, __frame, function __$__2() {
+
+
+
+
+ context = {
+ subscription: cli.category("account").lookupSubscriptionId(options.subscription),
+ site: {
+ name: name },
+
+ keyvaluepair: keyvaluepair };
+
+
+ settings = connectionStringParser.parse(context.keyvaluepair);
+
+ return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 11, 6, function __$__2() {
+ return site.doSiteConfigGet(context, __cb(_, __frame, 12, 31, function ___(__0, __1) { siteConfigurations = __1;
+
+ if ((Object.keys(settings).length > 0)) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ for (setting in settings) {
+ if (settings.hasOwnProperty(setting)) {
+ if (siteConfigurations.AppSettings.NameValuePair.some(function(kvp) {
+ return (kvp.Name === setting);
+ })) {
+
+ return _(new Error((("Application setting with key \"" + setting) + "\" already exists."))); } ;
+
+
+ siteConfigurations.AppSettings.NameValuePair.push({
+ Name: setting,
+ Value: settings[setting] }); } ; }; } ;
+
+
+
+
+
+ return site.doSiteConfigPUT(siteConfigurations, context, __cb(_, __frame, 34, 6, _, true)); }, true)); }, true)); }); });
+
+
+ siteConfig.command("clear <key> [name]").usage("[options] <key> [name]").description("Clears an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __3(key, name, options, _) { var context, siteConfigurations, found, i; var __frame = { name: "__3", line: 98 }; return __func(_, this, arguments, __3, 3, __frame, function __$__3() {
+
+
+
+
+ context = {
+ subscription: cli.category("account").lookupSubscriptionId(options.subscription),
+ site: {
+ name: name },
+
+ key: key };
+
+
+ return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 9, 6, function __$__3() {
+ return site.doSiteConfigGet(context, __cb(_, __frame, 10, 31, function ___(__0, __1) { siteConfigurations = __1;
+
+ found = false; return (function __$__3(__then) {
+ if (siteConfigurations.AppSettings.NameValuePair) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ for (i = 0; (i < siteConfigurations.AppSettings.NameValuePair.length); i++) {
+ if ((siteConfigurations.AppSettings.NameValuePair[i].Name === key)) {
+ siteConfigurations.AppSettings.NameValuePair.splice(i, 1);
+ found = true;
+ i--; } ; }; return (function __$__3(__then) {
+
+
+
+ if (found) {
+ if ((siteConfigurations.AppSettings.NameValuePair.length === 0)) {
+ siteConfigurations.AppSettings = { }; } ;
+
+
+ return site.doSiteConfigPUT(siteConfigurations, context, __cb(_, __frame, 29, 10, __then, true)); } else { __then(); } ; })(__then); } else { __then(); } ; })(function __$__3() {
+
+
+
+ if (!found) {
+ return _(Error((("Application setting with key \"" + key) + "\" does not exist."))); } ; _(); }); }, true)); }, true)); }); });
+
+
+
+ siteConfig.command("get <key> [name]").usage("[options] <key> [name]").description("Gets an application setting for your site").option("-s, --subscription <id>", "use the subscription id").execute(function __4(key, name, options, _) { var context, siteConfigurations, found, i; var __frame = { name: "__4", line: 140 }; return __func(_, this, arguments, __4, 3, __frame, function __$__4() {
+
+
+
+
+ context = {
+ subscription: cli.category("account").lookupSubscriptionId(options.subscription),
+ site: {
+ name: name },
+
+ key: key };
+
+
+ return site.lookupSiteNameAndWebSpace(context, __cb(_, __frame, 9, 6, function __$__4() {
+ return site.doSiteConfigGet(context, __cb(_, __frame, 10, 31, function ___(__0, __1) { siteConfigurations = __1;
+
+ found = false;
+ if (siteConfigurations.AppSettings.NameValuePair) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ for (i = 0; (i < siteConfigurations.AppSettings.NameValuePair.length); i++) {
+ if ((siteConfigurations.AppSettings.NameValuePair[i].Name === key)) {
+ log.data("Value: ", siteConfigurations.AppSettings.NameValuePair[i].Value); return _(null); } ; }; } ;
+
+
+
+
+
+ if (!found) {
+ return _(Error((("Application setting with key \"" + key) + "\" does not exist."))); } ; _(); }, true)); }, true)); }); });
+
+
+
+ function getSettings(appSettings) {
+ if (!appSettings.NameValuePair) {
+ appSettings.NameValuePair = []; }
+ else if (appSettings.NameValuePair.Name) {
+ appSettings.NameValuePair = [appSettings.NameValuePair,]; } ;
+
+
+ return appSettings; };};
@@ -0,0 +1,178 @@
+/**
+* Copyright (c) Microsoft. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+var connectionStringParser = require('../../services/core/connectionstringparser');
+var linkedRevisionControl = require('../linkedrevisioncontrol');
+
+exports.init = function (cli) {
+
+ var log = cli.output;
+ var site = cli.category('site');
+ var siteConfig = site.category('config')
+ .description('Commands to manage your site configurations');
+
+ siteConfig.command('list [name]')
+ .usage('[options] [name]')
+ .description('Show your site application settings')
+ .option('-s, --subscription <id>', 'use the subscription id')
+ .execute(function (name, options, _) {
+ var context = {
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: name
+ }
+ };
+
+ site.lookupSiteNameAndWebSpace(context, _);
+
+ var siteConfigurations = site.doSiteConfigGet(context, _);
+ if (siteConfigurations.AppSettings.NameValuePair) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ log.table(siteConfigurations.AppSettings.NameValuePair, function (row, item) {
+ row.cell('Name', item.Name);
+ row.cell('Value', item.Value);
+ });
+ } else {
+ log.info('No app settings defined yet. You can define app settings using "azure site config set <name>=<value>.');
+ }
+ });
+
+ siteConfig.command('add <keyvaluepair> [name]')
+ .usage('[options] <keyvaluepair> [name]')
+ .description('Adds an application setting for your site')
+ .option('-s, --subscription <id>', 'use the subscription id')
+ .execute(function (keyvaluepair, name, options, _) {
+ var context = {
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: name
+ },
+ keyvaluepair: keyvaluepair
+ };
+
+ var settings = connectionStringParser.parse(context.keyvaluepair);
+
+ site.lookupSiteNameAndWebSpace(context, _);
+ var siteConfigurations = site.doSiteConfigGet(context, _);
+
+ if (Object.keys(settings).length > 0) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ for (var setting in settings) {
+ if (settings.hasOwnProperty(setting)) {
+ if (siteConfigurations.AppSettings.NameValuePair.some(function (kvp) {
+ return kvp.Name === setting;
+ })) {
+ // add should throw if any of the added kvp already exists
+ throw new Error('Application setting with key "' + setting + '" already exists.');
+ }
+
+ siteConfigurations.AppSettings.NameValuePair.push({
+ Name: setting,
+ Value: settings[setting]
+ });
+ }
+ }
+ }
+
+ site.doSiteConfigPUT(siteConfigurations, context, _);
+ });
+
+ siteConfig.command('clear <key> [name]')
+ .usage('[options] <key> [name]')
+ .description('Clears an application setting for your site')
+ .option('-s, --subscription <id>', 'use the subscription id')
+ .execute(function (key, name, options, _) {
+ var context = {
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: name
+ },
+ key: key
+ };
+
+ site.lookupSiteNameAndWebSpace(context, _);
+ var siteConfigurations = site.doSiteConfigGet(context, _);
+
+ var found = false;
+ if (siteConfigurations.AppSettings.NameValuePair) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ for (var i = 0; i < siteConfigurations.AppSettings.NameValuePair.length; i++) {
+ if (siteConfigurations.AppSettings.NameValuePair[i].Name === key) {
+ siteConfigurations.AppSettings.NameValuePair.splice(i, 1);
+ found = true;
+ i--;
+ }
+ }
+
+ if (found) {
+ if (siteConfigurations.AppSettings.NameValuePair.length === 0) {
+ siteConfigurations.AppSettings = { };
+ }
+
+ site.doSiteConfigPUT(siteConfigurations, context, _);
+ }
+ }
+
+ if (!found) {
+ throw Error('Application setting with key "' + key + '" does not exist.')
+ }
+ });
+
+ siteConfig.command('get <key> [name]')
+ .usage('[options] <key> [name]')
+ .description('Gets an application setting for your site')
+ .option('-s, --subscription <id>', 'use the subscription id')
+ .execute(function (key, name, options, _) {
+ var context = {
+ subscription: cli.category('account').lookupSubscriptionId(options.subscription),
+ site: {
+ name: name
+ },
+ key: key
+ };
+
+ site.lookupSiteNameAndWebSpace(context, _);
+ var siteConfigurations = site.doSiteConfigGet(context, _);
+
+ var found = false;
+ if (siteConfigurations.AppSettings.NameValuePair) {
+ siteConfigurations.AppSettings = getSettings(siteConfigurations.AppSettings);
+
+ for (var i = 0; i < siteConfigurations.AppSettings.NameValuePair.length; i++) {
+ if (siteConfigurations.AppSettings.NameValuePair[i].Name === key) {
+ log.data('Value: ', siteConfigurations.AppSettings.NameValuePair[i].Value);
+ return;
+ }
+ }
+ }
+
+ if (!found) {
+ throw Error('Application setting with key "' + key + '" does not exist.')
+ }
+ });
+
+ function getSettings(appSettings) {
+ if (!appSettings.NameValuePair) {
+ appSettings.NameValuePair = [ ];
+ } else if (appSettings.NameValuePair.Name) {
+ appSettings.NameValuePair = [ appSettings.NameValuePair ];
+ }
+
+ return appSettings;
+ };
+};
Oops, something went wrong.

0 comments on commit ff447c2

Please sign in to comment.