mholt / acmez

Premier ACME client library for Go
https://pkg.go.dev/github.com/mholt/acmez/v2
Apache License 2.0
281 stars 35 forks source link

add get order method #9

Closed mailbaoer closed 2 years ago

mailbaoer commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.

mailbaoer commented 2 years ago

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