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-9625] add discover service #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

[RSDK-9625] add discover service #65

wants to merge 3 commits into from

Conversation

JohnN193
Copy link

@JohnN193 JohnN193 commented Jan 9, 2025

https://viam.atlassian.net/browse/RSDK-9625

adds the discover service. Made it a separate package from the current viamonvif to avoid circular dependencies happening and to not break the current discovery workflow that people use.

requires this rdk pr to be merged before usage. In addition only viam-servers on this version or later can use the module due to the tagger/proto reflection issue we ran into.

test robot

example code(get the API key from the robot)

package main

import (
	"context"

	"go.viam.com/rdk/logging"
	"go.viam.com/rdk/robot/client"
	"go.viam.com/rdk/services/discovery"
	"go.viam.com/utils/rpc"
)

func main() {
	logger := logging.NewLogger("client")
	machine, err := client.New(
		context.Background(),
		"rtsp-cams-main.ytxdza0q92.viam.cloud",
		logger,
		client.WithDialOptions(rpc.WithEntityCredentials( 
            /* Replace "<API-KEY-ID>" (including brackets) with your machine's api key id */
			"<API-KEY-ID>",
			rpc.Credentials{
				Type:    rpc.CredentialsTypeAPIKey, 
                /* Replace "<API-KEY>" (including brackets) with your machine's api key */
				Payload: "<API-KEY>",
			})),
	)
	if err != nil {
		logger.Fatal(err)
	}
	ctx := context.Background()

	defer machine.Close(ctx)
	logger.Info("Resources:")
	logger.Info(machine.ResourceNames())

	dis, err := discovery.FromRobot(machine, "discover")
	if err != nil {
		logger.Fatal(err)
	}
	cfgs, err := dis.DiscoverResources(ctx, nil)
	if err != nil {
		logger.Fatal(err)
	}
	for _, cfg := range cfgs {
		logger.Infof("Name: %v\tModel: %v\tAPI: %v", cfg.Name, cfg.Model, cfg.API)
		logger.Infof("Attributes: ", cfg.Attributes)
	}
}

Comment on lines +343 to +346

// replace go.viam.com/rdk => /Users/johnnicholson/viam-slam/rdk

// replace go.viam.com/api => /Users/johnnicholson/viam-slam/api
Copy link
Author

Choose a reason for hiding this comment

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

will remove before merging

Comment on lines +112 to +117
func (cred *Creds) createName(index int) string {
if cred.Username == "" {
return fmt.Sprintf("Camera_Insecure_%v", index)
}
return fmt.Sprintf("Camera_%s_%v", cred.Username, index)
}
Copy link
Author

Choose a reason for hiding this comment

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

currently using the camera's username and the camera number as the name of the resource we surface. Can further separate by url if requested(since cameras appear to have multiple urls)

}

func (cfg *Config) Validate(deps string) ([]string, error) {
// check that all creds have both usernames and passwords set. Note a credential can have both fields empty
Copy link
Author

Choose a reason for hiding this comment

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

I don't know if a camera can have only a username or only a password, so I disallowed those combinations

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.

1 participant