yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/redis_acl.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package azure 16 17 import ( 18 "fmt" 19 "net/url" 20 "strings" 21 22 "yunion.io/x/jsonutils" 23 "yunion.io/x/pkg/errors" 24 25 api "yunion.io/x/cloudmux/pkg/apis/compute" 26 "yunion.io/x/cloudmux/pkg/cloudprovider" 27 "yunion.io/x/cloudmux/pkg/multicloud" 28 ) 29 30 type SRedisAcl struct { 31 redis *SRedisCache 32 multicloud.SResourceBase 33 AzureTags 34 35 ID string `json:"id"` 36 Name string `json:"name"` 37 Type string `json:"type"` 38 Properties struct { 39 Startip string `json:"startIP"` 40 Endip string `json:"endIP"` 41 } `json:"properties"` 42 } 43 44 func (self *SRedisAcl) GetId() string { 45 return self.ID 46 } 47 48 func (self *SRedisAcl) GetGlobalId() string { 49 return strings.ToLower(self.ID) 50 } 51 52 func (self *SRedisAcl) GetName() string { 53 return self.Name 54 } 55 56 func (self *SRedisAcl) GetStatus() string { 57 return api.ELASTIC_CACHE_ACL_STATUS_AVAILABLE 58 } 59 60 func (self *SRedisAcl) Refresh() error { 61 acl, err := self.redis.region.GetRedisAcl(self.ID) 62 if err != nil { 63 return err 64 } 65 return jsonutils.Update(self, acl) 66 } 67 68 func (self *SRedisAcl) GetIpList() string { 69 return fmt.Sprintf("%s-%s", self.Properties.Startip, self.Properties.Endip) 70 } 71 72 func (self *SRedisAcl) Delete() error { 73 return self.redis.region.Delete(self.ID) 74 } 75 76 func (self *SRedisAcl) UpdateAcl(securityIps string) error { 77 return errors.Wrapf(cloudprovider.ErrNotImplemented, "UpdateAcl") 78 } 79 80 func (self *SRegion) GetRedisAcls(id string) ([]SRedisAcl, error) { 81 result := struct { 82 Value []SRedisAcl 83 }{} 84 return result.Value, self.get(id+"/firewallRules", url.Values{}, &result) 85 } 86 87 func (self *SRegion) GetRedisAcl(id string) (*SRedisAcl, error) { 88 acl := &SRedisAcl{} 89 return acl, self.get(id, url.Values{}, acl) 90 }