Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
aliyun_log_ruby_sdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gems
aliyun_log_ruby_sdk
Commits
d94d1b10
Commit
d94d1b10
authored
Nov 07, 2018
by
陈雨佳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
instance variables => local variables
parent
c1c919cb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
25 deletions
+23
-25
lib/aliyun_log_ruby_sdk/headers.rb
+23
-25
No files found.
lib/aliyun_log_ruby_sdk/headers.rb
View file @
d94d1b10
...
...
@@ -11,12 +11,10 @@ module AliyunLogRubySdk
X_LOG_SIGNATURE_METHOD
=
'hmac-sha1'
.
freeze
def
generate_headers
(
options
=
{})
@options
=
options
headers
=
options
[
:headers
]
||
{}
host
=
headers
.
delete
(
'x-log-host'
)
@headers
=
options
[
:headers
]
||
{}
host
=
@headers
.
delete
(
'x-log-host'
)
@headers
=
@headers
.
merge
(
'x-log-apiversion'
=>
X_LOG_API_VERSION
,
headers
=
headers
.
merge
(
'x-log-apiversion'
=>
X_LOG_API_VERSION
,
'x-log-signaturemethod'
=>
X_LOG_SIGNATURE_METHOD
,
'Date'
=>
Time
.
now
.
httpdate
,
'Host'
=>
(
host
||
"
#{
project_name
}
.
#{
endpoint
}
"
))
...
...
@@ -24,38 +22,38 @@ module AliyunLogRubySdk
body
=
options
[
:body
]
if
body
.
present?
@
headers
[
'Content-Length'
]
=
body
.
bytesize
.
to_s
@
headers
[
'Content-MD5'
]
=
calculate_md5
(
body
)
headers
[
'Content-Length'
]
=
body
.
bytesize
.
to_s
headers
[
'Content-MD5'
]
=
calculate_md5
(
body
)
else
@
headers
[
'Content-Length'
]
=
'0'
@
headers
[
'x-log-bodyrawsize'
]
=
'0'
headers
[
'Content-Length'
]
=
'0'
headers
[
'x-log-bodyrawsize'
]
=
'0'
end
@headers
[
'Authorization'
]
=
authorization
headers
[
'Authorization'
]
=
generate_authorization
(
options
[
:verb
]
||
'GET'
,
headers
,
options
[
:resource
])
@headers
[
'x-log-date'
]
=
@
headers
[
'Date'
]
headers
[
'x-log-date'
]
=
headers
[
'Date'
]
@
headers
headers
end
private
def
authorization
"LOG
#{
access_key_id
}
:
#{
signature
}
"
def
generate_authorization
(
verb
,
headers
,
resource
)
"LOG
#{
access_key_id
}
:
#{
generate_signature
(
verb
,
headers
,
resource
)
}
"
end
def
signature
Base64
.
encode64
(
OpenSSL
::
HMAC
.
digest
(
'sha1'
,
access_key_secret
,
sign_string
.
encode
(
'utf-8'
))).
rstrip
def
generate_signature
(
verb
,
headers
,
resource
)
Base64
.
encode64
(
OpenSSL
::
HMAC
.
digest
(
'sha1'
,
access_key_secret
,
generate_sign_string
(
verb
,
headers
,
resource
)
.
encode
(
'utf-8'
))).
rstrip
end
def
sign_string
def
generate_sign_string
(
verb
,
headers
,
resource
)
%W[
#{
@options
[
:verb
]
||
'GET'
}
#{
@
headers
[
'Content-MD5'
]
}
#{
@
headers
[
'Content-Type'
]
}
#{
@
headers
[
'Date'
]
}
#{
canonicalized_log_headers
}
#{
@options
[
:resource
]
}
#{
verb
}
#{
headers
[
'Content-MD5'
]
}
#{
headers
[
'Content-Type'
]
}
#{
headers
[
'Date'
]
}
#{
canonicalized_log_headers
(
headers
)
}
#{
resource
}
]
.
join
(
"
\n
"
)
end
...
...
@@ -63,8 +61,8 @@ module AliyunLogRubySdk
Digest
::
MD5
.
hexdigest
(
body
).
upcase
end
def
canonicalized_log_headers
@
headers
.
select
{
|
key
,
_value
|
key
.
match
(
/x-log-*|x-acs-*/
)
}.
map
do
|
key
,
value
|
def
canonicalized_log_headers
(
headers
)
headers
.
select
{
|
key
,
_value
|
key
.
match
(
/x-log-*|x-acs-*/
)
}.
map
do
|
key
,
value
|
"
#{
key
.
downcase
}
:
#{
value
}
"
end
.
sort
.
join
(
"
\n
"
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment