@@ -48,15 +48,6 @@ type certManager struct {
4848
4949 httpClientTimeout time.Duration
5050 waitGenerateTimeout time.Duration
51-
52- // apis
53- apiGenerate string
54- apiGenerateStatus string
55- apiAddDNSRecord string
56- apiDeleteDNSRecord string
57- apiDownloadCert string
58- apiSetCustomDomainOnCloudflare string
59- apiCheckCustomDomainStatus string
6051}
6152
6253var _ Interface = & certManager {}
@@ -67,31 +58,19 @@ func NewCertManager(terminusName constants.TerminusName) Interface {
6758 c .httpClientTimeout = 30 * time .Second
6859 c .waitGenerateTimeout = 5 * time .Minute
6960
70- // apis
71- c .apiGenerate = fmt .Sprintf (constants .APIFormatCertGenerateRequest , terminusName )
72- c .apiGenerateStatus = fmt .Sprintf (constants .APIFormatCertGenerateStatus , terminusName )
73- c .apiDownloadCert = fmt .Sprintf (constants .APIFormatCertDownload , terminusName )
74-
75- c .apiAddDNSRecord = constants .APIDNSAddRecord
76- c .apiDeleteDNSRecord = fmt .Sprintf (constants .APIFormatDNSDeleteRecord , terminusName )
77-
78- c .apiSetCustomDomainOnCloudflare = constants .APIDNSAddCustomDomain
79-
80- c .apiCheckCustomDomainStatus = constants .APIDNSCheckCustomDomainCname
81-
8261 return c
8362}
8463
8564func (c * certManager ) GenerateCert () error {
86- err := c .request (context .TODO (), "GET" , c . apiGenerate , nil , nil )
65+ err := c .request (context .TODO (), "GET" , fmt . Sprintf ( constants . APIFormatCertGenerateRequest , c . terminusName ) , nil , nil )
8766 if err != nil {
8867 return err
8968 }
9069
9170 t := time .After (c .waitGenerateTimeout )
9271
9372 for {
94- err = c .request (context .TODO (), "GET" , c . apiGenerateStatus , nil , nil )
73+ err = c .request (context .TODO (), "GET" , fmt . Sprintf ( constants . APIFormatCertGenerateStatus , c . terminusName ) , nil , nil )
9574 if err == nil {
9675 break
9776 }
@@ -109,7 +88,7 @@ func (c *certManager) GenerateCert() error {
10988func (c * certManager ) DownloadCert () (* ResponseCert , error ) {
11089 var r ResponseDownloadCert
11190
112- err := c .request (context .TODO (), "GET" , c . apiDownloadCert , nil , & r )
91+ err := c .request (context .TODO (), "GET" , fmt . Sprintf ( constants . APIFormatCertDownload , c . terminusName ) , nil , & r )
11392 if err != nil {
11493 return nil , err
11594 }
@@ -130,11 +109,11 @@ func (c *certManager) AddDNSRecord(publicIP, domain *string) error {
130109 payload .Domain = * domain
131110 }
132111
133- return c .request (context .TODO (), "POST" , c . apiAddDNSRecord , payload , nil )
112+ return c .request (context .TODO (), "POST" , constants . APIDNSAddRecord , payload , nil )
134113}
135114
136115func (c * certManager ) DeleteDNSRecord () error {
137- return c .request (context .TODO (), "GET" , c . apiDeleteDNSRecord , nil , nil )
116+ return c .request (context .TODO (), "GET" , fmt . Sprintf ( constants . APIFormatDNSDeleteRecord , c . terminusName ) , nil , nil )
138117}
139118
140119func (c * certManager ) getCertManagerJWSToken () (string , error ) {
@@ -278,7 +257,7 @@ func ValidPemCert(cert string) error {
278257func (c * certManager ) AddCustomDomainOnCloudflare (customDomain string ) (* ResponseCustomDomainStatus , error ) {
279258 payload := CustomDomainPayload {Name : string (c .terminusName ), CustomDomain : customDomain }
280259 var r ResponseAddCustomDomain
281- err := c .request (context .TODO (), "POST" , c . apiSetCustomDomainOnCloudflare , payload , & r )
260+ err := c .request (context .TODO (), "POST" , constants . APIDNSAddCustomDomain , payload , & r )
282261 if err != nil && ! strings .Contains (err .Error (), "409 Conflict" ) {
283262 return nil , err
284263 }
@@ -290,7 +269,7 @@ func (c *certManager) GetCustomDomainOnCloudflare(customDomain string) (*Respons
290269 defer cancel ()
291270
292271 var r ResponseGetCustomDomain
293- var url = fmt .Sprintf ("%s?name=%s&custom-host-name=%s" , c . apiSetCustomDomainOnCloudflare , c .terminusName , customDomain )
272+ var url = fmt .Sprintf ("%s?name=%s&custom-host-name=%s" , constants . APIDNSAddCustomDomain , c .terminusName , customDomain )
294273 err := c .request (ctx , "GET" , url , nil , & r )
295274 if err != nil {
296275 return nil , err
@@ -301,7 +280,7 @@ func (c *certManager) GetCustomDomainOnCloudflare(customDomain string) (*Respons
301280func (c * certManager ) DeleteCustomDomainOnCloudflare (customDomain string ) (* Response , error ) {
302281 payload := CustomDomainPayload {Name : string (c .terminusName ), CustomDomain : customDomain }
303282 var r Response
304- err := c .request (context .Background (), "DELETE" , c . apiSetCustomDomainOnCloudflare , payload , & r )
283+ err := c .request (context .Background (), "DELETE" , constants . APIDNSSetCloudFlareTunnel , payload , & r )
305284 if err != nil && ! strings .Contains (err .Error (), "The custom hostname was not found" ) {
306285 return nil , err
307286 }
@@ -315,7 +294,7 @@ func (c *certManager) GetCustomDomainCnameStatus(customDomain string) (*Response
315294 payload := CustomDomainPayload {Name : string (c .terminusName ), CustomDomain : customDomain }
316295 var r Response
317296
318- err := c .request (ctx , "POST" , c . apiCheckCustomDomainStatus , payload , & r )
297+ err := c .request (ctx , "POST" , constants . APIDNSCheckCustomDomainCname , payload , & r )
319298 if err != nil && ! strings .Contains (err .Error (), "cname configuration error" ) {
320299 return nil , err
321300 }
0 commit comments