Skip to content

Commit

Permalink
Merge pull request #63 from BenB196/staging
Browse files Browse the repository at this point in the history
Fix API changes and bump Golang Version
  • Loading branch information
BenB196 authored May 2, 2022
2 parents d7277ce + 0b5b362 commit 72ca641
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.7
0.4.8
17 changes: 8 additions & 9 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (

// Code42 Auth

//Structs of Crashplan FFS API Authentication Token Return
// AuthData Structs of Crashplan FFS API Authentication Token Return
type AuthData struct {
Data AuthToken `json:"data"`
Error string `json:"error,omitempty"`
Warnings string `json:"warnings,omitempty"`
}
type AuthToken struct {
V3UserToken string `json:"v3_user_token"`
AccessToken string `json:"access_token"`
Error string `json:"error,omitempty"`
Warnings string `json:"warnings,omitempty"`
TokenType string `json:"token_type,omitempty"`
ExpiresIn *int `json:"expires_in,omitempty"`
}

/*
Expand All @@ -26,7 +25,7 @@ The authentication token is good for up to 1 hour before it expires
*/
func GetAuthData(uri string, username string, password string) (*AuthData, error) {
//Build HTTP GET request
req, err := http.NewRequest("GET", uri, nil)
req, err := http.NewRequest("POST", uri, nil)

//Return nil and err if Building of HTTP GET request fails
if err != nil {
Expand Down Expand Up @@ -74,4 +73,4 @@ func GetAuthData(uri string, username string, password string) (*AuthData, error

//Return AuthData
return &authData, nil
}
}
4 changes: 2 additions & 2 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ func TestGetAuthData(t *testing.T) {
}

log.Println("Warnings: " + authData.Warnings)
log.Println("Auth Token: " + authData.Data.V3UserToken)
}
log.Println("Auth Token: " + authData.AccessToken)
}
8 changes: 4 additions & 4 deletions csvExport.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func GetCsvFileEvents(authData AuthData, ffsURI string, query Query) (*[]CsvFile
}

//Make sure authData token is not ""
if authData.Data.V3UserToken == "" {
if authData.AccessToken == "" {
return nil, errors.New("authData cannot be nil")
}

Expand All @@ -531,7 +531,7 @@ func GetCsvFileEvents(authData AuthData, ffsURI string, query Query) (*[]CsvFile

//Set request headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "v3_user_token "+authData.Data.V3UserToken)
req.Header.Set("Authorization", "Bearer "+authData.AccessToken)

//Get Response
resp, err := http.DefaultClient.Do(req)
Expand Down Expand Up @@ -601,7 +601,7 @@ func equal(slice1 []string, slice2 []string) error {

//loop through slices to check values
for i, v := range slice1 {
if i == len(slice1) - 1 {
if i == len(slice1)-1 {
//if last element in slice1, remove potential eol char
v = strings.Replace(v, "\r\n", "", -1)
v = strings.Replace(v, "\r", "", -1)
Expand Down Expand Up @@ -636,4 +636,4 @@ func equal(slice1 []string, slice2 []string) error {
}

return nil
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/BenB196/crashplan-ffs-go-pkg

go 1.15
go 1.18

require github.com/spkg/bom v1.0.0
4 changes: 2 additions & 2 deletions jsonExport.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func GetJsonFileEvents(authData AuthData, ffsURI string, query Query, pgToken st
}

//Make sure authData token is not ""
if authData.Data.V3UserToken == "" {
if authData.AccessToken == "" {
return nil, "", errors.New("authData cannot be nil")
}

Expand All @@ -146,7 +146,7 @@ func GetJsonFileEvents(authData AuthData, ffsURI string, query Query, pgToken st

//Set request headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "v3_user_token "+authData.Data.V3UserToken)
req.Header.Set("Authorization", "Bearer "+authData.AccessToken)

//Get Response
resp, err := http.DefaultClient.Do(req)
Expand Down
2 changes: 1 addition & 1 deletion jsonExport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestGetJsonFileEvents(t *testing.T) {
}

log.Println("Warnings: " + authData.Warnings)
log.Println("Auth Token: " + authData.Data.V3UserToken)
log.Println("Auth Token: " + authData.AccessToken)

jsonFileEvents, nextPgToken, err := GetJsonFileEvents(*authData, ffsUri, jsonQuery, "", true)

Expand Down

0 comments on commit 72ca641

Please sign in to comment.