fixed bug where edge connect did not undoubleslashes url paths
Some checks failed
Go Tests / go-tests (push) Failing after 1m0s
Some checks failed
Go Tests / go-tests (push) Failing after 1m0s
This commit is contained in:
parent
ebd16d7c50
commit
94d7147953
2 changed files with 13 additions and 16 deletions
|
|
@ -10,7 +10,7 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
var ErrNotFound = fmt.Errorf("Not found!")
|
||||
var ErrResourceNotFound = fmt.Errorf("resource not found")
|
||||
|
||||
type EdgeConnect struct {
|
||||
BaseURL string
|
||||
|
|
@ -90,7 +90,7 @@ func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string)
|
|||
}
|
||||
|
||||
if responses.StatusCode == http.StatusNotFound {
|
||||
return App{}, fmt.Errorf("Error retrieving App: %w", ErrNotFound)
|
||||
return App{}, fmt.Errorf("Error retrieving App: %w", ErrResourceNotFound)
|
||||
}
|
||||
|
||||
if !responses.IsSuccessful() {
|
||||
|
|
@ -102,7 +102,7 @@ func (e *EdgeConnect) ShowApp(ctx context.Context, appkey AppKey, region string)
|
|||
return apps[0], nil
|
||||
}
|
||||
|
||||
return App{}, fmt.Errorf("could not find app with region/key: %s/%v", region, appkey)
|
||||
return App{}, fmt.Errorf("could not find app with region/key: %s/%v: %w", region, appkey, ErrResourceNotFound)
|
||||
}
|
||||
|
||||
func (e *EdgeConnect) ShowApps(ctx context.Context, appkey AppKey, region string) ([]App, error) {
|
||||
|
|
@ -192,7 +192,7 @@ func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanc
|
|||
}
|
||||
|
||||
if responses.StatusCode == http.StatusNotFound {
|
||||
return AppInstance{}, fmt.Errorf("Error retrieving AppInstance: %w", ErrNotFound)
|
||||
return AppInstance{}, fmt.Errorf("Error retrieving AppInstance: %w", ErrResourceNotFound)
|
||||
}
|
||||
|
||||
if !responses.IsSuccessful() {
|
||||
|
|
@ -204,7 +204,7 @@ func (e *EdgeConnect) ShowAppInstance(ctx context.Context, appinstkey AppInstanc
|
|||
return data[0], nil
|
||||
}
|
||||
|
||||
return AppInstance{}, fmt.Errorf("could not find app: %v", responses)
|
||||
return AppInstance{}, fmt.Errorf("could not find app instance: %v: %w", responses, ErrResourceNotFound)
|
||||
}
|
||||
|
||||
func (e *EdgeConnect) ShowAppInstances(ctx context.Context, appinstkey AppInstanceKey, region string) ([]AppInstance, error) {
|
||||
|
|
@ -256,14 +256,12 @@ func (e *EdgeConnect) DeleteAppInstance(ctx context.Context, appinstancekey AppI
|
|||
}
|
||||
|
||||
func call[T any](ctx context.Context, client *EdgeConnect, path string, body []byte) (Responses[T], error) {
|
||||
log.Printf("call(): trying %s\n", path)
|
||||
|
||||
token, err := client.RetrieveToken(ctx)
|
||||
if err != nil {
|
||||
return Responses[T]{}, err
|
||||
}
|
||||
|
||||
request, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/%s", client.BaseURL, path), bytes.NewBuffer(body))
|
||||
request, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s%s", client.BaseURL, path), bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return Responses[T]{}, err
|
||||
}
|
||||
|
|
@ -279,8 +277,7 @@ func call[T any](ctx context.Context, client *EdgeConnect, path string, body []b
|
|||
responses := Responses[T]{}
|
||||
responses.StatusCode = resp.StatusCode
|
||||
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
log.Printf("Error in call %s: %v", path, ErrNotFound)
|
||||
if responses.StatusCode == http.StatusNotFound {
|
||||
return responses, nil
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +294,7 @@ func call[T any](ctx context.Context, client *EdgeConnect, path string, body []b
|
|||
responses.Responses = append(responses.Responses, d)
|
||||
}
|
||||
|
||||
log.Printf("call(): %s resulting in %v and %v messages\n", path, resp.StatusCode, len(responses.Responses))
|
||||
log.Printf("call(): %s resulting in http status %v and %v messages\n", path, resp.StatusCode, len(responses.Responses))
|
||||
|
||||
return responses, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,10 +141,10 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
Name: instancename,
|
||||
Version: "0.0.1",
|
||||
}, a.cfg.Region)
|
||||
if err != nil && !errors.As(err, client.ErrNotFound) {
|
||||
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
|
||||
return params.ProviderInstance{}, err
|
||||
}
|
||||
if errors.As(err, client.ErrNotFound) {
|
||||
if errors.Is(err, client.ErrResourceNotFound) {
|
||||
err = a.client.CreateApp(ctx, client.NewAppInput{
|
||||
Region: a.cfg.Region,
|
||||
App: client.App{
|
||||
|
|
@ -175,10 +175,10 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
Name: instancename,
|
||||
CloudletKey: client.CloudletKey(a.cfg.CloudletKey),
|
||||
}, a.cfg.Region)
|
||||
if err != nil && !errors.As(err, client.ErrNotFound) {
|
||||
if err != nil && !errors.Is(err, client.ErrResourceNotFound) {
|
||||
return params.ProviderInstance{}, err
|
||||
}
|
||||
if errors.As(err, client.ErrNotFound) {
|
||||
if errors.Is(err, client.ErrResourceNotFound) {
|
||||
err = a.client.CreateAppInstance(ctx, client.NewAppInstanceInput{
|
||||
Region: a.cfg.Region,
|
||||
AppInst: client.AppInstance{
|
||||
|
|
@ -209,7 +209,7 @@ func (a *edgeConnectProvider) CreateInstance(ctx context.Context, bootstrapParam
|
|||
OSArch: params.Amd64,
|
||||
OSName: "lala",
|
||||
OSVersion: "lalatest",
|
||||
Status: params.InstanceCreating,
|
||||
Status: params.InstanceRunning,
|
||||
}
|
||||
|
||||
return instance, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue