in device/core/src/iotedge_authentication_provider.ts [62:109]
constructor(private _authConfig: EdgedAuthConfig, tokenValidTimeInSeconds?: number, tokenRenewalMarginInSeconds?: number) {
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_016: [ The constructor shall create the initial token value using the credentials parameter. ]
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_017: [ The constructor shall throw an ArgumentError if the tokenRenewalMarginInSeconds is less than or equal tokenValidTimeInSeconds. ]
super(
{
host: _authConfig && _authConfig.iothubHostName,
deviceId: _authConfig && _authConfig.deviceId,
moduleId: _authConfig && _authConfig.moduleId,
gatewayHostName: _authConfig && _authConfig.gatewayHostName
},
tokenValidTimeInSeconds,
tokenRenewalMarginInSeconds
);
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_001: [ The constructor shall throw a ReferenceError if the _authConfig parameter is falsy. ]
if (!this._authConfig) {
throw new ReferenceError('_authConfig cannot be \'' + _authConfig + '\'');
}
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_002: [ The constructor shall throw a ReferenceError if the _authConfig.workloadUri field is falsy. ]
if (!this._authConfig.workloadUri) {
throw new ReferenceError('_authConfig.workloadUri cannot be \'' + this._authConfig.workloadUri + '\'');
}
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_003: [ The constructor shall throw a ReferenceError if the _authConfig.moduleId field is falsy. ]
if (!this._authConfig.moduleId) {
throw new ReferenceError('_authConfig.moduleId cannot be \'' + this._authConfig.moduleId + '\'');
}
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_004: [ The constructor shall throw a ReferenceError if the _authConfig.generationId field is falsy. ]
if (!this._authConfig.generationId) {
throw new ReferenceError('_authConfig.generationId cannot be \'' + this._authConfig.generationId + '\'');
}
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_005: [ The constructor shall throw a TypeError if the _authConfig.workloadUri field is not a valid URI. ]
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_006: [ The constructor shall build a unix domain socket path host if the workload URI protocol is unix. ]
// Codes_SRS_NODE_IOTEDGED_AUTHENTICATION_PROVIDER_13_007: [ The constructor shall build a string host if the workload URI protocol is not unix. ]
this._workloadUri = url.parse(this._authConfig.workloadUri);
const config: RestApiClient.TransportConfig = {
host: this._workloadUri.protocol === 'unix:' ? { socketPath: this._workloadUri.pathname } : this._workloadUri.hostname,
tokenCredential: undefined
};
// Consider: The user agent string below needs to be constructed using the utils.getUserAgentString function.
// But that is an async function and since we can't do async things while initializing fields, one way to
// handle this might be to make this._restApiClient a lazily initialized object.
this._restApiClient = new RestApiClient(config, `${packageJson.name}/${packageJson.version}`);
}