github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/ns1/permissions.go (about) 1 package ns1 2 3 import ( 4 "github.com/hashicorp/terraform/helper/schema" 5 "gopkg.in/ns1/ns1-go.v2/rest/model/account" 6 ) 7 8 func addPermsSchema(s map[string]*schema.Schema) map[string]*schema.Schema { 9 s["dns_view_zones"] = &schema.Schema{ 10 Type: schema.TypeBool, 11 Optional: true, 12 } 13 s["dns_manage_zones"] = &schema.Schema{ 14 Type: schema.TypeBool, 15 Optional: true, 16 } 17 s["dns_zones_allow_by_default"] = &schema.Schema{ 18 Type: schema.TypeBool, 19 Optional: true, 20 } 21 s["dns_zones_deny"] = &schema.Schema{ 22 Type: schema.TypeList, 23 Optional: true, 24 Elem: &schema.Schema{Type: schema.TypeString}, 25 } 26 s["dns_zones_allow"] = &schema.Schema{ 27 Type: schema.TypeList, 28 Optional: true, 29 Elem: &schema.Schema{Type: schema.TypeString}, 30 } 31 s["data_push_to_datafeeds"] = &schema.Schema{ 32 Type: schema.TypeBool, 33 Optional: true, 34 } 35 s["data_manage_datasources"] = &schema.Schema{ 36 Type: schema.TypeBool, 37 Optional: true, 38 } 39 s["data_manage_datafeeds"] = &schema.Schema{ 40 Type: schema.TypeBool, 41 Optional: true, 42 } 43 s["account_manage_users"] = &schema.Schema{ 44 Type: schema.TypeBool, 45 Optional: true, 46 } 47 s["account_manage_payment_methods"] = &schema.Schema{ 48 Type: schema.TypeBool, 49 Optional: true, 50 } 51 s["account_manage_plan"] = &schema.Schema{ 52 Type: schema.TypeBool, 53 Optional: true, 54 } 55 s["account_manage_teams"] = &schema.Schema{ 56 Type: schema.TypeBool, 57 Optional: true, 58 } 59 s["account_manage_apikeys"] = &schema.Schema{ 60 Type: schema.TypeBool, 61 Optional: true, 62 } 63 s["account_manage_account_settings"] = &schema.Schema{ 64 Type: schema.TypeBool, 65 Optional: true, 66 } 67 s["account_view_activity_log"] = &schema.Schema{ 68 Type: schema.TypeBool, 69 Optional: true, 70 } 71 s["account_view_invoices"] = &schema.Schema{ 72 Type: schema.TypeBool, 73 Optional: true, 74 } 75 s["monitoring_manage_lists"] = &schema.Schema{ 76 Type: schema.TypeBool, 77 Optional: true, 78 } 79 s["monitoring_manage_jobs"] = &schema.Schema{ 80 Type: schema.TypeBool, 81 Optional: true, 82 } 83 s["monitoring_view_jobs"] = &schema.Schema{ 84 Type: schema.TypeBool, 85 Optional: true, 86 } 87 return s 88 } 89 90 func permissionsToResourceData(d *schema.ResourceData, permissions account.PermissionsMap) { 91 d.Set("dns_view_zones", permissions.DNS.ViewZones) 92 d.Set("dns_manage_zones", permissions.DNS.ManageZones) 93 d.Set("dns_zones_allow_by_default", permissions.DNS.ZonesAllowByDefault) 94 d.Set("dns_zones_deny", permissions.DNS.ZonesDeny) 95 d.Set("dns_zones_allow", permissions.DNS.ZonesAllow) 96 d.Set("data_push_to_datafeeds", permissions.Data.PushToDatafeeds) 97 d.Set("data_manage_datasources", permissions.Data.ManageDatasources) 98 d.Set("data_manage_datafeeds", permissions.Data.ManageDatafeeds) 99 d.Set("account_manage_users", permissions.Account.ManageUsers) 100 d.Set("account_manage_payment_methods", permissions.Account.ManagePaymentMethods) 101 d.Set("account_manage_plan", permissions.Account.ManagePlan) 102 d.Set("account_manage_teams", permissions.Account.ManageTeams) 103 d.Set("account_manage_apikeys", permissions.Account.ManageApikeys) 104 d.Set("account_manage_account_settings", permissions.Account.ManageAccountSettings) 105 d.Set("account_view_activity_log", permissions.Account.ViewActivityLog) 106 d.Set("account_view_invoices", permissions.Account.ViewInvoices) 107 d.Set("monitoring_manage_lists", permissions.Monitoring.ManageLists) 108 d.Set("monitoring_manage_jobs", permissions.Monitoring.ManageJobs) 109 d.Set("monitoring_view_jobs", permissions.Monitoring.ViewJobs) 110 } 111 112 func resourceDataToPermissions(d *schema.ResourceData) account.PermissionsMap { 113 var p account.PermissionsMap 114 if v, ok := d.GetOk("dns_view_zones"); ok { 115 p.DNS.ViewZones = v.(bool) 116 } 117 if v, ok := d.GetOk("dns_manage_zones"); ok { 118 p.DNS.ManageZones = v.(bool) 119 } 120 if v, ok := d.GetOk("dns_zones_allow_by_default"); ok { 121 p.DNS.ZonesAllowByDefault = v.(bool) 122 } 123 if v, ok := d.GetOk("dns_zones_deny"); ok { 124 denyRaw := v.([]interface{}) 125 p.DNS.ZonesDeny = make([]string, len(denyRaw)) 126 for i, deny := range denyRaw { 127 p.DNS.ZonesDeny[i] = deny.(string) 128 } 129 } else { 130 p.DNS.ZonesDeny = make([]string, 0) 131 } 132 if v, ok := d.GetOk("dns_zones_allow"); ok { 133 allowRaw := v.([]interface{}) 134 p.DNS.ZonesAllow = make([]string, len(allowRaw)) 135 for i, allow := range allowRaw { 136 p.DNS.ZonesAllow[i] = allow.(string) 137 } 138 } else { 139 p.DNS.ZonesAllow = make([]string, 0) 140 } 141 if v, ok := d.GetOk("data_push_to_datafeeds"); ok { 142 p.Data.PushToDatafeeds = v.(bool) 143 } 144 if v, ok := d.GetOk("data_manage_datasources"); ok { 145 p.Data.ManageDatasources = v.(bool) 146 } 147 if v, ok := d.GetOk("data_manage_datafeeds"); ok { 148 p.Data.ManageDatafeeds = v.(bool) 149 } 150 if v, ok := d.GetOk("account_manage_users"); ok { 151 p.Account.ManageUsers = v.(bool) 152 } 153 if v, ok := d.GetOk("account_manage_payment_methods"); ok { 154 p.Account.ManagePaymentMethods = v.(bool) 155 } 156 if v, ok := d.GetOk("account_manage_plan"); ok { 157 p.Account.ManagePlan = v.(bool) 158 } 159 if v, ok := d.GetOk("account_manage_teams"); ok { 160 p.Account.ManageTeams = v.(bool) 161 } 162 if v, ok := d.GetOk("account_manage_apikeys"); ok { 163 p.Account.ManageApikeys = v.(bool) 164 } 165 if v, ok := d.GetOk("account_manage_account_settings"); ok { 166 p.Account.ManageAccountSettings = v.(bool) 167 } 168 if v, ok := d.GetOk("account_view_activity_log"); ok { 169 p.Account.ViewActivityLog = v.(bool) 170 } 171 if v, ok := d.GetOk("account_view_invoices"); ok { 172 p.Account.ViewInvoices = v.(bool) 173 } 174 if v, ok := d.GetOk("monitoring_manage_lists"); ok { 175 p.Monitoring.ManageLists = v.(bool) 176 } 177 if v, ok := d.GetOk("monitoring_manage_jobs"); ok { 178 p.Monitoring.ManageJobs = v.(bool) 179 } 180 if v, ok := d.GetOk("monitoring_view_jobs"); ok { 181 p.Monitoring.ViewJobs = v.(bool) 182 } 183 return p 184 }