Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/emrcontainers/eks.py
1567 views
1
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
14
15
class EKS(object):
16
def __init__(self, eks_client):
17
self.eks_client = eks_client
18
self.cluster_info = {}
19
20
def get_oidc_issuer_id(self, cluster_name):
21
"""Method to get OIDC issuer id for the given EKS cluster"""
22
if cluster_name not in self.cluster_info:
23
self.cluster_info[cluster_name] = self.eks_client.describe_cluster(
24
name=cluster_name
25
)
26
27
oidc_issuer = self.cluster_info[cluster_name].get("cluster", {}).get(
28
"identity", {}).get("oidc", {}).get("issuer", "")
29
30
return oidc_issuer.split('https://')[1]
31
32
def get_account_id(self, cluster_name):
33
"""Method to get account id for the given EKS cluster"""
34
if cluster_name not in self.cluster_info:
35
self.cluster_info[cluster_name] = self.eks_client.describe_cluster(
36
name=cluster_name
37
)
38
39
cluster_arn = self.cluster_info[cluster_name].get("cluster", {}).get(
40
"arn", "")
41
42
return cluster_arn.split(':')[4]
43
44