1- package controller
1+ package cf
22
33import (
44 "context"
@@ -15,8 +15,8 @@ import (
1515// TXT_PREFIX is the prefix added to TXT records for whom the corresponding DNS records are managed by the operator.
1616const TXT_PREFIX = "_managed."
1717
18- // CloudflareAPI config object holding all relevant fields to use the API
19- type CloudflareAPI struct {
18+ // API config object holding all relevant fields to use the API
19+ type API struct {
2020 Log logr.Logger
2121 TunnelName string
2222 TunnelId string
@@ -30,8 +30,8 @@ type CloudflareAPI struct {
3030 CloudflareClient * cloudflare.API
3131}
3232
33- // CloudflareTunnelCredentialsFile object containing the fields that make up a Cloudflare Tunnel's credentials
34- type CloudflareTunnelCredentialsFile struct {
33+ // TunnelCredentialsFile object containing the fields that make up a Cloudflare Tunnel's credentials
34+ type TunnelCredentialsFile struct {
3535 AccountTag string `json:"AccountTag"`
3636 TunnelID string `json:"TunnelID"`
3737 TunnelName string `json:"TunnelName"`
@@ -45,8 +45,8 @@ type DnsManagedRecordTxt struct {
4545 TunnelId string // TunnelId of the managed record
4646}
4747
48- // CreateCloudflareTunnel creates a Cloudflare Tunnel and returns the tunnel Id and credentials file
49- func (c * CloudflareAPI ) CreateCloudflareTunnel () (string , string , error ) {
48+ // CreateTunnel creates a Cloudflare Tunnel and returns the tunnel Id and credentials file
49+ func (c * API ) CreateTunnel () (string , string , error ) {
5050 if _ , err := c .GetAccountId (); err != nil {
5151 c .Log .Error (err , "error code in getting account ID" )
5252 return "" , "" , err
@@ -78,7 +78,7 @@ func (c *CloudflareAPI) CreateCloudflareTunnel() (string, string, error) {
7878 c .ValidTunnelId = tunnel .ID
7979 c .ValidTunnelName = tunnel .Name
8080
81- credentialsFile := CloudflareTunnelCredentialsFile {
81+ credentialsFile := TunnelCredentialsFile {
8282 AccountTag : c .ValidAccountId ,
8383 TunnelID : tunnel .ID ,
8484 TunnelName : tunnel .Name ,
@@ -90,8 +90,8 @@ func (c *CloudflareAPI) CreateCloudflareTunnel() (string, string, error) {
9090 return tunnel .ID , string (creds ), err
9191}
9292
93- // DeleteCloudflareTunnel deletes a Cloudflare Tunnel
94- func (c * CloudflareAPI ) DeleteCloudflareTunnel () error {
93+ // DeleteTunnel deletes a Cloudflare Tunnel
94+ func (c * API ) DeleteTunnel () error {
9595 if err := c .ValidateAll (); err != nil {
9696 c .Log .Error (err , "Error in validation" )
9797 return err
@@ -117,8 +117,8 @@ func (c *CloudflareAPI) DeleteCloudflareTunnel() error {
117117 return nil
118118}
119119
120- // ValidateAll validates the contents of the CloudflareAPI struct
121- func (c * CloudflareAPI ) ValidateAll () error {
120+ // ValidateAll validates the contents of the API struct
121+ func (c * API ) ValidateAll () error {
122122 c .Log .Info ("In validation" )
123123 if _ , err := c .GetAccountId (); err != nil {
124124 return err
@@ -137,7 +137,7 @@ func (c *CloudflareAPI) ValidateAll() error {
137137}
138138
139139// GetAccountId gets AccountId from Account Name
140- func (c * CloudflareAPI ) GetAccountId () (string , error ) {
140+ func (c * API ) GetAccountId () (string , error ) {
141141 if c .ValidAccountId != "" {
142142 return c .ValidAccountId , nil
143143 }
@@ -161,7 +161,7 @@ func (c *CloudflareAPI) GetAccountId() (string, error) {
161161 return c .ValidAccountId , nil
162162}
163163
164- func (c CloudflareAPI ) validateAccountId () bool {
164+ func (c * API ) validateAccountId () bool {
165165 if c .AccountId == "" {
166166 c .Log .Info ("Account ID not provided" )
167167 return false
@@ -178,7 +178,7 @@ func (c CloudflareAPI) validateAccountId() bool {
178178 return account .ID == c .AccountId
179179}
180180
181- func (c * CloudflareAPI ) getAccountIdByName () (string , error ) {
181+ func (c * API ) getAccountIdByName () (string , error ) {
182182 ctx := context .Background ()
183183 params := cloudflare.AccountsListParams {
184184 Name : c .AccountName ,
@@ -204,7 +204,7 @@ func (c *CloudflareAPI) getAccountIdByName() (string, error) {
204204}
205205
206206// GetTunnelId gets Tunnel Id from available information
207- func (c * CloudflareAPI ) GetTunnelId () (string , error ) {
207+ func (c * API ) GetTunnelId () (string , error ) {
208208 if c .ValidTunnelId != "" {
209209 return c .ValidTunnelId , nil
210210 }
@@ -231,7 +231,7 @@ func (c *CloudflareAPI) GetTunnelId() (string, error) {
231231 return c .ValidTunnelId , nil
232232}
233233
234- func (c * CloudflareAPI ) validateTunnelId () bool {
234+ func (c * API ) validateTunnelId () bool {
235235 if c .TunnelId == "" {
236236 c .Log .Info ("Tunnel ID not provided" )
237237 return false
@@ -254,7 +254,7 @@ func (c *CloudflareAPI) validateTunnelId() bool {
254254 return tunnel .ID == c .TunnelId
255255}
256256
257- func (c * CloudflareAPI ) getTunnelIdByName () (string , error ) {
257+ func (c * API ) getTunnelIdByName () (string , error ) {
258258 if _ , err := c .GetAccountId (); err != nil {
259259 c .Log .Error (err , "error in getting account ID" )
260260 return "" , err
@@ -288,7 +288,7 @@ func (c *CloudflareAPI) getTunnelIdByName() (string, error) {
288288}
289289
290290// GetTunnelCreds gets Tunnel Credentials from Tunnel secret
291- func (c * CloudflareAPI ) GetTunnelCreds (tunnelSecret string ) (string , error ) {
291+ func (c * API ) GetTunnelCreds (tunnelSecret string ) (string , error ) {
292292 if _ , err := c .GetAccountId (); err != nil {
293293 c .Log .Error (err , "error in getting account ID" )
294294 return "" , err
@@ -310,7 +310,7 @@ func (c *CloudflareAPI) GetTunnelCreds(tunnelSecret string) (string, error) {
310310}
311311
312312// GetZoneId gets Zone Id from DNS domain
313- func (c * CloudflareAPI ) GetZoneId () (string , error ) {
313+ func (c * API ) GetZoneId () (string , error ) {
314314 if c .ValidZoneId != "" {
315315 return c .ValidZoneId , nil
316316 }
@@ -329,7 +329,7 @@ func (c *CloudflareAPI) GetZoneId() (string, error) {
329329 return c .ValidZoneId , nil
330330}
331331
332- func (c * CloudflareAPI ) getZoneIdByName () (string , error ) {
332+ func (c * API ) getZoneIdByName () (string , error ) {
333333 ctx := context .Background ()
334334 zones , err := c .CloudflareClient .ListZones (ctx , c .Domain )
335335
@@ -353,7 +353,7 @@ func (c *CloudflareAPI) getZoneIdByName() (string, error) {
353353}
354354
355355// InsertOrUpdateCName upsert DNS CNAME record for the given FQDN to point to the tunnel
356- func (c * CloudflareAPI ) InsertOrUpdateCName (fqdn , dnsId string ) (string , error ) {
356+ func (c * API ) InsertOrUpdateCName (fqdn , dnsId string ) (string , error ) {
357357 ctx := context .Background ()
358358 rc := cloudflare .ZoneIdentifier (c .ValidZoneId )
359359 if dnsId != "" {
@@ -395,7 +395,7 @@ func (c *CloudflareAPI) InsertOrUpdateCName(fqdn, dnsId string) (string, error)
395395}
396396
397397// DeleteDNSId deletes DNS entry for the given dnsId
398- func (c * CloudflareAPI ) DeleteDNSId (fqdn , dnsId string , created bool ) error {
398+ func (c * API ) DeleteDNSId (fqdn , dnsId string , created bool ) error {
399399 // Do not delete if we did not create the DNS in this cycle
400400 if ! created {
401401 return nil
@@ -414,7 +414,7 @@ func (c *CloudflareAPI) DeleteDNSId(fqdn, dnsId string, created bool) error {
414414}
415415
416416// GetDNSCNameId returns the ID of the CNAME record requested
417- func (c * CloudflareAPI ) GetDNSCNameId (fqdn string ) (string , error ) {
417+ func (c * API ) GetDNSCNameId (fqdn string ) (string , error ) {
418418 if _ , err := c .GetZoneId (); err != nil {
419419 c .Log .Error (err , "error in getting Zone ID" )
420420 return "" , err
@@ -447,7 +447,7 @@ func (c *CloudflareAPI) GetDNSCNameId(fqdn string) (string, error) {
447447}
448448
449449// GetManagedDnsTxt gets the TXT record corresponding to the fqdn
450- func (c * CloudflareAPI ) GetManagedDnsTxt (fqdn string ) (string , DnsManagedRecordTxt , bool , error ) {
450+ func (c * API ) GetManagedDnsTxt (fqdn string ) (string , DnsManagedRecordTxt , bool , error ) {
451451 if _ , err := c .GetZoneId (); err != nil {
452452 c .Log .Error (err , "error in getting Zone ID" )
453453 return "" , DnsManagedRecordTxt {}, false , err
@@ -488,7 +488,7 @@ func (c *CloudflareAPI) GetManagedDnsTxt(fqdn string) (string, DnsManagedRecordT
488488}
489489
490490// InsertOrUpdateTXT upsert DNS TXT record for the given FQDN to point to the tunnel
491- func (c * CloudflareAPI ) InsertOrUpdateTXT (fqdn , txtId , dnsId string ) error {
491+ func (c * API ) InsertOrUpdateTXT (fqdn , txtId , dnsId string ) error {
492492 content , err := json .Marshal (DnsManagedRecordTxt {
493493 DnsId : dnsId ,
494494 TunnelId : c .ValidTunnelId ,
0 commit comments