This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* manualy editing for github action * manualy editing for github action * bugfix * get token on start * move getAlleroToken call to init * refactor * add TODO * move endpoint to prod * CR fixes
- Loading branch information
Showing
8 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package alleroBackendClient | ||
|
||
import ( | ||
"github.com/allero-io/allero/pkg/configurationManager" | ||
"github.com/allero-io/allero/pkg/httpClient" | ||
) | ||
|
||
type AlleroBackendClientDeps struct { | ||
HttpClient *httpClient.HttpClient | ||
ConfigurationManager *configurationManager.ConfigurationManager | ||
} | ||
|
||
type AlleroBackendClient struct { | ||
httpClient *httpClient.HttpClient | ||
configurationManager *configurationManager.ConfigurationManager | ||
AlleroToken string | ||
} | ||
|
||
func New(deps *AlleroBackendClientDeps) (*AlleroBackendClient, error) { | ||
alleroToken, err := getAlleroToken(deps.HttpClient, deps.ConfigurationManager) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &AlleroBackendClient{ | ||
httpClient: deps.HttpClient, | ||
configurationManager: deps.ConfigurationManager, | ||
AlleroToken: alleroToken, | ||
}, nil | ||
} | ||
|
||
func getAlleroToken(hc *httpClient.HttpClient, cm *configurationManager.ConfigurationManager) (string, error) { | ||
userConfig, _, err := cm.GetUserConfig() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if userConfig.AlleroToken == "" { | ||
// TODO OY replace | ||
// respBody, err := c.HttpClient.Get("token") | ||
respBody, err := hc.Get("") | ||
if err != nil { | ||
return "", err | ||
} | ||
userConfig.AlleroToken = string(respBody) | ||
err = cm.UpdateUserConfig(userConfig) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
} | ||
return userConfig.AlleroToken, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package configurationManager | ||
|
||
type UserConfig struct { | ||
MachineId string `json:"machine_id"` | ||
MachineId string `json:"machine_id"` | ||
AlleroToken string `json:"allero_token"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package httpClient | ||
|
||
import ( | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
type HttpClient struct { | ||
baseUrl string | ||
} | ||
|
||
func New() (*HttpClient, error) { | ||
return &HttpClient{ | ||
// TODO OY replace | ||
baseUrl: "https://api-service-prod-goxe6bbhaa-uc.a.run.app", | ||
}, nil | ||
} | ||
|
||
func (c *HttpClient) Get(relativeUrl string) ([]byte, error) { | ||
var url string | ||
if relativeUrl == "" { | ||
url = c.baseUrl | ||
} else { | ||
url = c.baseUrl + "/" + relativeUrl | ||
} | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
return ioutil.ReadAll(resp.Body) | ||
} |