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: addon param can be an addon type name #983

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

curzolapierre
Copy link
Member

@curzolapierre curzolapierre commented Jul 5, 2023

  • Add a changelog entry in the section "To Be Released" of CHANGELOG.md

Fixes #937

@curzolapierre curzolapierre force-pushed the feat/get_addon_by_type branch 3 times, most recently from 99cbbc5 to 654fe93 Compare July 6, 2023 08:06
@curzolapierre curzolapierre marked this pull request as ready for review July 6, 2023 08:10
@curzolapierre curzolapierre changed the title feat: addon param can be a db type name feat: addon param can be an addon type name Jul 6, 2023

func GetAddonUUIDFromType(ctx context.Context, app, addonUUIDorType string) (string, error) {
// If addon does not contain a UUID, we consider it contains an addon type (e.g. MongoDB)
if !strings.HasPrefix(addonUUIDorType, "ad-") {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue(blocking): I thinks it should be

if strings.HasPrefix(addonUUIDorType, "ad-") {

Because, if it does have the prefix ad-, it means it's the addon UUID and we don't need to retrieve the UUID from the type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice catch, last minute copy/paste typo here


addonsClient, err := config.ScalingoClient(ctx)
if err != nil {
return "", errors.Notef(ctx, err, "unable to get Scalingo client")
Copy link
Contributor

Choose a reason for hiding this comment

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


"es": "elasticsearch",
}
addonTypeAlias, isAlias := aliases[addonType]
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: It's not the alias you get here. You retrieve the addonType from an alias

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure about what you are meaning here. Would you have a suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming addonTypeAlias variable to addonTypeFromAlias should be ok IMHO 🙂

"github.com/Scalingo/go-utils/errors/v2"
)

func GetAddonUUIDFromType(ctx context.Context, app, addonUUIDorType string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I found hard to read the variable addonUUIDorType maybe rename it to addonTypeOrUUID.
If you have a better name, use it 🙂


"es": "elasticsearch",
}
addonTypeAlias, isAlias := aliases[addonType]
Copy link
Contributor

Choose a reason for hiding this comment

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

Renaming addonTypeAlias variable to addonTypeFromAlias should be ok IMHO 🙂


func GetAddonUUIDFromType(ctx context.Context, app, addonTypeOrUUID string) (string, error) {
// If addon does not contain a UUID, we consider it contains an addon type (e.g. MongoDB)
if strings.HasPrefix(addonTypeOrUUID, "ad-") {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Is there a way to verify correctly if it's an UUID?
Because if I pass in argument ad-toto, we will do a request to retrieve list of addons for nothing 🙁

Copy link
Member Author

Choose a reason for hiding this comment

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

The test is already done in db-api side. It would returns an HTTP 404

@ipfaze
Copy link
Contributor

ipfaze commented Jul 6, 2023

Nitpick: your branch name is incorrect
It should contain the id of the issue you are fixing like feat/937/get_addon_by_type

@curzolapierre curzolapierre self-assigned this Jul 6, 2023
Copy link
Contributor

@ipfaze ipfaze left a comment

Choose a reason for hiding this comment

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

Except the branch name, LGTM 👍 🚀

cmd/flags.go Outdated
var err error
addonUUID, err = utils.GetAddonUUIDFromType(c.Context, app, addonName)
if err != nil {
fmt.Println("Unable to get the addon UUID based on its type:", err)
Copy link
Member

Choose a reason for hiding this comment

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

From what I remember error message in the CLI must be displayed calling io.Error (https://github.com/Scalingo/cli/blob/7cf4f23d162908d11803e5c03d15f977d53059f7/io/status.go).

@curzolapierre curzolapierre merged commit 8ffbbf1 into master Jul 6, 2023
4 checks passed
@curzolapierre curzolapierre deleted the feat/get_addon_by_type branch July 6, 2023 11:43
@curzolapierre curzolapierre mentioned this pull request Jul 6, 2023
1 task
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.

[addons-info] Should accept addon name as --addon parameter
3 participants