fix(ws): Get raw workspace yaml
Signed-off-by: mohamedch7 <121046693+mohamedch7@users.noreply.github.com>
This commit is contained in:
parent
d5dda0a8cd
commit
d1ae418733
|
|
@ -17,18 +17,17 @@ limitations under the License.
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories/workspaces"
|
"github.com/kubeflow/notebooks/workspaces/backend/internal/repositories/workspaces"
|
||||||
|
|
||||||
"sigs.k8s.io/yaml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WorkspaceYAMLEnvelope wraps the YAML string response
|
||||||
type WorkspaceYAMLEnvelope struct {
|
type WorkspaceYAMLEnvelope struct {
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +41,7 @@ func (a *App) GetWorkspaceYAMLHandler(w http.ResponseWriter, r *http.Request, ps
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace, err := a.repositories.Workspace.GetWorkspace(r.Context(), namespace, workspaceName)
|
rawWorkspace, err := a.repositories.Workspace.GetRawWorkspace(r.Context(), namespace, workspaceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, workspaces.ErrWorkspaceNotFound) {
|
if errors.Is(err, workspaces.ErrWorkspaceNotFound) {
|
||||||
a.notFoundResponse(w, r)
|
a.notFoundResponse(w, r)
|
||||||
|
|
@ -52,7 +51,7 @@ func (a *App) GetWorkspaceYAMLHandler(w http.ResponseWriter, r *http.Request, ps
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlBytes, err := yaml.Marshal(workspace)
|
yamlBytes, err := yaml.Marshal(rawWorkspace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.serverErrorResponse(w, r, err)
|
a.serverErrorResponse(w, r, err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -202,3 +202,14 @@ func (r *WorkspaceRepository) DeleteWorkspace(ctx context.Context, namespace, wo
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *WorkspaceRepository) GetRawWorkspace(ctx context.Context, namespace string, workspaceName string) (*kubefloworgv1beta1.Workspace, error) {
|
||||||
|
workspace := &kubefloworgv1beta1.Workspace{}
|
||||||
|
if err := r.client.Get(ctx, client.ObjectKey{Namespace: namespace, Name: workspaceName}, workspace); err != nil {
|
||||||
|
if apierrors.IsNotFound(err) {
|
||||||
|
return nil, ErrWorkspaceNotFound
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return workspace, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue