-
Notifications
You must be signed in to change notification settings - Fork 6
/
api_keys_figma_attachments.go
164 lines (130 loc) · 6 KB
/
api_keys_figma_attachments.go
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
package cmd
import (
"fmt"
"os"
"strings"
"github.com/antihax/optional"
helpers "github.com/phrase/phrase-cli/helpers"
api "github.com/phrase/phrase-go/v3"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
initFigmaAttachmentAttachToKey()
initFigmaAttachmentDetachFromKey()
rootCmd.AddCommand(KeysFigmaAttachmentsApiCmd)
}
var KeysFigmaAttachmentsApiCmd = &cobra.Command{
Use: helpers.ToSnakeCase("KeysFigmaAttachments"),
Short: "KeysFigmaAttachments API",
}
func initFigmaAttachmentAttachToKey() {
params := viper.New()
var use string
// this weird approach is due to mustache template limitations
use = strings.Join(strings.Split("figma_attachment/attach_to_key", "/")[1:], "_")
var FigmaAttachmentAttachToKey = &cobra.Command{
Use: use,
Short: "Attach the Figma attachment to a key",
Long: `Attach the Figma attachment to a key`,
Run: func(cmd *cobra.Command, args []string) {
auth := Auth()
cfg := api.NewConfiguration()
cfg.SetUserAgent(Config.UserAgent)
if Config.Credentials.Host != "" {
cfg.BasePath = Config.Credentials.Host
}
client := api.NewAPIClient(cfg)
localVarOptionals := api.FigmaAttachmentAttachToKeyOpts{}
if Config.Credentials.TFA && Config.Credentials.TFAToken != "" {
localVarOptionals.XPhraseAppOTP = optional.NewString(Config.Credentials.TFAToken)
}
projectId := params.GetString(helpers.ToSnakeCase("ProjectId"))
figmaAttachmentId := params.GetString(helpers.ToSnakeCase("FigmaAttachmentId"))
id := params.GetString(helpers.ToSnakeCase("Id"))
if params.IsSet(helpers.ToSnakeCase("xPhraseAppOTP")) {
localVarOptionals.XPhraseAppOTP = optional.NewString(params.GetString(helpers.ToSnakeCase("XPhraseAppOTP")))
}
if params.IsSet(helpers.ToSnakeCase("branch")) {
localVarOptionals.Branch = optional.NewString(params.GetString(helpers.ToSnakeCase("Branch")))
}
data, api_response, err := client.KeysFigmaAttachmentsApi.FigmaAttachmentAttachToKey(auth, projectId, figmaAttachmentId, id, &localVarOptionals)
if err != nil {
switch castedError := err.(type) {
case api.GenericOpenAPIError:
fmt.Printf("\n%s\n\n", string(castedError.Body()))
HandleError(castedError)
default:
HandleError(castedError)
}
} else if api_response.StatusCode >= 200 && api_response.StatusCode < 300 {
os.Stdout.Write(data)
if Config.Debug {
fmt.Printf("%+v\n", api_response) // &{Response:0xc00011ccf0 NextPage:2 FirstPage:1 LastPage:4 Rate:{Limit:1000 Remaining:998 Reset:2020-04-25 00:35:00 +0200 CEST}}
}
}
},
}
KeysFigmaAttachmentsApiCmd.AddCommand(FigmaAttachmentAttachToKey)
AddFlag(FigmaAttachmentAttachToKey, "string", helpers.ToSnakeCase("ProjectId"), "", "Project ID", true)
AddFlag(FigmaAttachmentAttachToKey, "string", helpers.ToSnakeCase("FigmaAttachmentId"), "", "Figma attachment ID", true)
AddFlag(FigmaAttachmentAttachToKey, "string", helpers.ToSnakeCase("Id"), "", "ID", true)
AddFlag(FigmaAttachmentAttachToKey, "string", helpers.ToSnakeCase("XPhraseAppOTP"), "", "Two-Factor-Authentication token (optional)", false)
AddFlag(FigmaAttachmentAttachToKey, "string", helpers.ToSnakeCase("Branch"), "", "specify the branch to use", false)
params.BindPFlags(FigmaAttachmentAttachToKey.Flags())
}
func initFigmaAttachmentDetachFromKey() {
params := viper.New()
var use string
// this weird approach is due to mustache template limitations
use = strings.Join(strings.Split("figma_attachment/detach_from_key", "/")[1:], "_")
var FigmaAttachmentDetachFromKey = &cobra.Command{
Use: use,
Short: "Detach the Figma attachment from a key",
Long: `Detach the Figma attachment from a key`,
Run: func(cmd *cobra.Command, args []string) {
auth := Auth()
cfg := api.NewConfiguration()
cfg.SetUserAgent(Config.UserAgent)
if Config.Credentials.Host != "" {
cfg.BasePath = Config.Credentials.Host
}
client := api.NewAPIClient(cfg)
localVarOptionals := api.FigmaAttachmentDetachFromKeyOpts{}
if Config.Credentials.TFA && Config.Credentials.TFAToken != "" {
localVarOptionals.XPhraseAppOTP = optional.NewString(Config.Credentials.TFAToken)
}
projectId := params.GetString(helpers.ToSnakeCase("ProjectId"))
figmaAttachmentId := params.GetString(helpers.ToSnakeCase("FigmaAttachmentId"))
id := params.GetString(helpers.ToSnakeCase("Id"))
if params.IsSet(helpers.ToSnakeCase("xPhraseAppOTP")) {
localVarOptionals.XPhraseAppOTP = optional.NewString(params.GetString(helpers.ToSnakeCase("XPhraseAppOTP")))
}
if params.IsSet(helpers.ToSnakeCase("branch")) {
localVarOptionals.Branch = optional.NewString(params.GetString(helpers.ToSnakeCase("Branch")))
}
data, api_response, err := client.KeysFigmaAttachmentsApi.FigmaAttachmentDetachFromKey(auth, projectId, figmaAttachmentId, id, &localVarOptionals)
if err != nil {
switch castedError := err.(type) {
case api.GenericOpenAPIError:
fmt.Printf("\n%s\n\n", string(castedError.Body()))
HandleError(castedError)
default:
HandleError(castedError)
}
} else if api_response.StatusCode >= 200 && api_response.StatusCode < 300 {
os.Stdout.Write(data)
if Config.Debug {
fmt.Printf("%+v\n", api_response) // &{Response:0xc00011ccf0 NextPage:2 FirstPage:1 LastPage:4 Rate:{Limit:1000 Remaining:998 Reset:2020-04-25 00:35:00 +0200 CEST}}
}
}
},
}
KeysFigmaAttachmentsApiCmd.AddCommand(FigmaAttachmentDetachFromKey)
AddFlag(FigmaAttachmentDetachFromKey, "string", helpers.ToSnakeCase("ProjectId"), "", "Project ID", true)
AddFlag(FigmaAttachmentDetachFromKey, "string", helpers.ToSnakeCase("FigmaAttachmentId"), "", "Figma attachment ID", true)
AddFlag(FigmaAttachmentDetachFromKey, "string", helpers.ToSnakeCase("Id"), "", "ID", true)
AddFlag(FigmaAttachmentDetachFromKey, "string", helpers.ToSnakeCase("XPhraseAppOTP"), "", "Two-Factor-Authentication token (optional)", false)
AddFlag(FigmaAttachmentDetachFromKey, "string", helpers.ToSnakeCase("Branch"), "", "specify the branch to use", false)
params.BindPFlags(FigmaAttachmentDetachFromKey.Flags())
}