|
1 | 1 | package kafka |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | | - "encoding/binary" |
6 | | - "encoding/json" |
7 | 4 | "fmt" |
8 | | - "io/ioutil" |
9 | | - "os" |
10 | | - "path/filepath" |
11 | | - "strconv" |
12 | 5 | "time" |
13 | 6 |
|
14 | 7 | ckafka "github.com/confluentinc/confluent-kafka-go/kafka" |
15 | | - srsdk "github.com/confluentinc/schema-registry-sdk-go" |
16 | 8 | "github.com/spf13/cobra" |
17 | 9 |
|
18 | 10 | pcmd "github.com/confluentinc/cli/internal/pkg/cmd" |
19 | 11 | v1 "github.com/confluentinc/cli/internal/pkg/config/v1" |
20 | 12 | "github.com/confluentinc/cli/internal/pkg/errors" |
21 | 13 | "github.com/confluentinc/cli/internal/pkg/log" |
22 | | - "github.com/confluentinc/cli/internal/pkg/output" |
23 | | - "github.com/confluentinc/cli/internal/pkg/utils" |
24 | 14 | ) |
25 | 15 |
|
26 | 16 | const ( |
@@ -161,87 +151,3 @@ func (c *hasAPIKeyTopicCommand) validateTopic(client *ckafka.AdminClient, topic |
161 | 151 | log.CliLogger.Tracef("validateTopic succeeded") |
162 | 152 | return nil |
163 | 153 | } |
164 | | - |
165 | | -func registerSchemaWithAuth(cmd *cobra.Command, subject, schemaType, schemaPath string, refs []srsdk.SchemaReference, srClient *srsdk.APIClient, ctx context.Context) ([]byte, error) { |
166 | | - schema, err := ioutil.ReadFile(schemaPath) |
167 | | - if err != nil { |
168 | | - return nil, err |
169 | | - } |
170 | | - |
171 | | - response, _, err := srClient.DefaultApi.Register(ctx, subject, srsdk.RegisterSchemaRequest{Schema: string(schema), SchemaType: schemaType, References: refs}) |
172 | | - if err != nil { |
173 | | - return nil, err |
174 | | - } |
175 | | - |
176 | | - outputFormat, err := cmd.Flags().GetString(output.FlagName) |
177 | | - if err != nil { |
178 | | - return nil, err |
179 | | - } |
180 | | - if outputFormat == output.Human.String() { |
181 | | - utils.Printf(cmd, errors.RegisteredSchemaMsg, response.Id) |
182 | | - } else { |
183 | | - err = output.StructuredOutput(outputFormat, &struct { |
184 | | - Id int32 `json:"id" yaml:"id"` |
185 | | - }{response.Id}) |
186 | | - if err != nil { |
187 | | - return nil, err |
188 | | - } |
189 | | - } |
190 | | - |
191 | | - metaInfo := []byte{0x0} |
192 | | - schemaIdBuffer := make([]byte, 4) |
193 | | - binary.BigEndian.PutUint32(schemaIdBuffer, uint32(response.Id)) |
194 | | - metaInfo = append(metaInfo, schemaIdBuffer...) |
195 | | - return metaInfo, nil |
196 | | -} |
197 | | - |
198 | | -func readSchemaRefs(cmd *cobra.Command) ([]srsdk.SchemaReference, error) { |
199 | | - var refs []srsdk.SchemaReference |
200 | | - refPath, err := cmd.Flags().GetString("refs") |
201 | | - if err != nil { |
202 | | - return nil, err |
203 | | - } |
204 | | - if refPath != "" { |
205 | | - refBlob, err := ioutil.ReadFile(refPath) |
206 | | - if err != nil { |
207 | | - return nil, err |
208 | | - } |
209 | | - err = json.Unmarshal(refBlob, &refs) |
210 | | - if err != nil { |
211 | | - return nil, err |
212 | | - } |
213 | | - } |
214 | | - return refs, nil |
215 | | -} |
216 | | - |
217 | | -func storeSchemaReferences(refs []srsdk.SchemaReference, srClient *srsdk.APIClient, ctx context.Context) (map[string]string, error) { |
218 | | - dir := filepath.Join(os.TempDir(), "ccloud-schema") |
219 | | - if _, err := os.Stat(dir); os.IsNotExist(err) { |
220 | | - err = os.Mkdir(dir, 0755) |
221 | | - if err != nil { |
222 | | - return nil, err |
223 | | - } |
224 | | - } |
225 | | - |
226 | | - referencePathMap := map[string]string{} |
227 | | - for _, ref := range refs { |
228 | | - tempStorePath := filepath.Join(dir, ref.Name) |
229 | | - if !fileExists(tempStorePath) { |
230 | | - schema, _, err := srClient.DefaultApi.GetSchemaByVersion(ctx, ref.Subject, strconv.Itoa(int(ref.Version)), &srsdk.GetSchemaByVersionOpts{}) |
231 | | - if err != nil { |
232 | | - return nil, err |
233 | | - } |
234 | | - err = os.MkdirAll(filepath.Dir(tempStorePath), 0755) |
235 | | - if err != nil { |
236 | | - return nil, err |
237 | | - } |
238 | | - err = ioutil.WriteFile(tempStorePath, []byte(schema.Schema), 0644) |
239 | | - if err != nil { |
240 | | - return nil, err |
241 | | - } |
242 | | - } |
243 | | - referencePathMap[ref.Name] = tempStorePath |
244 | | - } |
245 | | - |
246 | | - return referencePathMap, nil |
247 | | -} |
0 commit comments