MCPcopy
hub / github.com/rclone/rclone / init

Function init

backend/sugarsync/sugarsync.go:74–189  ·  view source on GitHub ↗

Register with Fs

()

Source from the content-addressed store, hash-verified

72
73// Register with Fs
74func init() {
75 fs.Register(&fs.RegInfo{
76 Name: "sugarsync",
77 Description: "Sugarsync",
78 NewFs: NewFs,
79 Config: func(ctx context.Context, name string, m configmap.Mapper, config fs.ConfigIn) (*fs.ConfigOut, error) {
80 opt := new(Options)
81 err := configstruct.Set(m, opt)
82 if err != nil {
83 return nil, fmt.Errorf("failed to read options: %w", err)
84 }
85
86 switch config.State {
87 case "":
88 if opt.RefreshToken == "" {
89 return fs.ConfigGoto("username")
90 }
91 return fs.ConfigConfirm("refresh", true, "config_refresh", "Already have a token - refresh?")
92 case "refresh":
93 if config.Result == "false" {
94 return nil, nil
95 }
96 return fs.ConfigGoto("username")
97 case "username":
98 return fs.ConfigInput("password", "config_username", "username (email address)")
99 case "password":
100 m.Set("username", config.Result)
101 return fs.ConfigPassword("auth", "config_password", "Your Sugarsync password.\n\nOnly required during setup and will not be stored.")
102 case "auth":
103 username, _ := m.Get("username")
104 m.Set("username", "")
105 password := config.Result
106
107 authRequest := api.AppAuthorization{
108 Username: username,
109 Password: obscure.MustReveal(password),
110 Application: withDefault(opt.AppID, appID),
111 AccessKeyID: withDefault(opt.AccessKeyID, accessKeyID),
112 PrivateAccessKey: withDefault(opt.PrivateAccessKey, obscure.MustReveal(encryptedPrivateAccessKey)),
113 }
114
115 var resp *http.Response
116 opts := rest.Opts{
117 Method: "POST",
118 Path: "/app-authorization",
119 }
120 srv := rest.NewClient(fshttp.NewClient(ctx)).SetRoot(rootURL) // FIXME
121
122 // FIXME
123 // err = f.pacer.Call(func() (bool, error) {
124 resp, err = srv.CallXML(context.Background(), &opts, &authRequest, nil)
125 // return shouldRetry(ctx, resp, err)
126 //})
127 if err != nil {
128 return nil, fmt.Errorf("failed to get token: %w", err)
129 }
130 opt.RefreshToken = resp.Header.Get("Location")
131 m.Set("refresh_token", opt.RefreshToken)

Callers

nothing calls this directly

Calls 15

RegisterFunction · 0.92
SetFunction · 0.92
ConfigGotoFunction · 0.92
ConfigConfirmFunction · 0.92
ConfigInputFunction · 0.92
ConfigPasswordFunction · 0.92
MustRevealFunction · 0.92
NewClientFunction · 0.92
NewClientFunction · 0.92
withDefaultFunction · 0.85
SetRootMethod · 0.80
CallXMLMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…