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

APP-2517: org API key support #419

Merged
merged 3 commits into from
Sep 5, 2023
Merged

Conversation

ohEmily
Copy link
Member

@ohEmily ohEmily commented Sep 1, 2023

APP-2517

Requires changes to rust-utils, RSDK-4755

This script (in this case, with the little hacks in place to connect to a robot on localhost):

import asyncio
from viam import logging
from viam.robot.client import RobotClient
from viam.rpc.dial import Credentials, DialOptions

async def connect_robot_location_secret():
    creds = Credentials(
        type='robot-location-secret',
        payload='qymq89tpc8m5fe7o90wf3kxn3tb55eaqj1uchx0ul89puggu')
    opts = RobotClient.Options(
        refresh_interval=0,
        dial_options=DialOptions(credentials=creds)
    )
    return await RobotClient.at_address('robot-main.gmmaqnzytw.viam.cloud', opts)

async def connect_api_key():
    creds = Credentials(
        type='api-key',
        payload='t5pp84x7yl05uldjhllxzbuwjt0p6m49')
    opts = RobotClient.Options(
        refresh_interval=0,
        log_level=logging.DEBUG,
        dial_options=DialOptions(credentials=creds, auth_entity="4bccae38-c344-4183-a454-321b9566c721")
    )
    return await RobotClient.at_address('robot-main.gmmaqnzytw.viam.cloud', opts)

async def main():
    robot = await connect_robot_location_secret()
    print('Resources (robot location secret):')
    print(robot.resource_names)

    robot = await connect_api_key()
    print('Resources (API key):')
    print(robot.resource_names)

    # Don't forget to close the robot when you're done!
    await robot.close()

if __name__ == '__main__':
    asyncio.run(main())

Will output this:

⇒  python localhostRobotHost.py
2023-09-01 19:22:34,768		INFO	viam.rpc.dial (dial.py:245)	Connecting to socket: /tmp/proxy-YHLqeW0A.sock
Resources (robot location secret):
[namespace: "rdk"
type: "service"
subtype: "data_manager"
name: "builtin"
, namespace: "rdk"
type: "service"
subtype: "sensors"
name: "builtin"
, namespace: "rdk"
type: "service"
subtype: "motion"
name: "builtin"
, namespace: "rdk"
type: "component"
subtype: "servo"
name: "fakeservo"
]
2023-09-01 19:22:34,808		DEBUG	viam.rpc.dial (dial.py:188)	Creating new viam-rust-utils runtime
2023-09-01 19:22:34,808		DEBUG	viam.rpc.dial (dial.py:214)	Dialing robot-main.gmmaqnzytw.viam.cloud using viam-rust-utils library
2023-09-01 19:22:36,397		INFO	viam.rpc.dial (dial.py:245)	Connecting to socket: /tmp/proxy-XeOTExCL.sock
2023-09-01 19:22:36,397		INFO	viam.rpc.dial (dial.py:245)	Connecting to socket: /tmp/proxy-XeOTExCL.sock
Resources (API key):
[namespace: "rdk"
type: "service"
subtype: "data_manager"
name: "builtin"
, namespace: "rdk"
type: "service"
subtype: "sensors"
name: "builtin"
, namespace: "rdk"
type: "service"
subtype: "motion"
name: "builtin"
, namespace: "rdk"
type: "component"
subtype: "servo"
name: "fakeservo"
]
2023-09-01 19:22:36,399		DEBUG	viam.robot.client (client.py:435)	Closing RobotClient
2023-09-01 19:22:36,399		DEBUG	viam.sessions_client (sessions_client.py:63)	resetting session
2023-09-01 19:22:36,400		DEBUG	viam.robot.client (client.py:448)	Closing tasks spawned by Viam
2023-09-01 19:22:36,400		DEBUG	viam.robot.client (client.py:451)		Closing task 455ba5166b604d25b6ef74bf20db2ad4-robot_check_connection
2023-09-01 19:22:36,400		DEBUG	viam.robot.client (client.py:451)		Closing task 455ba5166b604d25b6ef74bf20db2ad4-robot_check_connection
2023-09-01 19:22:36,400		DEBUG	viam.robot.client (client.py:456)	Closing gRPC channel to remote robot
2023-09-01 19:22:36,400		DEBUG	viam.robot.client (client.py:425)		 Closing ViamChannel instance
2023-09-01 19:22:36,400		DEBUG	viam.rpc.dial (dial.py:233)	Freeing socket string
2023-09-01 19:22:36,400		DEBUG	viam.rpc.dial (dial.py:229)	Freeing viam-rust-utils runtime
2023-09-01 19:22:36,406		DEBUG	viam.rpc.dial (dial.py:166)	ViamChannel might not have shut down cleanly - Event loop was closed
2023-09-01 19:22:36,406		DEBUG	viam.rpc.dial (dial.py:233)	Freeing socket string
2023-09-01 19:22:36,406		DEBUG	viam.rpc.dial (dial.py:229)	Freeing viam-rust-utils runtime

@ohEmily ohEmily requested a review from a team as a code owner September 1, 2023 23:23
@ohEmily
Copy link
Member Author

ohEmily commented Sep 5, 2023

Thanks for reviewing @stuqdog! Other than eventually merging the other ticket I put you in review for, viamrobotics/rust-utils#75, is there anything else I need to do before hitting merge on this one?

@stuqdog
Copy link
Member

stuqdog commented Sep 5, 2023

Thanks for reviewing @stuqdog! Other than eventually merging the other ticket I put you in review for, viamrobotics/rust-utils#75, is there anything else I need to do before hitting merge on this one?

I don't think anything needs to be done here specifically, but we'll want to coordinate the releases of rust-utils and the C++ sdk. There's plenty of leeway on releasing this first (we won't be cutting new releases until next Thursday) but might be good to coordinate the release of all three just to be safe.

Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on call and can help with the coordinated release candidate cutting on Thursday. nvm this is next thursday!

@ohEmily
Copy link
Member Author

ohEmily commented Sep 5, 2023

Did this mean that I should hold off on merging? Or is it safe to merge? I think safe but wanted to double-check.

@ohEmily ohEmily merged commit a37a992 into viamrobotics:main Sep 5, 2023
6 checks passed
@ohEmily ohEmily deleted the APP-2517 branch September 5, 2023 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants