Skip to content

Commit f956754

Browse files
committed
MEDIUM: api consolitation- Move child resources as nested resources
Instruction for the generation of handlers/parents_xxx_generated.go can be found in CONTRIBUTING.md
1 parent dbf42e8 commit f956754

File tree

1,579 files changed

+187670
-92574
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,579 files changed

+187670
-92574
lines changed

.gitlab-ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ diff:
2929
- make generate-native
3030
- test -z "$(git diff 2> /dev/null)" || exit "Specification is not generated, issue \`make generate\` and commit the result"
3131
- test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Specification generation created untracked files, cannot proceed"
32+
diff-spec-parent:
33+
stage: lint
34+
image:
35+
name: $CI_REGISTRY_GO/golang:$GO_VERSION
36+
entrypoint: [""]
37+
tags:
38+
- go
39+
rules:
40+
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
41+
- if: $CI_PIPELINE_SOURCE == 'push'
42+
script:
43+
- make generate-parent-aliases
44+
- test -z "$(git diff 2> /dev/null)" || exit "Parent aliases are not generated, issue \`make generate-parent-aliases\` and commit the result"
45+
- test -z "$(git ls-files --others --exclude-standard 2> /dev/null)" || exit "Parent aliases created untracked files, cannot proceed"
3246
golangci-lint:
3347
stage: lint
3448
artifacts:

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
linters-settings:
2-
govet:
3-
check-shadowing: true
42
golint:
53
min-confidence: 0
64
gocyclo:

CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This document is a short guide for contributing to this project.
66

77
## API Specification - Development guide
88

9+
### Dataplane API generation
910
Data Plane API is generated using [go-swagger](https://github.com/go-swagger/go-swagger) from the swagger spec found [here](https://github.com/haproxytech/client-native/blob/master/specification/build/haproxy_spec.yaml) using the following command.
1011

1112
```
@@ -21,6 +22,39 @@ make generate-native
2122
This command generates some of the files in this project, which are marked with // Code generated by go-swagger; DO NOT EDIT.
2223
comments at the top of the files. These are not to be edited, as they are overwritten when specification is changed and the above-mentioned command is run. If you want to change those files, please change the specification where necessary and then generate them again.
2324

25+
### handlers/parents_xxx_generated.go generation
26+
27+
Some handler files `handler/parents_xxx_generated.go` are automatically generated. For this use the following command:
28+
```
29+
make generate-parent-aliases
30+
```
31+
32+
Pre-requisites: for this command to run you need to update the following files:
33+
- [generate/parents/main.go](./generate/parents/main.go)
34+
- Update this section with the list of children for which you generate a `handler/parents_xxx_generated.go`
35+
```
36+
children := []string{
37+
cnparents.ServerChildType,
38+
cnparents.HTTPAfterResponseRuleChildType,
39+
cnparents.HTTPCheckChildType,
40+
cnparents.HTTPErrorRuleChildType,
41+
cnparents.HTTPRequestRuleChildType,
42+
cnparents.HTTPResponseRuleChildType,
43+
cnparents.TCPCheckChildType,
44+
cnparents.TCPRequestRuleChildType,
45+
cnparents.TCPResponseRuleChildType,
46+
cnparents.ACLChildType,
47+
cnparents.BindChildType,
48+
cnparents.FilterChildType,
49+
cnparents.LogTargetChildType,
50+
}
51+
```
52+
53+
- [generate/parents/operations.go](./generate/parents/operations.go)
54+
- Contains the list of operations to generate an alias for in the `handler/parents_xxx_generated.go`.
55+
- Note that the list of parents for wich an alias is generated is defined in: *client-native* (refer to client-native `specification/README.md`)
56+
57+
2458
## Commit Messages and General Style
2559

2660
For commit messages and general style please follow the haproxy project's [CONTRIBUTING guide](https://github.com/haproxy/haproxy/blob/master/CONTRIBUTING) and use that where applicable.

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ build:
3838
e2e: build
3939
TESTNAME=$(TESTNAME) TESTNUMBER=$(TESTNUMBER) TESTDESCRIPTION="$(TESTDESCRIPTION)" SKIP_CLEANUP=$(SKIP_CLEANUP) PREWIPE=$(PREWIPE) HAPROXY_VERSION=$(HAPROXY_VERSION) ./e2e/run.bash
4040

41+
.PHONY: generate-parent-aliases_no_formatting
42+
generate-parent-aliases_no_formatting:
43+
rm -f handlers/parent_*_generated.go
44+
go run generate/parents/*.go
45+
46+
.PHONY: generate-parent-aliases
47+
generate-parent-aliases: generate-parent-aliases_no_formatting gofumpt
48+
49+
4150
.PHONY: generate
4251
generate:
4352
cd generate/swagger;docker build \

configure_data_plane.go

Lines changed: 223 additions & 86 deletions
Large diffs are not rendered by default.

e2e/libs/version_spoe.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ function deprecated_auth_curl() {
3737
}
3838

3939
function get_version() {
40-
resource_get "/services/haproxy/spoe/version" "spoe=$SPOE_FILE"
40+
resource_get "/services/haproxy/spoe/$SPOE_FILE/version"
4141
eval VERSION="'$BODY'"
4242
}

e2e/tests/acl_files/acl_file_entries.bats

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ load '../../libs/version'
2525
load 'utils/_helpers'
2626

2727
@test "acl_runtime: Return ACL file entries list" {
28-
resource_get "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH" "acl_id=0"
28+
PARENT_NAME="0"
29+
resource_get "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries"
2930
assert_equal "$SC" 200
3031

3132
assert_equal "$(get_json_path "${BODY}" " .[0].value" )" "/static"
@@ -35,7 +36,8 @@ load 'utils/_helpers'
3536
}
3637

3738
@test "acl_runtime: Return ACL file entries by their ID" {
38-
resource_get "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH" "acl_id=0"
39+
PARENT_NAME="0"
40+
resource_get "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries"
3941
assert_equal "$SC" 200
4042

4143
local list; list=$BODY
@@ -44,35 +46,37 @@ load 'utils/_helpers'
4446
local id; id="$(get_json_path "${list}" ".[${index}].id" )"
4547
local value; value="$(get_json_path "${list}" ".[${index}].value" )"
4648

47-
resource_get "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH/$id" "acl_id=0"
49+
resource_get "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries/$id"
4850
assert_equal "$SC" 200
4951
assert_equal "$(get_json_path "${BODY}" ".value" )" "$value"
5052
done
5153
}
5254

5355
@test "acl_runtime: Add an ACL file entry" {
54-
resource_post "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH" "data/post.json" "acl_id=0"
56+
PARENT_NAME="0"
57+
resource_post "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries" "data/post.json"
5558
assert_equal "$SC" 201
5659
assert_equal "$(get_json_path "${BODY}" " .value" )" "/js"
5760
}
5861

5962
@test "acl_runtime: Delete an ACL file entry by its ID" {
63+
PARENT_NAME="1"
6064
if haproxy_version_ge "2.9"; then
6165
skip "cause: bug in HAPRoxy 2.9"
6266
fi
6367
# checking items and retrieving first ID
64-
resource_get "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH" "acl_id=1"
68+
resource_get "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries"
6569
assert_equal "$SC" 200
6670
assert_equal "$(get_json_path "$BODY" ". | length" )" "5"
6771

6872
local id; id="$(get_json_path "$BODY" ".[0].id")"
6973

7074
# deleting the entry file by its ID
71-
resource_delete "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH/$id" "acl_id=1"
75+
resource_delete "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries/$id"
7276
assert_equal "$SC" 204
7377

7478
# checking the file entry has been deleted counting the items
75-
resource_get "$_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH" "acl_id=1"
79+
resource_get "$_RUNTIME_ACL_BASE_PATH/$PARENT_NAME/entries"
7680
assert_equal "$SC" 200
7781
assert_equal "$(get_json_path "$BODY" ". | length" )" "4"
7882
}

e2e/tests/acl_files/utils/_helpers.bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
#
1717

1818
_RUNTIME_ACL_BASE_PATH="/services/haproxy/runtime/acls"
19-
_RUNTIME_ACL_FILE_ENTRIES_BASE_PATH="/services/haproxy/runtime/acl_file_entries"

e2e/tests/acls/add.bats

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,24 @@ load '../../libs/resource_client'
2424
load 'utils/_helpers'
2525

2626
@test "acls: Add a new ACL" {
27-
resource_post "$_ACL_BASE_PATH"/2 "data/post.json" "index=2&parent_name=fe_acl&parent_type=frontend"
27+
PARENT_NAME="fe_acl"
28+
resource_post "$_FRONTEND_BASE_PATH/$PARENT_NAME/acls/2" "data/post.json"
2829
assert_equal "$SC" 202
2930
#
3031
# verify that ACL is actually added
3132
#
32-
resource_get "$_ACL_BASE_PATH/2" "parent_name=fe_acl&parent_type=frontend"
33+
resource_get "$_FRONTEND_BASE_PATH/$PARENT_NAME/acls/2"
34+
assert_equal "$SC" 200
35+
36+
assert_equal "$(get_json_path "${BODY}" ".")" "$(cat ${BATS_TEST_DIRNAME}/data/post.json)"
37+
}
38+
39+
@test "acls: Add a newACL for fcgi-app" {
40+
PARENT_NAME="test_1"
41+
resource_post "$_FCGIAPP_BASE_PATH/$PARENT_NAME/acls/0" "data/post.json"
42+
assert_equal "$SC" 202
43+
44+
resource_get "$_FCGIAPP_BASE_PATH/$PARENT_NAME/acls/0"
3345
assert_equal "$SC" 200
3446

3547
assert_equal "$(get_json_path "${BODY}" ".")" "$(cat ${BATS_TEST_DIRNAME}/data/post.json)"

e2e/tests/acls/data/haproxy.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ frontend fe_acl
2323
acl invalid_src src 0.0.0.0/7 224.0.0.0/3
2424
acl invalid_src src_port 0:1023
2525
acl local_dst hdr(host) -i localhost
26+
27+
fcgi-app test_1
28+
docroot /path/to/chroot
29+
index index.php
30+
log-stderr global
31+
acl local_dst hdr(host) -i localhost

0 commit comments

Comments
 (0)