Re: Ternary if and ~ does not work quite well
On Monday, 12 October 2015 at 05:34:13 UTC, anonymous wrote: It's `assert(("foo "~ true) ? ("bar") : ("baz" == "foo bar"));` though. "foo" ~ true Stupid C implicit conversion rules...
Re: AWS API Dlang, hmac sha256 function.
On Sunday, 11 October 2015 at 23:16:51 UTC, holo wrote: auto hmac_sha256(ubyte[] key, ubyte[] msg) { auto hmac = hmac!SHA256(key); hmac.put(msg); auto digest = hmac.finish; return digest; } alias sign = hmac_sha256; std.digest.hmac already contains a helper function for this: hmac!SHA256(data, secret); The order of arguments is this way to allow chaining with UFCS: data.hmac!SHA256(secret); But it seems the documentation generator can't handle ddoc comments in templates, so unfortunately it doesn't appear in the documentation.
Re: Ternary if and ~ does not work quite well
On Monday, 12 October 2015 at 05:19:40 UTC, Andre wrote: Hi, writeln("foo "~ true ? "bar" : "baz"); André "foo" ~ true How does this compile? All i can see is a user trying to append a boolean to a string which is obvously a type error. Or are they converted to ints and then ~ would be a complement operator? In that case.. horror.
DMD Compiler 'switches'
I'm relearning D. I'm using the reference compiler (DMD) and I am a bit confused with how the compiler 'switches' are supposed to be used. I find some 'switches' that require an equal (=) symbol when a value is required to be passed in. -boundscheck=[on|safeonly|off] -color[=on|off] -conf=path -debug -debug=level -debug=ident But there are also 'switches' requiring a value that do not require/use the equal (=) symbol. -Dddocdir -Dffilename -odobjdir -offilename I'm wondering if this small irregularity should be made consistent or maybe I misunderstood something.
Re: Tell GC to use shared memory
On Thursday, 8 October 2015 at 09:25:36 UTC, tcak wrote: On Thursday, 8 October 2015 at 05:46:31 UTC, ketmar wrote: On Thursday, 8 October 2015 at 04:38:43 UTC, tcak wrote: Is it possible to modify GC (without rebuilding the compiler), so it uses a given shared memory area instead of heap for allocations? sure. you don't need to rebuild the compiler, only druntime. Any better solution? Like overriding GC class, etc. You can install your own GC proxy, see module gc.proxy in druntime, the struct Proxy and functions gc_getProxy, gc_setProxy. No need to recompile druntime. Here's an example where I install my own GC proxy to do all allocations in my arena: https://bitbucket.org/infognition/dstuff/src/97cef6d4a0438f9a9f4ff0d18f819262b8a74888/gcarena.d?at=default=file-view-default
Re: AWS API Dlang, hmac sha256 function.
Thank you for info, i changed my code to use that build in template and changed "cast(ubyte[]" to "xxx.representation" and it is still working: #!/usr/bin/rdmd -L-lcurl module sigawsv4; import std.stdio, std.process; import std.digest.sha, std.digest.hmac; import std.string; import std.conv; import std.datetime; import std.net.curl; void main() { auto accessKey = environment["AWS_ACCESS_KEY"]; auto secretKey = environment["AWS_SECRET_KEY"]; auto currentClock = Clock.currTime(UTC()); auto currentDate = cast(Date)currentClock; auto curDateStr = currentDate.toISOString; auto currentTime = cast(TimeOfDay)currentClock; auto curTimeStr = currentTime.toISOString; auto xamztime = curDateStr ~ "T" ~ curTimeStr ~ "Z"; string method = "GET"; string service = "ec2"; string host = "ec2.amazonaws.com"; string region = "us-east-1"; string endpoint = "https://ec2.amazonaws.com;; string request_parameters = "Action=DescribeInstances=2013-10-15"; alias sign = hmac!SHA256; auto getSignatureKey(string key, string dateStamp, string regionName, string serviceName) { auto kString = ("AWS4" ~ key).representation; auto kDate = sign(dateStamp.representation, kString); auto kRegion = sign(regionName.representation, kDate); auto kService = sign(serviceName.representation, kRegion); auto kSigning = sign("aws4_request".representation, kService); return kSigning; } string canonicalURI = "/"; string canonicalQueryString = request_parameters; string canonicalHeadersString = "host:" ~ host ~ "\n" ~ "x-amz-date:" ~ xamztime ~ "\n"; string signedHeaders = "host;x-amz-date"; string payloadHash = sha256Of("").toHexString.toLower; string canonicalRequest = method ~ "\n" ~ canonicalURI ~ "\n" ~ canonicalQueryString ~ "\n" ~ canonicalHeadersString ~ "\n" ~ signedHeaders ~ "\n" ~ payloadHash; string algorithm = "AWS4-HMAC-SHA256"; string credentialScope = curDateStr ~ "/" ~ region ~ "/" ~ service ~ "/" ~ "aws4_request"; string stringToSign = algorithm ~ "\n" ~ xamztime ~ "\n" ~ credentialScope ~ "\n" ~ sha256Of(canonicalRequest).toHexString.toLower; auto signingKey = getSignatureKey(secretKey, curDateStr, region, service); string signature = hmac!SHA256(stringToSign.representation, signingKey).toHexString.toLower; string authorizationHeader = algorithm ~ " " ~ "Credential=" ~ accessKey ~ "/" ~ credentialScope ~ ", " ~ "SignedHeaders=" ~ signedHeaders ~ ", " ~ "Signature=" ~ signature; auto client = HTTP(endpoint ~ "?" ~ canonicalQueryString); client.method = HTTP.Method.get; client.addRequestHeader("x-amz-date", xamztime); client.addRequestHeader("Authorization", authorizationHeader); auto content = client.perform(); writeln(content); }
Re: Hash-Table-Based Multiple Arguments Replacement
On Saturday, 10 October 2015 at 16:19:53 UTC, Nordlöw wrote: Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to string replaceWhole(string a) { switch (x) { case "a": return "1"; case "b": return "2"; default: return x; } } ? Desired interface y = x.replaceWhole!("a","x", "b","y", "c","z") or perhaps y = x.replaceWhole!(tuple("a","x"), tuple("b","y"), tuple("c","z")) kind of like "a".among!("a", "b", "c") but for replacements. It would also be nice to have a splitter that can split on any of a number of conditions being fulfilled in a similar vein.
Re: Class, constructor and inherance.
@Rikki: If you didn't need to make it easily changeable I would say not even bother with OOP at all. Basically that what i had was enough for me and on top of that i could build my app. It need to just periodically check for new instances and if they are started or stopped and count "up and running time" for billing purpose. But like i said i want to learn programming in D and basically OOP too so i want to make it "proper way". BTW: i think right now i understand what tuple is, but still don't know for what to duplicate struct functionalities :). Those Templates still don't understand but i hope that will came naturally with time and practice. eg.. they are very similar to normal functions but you can call it with types not only attributes.. strange ;) I red yours advises and try to create according to it my own first class. I moved time functions and variables to method "go" they need to be current as possible when im sending request, if wont authorization could not pass.. so i think they shouldn't be in constructor. I moved some other variables too, and created interface. From all that things came out such monster which is working and doing its job :) module sigawsv4; import std.stdio, std.process; import std.digest.sha, std.digest.hmac; import std.string; import std.conv; import std.datetime; import std.net.curl; interface credential { int go(); } class sigv4 : credential { //could be changed to take some structure as parameter instead of such ammount of attributes this(string methodStr = "GET", string serviceStr = "ec2", string hostStr = "ec2.amazonaws.com", string regionStr = "us-east-1", string endpointStr = "https://ec2.amazonaws.com;, string payloadStr = "", string parmStr = "Action=DescribeInstances=2013-10-15") { this.method = methodStr; this.service = serviceStr; this.host = hostStr; this.region = regionStr; this.endpoint = endpointStr; this.payload = payloadStr; this.request_parameters = parmStr; this.accessKey = environment.get("AWS_ACCESS_KEY"); this.secretKey = environment.get("AWS_SECRET_KEY"); } public: string method; string service; string host; string region; string endpoint; string payload; string request_parameters; int go() { //time need to be set when we are sending request not before auto currentClock = Clock.currTime(UTC()); auto currentDate = cast(Date)currentClock; auto curDateStr = currentDate.toISOString; auto currentTime = cast(TimeOfDay)currentClock; auto curTimeStr = currentTime.toISOString; auto xamztime = curDateStr ~ "T" ~ curTimeStr ~ "Z"; canonicalURI = "/"; canonicalQueryString = request_parameters; canonicalHeadersString = "host:" ~ this.host ~ "\n" ~ "x-amz-date:" ~ xamztime ~ "\n"; signedHeaders = "host;x-amz-date"; auto canonicalRequest = getCanonicalRequest(canonicalURI, canonicalQueryString, canonicalHeadersString, signedHeaders); string credentialScope = curDateStr ~ "/" ~ region ~ "/" ~ service ~ "/" ~ "aws4_request"; string stringToSign = algorithm ~ "\n" ~ xamztime ~ "\n" ~ credentialScope ~ "\n" ~ sha256Of(canonicalRequest).toHexString.toLower; auto signingKey = getSignatureKey(secretKey, curDateStr, region, service); string signature = hmac!SHA256(stringToSign.representation, signingKey).toHexString.toLower; string authorizationHeader = algorithm ~ " " ~ "Credential=" ~ accessKey ~ "/" ~ credentialScope ~ ", " ~ "SignedHeaders=" ~ signedHeaders ~ ", " ~ "Signature=" ~ signature; auto client = HTTP(endpoint ~ "?" ~ canonicalQueryString); client.method = HTTP.Method.get; client.addRequestHeader("x-amz-date", xamztime); client.addRequestHeader("Authorization", authorizationHeader); auto content = client.perform(); return content; } private: const algorithm = "AWS4-HMAC-SHA256"; string accessKey; string secretKey; string currentClock; string currentDate; string curDateStr; string currentTime; string curTimeStr; string xamztime; string canonicalURI; string canonicalQueryString; string canonicalHeadersString;
Re: Ternary if and ~ does not work quite well
On Monday, 12 October 2015 at 15:39:15 UTC, TheFlyingFiddle wrote: How does this compile? { string str = "hello"; foreach (n; [32, 119, 111, 114, 108, 100, 33]) str ~= n; import std.stdio : writeln; str.writeln;// prints "hello world!" writeln(true == 1); // true writeln(false == 0);// true string str2 = str.dup; str ~= 0; str2 ~= false; writeln(str == str2); // true str ~= 1; str2 ~= true; writeln(str == str2); // true }
Re: DMD Compiler 'switches'
On Monday 12 October 2015 17:38, ric maicle wrote: > I'm wondering if this small irregularity should be made consistent or > maybe I misunderstood something. As far as I know, the difference just happened, and there is point to it. The style without "=" is older and wasn't followed when new switches were added. Consistency between different switches has to be weighed against stability here. So far stability has won, I guess. FWIW, dmd seems to be in good company as gcc is in a similar situation. For example, `gcc -std=c11 -ofoo foo.c` is a proper gcc command line, generating the file "foo".
Re: Ternary if and ~ does not work quite well
On Monday 12 October 2015 17:39, TheFlyingFiddle wrote: > "foo" ~ true > > How does this compile? All i can see is a user trying to append a > boolean to a string which is obvously a type error. Or are they > converted to ints and then ~ would be a complement operator? In > that case.. horror. char and bool are considered integral types. In `"foo " ~ true`, true is converted to a char with a value of 1, i.e. some control character. I'm not a fan either.
Re: DMD Compiler 'switches'
On 10/12/2015 11:34 AM, Gary Willoughby wrote: On Monday, 12 October 2015 at 15:38:27 UTC, ric maicle wrote: -Dddocdir -Dffilename -odobjdir -offilename I'm wondering if this small irregularity should be made consistent or maybe I misunderstood something. Yeah, it is a bit confusing and should be tidied up (using the established deprecation path) really. If we accept that = cannot be a part of a file name then we could support -D=ddocdir as well, but I checked and = can be used as part of a name at least on Linux. Which may explain why those switches are not consistent with the rest and we cannot support -D= at this point. Ali
Re: DMD Compiler 'switches'
On Monday 12 October 2015 19:46, anonymous wrote: > and there is point to it Ugh, should have been: and there is *no* point to it.
Re: DMD Compiler 'switches'
On Tuesday, 13 October, 2015 01:46 AM, anonymous wrote: On Monday 12 October 2015 17:38, ric maicle wrote: I'm wondering if this small irregularity should be made consistent or maybe I misunderstood something. As far as I know, the difference just happened, and there is point to it. The style without "=" is older and wasn't followed when new switches were added. Consistency between different switches has to be weighed against stability here. So far stability has won, I guess. I think you made it clearer now. And changing it in minor releases will break build scripts. 'Deprecating' command line switches may be an option and possibly better addressed in a major release. Also, someone may have already filed an issue about this.
Re: Ternary if and ~ does not work quite well
On 10/12/2015 08:39 AM, TheFlyingFiddle wrote: On Monday, 12 October 2015 at 05:19:40 UTC, Andre wrote: Hi, writeln("foo "~ true ? "bar" : "baz"); André "foo" ~ true How does this compile? All i can see is a user trying to append a boolean to a string which is obvously a type error. Or are they converted to ints and then ~ would be a complement operator? In that case.. horror. Yes, horror and the mandatory link: :) http://dlang.org/type.html#integer-promotions That is why most C++ guidelines (used to) recommend against defining 'operator bool()' for user types because then objects of that type take part in expressions as integers. The common recommendation in C++ used to be to define 'operator void*()' instead, which is not integral but if I remember correctly, it had its own share of issues. (Sorry, can't find a reference for that at the moment.) C++11 made it possible to define 'operator bool()' as 'explicit' to prevent implicit conversion bugs. Ali
Writing a screen saver in D what libraries will help?
If I was writing a screensaver in D what libraries are available for opening a window and drawing sprites, etc on it. GPU accelerated if possible. I'm using Ubuntu 14.04 and latest DMD compiler.
Re: DMD Compiler 'switches'
On Tuesday, 13 October, 2015 02:39 AM, Ali Çehreli wrote: If we accept that = cannot be a part of a file name then we could support -D=ddocdir as well, but I checked and = can be used as part of a name at least on Linux. Which may explain why those switches are not consistent with the rest and we cannot support -D= at this point. I think I'm confused. I see the following switches using the = symbol: -config=path -debuglib=name -defaultlib=name -deps=filename
Re: Writing a screen saver in D what libraries will help?
On Monday, 12 October 2015 at 19:16:10 UTC, Gary Willoughby wrote: If I was writing a screensaver in D what libraries are available for opening a window and drawing sprites, etc on it. GPU accelerated if possible. I'm using Ubuntu 14.04 and latest DMD compiler. I've found Dgame which looks surprisingly good. http://rswhite.de/dgame5/?page=tutorial
Re: DMD Compiler 'switches'
On Monday, 12 October 2015 at 15:38:27 UTC, ric maicle wrote: I'm relearning D. I'm using the reference compiler (DMD) and I am a bit confused with how the compiler 'switches' are supposed to be used. I find some 'switches' that require an equal (=) symbol when a value is required to be passed in. -boundscheck=[on|safeonly|off] -color[=on|off] -conf=path -debug -debug=level -debug=ident But there are also 'switches' requiring a value that do not require/use the equal (=) symbol. -Dddocdir -Dffilename -odobjdir -offilename I'm wondering if this small irregularity should be made consistent or maybe I misunderstood something. Yeah, it is a bit confusing and should be tidied up (using the established deprecation path) really.
Re: DMD Compiler 'switches'
On Mon, Oct 12, 2015 at 11:33 AM, ric maicle via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 13 October, 2015 01:46 AM, anonymous wrote: > >> On Monday 12 October 2015 17:38, ric maicle wrote: >> >> I'm wondering if this small irregularity should be made consistent or >>> maybe I misunderstood something. >>> >> >> As far as I know, the difference just happened, and there is point to it. >> The style without "=" is older and wasn't followed when new switches were >> added. >> >> Consistency between different switches has to be weighed against stability >> here. So far stability has won, I guess. >> > > I think you made it clearer now. And changing it in minor releases will > break build scripts. 'Deprecating' command line switches may be an option > and possibly better addressed in a major release. > > Also, someone may have already filed an issue about this. > Ya I did a while ago: "new DIP41: dmd/rdmd command line overhaul." http://forum.dlang.org/thread/mailman.1468.1369129517.4724.digitalmar...@puremagic.com
Re: Writing a screen saver in D what libraries will help?
On Monday, 12 October 2015 at 19:16:10 UTC, Gary Willoughby wrote: If I was writing a screensaver in D what libraries are available for opening a window and drawing sprites, etc on it. GPU accelerated if possible. I'm using Ubuntu 14.04 and latest DMD compiler. You will need to interface to C libraries like SDL. There are bidings for it on DUB called derelict-sdl2
Re: Class, constructor and inherance.
On 13/10/15 5:56 AM, holo wrote: @Rikki: If you didn't need to make it easily changeable I would say not even bother with OOP at all. Basically that what i had was enough for me and on top of that i could build my app. It need to just periodically check for new instances and if they are started or stopped and count "up and running time" for billing purpose. But like i said i want to learn programming in D and basically OOP too so i want to make it "proper way". BTW: i think right now i understand what tuple is, but still don't know for what to duplicate struct functionalities :). Those Templates still don't understand but i hope that will came naturally with time and practice. eg.. they are very similar to normal functions but you can call it with types not only attributes.. strange ;) I red yours advises and try to create according to it my own first class. I moved time functions and variables to method "go" they need to be current as possible when im sending request, if wont authorization could not pass.. so i think they shouldn't be in constructor. I moved some other variables too, and created interface. From all that things came out such monster which is working and doing its job :) module sigawsv4; import std.stdio, std.process; import std.digest.sha, std.digest.hmac; import std.string; import std.conv; import std.datetime; import std.net.curl; interface credential { int go(); } class sigv4 : credential { //could be changed to take some structure as parameter instead of such ammount of attributes this(string methodStr = "GET", string serviceStr = "ec2", string hostStr = "ec2.amazonaws.com", string regionStr = "us-east-1", string endpointStr = "https://ec2.amazonaws.com;, string payloadStr = "", string parmStr = "Action=DescribeInstances=2013-10-15") { this.method = methodStr; this.service = serviceStr; this.host = hostStr; this.region = regionStr; this.endpoint = endpointStr; this.payload = payloadStr; this.request_parameters = parmStr; this.accessKey = environment.get("AWS_ACCESS_KEY"); this.secretKey = environment.get("AWS_SECRET_KEY"); } public: string method; string service; string host; string region; string endpoint; string payload; string request_parameters; int go() { //time need to be set when we are sending request not before auto currentClock = Clock.currTime(UTC()); auto currentDate = cast(Date)currentClock; auto curDateStr = currentDate.toISOString; auto currentTime = cast(TimeOfDay)currentClock; auto curTimeStr = currentTime.toISOString; auto xamztime = curDateStr ~ "T" ~ curTimeStr ~ "Z"; canonicalURI = "/"; canonicalQueryString = request_parameters; canonicalHeadersString = "host:" ~ this.host ~ "\n" ~ "x-amz-date:" ~ xamztime ~ "\n"; signedHeaders = "host;x-amz-date"; auto canonicalRequest = getCanonicalRequest(canonicalURI, canonicalQueryString, canonicalHeadersString, signedHeaders); string credentialScope = curDateStr ~ "/" ~ region ~ "/" ~ service ~ "/" ~ "aws4_request"; string stringToSign = algorithm ~ "\n" ~ xamztime ~ "\n" ~ credentialScope ~ "\n" ~ sha256Of(canonicalRequest).toHexString.toLower; auto signingKey = getSignatureKey(secretKey, curDateStr, region, service); string signature = hmac!SHA256(stringToSign.representation, signingKey).toHexString.toLower; string authorizationHeader = algorithm ~ " " ~ "Credential=" ~ accessKey ~ "/" ~ credentialScope ~ ", " ~ "SignedHeaders=" ~ signedHeaders ~ ", " ~ "Signature=" ~ signature; auto client = HTTP(endpoint ~ "?" ~ canonicalQueryString); client.method = HTTP.Method.get; client.addRequestHeader("x-amz-date", xamztime); client.addRequestHeader("Authorization", authorizationHeader); auto content = client.perform(); return content; } private: const algorithm = "AWS4-HMAC-SHA256"; string accessKey; string secretKey; string currentClock; string currentDate; string curDateStr; string currentTime; string curTimeStr; string xamztime; string canonicalURI; string canonicalQueryString; string canonicalHeadersString; string signedHeaders; alias sign = hmac!SHA256; auto getSignatureKey(string key, string dateStamp, string regionName, string serviceName) { auto kString = ("AWS4" ~ key).representation; auto kDate = sign(dateStamp.representation, kString); auto kRegion = sign(regionName.representation, kDate);
Re: DMD Compiler 'switches'
On 10/12/2015 01:03 PM, ric maicle wrote: On Tuesday, 13 October, 2015 02:39 AM, Ali Çehreli wrote: If we accept that = cannot be a part of a file name then we could support -D=ddocdir as well, but I checked and = can be used as part of a name at least on Linux. Which may explain why those switches are not consistent with the rest and we cannot support -D= at this point. I think I'm confused. I see the following switches using the = symbol: -config=path -debuglib=name -defaultlib=name -deps=filename Perhaps those were introduced after the other ones. I am agreeing with the other posters that we cannot fix the other ones because if anyone used = before, it was the part of the path. (Maybe... Never tried... :) ) So, we cannot change the syntax today because then some users' paths will lose the = character. Ali
Re: DMD Compiler 'switches'
On Tuesday, 13 October, 2015 05:43 AM, Ali Çehreli wrote: Perhaps those were introduced after the other ones. I am agreeing with the other posters that we cannot fix the other ones because if anyone used = before, it was the part of the path. (Maybe... Never tried... :) ) So, we cannot change the syntax today because then some users' paths will lose the = character. Would it be possible to deprecate the old syntax, provide notice to all D users and make it obsolete after a year?
Re: DMD Compiler 'switches'
On Tuesday, 13 October, 2015 06:11 AM, ric maicle wrote: Would it be possible to deprecate the old syntax, provide notice to all D users and make it obsolete after a year? Please ignore. There is already a DIP filed regarding this matter. DIP41: dmd/rdmd command line overhaul. (http://wiki.dlang.org/DIP41)
Re: Writing a screen saver in D what libraries will help?
On Monday, 12 October 2015 at 23:24:56 UTC, welkam wrote: You will need to interface to C libraries like SDL. Not necessarily any beyond the operating system libs. In fact, for a screensaver, you might want to use lower level calls. I don't know how they are made anymore, but in Windows 95 (showing my knowledge's age...) there were a few special screen saver functions you needed to implement for it to be recognized by the properties sheet. I don't know about Ubuntu at all though.
Re: Writing a screen saver in D what libraries will help?
On Monday, 12 October 2015 at 19:16:10 UTC, Gary Willoughby wrote: If I was writing a screensaver in D what libraries are available for opening a window and drawing sprites, etc on it. GPU accelerated if possible. My simpledisplay.d might be able to do it but it doesn't fully wrap stuff like full screen windows yet (it isn't hard to use the platform-specific functions to ask for one though). https://github.com/adamdruppe/arsd simpledisplay.d and color.d WIP docs here http://arsdnet.net/arsd/simpledisplay.html
Re: Class, constructor and inherance.
On Tuesday, 13 October 2015 at 02:03:46 UTC, Rikki Cattermole wrote: On 13/10/15 5:56 AM, holo wrote: @Rikki: If you didn't need to make it easily changeable I would say not even bother with OOP at all. Basically that what i had was enough for me and on top of that i could build my app. It need to just periodically check for new instances and if they are started or stopped and count "up and running time" for billing purpose. But like i said i want to learn programming in D and basically OOP too so i want to make it "proper way". BTW: i think right now i understand what tuple is, but still don't know for what to duplicate struct functionalities :). Those Templates still don't understand but i hope that will came naturally with time and practice. eg.. they are very similar to normal functions but you can call it with types not only attributes.. strange ;) I red yours advises and try to create according to it my own first class. I moved time functions and variables to method "go" they need to be current as possible when im sending request, if wont authorization could not pass.. so i think they shouldn't be in constructor. I moved some other variables too, and created interface. From all that things came out such monster which is working and doing its job :) module sigawsv4; import std.stdio, std.process; import std.digest.sha, std.digest.hmac; import std.string; import std.conv; import std.datetime; import std.net.curl; interface credential { int go(); } class sigv4 : credential { //could be changed to take some structure as parameter instead of such ammount of attributes this(string methodStr = "GET", string serviceStr = "ec2", string hostStr = "ec2.amazonaws.com", string regionStr = "us-east-1", string endpointStr = "https://ec2.amazonaws.com;, string payloadStr = "", string parmStr = "Action=DescribeInstances=2013-10-15") { this.method = methodStr; this.service = serviceStr; this.host = hostStr; this.region = regionStr; this.endpoint = endpointStr; this.payload = payloadStr; this.request_parameters = parmStr; this.accessKey = environment.get("AWS_ACCESS_KEY"); this.secretKey = environment.get("AWS_SECRET_KEY"); } public: string method; string service; string host; string region; string endpoint; string payload; string request_parameters; int go() { //time need to be set when we are sending request not before auto currentClock = Clock.currTime(UTC()); auto currentDate = cast(Date)currentClock; auto curDateStr = currentDate.toISOString; auto currentTime = cast(TimeOfDay)currentClock; auto curTimeStr = currentTime.toISOString; auto xamztime = curDateStr ~ "T" ~ curTimeStr ~ "Z"; canonicalURI = "/"; canonicalQueryString = request_parameters; canonicalHeadersString = "host:" ~ this.host ~ "\n" ~ "x-amz-date:" ~ xamztime ~ "\n"; signedHeaders = "host;x-amz-date"; auto canonicalRequest = getCanonicalRequest(canonicalURI, canonicalQueryString, canonicalHeadersString, signedHeaders); string credentialScope = curDateStr ~ "/" ~ region ~ "/" ~ service ~ "/" ~ "aws4_request"; string stringToSign = algorithm ~ "\n" ~ xamztime ~ "\n" ~ credentialScope ~ "\n" ~ sha256Of(canonicalRequest).toHexString.toLower; auto signingKey = getSignatureKey(secretKey, curDateStr, region, service); string signature = hmac!SHA256(stringToSign.representation, signingKey).toHexString.toLower; string authorizationHeader = algorithm ~ " " ~ "Credential=" ~ accessKey ~ "/" ~ credentialScope ~ ", " ~ "SignedHeaders=" ~ signedHeaders ~ ", " ~ "Signature=" ~ signature; auto client = HTTP(endpoint ~ "?" ~ canonicalQueryString); client.method = HTTP.Method.get; client.addRequestHeader("x-amz-date", xamztime); client.addRequestHeader("Authorization", authorizationHeader); auto content = client.perform(); return content; } private: const algorithm = "AWS4-HMAC-SHA256"; string accessKey; string secretKey; string currentClock; string currentDate; string curDateStr; string currentTime; string curTimeStr; string xamztime; string canonicalURI; string canonicalQueryString; string canonicalHeadersString; string signedHeaders; alias sign = hmac!SHA256; auto getSignatureKey(string key, string dateStamp, string regionName, string serviceName) { auto kString = ("AWS4" ~ key).representation; auto