-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefs.go
executable file
·123 lines (100 loc) · 3 KB
/
defs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// (c) Kamiar Bahri
package icannclient
import (
"net/http"
"os"
"time"
)
var mLastAuthenticationAttempt time.Time
const (
GET = "GET"
HEAD = "HEAD"
POST = "POST"
tokenFileName string = "token.dat"
linux string = "linux"
czdsAPIBasedURL string = "https://czds-api.icann.org"
czdsAPIDownloadLinksURL string = "https://czds-api.icann.org/czds/downloads/links"
authenticateBaseURL string = "https://account-api.icann.org/api/authenticate"
)
// configData is used to initialize variables
// from environment file.
type configData struct {
AppDataDir string
UserAgent string
IcannAccountUserName string
IcannAccountPassword string
ApprovedTLD []string
ZoneFileDir string
HoursToWaitBetweenDownloads int
}
// failedDownloadItem hold info on a filed download so that
// the download can be tried again; after other files
// are downloaded, since there is one download in-progress
// at a time.
type failedDownloadItem struct {
TLD string // com, net,...
DateTimeAborted time.Time
LocalFilePath string
DownloadURL string
AttempCount uint8 // 1 thru 3
StatusCode int
ErrTxt string
}
// IcannAPI defines the structure of the IIcannAPI interface.
type IcannAPI struct {
// AppDataDir is the directory (on the volume) that zone files will be downloaded to.
AppDataDir string
// UserAgent is required for all ICANN API calls; its format is:
// <name of you product> / <version> <comment about your product>
UserAgent string
// ICANN person account username.
UserName string
// Password is the ICANN person account password.
Password string
// ApprovedTLD is an array of TLDs e.g. com, net.
ApprovedTLD []string
// Authenticated is used by callers to get the status of the authentication.
Authenticated bool
// AccessToken is available to callers to use for Bearer in the Authorization header.
AccessToken JWT
// isDirty is used to mark the first-time use of the app; so that
// the 120 second wait is skipped when this app is first launched.
isDirty bool
HoursToWaitBetweenDownloads int
failedDownloadQueue []failedDownloadItem
}
type JWT struct {
Token string
DateTimeIssued time.Time
DateTimeExpires time.Time
}
type HTTPResult struct {
StatusCode int
Error error
ResponseBody []byte
ResponseHeaders http.Header
}
type IcannClient struct {
IcannAPI IIcannAPI
CzdsAPI ICzdsAPI
}
type autResult struct {
AccessToken string `json:"accessToken"`
Message string `json:"message"`
}
type ZoneFileStatus struct {
HTTPResult HTTPResult
OriginalFileName string // e.g. com.txt.gz
FileLength uint64
TLDType string // e.g. com
}
// TeeWriter defines the structure of the callback,
// to get status of the download in porgress.
type TeeWriter struct {
TotalDownloaded uint64
File *os.File
TempFilePath string
FileName string
TLDType string
StartTime time.Time
}