• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

denvrdata / go-denvr / 12306392699

12 Dec 2024 11:11PM UTC coverage: 90.566%. First build
12306392699

Pull #1

github

web-flow
Merge f49b1922b into e33b21ad0
Pull Request #1: Initial structure

48 of 53 new or added lines in 2 files covered. (90.57%)

48 of 53 relevant lines covered (90.57%)

1.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/auth/auth.go
1
package auth
2

3
import (
4
        "bytes"
5
        "encoding/json"
6
        "fmt"
7
        "net/http"
8
        "time"
9

10
        "github.com/denvrdata/go-denvr/result"
11
)
12

13
type Auth struct {
14
        Server         string
15
        AccessToken    string
16
        RefreshToken   string
17
        AccessExpires  int64
18
        RefreshExpires int64
19
}
20

21
func NewAuth(server string, username string, password string) Auth {
1✔
22
        data := result.Wrap(
1✔
23
                json.Marshal(
1✔
24
                        map[string]string{
1✔
25
                                "userNameOrEmailAddress": username,
1✔
26
                                "password":               password,
1✔
27
                        },
1✔
28
                ),
1✔
29
        ).Unwrap()
1✔
30

1✔
31
        resp := result.Wrap(
1✔
32
                http.Post(
1✔
33
                        fmt.Sprintf("%s/api/TokenAuth/Authenticate", server),
1✔
34
                        "application/json",
1✔
35
                        bytes.NewBuffer(data),
1✔
36
                ),
1✔
37
        ).Unwrap()
1✔
38

1✔
39
        defer resp.Body.Close()
1✔
40

1✔
41
        // A bit ugly, but we'll define our specific response content to decode
1✔
42
        var content struct {
1✔
43
                Result struct {
1✔
44
                        AccessToken                 string `json:"accessToken"`
1✔
45
                        RefreshToken                string `json:"refreshToken"`
1✔
46
                        ExpireInSeconds             int64  `json:"expireInSeconds"`
1✔
47
                        RefreshTokenExpireInSeconds int64  `json:"refreshTokenExpireInSeconds"`
1✔
48
                } `json:"result"`
1✔
49
        }
1✔
50
        result.Wrap(content, json.NewDecoder(resp.Body).Decode(&content)).Unwrap()
1✔
51

1✔
52
        return Auth{
1✔
53
                server,
1✔
54
                content.Result.AccessToken,
1✔
55
                content.Result.RefreshToken,
1✔
56
                content.Result.ExpireInSeconds,
1✔
57
                content.Result.RefreshTokenExpireInSeconds,
1✔
58
        }
1✔
59
}
1✔
60

NEW
61
func (auth Auth) Token() {
×
NEW
62
        time.Now().Unix()
×
NEW
63
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc