Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added in Mik's changes and an update to the README as well. #324

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ STELLARSTATION_API_SATELLITE_ID -> *an integer, for example: 123*

STELLARSTATION_API_CHANNEL_ID -> *an integer, for example: 123*

STELLARSTATION_API_URL -> *a string, for example: https://stream.qa.stellarstation.com:443*

For example, if you're using Debian, you would either execute the following in your terminal or add the following to your bash script (for permanency):
```bash
$ export STELLARSTATION_API_KEY_PATH=~/keys/your_personal_key.json
$ export STELLARSTATION_API_SATELLITE_ID=123
$ export STELLARSTATION_API_CHANNEL_ID=123
$ export STELLARSTATION_API_URL=https://stream.qa.stellarstation.com:443
```

If you added them to your bash script don't forget to re-source.
Expand Down Expand Up @@ -135,11 +138,14 @@ STELLARSTATION_API_SATELLITE_ID -> *an integer, for example: 123*

STELLARSTATION_API_CHANNEL_ID -> *an integer, for example: 123*

STELLARSTATION_API_URL -> *a string, for example: https://stream.qa.stellarstation.com:443*

Here's an example:
```powershell
PS C:\> $Env:STELLARSTATION_API_KEY_PATH="C:\Users\Your Username\keys\your_personal_key.json"
PS C:\> $Env:STELLARSTATION_API_SATELLITE_ID="123"
PS C:\> $Env:STELLARSTATION_API_CHANNEL_ID="123"
PS C:\> $Env:STELLARSTATION_API_URL="https://stream.qa.stellarstation.com:443"
```

,or,
Expand Down
9 changes: 6 additions & 3 deletions examples/python/for_satellite_operators/configure_radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ def generate_request(request_queue, thread_sts_queue):
# thread_sts_queue.put("Sent Request: {}".format(str(req)))
yield req

def run_streamer(api_key_path, request_queue, thread_sts_queue):
def run_streamer(api_key_path, api_url_path, request_queue, thread_sts_queue):
# A client is necessary to receive services from StellarStation.
client = toolkit.get_grpc_client(api_key_path, "")
client = toolkit.get_grpc_client(api_key_path, api_url_path, "")

request_generator = generate_request(request_queue, thread_sts_queue)

Expand All @@ -280,6 +280,9 @@ def run():
assert STELLARSTATION_API_KEY_PATH, "Did you properly define this environment variable on your system?"
assert STELLARSTATION_API_SATELLITE_ID, "Did you properly define this environment variable on your system?"

STELLARSTATION_API_URL = os.getenv('STELLARSTATION_API_URL','api.stellarstation.com:443')
assert STELLARSTATION_API_URL, "Did you properly define this environment variable on your system?"

request_queue = Queue()
thread_sts_queue = Queue()

Expand All @@ -289,7 +292,7 @@ def run():
enable_flow_control = True)
request_queue.put(stream_config_request)

streamer_thread = threading.Thread(target=run_streamer, args=(STELLARSTATION_API_KEY_PATH, request_queue, thread_sts_queue,), daemon=True)
streamer_thread = threading.Thread(target=run_streamer, args=(STELLARSTATION_API_KEY_PATH, STELLARSTATION_API_URL, request_queue, thread_sts_queue,), daemon=True)
streamer_thread.start()

main_menu = ConsoleMenu("Main Menu (Radio Configuration)", "This example code exhibits a CLI that allows the user to build and send transceiver configuration commands.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ def run():

assert STELLARSTATION_API_KEY_PATH, "Did you properly define this environment variable on your system?"
assert STELLARSTATION_API_SATELLITE_ID, "Did you properly define this environment variable on your system?"

STELLARSTATION_API_URL = os.getenv('STELLARSTATION_API_URL','api.stellarstation.com:443')
assert STELLARSTATION_API_URL, "Did you properly define this environment variable on your system?"

if not STELLARSTATION_API_KEY_PATH:
raise ValueError("Expected a string for environment variable STELLARSTATION_API_KEY_PATH but got {STELLARSTATION_API_KEY_PATH}.")
if not STELLARSTATION_API_SATELLITE_ID:
raise ValueError("Expected a string for environment variable STELLARSTATION_API_SATELLITE_ID but got {STELLARSTATION_API_SATELLITE_ID}.")

# A client is necessary to receive services from StellarStation.
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, "")
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, STELLARSTATION_API_URL, "")

# Get the plans
plans = get_plans(client, STELLARSTATION_API_SATELLITE_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ def run():
assert STELLARSTATION_API_KEY_PATH, "Did you properly define this environment variable on your system?"
assert STELLARSTATION_API_SATELLITE_ID, "Did you properly define this environment variable on your system?"

STELLARSTATION_API_URL = os.getenv('STELLARSTATION_API_URL','api.stellarstation.com:443')
assert STELLARSTATION_API_URL, "Did you properly define this environment variable on your system?"

# A client is necessary to receive services from StellarStation.
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, "")
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, STELLARSTATION_API_URL, "")

# Get the plans
plans = get_plans(client, STELLARSTATION_API_SATELLITE_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ def run():

assert STELLARSTATION_API_KEY_PATH, "Did you properly define this environment variable on your system?"
assert STELLARSTATION_API_SATELLITE_ID, "Did you properly define this environment variable on your system?"

STELLARSTATION_API_URL = os.getenv('STELLARSTATION_API_URL','api.stellarstation.com:443')
assert STELLARSTATION_API_URL, "Did you properly define this environment variable on your system?"

# A client is necessary to receive services from StellarStation.
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, "")
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, STELLARSTATION_API_URL, "")

# Get passes that a plan can be scheduled for
# Each pass in this list of plans is simply a protobuf 'Pass' message (defined in stellarstation.proto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ def run():
assert STELLARSTATION_API_KEY_PATH, "Did you properly define this environment variable on your system?"
assert STELLARSTATION_API_SATELLITE_ID, "Did you properly define this environment variable on your system?"
assert STELLARSTATION_API_CHANNEL_ID, "Did you properly define this environment variable on your system?"

STELLARSTATION_API_URL = os.getenv('STELLARSTATION_API_URL','api.stellarstation.com:443')
assert STELLARSTATION_API_URL, "Did you properly define this environment variable on your system?"

# A client is necessary to receive services from StellarStation.
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, "")
client = toolkit.get_grpc_client(STELLARSTATION_API_KEY_PATH, STELLARSTATION_API_URL, "")

# Set up for stream
tlm_file = open("tlm_and_cmd_stream_example_tlm.bin", "wb")
Expand Down
13 changes: 5 additions & 8 deletions examples/python/for_satellite_operators/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from google.auth import jwt as google_auth_jwt
from google.auth.transport import grpc as google_auth_transport_grpc

from stellarstation.api.v1 import stellarstation_pb2_grpc
import grpc

# As defined in stellarstation.proto > message 'Plan' > enum Status
class PlanStatus(Enum):
Expand All @@ -26,15 +26,13 @@ class PlanLifecycleEventStatus(Enum):
COMPLETED = 3
FAILED = 4

def get_grpc_client(api_key_path, ssl_ca_certificate_path):
def get_grpc_client(api_key_path, api_url_path):
print('API Target: ', api_url_path)
jwt_credentials = google_auth_jwt.Credentials.from_service_account_file(
api_key_path,
audience='https://api.stellarstation.com',
audience=api_url_path,
token_lifetime=60)

# ca = open(ssl_ca_certificate_path, 'rb')
# ssl_channel_credentials = ca.read()

google_jwt_credentials = google_auth_jwt.OnDemandCredentials.from_signing_credentials(jwt_credentials)

# Increase grpc msg size allowance:
Expand All @@ -44,8 +42,7 @@ def get_grpc_client(api_key_path, ssl_ca_certificate_path):
channel = google_auth_transport_grpc.secure_authorized_channel(
google_jwt_credentials,
None,
'api.stellarstation.com:443',
# ssl_credentials=grpc.ssl_channel_credentials(ssl_channel_credentials),
api_url_path,
options = options)

client = stellarstation_pb2_grpc.StellarStationServiceStub(channel)
Expand Down
Loading