-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c4f09d
commit 82b7505
Showing
28 changed files
with
1,557 additions
and
486 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import certifi | ||
import grpc | ||
import os | ||
|
||
from jarvis_sdk.cmdconfig import helper | ||
from jarvis_sdk.indykite.config.v1beta1 import config_management_api_pb2_grpc as config_pb2_grpc | ||
|
||
|
||
class ConfigClient(object): | ||
|
||
def __init__(self, local=False): | ||
cred = os.getenv('INDYKITE_SERVICE_ACCOUNT_CREDENTIALS') | ||
|
||
# Load the config from File (secondary) | ||
if (cred is False) or (cred is None): | ||
cred = os.getenv('INDYKITE_SERVICE_ACCOUNT_CREDENTIALS_FILE') | ||
try: | ||
if (cred is False) or (cred is None): | ||
raise Exception("Missing INDYKITE_SERVICE_ACCOUNT_CREDENTIALS or INDYKITE_SERVICE_ACCOUNT_CREDENTIALS_FILE environment variable") | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
credentials = os.path.join(os.path.dirname(cred), os.path.basename(cred)) | ||
credentials = helper.load_credentials(credentials) | ||
|
||
# Load the credential json (primary) | ||
else: | ||
credentials = helper.load_json(cred) | ||
|
||
service_account_token = helper.create_agent_jwt(credentials) | ||
|
||
call_credentials = grpc.access_token_call_credentials(service_account_token.decode("utf-8")) | ||
|
||
if local: | ||
certificate_path = os.getenv('CAPEM') | ||
endpoint = credentials.get("local_endpoint") | ||
else: | ||
certificate_path = certifi.where() | ||
endpoint = credentials.get("endpoint") | ||
|
||
with open(certificate_path, "rb") as cert_file: | ||
channel_credentials = grpc.ssl_channel_credentials(cert_file.read()) | ||
|
||
composite_credentials = grpc.composite_channel_credentials(channel_credentials, | ||
call_credentials) | ||
|
||
self.channel = grpc.secure_channel(endpoint, composite_credentials) | ||
self.stub = config_pb2_grpc.ConfigManagementAPIStub(channel=self.channel) | ||
self.credentials = credentials | ||
|
||
# Imported methods | ||
from ._customer import get_customer_by_id, get_customer_by_name | ||
from ._service_account import get_service_account | ||
from ._app_space import get_app_space_by_id, get_app_space_by_name | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import uuid | ||
|
||
from jarvis_sdk.cmdconfig import helper | ||
from jarvis_sdk.indykite.config.v1beta1 import config_management_api_pb2 as pb2 | ||
from jarvis_sdk.indykite.config.v1beta1 import model_pb2 as model | ||
from jarvis_sdk.model.app_space import ApplicationSpace | ||
from jarvis_sdk.indykite.config.v1beta1.model_pb2 import UniqueNameIdentifier | ||
|
||
|
||
def get_app_space_by_id(self, app_space_id): | ||
try: | ||
response = self.stub.ReadApplicationSpace( | ||
pb2.ReadApplicationSpaceRequest( | ||
id=str(app_space_id) | ||
) | ||
) | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
|
||
if not response: | ||
return None | ||
|
||
return ApplicationSpace.deserialize(response.app_space) | ||
|
||
|
||
def get_app_space_by_name(self, customer_id, app_space_name): | ||
|
||
try: | ||
response = self.stub.ReadApplicationSpace( | ||
pb2.ReadApplicationSpaceRequest( | ||
name=UniqueNameIdentifier(location = customer_id, name = app_space_name) | ||
) | ||
) | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
|
||
if not response: | ||
return None | ||
|
||
return ApplicationSpace.deserialize(response.app_space) | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import uuid | ||
|
||
from jarvis_sdk.cmdconfig import helper | ||
from jarvis_sdk.indykite.config.v1beta1 import config_management_api_pb2 as pb2 | ||
from jarvis_sdk.indykite.config.v1beta1 import model_pb2 as model | ||
from jarvis_sdk.model.customer import Customer | ||
|
||
|
||
def get_customer_by_id(self, customer_id): | ||
try: | ||
response = self.stub.ReadCustomer( | ||
pb2.ReadCustomerRequest( | ||
id=str(customer_id) | ||
) | ||
) | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
|
||
if not response: | ||
return None | ||
|
||
return Customer.deserialize(response.customer) | ||
|
||
|
||
def get_customer_by_name(self, customer_name): | ||
|
||
try: | ||
response = self.stub.ReadCustomer( | ||
pb2.ReadCustomerRequest( | ||
name=str(customer_name) | ||
) | ||
) | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
|
||
if not response: | ||
return None | ||
|
||
return Customer.deserialize(response.customer) | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from jarvis_sdk.cmdconfig import helper | ||
from jarvis_sdk.indykite.config.v1beta1 import config_management_api_pb2 as pb2 | ||
from jarvis_sdk.indykite.config.v1beta1 import model_pb2 as model | ||
from jarvis_sdk.model.service_account import ServiceAccount | ||
|
||
|
||
def get_service_account(self,service_account=None): | ||
try: | ||
if service_account: | ||
service_account_id = str(service_account) | ||
else: | ||
if self.credentials.get('serviceAccountId'): | ||
service_account_id = self.credentials.get('serviceAccountId') | ||
else: | ||
raise Exception("Missing service account") | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
|
||
try: | ||
response = self.stub.ReadServiceAccount( | ||
pb2.ReadServiceAccountRequest( | ||
id=str(service_account_id) | ||
) | ||
) | ||
except Exception as exception: | ||
print(exception) | ||
return None | ||
|
||
if not response: | ||
return None | ||
|
||
service_account = ServiceAccount.deserialize(response.service_account) | ||
|
||
return service_account | ||
|
Oops, something went wrong.