Compare commits
2 Commits
4c3b736efb
...
ea97070fea
Author | SHA1 | Date | |
---|---|---|---|
ea97070fea | |||
dae9c1cf45 |
@ -182,6 +182,11 @@ func (u *User) UseConfig(config data.ConfigurationValueGetter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) ResolveId(ctx context.Context) string {
|
func (u *User) ResolveId(ctx context.Context) string {
|
||||||
|
if u.config != nil {
|
||||||
|
if configUser, configUserErr := u.config.GetValue("user"); configUserErr == nil && u.Name == "" {
|
||||||
|
u.Name = configUser.(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
return LookupUIDString(u.Name)
|
return LookupUIDString(u.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
_ "os"
|
_ "os"
|
||||||
_ "strings"
|
_ "strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"decl/internal/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewUserResource(t *testing.T) {
|
func TestNewUserResource(t *testing.T) {
|
||||||
@ -77,3 +78,22 @@ func TestCreateUser(t *testing.T) {
|
|||||||
applyDeleteErr := u.Apply()
|
applyDeleteErr := u.Apply()
|
||||||
assert.Equal(t, nil, applyDeleteErr)
|
assert.Equal(t, nil, applyDeleteErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSystemUser(t *testing.T) {
|
||||||
|
u := NewUser()
|
||||||
|
|
||||||
|
u.UseConfig(MockConfigValueGetter(func(key string) (any, error) {
|
||||||
|
switch key {
|
||||||
|
case "user":
|
||||||
|
return "bar", nil
|
||||||
|
case "group":
|
||||||
|
return "foo", nil
|
||||||
|
case "uid":
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("%w: %s", data.ErrUnknownConfigurationKey, key)
|
||||||
|
}))
|
||||||
|
|
||||||
|
u.ResolveId(context.Background())
|
||||||
|
assert.Equal(t, "bar", u.Name)
|
||||||
|
}
|
||||||
|
@ -91,6 +91,10 @@ func (h *HTTP) Stat() (info fs.FileInfo, err error) {
|
|||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
if response.StatusCode > 399 {
|
||||||
|
err = ErrTransportResourceAbsent
|
||||||
|
return
|
||||||
|
}
|
||||||
fi := NewHTTPFileInfo(uri)
|
fi := NewHTTPFileInfo(uri)
|
||||||
contentLength := response.Header.Get("Content-Length")
|
contentLength := response.Header.Get("Content-Length")
|
||||||
if contentLength != "" {
|
if contentLength != "" {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
package transport
|
package transport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "errors"
|
"errors"
|
||||||
_ "fmt"
|
_ "fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -15,6 +15,10 @@ _ "os"
|
|||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrTransportResourceAbsent error = errors.New("Transport resource is absent")
|
||||||
|
)
|
||||||
|
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
URI() *url.URL
|
URI() *url.URL
|
||||||
ContentType() string
|
ContentType() string
|
||||||
@ -162,11 +166,19 @@ func (r *Reader) AddHeader(name string, value string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) Status() string {
|
func (r *Reader) Status() string {
|
||||||
return r.handle.(*HTTPReader).GetResponse().Status
|
if httpReader, ok := r.handle.(*HTTPReader); ok {
|
||||||
|
return httpReader.GetResponse().Status
|
||||||
|
}
|
||||||
|
panic("Unable to get HTTP status from reader")
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) StatusCode() int {
|
func (r *Reader) StatusCode() int {
|
||||||
return r.handle.(*HTTPReader).GetResponse().StatusCode
|
if httpReader, ok := r.handle.(*HTTPReader); ok {
|
||||||
|
return httpReader.GetResponse().StatusCode
|
||||||
|
}
|
||||||
|
panic("Unable to get HTTP status code from reader")
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) Response() *http.Response {
|
func (r *Reader) Response() *http.Response {
|
||||||
|
Loading…
Reference in New Issue
Block a user