Compare commits

..

4 commits

Author SHA1 Message Date
a00e34f7c3
checkpoint: continuiung writing the getting started guide 2024-06-29 20:33:50 +01:00
0509290e15
checkpoint: writing getting started guide 2024-06-29 16:08:13 +01:00
c75c5ad3b2
checkpoint: moved installation instructions to docs/install.md 2024-06-29 16:08:13 +01:00
b03b3c31cc
fix: set absolute path to the credentials file
When creating the configuration file during the initialisation process
calculate the absolute path to the credentials file instead of the
relative path.
2024-06-29 16:02:19 +01:00
8 changed files with 143 additions and 9 deletions

View file

@ -134,7 +134,7 @@ enbas show --type status --status-id 01HQE43KT5YEDN4RGMT7BC63PF
== Inspirations == Inspirations
This project was inspired from the following projects: This project was inspired by the following projects:
* **madonctl:** https://github.com/McKael/madonctl[A Mastodon CLI client written in Go.] * **madonctl:** https://github.com/McKael/madonctl[A Mastodon CLI client written in Go.]
* **toot:** https://pypi.org/project/toot/[A Mastodon CLI and TUI written in Python.] * **toot:** https://pypi.org/project/toot/[A Mastodon CLI and TUI written in Python.]

0
docs/changelog.md Normal file
View file

0
docs/cheatsheet.md Normal file
View file

96
docs/getting-started.md Normal file
View file

@ -0,0 +1,96 @@
# Getting Started
## Summary
In this guide we are going to log into an account on a private GoToSocial server.
Follow along to log into your own account.
## Your configuration directory
Enbas uses Go's [os.UserConfigDir()](https://pkg.go.dev/os#UserConfigDir) function to calculate the location of your configuration directory.
If you've set the `XDG_CONFIG_HOME` environment variable, the configuration directory will be set to `$XDG_CONFIG_HOME/enbas`.
If this is not set, then:
- on Linux the configuration directory will be set to `$HOME/.config/enbas`.
- on Darwin (MacOS) the configuration directory will be set to `$HOME/Library/Application Support/enbas`.
- on Windows the configuration directory will be set within the `%AppData%` directory.
Alternatively you can use the `--config-dir` global flag to specify your configuration directory.
## Generate your configuration file
Run the `init` command to generate your configuration file.
```bash
enbas init
```
Use the `--config-dir` flag if you want to generate it in a specific directory
```bash
enbas --config-dir config init
```
You should now see a file called `config.json` in your configuration directory.
Feel free to edit the file to your preferences (configuration documentation coming soon).
For this 'Getting Started' guide you may want to specify your preferred browser in the configuration to allow Enbas to open the link to your instance's authorisation page. If you prefer to open the link manually then you can leave it blank.
## Log into your GoToSocial account
Enbas uses the Oauth2 authentication flow to log into your account on GoToSocial.
```
[WARNING]
As of writing GoToSocial does not currently support scoped authorization tokens so even if we request read-only
tokens, the application will be able to perform any actions within the limitations of your account
(including admin actions if you are an admin).
You can read more about this https://docs.gotosocial.org/en/latest/api/authentication/[here].
```
Follow the below steps to log into your account:
1. Run the `login` command specifying the instance that you want to log into.
```
enbas login --instance gts.enbas-demo.private
```
2. Enbas will send a registration request to your instance and receive a new client ID and secret that it needs for authentication.
3. Enbas will then generate a link to the consent form for you to access in your browser and print it to your terminal screen along with a message explaining that you need to obtain the `out-of-band` token to continue.
The link will open in a tab in your preferred browser if you've specified it in your configuration, otherwise you can manually open it yourself.
If the browser tab doesn't open for you as expected you can still manually open it yourself.
4. Once you've signed into GoToSocial on your browser, you will be informed that Enbas would like to perform actions on your behalf.
If you're happy with this then click on the `Allow` button.
![A screenshot of the consent form](/assets/images/consent_form.png "Consent Form")
5. The `out-of-band` token from your instance will be displayed to you in your browser. Copy it and return to your terminal.
6. Paste the token into the prompt and press `ENTER`.
Enbas will then exchange the token for an access token which will be used to authentication to your instance on your behalf.
7. Enbas will then verify the access token, save the credentials to the `credentials.json` file in your configuration directory,
and inform you that you have successfully logged into your account.
```
$ enbas login --instance gotosocial-01.social.example
You'll need to sign into your GoToSocial's consent page in order to generate the out-of-band token to continue with
the application's login process. Your browser may have opened the link to the consent page already. If not, please
copy and paste the link below to your browser:
https://gotosocial-01.social.example/oauth/authorize?client_id=01RHK48N1KH9SFNH2VVZR414BJ&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code
Once you have the code please copy and paste it below.
Out-of-band token: ZGJKNDA2YWMTNGEYMS0ZZJLJLWJHNDITM2IZYJJLNJM3YJBK
Successfully logged into bobby@gotosocial-01.social.example
```
## View your account information

View file

@ -35,7 +35,7 @@ ENBAS_INSTALL_PREFIX=${HOME}/.local mage install
This will install Enbas to `~/.local/bin/enbas`. This will install Enbas to `~/.local/bin/enbas`.
===== Environment variables you can use with Mage The table below shows all the environment variables you can use when building with Mage.
| Environment Variable | Description | | Environment Variable | Description |
|--------------------------|------------------------------------------------------------------------------| |--------------------------|------------------------------------------------------------------------------|
@ -53,7 +53,7 @@ cd enbas
go install ./cmd/enbas go install ./cmd/enbas
``` ```
### Verify the installation ## Verify the installation
Type `enbas` from your terminal to verify that the installation was successful. You should see the help documentation. Type `enbas` from your terminal to verify that the installation was successful. You should see the help documentation.
@ -113,3 +113,5 @@ Git commit: c8892a6
Go version: go1.22.4 Go version: go1.22.4
Build date: 2024-06-28T21:57:37Z Build date: 2024-06-28T21:57:37Z
``` ```
Once you have completed the installation proceed to the [Getting Started guide](./getting-started.md).

View file

@ -71,7 +71,15 @@ func SaveDefaultConfigToFile(configDir string) error {
} }
defer file.Close() defer file.Close()
config := defaultConfig(configDir) config := defaultConfig()
credentialsFilePath, err := utilities.AbsolutePath(defaultCredentialsConfigFile(configDir))
if err != nil {
return fmt.Errorf("unable to calculate the path to the credentials file: %w", err)
}
config.CredentialsFile = credentialsFilePath
encoder := json.NewEncoder(file) encoder := json.NewEncoder(file)
encoder.SetIndent("", " ") encoder.SetIndent("", " ")
@ -86,11 +94,9 @@ func configFile(configDir string) string {
return filepath.Join(utilities.CalculateConfigDir(configDir), configFileName) return filepath.Join(utilities.CalculateConfigDir(configDir), configFileName)
} }
func defaultConfig(configDir string) Config { func defaultConfig() Config {
credentialsFilePath := defaultCredentialsConfigFile(configDir)
return Config{ return Config{
CredentialsFile: credentialsFilePath, CredentialsFile: "",
CacheDirectory: "", CacheDirectory: "",
HTTP: HTTPConfig{ HTTP: HTTPConfig{
Timeout: 5, Timeout: 5,

View file

@ -100,7 +100,7 @@ func (l *LoginExecutor) Execute() error {
return fmt.Errorf("unable to save the authentication details: %w", err) return fmt.Errorf("unable to save the authentication details: %w", err)
} }
l.printer.PrintSuccess("Successfully logged into " + loginName + ".") l.printer.PrintSuccess("You have successfully logged as " + loginName + ".")
return nil return nil
} }

View file

@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later
package utilities
import (
"fmt"
"os"
"path/filepath"
"strings"
)
func AbsolutePath(path string) (string, error) {
if strings.HasPrefix(path, "~") {
homeDir, err := os.UserHomeDir()
if err != nil {
return "", fmt.Errorf("unable to get user's home directory; %w", err)
}
path = filepath.Join(homeDir, path[1:])
}
absPath, err := filepath.Abs(path)
if err != nil {
return "", fmt.Errorf("unable to get the absolute path: %w", err)
}
return absPath, nil
}