-
Notifications
You must be signed in to change notification settings - Fork 8
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
CSS-9587 unique offer urls #1273
Conversation
err = j.Database.GetApplicationOffer(ctx, &offerCheck) | ||
if err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Since err
is just used in the if-else statement, you can limit the scope by doing if err := ...; err == nil {
,
if err == nil { | ||
return errors.E(fmt.Sprintf("offer %s already exists, use a different name", offerURL.String()), errors.CodeAlreadyExists) | ||
} else { | ||
if errors.ErrorCode(err) != errors.CodeNotFound { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a leftover after removing something? -> else if
feel free to leave it as is, only a semantic difference
071858b
to
bc94895
Compare
@@ -0,0 +1,4 @@ | |||
-- 1_11.sql is a migration that enforces uniqueness on URLs in application offers. | |||
ALTER TABLE application_offers ADD UNIQUE (url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess again can we have the gorm tag too plz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add this in a follow-up
offerCheck.URL = offerURL.String() | ||
err = j.Database.GetApplicationOffer(ctx, &offerCheck) | ||
if err == nil { | ||
return errors.E(fmt.Sprintf("offer %s already exists, use a different name", offerURL.String()), errors.CodeAlreadyExists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use a different offer name would be better language
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add this in a follow-up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
This PR builds on #1272. Review the second commit from this PR.
This change ensures uniqueness of offer URLs. Offer URLs are used by Juju clients when performing cross-model relations. It's important that offer URLs maintain uniqueness as we use the URL to query our DB for offer details. Currently it is possible for an offer URL to be duplicated if a user creates an offer for 2 models where the models have the same name and the offer name is the same.
Two models with the same name are possible when they are owned by separate users. The offer URL resembles
username/model-name.offer-name
. To resolve this issue, add a unique constrain to the DB and simply check if the offer URL already exists before attempting to create it. If it does exist, return an error and request the user to use a different alias for the offer-name. By default when no offer-name alias is provided, the name will match the application being offered but the user can supply an alternative name.Fixes CSS-9587
Engineering checklist
Check only items that apply