Skip to content

Commit

Permalink
remove unnecessary client check
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 committed Nov 15, 2024
1 parent 1b27971 commit 1d136d9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 20 deletions.
18 changes: 0 additions & 18 deletions app/viam_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"net/url"
"regexp"
"strings"

"go.viam.com/utils/rpc"
Expand Down Expand Up @@ -55,13 +54,6 @@ func CreateViamClientWithOptions(ctx context.Context, options Options, logger lo
func CreateViamClientWithAPIKey(
ctx context.Context, options Options, apiKey, apiKeyID string, logger logging.Logger,
) (*ViamClient, error) {
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")
}

options.entity = apiKeyID
options.credentials = rpc.Credentials{
Type: rpc.CredentialsTypeAPIKey,
Expand All @@ -74,13 +66,3 @@ func CreateViamClientWithAPIKey(
func (c *ViamClient) Close() error {
return c.conn.Close()
}

func validateAPIKeyFormat(apiKey string) bool {
regex := regexp.MustCompile("^[a-z0-9]{32}$")
return regex.MatchString(apiKey)
}

func validateAPIKeyIDFormat(apiKeyID string) bool {
regex := regexp.MustCompile("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}")
return regex.MatchString(apiKeyID)
}
2 changes: 0 additions & 2 deletions app/viam_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func TestCreateViamClientWithAPIKeyTests(t *testing.T) {
{"Valid API Key", testAPIKey, testAPIKeyID, false},
{"Empty API Key", "", testAPIKeyID, true},
{"Empty API Key ID", testAPIKey, "", true},
{"Invalid API Key", "fake", testAPIKeyID, true},
{"Invalid API Key ID", testAPIKey, "fake", true},
}
for _, tt := range apiKeyTests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1d136d9

Please sign in to comment.