Last active
December 3, 2018 14:50
-
-
Save clcollins/7bc2bf10a8868e4385fcacad24b107e0 to your computer and use it in GitHub Desktop.
Atom Snippet: Python OpenShift Dynamic Client init function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A snippet for instantiating an OpenShift dynamic client | |
# for working with the OpenShist Rest API | |
# | |
# Requires: | |
# OpenShift-RestClient-Python - https://github.com/openshift/openshift-restclient-python | |
# Kubernetes Python Client - https://github.com/kubernetes-client/python | |
# | |
# `pip3 install --user kubernetes && pip3 install --user openshift` | |
# | |
# import kubernetes | |
# from openshift.dynamic import DynamicClient | |
# | |
# Add the following to ~/.atom/snippets.cson, creating or appending to ".source.python": | |
'.source.python': | |
'Python OpenShift API Auth': | |
'prefix': 'pyosauth' | |
'body': """ | |
def authenticate(host, key): | |
\"\"\"Creates an OpenShift DynamicClient using a Kubernetes client config.\"\"\" | |
k8s_client = kubernetes.client.Configuration() | |
k8s_client.host = host | |
k8s_client.api_key = key | |
setattr(k8s_client, | |
'api_key', | |
{'authorization': "Bearer {0}".format(k8s_client.api_key)}) | |
kubernetes.client.Configuration.set_default(k8s_client) | |
return DynamicClient(kubernetes.client.ApiClient(k8s_client)) | |
""" | |
'description': 'Python OpenShift API Client' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment