Loading .gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -17,5 +17,6 @@ app.py invoker_sdk_config.json requirements.txt discoverer.pkl invoker.pkl invoker_info/ logs/ No newline at end of file README.md +13 −7 Original line number Diff line number Diff line Loading @@ -29,17 +29,17 @@ To start the service, follow the steps below 1. Copy requirements_template.txt to requirements.txt ``` cp requirements_template.txt requirements.txt cp ./app/requirements_template.txt ./app/requirements.txt ``` 2. Copy app_template.py to app.py ``` cp app_template.py app.py cp ./app/app_template.py ./app/app.py ``` 3. Copy invoker_sdk_config_template.json to invoker_sdk_config.json ``` cp invoker_sdk_config_template.json invoker_sdk_config.json cp ./app/invoker_sdk_config_template.json ./app/invoker_sdk_config.json ``` 4. Add opencapif_sdk in requirements.txt Loading @@ -51,11 +51,17 @@ To start the service, follow the steps below 6. To deploy the service, run the following commands in an Ubuntu or MacOS terminal. To stop the invoker just press Ctrl+C or Command+C ``` chmod +x start_invoker.sh ./start_invoker.sh -u <username given by organizers> [-n <host:ip>]" ./start_invoker.sh -u <username given by organizers> ``` 7. To remove the files of the invoker instance (invoker_info, logs and pkl file), execute the following commands. 7. To see the logs, execute the following commands. ``` chmod +x clean_files.sh ./clean_files.sh chmod +x logs_invoker.sh ./logs_invoker.sh -u <username given by organizers> ``` 8. To stop the invoker service and remove the files of the invoker instance (invoker_info, logs and pkl file), execute the following commands. ``` chmod +x stop_invoker.sh ./stop_invoker.sh -u <username given by organizers> ``` No newline at end of file Dockerfile→app/Dockerfile +0 −0 File moved. View file app_template.py→app/app_template.py +42 −14 Original line number Diff line number Diff line Loading @@ -3,7 +3,8 @@ import json import pickle import requests from flask import Flask, jsonify, request # import OpenCAPIF SDK ### Import OpenCAPIF SDK package # import opencapif_sdk app = Flask(__name__) OBJ_FILE = "discoverer.pkl" Loading @@ -16,18 +17,21 @@ user_name = os.getenv("USER_NAME", "test") def onboard(): response_message = "Onboard" ### Create the connection with CAPIF and set the invoker's config file # invoker = opencapif_sdk.capif_invoker_connector(config_file="invoker_sdk_config.json") ### Onboard the invoker # invoker.onboard_invoker() ### Uncomment to print the Invoker ID ### Uncomment to get the Invoker ID # with open("./invoker_info/{0}/capif_api_security_context_details-{0}.json".format(user_name), "rb") as f: # d = json.load(f) # invoker_id = d['api_invoker_id'] ### Uncomment, fill the ... with the object and store invoker object ### Uncomment to store invoker object # with open(OBJ_FILE_INV, 'wb') as f: # pickle.dump(invoker, f) # response_message = "Invoker onboarded with ID: {}".format(d['api_invoker_id']) # response_message = "Invoker onboarded with ID: {}".format(invoker_id) return response_message Loading @@ -36,12 +40,14 @@ def onboard(): def discover(): response_message = "Discover" ### Create the connection with CAPIF as an onboarded invoker # service_discoverer = opencapif_sdk.service_discoverer(config_file="invoker_sdk_config.json") ### Discover APIs according to the filters # service_discoverer.discover() ### Uncomment, fill the ... with the object and store discoverer object ### Uncomment to store discoverer object # with open(OBJ_FILE, 'wb') as f: # pickle.dump( ... , f) # pickle.dump( service_discoverer , f) ### Uncomment to read and return the discovered API # with open("./invoker_info/{0}/capif_api_security_context_details-{0}.json".format(user_name), "rb") as f: Loading @@ -60,20 +66,23 @@ def access_service(): # resource_name = request_data['resource_name'] # method = request_data['method'] ### Uncomment, fill the ... with a preferred variable name and fetch the discoverer object ### Uncomment to fetch the discoverer object # if not os.path.exists(OBJ_FILE): # return "No session found.", 404 # with open(OBJ_FILE, 'rb') as f: # ... = pickle.load(f) # service_discoverer = pickle.load(f) ### Fetch the necessary information of the targeted API and add to a url parameter # service_path = ... # api_details = ... # service_interface = # url = ... # service_path = service_discoverer.retrieve_specific_resource_name(api_name, resource_name).split("/")[-1] # api_details = service_discoverer.retrieve_api_description_by_name(api_name) # service_interface = api_details["aefProfiles"][0]['interfaceDescriptions'][0] # url = "http://{}:{}/{}".format(service_interface['ipv4Addr'], service_interface['port'], service_path) ### Get API token for the discovered API and add it to a header # jwt_token = ... ### Get API token for the discovered API # service_discoverer.get_tokens() # jwt_token = service_discoverer.token ### Uncomment to add token to a header # headers = { # 'Authorization': 'Bearer {}'.format(jwt_token) # } Loading @@ -84,6 +93,25 @@ def access_service(): return response_message @app.get("/offboard") def offboard(): response_message = "Offboard" ### Uncomment to fetch the invoker object # if not os.path.exists(OBJ_FILE): # return "No session found.", 404 # with open(OBJ_FILE_INV, 'rb') as f: # invoker = pickle.load(f) ### Offboard invoker # invoker.offboard_invoker() ### Uncomment to check if invoker was successfully offboarded # if not os.path.exists("./invoker_info/{}".format(user_name)): # response_message = "Invoker offboarded successfully" return response_message if __name__ == "__main__": port = int(os.getenv("PORT", 8001)) app.run(host='0.0.0.0', port=port, debug=True) No newline at end of file invoker_sdk_config_template.json→app/invoker_sdk_config_template.json +0 −0 File moved. View file Loading
.gitignore +1 −0 Original line number Diff line number Diff line Loading @@ -17,5 +17,6 @@ app.py invoker_sdk_config.json requirements.txt discoverer.pkl invoker.pkl invoker_info/ logs/ No newline at end of file
README.md +13 −7 Original line number Diff line number Diff line Loading @@ -29,17 +29,17 @@ To start the service, follow the steps below 1. Copy requirements_template.txt to requirements.txt ``` cp requirements_template.txt requirements.txt cp ./app/requirements_template.txt ./app/requirements.txt ``` 2. Copy app_template.py to app.py ``` cp app_template.py app.py cp ./app/app_template.py ./app/app.py ``` 3. Copy invoker_sdk_config_template.json to invoker_sdk_config.json ``` cp invoker_sdk_config_template.json invoker_sdk_config.json cp ./app/invoker_sdk_config_template.json ./app/invoker_sdk_config.json ``` 4. Add opencapif_sdk in requirements.txt Loading @@ -51,11 +51,17 @@ To start the service, follow the steps below 6. To deploy the service, run the following commands in an Ubuntu or MacOS terminal. To stop the invoker just press Ctrl+C or Command+C ``` chmod +x start_invoker.sh ./start_invoker.sh -u <username given by organizers> [-n <host:ip>]" ./start_invoker.sh -u <username given by organizers> ``` 7. To remove the files of the invoker instance (invoker_info, logs and pkl file), execute the following commands. 7. To see the logs, execute the following commands. ``` chmod +x clean_files.sh ./clean_files.sh chmod +x logs_invoker.sh ./logs_invoker.sh -u <username given by organizers> ``` 8. To stop the invoker service and remove the files of the invoker instance (invoker_info, logs and pkl file), execute the following commands. ``` chmod +x stop_invoker.sh ./stop_invoker.sh -u <username given by organizers> ``` No newline at end of file
app_template.py→app/app_template.py +42 −14 Original line number Diff line number Diff line Loading @@ -3,7 +3,8 @@ import json import pickle import requests from flask import Flask, jsonify, request # import OpenCAPIF SDK ### Import OpenCAPIF SDK package # import opencapif_sdk app = Flask(__name__) OBJ_FILE = "discoverer.pkl" Loading @@ -16,18 +17,21 @@ user_name = os.getenv("USER_NAME", "test") def onboard(): response_message = "Onboard" ### Create the connection with CAPIF and set the invoker's config file # invoker = opencapif_sdk.capif_invoker_connector(config_file="invoker_sdk_config.json") ### Onboard the invoker # invoker.onboard_invoker() ### Uncomment to print the Invoker ID ### Uncomment to get the Invoker ID # with open("./invoker_info/{0}/capif_api_security_context_details-{0}.json".format(user_name), "rb") as f: # d = json.load(f) # invoker_id = d['api_invoker_id'] ### Uncomment, fill the ... with the object and store invoker object ### Uncomment to store invoker object # with open(OBJ_FILE_INV, 'wb') as f: # pickle.dump(invoker, f) # response_message = "Invoker onboarded with ID: {}".format(d['api_invoker_id']) # response_message = "Invoker onboarded with ID: {}".format(invoker_id) return response_message Loading @@ -36,12 +40,14 @@ def onboard(): def discover(): response_message = "Discover" ### Create the connection with CAPIF as an onboarded invoker # service_discoverer = opencapif_sdk.service_discoverer(config_file="invoker_sdk_config.json") ### Discover APIs according to the filters # service_discoverer.discover() ### Uncomment, fill the ... with the object and store discoverer object ### Uncomment to store discoverer object # with open(OBJ_FILE, 'wb') as f: # pickle.dump( ... , f) # pickle.dump( service_discoverer , f) ### Uncomment to read and return the discovered API # with open("./invoker_info/{0}/capif_api_security_context_details-{0}.json".format(user_name), "rb") as f: Loading @@ -60,20 +66,23 @@ def access_service(): # resource_name = request_data['resource_name'] # method = request_data['method'] ### Uncomment, fill the ... with a preferred variable name and fetch the discoverer object ### Uncomment to fetch the discoverer object # if not os.path.exists(OBJ_FILE): # return "No session found.", 404 # with open(OBJ_FILE, 'rb') as f: # ... = pickle.load(f) # service_discoverer = pickle.load(f) ### Fetch the necessary information of the targeted API and add to a url parameter # service_path = ... # api_details = ... # service_interface = # url = ... # service_path = service_discoverer.retrieve_specific_resource_name(api_name, resource_name).split("/")[-1] # api_details = service_discoverer.retrieve_api_description_by_name(api_name) # service_interface = api_details["aefProfiles"][0]['interfaceDescriptions'][0] # url = "http://{}:{}/{}".format(service_interface['ipv4Addr'], service_interface['port'], service_path) ### Get API token for the discovered API and add it to a header # jwt_token = ... ### Get API token for the discovered API # service_discoverer.get_tokens() # jwt_token = service_discoverer.token ### Uncomment to add token to a header # headers = { # 'Authorization': 'Bearer {}'.format(jwt_token) # } Loading @@ -84,6 +93,25 @@ def access_service(): return response_message @app.get("/offboard") def offboard(): response_message = "Offboard" ### Uncomment to fetch the invoker object # if not os.path.exists(OBJ_FILE): # return "No session found.", 404 # with open(OBJ_FILE_INV, 'rb') as f: # invoker = pickle.load(f) ### Offboard invoker # invoker.offboard_invoker() ### Uncomment to check if invoker was successfully offboarded # if not os.path.exists("./invoker_info/{}".format(user_name)): # response_message = "Invoker offboarded successfully" return response_message if __name__ == "__main__": port = int(os.getenv("PORT", 8001)) app.run(host='0.0.0.0', port=port, debug=True) No newline at end of file