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

feat: Add methods blink, update and device to supervisor v1 struct #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cakoolen
Copy link
Contributor

@cakoolen cakoolen commented Feb 2, 2023

Added the following methods:

  • Blink: start a blink pattern on a LED for 15 s
  • Update: trigger a check for the target state of configurations
  • Device: return the current device state

@cakoolen cakoolen requested a review from alethenorio as a code owner February 2, 2023 06:21
@cakoolen cakoolen force-pushed the Add-update-endpoint-to-supervisor-v1-service branch 2 times, most recently from a9bf476 to 3589bdb Compare February 3, 2023 09:55
@@ -29,22 +30,104 @@ func (s *SupervisorV1Service) Reboot(ctx context.Context, force bool) error {
&request{Force: force},
)
if err != nil {
return fmt.Errorf("unable to create restart service request: %v", err)
return fmt.Errorf("unable to create restart service request: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for this change? As this is an open source library, I'd be reluctant to exposing the underlying implementation error without a good reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can understand that though we probably want to respond differently when we receive an internal server error versus a bad request response. If we can wrap this error here, on a higher level we can decide whether to do a retry or ask an operator for help.

supervisorv1.go Outdated
return fmt.Errorf("unable to create blink request: %w", err)
}

err = s.client.Do(req, io.Discard)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to switch to (also in other places)

Suggested change
err = s.client.Do(req, io.Discard)
err = s.client.Do(req, nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough

supervisorv1.go Outdated
Comment on lines 121 to 126
response := new(SupervisorV1DeviceResponse)

err = s.client.Do(req, response)
if err != nil {
return nil, fmt.Errorf("unable to get device state: %w", err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We generally follow the slightly more idiomatic form (at least these days)

Suggested change
response := new(SupervisorV1DeviceResponse)
err = s.client.Do(req, response)
if err != nil {
return nil, fmt.Errorf("unable to get device state: %w", err)
}
var response SupervisorV1DeviceResponse
err = s.client.Do(req, &response)
if err != nil {
return nil, fmt.Errorf("unable to get device state: %w", err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine with that. Though in other parts of this repository, I see a construction where the response created by:

response := &SupervisorV1DeviceResponse{}

In hindsight, I probably should have used that. Do you still want me to stick to your suggestion?

Copy link
Contributor

@alethenorio alethenorio Feb 25, 2023

Choose a reason for hiding this comment

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

Yeah the library needs a little cleaning to be honest. Lets go with the more idiomatic way I suggested here for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. That will give me a guide for potential future pull requests.

@cakoolen cakoolen force-pushed the Add-update-endpoint-to-supervisor-v1-service branch from 3589bdb to df029f7 Compare February 25, 2023 10:29
Added the following methods:
- Blink: start a blink pattern on a LED for 15 s
- Update: trigger a check for the target state of configurations
- Device: return the current device state
@cakoolen cakoolen force-pushed the Add-update-endpoint-to-supervisor-v1-service branch from df029f7 to 14563d1 Compare February 25, 2023 10:33
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.

2 participants