(cmd *cobra.Command, t, image, name, user string)
| 91 | } |
| 92 | |
| 93 | func createPlugin(cmd *cobra.Command, t, image, name, user string) error { |
| 94 | bodyBuf := &bytes.Buffer{} |
| 95 | bodyWriter := multipart.NewWriter(bodyBuf) |
| 96 | bodyWriter.WriteField("NAME", name) |
| 97 | switch t { |
| 98 | case "wasm": |
| 99 | bodyWriter.WriteField("TYPE", "1") |
| 100 | case "so": |
| 101 | bodyWriter.WriteField("TYPE", "2") |
| 102 | case "lua": |
| 103 | bodyWriter.WriteField("TYPE", "3") |
| 104 | default: |
| 105 | return errors.New(fmt.Sprintf("unknown type %s", t)) |
| 106 | } |
| 107 | switch user { |
| 108 | case "agent": |
| 109 | bodyWriter.WriteField("USER", "1") |
| 110 | case "server": |
| 111 | if !strings.HasSuffix(image, "lua") || t != "lua" { |
| 112 | return errors.New(fmt.Sprintf("if user is server, expected image: <filename>.lua, but got image: %s\n expected type: lua, but got type: %s ", image, t)) |
| 113 | } |
| 114 | bodyWriter.WriteField("USER", "2") |
| 115 | default: |
| 116 | return errors.New(fmt.Sprintf("unknown user %s", user)) |
| 117 | } |
| 118 | |
| 119 | fileWriter, err := bodyWriter.CreateFormFile("IMAGE", path.Base(image)) |
| 120 | f, err := os.Open(image) |
| 121 | if err != nil { |
| 122 | return err |
| 123 | } |
| 124 | defer f.Close() |
| 125 | if _, err = io.Copy(fileWriter, f); err != nil { |
| 126 | return err |
| 127 | } |
| 128 | contentType := bodyWriter.FormDataContentType() |
| 129 | bodyWriter.Close() |
| 130 | |
| 131 | server := common.GetServerInfo(cmd) |
| 132 | url := fmt.Sprintf("http://%s:%d/v1/plugin/", server.IP, server.Port) |
| 133 | _, err = common.CURLPostFormData(url, contentType, bodyBuf, []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...) |
| 134 | return err |
| 135 | } |
| 136 | |
| 137 | func listPlugin(cmd *cobra.Command) { |
| 138 | server := common.GetServerInfo(cmd) |
no test coverage detected