Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | 1x 1x 135x 135x 135x 142x 142x 142x 1x 142x 1136x 135x 124x 124x 124x 124x 138x 124x 15x 5x 123x 122x 7x | import util from "./aws-util";
/**
* Represents your RSTREAMS configuration
* Creating a `Configuration` object allows you to pass around your
* coinfig information to configuration and service objects.
*
*
* ## Expiring and Refreshing Configuration
*
* Occasionally configuration can expire in the middle of a long-running
* application. In this case, the SDK will automatically attempt to
* refresh the configuration from the storage location if the Configuration
* class implements the {refresh} method.
*
* If you are implementing a configuration storage location, you
* will want to create a subclass of the `Configuration` class and
* override the {refresh} method. This method allows configuration to be
* retrieved from the backing store, be it a file system, database, or
* some network storage. The method should reset the configuration attributes
* on the object.
*
* @!attribute expired
* @return [Boolean] whether the configuration have been expired and
* require a refresh. Used in conjunction with {expireTime}.
* @!attribute expireTime
* @return [Date] a time when configuration should be considered expired. Used
* in conjunction with {expired}.
*/
export default class Configuration {
expireTime: number = 0;
expired: boolean = false;
Region: string;
LeoStream: string;
LeoEvent: string;
LeoS3: string;
LeoKinesisStream: string;
LeoFirehoseStream: string;
LeoSettings: string;
LeoCron: string;
/**
* A configuration object can be created using positional arguments or an options
* hash.
*
*/
constructor(config: any = {}) {
this.update(config)
}
update(config: any = {}) {
this.expired = false;
this.expireTime = 0;
// Got verbose style so switch it to just the resource style
if (config.s3 && config.resources) {
config = config.resources;
}
[
"Region",
"LeoStream",
"LeoCron",
"LeoEvent",
"LeoS3",
"LeoKinesisStream",
"LeoFirehoseStream",
"LeoSettings"
].forEach(field => {
this[field] = config[field];
});
}
/**
* @return [Integer] the number of seconds before {expireTime} during which
* the configuration will be considered expired.
*/
expiryWindow: number = 15;
/**
* @return [Boolean] whether the configuration object should call {refresh}
* @note Subclasses should override this method to provide custom refresh
* logic.
*/
needsRefresh() {
var currentTime = util.date.getDate().getTime();
var adjustedTime = new Date(currentTime + this.expiryWindow * 1000);
Iif (this.expireTime && adjustedTime.valueOf() > this.expireTime) {
return true;
} else {
let valid = [
"Region",
"LeoStream",
"LeoCron",
"LeoEvent",
"LeoS3",
"LeoKinesisStream",
"LeoFirehoseStream",
"LeoSettings"
].every(field => {
return this[field] != null || field === "LeoSettings";
});
return this.expired || !valid
}
}
resolveSync() {
this.getSync();
return {
Region: this.Region,
LeoStream: this.LeoStream,
LeoCron: this.LeoCron,
LeoEvent: this.LeoEvent,
LeoS3: this.LeoS3,
LeoKinesisStream: this.LeoKinesisStream,
LeoFirehoseStream: this.LeoFirehoseStream,
LeoSettings: this.LeoSettings,
};
}
/**
* Gets the existing configuration, refreshing them if they are not yet loaded
* or have expired. Users should call this method before using {refresh},
* as this will not attempt to reload configuration when they are already
* loaded into the object.
*/
getSync() {
if (this.needsRefresh()) {
this.refreshSync();
this.expired = false;
}
}
/**
* Refreshes the configuration. Users should call {get} before attempting
* to forcibly refresh configuration.
*
* @note Subclasses should override this class to reset then
* configuration object and then call the callback with
* any error information.
* @see get
*/
refreshSync() {
this.expired = false;
}
};
|