Created
March 4, 2020 00:51
-
-
Save stefan2904/a83d9c41e75775ea1d6224675e9e8c39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func testLE() { | |
teststring1 := "Test1" | |
var testint1 int64 = 111 | |
a1 := authzModel{ | |
ID: testint1, | |
IdentifierValue: teststring1, | |
RegistrationID: testint1, | |
Status: 1, | |
} | |
teststring2 := "Test2" | |
var testint2 int64 = 222 | |
a2 := authzModel{ | |
ID: testint2, | |
IdentifierValue: teststring2, | |
RegistrationID: testint2, | |
Status: 42, | |
} | |
m := make(map[string]authzModel) | |
m["test1"] = a1 | |
m["test2"] = a2 | |
r1, _ := authzModelMapToPB(m) | |
for _, elem := range r1.Authz { | |
fmt.Println("") | |
fmt.Println(*elem.Domain) | |
fmt.Println(*elem.Authz.Identifier) | |
fmt.Println(*elem.Authz.RegistrationID) | |
} | |
} | |
// via https://github.com/letsencrypt/boulder/blob/ba6b85ee126b50d19837a53a52cb6d894594935f/sa/model.go#L607 | |
type authzModel struct { | |
ID int64 `db:"id"` | |
//IdentifierType uint8 `db:"identifierType"` | |
IdentifierValue string `db:"identifierValue"` | |
RegistrationID int64 `db:"registrationID"` | |
Status uint8 `db:"status"` | |
//Expires time.Time `db:"expires"` | |
//Challenges uint8 `db:"challenges"` | |
//Attempted *uint8 `db:"attempted"` | |
//Token []byte `db:"token"` | |
//ValidationError []byte `db:"validationError"` | |
//ValidationRecord []byte `db:"validationRecord"` | |
} | |
// via https://github.com/letsencrypt/boulder/blob/ba6b85ee126b50d19837a53a52cb6d894594935f/sa/proto/sa.pb.go#L1423 | |
type Authorizations struct { | |
Authz []*Authorizations_MapElement `protobuf:"bytes,1,rep,name=authz" json:"authz,omitempty"` | |
XXX_NoUnkeyedLiteral struct{} `json:"-"` | |
XXX_unrecognized []byte `json:"-"` | |
XXX_sizecache int32 `json:"-"` | |
} | |
type Authorizations_MapElement struct { | |
Domain *string `protobuf:"bytes,1,opt,name=domain" json:"domain,omitempty"` | |
Authz *Authorization `protobuf:"bytes,2,opt,name=authz" json:"authz,omitempty"` | |
//XXX_NoUnkeyedLiteral struct{} `json:"-"` | |
//XXX_unrecognized []byte `json:"-"` | |
//XXX_sizecache int32 `json:"-"` | |
} | |
// via https://github.com/letsencrypt/boulder/blob/ba6b85ee126b50d19837a53a52cb6d894594935f/core/proto/core.pb.go#L437 | |
type Authorization struct { | |
Id *string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` | |
Identifier *string `protobuf:"bytes,2,opt,name=identifier" json:"identifier,omitempty"` | |
RegistrationID *int64 `protobuf:"varint,3,opt,name=registrationID" json:"registrationID,omitempty"` | |
Status *string `protobuf:"bytes,4,opt,name=status" json:"status,omitempty"` | |
Expires *int64 `protobuf:"varint,5,opt,name=expires" json:"expires,omitempty"` | |
//Challenges []*Challenge `protobuf:"bytes,6,rep,name=challenges" json:"challenges,omitempty"` | |
XXX_NoUnkeyedLiteral struct{} `json:"-"` | |
XXX_unrecognized []byte `json:"-"` | |
XXX_sizecache int32 `json:"-"` | |
} | |
// via https://github.com/letsencrypt/boulder/blob/ba6b85ee126b50d19837a53a52cb6d894594935f/sa/sa.go#L1409 | |
func authzModelMapToPB(m map[string]authzModel) (*Authorizations, error) { | |
resp := &Authorizations{} | |
for k, v := range m { | |
// Make a copy of k because it will be reassigned with each loop. | |
kCopy := k | |
authzPB, err := modelToAuthzPB(&v) | |
if err != nil { | |
return nil, err | |
} | |
resp.Authz = append(resp.Authz, &Authorizations_MapElement{Domain: &kCopy, Authz: authzPB}) | |
} | |
return resp, nil | |
} | |
// via https://github.com/letsencrypt/boulder/blob/ba6b85ee126b50d19837a53a52cb6d894594935f/sa/model.go#L607 | |
func modelToAuthzPB(am *authzModel) (*Authorization, error) { | |
//expires := am.Expires.UTC().UnixNano() | |
id := fmt.Sprintf("%d", am.ID) | |
//status := uintToStatus[am.Status] | |
pb := &Authorization{ | |
Id: &id, | |
//Status: &status, | |
Identifier: &am.IdentifierValue, | |
RegistrationID: &am.RegistrationID, | |
//Expires: &expires, | |
} | |
//... | |
return pb, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment