def token_explicitly_created_on_cluster(cluster, token_cluster_name): """Returns true if the given token cluster matches the configured cluster name of the given cluster""" cluster_settings, _ = http_util.make_data_request( cluster, lambda: http_util.get(cluster, '/settings')) cluster_config_name = cluster_settings['cluster-config']['name'].upper() created_on_this_cluster = token_cluster_name == cluster_config_name return created_on_this_cluster
def get_service(cluster, service_id): """Retrieves the service with the given service id""" params = {'effective-parameters': True} endpoint = f'/apps/{service_id}' service, _ = http_util.make_data_request( cluster, lambda: http_util.get(cluster, endpoint, params=params)) return service
def get_token(cluster, token_name, include=None): """Gets the token with the given name from the given cluster""" params = {'token': token_name} if include: params['include'] = include token_data, headers = http_util.make_data_request(cluster, lambda: http_util.get(cluster, 'token', params=params)) etag = headers.get('ETag', None) return token_data, etag
def get_services_using_token(cluster, token_name): """Retrieves all services that are using the token""" params = {'effective-parameters': 'true', 'token': token_name} services, _ = http_util.make_data_request(cluster, lambda: http_util.get(cluster, 'apps', params=params)) return services
def get_tokens(cluster, user): """Gets the tokens owned by the given user from the given cluster""" params = {'owner': user, 'include': 'metadata'} tokens, _ = http_util.make_data_request(cluster, lambda: http_util.get(cluster, 'tokens', params=params)) return tokens