Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for VCL #16

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ $ ansible-galaxy install Jimdo.fastly
| gzips | false | List of gzip configurations | |
| headers | false | List of headers to manipulate for each request | |
| response_objects | false | List of response objects | |
| vcls | false | List of VCLs
| s3s | false | List of S3 log entries

### Condition

Expand All @@ -38,6 +40,36 @@ $ ansible-galaxy install Jimdo.fastly
| statement | true | string | |
| type | true | enum ('REQUEST', 'PREFETCH', 'CACHE', 'RESPONSE') | |

### Backends

[Fastly documentation](https://docs.fastly.com/api/config#backend)

| Field | Required | Type | Default |
|:----------------------|:---------|:--------------------------------------------------------|:--------|
| name | true | string | |
| port | false | integer | 80 |
| address | true | string | |
| comment | false | string | |
| shield | false | string | |
| max_conn | false | integer | 200 |
| error_threshold | false | integer | 0 |
| connect_timeout | false | integer | 1000 |
| first_byte_timeout | false | integer | 15000 |
| between_bytes_timeout | false | integer | 10000 |
| request_condition | false | string | |
| auto_loadbalance | false | bool | false |
| weight | false | integer | 0 |
| ssl_hostname | false | string | |
| ssl_check_cert | false | bool | true |
| ssl_cert_hostname | false | string | |
| ssl_ca_cert | false | string | |
| min_tls_version | false | string | |
| max_tls_version | false | string | |
| ssl_ciphers | false | string | |
| ssl_sni_hostname | false | string | |
| ssl_client_cert | false | string | |
| ssl_client_key | false | string | |

### Header

[Fastly documentation](https://docs.fastly.com/api/config#header)
Expand Down Expand Up @@ -65,6 +97,57 @@ $ ansible-galaxy install Jimdo.fastly
| response | false | string | Ok |
| status | false | int | 200 |

### Request Settings

[Fastly documentation](https://docs.fastly.com/api/config#request_settings)

| Field | Required | Type | Default |
|:------------------|:---------|:------------------------------------------------------------|:--------|
| name | true | string | |
| request_condition | false | string | |
| action | false | string | |
| force_ssl | false | int | 0 |
| xff | false | enum('clear', 'leave', 'append', 'append_all', 'overwrite') | leave |
| default_host | false | string | |
| timer_support | false | string | |
| max_stale_age | false | string | |
| force_miss | false | string | |
| bypass_busy_wait | false | string | |
| hash_keys | false | string | |

### VCL

[Fastly documentation](https://docs.fastly.com/api/config#vcl)

| Field | Required | Type | Default |
|:------------------|:---------|:----------------------------------------------------------|:--------|
| name | true | string | |
| content | true | string | |
| main | false | bool | true |

### S3 log entries

[Fastly documentation](https://docs-next.fastly.com/api/logging#logging_s3)

| Field | Required | Type | Default |
|:----------------------------------|:---------|:------------------------------------------------|:-------------------|
| name | true | str | |
| format | false | str | %h %l %u %t %r %>s |
| format_version | false | intstr | 1 |
| bucket_name | true | str | |
| access_key | true | str | |
| secret_key | true | str | |
| period | false | intstr | 3600 |
| path | false | str | |
| domain | false | str | |
| gzip_level | false | intstr | 0 |
| redundancy | false | enum('standard','reduced_redundancy') | standard |
| response_condition | false | str | |
| server_side_encryption | false | enum(None, 'AES256', 'aws:kms') | |
| message_type | false | enum('classic', 'loggly', 'logplex', 'blank') | classic |
| server_side_encryption_kms_key_id | false | str | |
| timestamp_format | false | str | |

## Examples

### Using the fastly_service module in a Playbook
Expand Down Expand Up @@ -97,8 +180,42 @@ $ ansible-galaxy install Jimdo.fastly
response_objects:
- name: Set 301 status code
status: 301
vcls:
- name: main
main: true
content: |
sub vcl_hit {
#FASTLY hit
if (!obj.cacheable) {
return(pass);
}
return(deliver);
}
s3s:
- name: s3-bucket-logger
access_key: iam-key
secret_key: iam-secret
bucket_name: s3-bucket
path: /my-app/
period: 3600

```

``` bash
$ ansible-playbook -i localhost, fastly.yml
```

## Testing

Requires vcrpy, wraps

- Set `FASTLY_API_KEY` to the Fastly key for your account. You will need a valid Fastly account to generate the cassettes for new tests.
- Change the `address` of the `localhost` backend to a valid address in `test_common.py`, will not work with `127.0.0.1`.
- Run the tests, the existing tests that are based on `127.0.0.1` will report errors, that's fine.
- Once you have a cassette for your tests, replace all instances of the address back to `127.0.0.1`, including the one in `test_common.py`.
- Re-run the tests and they should all pass now

To run all the tests
``` bash
$ python -m unittest discover tests
```