Skip to content

Commit

Permalink
update cdn event trigger demo
Browse files Browse the repository at this point in the history
1. update cdn event trigger demo
2. fix oss and cdn spec definition
3. add compatibility for lowcase spec declaration of oss trigger
  • Loading branch information
coco-super authored and tanhe123 committed Apr 29, 2019
1 parent d0d3251 commit 30bbeae
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 95 deletions.
52 changes: 26 additions & 26 deletions docs/specs/2018-04-03-zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,25 @@ tablestore-trigger-test: # trigger name

属性名称 | 类型 | 描述
---|:---:|---
events| `array` | **必填。** 为 OSS 端触发函数执行的事件,比如参数为 ["oss:ObjectCreated:PutObject", "oss:ObjectCreated:PutSymlink"] 等...
bucketName| `stirng` | **必填。** 为 OSS 中对应的 bucket 名称。可参照[OSS 示例](https://help.aliyun.com/document_detail/74762.html)
filter | `object` | **必填。** 为 OSS 对象过滤参数,满足过滤条件的 OSS 对象才可以触发函数,包含一个配置属性 key,表示过滤器支持过滤的对象键 (key)。
key | [OSS Key 对象](#OSS-Key-配置对象) | **必填。** 过滤器支持过滤的对象键
Events| `array` | **必填。** 为 OSS 端触发函数执行的事件,比如参数为 ["oss:ObjectCreated:PutObject", "oss:ObjectCreated:PutSymlink"] 等...
BucketName| `stirng` | **必填。** 为 OSS 中对应的 bucket 名称。可参照[OSS 示例](https://help.aliyun.com/document_detail/74762.html)
Filter | `object` | **必填。** 为 OSS 对象过滤参数,满足过滤条件的 OSS 对象才可以触发函数,包含一个配置属性 key,表示过滤器支持过滤的对象键 (key)。
Key | [OSS Key 对象](#OSS-Key-配置对象) | **必填。** 过滤器支持过滤的对象键

##### 示例:OSS 事件源对象

```yaml
oss-trigger-test: # trigger name
Type: OSS # trigger type
Properties:
bucketName: ossBucketName # oss bucket name
events:
BucketName: ossBucketName # oss bucket name
Events:
- oss:ObjectCreated:*
- oss:ObjectRemoved:DeleteObject
filter:
key:
prefix: source/
suffix: .png
Filter:
Key:
Prefix: source/
Suffix: .png
```

#### CDN
Expand All @@ -462,22 +462,22 @@ oss-trigger-test: # trigger name

属性名称 | 类型 | 描述
---|:---:|---
eventName| `stirng` | **必填。** 为 CDN 端触发函数执行的事件,一经创建不能更改
eventVersion| `stirng` | **必填。** 为 CDN 端触发函数执行事件的版本,一经创建不能更改
notes| `stirng` | **必填。** 备注信息
filter | [CDN Filter 对象](#CDN-Filter-配置对象) | **必填。** 过滤器(至少需要一个过滤器)
EventName| `stirng` | **必填。** 为 CDN 端触发函数执行的事件,一经创建不能更改
EventVersion| `stirng` | **必填。** 为 CDN 端触发函数执行事件的版本,一经创建不能更改
Notes| `stirng` | **必填。** 备注信息
Filter | [CDN Filter 对象](#CDN-Filter-配置对象) | **必填。** 过滤器(至少需要一个过滤器)

##### 示例:CDN 事件源对象

```yaml
cdn-trigger-name: # trigger name
Type: CDN # trigger type
Properties:
eventName: LogFileCreated
eventVersion: '1.0.0'
notes: cdn events trigger test
filter:
domain: ['www.taobao.com','www.tmall.com']
EventName: LogFileCreated
EventVersion: '1.0.0'
Notes: cdn events trigger test
Filter:
Domain: ['www.taobao.com','www.tmall.com']
```

### Property 类型
Expand Down Expand Up @@ -630,25 +630,25 @@ PathConfig 用于设置自定义域名中路径与函数的映射关系。

#### OSS Key 配置对象

key 配置对象的属性包括: `prefix``suffix` 属性。它们所代表的含义分别为:匹配前缀和匹配后缀。
Key 配置对象的属性包括: `Prefix``Suffix` 属性。它们所代表的含义分别为:匹配前缀和匹配后缀。

示例:

```
key:
prefix: source/
suffix: .png
Key:
Prefix: source/
Suffix: .png
```

#### CDN Filter 配置对象

filter 配置对象为 CDN 过滤参数,满足过滤条件的才可以触发函数。filter 对象可配置的属性目前只包括:`domain`, domain 是个字符串数组且必填,代表过滤参数值的集合。
Filter 配置对象为 CDN 过滤参数,满足过滤条件的才可以触发函数。Filter 对象可配置的属性目前只包括:`Domain`, Domain 是个字符串数组且必填,代表过滤参数值的集合。

示例:

```
filter:
domain: ['www.taobao.com','www.tmall.com']
Filter:
Domain: ['www.taobao.com','www.tmall.com']
```
52 changes: 26 additions & 26 deletions docs/specs/2018-04-03.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,25 +406,25 @@ Describe the object of type [OSS Trigger](https://help.aliyun.com/document_detai

Property Name | Type | Description
---|:---:|---
events | `array` | **Required.** Indicates the type of an OSS event.
bucketName | `string` | **Required.** the corresponding bucket name in OSS. can refer to [OSS example](https://www.alibabacloud.com/help/doc-detail/31885.html).
filter | `object` | **Required.** Filters OSS events. Only OSS objects that meet the filtering condition can trigger a function. This parameter has a key attribute:
key | [`OSS Key configuration object`](#OSS-Key-configuration-object) | **Required** Indicates the key supported by the filter.
Events | `array` | **Required.** Indicates the type of an OSS event.
BucketName | `string` | **Required.** the corresponding bucket name in OSS. can refer to [OSS example](https://www.alibabacloud.com/help/doc-detail/31885.html).
Filter | `object` | **Required.** Filters OSS events. Only OSS objects that meet the filtering condition can trigger a function. This parameter has a key attribute:
Key | [`OSS Key configuration object`](#OSS-Key-configuration-object) | **Required** Indicates the key supported by the filter.

##### Example: OSS event source object

```yaml
oss-trigger-test: # trigger name
Type: OSS # trigger type
Properties:
bucketName: ossBucketName # oss bucket name
events:
BucketName: ossBucketName # oss bucket name
Events:
- oss:ObjectCreated:*
- oss:ObjectRemoved:DeleteObject
filter:
key:
prefix: source/
suffix: .png
Filter:
Key:
Prefix: source/
Suffix: .png
```

#### CDN
Expand All @@ -435,22 +435,22 @@ Describe the object of type [CDN Trigger](https://www.alibabacloud.com/help/doc-

Property Name | Type | Description
---|:---:|---
eventName | `string` | **Required.** is CDN event which invokes the function execution, can not be changed after creation.
eventVersion | `string` | **Required.** is CDN event version which invokes the function execution, can not be changed after creation.
notes | `string` | **Required.** Descriptions.
filter | [`CDN Filter configuration object`](#CDN-Filter-configuration-object) | **Required** Filters (Need to have at least one filter).
EventName | `string` | **Required.** is CDN event which invokes the function execution, can not be changed after creation.
EventVersion | `string` | **Required.** is CDN event version which invokes the function execution, can not be changed after creation.
Notes | `string` | **Required.** Descriptions.
Filter | [`CDN Filter configuration object`](#CDN-Filter-configuration-object) | **Required** Filters (Need to have at least one filter).

##### Example: CDN event source object

```yaml
cdn-trigger-name: # trigger name
Type: CDN # trigger type
Properties:
eventName: LogFileCreated
eventVersion: '1.0.0'
notes: cdn events trigger test
filter:
domain: ['www.taobao.com','www.tmall.com']
EventName: LogFileCreated
EventVersion: '1.0.0'
Notes: cdn events trigger test
Filter:
Domain: ['www.taobao.com','www.tmall.com']
```

### Property types
Expand Down Expand Up @@ -604,26 +604,26 @@ Example:

#### OSS Key configuration object

The properties that the key configuration object contains include the `prefix` and `suffix` attributes.
The properties that the key configuration object contains include the `Prefix` and `Suffix` attributes.
They mean the following: matching prefix and matching suffix.

Example:

```
key:
prefix: source/
suffix: .png
Key:
Prefix: source/
Suffix: .png
```

#### CDN Filter configuration object

The configurable properties of the filter object currently only include: `domain`, which is an array of strings, which is required to represent a collection of filter parameter values.
The configurable properties of the Filter object currently only include: `Domain`, which is an array of strings, which is required to represent a collection of Filter parameter values.

Example:

```
filter:
domain: ['www.taobao.com','www.tmall.com']
Filter:
Domain: ['www.taobao.com','www.tmall.com']
```
12 changes: 12 additions & 0 deletions examples/cdn-trigger/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exports.handler = function(event, context, callback) {
var eventObj = JSON.parse(event.toString());
console.log("event: " + event);
console.log('context: ', JSON.stringify(context));
console.log('eventName: '+ eventObj.events[0].eventName);
console.log('eventVersion: '+ eventObj.events[0].eventVersion);
console.log('eventSource: '+ eventObj.events[0].eventSource);
console.log('region: '+ eventObj.events[0].region);
console.log('eventParameter: '+ JSON.stringify(eventObj.events[0].eventParameter,null,4))
// cdn trigger 事件格式请参考 https://help.aliyun.com/document_detail/73333.html
callback(null, 'hello cdn_trigger');
};
7 changes: 0 additions & 7 deletions examples/cdn-trigger/index.py

This file was deleted.

12 changes: 6 additions & 6 deletions examples/cdn-trigger/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Resources:
Type: 'Aliyun::Serverless::Function'
Properties:
Handler: index.handler
Runtime: python2.7
Runtime: nodejs8
CodeUri: './'
Events:
cdn-trigger-name: # trigger name
Type: CDN # trigger type
Properties:
eventName: CachedObjectsRefreshed
eventVersion: '1.0.0'
notes: cdn events trigger test
filter:
domain: ['cdn-trigger.sunfeiyu.top']
EventName: CachedObjectsRefreshed
EventVersion: '1.0.0'
Notes: cdn events trigger test
Filter:
Domain: ['cdn-trigger.sunfeiyu.top']

12 changes: 6 additions & 6 deletions examples/oss-trigger/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ Resources:
oss-trigger-name:
Type: OSS # trigger type
Properties:
bucketName: coco-superme # oss bucket name
events:
BucketName: coco-superme # oss bucket name
Events:
- oss:ObjectCreated:*
- oss:ObjectRemoved:DeleteObject
filter:
key:
prefix: source/
suffix: .png
Filter:
Key:
Prefix: source/
Suffix: .png

14 changes: 7 additions & 7 deletions lib/deploy/deploy-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ async function getSourceArn(triggerType, triggerProperties) {
} else if (triggerType === 'TableStore') {
return `acs:ots:${profile.defaultRegion}:${profile.accountId}:instance/${triggerProperties.InstanceName}/table/${triggerProperties.TableName}`;
} else if (triggerType === 'OSS') {
return `acs:oss:${profile.defaultRegion}:${profile.accountId}:${triggerProperties.bucketName}`;
return `acs:oss:${profile.defaultRegion}:${profile.accountId}:${triggerProperties.BucketName || triggerProperties.bucketName}`;
} else if (triggerType === 'CDN') {
return `acs:cdn:*:${profile.accountId}`;
}
Expand Down Expand Up @@ -557,15 +557,15 @@ function getTriggerConfig(triggerType, triggerProperties) {
return {};
} else if (triggerType === 'OSS') {
return {
events : triggerProperties.events,
filter : triggerProperties.filter
events : triggerProperties.Events || triggerProperties.events,
filter : triggerProperties.Filter || triggerProperties.filter
};
} else if (triggerType === 'CDN') {
return {
eventName : triggerProperties.eventName,
eventVersion : triggerProperties.eventVersion,
notes : triggerProperties.notes,
filter : triggerProperties.filter
eventName : triggerProperties.EventName,
eventVersion : triggerProperties.EventVersion,
notes : triggerProperties.Notes,
filter : triggerProperties.Filter
};
}
console.error(`trigger type is ${triggerType} not supported.`);
Expand Down
14 changes: 7 additions & 7 deletions lib/validate/schema/cdn-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ const cdnEventSchema = {
'Properties': {
'type': 'object',
'properties': {
'eventName': {
'EventName': {
'type': 'string'
},
'eventVersion': {
'EventVersion': {
'type': 'string'
},
'notes': {
'Notes': {
'type': 'string'
},
'filter': {
'Filter': {
'type': 'object',
'properties': {
'domain': {
'Domain': {
'type': 'array',
'items': {
'type': 'string',
}
}
},
'required': ['domain'],
'required': ['Domain'],
'additionalProperties': false
}
},
'required': ['eventName','eventVersion','notes','filter'],
'required': ['EventName','EventVersion','Notes','Filter'],
'additionalProperties': false
},
},
Expand Down
31 changes: 30 additions & 1 deletion lib/validate/schema/oss-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,38 @@ const ossEventSchema = {
},
'required': ['key'],
'additionalProperties': false
},
'Events': {
'type': 'array',
'items': {
'type': 'string',
}
},
'BucketName': {
'type': 'string'
},
'Filter': {
'type': 'object',
'properties': {
'Key': {
'type': 'object',
'properties': {
'Prefix': {
'type': 'string'
},
'Suffix': {
'type': 'string'
},
},
'required': ['Prefix','Suffix'],
'additionalProperties': false
}
},
'required': ['Key'],
'additionalProperties': false
}
},
'required': ['events','bucketName','filter'],
'patternRequired': ['[Ee]vents','[Bb]ucketName','[Ff]ilter'],//为了兼容 #192 这个 pr 定义的 oss trigger 首字母小写的 schama
'additionalProperties': false
},
},
Expand Down
Loading

0 comments on commit 30bbeae

Please sign in to comment.