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

fix: remove duplicated tenant version code #22

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pkg/c8y/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 99,9 @@ type Client struct {
// Cumulocity Tenant
TenantName string

// Cumulocity Version
Version string

// Password for Cumulocity Authentication
Password string

Expand Down Expand Up @@ -946,6 949,12 @@ func (c *Client) LoginUsingOAuth2(ctx context.Context, initRequest ...string) er
if err != nil {
return err
}

// Get Cumulocity system version, but don't fail if it does not work
if version, err := c.TenantOptions.GetVersion(ctx); err == nil {
c.Version = version
}

c.TenantName = tenant.Name
return nil
}
Expand All @@ -957,15 966,6 @@ func (c *Client) SetRequestOptions(options DefaultRequestOptions) {
c.requestOptions = options
}

// Get the current tenant version
func (c *Client) GetTenantVersion(ctx context.Context) (string, error) {
option, _, err := c.TenantOptions.GetOption(ctx, "system", "version")
if err != nil {
return "", err
}
return option.Value, nil
}

func withContext(ctx context.Context, req *http.Request) *http.Request {
return req.WithContext(ctx)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/c8y/tenantOptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 147,10 @@ func (s *TenantOptionsService) GetSystemOption(ctx context.Context, category, ke
}

// GetVersion returns Cumulocity version information
func (s *TenantOptionsService) GetVersion(ctx context.Context) (*TenantOption, *Response, error) {
return s.GetSystemOption(ctx, "system", "version")
func (s *TenantOptionsService) GetVersion(ctx context.Context) (string, error) {
opt, _, err := s.GetSystemOption(ctx, "system", "version")
if err != nil {
return "", err
}
return opt.Value, nil
}