From f80a216b63ce092d3880c9c4cf555a65a49697d2 Mon Sep 17 00:00:00 2001 From: Henry Avetisyan Date: Tue, 2 Jul 2024 15:17:49 -0700 Subject: [PATCH] skip conditions that are not present in domain (#118) Signed-off-by: Henry Avetisyan --- Makefile | 14 +++++++------- athenz/assertion.go | 13 ++++++++----- execution/pr-acc-test.sh | 2 +- execution/sys-test.sh | 2 +- screwdriver.yaml | 16 +++------------- scripts/git-tag.sh | 1 - scripts/goupdate.sh | 13 ------------- scripts/install_deps.sh | 41 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 61 insertions(+), 41 deletions(-) delete mode 100755 scripts/goupdate.sh create mode 100755 scripts/install_deps.sh diff --git a/Makefile b/Makefile index 568b5c3..0e00453 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ GOPKGNAME = github.com/AthenZ/terraform-provider-athenz -export GOPATH ?= $(shell go env GOPATH) +export GOPATH ?= $(shell /usr/local/go/bin/go env GOPATH) BINARY=terraform-provider-athenz FMT_LOG=/tmp/fmt.log @@ -23,14 +23,14 @@ ifndef SYS_TEST_KEY endif vet: - go vet $(GOPKGNAME)/... + /usr/local/go/bin/go vet $(GOPKGNAME)/... fmt: - gofmt -d . >$(FMT_LOG) + /usr/local/go/bin/gofmt -d . >$(FMT_LOG) @if [ -s $(FMT_LOG) ]; then echo gofmt FAIL; cat $(FMT_LOG); false; fi goimports: - go install golang.org/x/tools/cmd/goimports + /usr/local/go/bin/go install golang.org/x/tools/cmd/goimports go_import: goimports -d . >$(GOIMPORTS_LOG) @@ -44,18 +44,18 @@ build_linux: install_local: @echo VERSION: $(VERSION) OS_ARCH: $(OS_ARCH) GOOS: $(GOOS) GOARCH: $(GOARCH) - go build -o ${BINARY} + /usr/local/go/bin/go build -o ${BINARY} mkdir -p ~/.terraform.d/plugins/yahoo/provider/athenz/${VERSION}/${OS_ARCH} mv ${BINARY} ~/.terraform.d/plugins/yahoo/provider/athenz/${VERSION}/${OS_ARCH} unit: vet fmt - export TF_ACC=false ; go test -v $(GOPKGNAME)/... + export TF_ACC=false ; /usr/local/go/bin/go test -v $(GOPKGNAME)/... acc_test: vet fmt @echo acc_test: cacert: $(SYS_TEST_CA_CERT) @echo acc_test: cert: $(SYS_TEST_CERT) @echo acc_test: key: $(SYS_TEST_KEY) - export MEMBER_1=terraform-provider.athenz_provider_foo MEMBER_2=user.github-7654321 ADMIN_USER=user.github-7654321 SHORT_ID=github-7654321 TOP_LEVEL_DOMAIN=terraformTest DELEGATED_DOMAIN=terraform-provider-delegate DOMAIN=terraform-provider PARENT_DOMAIN=terraform-provider SUB_DOMAIN=Test DOMAIN=terraform-provider export TF_ACC=true export ATHENZ_CA_CERT=$(SYS_TEST_CA_CERT) export ATHENZ_ZMS_URL=https://localhost:4443/zms/v1 export ATHENZ_CERT=$(SYS_TEST_CERT) export ATHENZ_KEY=$(SYS_TEST_KEY) ; go test -v $(GOPKGNAME)/... + export MEMBER_1=terraform-provider.athenz_provider_foo MEMBER_2=user.github-7654321 ADMIN_USER=user.github-7654321 SHORT_ID=github-7654321 TOP_LEVEL_DOMAIN=terraformTest DELEGATED_DOMAIN=terraform-provider-delegate DOMAIN=terraform-provider PARENT_DOMAIN=terraform-provider SUB_DOMAIN=Test DOMAIN=terraform-provider export TF_ACC=true export ATHENZ_CA_CERT=$(SYS_TEST_CA_CERT) export ATHENZ_ZMS_URL=https://localhost:4443/zms/v1 export ATHENZ_CERT=$(SYS_TEST_CERT) export ATHENZ_KEY=$(SYS_TEST_KEY) ; /usr/local/go/bin/go test -v $(GOPKGNAME)/... test: unit diff --git a/athenz/assertion.go b/athenz/assertion.go index 882e6d0..778f286 100644 --- a/athenz/assertion.go +++ b/athenz/assertion.go @@ -288,11 +288,14 @@ func flattenAssertionConditions(list []*zms.AssertionCondition) []interface{} { c := make(map[string]interface{}, len(keys)) c["id"] = (int)(*condition.Id) for _, key := range keys { - c[key] = []map[string]interface{}{ - { - "operator": (int)(condition.ConditionsMap[zms.AssertionConditionKey(key)].Operator), - "value": (string)(condition.ConditionsMap[zms.AssertionConditionKey(key)].Value), - }, + conditionKey, ok := condition.ConditionsMap[zms.AssertionConditionKey(key)] + if ok { + c[key] = []map[string]interface{}{ + { + "operator": (int)(conditionKey.Operator), + "value": (string)(conditionKey.Value), + }, + } } } assertionConditions = append(assertionConditions, c) diff --git a/execution/pr-acc-test.sh b/execution/pr-acc-test.sh index 24f6ad4..871fb16 100755 --- a/execution/pr-acc-test.sh +++ b/execution/pr-acc-test.sh @@ -18,7 +18,7 @@ wget -O "${SD_ROOT_DIR}/terraform/terraform_${VERSION}_${OS_ARCH}.zip" "https:// unzip "${SD_ROOT_DIR}/terraform/terraform_${VERSION}_${OS_ARCH}.zip" -d ${SD_ROOT_DIR}/terraform ls ${SD_ROOT_DIR}/terraform chmod +x ${SD_ROOT_DIR}/terraform/terraform -sudo ln -sf ${SD_ROOT_DIR}/terraform/terraform /usr/local/bin +ln -sf ${SD_ROOT_DIR}/terraform/terraform /usr/local/bin ls /usr/local/bin terraform -v diff --git a/execution/sys-test.sh b/execution/sys-test.sh index 9a74e98..43fdf1e 100755 --- a/execution/sys-test.sh +++ b/execution/sys-test.sh @@ -29,7 +29,7 @@ if [[ ! $(which terraform) ]]; then unzip "${SD_ROOT_DIR}/terraform/terraform_${VERSION}_${OS_ARCH}.zip" -d ${SD_ROOT_DIR}/terraform ls ${SD_ROOT_DIR}/terraform chmod +x ${SD_ROOT_DIR}/terraform/terraform - sudo ln -sf ${SD_ROOT_DIR}/terraform/terraform /usr/local/bin + ln -sf ${SD_ROOT_DIR}/terraform/terraform /usr/local/bin ls /usr/local/bin terraform -v fi diff --git a/screwdriver.yaml b/screwdriver.yaml index fe5355e..0ac3420 100644 --- a/screwdriver.yaml +++ b/screwdriver.yaml @@ -1,7 +1,7 @@ # Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. shared: - image: vespaengine/vespa-build-centos7:latest + image: eclipse-temurin:11-jdk-focal settings: email: addresses: [athenz@yahooinc.com] @@ -30,12 +30,7 @@ jobs: - SD_DEPLOY_KEY steps: - install-deps: | - ./scripts/goupdate.sh - set -e - yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo - yum -y install wget docker-ce-cli - docker system info - ls -la $SD_DIND_SHARE_PATH + ./scripts/install_deps.sh - tag-prerelease-version: | ./scripts/git-tag.sh -r prerelease -t true - run-tests-prerelease-version: | @@ -58,12 +53,7 @@ jobs: requires: [~pr] steps: - install-deps: | - ./scripts/goupdate.sh - set -e - yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo - yum -y install wget docker-ce-cli - docker system info - ls -la $SD_DIND_SHARE_PATH + ./scripts/install_deps.sh - unit-test: | make unit ./execution/pr-acc-test.sh diff --git a/scripts/git-tag.sh b/scripts/git-tag.sh index b62459a..185d598 100755 --- a/scripts/git-tag.sh +++ b/scripts/git-tag.sh @@ -60,7 +60,6 @@ if [ -z $RELEASE_TYPE ]; then fi echo "Downloading gitversion" -yum install -y wget wget -O - https://github.com/screwdriver-cd/gitversion/releases/latest | egrep -o 'https://github.com/screwdriver-cd/gitversion/releases/expanded_assets/v[0-9.]*' | wget -O - -i - | diff --git a/scripts/goupdate.sh b/scripts/goupdate.sh deleted file mode 100755 index d03aeca..0000000 --- a/scripts/goupdate.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -ex - -sudo yum -y install wget -sudo yum erase -y go -go version || true -which go || true -LATEST_GO_VERSION="$(curl --silent https://go.dev/VERSION?m=text | grep go)"; -LATEST_GO_DOWNLOAD_URL="https://golang.org/dl/${LATEST_GO_VERSION}.linux-amd64.tar.gz" -wget ${LATEST_GO_DOWNLOAD_URL} -tar -C /usr/local -xzf go*.linux-amd64.tar.gz -sudo ln -s /usr/local/go/bin/* /usr/bin - -go version diff --git a/scripts/install_deps.sh b/scripts/install_deps.sh new file mode 100755 index 0000000..78ba69d --- /dev/null +++ b/scripts/install_deps.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -e + +apt-get update +apt-get clean +apt-get autoremove + +echo "-----------------Install libs: -----------------" +apt-get install -y libaio1 libnuma-dev build-essential libncurses5 aptitude net-tools gawk unzip + +echo "-----------------Install gcc: -----------------" +apt-get install -y software-properties-common +add-apt-repository -y ppa:ubuntu-toolchain-r/test +apt-get install -y gcc +apt-get install -y g++ + +echo "-----------------Install golang: -----------------" +LATEST_GO_VERSION="$(curl --silent https://go.dev/VERSION?m=text | grep go)"; + +wget https://go.dev/dl/${LATEST_GO_VERSION}.linux-amd64.tar.gz +tar -C /usr/local -xzf ${LATEST_GO_VERSION}.linux-amd64.tar.gz +export PATH=$PATH:/usr/local/go/bin + +echo "-----------------Install Docker: -----------------" +# Add Docker's official GPG key: +apt-get update +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - +apt-key fingerprint 0EBFCD88 + +add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" +apt-get update +apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin +docker system info +ls -la $SD_DIND_SHARE_PATH + +# check all installed dependencies +echo "-----------------Golang Version: -----------------" +go version +echo "-----------------Docker Version: -----------------" +docker version