1- package incapsula
1+ package imperva
22
33import (
44 "cmp"
@@ -17,7 +17,7 @@ import (
1717 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1818)
1919
20- type IncapsulaStore struct {
20+ type ImpervaStore struct {
2121 ID string `json:"api_id"`
2222 SiteID string `json:"site_id"`
2323 Key string `json:"api_key"`
@@ -26,21 +26,21 @@ type IncapsulaStore struct {
2626 SecretNamespace string
2727}
2828
29- func (s * IncapsulaStore ) GetApiKey (ctx context.Context ) error {
29+ func (s * ImpervaStore ) GetApiKey (ctx context.Context ) error {
3030 gopt := metav1.GetOptions {}
3131 if s .SecretName == "" {
3232 return fmt .Errorf ("secret name not set" )
3333 }
3434 sc , err := state .KubeClient .CoreV1 ().Secrets (s .SecretNamespace ).Get (ctx , s .SecretName , gopt )
3535 if err != nil {
36- return fmt .Errorf ("failed to get Incapsula credentials secret %s/%s: %w" , s .SecretNamespace , s .SecretName , err )
36+ return fmt .Errorf ("failed to get Imperva credentials secret %s/%s: %w" , s .SecretNamespace , s .SecretName , err )
3737 }
3838 s .ID = string (sc .Data ["api_id" ])
3939 s .Key = string (sc .Data ["api_key" ])
4040 return nil
4141}
4242
43- func (s * IncapsulaStore ) FromConfig (c tlssecret.GenericSecretSyncConfig ) error {
43+ func (s * ImpervaStore ) FromConfig (c tlssecret.GenericSecretSyncConfig ) error {
4444 l := log .WithFields (log.Fields {
4545 "action" : "FromConfig" ,
4646 })
@@ -64,8 +64,8 @@ func (s *IncapsulaStore) FromConfig(c tlssecret.GenericSecretSyncConfig) error {
6464 return nil
6565}
6666
67- // Incapsula response contains the response from Incapsula API
68- type IncapsulaResponse struct {
67+ // ImpervaResponse contains the response from Imperva API
68+ type ImpervaResponse struct {
6969 Res int `json:"res"`
7070 ResMessage string `json:"res_message"`
7171}
@@ -77,15 +77,15 @@ type ImpervaCertUpload struct {
7777 AuthType string `json:"auth_type"`
7878}
7979
80- // UploadIncapsulaCert syncs a certificate with Incapsula site
81- func (s * IncapsulaStore ) UploadIncapsulaCert (cert * tlssecret.Certificate ) error {
80+ // UploadImpervaCert syncs a certificate with Imperva site
81+ func (s * ImpervaStore ) UploadImpervaCert (cert * tlssecret.Certificate ) error {
8282 l := log .WithFields (
8383 log.Fields {
84- "action" : "UploadIncapsulaCert " ,
84+ "action" : "UploadImpervaCert " ,
8585 "siteID" : s .SiteID ,
8686 },
8787 )
88- l .Debugf ("UploadIncapsulaCert " )
88+ l .Debugf ("UploadImpervaCert " )
8989 var err error
9090 bCert := base64 .StdEncoding .EncodeToString (cert .FullChain ())
9191 bKey := base64 .StdEncoding .EncodeToString (cert .Key )
@@ -99,56 +99,56 @@ func (s *IncapsulaStore) UploadIncapsulaCert(cert *tlssecret.Certificate) error
9999 jd , err := json .Marshal (up )
100100 if err != nil {
101101 l .WithError (err ).Errorf ("json.Marshal error" )
102- return fmt .Errorf ("failed to marshal Incapsula certificate upload request: %w" , err )
102+ return fmt .Errorf ("failed to marshal Imperva certificate upload request: %w" , err )
103103 }
104104 l .Debugf ("url=%s data=%s" , iurl , string (jd ))
105105 req , rerr := http .NewRequest ("PUT" , iurl , strings .NewReader (string (jd )))
106106 if rerr != nil {
107107 l .WithError (rerr ).Errorf ("http.NewRequest error" )
108- return fmt .Errorf ("failed to create Incapsula API request for site %s: %w" , s .SiteID , rerr )
108+ return fmt .Errorf ("failed to create Imperva API request for site %s: %w" , s .SiteID , rerr )
109109 }
110110 req .Header .Set ("x-api-id" , s .ID )
111111 req .Header .Set ("x-api-key" , s .Key )
112112 req .Header .Set ("Content-Type" , "application/json" )
113113 res , serr := c .Do (req )
114114 if serr != nil {
115115 l .WithError (serr ).Errorf ("c.Do error=%v" , serr )
116- return fmt .Errorf ("failed to upload certificate to Incapsula site %s: %w" , s .SiteID , serr )
116+ return fmt .Errorf ("failed to upload certificate to Imperva site %s: %w" , s .SiteID , serr )
117117 }
118118 defer res .Body .Close ()
119119 bd , berr := io .ReadAll (res .Body )
120120 if berr != nil {
121121 l .WithError (berr ).Errorf ("io.ReadAll error" )
122- return fmt .Errorf ("failed to read Incapsula API response for site %s: %w" , s .SiteID , berr )
122+ return fmt .Errorf ("failed to read Imperva API response for site %s: %w" , s .SiteID , berr )
123123 }
124124 if res .StatusCode != 200 {
125125 l .Debugf ("status=%v body=%s" , res .StatusCode , string (bd ))
126- return fmt .Errorf ("incapsula upload failed for site %s (status: %d, secret: %s/%s): %s" , s .SiteID , res .StatusCode , s .SecretNamespace , s .SecretName , string (bd ))
126+ return fmt .Errorf ("imperva upload failed for site %s (status: %d, secret: %s/%s): %s" , s .SiteID , res .StatusCode , s .SecretNamespace , s .SecretName , string (bd ))
127127 }
128- ir := & IncapsulaResponse {}
128+ ir := & ImpervaResponse {}
129129 if err = json .Unmarshal (bd , ir ); err != nil {
130130 l .WithError (err ).Errorf ("json.Unmarshal error" )
131131 // debug dump the response
132132 l .Debugf ("status=%v body=%s" , res .StatusCode , string (bd ))
133- return fmt .Errorf ("failed to parse Incapsula API response for site %s: %w" , s .SiteID , err )
133+ return fmt .Errorf ("failed to parse Imperva API response for site %s: %w" , s .SiteID , err )
134134 }
135- l .Debugf ("incapsula statusCode=%d response=%v" , res .StatusCode , string (bd ))
135+ l .Debugf ("imperva statusCode=%d response=%v" , res .StatusCode , string (bd ))
136136 if ir .Res != 0 {
137137 l .Debugf ("status=%v body=%s" , res .StatusCode , string (bd ))
138- return fmt .Errorf ("incapsula upload failed for site %s (secret: %s/%s): %s" , s .SiteID , s .SecretNamespace , s .SecretName , string (bd ))
138+ return fmt .Errorf ("imperva upload failed for site %s (secret: %s/%s): %s" , s .SiteID , s .SecretNamespace , s .SecretName , string (bd ))
139139 }
140- l .Debugf ("incapsula response=%v" , string (bd ))
140+ l .Debugf ("imperva response=%v" , string (bd ))
141141 return err
142142}
143143
144- func (s * IncapsulaStore ) GetIncapsulaSiteStatus () (string , error ) {
144+ func (s * ImpervaStore ) GetImpervaSiteStatus () (string , error ) {
145145 l := log .WithFields (
146146 log.Fields {
147- "action" : "GetIncapsulaSiteStatus " ,
147+ "action" : "GetImpervaSiteStatus " ,
148148 "siteID" : s .SiteID ,
149149 },
150150 )
151- l .Debugf ("GetIncapsulaSiteStatus " )
151+ l .Debugf ("GetImpervaSiteStatus " )
152152 var err error
153153 iurl := "https://my.imperva.com/api/prov/v1/sites/status"
154154 c := http.Client {}
@@ -176,25 +176,25 @@ func (s *IncapsulaStore) GetIncapsulaSiteStatus() (string, error) {
176176 l .WithError (berr ).Errorf ("ioutil.ReadAll error" )
177177 return "" , berr
178178 }
179- ir := & IncapsulaResponse {}
179+ ir := & ImpervaResponse {}
180180 if err = json .Unmarshal (bd , ir ); err != nil {
181181 l .WithError (err ).Errorf ("json.Unmarshal error" )
182182 return string (bd ), err
183183 }
184- l .Debugf ("incapsula statusCode=%d response=%v" , res .StatusCode , string (bd ))
184+ l .Debugf ("imperva statusCode=%d response=%v" , res .StatusCode , string (bd ))
185185 if ir .Res != 0 {
186186 l .Debugf ("status=%v body=%s" , res .StatusCode , string (bd ))
187- return string (bd ), fmt .Errorf ("incapsula upload failed, body=%s" , string (bd ))
187+ return string (bd ), fmt .Errorf ("imperva upload failed, body=%s" , string (bd ))
188188 }
189- l .Debugf ("incapsula response=%v" , string (bd ))
189+ l .Debugf ("imperva response=%v" , string (bd ))
190190 return string (bd ), err
191191}
192192
193- func (s * IncapsulaStore ) Sync (c * tlssecret.Certificate ) (map [string ]string , error ) {
193+ func (s * ImpervaStore ) Sync (c * tlssecret.Certificate ) (map [string ]string , error ) {
194194 s .SecretNamespace = c .Namespace
195195 l := log .WithFields (log.Fields {
196196 "action" : "Sync" ,
197- "store" : "incapsula " ,
197+ "store" : "imperva " ,
198198 "secretName" : s .SecretName ,
199199 "secretNamespace" : s .SecretNamespace ,
200200 "siteID" : s .SiteID ,
@@ -205,18 +205,18 @@ func (s *IncapsulaStore) Sync(c *tlssecret.Certificate) (map[string]string, erro
205205 })
206206 ctx := context .Background ()
207207 if err := s .GetApiKey (ctx ); err != nil {
208- l .WithError (err ).Errorf ("incapsula .GetApiKey error" )
208+ l .WithError (err ).Errorf ("imperva .GetApiKey error" )
209209 l .WithError (err ).Errorf ("sync error" )
210210 return nil , err
211211 }
212- bd , err := s .GetIncapsulaSiteStatus ()
212+ bd , err := s .GetImpervaSiteStatus ()
213213 if err != nil {
214- l .WithError (err ).Errorf ("incapsula.GetIncapsulaSiteStatus error: %s" , bd )
214+ l .WithError (err ).Errorf ("imperva.GetImpervaSiteStatus error: %s" , bd )
215215 l .WithError (err ).Errorf ("sync error" )
216216 return nil , err
217217 }
218- if err := s .UploadIncapsulaCert (c ); err != nil {
219- l .WithError (err ).Errorf ("incapsula.UploadIncapsulaCert error" )
218+ if err := s .UploadImpervaCert (c ); err != nil {
219+ l .WithError (err ).Errorf ("imperva.UploadImpervaCert error" )
220220 l .WithError (err ).Errorf ("sync error" )
221221 return nil , err
222222 }
0 commit comments