This repository has been archived by the owner on May 5, 2023. It is now read-only.
/
servicemanagementsettings.js
120 lines (105 loc) · 3.69 KB
/
servicemanagementsettings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* 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 url = require('url');
var util = require('../../util/util');
var ConnectionStringParser = require('./connectionstringparser');
var ServiceSettings = require('./servicesettings');
var Constants = require('../../util/constants');
var ConnectionStringKeys = Constants.ConnectionStringKeys;
var Validate = require('../../util/validate');
exports = module.exports = ServiceManagementSettings;
var endpointSetting = ServiceSettings.settingWithFunc(
ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
Validate.isValidUri
);
var certificatePathSetting = ServiceSettings.setting(ConnectionStringKeys.CERTIFICATE_PATH_NAME);
var subscriptionIdSetting = ServiceSettings.setting(ConnectionStringKeys.SUBSCRIPTION_ID_NAME);
var validKeys = [
ConnectionStringKeys.SUBSCRIPTION_ID_NAME,
ConnectionStringKeys.CERTIFICATE_PATH_NAME,
ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME
];
/**
* Creates new service management settings instance.
*
* @param {string} subscriptionId The user provided subscription id.
* @param {string} endpointUri The service management endpoint uri.
* @param {string} certificatePath The management certificate path.
*/
function ServiceManagementSettings(subscriptionId, endpointUri, certificatePath) {
this._subscriptionId = subscriptionId;
this._endpointUri = endpointUri;
this._certificatePath = certificatePath;
}
/**
* Creates a ServiceBusSettings object from a set of settings.
*
* @param {object} settings The settings object.
*
* @return {ServiceManagementSettings}
*/
ServiceManagementSettings.createFromSettings = function (settings) {
var matchedSpecs = ServiceSettings.matchedSpecification(
settings,
ServiceSettings.allRequired(
subscriptionIdSetting,
certificatePathSetting
),
ServiceSettings.optional(
endpointSetting
)
);
if (matchedSpecs) {
var endpointUri = util.tryGetValueInsensitive(
ConnectionStringKeys.SERVICE_MANAGEMENT_ENDPOINT_NAME,
settings,
Constants.SERVICE_MANAGEMENT_URL
);
var subscriptionId = util.tryGetValueInsensitive(
ConnectionStringKeys.SUBSCRIPTION_ID_NAME,
settings
);
var certificatePath = util.tryGetValueInsensitive(
ConnectionStringKeys.CERTIFICATE_PATH_NAME,
settings
);
return new ServiceManagementSettings(
subscriptionId,
endpointUri,
certificatePath
);
}
ServiceSettings.noMatchSettings(settings);
};
/**
* Creates a ServiceManagementSettings object from the given connection string.
*
* @param {string} connectionString The storage settings connection string.
*
* @return {ServiceManagementSettings}
*/
ServiceManagementSettings.createFromConnectionString = function (connectionString) {
var tokenizedSettings = ServiceSettings.parseAndValidateKeys(connectionString, validKeys);
try {
return ServiceManagementSettings.createFromSettings(tokenizedSettings);
} catch (e) {
if (e instanceof ServiceSettings.NoMatchError) {
// Replace no match settings exception by no match connection string one.
ServiceSettings.noMatchConnectionString(connectionString);
} else {
throw e;
}
}
}