Skip to content

Commit 21dfc4b

Browse files
Consent management component (#14)
* move data-collection to its own subdir * consent-management wip * test ci * fix * fix gitignore and rename data-collection file * edgee-component: rename component
1 parent b1ef5f4 commit 21dfc4b

File tree

11 files changed

+169
-42
lines changed

11 files changed

+169
-42
lines changed

.github/workflows/check.yml

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
11
name: Check
22
on:
3-
push:
4-
branches:
5-
- main
6-
pull_request:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
77

88
env:
99
EDGEE_API_TOKEN: ${{ secrets.EDGEE_API_TOKEN }}
1010

1111
jobs:
12-
test:
13-
name: test
14-
runs-on: ubuntu-latest
15-
container:
16-
image: ghcr.io/webassembly/wasi-sdk:latest
17-
18-
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v4
21-
22-
- name: "Set up C component build system"
23-
run: |
24-
apt-get update
25-
apt install curl clang build-essential -y
26-
27-
- name: Set up minimal stable Rust toolchain
28-
uses: dtolnay/rust-toolchain@stable
29-
30-
- name: Install wasm tooling
31-
run: CC=clang cargo install wit-bindgen-cli wasm-tools --locked
32-
33-
- name: Install edgee
34-
uses: edgee-cloud/[email protected]
35-
36-
- name: Build component
37-
run: edgee component build
38-
39-
- name: Verify .wasm file exists
40-
run: |
41-
if [ ! -f "./dc_component.wasm" ]; then
42-
echo "❌ Error: dc_component.wasm not found" >&2
43-
exit 1
44-
fi
12+
full-ci:
13+
name: Full CI (${{ matrix.dir }})
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
dir: [consent-management, data-collection]
18+
defaults:
19+
run:
20+
working-directory: ${{ matrix.dir }}
21+
container:
22+
image: ghcr.io/webassembly/wasi-sdk:latest
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: "Set up C component build system"
29+
run: |
30+
apt-get update
31+
apt install curl clang build-essential -y
32+
33+
- name: Set up minimal stable Rust toolchain
34+
uses: dtolnay/rust-toolchain@stable
35+
36+
- name: Install wasm tooling
37+
run: CC=clang cargo install wit-bindgen-cli wasm-tools --locked
38+
39+
- name: Install edgee
40+
uses: edgee-cloud/[email protected]
41+
42+
- name: Build component
43+
run: edgee component build

.gitignore renamed to consent-management/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
internal/
44

55
# output
6-
dc_component.wasm
7-
dc_component_temp.wasm
6+
component.wasm

consent-management/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY: all
2+
MAKEFLAGS += --silent
3+
4+
all: help
5+
6+
help:
7+
@grep -E '^[a-zA-Z1-9\._-]+:.*?## .*$$' $(MAKEFILE_LIST) \
8+
| sort \
9+
| sed -e "s/^Makefile://" -e "s///" \
10+
| awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 }'
11+
build:
12+
edgee components build
13+
14+
clean: ## clean build artifacts
15+
rm -rf component.wasm
16+
rm -rf internal/
File renamed without changes.

consent-management/component.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "internal/consent_management.h"
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <stdbool.h>
5+
6+
struct component_settings {
7+
consent_management_string_t example;
8+
};
9+
10+
struct component_settings parse_settings(exports_edgee_components_consent_management_dict_t *settings) {
11+
struct component_settings ret;
12+
for (int i = 0; i < settings->len; i++) {
13+
if (settings->ptr[i].f0.len == 0) {
14+
continue;
15+
}
16+
if (strncmp((const char*)settings->ptr[i].f0.ptr, "example", settings->ptr[i].f0.len) == 0) {
17+
ret.example = settings->ptr[i].f1;
18+
}
19+
}
20+
return ret;
21+
}
22+
23+
struct cookies {
24+
consent_management_string_t example;
25+
};
26+
27+
struct cookies parse_cookies(exports_edgee_components_consent_management_dict_t *settings) {
28+
struct cookies ret;
29+
for (int i = 0; i < settings->len; i++) {
30+
if (settings->ptr[i].f0.len == 0) {
31+
continue;
32+
}
33+
if (strncmp((const char*)settings->ptr[i].f0.ptr, "example", settings->ptr[i].f0.len) == 0) {
34+
ret.example = settings->ptr[i].f1;
35+
}
36+
}
37+
return ret;
38+
}
39+
40+
bool exports_edgee_components_consent_management_map(exports_edgee_components_consent_management_dict_t *cookies, exports_edgee_components_consent_management_dict_t *settings, exports_edgee_components_consent_management_consent_t *ret) {
41+
42+
struct component_settings parsed_settings = parse_settings(settings);
43+
struct cookies parsed_cookies = parse_cookies(cookies);
44+
if (parsed_cookies.example.len == 0) {
45+
return false;
46+
}
47+
48+
if (strcmp((const char*)parsed_cookies.example.ptr, "granted") == 0) {
49+
*ret = EXPORTS_EDGEE_COMPONENTS_CONSENT_MANAGEMENT_CONSENT_GRANTED;
50+
} else if (strcmp((const char*)parsed_cookies.example.ptr, "denied") == 0) {
51+
*ret = EXPORTS_EDGEE_COMPONENTS_CONSENT_MANAGEMENT_CONSENT_DENIED;
52+
} else {
53+
*ret = EXPORTS_EDGEE_COMPONENTS_CONSENT_MANAGEMENT_CONSENT_PENDING;
54+
}
55+
56+
return true;
57+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
manifest-version = 1
2+
3+
[component]
4+
name = "example-c-consent-mapping-component"
5+
version = "1.0.0"
6+
category = "consent-management"
7+
subcategory = "consent-mapping"
8+
description = "Example C component for consent management"
9+
documentation = "https://github.com/edgee-cloud/example-c-component"
10+
repository = "https://github.com/edgee-cloud/example-c-component"
11+
language = "C"
12+
wit-version = "1.0.0"
13+
14+
[component.build]
15+
command = "mkdir -p internal && (cd internal && wit-bindgen c ../.edgee/wit && cd ..) && $CC component.c internal/consent_management.c internal/consent_management_component_type.o -mexec-model=reactor -Os && wasm-tools component new -o component.wasm a.out"
16+
output_path = "./component.wasm"
17+
18+
[component.settings.example]
19+
title = "Example Config Field"
20+
type = "string"

data-collection/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# generated files
2+
.edgee/
3+
internal/
4+
5+
# output
6+
component.wasm
File renamed without changes.

data-collection/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<div align="center">
2+
<p align="center">
3+
<a href="https://www.edgee.cloud">
4+
<picture>
5+
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.edgee.cloud/img/component-dark.svg">
6+
<img src="https://cdn.edgee.cloud/img/component.svg" height="100" alt="Edgee">
7+
</picture>
8+
</a>
9+
</p>
10+
</div>
11+
12+
<h1 align="center">Example C component for Edgee</h1>
13+
14+
This is an example of a C Edgee Component.
15+
16+
## Setup
17+
Requirements:
18+
- [WASI SDK](https://github.com/webassembly/wasi-sdk)
19+
- [wasm-tools](https://github.com/bytecodealliance/wasm-tools)
20+
- [wit-bindgen](https://github.com/bytecodealliance/wit-bindgen#cli-installation)
21+
- [edgee-cli] (https://github.com/edgee-cloud/edgee)
22+
23+
```shell
24+
$ make setup
25+
```
26+
## Building
27+
28+
```shell
29+
$ make build
30+
```
File renamed without changes.

edgee-component.toml renamed to data-collection/edgee-component.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
manifest-version = 1
22

33
[component]
4-
name = "example-c-component"
4+
name = "example-c-data-collection-component"
55
version = "1.0.0"
66
category = "data-collection"
77
subcategory = "analytics"
@@ -12,8 +12,8 @@ language = "C"
1212
wit-version = "1.0.0"
1313

1414
[component.build]
15-
command = "mkdir -p internal && (cd internal && wit-bindgen c ../.edgee/wit && cd ..) && $CC dc_component.c internal/data_collection.c internal/data_collection_component_type.o -mexec-model=reactor -Os && wasm-tools component new -o dc_component.wasm a.out"
16-
output_path = "./dc_component.wasm"
15+
command = "mkdir -p internal && (cd internal && wit-bindgen c ../.edgee/wit && cd ..) && $CC component.c internal/data_collection.c internal/data_collection_component_type.o -mexec-model=reactor -Os && wasm-tools component new -o component.wasm a.out"
16+
output_path = "./component.wasm"
1717

1818
[component.settings.example]
1919
title = "Example Config Field"

0 commit comments

Comments
 (0)