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

add get order method #9

Merged
merged 4 commits into from Mar 6, 2022
Merged

add get order method #9

merged 4 commits into from Mar 6, 2022

Conversation

mailbaoer
Copy link
Contributor

@mailbaoer mailbaoer commented Mar 5, 2022

I want make an api service for cert request for those who want get certificate use dns TXT records manually, like this steps:

  1. send request and return TXT records
  2. add TXT records manually from their dns servers
  3. solve the challenge
  4. get certificate

If we do not have a get order method, we can't get the order created from step 1, these will create a lot of invalid new orders, so I want to add a get order method, we just need to set the order's Location prop before call GetOrder method.

Hope to be merged. I have tested that method works!

@mholt
Copy link
Owner

mholt commented Mar 5, 2022

Hi, thanks for this contribution.

I want to make sure I understand the need for this though. Don't you get the order returned when you call NewOrder()?

@mailbaoer
Copy link
Contributor Author

mailbaoer commented Mar 6, 2022

ok, I will give my test code:

        var ids []acme.Identifier
	for _, domain := range domains {
		ids = append(ids, acme.Identifier{Type: "dns", Value: domain})
	}
	order := acme.Order{Identifiers: ids}
	order, err = client.NewOrder(ctx, account, order)
	if err != nil {
		return fmt.Errorf("creating new order err: %v", err)
	}
	fmt.Println("Order create result:", order.Location)

	order = acme.Order{Identifiers: ids, Location: "https://acme-staging-v02.api.letsencrypt.org/acme/order/xxxx/1947985738"} // xxx I replaced
	order, err = client.GetOrder(ctx, account, order)
	if err != nil {
		return fmt.Errorf("getting new order err: %v", err)
	}
	fmt.Println("Order get result:", order.Location)

and I can get the result
screenshot-20220306-101807

From the screenshot we can see that, NewOrder method will create new order every time, GetOrder method can return the given location of the order

@francislavoie
Copy link
Sponsor Contributor

I think Matt's question is "why do you need to get it again later, at all?" Why can't you just cache the order you get from NewOrder in some map if you need to reuse it?

@mailbaoer
Copy link
Contributor Author

mailbaoer commented Mar 6, 2022

oh, I just explained in the first, I want to make an api service, someone can submit a request, then I will record the txt records he need to add on their dns servers, they maybe add txt records later, when confirmed the records added, they can send another request to solve the challenge

@francislavoie
Copy link
Sponsor Contributor

Well, the order is just a struct with no unexported fields. Why can't you just store it somewhere in the meantime? Serialize it to JSON for example, write it to a database or to file.

@mailbaoer
Copy link
Contributor Author

mailbaoer commented Mar 6, 2022

Yes, you are right, I've already do that, but like https://github.com/mholt/acmez/blob/master/examples/plumbing/main.go#L114,when I want to get the latest order authentications or Challenges status, I must get the order latest status first. If we send the request to solve the challenges, it may take It will take a few minutes to get results, like https://github.com/mholt/acmez/blob/master/examples/plumbing/main.go#L144, it will polling loop for check authentications, if we can get the latest order status, we just need to send a request, no need polling.

@mailbaoer
Copy link
Contributor Author

mailbaoer commented Mar 6, 2022

Another motivation is that I use godaddy's dns nameserver, and the minimum txt records time can only be set to 600 seconds. If we go to solve channellege immediately, it is easy to cause letsencrypt to not be able to query the correct txt records, so I'd better wait After 600 seconds, I will go to the query. If there is an interface to query the order, then I can do other things in these 600 seconds.

@mholt
Copy link
Owner

mholt commented Mar 6, 2022

Hm, that is a unique flow. I guess having a getter method doesn't hurt. The spec even says:

Clients SHOULD check the "status" field of an order to determine
whether they need to take any action.

So, having the ability to read the current status of an order could be useful to some.

Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks, just a couple of nitpicks.

acme/order.go Outdated Show resolved Hide resolved
acme/order.go Outdated Show resolved Hide resolved
mailbaoer and others added 2 commits March 6, 2022 12:37
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
@mailbaoer
Copy link
Contributor Author

Thank you for your advise,I've already changed!

@mailbaoer mailbaoer requested a review from mholt March 6, 2022 05:35
acme/order.go Outdated Show resolved Hide resolved
Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@mholt mholt merged commit 4b14f80 into mholt:master Mar 6, 2022
@mailbaoer mailbaoer deleted the GetOrder branch March 7, 2022 01:42
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.

None yet

3 participants