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
...
@@ -11,12 +11,10 @@ module AliyunLogRubySdk
X_LOG_SIGNATURE_METHOD
=
'hmac-sha1'
.
freeze
X_LOG_SIGNATURE_METHOD
=
'hmac-sha1'
.
freeze
def
generate_headers
(
options
=
{})
def
generate_headers
(
options
=
{})
@options
=
options
headers
=
options
[
:headers
]
||
{}
host
=
headers
.
delete
(
'x-log-host'
)
@headers
=
options
[
:headers
]
||
{}
headers
=
headers
.
merge
(
'x-log-apiversion'
=>
X_LOG_API_VERSION
,
host
=
@headers
.
delete
(
'x-log-host'
)
@headers
=
@headers
.
merge
(
'x-log-apiversion'
=>
X_LOG_API_VERSION
,
'x-log-signaturemethod'
=>
X_LOG_SIGNATURE_METHOD
,
'x-log-signaturemethod'
=>
X_LOG_SIGNATURE_METHOD
,
'Date'
=>
Time
.
now
.
httpdate
,
'Date'
=>
Time
.
now
.
httpdate
,
'Host'
=>
(
host
||
"
#{
project_name
}
.
#{
endpoint
}
"
))
'Host'
=>
(
host
||
"
#{
project_name
}
.
#{
endpoint
}
"
))
...
@@ -24,38 +22,38 @@ module AliyunLogRubySdk
...
@@ -24,38 +22,38 @@ module AliyunLogRubySdk
body
=
options
[
:body
]
body
=
options
[
:body
]
if
body
.
present?
if
body
.
present?
@
headers
[
'Content-Length'
]
=
body
.
bytesize
.
to_s
headers
[
'Content-Length'
]
=
body
.
bytesize
.
to_s
@
headers
[
'Content-MD5'
]
=
calculate_md5
(
body
)
headers
[
'Content-MD5'
]
=
calculate_md5
(
body
)
else
else
@
headers
[
'Content-Length'
]
=
'0'
headers
[
'Content-Length'
]
=
'0'
@
headers
[
'x-log-bodyrawsize'
]
=
'0'
headers
[
'x-log-bodyrawsize'
]
=
'0'
end
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
end
private
private
def
authorization
def
generate_authorization
(
verb
,
headers
,
resource
)
"LOG
#{
access_key_id
}
:
#{
signature
}
"
"LOG
#{
access_key_id
}
:
#{
generate_signature
(
verb
,
headers
,
resource
)
}
"
end
end
def
signature
def
generate_signature
(
verb
,
headers
,
resource
)
Base64
.
encode64
(
OpenSSL
::
HMAC
.
digest
(
'sha1'
,
access_key_secret
,
sign_string
.
encode
(
'utf-8'
))).
rstrip
Base64
.
encode64
(
OpenSSL
::
HMAC
.
digest
(
'sha1'
,
access_key_secret
,
generate_sign_string
(
verb
,
headers
,
resource
)
.
encode
(
'utf-8'
))).
rstrip
end
end
def
sign_string
def
generate_sign_string
(
verb
,
headers
,
resource
)
%W[
%W[
#{
@options
[
:verb
]
||
'GET'
}
#{
verb
}
#{
@
headers
[
'Content-MD5'
]
}
#{
headers
[
'Content-MD5'
]
}
#{
@
headers
[
'Content-Type'
]
}
#{
headers
[
'Content-Type'
]
}
#{
@
headers
[
'Date'
]
}
#{
headers
[
'Date'
]
}
#{
canonicalized_log_headers
}
#{
canonicalized_log_headers
(
headers
)
}
#{
@options
[
:resource
]
}
#{
resource
}
]
.
join
(
"
\n
"
)
]
.
join
(
"
\n
"
)
end
end
...
@@ -63,8 +61,8 @@ module AliyunLogRubySdk
...
@@ -63,8 +61,8 @@ module AliyunLogRubySdk
Digest
::
MD5
.
hexdigest
(
body
).
upcase
Digest
::
MD5
.
hexdigest
(
body
).
upcase
end
end
def
canonicalized_log_headers
def
canonicalized_log_headers
(
headers
)
@
headers
.
select
{
|
key
,
_value
|
key
.
match
(
/x-log-*|x-acs-*/
)
}.
map
do
|
key
,
value
|
headers
.
select
{
|
key
,
_value
|
key
.
match
(
/x-log-*|x-acs-*/
)
}.
map
do
|
key
,
value
|
"
#{
key
.
downcase
}
:
#{
value
}
"
"
#{
key
.
downcase
}
:
#{
value
}
"
end
.
sort
.
join
(
"
\n
"
)
end
.
sort
.
join
(
"
\n
"
)
end
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