From 0a0b8cee3e2c2beedbf8e6a1c16b349c95efecd8 Mon Sep 17 00:00:00 2001 From: Gregor Noczinski Date: Sat, 21 Nov 2020 13:02:35 +0100 Subject: [PATCH] Migrate to GitLab Actions (#1) Migrate to GitLab Actions --- .github/workflows/ci.yml | 39 ++++++ .gitlab-ci.yml | 51 -------- .kubor.yml | 13 -- Dockerfile | 19 --- kubernetes/environment_test.go | 2 + kubernetes/resources/serviceaccount_namespace | 1 + kubernetes/templates/01-deployment.yml | 66 ---------- kubernetes/templates/02-service.yml | 17 --- kuborw | 114 ------------------ kuborw.cmd | 85 ------------- proxy/cors.go | 24 ++-- proxy/secure.go | 4 +- rules/headers.go | 14 +-- rules/hostPattern.go | 14 +-- rules/method.go | 14 +-- rules/options.go | 6 +- rules/options_cors.go | 22 ++-- rules/types.go | 56 ++++----- 18 files changed, 119 insertions(+), 442 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .gitlab-ci.yml delete mode 100644 .kubor.yml delete mode 100644 Dockerfile create mode 100644 kubernetes/resources/serviceaccount_namespace delete mode 100644 kubernetes/templates/01-deployment.yml delete mode 100644 kubernetes/templates/02-service.yml delete mode 100755 kuborw delete mode 100644 kuborw.cmd diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b6f6915 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +on: [ push, pull_request ] +name: Continuous Integration +jobs: + test: + strategy: + matrix: + go-version: [ 1.15.x ] + os: [ ubuntu-latest ] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Install + run: | + go mod download + + - name: Packr + run: | + go run github.com/gobuffalo/packr/packr clean + go run github.com/gobuffalo/packr/packr -z -i fallback + + - name: Test + run: | + mkdir -p var + go test -v -race -covermode atomic "-coverprofile=var/profile.cov" ./... diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 77b5448..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,51 +0,0 @@ -image: echocat/kubor:v0.4.8 -services: - - docker:dind - -variables: - KUBOR_RELEASE: $CI_COMMIT_REF_NAME:$CI_COMMIT_SHA - KUBOR_LOG_COLOR_MODE: always - -stages: - - test:unit - - build - - test:integration - - deploy:development - - deploy:pre-production - - deploy:production - -test:code: - image: golang:1.12 - stage: test:unit - cache: - key: go-cache - paths: - - .go - variables: - GOPATH: "$CI_PROJECT_DIR/.go" - except: - variables: - - $CI_UNIT_TESTS == "skip" - - $CI_ALL_TESTS == "skip" - before_script: - - go mod download - script: - - go run github.com/gobuffalo/packr/packr clean - - go run github.com/gobuffalo/packr/packr -z -i fallback - - go test -v ./... - -build: - stage: build - cache: - key: go-cache - paths: - - .go - variables: - IMAGE: "echocat/lingress" - before_script: - - echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY - script: - - docker build --network host -t $IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHA --build-arg "REVISION=$CI_COMMIT_SHA" --build-arg "BRANCH=$CI_COMMIT_REF_NAME" --build-arg "SSH_PRIVATE_KEY=$SSH_PRIVATE_KEY" . - - docker tag $IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHA $IMAGE/$CI_COMMIT_REF_NAME:latest - - docker push $IMAGE/$CI_COMMIT_REF_NAME:$CI_COMMIT_SHA - - docker push $IMAGE/$CI_COMMIT_REF_NAME:latest diff --git a/.kubor.yml b/.kubor.yml deleted file mode 100644 index a3444c6..0000000 --- a/.kubor.yml +++ /dev/null @@ -1,13 +0,0 @@ -groupId: echocat -artifactId: lingress - -values: - - podMinMemory: 64Mi - podMaxMemory: 256Mi - podMinCpu: 250m - podMaxCpu: 500m - replicas: 1 - logLevel: info - behindOtherReverseProxy: 'true' - corsEnabled: 'false' - forceSecureEnabled: '!false' diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 7d05bd8..0000000 --- a/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM golang:1.12 as builder -ARG GROUP_ID="echocat" -ARG ARTIFACT_ID="lingress" -ARG REVISION="latest" -ARG BRANCH="development" -ARG SSH_PRIVATE_KEY -COPY . /src -WORKDIR /src -RUN export GOPATH=/src/.go && mkdir -p $GOPATH \ - && go mod download \ - && go run github.com/gobuffalo/packr/packr clean \ - && go run github.com/gobuffalo/packr/packr -z -i fallback \ - && CGO_ENABLED=0 go run github.com/echocat/lingress/build -o /tmp/lingress ./lingress - -FROM scratch -USER 5000 -WORKDIR / -COPY --from=builder /tmp/lingress /lingress -ENTRYPOINT ["/lingress"] diff --git a/kubernetes/environment_test.go b/kubernetes/environment_test.go index f769b4a..e4b4ff5 100644 --- a/kubernetes/environment_test.go +++ b/kubernetes/environment_test.go @@ -165,6 +165,7 @@ func Test_Environment_get_with_incluster_succeeds(t *testing.T) { env := MustNewEnvironment() env.tokenFile = "resources/serviceaccount_token" env.rootCAFile = "resources/serviceaccount_ca.crt" + env.namespaceFile = "resources/serviceaccount_namespace" err := env.Kubeconfig.Set(KubeconfigInCluster) g.Expect(err).To(BeNil()) @@ -174,6 +175,7 @@ func Test_Environment_get_with_incluster_succeeds(t *testing.T) { g.Expect(instance).ToNot(BeNil()) g.Expect(instance.restConfig).NotTo(BeNil()) g.Expect(instance.contextName).To(Equal("incluster")) + g.Expect(env.Namespace).To(Equal("aNamespace")) } func Test_Environment_get_with_incluster_without_envVarServicePort_fails(t *testing.T) { diff --git a/kubernetes/resources/serviceaccount_namespace b/kubernetes/resources/serviceaccount_namespace new file mode 100644 index 0000000..720c0e3 --- /dev/null +++ b/kubernetes/resources/serviceaccount_namespace @@ -0,0 +1 @@ +aNamespace \ No newline at end of file diff --git a/kubernetes/templates/01-deployment.yml b/kubernetes/templates/01-deployment.yml deleted file mode 100644 index 5b733ed..0000000 --- a/kubernetes/templates/01-deployment.yml +++ /dev/null @@ -1,66 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{.ArtifactId}} - namespace: {{.GroupId}} -spec: - replicas: {{.Values.replicas}} - selector: - matchLabels: - name: {{.ArtifactId}} - template: - metadata: - labels: - name: {{.ArtifactId}} - spec: - imagePullSecrets: - - name: {{.Values.pullScret}} - containers: - - name: service - image: {{.GroupId}}/{{.ArtifactId}}/{{.Release}} - imagePullPolicy: Always - args: - - '--listen=:8080' - - '--kubeconfig=incluster' - - '--cors.enabled={{.Values.corsEnabled}}' - - '--forceSecure.enabled={{.Values.forceSecureEnabled}}' - {{if eq .Values.behindOtherReverseProxy "true"}} - - '--behindOtherReverseProxy' - {{end}} - - '--logLevel={{.Env | optional "TARGET_LOG_LEVEL" | default .Values.logLevel}}' - - '--ingressClass=main' - - '--ingressClass=' - - '--header.response=Strict-Transport-Security: max-age=31536000; includeSubDomains' - - '--header.response=X-Content-Type-Options: nosniff' - - '--header.response=X-Frame-Options: SAMEORIGIN' - - '--header.response=X-XSS-Protection: 1; mode=block' - ports: - - containerPort: 8080 - - containerPort: 8090 - resources: - limits: - cpu: {{.Values.podMaxCpu}} - memory: {{.Values.podMaxMemory}} - requests: - cpu: {{.Values.podMinCpu}} - memory: {{.Values.podMinMemory}} - readinessProbe: - failureThreshold: 5 - httpGet: - path: /health - port: 8090 - scheme: HTTP - initialDelaySeconds: 3 - periodSeconds: 5 - successThreshold: 1 - timeoutSeconds: 15 - livenessProbe: - failureThreshold: 5 - httpGet: - path: /health - port: 8090 - scheme: HTTP - initialDelaySeconds: 3 - periodSeconds: 5 - successThreshold: 1 - timeoutSeconds: 15 diff --git a/kubernetes/templates/02-service.yml b/kubernetes/templates/02-service.yml deleted file mode 100644 index c402bc5..0000000 --- a/kubernetes/templates/02-service.yml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{.ArtifactId}} - namespace: {{.GroupId}} -spec: - selector: - name: {{.ArtifactId}} - ports: - - name: service - protocol: TCP - port: 8080 - targetPort: 8080 - - name: management - protocol: TCP - port: 8090 - targetPort: 8090 diff --git a/kuborw b/kuborw deleted file mode 100755 index 3a0caeb..0000000 --- a/kuborw +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/sh -############################################################################## -## ## -## kubor bootstrap wrapper for *NIX systems ## -## ## -############################################################################## -version="v0.4.7" - -############################################################################## -## DO NOT EDIT BELOW!! ## -############################################################################## -scriptName="`basename \"$0\"`" -dirName="`dirname \"$0\"`" - -fatal() { - echo -e "FATAL: $*" 1>&2 - exit 1 -} - -info() { - echo -e "INFO: $*" 1>&2 -} - -doDownload() { - binaryDownloadUrl="https://github.com/echocat/kubor/releases/download/${version}/kubor-${os}-${arch}${ext}" - info "Downloading ${binaryDownloadUrl}..." - - mkdir -p "${binariesCacheDir}" - if [ "$?" != "0" ]; then - fatal "Cannot create cache directory for storing binaries. See above." - fi - tmpFile="${binary}.tmp" - if [ "$?" != "0" ]; then - fatal "Was not able to create a temporary file. See above." - fi - - if which curl > /dev/null; then - curl -sSLf "${binaryDownloadUrl}" > "${tmpFile}" - if [ "$?" != "0" ]; then - fatal "Was not able to download binary from ${binaryDownloadUrl}. See above." - fi - elif which wget > /dev/null; then - wget -q -O "${tmpFile}" "${binaryDownloadUrl}" - if [ "$?" != "0" ]; then - fatal "Was not able to download binary from ${binaryDownloadUrl}. See above." - fi - else - fatal "Neither curl nor wget found in \$PATH. Please install at least one of those tools." - fi - - chmod +x "${tmpFile}" - if [ "$?" != "0" ]; then - fatal "Was not able to make ${tmpFile} executable. See above." - fi - - mv "${tmpFile}" "${binary}" - if [ "$?" != "0" ]; then - fatal "Was not able to move ${tmpFile} to ${binary}. See above." - fi -} - -plainOs="`uname -s`" -case "${plainOs}" in - Linux*) os="linux";; - Darwin*) os="darwin";; - CYGWIN*) os="windows";; - MINGW*) os="windows";; - *) fatal "Unsupported operating system: ${plainOs}" -esac - -plainArch="`uname -m`" -case "${plainArch}" in - x86_64*) arch="amd64";; - i386*) arch="386";; - *) fatal "Unsupported architecture: ${plainArch}" -esac - -case "${os}" in - windows*) ext=".exe";; - *) ext="";; -esac - -binariesCacheDir="${HOME}/.kubor/binaries" -binaryFileName="kubor-${os}-${arch}-${version}${ext}" -binary="${binariesCacheDir}/${binaryFileName}" - -if [ "${KUBORW_IGNORE_DOCKER_IMAGE_MISMATCH}" != "yes" ]; then - if [ -r "/usr/lib/kubor/docker-version" ]; then - dockerVersion="`cat /usr/lib/kubor/docker-version`" - if [ "${dockerVersion}" != "${version}" ]; then - if [ -r "/usr/lib/kubor/docker-image" ]; then - dockerImage="`cat /usr/lib/kubor/docker-image`" - else - dockerImage="echocat/kubor" - fi - fatal "You're are using kuborw with version ${version} inside of a kubor docker image with version ${dockerVersion}." \ - "This could lead to unexpected behaviors. We recommend to align both versions together by either:" \ - "\n\t1.) Change ${0} to: version=\"${dockerVersion}\"" \ - "\n\t2.) ... or set the used image to: ${dockerImage}:${version}" \ - "\nYou can suppress this error by set KUBORW_IGNORE_DOCKER_IMAGE_MISMATCH=yes" - fi - fi -fi - -if [ -x "${binary}" ]; then - "${binary}" version 2>&1 | grep "${version}" > /dev/null - if [ "$?" != "0" ]; then - doDownload - fi -else - doDownload -fi - -"${binary}" "$@" diff --git a/kuborw.cmd b/kuborw.cmd deleted file mode 100644 index b27e331..0000000 --- a/kuborw.cmd +++ /dev/null @@ -1,85 +0,0 @@ -@ECHO OFF -SETLOCAL -REM ############################################################################## -REM ## ## -REM ## kubor bootstrap wrapper for Windows systems ## -REM ## ## -REM ############################################################################## -REM ## DO NOT EDIT!! ## -REM ############################################################################## - -SET scriptName=%~nx0 -SET dirName=%~dp0 -SET os=windows -SET arch=386 -SET ext=.exe -IF "%PROCESSOR_ARCHITECTURE%" == "AMD64" ( - SET arch=amd64 -) - -IF NOT EXIST "%dirName%\kuborw" ( - CALL :fatal This kubor wrapper was not initiated correctly. Try download kubor binary and run: kubor wrapper install - EXIT /b 1 -) -SET findCmd=FINDSTR /B "version=" "%dirName%\kuborw" -FOR /f %%i IN ('%findCmd%') DO SET versionLine=%%i -SET version=%versionLine:~9,-1% - -SET binariesCacheDir=%LOCALAPPDATA%\kubor\binaries -IF NOT EXIST "%binariesCacheDir%" ( - md "%binariesCacheDir%" -) -IF NOT ERRORLEVEL 0 ( - CALL :fatal "Cannot create cache directory for storing binaries. See above." -) -SET binaryFileName=kubor-%os%-%arch%-%version%%ext% -SET binary=%binariesCacheDir%\%binaryFileName% - -IF NOT EXIST "%binary%" ( - CALL :doDownload -) ELSE ( - "%binary%" version 2>&1 | find "%version%" > NUL - IF NOT ERRORLEVEL 0 ( - CALL :doDownload - ) -) - -IF "%ERRORLEVEL%" == "0" ( - "%binary%" %* -) -EXIT /b %ERRORLEVEL% -GOTO :eofSuccess - -:doDownload - SETLOCAL - SET binaryDownloadUrl=https://github.com/echocat/kubor/releases/download/%version%/kubor-%os%-%arch%%ext% - CALL :info Downloading %binaryDownloadUrl%... - - SET tmpFile=%binary%.%RANDOM%.tmp - PowerShell -Command "(New-Object Net.WebClient).DownloadFile('%binaryDownloadUrl%','%tmpFile%')" - IF "%ERRORLEVEL%" == "0" ( - MOVE /Y "%tmpFile%" "%binary%" > NUL - IF NOT "%ERRORLEVEL%" == "0" ( - CALL :fatal Was not able to move %tmpFile% to %binary%. See above. - ) - ) ELSE ( - CALL :fatal Was not able to download binary from %binaryDownloadUrl%. See above. - ) - ENDLOCAL - EXIT /b %ERRORLEVEL% - -:fatal - ECHO.FATAL: %* - GOTO :eofError - EXIT /b 1 - -:info - ECHO.INFO: %* - EXIT /b 0 - -:eofError -EXIT /b 1 -GOTO :eof - -:eofSuccess -EXIT /b 0 diff --git a/proxy/cors.go b/proxy/cors.go index 49f6689..cdee51f 100644 --- a/proxy/cors.go +++ b/proxy/cors.go @@ -20,22 +20,22 @@ var ( ) type CorsInterceptor struct { - AllowedOriginsHost rules.ForceableHostPatterns - AllowedMethods rules.ForceableMethods - AllowedHeaders rules.ForceableHeaderNames - AllowedCredentials rules.ForceableBool - MaxAge rules.ForceableDuration - Enabled rules.ForceableBool + AllowedOriginsHost rules.ForcibleHostPatterns + AllowedMethods rules.ForcibleMethods + AllowedHeaders rules.ForcibleHeaderNames + AllowedCredentials rules.ForcibleBool + MaxAge rules.ForcibleDuration + Enabled rules.ForcibleBool } func NewCorsInterceptor() *CorsInterceptor { return &CorsInterceptor{ - AllowedOriginsHost: rules.NewForceableHostPatterns(rules.HostPatterns{}, false), - AllowedMethods: rules.NewForceableMethods(rules.Methods{}, false), - AllowedHeaders: rules.NewForceableHeaders(rules.HeaderNames{}, false), - AllowedCredentials: rules.NewForceableBool(rules.True, false), - MaxAge: rules.NewForceableDuration(defaultMaxAge, false), - Enabled: rules.NewForceableBool(rules.False, false), + AllowedOriginsHost: rules.NewForcibleHostPatterns(rules.HostPatterns{}, false), + AllowedMethods: rules.NewForcibleMethods(rules.Methods{}, false), + AllowedHeaders: rules.NewForcibleHeaders(rules.HeaderNames{}, false), + AllowedCredentials: rules.NewForcibleBool(rules.True, false), + MaxAge: rules.NewForcibleDuration(defaultMaxAge, false), + Enabled: rules.NewForcibleBool(rules.False, false), } } diff --git a/proxy/secure.go b/proxy/secure.go index cbb8f37..d26a70d 100644 --- a/proxy/secure.go +++ b/proxy/secure.go @@ -16,12 +16,12 @@ func init() { } type ForceSecureInterceptor struct { - Enabled rules.ForceableBool + Enabled rules.ForcibleBool } func NewForceSecureInterceptor() *ForceSecureInterceptor { return &ForceSecureInterceptor{ - Enabled: rules.NewForceableBool(rules.False, false), + Enabled: rules.NewForcibleBool(rules.False, false), } } diff --git a/rules/headers.go b/rules/headers.go index ed62929..2dc2853 100644 --- a/rules/headers.go +++ b/rules/headers.go @@ -76,17 +76,17 @@ func (instance HeaderNames) IsPresent() bool { return len(instance) > 0 } -type ForceableHeaderNames struct { - Forceable +type ForcibleHeaderNames struct { + Forcible } -func NewForceableHeaders(init HeaderNames, forced bool) ForceableHeaderNames { +func NewForcibleHeaders(init HeaderNames, forced bool) ForcibleHeaderNames { val := init - return ForceableHeaderNames{ - Forceable: NewForceable(&val, forced), + return ForcibleHeaderNames{ + Forcible: NewForcible(&val, forced), } } -func (instance ForceableHeaderNames) Evaluate(other HeaderNames, def HeaderNames) HeaderNames { - return instance.Forceable.Evaluate(other, def).(HeaderNames) +func (instance ForcibleHeaderNames) Evaluate(other HeaderNames, def HeaderNames) HeaderNames { + return instance.Forcible.Evaluate(other, def).(HeaderNames) } diff --git a/rules/hostPattern.go b/rules/hostPattern.go index 77db0b4..9e31824 100644 --- a/rules/hostPattern.go +++ b/rules/hostPattern.go @@ -94,17 +94,17 @@ func (instance HostPatterns) IsPresent() bool { return len(instance) > 0 } -type ForceableHostPatterns struct { - Forceable +type ForcibleHostPatterns struct { + Forcible } -func NewForceableHostPatterns(init HostPatterns, forced bool) ForceableHostPatterns { +func NewForcibleHostPatterns(init HostPatterns, forced bool) ForcibleHostPatterns { val := init - return ForceableHostPatterns{ - Forceable: NewForceable(&val, forced), + return ForcibleHostPatterns{ + Forcible: NewForcible(&val, forced), } } -func (instance ForceableHostPatterns) Evaluate(other HostPatterns, def HostPatterns) HostPatterns { - return instance.Forceable.Evaluate(other, def).(HostPatterns) +func (instance ForcibleHostPatterns) Evaluate(other HostPatterns, def HostPatterns) HostPatterns { + return instance.Forcible.Evaluate(other, def).(HostPatterns) } diff --git a/rules/method.go b/rules/method.go index f2dab20..b1efc82 100644 --- a/rules/method.go +++ b/rules/method.go @@ -119,17 +119,17 @@ func (instance Methods) IsPresent() bool { return len(instance) > 0 } -type ForceableMethods struct { - Forceable +type ForcibleMethods struct { + Forcible } -func NewForceableMethods(init Methods, forced bool) ForceableMethods { +func NewForcibleMethods(init Methods, forced bool) ForcibleMethods { val := init - return ForceableMethods{ - Forceable: NewForceable(&val, forced), + return ForcibleMethods{ + Forcible: NewForcible(&val, forced), } } -func (instance ForceableMethods) Evaluate(other Methods, def Methods) Methods { - return instance.Forceable.Evaluate(other, def).(Methods) +func (instance ForcibleMethods) Evaluate(other Methods, def Methods) Methods { + return instance.Forcible.Evaluate(other, def).(Methods) } diff --git a/rules/options.go b/rules/options.go index 4486a10..87f6489 100644 --- a/rules/options.go +++ b/rules/options.go @@ -77,10 +77,10 @@ func AnnotationIsTrue(name, value string) (Bool, error) { return 0, fmt.Errorf("illegal boolean value for annotation %s: %s", name, value) } -func AnnotationIsForceableBool(name, value string) (result ForceableBool, err error) { - result = NewForceableBool(False, false) +func AnnotationIsForcibleBool(name, value string) (result ForcibleBool, err error) { + result = NewForcibleBool(False, false) if err := result.Set(value); err != nil { - return ForceableBool{}, fmt.Errorf("illegal boolean value for annotation %s: %s", name, value) + return ForcibleBool{}, fmt.Errorf("illegal boolean value for annotation %s: %s", name, value) } return } diff --git a/rules/options_cors.go b/rules/options_cors.go index f74b07a..9448a00 100644 --- a/rules/options_cors.go +++ b/rules/options_cors.go @@ -31,12 +31,12 @@ func OptionsCorsOf(rule Rule) *OptionsCors { } type OptionsCors struct { - Enabled ForceableBool `json:"enabled,omitempty"` - AllowedOriginsHost HostPatterns `json:"allowedOriginsHost,omitempty"` - AllowedMethods Methods `json:"allowedMethods,omitempty"` - AllowedHeaders HeaderNames `json:"allowedHeaders,omitempty"` - AllowedCredentials Bool `json:"allowedCredentials,omitempty"` - MaxAge Duration `json:"maxAge,omitempty"` + Enabled ForcibleBool `json:"enabled,omitempty"` + AllowedOriginsHost HostPatterns `json:"allowedOriginsHost,omitempty"` + AllowedMethods Methods `json:"allowedMethods,omitempty"` + AllowedHeaders HeaderNames `json:"allowedHeaders,omitempty"` + AllowedCredentials Bool `json:"allowedCredentials,omitempty"` + MaxAge Duration `json:"maxAge,omitempty"` } func (instance OptionsCors) Name() string { @@ -74,17 +74,17 @@ func (instance *OptionsCors) Set(annotations Annotations) (err error) { return } -func evaluateOptionCorsEnable(annotations map[string]string) (ForceableBool, error) { +func evaluateOptionCorsEnable(annotations map[string]string) (ForcibleBool, error) { if v, ok := annotations[annotationCorsEnabled]; ok { - return AnnotationIsForceableBool(annotationCorsEnabled, v) + return AnnotationIsForcibleBool(annotationCorsEnabled, v) } if v, ok := annotations[annotationCorsEnabledAlternative]; ok { - return AnnotationIsForceableBool(annotationCorsEnabledAlternative, v) + return AnnotationIsForcibleBool(annotationCorsEnabledAlternative, v) } if v, ok := annotations[annotationNginxCorsEnable]; ok { - return AnnotationIsForceableBool(annotationNginxCorsEnable, v) + return AnnotationIsForcibleBool(annotationNginxCorsEnable, v) } - return NewForceableBool(NotDefined, false), nil + return NewForcibleBool(NotDefined, false), nil } func evaluateOptionCorsAllowedOriginsHosts(annotations map[string]string) (HostPatterns, error) { diff --git a/rules/types.go b/rules/types.go index 0c7fc86..3b3be11 100644 --- a/rules/types.go +++ b/rules/types.go @@ -80,18 +80,18 @@ func (instance Bool) IsPresent() bool { return instance == True || instance == False } -type ForceableBool struct { - Forceable +type ForcibleBool struct { + Forcible } -func NewForceableBool(init Bool, forced bool) ForceableBool { +func NewForcibleBool(init Bool, forced bool) ForcibleBool { val := init - return ForceableBool{ - Forceable: NewForceable(&val, forced), + return ForcibleBool{ + Forcible: NewForcible(&val, forced), } } -func (instance ForceableBool) GetOr(def bool) bool { +func (instance ForcibleBool) GetOr(def bool) bool { switch *(instance.value.(*Bool)) { case True: return true @@ -101,33 +101,33 @@ func (instance ForceableBool) GetOr(def bool) bool { return def } -func (instance ForceableBool) Select(target ForceableBool) ForceableBool { - return ForceableBool{ - Forceable: instance.Forceable.Select(target.Forceable), +func (instance ForcibleBool) Select(target ForcibleBool) ForcibleBool { + return ForcibleBool{ + Forcible: instance.Forcible.Select(target.Forcible), } } -func (instance ForceableBool) Evaluate(other Bool, def bool) bool { - return instance.Forceable.Evaluate(other, NewBool(def)).(bool) +func (instance ForcibleBool) Evaluate(other Bool, def bool) bool { + return instance.Forcible.Evaluate(other, NewBool(def)).(bool) } -type Forceable struct { +type Forcible struct { value MutableValue forced bool } -func NewForceable(value MutableValue, forced bool) Forceable { - return Forceable{ +func NewForcible(value MutableValue, forced bool) Forcible { + return Forcible{ value: value, forced: forced, } } -func (instance Forceable) Get() interface{} { +func (instance Forcible) Get() interface{} { return instance.value.Get() } -func (instance Forceable) Evaluate(other Value, def Value) interface{} { +func (instance Forcible) Evaluate(other Value, def Value) interface{} { if instance.forced { if instance.IsPresent() { return instance.Get() @@ -140,7 +140,7 @@ func (instance Forceable) Evaluate(other Value, def Value) interface{} { return def.Get() } -func (instance Forceable) Select(target Forceable) Forceable { +func (instance Forcible) Select(target Forcible) Forcible { if instance.forced { return instance } @@ -150,7 +150,7 @@ func (instance Forceable) Select(target Forceable) Forceable { return instance } -func (instance *Forceable) Set(plain string) error { +func (instance *Forcible) Set(plain string) error { forced := false if len(plain) > 0 && plain[0] == '!' { forced = true @@ -163,7 +163,7 @@ func (instance *Forceable) Set(plain string) error { return nil } -func (instance Forceable) String() string { +func (instance Forcible) String() string { result := "" if instance.forced { result += "!" @@ -174,11 +174,11 @@ func (instance Forceable) String() string { return result } -func (instance Forceable) IsPresent() bool { +func (instance Forcible) IsPresent() bool { return instance.value != nil && instance.value.IsPresent() } -func (instance Forceable) IsForced() bool { +func (instance Forcible) IsForced() bool { return instance.forced } @@ -223,17 +223,17 @@ func (instance Duration) IsPresent() bool { return instance > 0 } -type ForceableDuration struct { - Forceable +type ForcibleDuration struct { + Forcible } -func NewForceableDuration(init Duration, forced bool) ForceableDuration { +func NewForcibleDuration(init Duration, forced bool) ForcibleDuration { val := init - return ForceableDuration{ - Forceable: NewForceable(&val, forced), + return ForcibleDuration{ + Forcible: NewForcible(&val, forced), } } -func (instance ForceableDuration) Evaluate(other Duration, def Duration) Duration { - return instance.Forceable.Evaluate(other, def).(Duration) +func (instance ForcibleDuration) Evaluate(other Duration, def Duration) Duration { + return instance.Forcible.Evaluate(other, def).(Duration) }