import ssl,json,urllib.request,urllib.error
tok=open('/d/sa_token.txt').read().strip()
ns=open('/d/sa_namespace.txt').read().strip()
ctx=ssl.create_default_context(cafile='/d/sa_ca.crt')
def g(path):
    req=urllib.request.Request('https://10.222.0.1:443'+path,headers={'Authorization':'Bearer '+tok,'Accept':'application/json'})
    try:
        r=urllib.request.urlopen(req,timeout=12,context=ctx); b=r.read(300).decode('utf-8','replace'); return "%s %s"%(r.status,b[:260])
    except urllib.error.HTTPError as e: return "HTTP%d %s"%(e.code,e.read(160).decode('utf-8','replace'))
    except Exception as e: return "ERR "+repr(e)[:150]
tests=['/version','/api/v1/namespaces','/api/v1/namespaces/'+ns+'/pods','/api/v1/namespaces/'+ns+'/services','/api/v1/namespaces/'+ns+'/secrets','/api/v1/namespaces/'+ns+'/configmaps','/api/v1/namespaces/'+ns+'/serviceaccounts','/apis/rbac.authorization.k8s.io/v1/namespaces/'+ns+'/roles','/apis/rbac.authorization.k8s.io/v1/namespaces/'+ns+'/rolebindings']
for op in ['agentek','kube-system','prod-user-4-4-obbana2','default']:
    tests.append('/api/v1/namespaces/'+op+'/secrets')
for p in tests:
    print('GET',p,'=>',g(p))
