Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: juruen/rmapi
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.25
Choose a base ref
...
head repository: juruen/rmapi
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 9 files changed
  • 5 contributors

Commits on Mar 7, 2023

  1. Bump golang.org/x/image from 0.0.0-20200119044424-58c23975cae1 to 0.5.0

    Bumps [golang.org/x/image](https://github.com/golang/image) from 0.0.0-20200119044424-58c23975cae1 to 0.5.0.
    - [Release notes](https://github.com/golang/image/releases)
    - [Commits](https://github.com/golang/image/commits/v0.5.0)
    
    ---
    updated-dependencies:
    - dependency-name: golang.org/x/image
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <[email protected]>
    dependabot[bot] authored Mar 7, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    900ceb6 View commit details

Commits on Apr 12, 2023

  1. * Documents config.ConfigPath to be more clear

    * Adds a test for config.ConfigPath
    * Adds error handling for config.ConfigPath
    kevin-cantwell committed Apr 12, 2023
    Copy the full SHA
    1340691 View commit details

Commits on Apr 13, 2023

  1. Merge pull request #300 from kevin-cantwell/config-path

    Adds docs, tests, and error handling to config path logic
    juruen authored Apr 13, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    18a9fb8 View commit details

Commits on Jul 6, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9effdbe View commit details

Commits on Sep 22, 2023

  1. Merge pull request #306 from arachnegl/patch-1

    Update tutorial-print-macosx.md - Release 0.0.25
    ddvk authored Sep 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ad7836a View commit details
  2. Merge pull request #295 from juruen/dependabot/go_modules/golang.org/…

    …x/image-0.5.0
    
    Bump golang.org/x/image from 0.0.0-20200119044424-58c23975cae1 to 0.5.0
    ddvk authored Sep 22, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    dd4e63f View commit details

Commits on Dec 23, 2023

  1. Update README.md

    juruen authored Dec 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    cd0279e View commit details
  2. Update README.md

    juruen authored Dec 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4963a39 View commit details
  3. Update README.md

    juruen authored Dec 23, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fca8021 View commit details
Showing with 141 additions and 27 deletions.
  1. +2 −0 README.md
  2. +4 −1 api/auth.go
  3. +17 −14 config/config.go
  4. +86 −1 config/config_test.go
  5. +1 −1 docs/tutorial-print-macosx.md
  6. +2 −2 go.mod
  7. +23 −4 go.sum
  8. +4 −2 main.go
  9. +2 −2 model/auth.go
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rMAPI

*Note: rMAPI is effectiviely unmaintaied at this point, and this repo will be archived in the next few weeks. Please see [this discussion for more info](https://github.com/juruen/rmapi/discussions/313).*

[![Actions Status](https://github.com/juruen/rmapi/workflows/Go/badge.svg)](https://github.com/juruen/rmapi/actions)


5 changes: 4 additions & 1 deletion api/auth.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,10 @@ const (
)

func AuthHttpCtx(reAuth, nonInteractive bool) *transport.HttpClientCtx {
configPath := config.ConfigPath()
configPath, err := config.ConfigPath()
if err != nil {
log.Error.Fatal("failed to get config path")
}
authTokens := config.LoadTokens(configPath)
httpClientCtx := transport.CreateHttpClientCtx(authTokens)

31 changes: 17 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package config

import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"

"github.com/juruen/rmapi/log"
@@ -18,39 +18,42 @@ const (
configFileEnvVar = "RMAPI_CONFIG"
)

func ConfigPath() (config string) {
configFile, ok := os.LookupEnv(configFileEnvVar)
if ok {
return configFile
/*
ConfigPath returns the path to the config file. It will check the following in order:
- If the RMAPI_CONFIG environment variable is set, it will use that path.
- If a config file exists in the user's home dir as described by os.UserHomeDir, it will use that.
- Otherwise, it will use the XDG config dir, as described by os.UserConfigDir.
*/
func ConfigPath() (string, error) {
if config, ok := os.LookupEnv(configFileEnvVar); ok {
return config, nil
}

user, err := user.Current()
home, err := os.UserHomeDir()
if err != nil {
log.Error.Panicln("failed to get current user:", err)
return "", fmt.Errorf("failed to get current user: %w", err)
}

home := user.HomeDir
config = filepath.Join(home, defaultConfigFile)
config := filepath.Join(home, defaultConfigFile)

//return config in home if exists
if _, err := os.Stat(config); err == nil {
return
return config, nil
}

configDir, err := os.UserConfigDir()
if err != nil {
log.Warning.Println("cannot determine config dir, using HOME", err)
return
return config, nil
}

xdgConfigDir := filepath.Join(configDir, appName)
err = os.MkdirAll(xdgConfigDir, 0700)
if err != nil {
if err := os.MkdirAll(xdgConfigDir, 0700); err != nil {
log.Error.Panicln("cannot create config dir "+xdgConfigDir, err)
}
config = filepath.Join(xdgConfigDir, defaultConfigFileXDG)

return
return config, nil

}

87 changes: 86 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
@@ -4,14 +4,20 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"sync"
"testing"

"github.com/juruen/rmapi/model"
"github.com/stretchr/testify/assert"
)

func TestSaveLoadConfig(t *testing.T) {
tokens := model.AuthTokens{"foo", "bar"}
tokens := model.AuthTokens{
DeviceToken: "foo",
UserToken: "bar",
}

f, err := ioutil.TempFile("", "rmapitmp")

@@ -30,3 +36,82 @@ func TestSaveLoadConfig(t *testing.T) {
assert.Equal(t, "foo", savedTokens.DeviceToken)
assert.Equal(t, "bar", savedTokens.UserToken)
}

func TestConfigPath(t *testing.T) {
// let's not mess with the user's home dir
home := "HOME"
switch runtime.GOOS {
case "windows":
home = "USERPROFILE"
case "plan9":
home = "home"
}
if err := os.Setenv(home, os.TempDir()); err != nil {
t.Error(err)
}

tearDown := func() {
_ = os.Unsetenv(configFileEnvVar)
_ = os.Remove(filepath.Join(os.TempDir(), defaultConfigFile))
}

tests := []struct {
name string
setup func()
want string
wantErr bool
}{
{
name: "no home no env config exists",
setup: func() {},
want: func() string {
xdgConfigDir, err := os.UserConfigDir()
if err != nil {
t.Error(err)
}
xdgConfig := filepath.Join(xdgConfigDir, appName, defaultConfigFileXDG)
return xdgConfig
}(),
},
{
name: "home config exists",
setup: func() {
homeConfig := filepath.Join(os.TempDir(), defaultConfigFile)
if err := ioutil.WriteFile(homeConfig, []byte("test"), 0644); err != nil {
t.Error(err)
}
},
want: filepath.Join(os.TempDir(), defaultConfigFile),
},
{
name: "env config exists",
setup: func() {
if err := os.Setenv(configFileEnvVar, filepath.Join(os.TempDir(), "rmapi.yaml")); err != nil {
t.Error(err)
}
},
want: filepath.Join(os.TempDir(), "rmapi.yaml"),
},
}

// Can't allow parallel execution because of shared file state
wg := sync.WaitGroup{}
for _, tt := range tests {
wg.Add(1)
t.Run(tt.name, func(t *testing.T) {
defer wg.Done()
defer tearDown()
tt.setup()

got, err := ConfigPath()
if (err != nil) != tt.wantErr {
t.Errorf("ConfigPath() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("ConfigPath() = %v, want %v", got, tt.want)
}
})
wg.Wait()
}
}
2 changes: 1 addition & 1 deletion docs/tutorial-print-macosx.md
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ Use `terminal` or `iterm` to get a terminal to run commands from it.
Download `rmapi` with the following command:

```bash
curl -L https://github.com/juruen/rmapi/releases/download/v0.0.24/rmapi-macosx.zip -o rmapi.zip -o rmapi.zip
curl -L https://github.com/juruen/rmapi/releases/download/v0.0.25/rmapi-macosx.zip -o rmapi.zip
```

Alternatively, you can build it from sources.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ require (
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
golang.org/x/image v0.5.0 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/text v0.7.0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
27 changes: 23 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -53,13 +53,21 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/unidoc/unipdf/v3 v3.6.1 h1:T9bb9NkFRuv3EKFranrgyCBS4sFV9LKc20UvuDJxhCU=
github.com/unidoc/unipdf/v3 v3.6.1/go.mod h1:oB/vP2a5OJfA5Op0X26CFX1JC8yECO2w+f6pMO/zpoo=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 h1:5h3ngYt7+vXCDZCup/HkCQgW5XwmSvR/nA2JmJ0RErg=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -68,12 +76,23 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -21,11 +21,13 @@ func parseOfflineCommands(cmd []string) bool {

switch cmd[0] {
case "reset":
configFile := config.ConfigPath()
err := os.Remove(configFile)
configFile, err := config.ConfigPath()
if err != nil {
log.Error.Fatalln(err)
}
if err := os.Remove(configFile); err != nil {
log.Error.Fatalln(err)
}
return true
case "version":
fmt.Println(version.Version)
4 changes: 2 additions & 2 deletions model/auth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package model

type AuthTokens struct {
DeviceToken string
UserToken string
DeviceToken string `yaml:"devicetoken"`
UserToken string `yaml:"usertoken"`
}

type DeviceTokenRequest struct {