(ctx context.Context, driver string, input *log_dto.Save)
| 88 | } |
| 89 | |
| 90 | func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.Save) error { |
| 91 | factory, has := log_driver.GetFactory(driver) |
| 92 | if !has { |
| 93 | return errors.New("driver not found") |
| 94 | } |
| 95 | input.Cluster = cluster.DefaultClusterID |
| 96 | var cfg *string |
| 97 | if input.Config != nil { |
| 98 | data, _ := json.Marshal(input.Config) |
| 99 | tmp := string(data) |
| 100 | cfg = &tmp |
| 101 | } |
| 102 | return i.transaction.Transaction(ctx, func(txCtx context.Context) error { |
| 103 | err := i.service.UpdateLogSource(txCtx, driver, &log.Save{ |
| 104 | ID: input.ID, |
| 105 | Cluster: &input.Cluster, |
| 106 | Config: cfg, |
| 107 | }) |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | info, err := i.service.GetLogSource(txCtx, driver) |
| 112 | if err != nil { |
| 113 | return err |
| 114 | } |
| 115 | d, c, err := factory.Create(info.Config) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | client, err := i.clusterService.GatewayClient(txCtx, input.Cluster) |
| 121 | if err != nil { |
| 122 | return err |
| 123 | } |
| 124 | defer client.Close(txCtx) |
| 125 | dynamicClient, err := client.Dynamic(driver) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | attr := make(map[string]interface{}) |
| 130 | attr["driver"] = driver |
| 131 | attr["formatter"] = logFormatter |
| 132 | attr["labels"] = labels |
| 133 | attr["method"] = "POST" |
| 134 | attr["scopes"] = []string{"access_log"} |
| 135 | attr["type"] = "json" |
| 136 | for k, v := range c { |
| 137 | attr[k] = v |
| 138 | } |
| 139 | err = dynamicClient.Online(txCtx, &gateway.DynamicRelease{ |
| 140 | BasicItem: &gateway.BasicItem{ |
| 141 | ID: driver, |
| 142 | Description: "collect access log", |
| 143 | Version: time.Now().Format("20060102150405"), |
| 144 | Resource: gateway.ProfessionOutput, |
| 145 | }, |
| 146 | Attr: attr, |
| 147 | }) |
nothing calls this directly
no test coverage detected