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

RSDK-9194: streamline app connection #4516

Conversation

purplenicole730
Copy link
Member

@purplenicole730 purplenicole730 commented Nov 1, 2024

Jira ticket

Changes:

  • added new directory app/
  • introduced a ViamClient struct
  • made a function CreateViamClient, which takes in api key for credentials
  • add unit tests for url and api key formatting

Testing:

  • called a proto dataClient and tested with an existing machine
  • unit tests

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Nov 1, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 4, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 4, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 4, 2024
@purplenicole730 purplenicole730 marked this pull request as ready for review November 4, 2024 20:32
@purplenicole730 purplenicole730 requested review from a team, njooma and jckras and removed request for a team November 4, 2024 20:32
Copy link
Member

@jckras jckras left a comment

Choose a reason for hiding this comment

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

Quick question - how are we going to implement the interfaces for other clients, such as DataClient and BillingClient, here? (In the Python sdk, we define data_client as a property of the ViamClient class). I'm not sure if this is outside the scope of this PR, but I just want to clarify our approach moving forward :)

Copy link
Member

@jckras jckras left a comment

Choose a reason for hiding this comment

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

I left a question about our approach towards building out the other clients w/ respect to ViamClient (but again maybe that is out of scope of this ticket) so LGTM.

app/viam_client_test.go Outdated Show resolved Hide resolved
@purplenicole730
Copy link
Member Author

purplenicole730 commented Nov 5, 2024

Quick question - how are we going to implement the interfaces for other clients, such as DataClient and BillingClient, here? (In the Python sdk, we define data_client as a property of the ViamClient class). I'm not sure if this is outside the scope of this PR, but I just want to clarify our approach moving forward :)

Similarly, the other clients would be part of ViamClient. But we don't have those yet so there's nothing to add. That's what the next tickets are.

Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

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

I think it would be better if there was an Options struct that contained 2 fields: BaseUri string and Credentials rpc.Credentials. Then, have a func WithOptions that takes in these options.

What I think can be improved from the current version is that baseURL has to always be specified, even if just to be an empty string. Plus, there might be more ways in the future of connecting to app that this allows for.

And nothing is stopping us from making convenience functions like FromApiKey so that the user can use API Keys instead of Options

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 7, 2024
@viambot viambot removed the safe to test This pull request is marked safe to test from a trusted zone label Nov 7, 2024
@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Nov 7, 2024
Comment on lines 28 to 33
// APIKeyOptions has what is necessary to connect through GRPC with an API key.
type APIKeyOptions struct {
baseURL string
apiKey string
apiKeyID string
}
Copy link
Member

Choose a reason for hiding this comment

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

Delete this

app/viam_client.go Show resolved Hide resolved
}

// CreateViamClientWithAPIKey creates a ViamClient with an API key.
func CreateViamClientWithAPIKey(ctx context.Context, apiKeyOptions APIKeyOptions, logger logging.Logger) (*ViamClient, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This should take in normal Options and apiKey and apiKeyID

Copy link
Member Author

@purplenicole730 purplenicole730 Nov 12, 2024

Choose a reason for hiding this comment

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

I am curious, if a user is going to pass in an Options object, at that point, wouldn't they just set the APIKey themselves?

app/viam_client_test.go Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 12, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 12, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 13, 2024
Comment on lines 58 to 63
if !validateAPIKeyFormat(apiKey) {
return nil, errors.New("API key should be a 32-char all-lowercase alphanumeric string")
}
if !validateAPIKeyIDFormat(apiKeyID) {
return nil, errors.New("API key ID should be an all-lowercase alphanumeric string with this format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
}
Copy link
Member

Choose a reason for hiding this comment

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

Ok to leave this in, but I do think it's unnecessary -- the server will tell the user that their creds are incorrect so no need to do client-side checking.

Copy link
Member Author

Choose a reason for hiding this comment

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

If it's unnecessary, then I'll take it out!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 15, 2024
@purplenicole730 purplenicole730 merged commit 8f47d2c into viamrobotics:main Nov 15, 2024
16 checks passed
@purplenicole730 purplenicole730 deleted the RSDK-9194-streamline-app-connection branch November 15, 2024 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants