Skip to content

Commit fe6bef7

Browse files
committed
release 0.3.0
1 parent fafb294 commit fe6bef7

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.3.0
2+
* Enhance log type validation: check not only alpha but also numeric, underscore, and character length (may not exceed 100) - [issue #11](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/11)
3+
14
## 0.2.0
25
* Support setting the x-ms-AzureResourceId Header - [issue #8](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/8)
36

lib/azure/loganalytics/datacollectorapi/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def initialize (customer_id, shared_key, endpoint ='ods.opinsights.azure.com')
2323

2424
def post_data(log_type, json_records, record_timestamp ='', azure_resource_id ='' )
2525
raise ConfigError, 'no log_type' if log_type.empty?
26-
raise ConfigError, 'log_type must be only alpha characters' if not is_alpha(log_type)
26+
raise ConfigError, 'log_type must only contain alpha numeric and _, and not exceed 100 chars' if not is_valid_log_type(log_type)
2727
raise ConfigError, 'no json_records' if json_records.empty?
2828
body = json_records.to_json
2929
uri = sprintf("https://%s.%s/api/logs?api-version=%s",
@@ -58,8 +58,8 @@ def self.is_success(res)
5858

5959
private
6060

61-
def is_alpha(s)
62-
return (s.match(/^[[:alpha:]]+$/)) ? true : false
61+
def is_valid_log_type(s)
62+
return ( s.match(/^[a-zA-Z0-9_]+$/) && s.length <= 100 ) ? true : false
6363
end
6464

6565
def rfc1123date()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Azure
22
module Loganalytics
33
module Datacollectorapi
4-
VERSION = "0.2.0"
4+
VERSION = "0.3.0"
55
end
66
end
77
end

spec/azure/loganalytics/datacollectorapi/client_spec.rb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,35 @@
55
expect(Azure::Loganalytics::Datacollectorapi::VERSION).not_to be nil
66
end
77

8-
#it "does something useful" do
9-
# expect(false).to eq(true)
10-
#end
11-
128
customer_id = '<Customer ID aka WorkspaceID String>'
139
shared_key = '<Primary Key String>'
1410
log_type = "MyCustomLog"
1511

12+
it "log type validation" do
13+
json_records = []
14+
dummy= {
15+
:string => "dummy title",
16+
:number => 10
17+
}
18+
valid_log_type = "abcedefghijklmnopqrstuvwxyz1234567890_"
19+
invalid_log_type1 = "*-|[]//"
20+
invalid_log_type2 = "abcde__xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
21+
json_records.push(dummy)
22+
client=Azure::Loganalytics::Datacollectorapi::Client::new( customer_id, shared_key)
23+
24+
res = client.post_data(valid_log_type, json_records)
25+
expect(Azure::Loganalytics::Datacollectorapi::Client.is_success(res)).to eq(true)
26+
27+
expect{
28+
client.post_data(invalid_log_type1, json_records)
29+
}.to raise_error(Exception)
30+
31+
expect{
32+
client.post_data(invalid_log_type2, json_records)
33+
}.to raise_error(Exception)
34+
35+
end
36+
1637
it "posting data to datacollector api" do
1738
json_records = []
1839
record1= {

0 commit comments

Comments
 (0)