Skip to content

Commit a073b0e

Browse files
authored
first iteration - deepcopy (#131)
* first iteration - deepcopy Signed-off-by: spolti <[email protected]> * review additions Signed-off-by: spolti <[email protected]> * add builders for the object types Signed-off-by: spolti <[email protected]> Signed-off-by: spolti <[email protected]>
1 parent bb8e1d9 commit a073b0e

30 files changed

+1946
-35
lines changed

.github/workflows/Go-SDK-PR-Check.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757
make addheaders
5858
changed_files=$(git status -s | grep -v 'go.mod\|go.sum\|tools.mod\|tools.sum' || :)
5959
[[ -z "$changed_files" ]] || (printf "Some files are missing the headers: \n$changed_files\n Did you run 'make lint' before sending the PR" && exit 1)
60+
- name: Check DeepCopy Generation
61+
run: |
62+
export GOPATH=$(go env GOPATH)
63+
make deepcopy
6064
- name: Check Formatting
6165
run: |
6266
make fmt

.lift.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ignoreFiles = """
2+
model/zz_generated.deepcopy.go
3+
"""

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ lint:
1414

1515
.PHONY: test
1616
coverage="false"
17-
test:
17+
test: deepcopy
1818
make lint
1919
@go test ./...
20+
21+
.PHONY: deepcopy
22+
deepcopy: $(DEEPCOPY_GEN) ## Download deeepcopy-gen locally if necessary.
23+
./hack/deepcopy-gen.sh deepcopy

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/pkg/errors v0.9.1
88
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46
99
github.com/stretchr/testify v1.7.0
10+
gopkg.in/yaml.v3 v3.0.1
1011
k8s.io/apimachinery v0.25.1
1112
sigs.k8s.io/yaml v1.3.0
1213
)
@@ -24,7 +25,6 @@ require (
2425
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
2526
golang.org/x/text v0.3.7 // indirect
2627
gopkg.in/yaml.v2 v2.4.0 // indirect
27-
gopkg.in/yaml.v3 v3.0.1 // indirect
2828
k8s.io/klog/v2 v2.70.1 // indirect
2929
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
3030
)

hack/boilerplate.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2022 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.

hack/deepcopy-gen.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2022 The Serverless Workflow Specification Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# retrieved from https://github.com/kubernetes/code-generator/blob/master/generate-internal-groups.sh
17+
# and adapted to only install and run the deepcopy-gen
18+
19+
set -o errexit
20+
set -o nounset
21+
set -o pipefail
22+
23+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
24+
echo "Script root is $SCRIPT_ROOT"
25+
26+
GENS="$1"
27+
shift 1
28+
29+
(
30+
# To support running this script from anywhere, first cd into this directory,
31+
# and then install with forced module mode on and fully qualified name.
32+
# make sure your GOPATH env is properly set.
33+
# it will go under $GOPATH/bin
34+
cd "$(dirname "${0}")"
35+
GO111MODULE=on go install k8s.io/code-generator/cmd/deepcopy-gen@latest
36+
)
37+
38+
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
39+
40+
if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
41+
echo "Generating deepcopy funcs"
42+
export GO111MODULE=on
43+
# for debug purposes, increase the log level by updating the -v flag to higher numbers, e.g. -v 4
44+
"${GOPATH}/bin/deepcopy-gen" -v 1 \
45+
--input-dirs ./model -O zz_generated.deepcopy \
46+
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.txt" \
47+
"$@"
48+
fi

model/action.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ type FunctionRef struct {
6969
RefName string `json:"refName" validate:"required"`
7070
// Function arguments
7171
// TODO: validate it as required if function type is graphql
72-
Arguments map[string]interface{} `json:"arguments,omitempty"`
72+
Arguments map[string]Object `json:"arguments,omitempty"`
7373
// String containing a valid GraphQL selection set
7474
// TODO: validate it as required if function type is graphql
7575
SelectionSet string `json:"selectionSet,omitempty"`
76-
7776
// Invoke specifies if the subflow should be invoked sync or async.
7877
// Defaults to sync.
7978
Invoke InvokeKind `json:"invoke,omitempty" validate:"required,oneof=async sync"`

model/auth.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ type AuthProperties interface {
110110
GetMetadata() *Metadata
111111
// GetSecret ...
112112
GetSecret() string
113+
// DeepCopyAuthProperties fixes in.Properties.DeepCopyAuthProperties undefined (type AuthProperties has no
114+
// field or method DeepCopyAuthProperties)
115+
DeepCopyAuthProperties() AuthProperties
113116
}
114117

115118
// BaseAuthProperties ...
@@ -148,6 +151,10 @@ func (b *BaseAuthProperties) GetSecret() string {
148151
return b.Secret
149152
}
150153

154+
func (b *BasicAuthProperties) DeepCopyAuthProperties() AuthProperties {
155+
return b
156+
}
157+
151158
// BasicAuthProperties Basic Auth Info
152159
type BasicAuthProperties struct {
153160
BaseAuthProperties
@@ -186,6 +193,10 @@ type BearerAuthProperties struct {
186193
Token string `json:"token" validate:"required"`
187194
}
188195

196+
func (b *BearerAuthProperties) DeepCopyAuthProperties() AuthProperties {
197+
return b
198+
}
199+
189200
// UnmarshalJSON ...
190201
func (b *BearerAuthProperties) UnmarshalJSON(data []byte) error {
191202
properties := make(map[string]json.RawMessage)
@@ -232,6 +243,10 @@ type OAuth2AuthProperties struct {
232243
RequestedIssuer string `json:"requestedIssuer,omitempty" validate:"omitempty,min=1"`
233244
}
234245

246+
func (b *OAuth2AuthProperties) DeepCopyAuthProperties() AuthProperties {
247+
return b
248+
}
249+
235250
// TODO: use reflection to unmarshal the keys and think on a generic approach to handle them
236251

237252
// UnmarshalJSON ...

model/callback_state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type CallbackState struct {
2828
EventDataFilter EventDataFilter `json:"eventDataFilter,omitempty"`
2929
}
3030

31+
func (in *CallbackState) DeepCopyState() State {
32+
return in
33+
}
34+
3135
// CallbackStateTimeout defines timeout settings for callback state
3236
type CallbackStateTimeout struct {
3337
StateExecTimeout *StateExecTimeout `json:"stateExecTimeout,omitempty"`

model/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ type Common struct {
2121
}
2222

2323
// Metadata information
24-
type Metadata map[string]interface{}
24+
type Metadata map[string]Object

0 commit comments

Comments
 (0)