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
b0ed40d9
Commit
b0ed40d9
authored
Nov 07, 2018
by
陈雨佳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate resource
parent
d94d1b10
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
41 additions
and
40 deletions
+41
-40
README.md
+1
-1
lib/aliyun_log_ruby_sdk/client.rb
+10
-12
lib/aliyun_log_ruby_sdk/consumer_group.rb
+3
-4
lib/aliyun_log_ruby_sdk/headers.rb
+15
-8
lib/aliyun_log_ruby_sdk/index.rb
+2
-3
lib/aliyun_log_ruby_sdk/log_store.rb
+3
-3
lib/aliyun_log_ruby_sdk/shard.rb
+5
-6
lib/aliyun_log_ruby_sdk/shipper.rb
+2
-3
No files found.
README.md
View file @
b0ed40d9
# 阿里云日志SDK
### https://help.aliyun.com/product/28958.html
?spm=a2c4g.750001.9.1.1f087b13e7djrJ
### https://help.aliyun.com/product/28958.html
### 依赖
...
...
lib/aliyun_log_ruby_sdk/client.rb
View file @
b0ed40d9
...
...
@@ -32,7 +32,6 @@ module AliyunLogRubySdk
:access_key_id
,
:access_key_secret
,
:project_name
,
:log_store_name
,
:debug
,
to: :'AliyunLogRubySdk.config'
...
...
@@ -43,8 +42,9 @@ module AliyunLogRubySdk
def
get
(
path
,
options
=
{})
options
[
:headers
]
||=
{}
headers
=
generate_headers
(
headers:
options
[
:headers
],
resource:
generate_resource
(
path
,
options
[
:query
]))
headers
=
generate_headers
(
path:
path
,
query:
options
[
:query
],
headers:
options
[
:headers
])
response
=
self
.
class
.
get
(
path
,
query:
options
[
:query
],
headers:
headers
)
...
...
@@ -74,8 +74,8 @@ module AliyunLogRubySdk
end
headers
=
generate_headers
(
verb:
'POST'
,
path:
path
,
headers:
options
[
:headers
],
resource:
generate_resource
(
path
),
body:
body
)
response
=
self
.
class
.
post
(
path
,
headers:
headers
,
body:
body
)
...
...
@@ -107,8 +107,8 @@ module AliyunLogRubySdk
body
=
body
.
to_json
if
body
.
present?
headers
=
generate_headers
(
verb:
'DELETE'
,
path:
path
,
headers:
options
[
:headers
],
resource:
generate_resource
(
path
),
body:
body
)
response
=
self
.
class
.
delete
(
path
,
headers:
headers
,
body:
body
)
...
...
@@ -124,14 +124,13 @@ module AliyunLogRubySdk
"http://
#{
project_name
}
.
#{
endpoint
}
"
end
def
generate_resource
(
path
,
query
=
{})
# 这里有一个很奇葩的地方:如果参数的值中存在 =,to_param 方法会将其转变成 %3D,但是阿里云日志签名时是用 = 做签名,因此这里替换回来
query
.
present?
?
"
#{
path
}
?
#{
query
.
to_param
.
gsub
(
'%3D'
,
'='
)
}
"
:
path
end
def
debug?
debug
end
def
log_store_name
(
options
=
{})
options
[
:log_store_name
]
||
AliyunLogRubySdk
.
config
.
log_store_name
end
end
end
\ No newline at end of file
end
lib/aliyun_log_ruby_sdk/consumer_group.rb
View file @
b0ed40d9
...
...
@@ -3,11 +3,11 @@
module
AliyunLogRubySdk
module
ConsumerGroup
def
list_consumer_group
(
options
=
{})
get
(
"/logstores/
#{
options
[
:log_store_name
]
}
/consumergroups"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/consumergroups"
,
options
)
end
def
get_check_point
(
options
=
{})
get
(
"/logstores/
#{
options
[
:log_store_name
]
}
/consumergroups/
#{
options
[
:consumer_group
]
}
"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/consumergroups/
#{
options
[
:consumer_group
]
}
"
,
options
)
end
end
end
\ No newline at end of file
end
lib/aliyun_log_ruby_sdk/headers.rb
View file @
b0ed40d9
...
...
@@ -29,7 +29,7 @@ module AliyunLogRubySdk
headers
[
'x-log-bodyrawsize'
]
=
'0'
end
headers
[
'Authorization'
]
=
generate_authorization
(
options
[
:verb
]
||
'GET'
,
headers
,
options
[
:resource
]
)
headers
[
'Authorization'
]
=
generate_authorization
(
options
.
merge
(
headers:
headers
)
)
headers
[
'x-log-date'
]
=
headers
[
'Date'
]
...
...
@@ -38,22 +38,24 @@ module AliyunLogRubySdk
private
def
generate_authorization
(
verb
,
headers
,
resource
)
"LOG
#{
access_key_id
}
:
#{
generate_signature
(
verb
,
headers
,
resource
)
}
"
def
generate_authorization
(
options
)
"LOG
#{
access_key_id
}
:
#{
generate_signature
(
options
)
}
"
end
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
def
generate_signature
(
options
)
Base64
.
encode64
(
OpenSSL
::
HMAC
.
digest
(
'sha1'
,
access_key_secret
,
generate_sign_string
(
options
).
encode
(
'utf-8'
))).
rstrip
end
def
generate_sign_string
(
verb
,
headers
,
resource
)
def
generate_sign_string
(
options
)
headers
=
options
[
:headers
]
%W[
#{
verb
}
#{
options
[
:verb
]
||
'GET'
}
#{
headers
[
'Content-MD5'
]
}
#{
headers
[
'Content-Type'
]
}
#{
headers
[
'Date'
]
}
#{
canonicalized_log_headers
(
headers
)
}
#{
resource
}
#{
canonicalized_log_resource
(
options
[
:path
],
options
[
:query
])
}
]
.
join
(
"
\n
"
)
end
...
...
@@ -66,5 +68,10 @@ module AliyunLogRubySdk
"
#{
key
.
downcase
}
:
#{
value
}
"
end
.
sort
.
join
(
"
\n
"
)
end
def
canonicalized_log_resource
(
path
,
query
=
{})
# 这里有一个很奇葩的地方:如果参数的值中存在 =,to_param 方法会将其转变成 %3D,但是阿里云日志签名时是用 = 做签名,因此这里替换回来
query
.
present?
?
"
#{
path
}
?
#{
query
.
to_param
.
gsub
(
'%3D'
,
'='
)
}
"
:
path
end
end
end
lib/aliyun_log_ruby_sdk/index.rb
View file @
b0ed40d9
...
...
@@ -3,7 +3,7 @@
module
AliyunLogRubySdk
module
Index
def
get_index
(
options
=
{})
get
(
"/logstores/
#{
options
[
:log_store_name
]
}
/index"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/index"
,
options
)
end
end
end
\ No newline at end of file
end
lib/aliyun_log_ruby_sdk/log_store.rb
View file @
b0ed40d9
...
...
@@ -19,7 +19,7 @@ module AliyunLogRubySdk
end
def
get_log_store
(
options
=
{})
get
(
"/logstores/
#{
log_store_name
}
"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
"
,
options
)
end
def
update_log_store
(
options
=
{})
...
...
@@ -30,14 +30,14 @@ module AliyunLogRubySdk
options
[
:query
]
||=
{}
options
[
:query
][
:type
]
=
'log'
get
(
"/logstores/
#{
log_store_name
}
"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
"
,
options
)
end
def
get_histograms
(
options
=
{})
options
[
:query
]
||=
{}
options
[
:query
][
:type
]
=
'histogram'
get
(
"/logstores/
#{
log_store_name
}
"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
"
,
options
)
end
end
end
lib/aliyun_log_ruby_sdk/shard.rb
View file @
b0ed40d9
...
...
@@ -3,14 +3,14 @@
module
AliyunLogRubySdk
module
Shard
def
list_shards
(
options
=
{})
get
(
"/logstores/
#{
log_store_name
}
/shards"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/shards"
,
options
)
end
def
get_cursor
(
options
=
{})
options
[
:query
]
||=
{}
options
[
:query
][
:type
]
=
'cursor'
get
(
"/logstores/
#{
log_store_name
}
/shards/
#{
options
[
:shard_id
]
}
"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/shards/
#{
options
[
:shard_id
]
}
"
,
options
)
end
def
put_logs
(
options
=
{})
...
...
@@ -26,7 +26,7 @@ module AliyunLogRubySdk
options
[
:body
]
=
Zlib
::
Deflate
.
deflate
(
body
)
post
(
"/logstores/
#{
log_store_name
}
/shards/lb"
,
options
)
post
(
"/logstores/
#{
log_store_name
(
options
)
}
/shards/lb"
,
options
)
end
def
pull_logs
(
options
=
{})
...
...
@@ -39,7 +39,7 @@ module AliyunLogRubySdk
options
[
:query
]
||=
{}
options
[
:query
][
:type
]
=
'log'
parse
(
get
(
"/logstores/
#{
log_store_name
}
/shards/
#{
options
[
:shard_id
]
}
"
,
options
))
parse
(
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/shards/
#{
options
[
:shard_id
]
}
"
,
options
))
end
private
...
...
@@ -88,4 +88,4 @@ module AliyunLogRubySdk
puts
"response:
#{
group_list
.
inspect
}
"
if
debug?
end
end
end
\ No newline at end of file
end
lib/aliyun_log_ruby_sdk/shipper.rb
View file @
b0ed40d9
...
...
@@ -3,7 +3,7 @@
module
AliyunLogRubySdk
module
Shipper
def
get_shipper_status
(
options
=
{})
get
(
"/logstores/
#{
options
[
:log_store_name
]
}
/shipper/
#{
options
[
:shipper_name
]
}
/tasks"
,
options
)
get
(
"/logstores/
#{
log_store_name
(
options
)
}
/shipper/
#{
options
[
:shipper_name
]
}
/tasks"
,
options
)
end
end
end
\ No newline at end of file
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