| 204 | } |
| 205 | |
| 206 | func initDbx(cmd *cobra.Command, args []string) (err error) { |
| 207 | currentAuthContext = nil |
| 208 | |
| 209 | if err := initCommandContext(cmd); err != nil { |
| 210 | return err |
| 211 | } |
| 212 | |
| 213 | if commandIsJSONHelp(cmd) { |
| 214 | return nil |
| 215 | } |
| 216 | if err := validateOutputFormat(cmd); err != nil { |
| 217 | return err |
| 218 | } |
| 219 | |
| 220 | if commandSkipsAuth(cmd) { |
| 221 | return nil |
| 222 | } |
| 223 | |
| 224 | verbose, _ := cmd.Flags().GetBool("verbose") |
| 225 | asMember, _ := cmd.Flags().GetString("as-member") |
| 226 | domain, _ := cmd.Flags().GetString("domain") |
| 227 | |
| 228 | if accessToken := os.Getenv(envAccessToken); accessToken != "" { |
| 229 | config = makeDropboxConfig(accessToken, verbose, asMember, domain) |
| 230 | currentAuthContext = &authContext{ |
| 231 | Source: authSourceEnv, |
| 232 | Refreshable: false, |
| 233 | AuthFile: authFileNone, |
| 234 | } |
| 235 | config = withRootNamespace(config, tokenType(cmd)) |
| 236 | return nil |
| 237 | } |
| 238 | |
| 239 | tokType := tokenType(cmd) |
| 240 | credential, _, err := getAccessCredential(tokType, domain, false) |
| 241 | if err != nil { |
| 242 | return err |
| 243 | } |
| 244 | |
| 245 | config = makeDropboxConfig(credential.AccessToken, verbose, asMember, domain) |
| 246 | currentAuthContext = &authContext{ |
| 247 | Source: authSourceSaved, |
| 248 | Refreshable: credential.RefreshToken != "", |
| 249 | AuthFile: authFileKind(), |
| 250 | } |
| 251 | config = withRootNamespace(config, tokType) |
| 252 | |
| 253 | return |
| 254 | } |
| 255 | |
| 256 | func withRootNamespace(cfg dropbox.Config, tokType string) dropbox.Config { |
| 257 | // Team manage tokens are for administrative operations and don't need a path root. |