diff --git a/cli/auth.go b/cli/auth.go index d38566ffc24..9ecce22c770 100644 --- a/cli/auth.go +++ b/cli/auth.go @@ -233,10 +233,6 @@ func PrintAccessTokenAction(cCtx *cli.Context, args emptyArgs) error { } func (c *viamClient) printAccessTokenAction(cCtx *cli.Context) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - if token, ok := c.conf.Auth.(*token); ok { printf(cCtx.App.Writer, token.AccessToken) } else { @@ -316,9 +312,6 @@ func OrganizationsAPIKeyCreateAction(cCtx *cli.Context, args organizationsAPIKey } func (c *viamClient) organizationsAPIKeyCreateAction(cCtx *cli.Context, args organizationsAPIKeyCreateArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } orgID := args.OrgID keyName := args.Name if keyName == "" { @@ -337,10 +330,6 @@ func (c *viamClient) organizationsAPIKeyCreateAction(cCtx *cli.Context, args org } func (c *viamClient) createOrganizationAPIKey(orgID, keyName string) (*apppb.CreateKeyResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } - req := &apppb.CreateKeyRequest{ Authorizations: []*apppb.Authorization{ { @@ -376,10 +365,6 @@ func LocationAPIKeyCreateAction(cCtx *cli.Context, args locationAPIKeyCreateArgs } func (c *viamClient) locationAPIKeyCreateAction(cCtx *cli.Context, args locationAPIKeyCreateArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - locationID := args.LocationID orgID := args.OrgID keyName := args.Name @@ -441,10 +426,6 @@ func RobotAPIKeyCreateAction(cCtx *cli.Context, args robotAPIKeyCreateArgs) erro } func (c *viamClient) robotAPIKeyCreateAction(cCtx *cli.Context, args robotAPIKeyCreateArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - robotID := args.MachineID keyName := args.Name orgID := args.OrgID @@ -600,9 +581,6 @@ func (c *viamClient) prepareDial( orgStr, locStr, robotStr, partStr string, debug bool, ) (context.Context, string, []rpc.DialOption, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, "", nil, err - } if err := c.selectOrganization(orgStr); err != nil { return nil, "", nil, err } diff --git a/cli/client.go b/cli/client.go index be43e0c2d12..ee5da08bc47 100644 --- a/cli/client.go +++ b/cli/client.go @@ -146,10 +146,6 @@ func OrganizationsSupportEmailSetAction(cCtx *cli.Context, args organizationsSup } func (c *viamClient) organizationsSupportEmailSetAction(cCtx *cli.Context, orgID, supportEmail string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - _, err := c.client.OrganizationSetSupportEmail(c.c.Context, &apppb.OrganizationSetSupportEmailRequest{ OrgId: orgID, Email: supportEmail, @@ -181,10 +177,6 @@ func OrganizationsSupportEmailGetAction(cCtx *cli.Context, args organizationsSup } func (c *viamClient) organizationsSupportEmailGetAction(cCtx *cli.Context, orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - resp, err := c.client.OrganizationGetSupportEmail(c.c.Context, &apppb.OrganizationGetSupportEmailRequest{ OrgId: orgID, }) @@ -242,10 +234,6 @@ func (c *viamClient) disableAuthServiceAction(cCtx *cli.Context, orgID string) e return errors.New("cannot disable auth service without an organization ID") } - if err := c.ensureLoggedIn(); err != nil { - return err - } - if _, err := c.client.DisableAuthService(cCtx.Context, &apppb.DisableAuthServiceRequest{OrgId: orgID}); err != nil { return err } @@ -274,10 +262,6 @@ func EnableAuthServiceAction(cCtx *cli.Context, args enableAuthServiceArgs) erro } func (c *viamClient) enableAuthServiceAction(cCtx *cli.Context, orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - _, err := c.client.EnableAuthService(cCtx.Context, &apppb.EnableAuthServiceRequest{OrgId: orgID}) if err != nil { return err @@ -312,9 +296,6 @@ func UpdateBillingServiceAction(cCtx *cli.Context, args updateBillingServiceArgs } func (c *viamClient) updateBillingServiceAction(cCtx *cli.Context, orgID, addressAsString string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } address, err := parseBillingAddress(addressAsString) if err != nil { return err @@ -355,10 +336,6 @@ func GetBillingConfigAction(cCtx *cli.Context, args getBillingConfigArgs) error } func (c *viamClient) getBillingConfig(cCtx *cli.Context, orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - resp, err := c.client.GetBillingServiceConfig(cCtx.Context, &apppb.GetBillingServiceConfigRequest{ OrgId: orgID, }) @@ -411,10 +388,6 @@ func OrganizationEnableBillingServiceAction(cCtx *cli.Context, args organization } func (c *viamClient) organizationEnableBillingServiceAction(cCtx *cli.Context, orgID, addressAsString string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - address, err := parseBillingAddress(addressAsString) if err != nil { return err @@ -449,10 +422,6 @@ func OrganizationDisableBillingServiceAction(cCtx *cli.Context, args organizatio } func (c *viamClient) organizationDisableBillingServiceAction(cCtx *cli.Context, orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - if _, err := c.client.DisableBillingService(cCtx.Context, &apppb.DisableBillingServiceRequest{ OrgId: orgID, }); err != nil { @@ -488,10 +457,6 @@ func OrganizationLogoSetAction(cCtx *cli.Context, args organizationsLogoSetArgs) } func (c *viamClient) organizationLogoSetAction(cCtx *cli.Context, orgID, logoFilePath string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - logoFile, err := os.Open(filepath.Clean(logoFilePath)) if err != nil { return errors.WithMessagef(err, "could not open logo file: %s", logoFilePath) @@ -544,10 +509,6 @@ func OrganizationsLogoGetAction(cCtx *cli.Context, args organizationsLogoGetArgs } func (c *viamClient) organizationsLogoGetAction(cCtx *cli.Context, orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - resp, err := c.client.OrganizationGetLogo(cCtx.Context, &apppb.OrganizationGetLogoRequest{ OrgId: orgID, }) @@ -584,10 +545,6 @@ func ListOAuthAppsAction(cCtx *cli.Context, args listOAuthAppsArgs) error { } func (c *viamClient) listOAuthAppsAction(cCtx *cli.Context, orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - resp, err := c.client.ListOAuthApps(cCtx.Context, &apppb.ListOAuthAppsRequest{ OrgId: orgID, }) @@ -1448,10 +1405,6 @@ func tunnelTraffic(ctx *cli.Context, robotClient *client.RobotClient, local, des } func (c *viamClient) robotPartTunnel(cCtx *cli.Context, args robotsPartTunnelArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - orgStr := args.Organization locStr := args.Location robotStr := args.Machine @@ -1761,7 +1714,14 @@ func newViamClientInner(c *cli.Context, disableBrowserOpen bool) (*viamClient, e // Creates a new viam client, defaulting to _not_ passing the `disableBrowerOpen` arg (which // users don't even have an option of setting for any CLI method currently except `Login`). func newViamClient(c *cli.Context) (*viamClient, error) { - return newViamClientInner(c, false) + client, err := newViamClientInner(c, false) + if err != nil { + return nil, err + } + if err := client.ensureLoggedIn(); err != nil { + return nil, err + } + return client, nil } func (c *viamClient) loadOrganizations() error { @@ -1774,9 +1734,6 @@ func (c *viamClient) loadOrganizations() error { } func (c *viamClient) selectOrganization(orgStr string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } if orgStr != "" && (c.selectedOrg.Id == orgStr || c.selectedOrg.Name == orgStr) { return nil } @@ -1822,9 +1779,6 @@ func (c *viamClient) selectOrganization(orgStr string) error { // org UUID, then this matchs on organization ID, otherwise this will match // on organization name. func (c *viamClient) getOrg(orgStr string) (*apppb.Organization, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } resp, err := c.client.ListOrganizations(c.c.Context, &apppb.ListOrganizationsRequest{}) if err != nil { return nil, err @@ -1849,10 +1803,6 @@ func (c *viamClient) getOrg(orgStr string) (*apppb.Organization, error) { // getUserOrgByPublicNamespace searches the logged in users orgs to see // if any have a matching public namespace. func (c *viamClient) getUserOrgByPublicNamespace(publicNamespace string) (*apppb.Organization, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } - if err := c.loadOrganizations(); err != nil { return nil, err } @@ -1865,9 +1815,6 @@ func (c *viamClient) getUserOrgByPublicNamespace(publicNamespace string) (*apppb } func (c *viamClient) listOrganizations() ([]*apppb.Organization, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } if err := c.loadOrganizations(); err != nil { return nil, err } @@ -1921,9 +1868,6 @@ func (c *viamClient) selectLocation(locStr string) error { } func (c *viamClient) listLocations(orgID string) ([]*apppb.Location, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } if err := c.selectOrganization(orgID); err != nil { return nil, err } @@ -1934,9 +1878,6 @@ func (c *viamClient) listLocations(orgID string) ([]*apppb.Location, error) { } func (c *viamClient) listRobots(orgStr, locStr string) ([]*apppb.Robot, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } if err := c.selectOrganization(orgStr); err != nil { return nil, err } @@ -1953,10 +1894,6 @@ func (c *viamClient) listRobots(orgStr, locStr string) ([]*apppb.Robot, error) { } func (c *viamClient) robot(orgStr, locStr, robotStr string) (*apppb.Robot, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } - robots, err := c.listRobots(orgStr, locStr) if err != nil { return nil, err @@ -1995,9 +1932,6 @@ func (c *viamClient) robotPart(orgStr, locStr, robotStr, partStr string) (*apppb } func (c *viamClient) robotPartInner(orgStr, locStr, robotStr, partStr string) (*apppb.RobotPart, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } parts, err := c.robotParts(orgStr, locStr, robotStr) if err != nil { return nil, err @@ -2033,16 +1967,10 @@ func (c *viamClient) robotPartInner(orgStr, locStr, robotStr, partStr string) (* // note: overlaps with viamClient.robotPart, which wraps GetRobotParts. // Use this variant if you don't know the robot ID. func (c *viamClient) getRobotPart(partID string) (*apppb.GetRobotPartResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } return c.client.GetRobotPart(c.c.Context, &apppb.GetRobotPartRequest{Id: partID}) } func (c *viamClient) updateRobotPart(part *apppb.RobotPart, confMap map[string]any) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } confStruct, err := structpb.NewStruct(confMap) if err != nil { return errors.Wrap(err, "in NewStruct") @@ -2100,9 +2028,6 @@ func (c *viamClient) robotPartLogs(orgStr, locStr, robotStr, partStr string, err } func (c *viamClient) robotParts(orgStr, locStr, robotStr string) ([]*apppb.RobotPart, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } robot, err := c.robot(orgStr, locStr, robotStr) if err != nil { return nil, err @@ -2630,10 +2555,6 @@ func ReadOAuthAppAction(c *cli.Context, args readOAuthAppArgs) error { } func (c *viamClient) readOAuthAppAction(cCtx *cli.Context, orgID, clientID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - req := &apppb.ReadOAuthAppRequest{OrgId: orgID, ClientId: clientID} resp, err := c.client.ReadOAuthApp(c.c.Context, req) if err != nil { @@ -2709,10 +2630,6 @@ func DeleteOAuthAppAction(c *cli.Context, args deleteOAuthAppArgs) error { } func (c *viamClient) deleteOAuthAppAction(cCtx *cli.Context, orgID, clientID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - req := &apppb.DeleteOAuthAppRequest{ OrgId: orgID, ClientId: clientID, @@ -2857,10 +2774,6 @@ func CreateOAuthAppAction(c *cli.Context, args createOAuthAppArgs) error { } func (c *viamClient) createOAuthAppAction(cCtx *cli.Context, args createOAuthAppArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - config, err := generateOAuthConfig(args.ClientAuthentication, args.Pkce, args.UrlValidation, args.LogoutURI, args.OriginURIs, args.RedirectURIs, args.EnabledGrants) if err != nil { @@ -2907,10 +2820,6 @@ func UpdateOAuthAppAction(c *cli.Context, args updateOAuthAppArgs) error { } func (c *viamClient) updateOAuthAppAction(cCtx *cli.Context, args updateOAuthAppArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - req, err := createUpdateOAuthAppRequest(args) if err != nil { return err diff --git a/cli/data.go b/cli/data.go index f643d86c03f..fb68f80afde 100644 --- a/cli/data.go +++ b/cli/data.go @@ -354,10 +354,6 @@ func (c *viamClient) dataExportTabularAction(cCtx *cli.Context, args dataExportT // BinaryData downloads binary data matching filter to dst. func (c *viamClient) binaryData(dst string, filter *datapb.Filter, parallelDownloads, timeout uint) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - return c.performActionOnBinaryDataFromFilter( func(id *datapb.BinaryID) error { return c.downloadBinary(dst, id, timeout) @@ -692,10 +688,6 @@ func filenameForDownload(meta *datapb.BinaryMetadata) string { // tabularData downloads unified tabular data and metadata for the requested data source and interval to the specified destination. func (c *viamClient) tabularData(dest string, request *datapb.ExportTabularDataRequest) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - if err := makeDestinationDirs(dest); err != nil { return errors.Wrapf(err, "could not create destination directories") } @@ -844,9 +836,6 @@ func makeDestinationDirs(dst string) error { } func (c *viamClient) deleteBinaryData(filter *datapb.Filter) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } resp, err := c.dataClient.DeleteBinaryDataByFilter(context.Background(), &datapb.DeleteBinaryDataByFilterRequest{Filter: filter}) if err != nil { @@ -857,9 +846,6 @@ func (c *viamClient) deleteBinaryData(filter *datapb.Filter) error { } func (c *viamClient) dataAddTagsToBinaryByFilter(filter *datapb.Filter, tags []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } _, err := c.dataClient.AddTagsToBinaryDataByFilter(context.Background(), &datapb.AddTagsToBinaryDataByFilterRequest{Filter: filter, Tags: tags}) if err != nil { @@ -870,9 +856,6 @@ func (c *viamClient) dataAddTagsToBinaryByFilter(filter *datapb.Filter, tags []s } func (c *viamClient) dataRemoveTagsFromBinaryByFilter(filter *datapb.Filter, tags []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } _, err := c.dataClient.RemoveTagsFromBinaryDataByFilter(context.Background(), &datapb.RemoveTagsFromBinaryDataByFilterRequest{Filter: filter, Tags: tags}) if err != nil { @@ -883,9 +866,6 @@ func (c *viamClient) dataRemoveTagsFromBinaryByFilter(filter *datapb.Filter, tag } func (c *viamClient) dataAddTagsToBinaryByIDs(tags []string, orgID, locationID string, fileIDs []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } binaryData := make([]*datapb.BinaryID, 0, len(fileIDs)) for _, fileID := range fileIDs { binaryData = append(binaryData, &datapb.BinaryID{ @@ -906,9 +886,6 @@ func (c *viamClient) dataAddTagsToBinaryByIDs(tags []string, orgID, locationID s // dataRemoveTagsFromData removes tags from data, with the specified org ID, location ID, // and file IDs. func (c *viamClient) dataRemoveTagsFromBinaryByIDs(tags []string, orgID, locationID string, fileIDs []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } binaryData := make([]*datapb.BinaryID, 0, len(fileIDs)) for _, fileID := range fileIDs { binaryData = append(binaryData, &datapb.BinaryID{ @@ -928,9 +905,6 @@ func (c *viamClient) dataRemoveTagsFromBinaryByIDs(tags []string, orgID, locatio // deleteTabularData delete tabular data matching filter. func (c *viamClient) deleteTabularData(orgID string, deleteOlderThanDays int) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } resp, err := c.dataClient.DeleteTabularData(context.Background(), &datapb.DeleteTabularDataRequest{OrganizationId: orgID, DeleteOlderThanDays: uint32(deleteOlderThanDays)}) if err != nil { @@ -962,9 +936,6 @@ func DataAddToDatasetByIDs(c *cli.Context, args dataAddToDatasetByIDsArgs) error // dataAddToDatasetByIDs adds data, with the specified org ID, location ID, and file IDs to the dataset corresponding to the dataset ID. func (c *viamClient) dataAddToDatasetByIDs(datasetID, orgID, locationID string, fileIDs []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } binaryData := make([]*datapb.BinaryID, 0, len(fileIDs)) for _, fileID := range fileIDs { binaryData = append(binaryData, &datapb.BinaryID{ @@ -1004,9 +975,6 @@ func DataAddToDatasetByFilter(c *cli.Context, args dataAddToDatasetByFilterArgs) // dataAddToDatasetByFilter adds data, with the specified filter to the dataset corresponding to the dataset ID. func (c *viamClient) dataAddToDatasetByFilter(filter *datapb.Filter, datasetID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } parallelActions := uint(100) return c.performActionOnBinaryDataFromFilter( @@ -1044,9 +1012,6 @@ func DataRemoveFromDataset(c *cli.Context, args dataRemoveFromDatasetArgs) error // dataRemoveFromDataset removes data, with the specified org ID, location ID, // and file IDs from the dataset corresponding to the dataset ID. func (c *viamClient) dataRemoveFromDataset(datasetID, orgID, locationID string, fileIDs []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } binaryData := make([]*datapb.BinaryID, 0, len(fileIDs)) for _, fileID := range fileIDs { binaryData = append(binaryData, &datapb.BinaryID{ @@ -1171,9 +1136,6 @@ func DataConfigureDatabaseUser(c *cli.Context, args dataConfigureDatabaseUserArg // being configured. Viam uses gRPC over TLS, so the entire request will be encrypted while in // flight, including the password. func (c *viamClient) dataConfigureDatabaseUser(orgID, password string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } _, err := c.dataClient.ConfigureDatabaseUser(context.Background(), &datapb.ConfigureDatabaseUserRequest{OrganizationId: orgID, Password: password}) if err != nil { @@ -1205,9 +1167,6 @@ func DataGetDatabaseConnection(c *cli.Context, args dataGetDatabaseConnectionArg // dataGetDatabaseConnection gets the hostname of the MongoDB Atlas Data Federation instance // for the given organization ID. func (c *viamClient) dataGetDatabaseConnection(orgID string) (*datapb.GetDatabaseConnectionResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } res, err := c.dataClient.GetDatabaseConnection(context.Background(), &datapb.GetDatabaseConnectionRequest{OrganizationId: orgID}) if err != nil { return nil, errors.Wrapf(err, serverErrorMessage) diff --git a/cli/dataset.go b/cli/dataset.go index 6e027aee8a2..7ab7fbac545 100644 --- a/cli/dataset.go +++ b/cli/dataset.go @@ -42,9 +42,6 @@ func DatasetCreateAction(c *cli.Context, args datasetCreateArgs) error { // createDataset creates a dataset with the a dataset ID. func (c *viamClient) createDataset(orgID, datasetName string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } resp, err := c.datasetClient.CreateDataset(context.Background(), &datasetpb.CreateDatasetRequest{OrganizationId: orgID, Name: datasetName}) if err != nil { @@ -73,9 +70,6 @@ func DatasetRenameAction(c *cli.Context, args datasetRenameArgs) error { // renameDataset renames an existing datasetID with the newDatasetName. func (c *viamClient) renameDataset(datasetID, newDatasetName string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } _, err := c.datasetClient.RenameDataset(context.Background(), &datasetpb.RenameDatasetRequest{Id: datasetID, Name: newDatasetName}) if err != nil { @@ -117,9 +111,6 @@ func DatasetListAction(c *cli.Context, args datasetListArgs) error { // listDatasetByIDs list all datasets by ID. func (c *viamClient) listDatasetByIDs(datasetIDs []string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } resp, err := c.datasetClient.ListDatasetsByIDs(context.Background(), &datasetpb.ListDatasetsByIDsRequest{Ids: datasetIDs}) if err != nil { @@ -133,9 +124,6 @@ func (c *viamClient) listDatasetByIDs(datasetIDs []string) error { // listDatasetByOrg list all datasets for the specified org ID. func (c *viamClient) listDatasetByOrg(orgID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } resp, err := c.datasetClient.ListDatasetsByOrganizationID(context.Background(), &datasetpb.ListDatasetsByOrganizationIDRequest{OrganizationId: orgID}) if err != nil { @@ -165,9 +153,6 @@ func DatasetDeleteAction(c *cli.Context, args datasetDeleteArgs) error { // deleteDataset deletes a dataset with the specified ID. func (c *viamClient) deleteDataset(datasetID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } _, err := c.datasetClient.DeleteDataset(context.Background(), &datasetpb.DeleteDatasetRequest{Id: datasetID}) if err != nil { @@ -200,10 +185,6 @@ func DatasetDownloadAction(c *cli.Context, args datasetDownloadArgs) error { // downloadDataset downloads a dataset with the specified ID. func (c *viamClient) downloadDataset(dst, datasetID string, includeJSONLines bool, parallelDownloads, timeout uint) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - var datasetFile *os.File var err error if includeJSONLines { diff --git a/cli/ml_training.go b/cli/ml_training.go index a30aec91a05..bd88bf224f3 100644 --- a/cli/ml_training.go +++ b/cli/ml_training.go @@ -131,9 +131,6 @@ func MLSubmitTrainingJob(c *cli.Context, args mlSubmitTrainingJobArgs) error { func (c *viamClient) mlSubmitTrainingJob(datasetID, orgID, modelName, modelVersion, modelType string, labels []string, ) (string, error) { - if err := c.ensureLoggedIn(); err != nil { - return "", err - } if modelVersion == "" { modelVersion = time.Now().Format("2006-01-02T15-04-05") } @@ -159,9 +156,6 @@ func (c *viamClient) mlSubmitTrainingJob(datasetID, orgID, modelName, modelVersi func (c *viamClient) mlSubmitCustomTrainingJob(datasetID, registryItemID, registryItemVersion, orgID, modelName, modelVersion string, args []string, ) (string, error) { - if err := c.ensureLoggedIn(); err != nil { - return "", err - } splitName := strings.Split(registryItemID, ":") if len(splitName) != 2 { return "", errors.Errorf("invalid training script name '%s'."+ @@ -220,9 +214,6 @@ func DataGetTrainingJob(c *cli.Context, args dataGetTrainingJobArgs) error { // dataGetTrainingJob gets a training job with the given ID. func (c *viamClient) dataGetTrainingJob(trainingJobID string) (*mltrainingpb.TrainingJobMetadata, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } resp, err := c.mlTrainingClient.GetTrainingJob(context.Background(), &mltrainingpb.GetTrainingJobRequest{Id: trainingJobID}) if err != nil { return nil, err @@ -256,9 +247,6 @@ func MLGetTrainingJobLogs(c *cli.Context, args mlGetTrainingJobLogsArgs) error { // mlGetTrainingJobLogs gets the training job logs with the given ID. func (c *viamClient) mlGetTrainingJobLogs(trainingJobID string) ([]*mltrainingpb.TrainingJobLogEntry, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } var allLogs []*mltrainingpb.TrainingJobLogEntry var page string @@ -299,9 +287,6 @@ func DataCancelTrainingJob(c *cli.Context, args dataCancelTrainingJobArgs) error // dataCancelTrainingJob cancels a training job with the given ID. func (c *viamClient) dataCancelTrainingJob(trainingJobID string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } if _, err := c.mlTrainingClient.CancelTrainingJob( context.Background(), &mltrainingpb.CancelTrainingJobRequest{Id: trainingJobID}); err != nil { return err @@ -332,10 +317,6 @@ func DataListTrainingJobs(c *cli.Context, args dataListTrainingJobsArgs) error { // dataListTrainingJobs lists training jobs for the given org. func (c *viamClient) dataListTrainingJobs(orgID, status string) ([]*mltrainingpb.TrainingJobMetadata, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } - if status == "" { status = "unspecified" } @@ -465,10 +446,6 @@ func MLTrainingUpdateAction(c *cli.Context, args mlTrainingUpdateArgs) error { } func (c *viamClient) updateTrainingScript(orgID, name, visibility, description, url string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - // Get registry item itemID := fmt.Sprintf("%s:%s", orgID, name) resp, err := c.client.GetRegistryItem(c.c.Context, &v1.GetRegistryItemRequest{ diff --git a/cli/module_build.go b/cli/module_build.go index 074f1373fdc..0145d4d07d2 100644 --- a/cli/module_build.go +++ b/cli/module_build.go @@ -102,9 +102,6 @@ func (c *viamClient) moduleBuildStartAction(cCtx *cli.Context, args moduleBuildS Token: &token, Workdir: &workdir, } - if err := c.ensureLoggedIn(); err != nil { - return err - } res, err := c.buildClient.StartBuild(c.c.Context, &req) if err != nil { return err @@ -352,9 +349,6 @@ func ModuleBuildLinkRepoAction(c *cli.Context, args moduleBuildLinkRepoArgs) err if err != nil { return err } - if err := client.ensureLoggedIn(); err != nil { - return err - } res, err := client.buildClient.LinkRepo(c.Context, &req) if err != nil { return err @@ -364,10 +358,6 @@ func ModuleBuildLinkRepoAction(c *cli.Context, args moduleBuildLinkRepoArgs) err } func (c *viamClient) printModuleBuildLogs(buildID, platform string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } - logsReq := &buildpb.GetLogsRequest{ BuildId: buildID, Platform: platform, @@ -400,9 +390,6 @@ func (c *viamClient) printModuleBuildLogs(buildID, platform string) error { } func (c *viamClient) listModuleBuildJobs(moduleIDFilter string, count *int32, buildIDFilter *string) (*buildpb.ListJobsResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } req := buildpb.ListJobsRequest{ ModuleId: moduleIDFilter, MaxJobsLength: count, @@ -519,6 +506,7 @@ func ReloadModuleAction(c *cli.Context, args reloadModuleArgs) error { // reloadModuleAction is the testable inner reload logic. func reloadModuleAction(c *cli.Context, vc *viamClient, args reloadModuleArgs, logger logging.Logger) error { + // TODO(RSDK-9727) it'd be nice for this to be a method on a viam client rather than taking one as an arg partID, err := resolvePartID(c.Context, args.PartID, "/etc/viam.json") if err != nil { return err @@ -691,13 +679,11 @@ func restartModule( manifest *moduleManifest, logger logging.Logger, ) error { + // TODO(RSDK-9727) it'd be nice for this to be a method on a viam client rather than taking one as an arg restartReq, err := resolveTargetModule(c, manifest) if err != nil { return err } - if err := vc.ensureLoggedIn(); err != nil { - return err - } apiRes, err := vc.client.GetRobotAPIKeys(c.Context, &apppb.GetRobotAPIKeysRequest{RobotId: part.Robot}) if err != nil { return err diff --git a/cli/module_generate.go b/cli/module_generate.go index 7300b1025dd..4d14385d721 100644 --- a/cli/module_generate.go +++ b/cli/module_generate.go @@ -70,9 +70,6 @@ func GenerateModuleAction(cCtx *cli.Context, args generateModuleArgs) error { } func (c *viamClient) generateModuleAction(cCtx *cli.Context, args generateModuleArgs) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } var newModule *modulegen.ModuleInputs var err error diff --git a/cli/module_registry.go b/cli/module_registry.go index 95c17c34717..8ab9ca848d4 100644 --- a/cli/module_registry.go +++ b/cli/module_registry.go @@ -413,9 +413,6 @@ func UpdateModelsAction(c *cli.Context, args updateModelsArgs) error { } func (c *viamClient) createModule(moduleName, organizationID string) (*apppb.CreateModuleResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } req := apppb.CreateModuleRequest{ Name: moduleName, OrganizationId: organizationID, @@ -424,9 +421,6 @@ func (c *viamClient) createModule(moduleName, organizationID string) (*apppb.Cre } func (c *viamClient) getModule(moduleID moduleID) (*apppb.GetModuleResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } req := apppb.GetModuleRequest{ ModuleId: moduleID.String(), } @@ -434,9 +428,6 @@ func (c *viamClient) getModule(moduleID moduleID) (*apppb.GetModuleResponse, err } func (c *viamClient) updateModule(moduleID moduleID, manifest moduleManifest) (*apppb.UpdateModuleResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } var models []*apppb.Model for _, moduleComponent := range manifest.Models { models = append(models, moduleComponentToProto(moduleComponent)) @@ -466,10 +457,6 @@ func (c *viamClient) uploadModuleFile( constraints []string, tarballPath string, ) (*apppb.UploadModuleFileResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } - //nolint:gosec file, err := os.Open(tarballPath) if err != nil { @@ -997,9 +984,6 @@ func DownloadModuleAction(c *cli.Context, flags downloadModuleFlags) error { if err != nil { return err } - if err := client.ensureLoggedIn(); err != nil { - return err - } req := &apppb.GetModuleRequest{ModuleId: moduleID} res, err := client.client.GetModule(c.Context, req) if err != nil { diff --git a/cli/packages.go b/cli/packages.go index c65ec812e64..f2dca3cd08f 100644 --- a/cli/packages.go +++ b/cli/packages.go @@ -84,9 +84,6 @@ func convertPackageTypeToProto(packageType string) (*packagespb.PackageType, err } func (c *viamClient) packageExportAction(orgID, name, version, packageType, destination string) error { - if err := c.ensureLoggedIn(); err != nil { - return err - } if orgID == "" || name == "" { if orgID != "" || name != "" { return fmt.Errorf("if either of %s or %s is missing, both must be missing", generalFlagOrgID, generalFlagName) @@ -227,10 +224,6 @@ func (c *viamClient) uploadPackage( orgID, name, version, packageType, tarballPath string, metadataStruct *structpb.Struct, ) (*packagespb.CreatePackageResponse, error) { - if err := c.ensureLoggedIn(); err != nil { - return nil, err - } - //nolint:gosec file, err := os.Open(tarballPath) if err != nil {