Skip to content

Commit

Permalink
feat: remove auth (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed May 17, 2024
1 parent 6781b34 commit 584f02c
Show file tree
Hide file tree
Showing 19 changed files with 9 additions and 467 deletions.
7 changes: 0 additions & 7 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,6 @@ checks:
postage-depth: 17
postage-topup-amount: 100
postage-new-depth: 18
authenticate:
type: authenticate
timeout: 5m
options:
role: consumer
admin-password: test
restricted-group-name: restricted
stake:
type: stake
timeout: 5m
Expand Down
7 changes: 0 additions & 7 deletions config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,6 @@ checks:
postage-depth: 17
postage-topup-amount: 100
postage-new-depth: 18
ci-authenticate:
type: authenticate
timeout: 5m
options:
role: consumer
admin-password: test
restricted-group-name: restricted
ci-stake:
type: stake
timeout: 5m
Expand Down
30 changes: 0 additions & 30 deletions pkg/bee/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var userAgent = "beekeeper/" + beekeeper.Version
type Client struct {
httpClient *http.Client // HTTP client must handle authentication implicitly.
service service // Reuse a single struct instead of allocating one for each service on the heap.
restricted bool

// Services that API provides.
Bytes *BytesService
Expand All @@ -43,13 +42,11 @@ type Client struct {
PSS *PSSService
SOC *SOCService
Stewardship *StewardshipService
Auth *AuthService
}

// ClientOptions holds optional parameters for the Client.
type ClientOptions struct {
HTTPClient *http.Client
Restricted bool
}

// NewClient constructs a new Client.
Expand All @@ -62,8 +59,6 @@ func NewClient(baseURL *url.URL, o *ClientOptions) (c *Client) {
}

c = newClient(httpClientWithTransport(baseURL, o.HTTPClient))
c.restricted = o.Restricted

return
}

Expand All @@ -81,7 +76,6 @@ func newClient(httpClient *http.Client) (c *Client) {
c.PSS = (*PSSService)(&c.service)
c.SOC = (*SOCService)(&c.service)
c.Stewardship = (*StewardshipService)(&c.service)
c.Auth = (*AuthService)(&c.service)
return c
}

Expand Down Expand Up @@ -140,14 +134,6 @@ func (c *Client) request(ctx context.Context, method, path string, body io.Reade
}
req.Header.Set("Accept", contentType)

if c.restricted && req.Header.Get("Authorization") == "" {
key, err := GetToken(path, method)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
}

r, err := c.httpClient.Do(req)
if err != nil {
return err
Expand Down Expand Up @@ -186,14 +172,6 @@ func (c *Client) requestData(ctx context.Context, method, path string, body io.R
}
req.Header.Set("Accept", contentType)

if c.restricted && req.Header.Get("Authorization") == "" {
key, err := GetToken(path, method)
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+key)
}

if opts != nil && opts.Cache != nil {
req.Header.Set(swarmCacheDownloadHeader, strconv.FormatBool(*opts.Cache))
}
Expand Down Expand Up @@ -224,14 +202,6 @@ func (c *Client) requestWithHeader(ctx context.Context, method, path string, hea
req.Header = header
req.Header.Add("Accept", contentType)

if c.restricted && req.Header.Get("Authorization") == "" {
key, err := GetToken(path, method)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
}

r, err := c.httpClient.Do(req)
if err != nil {
return err
Expand Down
175 changes: 0 additions & 175 deletions pkg/bee/api/auth.go

This file was deleted.

27 changes: 0 additions & 27 deletions pkg/bee/api/auth_test.go

This file was deleted.

17 changes: 2 additions & 15 deletions pkg/bee/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type ClientOptions struct {
DebugAPIURL *url.URL
DebugAPIInsecureTLS bool
Retry int
Restricted bool
}

// NewClient returns Bee client
Expand All @@ -53,12 +52,12 @@ func NewClient(opts ClientOptions, log logging.Logger) (c *Client) {
if opts.APIURL != nil {
c.api = api.NewClient(opts.APIURL, &api.ClientOptions{HTTPClient: &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: opts.APIInsecureTLS},
}}, Restricted: opts.Restricted})
}}})
}
if opts.DebugAPIURL != nil {
c.debug = debugapi.NewClient(opts.DebugAPIURL, &debugapi.ClientOptions{HTTPClient: &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: opts.DebugAPIInsecureTLS},
}}, Restricted: opts.Restricted})
}}})
}
if opts.Retry > 0 {
c.retry = opts.Retry
Expand Down Expand Up @@ -822,18 +821,6 @@ func (c *Client) Reupload(ctx context.Context, ref swarm.Address) error {
return c.api.Stewardship.Reupload(ctx, ref)
}

// Authenticate
func (c *Client) Authenticate(ctx context.Context, role, password string) (string, error) {
resp, err := c.api.Auth.Authenticate(ctx, role, password)
return resp, err
}

// Refresh
func (c *Client) Refresh(ctx context.Context, securityToken string) (string, error) {
resp, err := c.api.Auth.Refresh(ctx, securityToken)
return resp, err
}

// DepositStake deposits stake
func (c *Client) DepositStake(ctx context.Context, amount *big.Int) (string, error) {
return c.debug.Stake.DepositStake(ctx, amount)
Expand Down
Loading

0 comments on commit 584f02c

Please sign in to comment.