Skip to content

Commit

Permalink
fix: fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anaik91 committed Oct 23, 2023
1 parent 9f0b81f commit 485822f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
GROOVY_NPM_GROOVY_LINT_FILTER_REGEX_EXCLUDE: "Jenkinsfile"
MARKDOWN_MARKDOWN_LINK_CHECK_DISABLE_ERRORS: true
PYTHON_MYPY_DISABLE_ERRORS: true
PYTHON_BANDIT_DISABLE_ERRORS: true
DISABLE_LINTERS: PYTHON_PYLINT

commit-messages:
name: Conventional Commits Lint
Expand Down
Empty file added .pylintrc
Empty file.
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ FROM google/cloud-sdk:alpine
ENV HELM_BASE_URL="https://get.helm.sh"
ENV HELM_VERSION="3.13.1"
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN apk add --update --no-cache py-pip==23.1.2-r0 openssh==9.3_p2-r0
RUN python3 -m pip install --no-cache-dir \
RUN apk add --update --no-cache py-pip==23.1.2-r0 openssh==9.3_p2-r0 && \
python3 -m pip install --no-cache-dir \
requests==2.25.1 \
jsonschema==4.19.1 \
jsonschema-specifications==2023.7.1 \
jmespath==1.0.1 \
kubernetes==27.2.0 \
ansible-core==2.15.5 \
ansible==8.5.0 && \
ansible-galaxy collection install ansible.posix && \
case $(uname -m) in \
ansible-galaxy collection install ansible.posix && \
case $(uname -m) in \
x86_64) ARCH=amd64; ;; \
armv7l) ARCH=arm; ;; \
aarch64) ARCH=arm64; ;; \
ppc64le) ARCH=ppc64le; ;; \
s390x) ARCH=s390x; ;; \
*) echo "un-supported arch, exit ..."; exit 1; ;; \
esac && \
apk add --update --no-cache wget==1.21.4-r0 git==2.40.1-r0 curl==8.4.0-r0 bash==5.2.15-r5 yq==4.33.3-r4 && \
wget --progress=dot:giga "${HELM_BASE_URL}/helm-v${HELM_VERSION}-linux-${ARCH}.tar.gz" -O - | tar -xz && \
mv "linux-${ARCH}/helm" /usr/bin/helm && \
chmod +x /usr/bin/helm && \
rm -rf "linux-${ARCH}" && \
gcloud components install kubectl
apk add --update --no-cache wget==1.21.4-r0 git==2.40.1-r0 \
curl==8.4.0-r0 bash==5.2.15-r5 yq==4.33.3-r4 && \
wget --progress=dot:giga "${HELM_BASE_URL}/helm-v${HELM_VERSION}-linux-${ARCH}.tar.gz" -O - | tar -xz && \
mv "linux-${ARCH}/helm" /usr/bin/helm && \
chmod +x /usr/bin/helm && \
rm -rf "linux-${ARCH}" && \
gcloud components install kubectl
28 changes: 0 additions & 28 deletions roles/certificates/files/generate_client_certs.sh

This file was deleted.

26 changes: 0 additions & 26 deletions roles/certificates/files/generate_server_certs.sh

This file was deleted.

17 changes: 10 additions & 7 deletions roles/validate-api-calls/files/deploy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from time import sleep
import argparse


class Apigee:
def __init__(
self,
Expand Down Expand Up @@ -48,7 +49,7 @@ def is_token_valid(self, token):
return True
return False

def get_access_token(self,access_token):
def get_access_token(self, access_token):
token = access_token
if token is not None:
if self.apigee_type == "x":
Expand Down Expand Up @@ -86,7 +87,7 @@ def get_api(self, api_name):
revision = response.json().get('revision', ['1'])
return True, revision
else:
return False,None
return False, None

def create_api(self, api_name, proxy_bundle_path):
url = f"{self.baseurl}/apis?action=import&name={api_name}&validate=true" # noqa
Expand Down Expand Up @@ -172,7 +173,7 @@ def deploy_api_bundle(self, env, api_name, proxy_bundle_path, api_force_redeploy
if self.get_api_revisions_deployment(
env, api_name, api_rev
):
print(f"INFO : Proxy {api_name} already active in to {env} in Apigee Org {self.org} !")
print(f"INFO : Proxy {api_name} already active in to {env} in Apigee Org {self.org} !") # noqa
return True
else:
if self.deploy_api(env, api_name, api_rev):
Expand Down Expand Up @@ -235,14 +236,15 @@ def fetch_api_revision(self, api_type, api_name, revision, export_dir): # noqa
return True
return False


def main():
parser = argparse.ArgumentParser(description='Deploy Apigee API proxy bundle')
parser = argparse.ArgumentParser(description='Deploy Apigee API proxy bundle') # noqa
parser.add_argument('--project_id', help='GCP Project ID')
parser.add_argument('--env', help='Apigee Environment Name')
parser.add_argument('--api_name', help='Apigee API Name')
parser.add_argument('--api_bundle_path', help='Apigee API Proxy bundle path')
parser.add_argument('--api_bundle_path', help='Apigee API Proxy bundle path') # noqa
parser.add_argument('--access_token', help='GCP OAuth Access Token')
parser.add_argument('--api_redeploy', help='Redploy API',action="store_true")
parser.add_argument('--api_redeploy', help='Redploy API',action="store_true") # noqa
args = parser.parse_args()
TargetApigee = Apigee(
"x",
Expand All @@ -260,5 +262,6 @@ def main():
print(f"Proxy: {args.api_name} deployment failed.")
sys.exit(1)


if __name__ == '__main__':
main()
main()
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import json
import collections


class Apigee:
def __init__(
self,
Expand All @@ -40,13 +41,13 @@ def __init__(
else "Basic {}".format(access_token) # noqa
}

def get_token_user(self,token):
def get_token_user(self, token):
url = f"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={token}" # noqa
response = requests.get(url)
if response.status_code == 200:
return response.json()['email']
return ''

def is_token_valid(self, token):
url = f"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token={token}" # noqa
response = requests.get(url)
Expand All @@ -55,24 +56,23 @@ def is_token_valid(self, token):
return True
return False


def get_access_token(self,access_token):
def get_access_token(self, access_token):
token = access_token
if token is not None:
if self.apigee_type == "x":
if self.is_token_valid(token):
return token
else:
print(
'please run "export APIGEE_ACCESS_TOKEN=$(gcloud auth print-access-token)" first !! ' # noqa type: ignore
'please run "export APIGEE_ACCESS_TOKEN=$(gcloud auth print-access-token)" first !! ' # noqa pylint: disable=line-too-long
)
sys.exit(1)
else:
return token
else:
if self.apigee_type == "x":
print(
'please run "export APIGEE_ACCESS_TOKEN=$(gcloud auth print-access-token)" first !! ' # noqa
'please run "export APIGEE_ACCESS_TOKEN=$(gcloud auth print-access-token)" first !! ' # noqa pylint: disable=line-too-long
)
else:
print("please export APIGEE_OPDK_ACCESS_TOKEN")
Expand All @@ -87,38 +87,40 @@ def set_auth_header(self):
}

def get_org(self):
url=f"{self.baseurl}"
url = f"{self.baseurl}"
headers = self.auth_header.copy()
response = requests.request("GET", url, headers=headers)
if response.status_code == 200:
return True
else:
return False
def get_environment(self,env):
url=f"{self.baseurl}/environments/{env}"

def get_environment(self, env):
url = f"{self.baseurl}/environments/{env}"
headers = self.auth_header.copy()
response = requests.request("GET", url, headers=headers)
if response.status_code == 200:
return True
else:
return False

def get_env_group(self,env_group):
url=f"{self.baseurl}/envgroups/{env_group}"
def get_env_group(self, env_group):
url = f"{self.baseurl}/envgroups/{env_group}"
headers = self.auth_header.copy()
response = requests.request("GET", url, headers=headers)
if response.status_code == 200:
return True,response.json()
return True, response.json()
else:
return False,None
return False, None

def compare_lists(l1,l2):
if(collections.Counter(l1)==collections.Counter(l2)):
return True

def compare_lists(l1, l2):
if collections.Counter(l1) == collections.Counter(l2):
return True
else:
return False


def main():
parser = argparse.ArgumentParser(description='Validates Apigee Objects')
parser.add_argument('--input_data', help='Apigee Input data')
Expand All @@ -138,28 +140,29 @@ def main():
validations = []
authenticated_user = TargetApigee.get_token_user(args.access_token)
if not TargetApigee.get_org():
validations.append(f"Apigee Organization : {apigee_org} doesnt exist OR user {authenticated_user} doesnt have permissions ")
validations.append(f"Apigee Organization : {apigee_org} doesnt exist OR user {authenticated_user} doesnt have permissions ") # noqa pylint: disable=line-too-long

for apigee_env in apigee_envs:
if not TargetApigee.get_environment(apigee_env['name']):
validations.append(f"Apigee Environment : {apigee_env['name']} doesnt exist OR user {authenticated_user} doesnt have permissions ")
validations.append(f"Apigee Environment : {apigee_env['name']} doesnt exist OR user {authenticated_user} doesnt have permissions ") # noqa pylint: disable=line-too-long

for apigee_vhost in apigee_vhosts:
apigee_vhost_status, apigee_vhost_info = TargetApigee.get_env_group(apigee_vhost['name'])
apigee_vhost_status, apigee_vhost_info = TargetApigee.get_env_group(apigee_vhost['name']) # noqa pylint: disable=line-too-long
if not apigee_vhost_status:
validations.append(f"Apigee Environment Group : {apigee_vhost['name']} doesnt exist OR user {authenticated_user} doesnt have permissions ")
validations.append(f"Apigee Environment Group : {apigee_vhost['name']} doesnt exist OR user {authenticated_user} doesnt have permissions ") # noqa pylint: disable=line-too-long

if apigee_vhost_status:
apigee_vhost_hostname = apigee_vhost.get('hostnames',[])
apigee_vhost_info_hostname = apigee_vhost_info.get('hostnames',[])
if not compare_lists(apigee_vhost_hostname, apigee_vhost_info_hostname):
validations.append(f"Apigee Environmrnt Group {apigee_vhost['name']} hostnames {apigee_vhost_hostname} dont match the hostnames in Apigee Management API: {apigee_vhost_info_hostname}")
apigee_vhost_hostname = apigee_vhost.get('hostnames', [])
apigee_vhost_info_hostname = apigee_vhost_info.get('hostnames', []) # noqa pylint: disable=line-too-long
if not compare_lists(apigee_vhost_hostname, apigee_vhost_info_hostname): # noqa pylint: disable=line-too-long
validations.append(f"Apigee Environmrnt Group {apigee_vhost['name']} hostnames {apigee_vhost_hostname} dont match the hostnames in Apigee Management API: {apigee_vhost_info_hostname}") # noqa pylint: disable=line-too-long

if len(validations) > 0:
print('Validation Errors found !')
print("\n".join(validations))
sys.exit(1)
print('Apigee Control plane validations successfull')


if __name__ == '__main__':
main()
main()
Loading

0 comments on commit 485822f

Please sign in to comment.