-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcs.go
More file actions
318 lines (224 loc) · 11 KB
/
tcs.go
File metadata and controls
318 lines (224 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
package main
import (
"fmt"
"os"
"tcs-cli/cli"
"tcs-cli/telestream"
"gopkg.in/ini.v1"
)
const configFileName = ".tcs-credentials"
func createTtsProjectsCommands(client *telestream.TtsClient) []cli.CommandBaseInterface {
// projects list command
projectsListCmd := cli.NewCommand("list", client.ListProjects, "List all Projects")
// factories describe command
projectsDescribeCmd := cli.NewFlaggedCommand("describe", "project_id", client.DescribeProject,
client.GetDescribeProjectProperties(), "describes project by project_id")
// projects create command
projectsCreateCmd := cli.NewFlaggedCommand("create", "", client.CreateProject,
client.GetCreateProjectProperties(), "creates project")
// projects delete command
projectsDeleteCmd := cli.NewFlaggedCommand("delete", "project_id", client.DeleteProject,
client.GetDeleteProjectProperties(), "deletes project")
// projects update command
projectsUpdateCmd := cli.NewFlaggedCommand("update", "project_id", client.UpdateProject,
client.GetUpdateProjectProperties(), "updates project")
return []cli.CommandBaseInterface{projectsListCmd, projectsDescribeCmd, projectsCreateCmd,
projectsDeleteCmd, projectsUpdateCmd}
}
func createTtsJobsCommands(client *telestream.TtsClient) []cli.CommandBaseInterface {
// jobs list command
jobsListCmd := cli.NewFlaggedCommand("list", "", client.ListJobs,
client.GetListJobsProperties(), "List all jobs")
// jobs create command
jobsCreateCmd := cli.NewFlaggedCommand("create", "", client.CreateJob,
client.GetCreateJobProperties(), "Create job")
// jobs describe command
jobsDescribeCmd := cli.NewFlaggedCommand("describe", "job_id", client.DescribeJob,
client.GetDescribeJobProperties(), "Describe job")
// jobs delete command
jobsDeleteCmd := cli.NewFlaggedCommand("delete", "job_id", client.DeleteJob,
client.GetDeleteJobProperties(), "Delete job")
// jobs result command
jobsJobResultCmd := cli.NewFlaggedCommand("result", "job_id", client.JobResult,
client.GetJobResultProperties(), "Describe job result")
// jobs outputs command
jobsJobOutputsCmd := cli.NewFlaggedCommand("outputs", "job_id", client.JobOutputs,
client.GetJobOutputsProperties(), "Describe job outputs")
return []cli.CommandBaseInterface{jobsListCmd, jobsCreateCmd, jobsDescribeCmd, jobsDeleteCmd,
jobsJobResultCmd, jobsJobOutputsCmd}
}
func createTtsCorporaCommands(client *telestream.TtsClient) []cli.CommandBaseInterface {
// corpora list command
corporaListCmd := cli.NewFlaggedCommand("list", "", client.ListCorpora, client.GetListCorporaProperties(),
"List all corpora")
// corpora describe command
corporaDescribeCmd := cli.NewFlaggedCommand("describe", "corpus_name", client.DescribeCorpus,
client.GetDescribeCorpusProperties(), "describes corpus by project_id and corpus name")
// corpora create command
corporaCreateCmd := cli.NewFlaggedCommand("create", "", client.CreateCorpus,
client.GetCreateCorpusProperties(), "creates corpus")
// corpora delete command
corporaDeleteCmd := cli.NewFlaggedCommand("delete", "corpus_name", client.DeleteCorpus,
client.GetDeleteCorpusProperties(), "deletes corpus")
return []cli.CommandBaseInterface{corporaListCmd, corporaDescribeCmd, corporaCreateCmd,
corporaDeleteCmd}
}
func createTtsCommands(client *telestream.TtsClient) []cli.CommandBaseInterface {
// projects subcommand
projectsCmd := cli.NewSubCommand("projects", createTtsProjectsCommands(client),
"manage Telesteam cloud tts service projects")
// jobs subcommand
jobsCmd := cli.NewSubCommand("jobs", createTtsJobsCommands(client),
"manage Telesteam cloud tts service jobs")
// corpora subcommand
corporaCmd := cli.NewSubCommand("corpora", createTtsCorporaCommands(client),
"manage Telestream cloud tts service corpora")
// tts subcommand
flipCmd := cli.NewSubCommand("tts", []cli.CommandBaseInterface{projectsCmd, jobsCmd, corporaCmd},
"manage your tts service")
return []cli.CommandBaseInterface{flipCmd}
}
func createFactoriesCommands(client *telestream.FlipClient) []cli.CommandBaseInterface {
// factories list command
factoriesListCmd := cli.NewFlaggedCommand("list", "", client.ListFactories, client.GetListFactoriesProperties(),
"List all factories")
// factories describe command
factoriesDescribeCmd := cli.NewFlaggedCommand("describe", "factory_id", client.DescribeFactory,
client.GetDescribeFactoryProperties(), "describes factory by factory_id")
return []cli.CommandBaseInterface{factoriesListCmd, factoriesDescribeCmd}
}
func createProfilesCommands(client *telestream.FlipClient) []cli.CommandBaseInterface {
// profiles list command
profilesListCmd := cli.NewFlaggedCommand("list", "", client.ListProfiles,
client.GetListProfilesProperties(), "lists profiles by factory_id")
// profiles describe command
profilesDescribeByNameCmd := cli.NewFlaggedCommand("describe", "profile_id", client.DescribeProfile,
client.GetDescribeProfileProperties(), "describes profile by factory_id and its name or id")
// profiles create createcommand
profilesCreateCmd := cli.NewFlaggedCommand("create", "", client.CreateProfile,
client.GetCreateProfileProperties(), "creates profile")
// profiles delete createcommand
profilesDeleteCmd := cli.NewFlaggedCommand("delete", "profile_id", client.DeleteProfile,
client.GetDeleteProfileProperties(), "deletes profile")
// profiles update createcommand
profilesUpdateCmd := cli.NewFlaggedCommand("update", "profile_id", client.UpdateProfile,
client.GetUpdateProfileProperties(), "updates profile")
return []cli.CommandBaseInterface{profilesListCmd, profilesDescribeByNameCmd,
profilesCreateCmd, profilesDeleteCmd, profilesUpdateCmd}
}
func createVideosCommands(client *telestream.FlipClient) []cli.CommandBaseInterface {
// videos list command
videosListCmd := cli.NewFlaggedCommand("list", "", client.ListVideos,
client.GetListVideosProperties(), "lists videos by factory_id")
// videos describe command
videosDescribeCmd := cli.NewFlaggedCommand("describe", "video_id", client.DescribeVideo,
client.GetDescribeVideoProperties(), "describes videos by factory_id and its id")
// videos create command
videosCreateCmd := cli.NewFlaggedCommand("create", "", client.CreateVideo,
client.GetCreateVideoProperties(), "creates video")
// videos cancel command
videosCancelCmd := cli.NewFlaggedCommand("cancel", "video_id", client.CancelVideo,
client.GetCancelVideoProperties(), "cancels video")
// videos delete command
videosDeleteCmd := cli.NewFlaggedCommand("delete", "video_id", client.DeleteVideo,
client.GetDeleteVideoProperties(), "deletes video")
return []cli.CommandBaseInterface{videosListCmd, videosDescribeCmd, videosCreateCmd,
videosCancelCmd, videosDeleteCmd}
}
func createEncodingsCommands(client *telestream.FlipClient) []cli.CommandBaseInterface {
// encodings list command
encodingsListCmd := cli.NewFlaggedCommand("list", "", client.ListEncodings,
client.GetListEncodingsProperties(), "lists all encodings")
// encodings describe command
encodingsDescribeCmd := cli.NewFlaggedCommand("describe", "encoding_id", client.DescribeEncoding,
client.GetDescribeEncodingProperties(), "describes encoding by factory_id and its id")
// encodings cancel command
cancelDescribeCmd := cli.NewFlaggedCommand("cancel", "encoding_id", client.CancelEncoding,
client.GetCancelEncodingProperties(), "cancels encoding by factory_id and encoding id")
// encodings signed-urls command
signedUrlsDescribeCmd := cli.NewFlaggedCommand("signed-urls", "encoding_id", client.SignedUrlsEncoding,
client.GetSignedUrlsEncodingProperties(), "signed-urls by factory_id and encoding id")
// encodings delete command
deleteDescribeCmd := cli.NewFlaggedCommand("delete", "encoding_id", client.DeleteEncoding,
client.GetDeleteEncodingProperties(), "deletes encoding by factory_id and encoding id")
return []cli.CommandBaseInterface{encodingsListCmd, encodingsDescribeCmd, cancelDescribeCmd,
signedUrlsDescribeCmd, deleteDescribeCmd}
}
func createFlipCommands(client *telestream.FlipClient) []cli.CommandBaseInterface {
// factories subcommand
factoriesCmd := cli.NewSubCommand("factories", createFactoriesCommands(client),
"manage Telesteam cloud service factories")
// profiles subcommand
profilesCmd := cli.NewSubCommand("profiles", createProfilesCommands(client),
"manage Telesteam cloud service profiles")
// videos subcommand
videosCmd := cli.NewSubCommand("videos", createVideosCommands(client),
"menage Telestream cloud service videos")
// encodings subcommand
encodingsCmd := cli.NewSubCommand("encodings", createEncodingsCommands(client),
"menage Telestream cloud service encodings")
// flip subcommand
flipCmd := cli.NewSubCommand("flip", []cli.CommandBaseInterface{factoriesCmd, profilesCmd, videosCmd, encodingsCmd},
"manage your flip service")
return []cli.CommandBaseInterface{flipCmd}
}
func createConfig(argsMap cli.FlagMap) {
key := *argsMap["api_key"].Value
var home string
var err error
if home, err = os.UserHomeDir(); err != nil {
fmt.Println("Cannot get home directory: ", err.Error())
return
}
configFilePath := home + "/" + configFileName
os.Remove(configFilePath)
cfg := ini.Empty()
cfg.Section("default").Key("api_key").SetValue(key)
if _, err = os.Create(configFilePath); err != nil {
fmt.Println("Cannot create configuration file: ", err.Error())
return
}
if err = cfg.SaveTo(configFilePath); err != nil {
fmt.Println("Cannot save configuration file: ", err.Error())
return
}
fmt.Println("Credentials saved")
}
func readConfig() string {
var home string
var err error
if home, err = os.UserHomeDir(); err != nil {
fmt.Println("Cannot get home directory: ", err.Error())
return ""
}
cfg, err := ini.Load(home + "/" + configFileName)
if err != nil {
return ""
}
return cfg.Section("default").Key("api_key").String()
}
func createTcsCli() {
configureCmdStr := "configure"
apiKey := readConfig()
if apiKey == "" && len(os.Args) > 1 && os.Args[1] != configureCmdStr {
fmt.Println("Firstly you should configure credentials")
return
}
argvOutput := os.Args
var flags map[string]*string
argvOutput, flags = cli.GetAdditionalFlags(os.Args, map[string]string{"header_key": "additive http header key",
"header_val": "additive http header val"})
additionalHeaderKey := *flags["header_key"]
additionalHeaderVal := *flags["header_val"]
flipClient := telestream.NewFlipClient(apiKey, additionalHeaderKey, additionalHeaderVal, telestream.ServiceToStdOut)
ttsClient := telestream.NewTtsClient(apiKey, additionalHeaderKey, additionalHeaderVal, telestream.ServiceToStdOut)
// configure command
configureCmd := cli.NewFlaggedCommand(configureCmdStr, "api_key", createConfig, map[string]bool{"api_key": true},
"create configuration file for tsc command line tool with credentials that are used to interact with telestream cloud API")
commands := createFlipCommands(flipClient)
commands = append(commands, createTtsCommands(ttsClient)[0])
commands = append(commands, configureCmd)
cmdHndl := cli.NewCommandHandler("tcs", commands, map[string]string{"header_key": "additive http header key",
"header_val": "additive http header value"})
cmdHndl.ParseArgs(argvOutput)
}