| 11 | ) |
| 12 | |
| 13 | func generateDBRule() (*model.SpecObject, error) { |
| 14 | projectID := "" |
| 15 | if err := input.Survey.AskOne(&survey.Input{Message: "Enter Project ID"}, &projectID); err != nil { |
| 16 | return nil, err |
| 17 | } |
| 18 | ID := "" |
| 19 | if err := input.Survey.AskOne(&survey.Input{Message: "Enter Collection Name"}, &ID); err != nil { |
| 20 | return nil, err |
| 21 | } |
| 22 | dbAlias := "" |
| 23 | if err := input.Survey.AskOne(&survey.Input{Message: "Enter DB Alias"}, &dbAlias); err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | wantRealtimeEnabled := "" |
| 27 | if err := input.Survey.AskOne(&survey.Input{Message: "Is Realtime enabled (Y / n) ?", Default: "n"}, &wantRealtimeEnabled); err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | |
| 31 | var isRealTimeEnabled bool |
| 32 | if strings.ToLower(wantRealtimeEnabled) == "y" { |
| 33 | isRealTimeEnabled = true |
| 34 | } |
| 35 | |
| 36 | v := &model.SpecObject{ |
| 37 | API: "/v1/config/projects/{project}/database/{dbAlias}/collections/{col}/rules", |
| 38 | Type: "db-rules", |
| 39 | Meta: map[string]string{ |
| 40 | "dbAlias": dbAlias, |
| 41 | "col": ID, |
| 42 | "project": projectID, |
| 43 | }, |
| 44 | Spec: map[string]interface{}{ |
| 45 | "isRealtimeEnabled": isRealTimeEnabled, |
| 46 | "rules": map[string]interface{}{ |
| 47 | "create": map[string]interface{}{ |
| 48 | "rule": "allow", |
| 49 | }, |
| 50 | "delete": map[string]interface{}{ |
| 51 | "rule": "allow", |
| 52 | }, |
| 53 | "read": map[string]interface{}{ |
| 54 | "rule": "allow", |
| 55 | }, |
| 56 | "update": map[string]interface{}{ |
| 57 | "rule": "allow", |
| 58 | }, |
| 59 | }, |
| 60 | }, |
| 61 | } |
| 62 | |
| 63 | return v, nil |
| 64 | } |
| 65 | |
| 66 | func generateDBConfig() (*model.SpecObject, error) { |
| 67 | projectID := "" |