From 3cd7f441305bfe8811fa2a63b507ef88667d4bff Mon Sep 17 00:00:00 2001 From: shravan20 Date: Sun, 29 Jun 2025 20:26:34 +0530 Subject: [PATCH 01/72] test-cases: E2E for container flow --- api/api/versions.json | 8 +- api/doc/openapi.json | 2 +- api/internal/routes.go | 26 ++- .../tests/container/get_container_test.go | 216 ++++++++++++++++++ .../tests/container/list_containers_test.go | 156 +++++++++++++ api/internal/tests/helper.go | 8 + docker-compose-test.yml | 19 ++ 7 files changed, 430 insertions(+), 5 deletions(-) create mode 100644 api/internal/tests/container/get_container_test.go create mode 100644 api/internal/tests/container/list_containers_test.go create mode 100644 docker-compose-test.yml diff --git a/api/api/versions.json b/api/api/versions.json index ace413bb..ccc72edb 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,9 +3,11 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-28T00:59:10.212737+05:30", + "release_date": "2025-06-29T19:08:38.461985+05:30", "end_of_life": "0001-01-01T00:00:00Z", - "changes": ["Initial API version"] + "changes": [ + "Initial API version" + ] } ] -} +} \ No newline at end of file diff --git a/api/doc/openapi.json b/api/doc/openapi.json index a9f16ac0..0d798bae 100644 --- a/api/doc/openapi.json +++ b/api/doc/openapi.json @@ -1 +1 @@ -{"components":{"schemas":{"AddUserToOrganizationRequest":{"description":"AddUserToOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"role_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ContainerLogsRequest":{"description":"ContainerLogsRequest schema","properties":{"follow":{"type":"boolean"},"id":{"type":"string"},"since":{"type":"string"},"stderr":{"type":"boolean"},"stdout":{"type":"boolean"},"tail":{"type":"integer"},"until":{"type":"string"}},"type":"object"},"CopyDirectory":{"description":"CopyDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"CreateDeploymentRequest":{"description":"CreateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"branch":{"type":"string"},"build_pack":{"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"domain":{"type":"string"},"environment":{"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"type":"object"},"name":{"type":"string"},"port":{"type":"integer"},"post_run_command":{"type":"string"},"pre_run_command":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"CreateDirectoryRequest":{"description":"CreateDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"CreateDomainRequest":{"description":"CreateDomainRequest schema","properties":{"name":{"type":"string"},"organization_id":{}},"type":"object"},"CreateGithubConnectorRequest":{"description":"CreateGithubConnectorRequest schema","properties":{"app_id":{"type":"string"},"client_id":{"type":"string"},"client_secret":{"type":"string"},"pem":{"type":"string"},"slug":{"type":"string"},"webhook_secret":{"type":"string"}},"type":"object"},"CreateOrganizationRequest":{"description":"CreateOrganizationRequest schema","properties":{"description":{"type":"string"},"name":{"type":"string"}},"type":"object"},"CreateSMTPConfigRequest":{"description":"CreateSMTPConfigRequest schema","properties":{"from_email":{"type":"string"},"from_name":{"type":"string"},"host":{"type":"string"},"organization_id":{},"password":{"type":"string"},"port":{"type":"integer"},"username":{"type":"string"}},"type":"object"},"CreateWebhookConfigRequest":{"description":"CreateWebhookConfigRequest schema","properties":{"type":{"type":"string"},"webhook_url":{"type":"string"}},"required":["type"],"type":"object"},"DeleteDeploymentRequest":{"description":"DeleteDeploymentRequest schema","properties":{"id":{}},"type":"object"},"DeleteDirectoryRequest":{"description":"DeleteDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"DeleteDomainRequest":{"description":"DeleteDomainRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteOrganizationRequest":{"description":"DeleteOrganizationRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteSMTPConfigRequest":{"description":"DeleteSMTPConfigRequest schema","properties":{"id":{}},"type":"object"},"DeleteWebhookConfigRequest":{"description":"DeleteWebhookConfigRequest schema","properties":{"type":{"type":"string"}},"required":["type"],"type":"object"},"GetApplicationDeploymentsRequest":{"description":"GetApplicationDeploymentsRequest schema","properties":{"id":{"type":"string"},"limit":{"type":"string"},"page":{"type":"string"}},"type":"object"},"GetApplicationsRequest":{"description":"GetApplicationsRequest schema","properties":{"page":{"type":"string"},"page_size":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"GetOrganizationUsersRequest":{"description":"GetOrganizationUsersRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"HTTPError":{"description":"HTTPError schema","properties":{"detail":{"description":"Human readable error message","nullable":true,"type":"string"},"errors":{"items":{"properties":{"more":{"additionalProperties":{},"type":"object"},"name":{"type":"string"},"reason":{"type":"string"}},"type":"object"},"nullable":true,"type":"array"},"instance":{"nullable":true,"type":"string"},"status":{"description":"HTTP status code","example":403,"nullable":true,"type":"integer"},"title":{"description":"Short title of the error","nullable":true,"type":"string"},"type":{"description":"URL of the error type. Can be used to lookup the error in a documentation","nullable":true,"type":"string"}},"type":"object"},"ListFilesRequest":{"description":"ListFilesRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"ListImagesRequest":{"description":"ListImagesRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"container_id":{"nullable":true,"type":"string"},"image_prefix":{"nullable":true,"type":"string"}},"type":"object"},"LoginRequest":{"description":"LoginRequest schema","properties":{"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"LogoutRequest":{"description":"LogoutRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"MoveDirectory":{"description":"MoveDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"PruneBuildCacheRequest":{"description":"PruneBuildCacheRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"filters":{"nullable":true,"type":"string"}},"type":"object"},"PruneImagesRequest":{"description":"PruneImagesRequest schema","properties":{"dangling":{"nullable":true,"type":"boolean"},"label":{"nullable":true,"type":"string"},"until":{"nullable":true,"type":"string"}},"type":"object"},"ReDeployApplicationRequest":{"description":"ReDeployApplicationRequest schema","properties":{"force":{"type":"boolean"},"force_without_cache":{"type":"boolean"},"id":{}},"type":"object"},"RefreshTokenRequest":{"description":"RefreshTokenRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"RegisterRequest":{"description":"RegisterRequest schema","properties":{"email":{"type":"string"},"organization":{"type":"string"},"password":{"type":"string"},"type":{"type":"string"},"username":{"type":"string"}},"type":"object"},"RemoveUserFromOrganizationRequest":{"description":"RemoveUserFromOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ResetPasswordRequest":{"description":"ResetPasswordRequest schema","properties":{"password":{"type":"string"}},"type":"object"},"Response":{"description":"Response schema","properties":{"data":{"nullable":true},"error":{"nullable":true,"type":"string"},"message":{"nullable":true,"type":"string"},"status":{"type":"string"}},"type":"object"},"RestartDeploymentRequest":{"description":"RestartDeploymentRequest schema","properties":{"id":{}},"type":"object"},"RollbackDeploymentRequest":{"description":"RollbackDeploymentRequest schema","properties":{"id":{}},"type":"object"},"TwoFactorLoginRequest":{"description":"TwoFactorLoginRequest schema","properties":{"code":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"TwoFactorVerifyRequest":{"description":"TwoFactorVerifyRequest schema","properties":{"code":{"type":"string"}},"type":"object"},"UpdateAutoUpdateRequest":{"description":"UpdateAutoUpdateRequest schema","properties":{"auto_update":{"type":"boolean"}},"type":"object"},"UpdateAvatarRequest":{"description":"UpdateAvatarRequest schema","properties":{"avatarData":{"type":"string"}},"type":"object"},"UpdateCheckResponse":{"description":"UpdateCheckResponse schema","properties":{"current_version":{"type":"string"},"environment":{"type":"string"},"last_checked":{"format":"date-time","type":"string"},"latest_version":{"type":"string"},"update_available":{"type":"boolean"}},"type":"object"},"UpdateDeploymentRequest":{"description":"UpdateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"force":{"nullable":true,"type":"boolean"},"id":{"nullable":true},"name":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"post_run_command":{"nullable":true,"type":"string"},"pre_run_command":{"nullable":true,"type":"string"}},"type":"object"},"UpdateDomainRequest":{"description":"UpdateDomainRequest schema","properties":{"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdateFeatureFlagRequest":{"description":"UpdateFeatureFlagRequest schema","properties":{"feature_name":{"type":"string"},"is_enabled":{"type":"boolean"}},"required":["feature_name"],"type":"object"},"UpdateFontRequest":{"description":"UpdateFontRequest schema","properties":{"font_family":{"type":"string"},"font_size":{"type":"integer"}},"type":"object"},"UpdateGithubConnectorRequest":{"description":"UpdateGithubConnectorRequest schema","properties":{"installation_id":{"type":"string"}},"type":"object"},"UpdateLanguageRequest":{"description":"UpdateLanguageRequest schema","properties":{"language":{"type":"string"}},"type":"object"},"UpdateOrganizationRequest":{"description":"UpdateOrganizationRequest schema","properties":{"description":{"type":"string"},"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdatePreferenceRequest":{"description":"UpdatePreferenceRequest schema","properties":{"category":{"type":"string"},"enabled":{"type":"boolean"},"type":{"type":"string"}},"required":["category","type"],"type":"object"},"UpdateRequest":{"description":"UpdateRequest schema","properties":{"force":{"type":"boolean"}},"type":"object"},"UpdateResponse":{"description":"UpdateResponse schema","properties":{"message":{"type":"string"},"success":{"type":"boolean"}},"type":"object"},"UpdateSMTPConfigRequest":{"description":"UpdateSMTPConfigRequest schema","properties":{"from_email":{"nullable":true,"type":"string"},"from_name":{"nullable":true,"type":"string"},"host":{"nullable":true,"type":"string"},"id":{},"organization_id":{},"password":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"username":{"nullable":true,"type":"string"}},"type":"object"},"UpdateThemeRequest":{"description":"UpdateThemeRequest schema","properties":{"theme":{"type":"string"}},"type":"object"},"UpdateUserNameRequest":{"description":"UpdateUserNameRequest schema","properties":{"name":{"type":"string"}},"type":"object"},"UpdateUserRoleRequest":{"description":"UpdateUserRoleRequest schema","properties":{"organization_id":{"type":"string"},"role_name":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"UpdateWebhookConfigRequest":{"description":"UpdateWebhookConfigRequest schema","properties":{"is_active":{"nullable":true,"type":"boolean"},"type":{"type":"string"},"webhook_url":{"nullable":true,"type":"string"}},"required":["type"],"type":"object"},"unknown-interface":{"description":"unknown-interface schema"}},"securitySchemes":{"bearerAuth":{"bearerFormat":"JWT","description":"Enter your JWT token in the format: Bearer \u003ctoken\u003e","scheme":"bearer","type":"http"}}},"info":{"description":"\nThis is the autogenerated OpenAPI documentation for your [Fuego](https://github.com/go-fuego/fuego) API.\n\nBelow is a Fuego Cheatsheet to help you get started. Don't hesitate to check the [Fuego documentation](https://go-fuego.dev) for more details.\n\nHappy coding! 🔥\n\n## Usage\n\n### Route registration\n\n```go\nfunc main() {\n\t// Create a new server\n\ts := fuego.NewServer()\n\n\t// Register some routes\n\tfuego.Post(s, \"/hello\", myController)\n\tfuego.Get(s, \"/myPath\", otherController)\n\tfuego.Put(s, \"/hello\", thirdController)\n\n\tadminRoutes := fuego.Group(s, \"/admin\")\n\tfuego.Use(adminRoutes, myMiddleware) // This middleware (for authentication, etc...) will be available for routes starting by /admin/*, \n\tfuego.Get(adminRoutes, \"/hello\", groupController) // This route will be available at /admin/hello\n\n\t// Start the server\n\ts.Start()\n}\n```\n\n### Basic controller\n\n```go\ntype MyBody struct {\n\tName string `json:\"name\" validate:\"required,max=30\"`\n}\n\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc hello(ctx fuego.ContextWithBody[MyBody]) (*MyResponse, error) {\n\tbody, err := ctx.Body()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + body.Name}, nil\n}\n```\n\n### Add openAPI information to the route\n\n```go\nimport (\n\t\"github.com/go-fuego/fuego\"\n\t\"github.com/go-fuego/fuego/option\"\n\t\"github.com/go-fuego/fuego/param\"\n)\n\nfunc main() {\n\ts := fuego.NewServer()\n\n\t// Custom OpenAPI options\n\tfuego.Post(s, \"/\", myController\n\t\toption.Description(\"This route does something...\"),\n\t\toption.Summary(\"This is my summary\"),\n\t\toption.Tags(\"MyTag\"), // A tag is set by default according to the return type (can be deactivated)\n\t\toption.Deprecated(), // Marks the route as deprecated in the OpenAPI spec\n\n\t\toption.Query(\"name\", \"Declares a query parameter with default value\", param.Default(\"Carmack\")),\n\t\toption.Header(\"Authorization\", \"Bearer token\", param.Required()),\n\t\toptionPagination,\n\t\toptionCustomBehavior,\n\t)\n\n\ts.Run()\n}\n\nvar optionPagination = option.Group(\n\toption.QueryInt(\"page\", \"Page number\", param.Default(1), param.Example(\"1st page\", 1), param.Example(\"42nd page\", 42)),\n\toption.QueryInt(\"perPage\", \"Number of items per page\"),\n)\n\nvar optionCustomBehavior = func(r *fuego.BaseRoute) {\n\tr.XXX = \"YYY\"\n}\n```\n\nThen, in the controller\n\n```go\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc getAllPets(ctx fuego.ContextNoBody) (*MyResponse, error) {\n\tname := ctx.QueryParam(\"name\")\n\tperPage, _ := ctx.QueryParamIntErr(\"per_page\")\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + name}, nil\n}\n```\n","title":"OpenAPI","version":"0.0.1"},"openapi":"3.1.0","paths":{"/api/v1/audit/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/audit/controller.(*AuditController).GetRecentAuditLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func16`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func17`\n\n---\n\n","operationId":"GET_/api/v1/audit/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get recent audit logs","tags":["api/v1/audit"]}},"/api/v1/auth/2fa-login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).TwoFactorLogin`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/2fa-login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorLoginRequest"}}},"description":"Request body for types.TwoFactorLoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"two factor login","tags":["api/v1/auth"]}},"/api/v1/auth/create-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).CreateUser`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/create-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create user","tags":["api/v1/auth"]}},"/api/v1/auth/disable-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).DisableTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/disable-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"disable two factor","tags":["api/v1/auth"]}},"/api/v1/auth/is-admin-registered":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).IsAdminRegistered`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/auth/is-admin-registered","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is admin registered","tags":["api/v1/auth"]}},"/api/v1/auth/login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Login`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LoginRequest"}}},"description":"Request body for types.LoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"login","tags":["api/v1/auth"]}},"/api/v1/auth/logout":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Logout`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/logout","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LogoutRequest"}}},"description":"Request body for types.LogoutRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"logout","tags":["api/v1/auth"]}},"/api/v1/auth/refresh-token":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).RefreshToken`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/refresh-token","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RefreshTokenRequest"}}},"description":"Request body for types.RefreshTokenRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"refresh token","tags":["api/v1/auth"]}},"/api/v1/auth/register":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Register`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/register","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"register","tags":["api/v1/auth"]}},"/api/v1/auth/request-password-reset":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).GeneratePasswordResetLink`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/request-password-reset","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate password reset link","tags":["api/v1/auth"]}},"/api/v1/auth/reset-password":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).ResetPassword`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/reset-password","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ResetPasswordRequest"}}},"description":"Request body for types.ResetPasswordRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"reset password","tags":["api/v1/auth"]}},"/api/v1/auth/send-verification-email":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SendVerificationEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/send-verification-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"send verification email","tags":["api/v1/auth"]}},"/api/v1/auth/setup-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SetupTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/setup-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"setup two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/verify-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorVerifyRequest"}}},"description":"Request body for types.TwoFactorVerifyRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-email":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/auth/verify-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify email","tags":["api/v1/auth"]}},"/api/v1/container":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListContainers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list containers","tags":["api/v1/container"]}},"/api/v1/container/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListImagesRequest"}}},"description":"Request body for controller.ListImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list images","tags":["api/v1/container"]}},"/api/v1/container/prune/build-cache":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneBuildCache`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/build-cache","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneBuildCacheRequest"}}},"description":"Request body for controller.PruneBuildCacheRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune build cache","tags":["api/v1/container"]}},"/api/v1/container/prune/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneImagesRequest"}}},"description":"Request body for controller.PruneImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune images","tags":["api/v1/container"]}},"/api/v1/container/{container_id}":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RemoveContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"DELETE_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove container","tags":["api/v1/container"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/logs":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainerLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ContainerLogsRequest"}}},"description":"Request body for types.ContainerLogsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container logs","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RestartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"restart container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/start":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/start","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"start container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/stop":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StopContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/stop","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"stop container","tags":["api/v1/container"]}},"/api/v1/deploy/application":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).DeleteApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"DELETE_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDeploymentRequest"}}},"description":"Request body for types.DeleteDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete application","tags":["api/v1/deploy","application"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application by id","tags":["api/v1/deploy","application"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleDeploy`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDeploymentRequest"}}},"description":"Request body for types.CreateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle deploy","tags":["api/v1/deploy","application"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).UpdateApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"PUT_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDeploymentRequest"}}},"description":"Request body for types.UpdateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationDeployments`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationDeploymentsRequest"}}},"description":"Request body for controller.GetApplicationDeploymentsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application deployments","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment by id","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/logs/{application_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/logs/:application_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"application_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/redeploy":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).ReDeployApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/redeploy","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ReDeployApplicationRequest"}}},"description":"Request body for types.ReDeployApplicationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"re deploy application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRestart`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RestartDeploymentRequest"}}},"description":"Request body for types.RestartDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle restart","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/rollback":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRollback`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/rollback","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RollbackDeploymentRequest"}}},"description":"Request body for types.RollbackDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle rollback","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/applications":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplications`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/applications","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationsRequest"}}},"description":"Request body for controller.GetApplicationsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get applications","tags":["api/v1/deploy"]}},"/api/v1/domain":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).DeleteDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"DELETE_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDomainRequest"}}},"description":"Request body for types.DeleteDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete domain","tags":["api/v1/domain"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).CreateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"POST_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDomainRequest"}}},"description":"Request body for types.CreateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create domain","tags":["api/v1/domain"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).UpdateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"PUT_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDomainRequest"}}},"description":"Request body for types.UpdateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update domain","tags":["api/v1/domain"]}},"/api/v1/domain/generate":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GenerateRandomSubDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"GET_/api/v1/domain/generate","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate random sub domain","tags":["api/v1/domain"]}},"/api/v1/domains":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GetDomains`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func6`\n\n---\n\n","operationId":"GET_/api/v1/domains","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get domains","tags":["api/v1/domains"]}},"/api/v1/feature-flags":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).GetFeatureFlags`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get feature flags","tags":["api/v1/feature-flags"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).UpdateFeatureFlag`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"PUT_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFeatureFlagRequest"}}},"description":"Request body for types.UpdateFeatureFlagRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update feature flag","tags":["api/v1/feature-flags"]}},"/api/v1/feature-flags/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).IsFeatureEnabled`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is feature enabled","tags":["api/v1/feature-flags"]}},"/api/v1/file-manager":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).ListFiles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"GET_/api/v1/file-manager","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListFilesRequest"}}},"description":"Request body for controller.ListFilesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list files","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/copy-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CopyDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/copy-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CopyDirectory"}}},"description":"Request body for controller.CopyDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"copy directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/create-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CreateDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/create-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDirectoryRequest"}}},"description":"Request body for controller.CreateDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/delete-directory":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).DeleteDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"DELETE_/api/v1/file-manager/delete-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDirectoryRequest"}}},"description":"Request body for controller.DeleteDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/move-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).MoveDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/move-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/MoveDirectory"}}},"description":"Request body for controller.MoveDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"move directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/upload":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).UploadFile`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/upload","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"upload file","tags":["api/v1/file-manager"]}},"/api/v1/github-connector":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).CreateGithubConnector`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"POST_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateGithubConnectorRequest"}}},"description":"Request body for types.CreateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create github connector","tags":["api/v1/github-connector"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).UpdateGithubConnectorRequest`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"PUT_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateGithubConnectorRequest"}}},"description":"Request body for types.UpdateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update github connector request","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/all":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubConnectors`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/all","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github connectors","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/repositories":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubRepositories`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/repositories","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github repositories","tags":["api/v1/github-connector"]}},"/api/v1/health":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/health.HealthCheck`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"health check","tags":["api/v1/health"]}},"/api/v1/health/versions":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).BasicRoutes.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health/versions","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1","tags":["api/v1/health","versions"]}},"/api/v1/notification/preferences":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetPreferences`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get preferences","tags":["api/v1/notification","preferences"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdatePreference`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdatePreferenceRequest"}}},"description":"Request body for notification.UpdatePreferenceRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update preference","tags":["api/v1/notification","preferences"]}},"/api/v1/notification/smtp":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteSMTPConfigRequest"}}},"description":"Request body for notification.DeleteSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete smtp","tags":["api/v1/notification","smtp"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get smtp","tags":["api/v1/notification","smtp"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).AddSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateSMTPConfigRequest"}}},"description":"Request body for notification.CreateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add smtp","tags":["api/v1/notification","smtp"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateSMTPConfigRequest"}}},"description":"Request body for notification.UpdateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update smtp","tags":["api/v1/notification","smtp"]}},"/api/v1/notification/webhook":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteWebhookConfigRequest"}}},"description":"Request body for notification.DeleteWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete webhook config","tags":["api/v1/notification","webhook"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).CreateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateWebhookConfigRequest"}}},"description":"Request body for notification.CreateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create webhook config","tags":["api/v1/notification","webhook"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateWebhookConfigRequest"}}},"description":"Request body for notification.UpdateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/notification/webhook/{type}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/webhook/:type","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"type","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/organizations":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).DeleteOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"DELETE_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteOrganizationRequest"}}},"description":"Request body for types.DeleteOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete organization","tags":["api/v1/organizations"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).CreateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateOrganizationRequest"}}},"description":"Request body for types.CreateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create organization","tags":["api/v1/organizations"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"PUT_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateOrganizationRequest"}}},"description":"Request body for types.UpdateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/add-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).AddUserToOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/add-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/AddUserToOrganizationRequest"}}},"description":"Request body for types.AddUserToOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add user to organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/remove-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).RemoveUserFromOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/remove-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RemoveUserFromOrganizationRequest"}}},"description":"Request body for types.RemoveUserFromOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove user from organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/resources":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetResources`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/resources","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get resources","tags":["api/v1/organizations"]}},"/api/v1/organizations/roles":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetRoles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/roles","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get roles","tags":["api/v1/organizations"]}},"/api/v1/organizations/update-user-role":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateUserRole`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/update-user-role","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserRoleRequest"}}},"description":"Request body for controller.UpdateUserRoleRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user role","tags":["api/v1/organizations"]}},"/api/v1/organizations/users":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetOrganizationUsers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/users","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetOrganizationUsersRequest"}}},"description":"Request body for controller.GetOrganizationUsersRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get organization users","tags":["api/v1/organizations"]}},"/api/v1/update":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).PerformUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateRequest"}}},"description":"Request body for types.UpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"perform update","tags":["api/v1/update"]}},"/api/v1/update/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).CheckForUpdates`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/update/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"check for updates","tags":["api/v1/update"]}},"/api/v1/user":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserDetails`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user details","tags":["api/v1/user"]}},"/api/v1/user/avatar":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAvatar`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/avatar","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAvatarRequest"}}},"description":"Request body for types.UpdateAvatarRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update avatar","tags":["api/v1/user"]}},"/api/v1/user/name":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateUserName`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/name","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserNameRequest"}}},"description":"Request body for types.UpdateUserNameRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user name","tags":["api/v1/user"]}},"/api/v1/user/organizations":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserOrganizations`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user organizations","tags":["api/v1/user"]}},"/api/v1/user/settings":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetSettings`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/settings","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get settings","tags":["api/v1/user"]}},"/api/v1/user/settings/auto-update":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAutoUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/auto-update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAutoUpdateRequest"}}},"description":"Request body for controller.UpdateAutoUpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update auto update","tags":["api/v1/user"]}},"/api/v1/user/settings/font":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateFont`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/font","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFontRequest"}}},"description":"Request body for controller.UpdateFontRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update font","tags":["api/v1/user"]}},"/api/v1/user/settings/language":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateLanguage`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/language","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateLanguageRequest"}}},"description":"Request body for controller.UpdateLanguageRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update language","tags":["api/v1/user"]}},"/api/v1/user/settings/theme":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateTheme`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/theme","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateThemeRequest"}}},"description":"Request body for controller.UpdateThemeRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update theme","tags":["api/v1/user"]}},"/api/v1/webhook":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleGithubWebhook`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle github webhook","tags":["api/v1/webhook"]}},"/ws":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).WebSocketServer.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/ws","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1"}}},"servers":[{"description":"local server","url":"http://:8080"}],"tags":[{"name":"api/v1/audit"},{"name":"api/v1/auth"},{"name":"api/v1/container"},{"name":"api/v1/deploy"},{"name":"api/v1/domain"},{"name":"api/v1/domains"},{"name":"api/v1/feature-flags"},{"name":"api/v1/file-manager"},{"name":"api/v1/github-connector"},{"name":"api/v1/health"},{"name":"api/v1/notification"},{"name":"api/v1/organizations"},{"name":"api/v1/update"},{"name":"api/v1/user"},{"name":"api/v1/webhook"},{"name":"application"},{"name":"preferences"},{"name":"smtp"},{"name":"versions"},{"name":"webhook"}]} \ No newline at end of file +{"components":{"schemas":{"AddUserToOrganizationRequest":{"description":"AddUserToOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"role_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ContainerLogsRequest":{"description":"ContainerLogsRequest schema","properties":{"follow":{"type":"boolean"},"id":{"type":"string"},"since":{"type":"string"},"stderr":{"type":"boolean"},"stdout":{"type":"boolean"},"tail":{"type":"integer"},"until":{"type":"string"}},"type":"object"},"CopyDirectory":{"description":"CopyDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"CreateDeploymentRequest":{"description":"CreateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"branch":{"type":"string"},"build_pack":{"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"domain":{"type":"string"},"environment":{"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"type":"object"},"name":{"type":"string"},"port":{"type":"integer"},"post_run_command":{"type":"string"},"pre_run_command":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"CreateDirectoryRequest":{"description":"CreateDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"CreateDomainRequest":{"description":"CreateDomainRequest schema","properties":{"name":{"type":"string"},"organization_id":{}},"type":"object"},"CreateGithubConnectorRequest":{"description":"CreateGithubConnectorRequest schema","properties":{"app_id":{"type":"string"},"client_id":{"type":"string"},"client_secret":{"type":"string"},"pem":{"type":"string"},"slug":{"type":"string"},"webhook_secret":{"type":"string"}},"type":"object"},"CreateOrganizationRequest":{"description":"CreateOrganizationRequest schema","properties":{"description":{"type":"string"},"name":{"type":"string"}},"type":"object"},"CreateSMTPConfigRequest":{"description":"CreateSMTPConfigRequest schema","properties":{"from_email":{"type":"string"},"from_name":{"type":"string"},"host":{"type":"string"},"organization_id":{},"password":{"type":"string"},"port":{"type":"integer"},"username":{"type":"string"}},"type":"object"},"CreateWebhookConfigRequest":{"description":"CreateWebhookConfigRequest schema","properties":{"type":{"type":"string"},"webhook_url":{"type":"string"}},"required":["type"],"type":"object"},"DeleteDeploymentRequest":{"description":"DeleteDeploymentRequest schema","properties":{"id":{}},"type":"object"},"DeleteDirectoryRequest":{"description":"DeleteDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"DeleteDomainRequest":{"description":"DeleteDomainRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteOrganizationRequest":{"description":"DeleteOrganizationRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteSMTPConfigRequest":{"description":"DeleteSMTPConfigRequest schema","properties":{"id":{}},"type":"object"},"DeleteWebhookConfigRequest":{"description":"DeleteWebhookConfigRequest schema","properties":{"type":{"type":"string"}},"required":["type"],"type":"object"},"GetApplicationDeploymentsRequest":{"description":"GetApplicationDeploymentsRequest schema","properties":{"id":{"type":"string"},"limit":{"type":"string"},"page":{"type":"string"}},"type":"object"},"GetApplicationsRequest":{"description":"GetApplicationsRequest schema","properties":{"page":{"type":"string"},"page_size":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"GetOrganizationUsersRequest":{"description":"GetOrganizationUsersRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"HTTPError":{"description":"HTTPError schema","properties":{"detail":{"description":"Human readable error message","nullable":true,"type":"string"},"errors":{"items":{"properties":{"more":{"additionalProperties":{},"type":"object"},"name":{"type":"string"},"reason":{"type":"string"}},"type":"object"},"nullable":true,"type":"array"},"instance":{"nullable":true,"type":"string"},"status":{"description":"HTTP status code","example":403,"nullable":true,"type":"integer"},"title":{"description":"Short title of the error","nullable":true,"type":"string"},"type":{"description":"URL of the error type. Can be used to lookup the error in a documentation","nullable":true,"type":"string"}},"type":"object"},"ListFilesRequest":{"description":"ListFilesRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"ListImagesRequest":{"description":"ListImagesRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"container_id":{"nullable":true,"type":"string"},"image_prefix":{"nullable":true,"type":"string"}},"type":"object"},"LoginRequest":{"description":"LoginRequest schema","properties":{"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"LogoutRequest":{"description":"LogoutRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"MoveDirectory":{"description":"MoveDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"PruneBuildCacheRequest":{"description":"PruneBuildCacheRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"filters":{"nullable":true,"type":"string"}},"type":"object"},"PruneImagesRequest":{"description":"PruneImagesRequest schema","properties":{"dangling":{"nullable":true,"type":"boolean"},"label":{"nullable":true,"type":"string"},"until":{"nullable":true,"type":"string"}},"type":"object"},"ReDeployApplicationRequest":{"description":"ReDeployApplicationRequest schema","properties":{"force":{"type":"boolean"},"force_without_cache":{"type":"boolean"},"id":{}},"type":"object"},"RefreshTokenRequest":{"description":"RefreshTokenRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"RegisterRequest":{"description":"RegisterRequest schema","properties":{"email":{"type":"string"},"organization":{"type":"string"},"password":{"type":"string"},"type":{"type":"string"},"username":{"type":"string"}},"type":"object"},"RemoveUserFromOrganizationRequest":{"description":"RemoveUserFromOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ResetPasswordRequest":{"description":"ResetPasswordRequest schema","properties":{"password":{"type":"string"}},"type":"object"},"Response":{"description":"Response schema","properties":{"data":{"nullable":true},"error":{"nullable":true,"type":"string"},"message":{"nullable":true,"type":"string"},"status":{"type":"string"}},"type":"object"},"RestartDeploymentRequest":{"description":"RestartDeploymentRequest schema","properties":{"id":{}},"type":"object"},"RollbackDeploymentRequest":{"description":"RollbackDeploymentRequest schema","properties":{"id":{}},"type":"object"},"TwoFactorLoginRequest":{"description":"TwoFactorLoginRequest schema","properties":{"code":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"TwoFactorVerifyRequest":{"description":"TwoFactorVerifyRequest schema","properties":{"code":{"type":"string"}},"type":"object"},"UpdateAutoUpdateRequest":{"description":"UpdateAutoUpdateRequest schema","properties":{"auto_update":{"type":"boolean"}},"type":"object"},"UpdateAvatarRequest":{"description":"UpdateAvatarRequest schema","properties":{"avatarData":{"type":"string"}},"type":"object"},"UpdateCheckResponse":{"description":"UpdateCheckResponse schema","properties":{"current_version":{"type":"string"},"environment":{"type":"string"},"last_checked":{"format":"date-time","type":"string"},"latest_version":{"type":"string"},"update_available":{"type":"boolean"}},"type":"object"},"UpdateDeploymentRequest":{"description":"UpdateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"force":{"nullable":true,"type":"boolean"},"id":{"nullable":true},"name":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"post_run_command":{"nullable":true,"type":"string"},"pre_run_command":{"nullable":true,"type":"string"}},"type":"object"},"UpdateDomainRequest":{"description":"UpdateDomainRequest schema","properties":{"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdateFeatureFlagRequest":{"description":"UpdateFeatureFlagRequest schema","properties":{"feature_name":{"type":"string"},"is_enabled":{"type":"boolean"}},"required":["feature_name"],"type":"object"},"UpdateFontRequest":{"description":"UpdateFontRequest schema","properties":{"font_family":{"type":"string"},"font_size":{"type":"integer"}},"type":"object"},"UpdateGithubConnectorRequest":{"description":"UpdateGithubConnectorRequest schema","properties":{"installation_id":{"type":"string"}},"type":"object"},"UpdateLanguageRequest":{"description":"UpdateLanguageRequest schema","properties":{"language":{"type":"string"}},"type":"object"},"UpdateOrganizationRequest":{"description":"UpdateOrganizationRequest schema","properties":{"description":{"type":"string"},"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdatePreferenceRequest":{"description":"UpdatePreferenceRequest schema","properties":{"category":{"type":"string"},"enabled":{"type":"boolean"},"type":{"type":"string"}},"required":["category","type"],"type":"object"},"UpdateRequest":{"description":"UpdateRequest schema","properties":{"force":{"type":"boolean"}},"type":"object"},"UpdateResponse":{"description":"UpdateResponse schema","properties":{"message":{"type":"string"},"success":{"type":"boolean"}},"type":"object"},"UpdateSMTPConfigRequest":{"description":"UpdateSMTPConfigRequest schema","properties":{"from_email":{"nullable":true,"type":"string"},"from_name":{"nullable":true,"type":"string"},"host":{"nullable":true,"type":"string"},"id":{},"organization_id":{},"password":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"username":{"nullable":true,"type":"string"}},"type":"object"},"UpdateThemeRequest":{"description":"UpdateThemeRequest schema","properties":{"theme":{"type":"string"}},"type":"object"},"UpdateUserNameRequest":{"description":"UpdateUserNameRequest schema","properties":{"name":{"type":"string"}},"type":"object"},"UpdateUserRoleRequest":{"description":"UpdateUserRoleRequest schema","properties":{"organization_id":{"type":"string"},"role_name":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"UpdateWebhookConfigRequest":{"description":"UpdateWebhookConfigRequest schema","properties":{"is_active":{"nullable":true,"type":"boolean"},"type":{"type":"string"},"webhook_url":{"nullable":true,"type":"string"}},"required":["type"],"type":"object"},"unknown-interface":{"description":"unknown-interface schema"}},"securitySchemes":{"bearerAuth":{"bearerFormat":"JWT","description":"Enter your JWT token in the format: Bearer \u003ctoken\u003e","scheme":"bearer","type":"http"}}},"info":{"description":"\nThis is the autogenerated OpenAPI documentation for your [Fuego](https://github.com/go-fuego/fuego) API.\n\nBelow is a Fuego Cheatsheet to help you get started. Don't hesitate to check the [Fuego documentation](https://go-fuego.dev) for more details.\n\nHappy coding! 🔥\n\n## Usage\n\n### Route registration\n\n```go\nfunc main() {\n\t// Create a new server\n\ts := fuego.NewServer()\n\n\t// Register some routes\n\tfuego.Post(s, \"/hello\", myController)\n\tfuego.Get(s, \"/myPath\", otherController)\n\tfuego.Put(s, \"/hello\", thirdController)\n\n\tadminRoutes := fuego.Group(s, \"/admin\")\n\tfuego.Use(adminRoutes, myMiddleware) // This middleware (for authentication, etc...) will be available for routes starting by /admin/*, \n\tfuego.Get(adminRoutes, \"/hello\", groupController) // This route will be available at /admin/hello\n\n\t// Start the server\n\ts.Start()\n}\n```\n\n### Basic controller\n\n```go\ntype MyBody struct {\n\tName string `json:\"name\" validate:\"required,max=30\"`\n}\n\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc hello(ctx fuego.ContextWithBody[MyBody]) (*MyResponse, error) {\n\tbody, err := ctx.Body()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + body.Name}, nil\n}\n```\n\n### Add openAPI information to the route\n\n```go\nimport (\n\t\"github.com/go-fuego/fuego\"\n\t\"github.com/go-fuego/fuego/option\"\n\t\"github.com/go-fuego/fuego/param\"\n)\n\nfunc main() {\n\ts := fuego.NewServer()\n\n\t// Custom OpenAPI options\n\tfuego.Post(s, \"/\", myController\n\t\toption.Description(\"This route does something...\"),\n\t\toption.Summary(\"This is my summary\"),\n\t\toption.Tags(\"MyTag\"), // A tag is set by default according to the return type (can be deactivated)\n\t\toption.Deprecated(), // Marks the route as deprecated in the OpenAPI spec\n\n\t\toption.Query(\"name\", \"Declares a query parameter with default value\", param.Default(\"Carmack\")),\n\t\toption.Header(\"Authorization\", \"Bearer token\", param.Required()),\n\t\toptionPagination,\n\t\toptionCustomBehavior,\n\t)\n\n\ts.Run()\n}\n\nvar optionPagination = option.Group(\n\toption.QueryInt(\"page\", \"Page number\", param.Default(1), param.Example(\"1st page\", 1), param.Example(\"42nd page\", 42)),\n\toption.QueryInt(\"perPage\", \"Number of items per page\"),\n)\n\nvar optionCustomBehavior = func(r *fuego.BaseRoute) {\n\tr.XXX = \"YYY\"\n}\n```\n\nThen, in the controller\n\n```go\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc getAllPets(ctx fuego.ContextNoBody) (*MyResponse, error) {\n\tname := ctx.QueryParam(\"name\")\n\tperPage, _ := ctx.QueryParamIntErr(\"per_page\")\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + name}, nil\n}\n```\n","title":"OpenAPI","version":"0.0.1"},"openapi":"3.1.0","paths":{"/api/v1/audit/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/audit/controller.(*AuditController).GetRecentAuditLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func16`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func17`\n\n---\n\n","operationId":"GET_/api/v1/audit/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get recent audit logs","tags":["api/v1/audit"]}},"/api/v1/auth/2fa-login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).TwoFactorLogin`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/2fa-login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorLoginRequest"}}},"description":"Request body for types.TwoFactorLoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"two factor login","tags":["api/v1/auth"]}},"/api/v1/auth/create-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).CreateUser`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/create-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create user","tags":["api/v1/auth"]}},"/api/v1/auth/disable-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).DisableTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/disable-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"disable two factor","tags":["api/v1/auth"]}},"/api/v1/auth/is-admin-registered":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).IsAdminRegistered`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/auth/is-admin-registered","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is admin registered","tags":["api/v1/auth"]}},"/api/v1/auth/login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Login`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LoginRequest"}}},"description":"Request body for types.LoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"login","tags":["api/v1/auth"]}},"/api/v1/auth/logout":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Logout`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/logout","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LogoutRequest"}}},"description":"Request body for types.LogoutRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"logout","tags":["api/v1/auth"]}},"/api/v1/auth/refresh-token":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).RefreshToken`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/refresh-token","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RefreshTokenRequest"}}},"description":"Request body for types.RefreshTokenRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"refresh token","tags":["api/v1/auth"]}},"/api/v1/auth/register":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Register`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/register","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"register","tags":["api/v1/auth"]}},"/api/v1/auth/request-password-reset":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).GeneratePasswordResetLink`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/request-password-reset","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate password reset link","tags":["api/v1/auth"]}},"/api/v1/auth/reset-password":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).ResetPassword`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/reset-password","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ResetPasswordRequest"}}},"description":"Request body for types.ResetPasswordRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"reset password","tags":["api/v1/auth"]}},"/api/v1/auth/send-verification-email":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SendVerificationEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/send-verification-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"send verification email","tags":["api/v1/auth"]}},"/api/v1/auth/setup-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SetupTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/setup-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"setup two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/verify-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorVerifyRequest"}}},"description":"Request body for types.TwoFactorVerifyRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-email":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/auth/verify-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify email","tags":["api/v1/auth"]}},"/api/v1/container":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListContainers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list containers","tags":["api/v1/container"]}},"/api/v1/container/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListImagesRequest"}}},"description":"Request body for controller.ListImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list images","tags":["api/v1/container"]}},"/api/v1/container/prune/build-cache":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneBuildCache`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/build-cache","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneBuildCacheRequest"}}},"description":"Request body for controller.PruneBuildCacheRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune build cache","tags":["api/v1/container"]}},"/api/v1/container/prune/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneImagesRequest"}}},"description":"Request body for controller.PruneImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune images","tags":["api/v1/container"]}},"/api/v1/container/{container_id}":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RemoveContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"DELETE_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove container","tags":["api/v1/container"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/logs":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainerLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ContainerLogsRequest"}}},"description":"Request body for types.ContainerLogsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container logs","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RestartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"restart container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/start":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/start","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"start container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/stop":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StopContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/stop","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"stop container","tags":["api/v1/container"]}},"/api/v1/deploy/application":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).DeleteApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"DELETE_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDeploymentRequest"}}},"description":"Request body for types.DeleteDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete application","tags":["api/v1/deploy","application"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application by id","tags":["api/v1/deploy","application"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleDeploy`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDeploymentRequest"}}},"description":"Request body for types.CreateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle deploy","tags":["api/v1/deploy","application"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).UpdateApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"PUT_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDeploymentRequest"}}},"description":"Request body for types.UpdateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationDeployments`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationDeploymentsRequest"}}},"description":"Request body for controller.GetApplicationDeploymentsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application deployments","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment by id","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/logs/{application_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/logs/:application_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"application_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/redeploy":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).ReDeployApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/redeploy","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ReDeployApplicationRequest"}}},"description":"Request body for types.ReDeployApplicationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"re deploy application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRestart`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RestartDeploymentRequest"}}},"description":"Request body for types.RestartDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle restart","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/rollback":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRollback`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/rollback","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RollbackDeploymentRequest"}}},"description":"Request body for types.RollbackDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle rollback","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/applications":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplications`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/applications","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationsRequest"}}},"description":"Request body for controller.GetApplicationsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get applications","tags":["api/v1/deploy"]}},"/api/v1/domain":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).DeleteDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"DELETE_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDomainRequest"}}},"description":"Request body for types.DeleteDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete domain","tags":["api/v1/domain"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).CreateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"POST_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDomainRequest"}}},"description":"Request body for types.CreateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create domain","tags":["api/v1/domain"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).UpdateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"PUT_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDomainRequest"}}},"description":"Request body for types.UpdateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update domain","tags":["api/v1/domain"]}},"/api/v1/domain/generate":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GenerateRandomSubDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"GET_/api/v1/domain/generate","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate random sub domain","tags":["api/v1/domain"]}},"/api/v1/domains":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GetDomains`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func6`\n\n---\n\n","operationId":"GET_/api/v1/domains","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get domains","tags":["api/v1/domains"]}},"/api/v1/feature-flags":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).GetFeatureFlags`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get feature flags","tags":["api/v1/feature-flags"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).UpdateFeatureFlag`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"PUT_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFeatureFlagRequest"}}},"description":"Request body for types.UpdateFeatureFlagRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update feature flag","tags":["api/v1/feature-flags"]}},"/api/v1/feature-flags/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).IsFeatureEnabled`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is feature enabled","tags":["api/v1/feature-flags"]}},"/api/v1/file-manager":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).ListFiles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"GET_/api/v1/file-manager","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListFilesRequest"}}},"description":"Request body for controller.ListFilesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list files","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/copy-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CopyDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/copy-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CopyDirectory"}}},"description":"Request body for controller.CopyDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"copy directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/create-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CreateDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/create-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDirectoryRequest"}}},"description":"Request body for controller.CreateDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/delete-directory":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).DeleteDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"DELETE_/api/v1/file-manager/delete-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDirectoryRequest"}}},"description":"Request body for controller.DeleteDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/move-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).MoveDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/move-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/MoveDirectory"}}},"description":"Request body for controller.MoveDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"move directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/upload":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).UploadFile`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/upload","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"upload file","tags":["api/v1/file-manager"]}},"/api/v1/github-connector":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).CreateGithubConnector`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"POST_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateGithubConnectorRequest"}}},"description":"Request body for types.CreateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create github connector","tags":["api/v1/github-connector"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).UpdateGithubConnectorRequest`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"PUT_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateGithubConnectorRequest"}}},"description":"Request body for types.UpdateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update github connector request","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/all":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubConnectors`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/all","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github connectors","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/repositories":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubRepositories`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/repositories","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github repositories","tags":["api/v1/github-connector"]}},"/api/v1/health":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/health.HealthCheck`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"health check","tags":["api/v1/health"]}},"/api/v1/health/versions":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).BasicRoutes.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health/versions","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1","tags":["api/v1/health","versions"]}},"/api/v1/notification/preferences":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetPreferences`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get preferences","tags":["api/v1/notification","preferences"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdatePreference`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdatePreferenceRequest"}}},"description":"Request body for notification.UpdatePreferenceRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update preference","tags":["api/v1/notification","preferences"]}},"/api/v1/notification/smtp":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteSMTPConfigRequest"}}},"description":"Request body for notification.DeleteSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete smtp","tags":["api/v1/notification","smtp"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get smtp","tags":["api/v1/notification","smtp"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).AddSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateSMTPConfigRequest"}}},"description":"Request body for notification.CreateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add smtp","tags":["api/v1/notification","smtp"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateSMTPConfigRequest"}}},"description":"Request body for notification.UpdateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update smtp","tags":["api/v1/notification","smtp"]}},"/api/v1/notification/webhook":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteWebhookConfigRequest"}}},"description":"Request body for notification.DeleteWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete webhook config","tags":["api/v1/notification","webhook"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).CreateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateWebhookConfigRequest"}}},"description":"Request body for notification.CreateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create webhook config","tags":["api/v1/notification","webhook"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateWebhookConfigRequest"}}},"description":"Request body for notification.UpdateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/notification/webhook/{type}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/webhook/:type","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"type","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/organizations":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).DeleteOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"DELETE_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteOrganizationRequest"}}},"description":"Request body for types.DeleteOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete organization","tags":["api/v1/organizations"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).CreateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateOrganizationRequest"}}},"description":"Request body for types.CreateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create organization","tags":["api/v1/organizations"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"PUT_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateOrganizationRequest"}}},"description":"Request body for types.UpdateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/add-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).AddUserToOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/add-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/AddUserToOrganizationRequest"}}},"description":"Request body for types.AddUserToOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add user to organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/remove-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).RemoveUserFromOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/remove-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RemoveUserFromOrganizationRequest"}}},"description":"Request body for types.RemoveUserFromOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove user from organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/resources":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetResources`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/resources","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get resources","tags":["api/v1/organizations"]}},"/api/v1/organizations/roles":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetRoles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/roles","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get roles","tags":["api/v1/organizations"]}},"/api/v1/organizations/update-user-role":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateUserRole`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/update-user-role","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserRoleRequest"}}},"description":"Request body for controller.UpdateUserRoleRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user role","tags":["api/v1/organizations"]}},"/api/v1/organizations/users":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetOrganizationUsers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/users","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetOrganizationUsersRequest"}}},"description":"Request body for controller.GetOrganizationUsersRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get organization users","tags":["api/v1/organizations"]}},"/api/v1/update":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).PerformUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateRequest"}}},"description":"Request body for types.UpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"perform update","tags":["api/v1/update"]}},"/api/v1/update/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).CheckForUpdates`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/update/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"check for updates","tags":["api/v1/update"]}},"/api/v1/user":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserDetails`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user details","tags":["api/v1/user"]}},"/api/v1/user/avatar":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAvatar`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/avatar","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAvatarRequest"}}},"description":"Request body for types.UpdateAvatarRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update avatar","tags":["api/v1/user"]}},"/api/v1/user/name":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateUserName`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/name","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserNameRequest"}}},"description":"Request body for types.UpdateUserNameRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user name","tags":["api/v1/user"]}},"/api/v1/user/organizations":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserOrganizations`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user organizations","tags":["api/v1/user"]}},"/api/v1/user/settings":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetSettings`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/settings","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get settings","tags":["api/v1/user"]}},"/api/v1/user/settings/auto-update":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAutoUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/auto-update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAutoUpdateRequest"}}},"description":"Request body for controller.UpdateAutoUpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update auto update","tags":["api/v1/user"]}},"/api/v1/user/settings/font":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateFont`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/font","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFontRequest"}}},"description":"Request body for controller.UpdateFontRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update font","tags":["api/v1/user"]}},"/api/v1/user/settings/language":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateLanguage`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/language","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateLanguageRequest"}}},"description":"Request body for controller.UpdateLanguageRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update language","tags":["api/v1/user"]}},"/api/v1/user/settings/theme":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateTheme`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/theme","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateThemeRequest"}}},"description":"Request body for controller.UpdateThemeRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update theme","tags":["api/v1/user"]}},"/api/v1/webhook":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleGithubWebhook`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle github webhook","tags":["api/v1/webhook"]}},"/ws":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).WebSocketServer.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/ws","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1"}}},"servers":[{"description":"local server","url":"http://localhost:8080"}],"tags":[{"name":"api/v1/audit"},{"name":"api/v1/auth"},{"name":"api/v1/container"},{"name":"api/v1/deploy"},{"name":"api/v1/domain"},{"name":"api/v1/domains"},{"name":"api/v1/feature-flags"},{"name":"api/v1/file-manager"},{"name":"api/v1/github-connector"},{"name":"api/v1/health"},{"name":"api/v1/notification"},{"name":"api/v1/organizations"},{"name":"api/v1/update"},{"name":"api/v1/user"},{"name":"api/v1/webhook"},{"name":"application"},{"name":"preferences"},{"name":"smtp"},{"name":"versions"},{"name":"webhook"}]} \ No newline at end of file diff --git a/api/internal/routes.go b/api/internal/routes.go index 25ffa1ef..bc5d1ccc 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -65,6 +65,30 @@ func (router *Router) Routes() { log.Fatal("Error loading .env file") } PORT := os.Getenv("PORT") + if PORT == "" { + PORT = "8080" + } + + // Build server address based on environment + ENV := os.Getenv("ENV") + HOST := os.Getenv("HOST") + var serverAddr string + + switch ENV { + case "production": + // In production, use the HOST env var or empty for all interfaces + if HOST != "" { + serverAddr = HOST + ":" + PORT + } else { + serverAddr = ":" + PORT + } + case "development": + // In development, use localhost + serverAddr = "localhost:" + PORT + default: + // Default to localhost for local development + serverAddr = "localhost:" + PORT + } docs := api.NewVersionDocumentation() if err := docs.Save("api/versions.json"); err != nil { @@ -90,7 +114,7 @@ func (router *Router) Routes() { WithDescription("Enter your JWT token in the format: Bearer "), }, }), - fuego.WithAddr(":"+PORT), + fuego.WithAddr(serverAddr), ) apiV1 := api.NewVersion(api.CurrentVersion) diff --git a/api/internal/tests/container/get_container_test.go b/api/internal/tests/container/get_container_test.go new file mode 100644 index 00000000..0d11cc62 --- /dev/null +++ b/api/internal/tests/container/get_container_test.go @@ -0,0 +1,216 @@ +package container + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetContainer(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, get a container ID from the list + var containerID string + Test(t, + Description("Get container ID for individual container tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + testCases := []struct { + name string + containerID string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch container with valid ID and token", + containerID: containerID, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return container details", + }, + { + name: "Unauthorized request without token", + containerID: containerID, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Request with invalid container ID", + containerID: "invalid-container-id", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container ID is invalid/doesnt exist", + }, + { + name: "Request with container ID doesnt exist", + containerID: "1234567890123456789012345678901234567890123456789012345678901234", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container doesnt exist", + }, + { + name: "Request without organization header", + containerID: containerID, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Skip tests that depend on valid container ID if we couldn't get one + if tc.containerID == containerID && containerID == "" { + t.Skip("No container ID available for testing") + } + + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetContainerURL(tc.containerID)), + } + + // Add authentication header if token is provided + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + // Add organization header if provided + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + // Additional validations for successful response + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + Expect().Body().JSON().JQ(".data.id").Equal(tc.containerID), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetContainerDetailedValidation(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // Get the test container ID specifically + var containerID string + Test(t, + Description("Get test container ID for detailed validation"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(`.data[] | select(.name == "nixopus-test-db-container") | .id`).In(&containerID), + ) + + if containerID == "" { + t.Skip("nixopus-test-db-container not found, skipping detailed validation") + } + + t.Run("Validate complete container structure for test container", func(t *testing.T) { + Test(t, + Description("Should return complete container structure with all expected fields"), + Get(tests.GetContainerURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container fetched successfully"), + Expect().Body().JSON().JQ(".data.name").Equal("nixopus-test-db-container"), + Expect().Body().JSON().JQ(".data.image").Equal("postgres:14-alpine"), + Expect().Body().JSON().JQ(".data.command").NotEqual(""), + Expect().Body().JSON().JQ(".data.status").NotEqual(""), + Expect().Body().JSON().JQ(".data.state").NotEqual(""), + Expect().Body().JSON().JQ(".data.created").NotEqual(""), + Expect().Body().JSON().JQ(".data.labels").NotEqual(nil), + Expect().Body().JSON().JQ(".data.ports").NotEqual(nil), + Expect().Body().JSON().JQ(".data.mounts").NotEqual(nil), + Expect().Body().JSON().JQ(".data.networks").NotEqual(nil), + Expect().Body().JSON().JQ(".data.host_config").NotEqual(nil), + + Expect().Body().JSON().JQ(".data.ports[0].private_port").Equal(float64(5432)), + Expect().Body().JSON().JQ(".data.ports[0].public_port").Equal(float64(5433)), + Expect().Body().JSON().JQ(".data.ports[0].type").Equal("tcp"), + + Expect().Body().JSON().JQ(".data.host_config.memory").NotEqual(nil), + Expect().Body().JSON().JQ(".data.host_config.memory_swap").NotEqual(nil), + Expect().Body().JSON().JQ(".data.host_config.cpu_shares").NotEqual(nil), + ) + }) +} + +func TestGetContainerErrorScenarios(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Container ID with special characters", func(t *testing.T) { + Test(t, + Description("Should handle container ID with special characters"), + Get(tests.GetContainerURL("container-special")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) + + t.Run("Empty container ID", func(t *testing.T) { + Test(t, + Description("Should handle empty container ID"), + Get(tests.GetContainerURL("")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusNotFound), + ) + }) + + t.Run("Very long container ID", func(t *testing.T) { + longID := "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890" + Test(t, + Description("Should handle very long container ID"), + Get(tests.GetContainerURL(longID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) +} diff --git a/api/internal/tests/container/list_containers_test.go b/api/internal/tests/container/list_containers_test.go new file mode 100644 index 00000000..093dbe32 --- /dev/null +++ b/api/internal/tests/container/list_containers_test.go @@ -0,0 +1,156 @@ +package container + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestListContainers(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch containers with valid token", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return containers list with valid authentication, basically return one container which is DB test container that is up and running", + }, + { + name: "Unauthorized request without token", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Request with invalid organization ID", + token: user.AccessToken, + organizationID: "invalid-org-id", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when organization ID format is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetContainersURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Containers fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestListContainersWithSpecificContainer(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Verify test container exists and has expected properties", func(t *testing.T) { + Test(t, + Description("Should find the nixopus-test-db-container and validate its properties"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Containers fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + }) +} + +func TestListContainersErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + Test(t, + Description("Should handle malformed authorization header gracefully"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + Test(t, + Description("Should handle empty authorization header"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Bearer token with extra spaces", func(t *testing.T) { + Test(t, + Description("Should handle get containers base case"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + ) + }) +} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index 2272d9e6..2717b777 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -64,4 +64,12 @@ func GetUserDetailsURL() string { func GetIsAdminRegisteredURL() string { return baseURL + "/auth/is-admin-registered" +} + +func GetContainersURL() string { + return baseURL + "/container" +} + +func GetContainerURL(containerID string) string { + return baseURL + "/container/" + containerID } \ No newline at end of file diff --git a/docker-compose-test.yml b/docker-compose-test.yml new file mode 100644 index 00000000..c744dd92 --- /dev/null +++ b/docker-compose-test.yml @@ -0,0 +1,19 @@ +version: "3.8" + +services: + nixopus-test-db: + image: postgres:14-alpine + container_name: nixopus-test-db-container + ports: + - "${TEST_DB_PORT:-5433}:5432" + restart: unless-stopped + environment: + - POSTGRES_USER=${TEST_DB_USERNAME:-nixopus} + - POSTGRES_PASSWORD=${TEST_DB_PASSWORD:-nixopus} + - POSTGRES_DB=${TEST_DB_NAME:-nixopus_test} + networks: + - nixopus-network + +networks: + nixopus-network: + driver: bridge From f0b0d88825fd110ff48b47caa7997c34e5fee5e4 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Sun, 29 Jun 2025 21:27:27 +0530 Subject: [PATCH 02/72] test-cases: E2E for container logs flow --- api/api/versions.json | 2 +- .../container/get_container_logs_test.go | 397 ++++++++++++++++++ api/internal/tests/helper.go | 4 + 3 files changed, 402 insertions(+), 1 deletion(-) create mode 100644 api/internal/tests/container/get_container_logs_test.go diff --git a/api/api/versions.json b/api/api/versions.json index ccc72edb..0694921f 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-29T19:08:38.461985+05:30", + "release_date": "2025-06-29T20:43:09.999966+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go new file mode 100644 index 00000000..464d8af1 --- /dev/null +++ b/api/internal/tests/container/get_container_logs_test.go @@ -0,0 +1,397 @@ +package container + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetContainerLogs(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, get a container ID from the list + var containerID string + Test(t, + Description("Get container ID for logs tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + testCases := []struct { + name string + containerID string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch container logs with valid ID and token", + containerID: containerID, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return container logs with valid authentication", + }, + { + name: "Unauthorized request without token", + containerID: containerID, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + containerID: containerID, + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + containerID: containerID, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Request with invalid container ID", + containerID: "invalid-container-id", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container ID doesn't exist", + }, + { + name: "Request with empty container ID", + containerID: "", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container ID is empty", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetContainerLogsURL(tc.containerID)), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + // Add JSON body with container logs request + requestBody := map[string]interface{}{ + "id": tc.containerID, + "follow": false, + "tail": 100, + "stdout": true, + "stderr": true, + } + testSteps = append(testSteps, Send().Body().JSON(requestBody)) + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetContainerLogsWithFilters(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, get a container ID from the list + var containerID string + Test(t, + Description("Get container ID for logs filter tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + t.Run("Fetch logs with tail parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "tail": 50, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return limited number of log lines when tail parameter is provided"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + }) + + t.Run("Fetch logs with since parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "since": "2024-01-01T00:00:00Z", + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return logs since specified timestamp"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + ) + }) + + t.Run("Fetch logs with timestamps", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return logs with timestamps when timestamps=true"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + ) + }) + + t.Run("Fetch logs with follow parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle follow parameter for streaming logs"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + ) + }) +} + +func TestGetContainerLogsErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle malformed authorization header gracefully"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle empty authorization header"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Invalid UUID format for container ID", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "not-a-uuid", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle invalid UUID format for container ID"), + Post(tests.GetContainerLogsURL("not-a-uuid")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) + + t.Run("Non-existent container ID with valid UUID format", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "123e4567-e89b-12d3-a456-426614174000", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return 500 for non-existent container with valid UUID format"), + Post(tests.GetContainerLogsURL("123e4567-e89b-12d3-a456-426614174000")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) + + t.Run("Invalid tail parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "tail": "invalid-number", // This should cause an error since tail expects int + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle invalid tail parameter gracefully"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) + + t.Run("Invalid since parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "since": "invalid-timestamp", + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle invalid since timestamp parameter"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) +} + +func TestGetContainerLogsPermissions(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // Get a container ID + var containerID string + Test(t, + Description("Get container ID for permission tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + t.Run("Access logs with organization member permissions", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should allow organization members to access container logs"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + ) + }) + + t.Run("Cross-organization access attempt", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should deny access to logs from different organization"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusForbidden), + ) + }) +} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index 2717b777..e23685c8 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -72,4 +72,8 @@ func GetContainersURL() string { func GetContainerURL(containerID string) string { return baseURL + "/container/" + containerID +} + +func GetContainerLogsURL(containerID string) string { + return baseURL + "/container/" + containerID + "/logs" } \ No newline at end of file From 4dcd59220af468aa73611e7f3e1c64e286b87252 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:21:57 +0530 Subject: [PATCH 03/72] test-cases: E2E test cases for Domain and Container flow --- api/api/versions.json | 2 +- .../domain/controller/create_domain.go | 15 + .../domain/controller/delete_domain.go | 15 + .../features/domain/controller/get_domains.go | 23 +- .../domain/controller/update_domain.go | 15 + api/internal/features/domain/storage/init.go | 31 +- .../container/get_container_logs_test.go | 9 +- api/internal/tests/domain/domain_flow_test.go | 880 ++++++++++++++++++ api/internal/tests/helper.go | 12 + 9 files changed, 983 insertions(+), 19 deletions(-) create mode 100644 api/internal/tests/domain/domain_flow_test.go diff --git a/api/api/versions.json b/api/api/versions.json index 0694921f..0eca3347 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-29T20:43:09.999966+05:30", + "release_date": "2025-06-30T00:19:14.614053+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/features/domain/controller/create_domain.go b/api/internal/features/domain/controller/create_domain.go index 2916c951..655cbcfb 100644 --- a/api/internal/features/domain/controller/create_domain.go +++ b/api/internal/features/domain/controller/create_domain.go @@ -42,6 +42,21 @@ func (c *DomainsController) CreateDomain(f fuego.ContextWithBody[types.CreateDom if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if err == types.ErrDomainAlreadyExists { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusConflict, + } + } + + if err == types.ErrDomainNameInvalid || err == types.ErrDomainNameTooLong || err == types.ErrDomainNameTooShort || err == types.ErrMissingDomainName { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusBadRequest, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/controller/delete_domain.go b/api/internal/features/domain/controller/delete_domain.go index ce8703bb..c8c0ff36 100644 --- a/api/internal/features/domain/controller/delete_domain.go +++ b/api/internal/features/domain/controller/delete_domain.go @@ -31,6 +31,21 @@ func (c *DomainsController) DeleteDomain(f fuego.ContextWithBody[types.DeleteDom err = c.service.DeleteDomain(domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + // TODO: Util to handle err-status mapping + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + + if err == types.ErrInvalidDomainID || err == types.ErrMissingDomainID { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusBadRequest, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/controller/get_domains.go b/api/internal/features/domain/controller/get_domains.go index 4671d940..d39173ef 100644 --- a/api/internal/features/domain/controller/get_domains.go +++ b/api/internal/features/domain/controller/get_domains.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-fuego/fuego" + "github.com/google/uuid" "github.com/raghavyuva/nixopus-api/internal/features/domain/types" "github.com/raghavyuva/nixopus-api/internal/features/logger" "github.com/raghavyuva/nixopus-api/internal/utils" @@ -15,10 +16,16 @@ import ( ) func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Response, error) { - organization_id := f.QueryParam("id") - w, r := f.Response(), f.Request() + organization_id := utils.GetOrganizationID(r) + if organization_id == uuid.Nil { + return nil, fuego.HTTPError{ + Err: nil, + Status: http.StatusBadRequest, + } + } + user := utils.GetUser(w, r) if user == nil { @@ -30,7 +37,7 @@ func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Res c.logger.Log(logger.Info, "fetching domains", fmt.Sprintf("organization_id: %s", organization_id)) - domains, err := c.service.GetDomains(organization_id, user.ID) + domains, err := c.service.GetDomains(organization_id.String(), user.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") return nil, fuego.HTTPError{ @@ -49,9 +56,15 @@ func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Res func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*shared_types.Response, error) { w, r := f.Response(), f.Request() - organization_id := f.QueryParam("id") + organization_id := utils.GetOrganizationID(r) + if organization_id == uuid.Nil { + return nil, fuego.HTTPError{ + Err: nil, + Status: http.StatusBadRequest, + } + } - domains, err := c.service.GetDomains(organization_id, utils.GetUser(w, r).ID) + domains, err := c.service.GetDomains(organization_id.String(), utils.GetUser(w, r).ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") return nil, fuego.HTTPError{ diff --git a/api/internal/features/domain/controller/update_domain.go b/api/internal/features/domain/controller/update_domain.go index ce25def2..9df1e20d 100644 --- a/api/internal/features/domain/controller/update_domain.go +++ b/api/internal/features/domain/controller/update_domain.go @@ -41,6 +41,21 @@ func (c *DomainsController) UpdateDomain(f fuego.ContextWithBody[types.UpdateDom updated, err := c.service.UpdateDomain(domainRequest.Name, user.ID.String(), domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + + if err == types.ErrInvalidDomainID || err == types.ErrMissingDomainID || err == types.ErrDomainNameInvalid || err == types.ErrDomainNameTooLong || err == types.ErrDomainNameTooShort || err == types.ErrMissingDomainName { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusBadRequest, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/storage/init.go b/api/internal/features/domain/storage/init.go index e4152799..f0d7ed9a 100644 --- a/api/internal/features/domain/storage/init.go +++ b/api/internal/features/domain/storage/init.go @@ -60,7 +60,7 @@ func (s *DomainStorage) CreateDomain(domain *shared_types.Domain) error { func (s *DomainStorage) GetDomain(id string) (*shared_types.Domain, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", id).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", id).Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, types.ErrDomainNotFound @@ -72,13 +72,13 @@ func (s *DomainStorage) GetDomain(id string) (*shared_types.Domain, error) { func (s *DomainStorage) UpdateDomain(ID string, Name string) error { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) if err != nil { return err } domain.Name = Name domain.UpdatedAt = time.Now() - _, err = s.getDB().NewUpdate().Model(&domain).Where("id = ?", ID).Exec(s.Ctx) + _, err = s.getDB().NewUpdate().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Exec(s.Ctx) if err != nil { return err } @@ -86,17 +86,32 @@ func (s *DomainStorage) UpdateDomain(ID string, Name string) error { } func (s *DomainStorage) DeleteDomain(domain *shared_types.Domain) error { - _, err := s.getDB().NewDelete().Model(domain).Where("id = ?", domain.ID).Exec(s.Ctx) + now := time.Now() + result, err := s.getDB().NewUpdate().Model(domain). + Set("deleted_at = ?", now). + Set("updated_at = ?", now). + Where("id = ? AND deleted_at IS NULL", domain.ID). + Exec(s.Ctx) if err != nil { return err } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return err + } + + if rowsAffected == 0 { + return types.ErrDomainNotFound + } + return nil } func (s *DomainStorage) GetDomains(OrganizationID string, UserID uuid.UUID) ([]shared_types.Domain, error) { var domains []shared_types.Domain err := s.getDB().NewSelect().Model(&domains). - Where("organization_id = ?", OrganizationID). + Where("organization_id = ? AND deleted_at IS NULL", OrganizationID). Scan(s.Ctx) if err != nil { return nil, err @@ -107,7 +122,7 @@ func (s *DomainStorage) GetDomains(OrganizationID string, UserID uuid.UUID) ([]s func (s *DomainStorage) GetDomainByName(name string, organizationID uuid.UUID) (*shared_types.Domain, error) { var domain shared_types.Domain err := s.getDB().NewSelect().Model(&domain). - Where("name = ? AND organization_id = ?", name, organizationID). + Where("name = ? AND organization_id = ? AND deleted_at IS NULL", name, organizationID). Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -120,7 +135,7 @@ func (s *DomainStorage) GetDomainByName(name string, organizationID uuid.UUID) ( func (s *DomainStorage) IsDomainExists(ID string) (bool, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { return false, nil @@ -132,7 +147,7 @@ func (s *DomainStorage) IsDomainExists(ID string) (bool, error) { func (s *DomainStorage) GetDomainOwnerByID(ID string) (string, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) if err != nil { return "", err } diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go index 464d8af1..4de68137 100644 --- a/api/internal/tests/container/get_container_logs_test.go +++ b/api/internal/tests/container/get_container_logs_test.go @@ -18,10 +18,12 @@ func TestGetContainerLogs(t *testing.T) { orgID := org.ID.String() - // First, get a container ID from the list + // Note: First, get a container ID from the list; sue the same for test validation (PSQL test db container) + // Test casess are designed to work with an existing container. + // TODO: @shravan20 - Run a script on pre running E2E tests to create a containers & add as DB seeding var containerID string Test(t, - Description("Get container ID for logs tests"), + Description("Get container id for logs tests"), Get(tests.GetContainersURL()), Send().Headers("Authorization").Add("Bearer "+user.AccessToken), Send().Headers("X-Organization-Id").Add(orgID), @@ -102,7 +104,6 @@ func TestGetContainerLogs(t *testing.T) { testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) } - // Add JSON body with container logs request requestBody := map[string]interface{}{ "id": tc.containerID, "follow": false, @@ -136,7 +137,6 @@ func TestGetContainerLogsWithFilters(t *testing.T) { orgID := org.ID.String() - // First, get a container ID from the list var containerID string Test(t, Description("Get container ID for logs filter tests"), @@ -349,7 +349,6 @@ func TestGetContainerLogsPermissions(t *testing.T) { orgID := org.ID.String() - // Get a container ID var containerID string Test(t, Description("Get container ID for permission tests"), diff --git a/api/internal/tests/domain/domain_flow_test.go b/api/internal/tests/domain/domain_flow_test.go new file mode 100644 index 00000000..05003077 --- /dev/null +++ b/api/internal/tests/domain/domain_flow_test.go @@ -0,0 +1,880 @@ +package domain + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestCreateDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + domainName string + organizationID string + token string + expectedStatus int + description string + }{ + { + name: "Successfully create domain with valid data", + domainName: "test-domain.nixopus.dev", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusOK, + description: "Should create domain successfully with valid data", + }, + { + name: "Create domain with subdomain", + domainName: "api.test-domain.nixopus.dev", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusOK, + description: "Should create subdomain successfully", + }, + { + name: "Unauthorized request without token", + domainName: "unauthorized.nixopus.dev", + organizationID: orgID, + token: "", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + domainName: "invalid-token.nixopus.dev", + organizationID: orgID, + token: "invalid-token", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + domainName: "no-org.nixopus.dev", + organizationID: "", + token: user.AccessToken, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Create domain with empty name", + domainName: "", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name is empty", + }, + { + name: "Create domain with invalid name format", + domainName: "invalid..domain", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name format is invalid", + }, + { + name: "Create duplicate domain", + domainName: "test-domain.nixopus.dev", // Same as first test case + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusConflict, + description: "Should return 409 when domain already exists", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "name": tc.domainName, + "organization_id": tc.organizationID, + } + + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetDomainURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain created successfully"), + Expect().Body().JSON().JQ(".data.id").NotEqual(""), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetDomains(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, create a test domain + createDomainRequest := map[string]interface{}{ + "name": "list-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a test domain for listing"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest), + Expect().Status().Equal(http.StatusOK), + ) + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch domains with valid token", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return domains list with valid authentication", + }, + { + name: "Unauthorized request without token", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Cross-organization access attempt", + token: user.AccessToken, + organizationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusForbidden, + description: "Should deny access to domains from different organization", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetDomainsURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domains fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestUpdateDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, create a test domain to update + var domainID string + createDomainRequest := map[string]interface{}{ + "name": "update-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a test domain for updating"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID), + ) + + testCases := []struct { + name string + domainID string + newName string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully update domain with valid data", + domainID: domainID, + newName: "updated-domain.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should update domain successfully with valid data", + }, + { + name: "Update domain with subdomain", + domainID: domainID, + newName: "api.updated-domain.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should update domain to subdomain successfully", + }, + { + name: "Unauthorized request without token", + domainID: domainID, + newName: "unauthorized-update.nixopus.dev", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + domainID: domainID, + newName: "invalid-token-update.nixopus.dev", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + domainID: domainID, + newName: "no-org-update.nixopus.dev", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Update domain with empty name", + domainID: domainID, + newName: "", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name is empty", + }, + { + name: "Update domain with invalid name format", + domainID: domainID, + newName: "invalid..domain", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name format is invalid", + }, + { + name: "Update non-existent domain", + domainID: "123e4567-e89b-12d3-a456-426614174000", + newName: "non-existent-update.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusNotFound, + description: "Should return 404 when domain doesn't exist", + }, + { + name: "Update domain with invalid ID format", + domainID: "invalid-id", + newName: "invalid-id-update.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain ID format is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": tc.domainID, + "name": tc.newName, + } + + testSteps := []IStep{ + Description(tc.description), + Put(tests.GetDomainURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain updated successfully"), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestDeleteDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // Create test domains for deletion + var domainID1, domainID2 string + + createDomainRequest1 := map[string]interface{}{ + "name": "delete-test1.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create first test domain for deletion"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest1), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID1), + ) + + createDomainRequest2 := map[string]interface{}{ + "name": "delete-test2.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create second test domain for deletion"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest2), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID2), + ) + + testCases := []struct { + name string + domainID string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully delete domain with valid ID", + domainID: domainID1, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should delete domain successfully with valid ID", + }, + { + name: "Unauthorized request without token", + domainID: domainID2, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + domainID: domainID2, + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + domainID: domainID2, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Delete non-existent domain", + domainID: "123e4567-e89b-12d3-a456-426614174000", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusNotFound, + description: "Should return 404 when domain doesn't exist", + }, + { + name: "Delete domain with invalid ID format", + domainID: "invalid-id", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain ID format is invalid", + }, + { + name: "Delete already deleted domain", + domainID: domainID1, // Already deleted in first test case so expcected to throw 404 + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusNotFound, + description: "Should return 404 when trying to delete already deleted domain", + }, + { + name: "Successfully delete second domain", + domainID: domainID2, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should delete second domain successfully", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": tc.domainID, + } + + testSteps := []IStep{ + Description(tc.description), + Delete(tests.GetDomainURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain deleted successfully"), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGenerateRandomSubDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // first create a domain then generating subdomains + createRequest := map[string]interface{}{ + "name": "base-domain.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a base domain for subdomain generation"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + ) + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully generate random subdomain", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should generate random subdomain successfully", + }, + { + name: "Unauthorized request without token", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetDomainGenerateURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Random subdomain generated successfully"), + Expect().Body().JSON().JQ(".data.subdomain").NotEqual(""), + Expect().Body().JSON().JQ(".data.domain").NotEqual(""), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestDomainsCRUDFlow(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Validate CRUD flow for domains", func(t *testing.T) { + var domainID string + + // creating a domain + createRequest := map[string]interface{}{ + "name": "crud-flow.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a new domain"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain created successfully"), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID), + ) + + // check listing if added once in available or not + Test(t, + Description("Verify domain appears in domains listing"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + Expect().Body().JSON().JQ(".data[0].id").NotEqual(nil), + ) + + updateRequest := map[string]interface{}{ + "id": domainID, + "name": "updated-crud-flow.nixopus.dev", + } + + Test(t, + Description("Update the domain"), + Put(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(updateRequest), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain updated successfully"), + ) + + // Cross check domain update in listing + Test(t, + Description("Verify domain update appears in domains listing"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + // assert agaisnst the updated domain name + Expect().Body().JSON().JQ(".data[0].name").Equal("updated-crud-flow.nixopus.dev"), + ) + + // Step 5: Delete the domain + deleteRequest := map[string]interface{}{ + "id": domainID, + } + + Test(t, + Description("Step 5: Delete the domain"), + Delete(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(deleteRequest), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain deleted successfully"), + ) + + // Step 6: Verify domain is removed from listing + Test(t, + Description("Step 6: Verify domain is removed from domains listing"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + // Verify the domain list is empty after deletion (could be null or empty array) + // Just check that the response is successful, domains being null indicates empty list + ) + }) +} + +func TestDomainPermissions(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Domain permissions and organization isolation", func(t *testing.T) { + var domainID string + + // Create a domain in the user's organization + createRequest := map[string]interface{}{ + "name": "permissions-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create domain in user's organization"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID), + ) + + // Try to access with different organization ID + Test(t, + Description("Should deny access to domains from different organization"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Try to update domain from different organization id + updateRequest := map[string]interface{}{ + "id": domainID, + "name": "unauthorized-update.nixopus.dev", + } + + Test(t, + Description("Should deny domain update from different organization"), + Put(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(updateRequest), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Try to delete domain from different organization Id + deleteRequest := map[string]interface{}{ + "id": domainID, + } + + Test(t, + Description("Should deny domain deletion from different organization"), + Delete(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(deleteRequest), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Clean up: Delete the domain with correct organization id + Test(t, + Description("Clean up: Delete domain with correct organization"), + Delete(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(deleteRequest), + Expect().Status().Equal(http.StatusOK), + ) + }) +} + +func TestDomainErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + Test(t, + Description("Should handle malformed authorization header gracefully"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + Test(t, + Description("Should handle empty authorization header"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Missing Content-Type header for POST requests", func(t *testing.T) { + createRequest := map[string]interface{}{ + "name": "content-type-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Should handle missing Content-Type header"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + ) + }) + + t.Run("Invalid JSON payload", func(t *testing.T) { + Test(t, + Description("Should handle invalid JSON payload"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().String("{invalid-json}"), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) + + t.Run("Very long domain name", func(t *testing.T) { + longDomainName := "" + for i := 0; i < 300; i++ { + longDomainName += "a" + } + longDomainName += ".nixopus.dev" + + createRequest := map[string]interface{}{ + "name": longDomainName, + "organization_id": orgID, + } + + Test(t, + Description("Should throw an error for very long domain names"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) +} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index e23685c8..71176885 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -76,4 +76,16 @@ func GetContainerURL(containerID string) string { func GetContainerLogsURL(containerID string) string { return baseURL + "/container/" + containerID + "/logs" +} + +func GetDomainURL() string { + return baseURL + "/domain" +} + +func GetDomainsURL() string { + return baseURL + "/domains" +} + +func GetDomainGenerateURL() string { + return baseURL + "/domain/generate" } \ No newline at end of file From 5bd8a594da2b84cbb6ceb73267f8630b366143da Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:23:03 +0530 Subject: [PATCH 04/72] test-cases: E2E for container logs flow --- api/internal/tests/domain/domain_flow_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/internal/tests/domain/domain_flow_test.go b/api/internal/tests/domain/domain_flow_test.go index 05003077..c459ccb3 100644 --- a/api/internal/tests/domain/domain_flow_test.go +++ b/api/internal/tests/domain/domain_flow_test.go @@ -734,7 +734,7 @@ func TestDomainPermissions(t *testing.T) { t.Run("Domain permissions and organization isolation", func(t *testing.T) { var domainID string - // Create a domain in the user's organization + // Create a domain in the user' organization createRequest := map[string]interface{}{ "name": "permissions-test.nixopus.dev", "organization_id": orgID, From 88ce5a5a1a99fa4c2deb48df2bc59a6afd4a1b56 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:23:20 +0530 Subject: [PATCH 05/72] test-cases: E2E for container logs flow --- api/api/versions.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index 0eca3347..8c0cd580 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -5,9 +5,7 @@ "status": "active", "release_date": "2025-06-30T00:19:14.614053+05:30", "end_of_life": "0001-01-01T00:00:00Z", - "changes": [ - "Initial API version" - ] + "changes": ["Initial API version"] } ] -} \ No newline at end of file +} From cf5e69d6bda506a8ce43998f479442f28a8a1876 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:29:46 +0530 Subject: [PATCH 06/72] test-cases: E2E for container logs flow --- api/api/versions.json | 8 +++++--- api/internal/routes.go | 13 +++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index 8c0cd580..08dcb5cc 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,9 +3,11 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T00:19:14.614053+05:30", + "release_date": "2025-06-30T00:29:19.828182+05:30", "end_of_life": "0001-01-01T00:00:00Z", - "changes": ["Initial API version"] + "changes": [ + "Initial API version" + ] } ] -} +} \ No newline at end of file diff --git a/api/internal/routes.go b/api/internal/routes.go index bc5d1ccc..ba98fe51 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -68,25 +68,18 @@ func (router *Router) Routes() { if PORT == "" { PORT = "8080" } - + // Build server address based on environment ENV := os.Getenv("ENV") HOST := os.Getenv("HOST") - var serverAddr string - + var serverAddr string = "" + switch ENV { case "production": - // In production, use the HOST env var or empty for all interfaces if HOST != "" { serverAddr = HOST + ":" + PORT - } else { - serverAddr = ":" + PORT } - case "development": - // In development, use localhost - serverAddr = "localhost:" + PORT default: - // Default to localhost for local development serverAddr = "localhost:" + PORT } From c6e4ffeaf95cfd32185e37de902745c110677c45 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:31:54 +0530 Subject: [PATCH 07/72] test-cases: E2E for container logs flow --- api/api/versions.json | 2 +- api/internal/routes.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/api/api/versions.json b/api/api/versions.json index 08dcb5cc..70ae60fb 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T00:29:19.828182+05:30", + "release_date": "2025-06-30T00:29:49.566331+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/routes.go b/api/internal/routes.go index ba98fe51..57151f46 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -78,6 +78,8 @@ func (router *Router) Routes() { case "production": if HOST != "" { serverAddr = HOST + ":" + PORT + } else { + serverAddr = "localhost:" + PORT } default: serverAddr = "localhost:" + PORT From 7d7907e97a02682a6522f9050fa59a3a83276dd5 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:34:10 +0530 Subject: [PATCH 08/72] test-cases: E2E for container logs flow --- api/api/versions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/api/versions.json b/api/api/versions.json index 70ae60fb..c721238d 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T00:29:49.566331+05:30", + "release_date": "2025-06-30T00:33:34.108486+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" From b210ac0e9cdb425a0e1650b58ae971b6f9e3c1ff Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:34:22 +0530 Subject: [PATCH 09/72] test-cases: E2E for container logs flow --- api/api/versions.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index c721238d..f10e1f29 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -5,9 +5,7 @@ "status": "active", "release_date": "2025-06-30T00:33:34.108486+05:30", "end_of_life": "0001-01-01T00:00:00Z", - "changes": [ - "Initial API version" - ] + "changes": ["Initial API version"] } ] -} \ No newline at end of file +} From af923ac0a1a3aaa44810564217106a79e57ac00b Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:35:44 +0530 Subject: [PATCH 10/72] test-cases: E2E for container logs flow --- api/internal/tests/container/get_container_logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go index 4de68137..91375b4c 100644 --- a/api/internal/tests/container/get_container_logs_test.go +++ b/api/internal/tests/container/get_container_logs_test.go @@ -20,7 +20,7 @@ func TestGetContainerLogs(t *testing.T) { // Note: First, get a container ID from the list; sue the same for test validation (PSQL test db container) // Test casess are designed to work with an existing container. - // TODO: @shravan20 - Run a script on pre running E2E tests to create a containers & add as DB seeding + // TODO: Run a script on pre running E2E tests to create a containers & add as DB seeding var containerID string Test(t, Description("Get container id for logs tests"), From b79863fafb7e71c881c13dd80ae700549aeab4c5 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:36:25 +0530 Subject: [PATCH 11/72] sefl-review: fix typo --- api/internal/tests/container/get_container_logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go index 91375b4c..e4f306b6 100644 --- a/api/internal/tests/container/get_container_logs_test.go +++ b/api/internal/tests/container/get_container_logs_test.go @@ -19,7 +19,7 @@ func TestGetContainerLogs(t *testing.T) { orgID := org.ID.String() // Note: First, get a container ID from the list; sue the same for test validation (PSQL test db container) - // Test casess are designed to work with an existing container. + // Test cases are designed to work with an existing container. // TODO: Run a script on pre running E2E tests to create a containers & add as DB seeding var containerID string Test(t, From 66490eb9d40513d71c292bb293d2809f37e69307 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:36:52 +0530 Subject: [PATCH 12/72] sefl-review: fix typo --- api/internal/tests/container/get_container_logs_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go index e4f306b6..067889bc 100644 --- a/api/internal/tests/container/get_container_logs_test.go +++ b/api/internal/tests/container/get_container_logs_test.go @@ -307,7 +307,7 @@ func TestGetContainerLogsErrorHandling(t *testing.T) { requestBody := map[string]interface{}{ "id": "some-container-id", "follow": false, - "tail": "invalid-number", // This should cause an error since tail expects int + "tail": "invalid-number", // should throw an error since tail expects int "stdout": true, "stderr": true, } From 715b5a74e4597bd47fee14057ab5f31f3218a96b Mon Sep 17 00:00:00 2001 From: shravan20 Date: Mon, 30 Jun 2025 00:52:15 +0530 Subject: [PATCH 13/72] sefl-review: remove switch to simple if else --- api/api/versions.json | 8 +++++--- api/internal/routes.go | 11 +++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index f10e1f29..a6ba9e0f 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,9 +3,11 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T00:33:34.108486+05:30", + "release_date": "2025-06-30T00:51:43.573216+05:30", "end_of_life": "0001-01-01T00:00:00Z", - "changes": ["Initial API version"] + "changes": [ + "Initial API version" + ] } ] -} +} \ No newline at end of file diff --git a/api/internal/routes.go b/api/internal/routes.go index 57151f46..f3fa86c6 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -74,14 +74,9 @@ func (router *Router) Routes() { HOST := os.Getenv("HOST") var serverAddr string = "" - switch ENV { - case "production": - if HOST != "" { - serverAddr = HOST + ":" + PORT - } else { - serverAddr = "localhost:" + PORT - } - default: + if ENV == "production" && HOST != "" { + serverAddr = HOST + ":" + PORT + } else { serverAddr = "localhost:" + PORT } From ed03066305569aec4e52c20ffc5507f64ee06670 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Wed, 2 Jul 2025 04:06:26 +0530 Subject: [PATCH 14/72] pr-review: addressed comments --- api/api/versions.json | 2 +- .../domain/controller/create_domain.go | 8 +-- .../domain/controller/delete_domain.go | 10 ++-- .../domain/controller/error_helpers.go | 27 +++++++++ .../features/domain/controller/get_domains.go | 57 ++++++++++++++++--- .../domain/controller/update_domain.go | 8 +-- .../self-host/hooks/use_create_deployment.ts | 1 - .../self-host/hooks/use_update_deployment.ts | 2 +- .../domains/components/delete-domain.tsx | 2 +- view/app/settings/domains/page.tsx | 2 +- .../domains/random-subdomain-generator.tsx | 56 ++++++++++++++++++ view/redux/services/settings/domainsApi.ts | 35 +++++++----- view/redux/types/domain.ts | 19 +++++++ 13 files changed, 190 insertions(+), 39 deletions(-) create mode 100644 api/internal/features/domain/controller/error_helpers.go create mode 100644 view/components/domains/random-subdomain-generator.tsx diff --git a/api/api/versions.json b/api/api/versions.json index a6ba9e0f..9d924fbc 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T00:51:43.573216+05:30", + "release_date": "2025-07-02T04:06:05.74728+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/features/domain/controller/create_domain.go b/api/internal/features/domain/controller/create_domain.go index 655cbcfb..0668b693 100644 --- a/api/internal/features/domain/controller/create_domain.go +++ b/api/internal/features/domain/controller/create_domain.go @@ -43,17 +43,17 @@ func (c *DomainsController) CreateDomain(f fuego.ContextWithBody[types.CreateDom if err != nil { c.logger.Log(logger.Error, err.Error(), "") - if err == types.ErrDomainAlreadyExists { + if isInvalidDomainError(err) { return nil, fuego.HTTPError{ Err: err, - Status: http.StatusConflict, + Status: http.StatusBadRequest, } } - if err == types.ErrDomainNameInvalid || err == types.ErrDomainNameTooLong || err == types.ErrDomainNameTooShort || err == types.ErrMissingDomainName { + if err == types.ErrDomainAlreadyExists { return nil, fuego.HTTPError{ Err: err, - Status: http.StatusBadRequest, + Status: http.StatusConflict, } } diff --git a/api/internal/features/domain/controller/delete_domain.go b/api/internal/features/domain/controller/delete_domain.go index c8c0ff36..1890d9d3 100644 --- a/api/internal/features/domain/controller/delete_domain.go +++ b/api/internal/features/domain/controller/delete_domain.go @@ -31,18 +31,18 @@ func (c *DomainsController) DeleteDomain(f fuego.ContextWithBody[types.DeleteDom err = c.service.DeleteDomain(domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") - // TODO: Util to handle err-status mapping - if err == types.ErrDomainNotFound { + + if isInvalidDomainError(err) { return nil, fuego.HTTPError{ Err: err, - Status: http.StatusNotFound, + Status: http.StatusBadRequest, } } - if err == types.ErrInvalidDomainID || err == types.ErrMissingDomainID { + if err == types.ErrDomainNotFound { return nil, fuego.HTTPError{ Err: err, - Status: http.StatusBadRequest, + Status: http.StatusNotFound, } } diff --git a/api/internal/features/domain/controller/error_helpers.go b/api/internal/features/domain/controller/error_helpers.go new file mode 100644 index 00000000..05e70c0b --- /dev/null +++ b/api/internal/features/domain/controller/error_helpers.go @@ -0,0 +1,27 @@ +package controller + +import "github.com/raghavyuva/nixopus-api/internal/features/domain/types" + +func isInvalidDomainError(err error) bool { + switch err { + case types.ErrInvalidDomainID, + types.ErrMissingDomainID, + types.ErrDomainNameInvalid, + types.ErrDomainNameTooLong, + types.ErrDomainNameTooShort, + types.ErrMissingDomainName: + return true + default: + return false + } +} + +func isPermissionError(err error) bool { + switch err { + case types.ErrUserDoesNotBelongToOrganization, + types.ErrPermissionDenied: + return true + default: + return false + } +} diff --git a/api/internal/features/domain/controller/get_domains.go b/api/internal/features/domain/controller/get_domains.go index d39173ef..b964b946 100644 --- a/api/internal/features/domain/controller/get_domains.go +++ b/api/internal/features/domain/controller/get_domains.go @@ -20,17 +20,18 @@ func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Res organization_id := utils.GetOrganizationID(r) if organization_id == uuid.Nil { + c.logger.Log(logger.Error, "invalid organization id", "") return nil, fuego.HTTPError{ - Err: nil, + Err: types.ErrMissingID, Status: http.StatusBadRequest, } } user := utils.GetUser(w, r) - if user == nil { + c.logger.Log(logger.Error, "unauthorized user", "") return nil, fuego.HTTPError{ - Err: nil, + Err: types.ErrAccessDenied, Status: http.StatusUnauthorized, } } @@ -40,6 +41,21 @@ func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Res domains, err := c.service.GetDomains(organization_id.String(), user.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isPermissionError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusForbidden, + } + } + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, @@ -58,15 +74,40 @@ func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*sha organization_id := utils.GetOrganizationID(r) if organization_id == uuid.Nil { + c.logger.Log(logger.Error, "invalid organization id", "") return nil, fuego.HTTPError{ - Err: nil, + Err: types.ErrMissingID, Status: http.StatusBadRequest, } } - domains, err := c.service.GetDomains(organization_id.String(), utils.GetUser(w, r).ID) + user := utils.GetUser(w, r) + if user == nil { + c.logger.Log(logger.Error, "unauthorized user", "") + return nil, fuego.HTTPError{ + Err: types.ErrAccessDenied, + Status: http.StatusUnauthorized, + } + } + + domains, err := c.service.GetDomains(organization_id.String(), user.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isPermissionError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusForbidden, + } + } + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, @@ -74,10 +115,10 @@ func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*sha } if len(domains) == 0 { - c.logger.Log(logger.Error, "no domains available", "") + c.logger.Log(logger.Error, "no domains available for subdomain generation", "") return nil, fuego.HTTPError{ - Err: nil, - Status: http.StatusBadRequest, + Err: types.ErrDomainNotFound, + Status: http.StatusNotFound, } } diff --git a/api/internal/features/domain/controller/update_domain.go b/api/internal/features/domain/controller/update_domain.go index 9df1e20d..d0a4c7f3 100644 --- a/api/internal/features/domain/controller/update_domain.go +++ b/api/internal/features/domain/controller/update_domain.go @@ -42,17 +42,17 @@ func (c *DomainsController) UpdateDomain(f fuego.ContextWithBody[types.UpdateDom if err != nil { c.logger.Log(logger.Error, err.Error(), "") - if err == types.ErrDomainNotFound { + if isInvalidDomainError(err) { return nil, fuego.HTTPError{ Err: err, - Status: http.StatusNotFound, + Status: http.StatusBadRequest, } } - if err == types.ErrInvalidDomainID || err == types.ErrMissingDomainID || err == types.ErrDomainNameInvalid || err == types.ErrDomainNameTooLong || err == types.ErrDomainNameTooShort || err == types.ErrMissingDomainName { + if err == types.ErrDomainNotFound { return nil, fuego.HTTPError{ Err: err, - Status: http.StatusBadRequest, + Status: http.StatusNotFound, } } diff --git a/view/app/self-host/hooks/use_create_deployment.ts b/view/app/self-host/hooks/use_create_deployment.ts index 112e4604..97744a60 100644 --- a/view/app/self-host/hooks/use_create_deployment.ts +++ b/view/app/self-host/hooks/use_create_deployment.ts @@ -3,7 +3,6 @@ import { z } from 'zod'; import { useEffect } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; -import { useGetAllDomainsQuery } from '@/redux/services/settings/domainsApi'; import { useWebSocket } from '@/hooks/socket-provider'; import { useRouter } from 'next/navigation'; import { useCreateDeploymentMutation } from '@/redux/services/deploy/applicationsApi'; diff --git a/view/app/self-host/hooks/use_update_deployment.ts b/view/app/self-host/hooks/use_update_deployment.ts index f3ff8006..943892f7 100644 --- a/view/app/self-host/hooks/use_update_deployment.ts +++ b/view/app/self-host/hooks/use_update_deployment.ts @@ -42,7 +42,7 @@ function useUpdateDeployment({ const [updateDeployment, { isLoading }] = useUpdateDeploymentMutation(); const router = useRouter(); const activeOrg = useAppSelector((state) => state.user.activeOrganization); - const { data: domains } = useGetAllDomainsQuery(activeOrg?.id); + const { data: domains } = useGetAllDomainsQuery(); const deploymentFormSchema = z.object({ name: z diff --git a/view/app/settings/domains/components/delete-domain.tsx b/view/app/settings/domains/components/delete-domain.tsx index 2ab438ff..00d81f91 100644 --- a/view/app/settings/domains/components/delete-domain.tsx +++ b/view/app/settings/domains/components/delete-domain.tsx @@ -26,7 +26,7 @@ const DeleteDomain = ({ open, setOpen, id }: DeleteDomainProps) => { const handleDelete = async () => { setIsLoading(true); try { - await deleteDomain(id); + await deleteDomain({ id }); toast.success(t('settings.domains.delete.success')); } catch (error) { toast.error(t('settings.domains.delete.error')); diff --git a/view/app/settings/domains/page.tsx b/view/app/settings/domains/page.tsx index 60bdfcc6..7f75736a 100644 --- a/view/app/settings/domains/page.tsx +++ b/view/app/settings/domains/page.tsx @@ -22,7 +22,7 @@ const Page = () => { data: domains, isLoading, error - } = useGetAllDomainsQuery({ organizationId: activeOrg?.id || '' }, { skip: !activeOrg?.id }); + } = useGetAllDomainsQuery(); const [addDomainDialogOpen, setAddDomainDialogOpen] = React.useState(false); const { isFeatureEnabled, isLoading: isFeatureFlagsLoading } = useFeatureFlags(); diff --git a/view/components/domains/random-subdomain-generator.tsx b/view/components/domains/random-subdomain-generator.tsx new file mode 100644 index 00000000..9dc831d7 --- /dev/null +++ b/view/components/domains/random-subdomain-generator.tsx @@ -0,0 +1,56 @@ +import React from 'react'; +import { useGenerateRandomSubdomainQuery } from '@/redux/services/settings/domainsApi'; +import { Button } from '@/components/ui/button'; +import { toast } from 'sonner'; + +interface RandomSubdomainGeneratorProps { + onSubdomainGenerated?: (subdomain: string) => void; +} + +export const RandomSubdomainGenerator: React.FC = ({ + onSubdomainGenerated +}) => { + const { + data: randomSubdomainData, + isLoading, + error, + refetch + } = useGenerateRandomSubdomainQuery(); + + const handleGenerateSubdomain = async () => { + try { + const result = await refetch(); + if (result.data) { + toast.success(`Generated subdomain: ${result.data.subdomain}`); + onSubdomainGenerated?.(result.data.subdomain); + } + } catch (err) { + toast.error('Failed to generate random subdomain'); + } + }; + + return ( +
+ + + {randomSubdomainData && ( +
+

Subdomain: {randomSubdomainData.subdomain}

+

Domain: {randomSubdomainData.domain}

+
+ )} + + {error && ( +

+ Failed to generate subdomain. Please try again. +

+ )} +
+ ); +}; diff --git a/view/redux/services/settings/domainsApi.ts b/view/redux/services/settings/domainsApi.ts index 02f4426d..f5747327 100644 --- a/view/redux/services/settings/domainsApi.ts +++ b/view/redux/services/settings/domainsApi.ts @@ -1,16 +1,22 @@ import { DOMAIN_SETTINGS } from '@/redux/api-conf'; import { createApi } from '@reduxjs/toolkit/query/react'; import { baseQueryWithReauth } from '@/redux/base-query'; -import { Domain } from '@/redux/types/domain'; +import { + Domain, + RandomSubdomainResponse, + CreateDomainRequest, + UpdateDomainRequest, + DeleteDomainRequest +} from '@/redux/types/domain'; export const domainsApi = createApi({ reducerPath: 'domainsApi', baseQuery: baseQueryWithReauth, tagTypes: ['Domains'], endpoints: (builder) => ({ - getAllDomains: builder.query({ - query: ({ organizationId }) => ({ - url: DOMAIN_SETTINGS.GET_DOMAINS + `?id=${organizationId}`, + getAllDomains: builder.query({ + query: () => ({ + url: DOMAIN_SETTINGS.GET_DOMAINS, method: 'GET' }), providesTags: [{ type: 'Domains', id: 'LIST' }], @@ -18,18 +24,18 @@ export const domainsApi = createApi({ return response.data; } }), - createDomain: builder.mutation({ + createDomain: builder.mutation<{ id: string }, CreateDomainRequest>({ query: (data) => ({ url: DOMAIN_SETTINGS.ADD_DOMAIN, method: 'POST', body: data }), invalidatesTags: [{ type: 'Domains', id: 'LIST' }], - transformResponse: (response: { data: null }) => { + transformResponse: (response: { data: { id: string } }) => { return response.data; } }), - updateDomain: builder.mutation({ + updateDomain: builder.mutation({ query: (data) => ({ url: DOMAIN_SETTINGS.UPDATE_DOMAIN, method: 'PUT', @@ -40,22 +46,25 @@ export const domainsApi = createApi({ return response.data; } }), - deleteDomain: builder.mutation({ - query: (id) => ({ + deleteDomain: builder.mutation({ + query: (data) => ({ url: DOMAIN_SETTINGS.DELETE_DOMAIN, method: 'DELETE', - body: { id } + body: data }), invalidatesTags: [{ type: 'Domains', id: 'LIST' }], transformResponse: (response: { data: null }) => { return response.data; } }), - generateRandomSubdomain: builder.query({ - query: (id) => ({ + generateRandomSubdomain: builder.query({ + query: () => ({ url: DOMAIN_SETTINGS.GENERATE_RANDOM_SUBDOMAIN, method: 'GET' - }) + }), + transformResponse: (response: { data: RandomSubdomainResponse }) => { + return response.data; + } }) }) }); diff --git a/view/redux/types/domain.ts b/view/redux/types/domain.ts index 2a15ce98..a90d0247 100644 --- a/view/redux/types/domain.ts +++ b/view/redux/types/domain.ts @@ -4,3 +4,22 @@ export interface Domain { created_at: string; updated_at: string; } + +export interface RandomSubdomainResponse { + subdomain: string; + domain: string; +} + +export interface CreateDomainRequest { + name: string; + organization_id: string; +} + +export interface UpdateDomainRequest { + name: string; + id: string; +} + +export interface DeleteDomainRequest { + id: string; +} From 3b81461752e2e8d7fbd7591684f5225673f2ef69 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Wed, 2 Jul 2025 04:28:27 +0530 Subject: [PATCH 15/72] pr-review: addressed comments --- api/api/versions.json | 2 +- api/doc/openapi.json | 2 +- api/internal/routes.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index 9d924fbc..90e7b7e6 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-07-02T04:06:05.74728+05:30", + "release_date": "2025-07-02T04:28:01.164547+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/doc/openapi.json b/api/doc/openapi.json index 0d798bae..a9f16ac0 100644 --- a/api/doc/openapi.json +++ b/api/doc/openapi.json @@ -1 +1 @@ -{"components":{"schemas":{"AddUserToOrganizationRequest":{"description":"AddUserToOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"role_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ContainerLogsRequest":{"description":"ContainerLogsRequest schema","properties":{"follow":{"type":"boolean"},"id":{"type":"string"},"since":{"type":"string"},"stderr":{"type":"boolean"},"stdout":{"type":"boolean"},"tail":{"type":"integer"},"until":{"type":"string"}},"type":"object"},"CopyDirectory":{"description":"CopyDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"CreateDeploymentRequest":{"description":"CreateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"branch":{"type":"string"},"build_pack":{"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"domain":{"type":"string"},"environment":{"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"type":"object"},"name":{"type":"string"},"port":{"type":"integer"},"post_run_command":{"type":"string"},"pre_run_command":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"CreateDirectoryRequest":{"description":"CreateDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"CreateDomainRequest":{"description":"CreateDomainRequest schema","properties":{"name":{"type":"string"},"organization_id":{}},"type":"object"},"CreateGithubConnectorRequest":{"description":"CreateGithubConnectorRequest schema","properties":{"app_id":{"type":"string"},"client_id":{"type":"string"},"client_secret":{"type":"string"},"pem":{"type":"string"},"slug":{"type":"string"},"webhook_secret":{"type":"string"}},"type":"object"},"CreateOrganizationRequest":{"description":"CreateOrganizationRequest schema","properties":{"description":{"type":"string"},"name":{"type":"string"}},"type":"object"},"CreateSMTPConfigRequest":{"description":"CreateSMTPConfigRequest schema","properties":{"from_email":{"type":"string"},"from_name":{"type":"string"},"host":{"type":"string"},"organization_id":{},"password":{"type":"string"},"port":{"type":"integer"},"username":{"type":"string"}},"type":"object"},"CreateWebhookConfigRequest":{"description":"CreateWebhookConfigRequest schema","properties":{"type":{"type":"string"},"webhook_url":{"type":"string"}},"required":["type"],"type":"object"},"DeleteDeploymentRequest":{"description":"DeleteDeploymentRequest schema","properties":{"id":{}},"type":"object"},"DeleteDirectoryRequest":{"description":"DeleteDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"DeleteDomainRequest":{"description":"DeleteDomainRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteOrganizationRequest":{"description":"DeleteOrganizationRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteSMTPConfigRequest":{"description":"DeleteSMTPConfigRequest schema","properties":{"id":{}},"type":"object"},"DeleteWebhookConfigRequest":{"description":"DeleteWebhookConfigRequest schema","properties":{"type":{"type":"string"}},"required":["type"],"type":"object"},"GetApplicationDeploymentsRequest":{"description":"GetApplicationDeploymentsRequest schema","properties":{"id":{"type":"string"},"limit":{"type":"string"},"page":{"type":"string"}},"type":"object"},"GetApplicationsRequest":{"description":"GetApplicationsRequest schema","properties":{"page":{"type":"string"},"page_size":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"GetOrganizationUsersRequest":{"description":"GetOrganizationUsersRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"HTTPError":{"description":"HTTPError schema","properties":{"detail":{"description":"Human readable error message","nullable":true,"type":"string"},"errors":{"items":{"properties":{"more":{"additionalProperties":{},"type":"object"},"name":{"type":"string"},"reason":{"type":"string"}},"type":"object"},"nullable":true,"type":"array"},"instance":{"nullable":true,"type":"string"},"status":{"description":"HTTP status code","example":403,"nullable":true,"type":"integer"},"title":{"description":"Short title of the error","nullable":true,"type":"string"},"type":{"description":"URL of the error type. Can be used to lookup the error in a documentation","nullable":true,"type":"string"}},"type":"object"},"ListFilesRequest":{"description":"ListFilesRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"ListImagesRequest":{"description":"ListImagesRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"container_id":{"nullable":true,"type":"string"},"image_prefix":{"nullable":true,"type":"string"}},"type":"object"},"LoginRequest":{"description":"LoginRequest schema","properties":{"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"LogoutRequest":{"description":"LogoutRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"MoveDirectory":{"description":"MoveDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"PruneBuildCacheRequest":{"description":"PruneBuildCacheRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"filters":{"nullable":true,"type":"string"}},"type":"object"},"PruneImagesRequest":{"description":"PruneImagesRequest schema","properties":{"dangling":{"nullable":true,"type":"boolean"},"label":{"nullable":true,"type":"string"},"until":{"nullable":true,"type":"string"}},"type":"object"},"ReDeployApplicationRequest":{"description":"ReDeployApplicationRequest schema","properties":{"force":{"type":"boolean"},"force_without_cache":{"type":"boolean"},"id":{}},"type":"object"},"RefreshTokenRequest":{"description":"RefreshTokenRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"RegisterRequest":{"description":"RegisterRequest schema","properties":{"email":{"type":"string"},"organization":{"type":"string"},"password":{"type":"string"},"type":{"type":"string"},"username":{"type":"string"}},"type":"object"},"RemoveUserFromOrganizationRequest":{"description":"RemoveUserFromOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ResetPasswordRequest":{"description":"ResetPasswordRequest schema","properties":{"password":{"type":"string"}},"type":"object"},"Response":{"description":"Response schema","properties":{"data":{"nullable":true},"error":{"nullable":true,"type":"string"},"message":{"nullable":true,"type":"string"},"status":{"type":"string"}},"type":"object"},"RestartDeploymentRequest":{"description":"RestartDeploymentRequest schema","properties":{"id":{}},"type":"object"},"RollbackDeploymentRequest":{"description":"RollbackDeploymentRequest schema","properties":{"id":{}},"type":"object"},"TwoFactorLoginRequest":{"description":"TwoFactorLoginRequest schema","properties":{"code":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"TwoFactorVerifyRequest":{"description":"TwoFactorVerifyRequest schema","properties":{"code":{"type":"string"}},"type":"object"},"UpdateAutoUpdateRequest":{"description":"UpdateAutoUpdateRequest schema","properties":{"auto_update":{"type":"boolean"}},"type":"object"},"UpdateAvatarRequest":{"description":"UpdateAvatarRequest schema","properties":{"avatarData":{"type":"string"}},"type":"object"},"UpdateCheckResponse":{"description":"UpdateCheckResponse schema","properties":{"current_version":{"type":"string"},"environment":{"type":"string"},"last_checked":{"format":"date-time","type":"string"},"latest_version":{"type":"string"},"update_available":{"type":"boolean"}},"type":"object"},"UpdateDeploymentRequest":{"description":"UpdateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"force":{"nullable":true,"type":"boolean"},"id":{"nullable":true},"name":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"post_run_command":{"nullable":true,"type":"string"},"pre_run_command":{"nullable":true,"type":"string"}},"type":"object"},"UpdateDomainRequest":{"description":"UpdateDomainRequest schema","properties":{"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdateFeatureFlagRequest":{"description":"UpdateFeatureFlagRequest schema","properties":{"feature_name":{"type":"string"},"is_enabled":{"type":"boolean"}},"required":["feature_name"],"type":"object"},"UpdateFontRequest":{"description":"UpdateFontRequest schema","properties":{"font_family":{"type":"string"},"font_size":{"type":"integer"}},"type":"object"},"UpdateGithubConnectorRequest":{"description":"UpdateGithubConnectorRequest schema","properties":{"installation_id":{"type":"string"}},"type":"object"},"UpdateLanguageRequest":{"description":"UpdateLanguageRequest schema","properties":{"language":{"type":"string"}},"type":"object"},"UpdateOrganizationRequest":{"description":"UpdateOrganizationRequest schema","properties":{"description":{"type":"string"},"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdatePreferenceRequest":{"description":"UpdatePreferenceRequest schema","properties":{"category":{"type":"string"},"enabled":{"type":"boolean"},"type":{"type":"string"}},"required":["category","type"],"type":"object"},"UpdateRequest":{"description":"UpdateRequest schema","properties":{"force":{"type":"boolean"}},"type":"object"},"UpdateResponse":{"description":"UpdateResponse schema","properties":{"message":{"type":"string"},"success":{"type":"boolean"}},"type":"object"},"UpdateSMTPConfigRequest":{"description":"UpdateSMTPConfigRequest schema","properties":{"from_email":{"nullable":true,"type":"string"},"from_name":{"nullable":true,"type":"string"},"host":{"nullable":true,"type":"string"},"id":{},"organization_id":{},"password":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"username":{"nullable":true,"type":"string"}},"type":"object"},"UpdateThemeRequest":{"description":"UpdateThemeRequest schema","properties":{"theme":{"type":"string"}},"type":"object"},"UpdateUserNameRequest":{"description":"UpdateUserNameRequest schema","properties":{"name":{"type":"string"}},"type":"object"},"UpdateUserRoleRequest":{"description":"UpdateUserRoleRequest schema","properties":{"organization_id":{"type":"string"},"role_name":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"UpdateWebhookConfigRequest":{"description":"UpdateWebhookConfigRequest schema","properties":{"is_active":{"nullable":true,"type":"boolean"},"type":{"type":"string"},"webhook_url":{"nullable":true,"type":"string"}},"required":["type"],"type":"object"},"unknown-interface":{"description":"unknown-interface schema"}},"securitySchemes":{"bearerAuth":{"bearerFormat":"JWT","description":"Enter your JWT token in the format: Bearer \u003ctoken\u003e","scheme":"bearer","type":"http"}}},"info":{"description":"\nThis is the autogenerated OpenAPI documentation for your [Fuego](https://github.com/go-fuego/fuego) API.\n\nBelow is a Fuego Cheatsheet to help you get started. Don't hesitate to check the [Fuego documentation](https://go-fuego.dev) for more details.\n\nHappy coding! 🔥\n\n## Usage\n\n### Route registration\n\n```go\nfunc main() {\n\t// Create a new server\n\ts := fuego.NewServer()\n\n\t// Register some routes\n\tfuego.Post(s, \"/hello\", myController)\n\tfuego.Get(s, \"/myPath\", otherController)\n\tfuego.Put(s, \"/hello\", thirdController)\n\n\tadminRoutes := fuego.Group(s, \"/admin\")\n\tfuego.Use(adminRoutes, myMiddleware) // This middleware (for authentication, etc...) will be available for routes starting by /admin/*, \n\tfuego.Get(adminRoutes, \"/hello\", groupController) // This route will be available at /admin/hello\n\n\t// Start the server\n\ts.Start()\n}\n```\n\n### Basic controller\n\n```go\ntype MyBody struct {\n\tName string `json:\"name\" validate:\"required,max=30\"`\n}\n\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc hello(ctx fuego.ContextWithBody[MyBody]) (*MyResponse, error) {\n\tbody, err := ctx.Body()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + body.Name}, nil\n}\n```\n\n### Add openAPI information to the route\n\n```go\nimport (\n\t\"github.com/go-fuego/fuego\"\n\t\"github.com/go-fuego/fuego/option\"\n\t\"github.com/go-fuego/fuego/param\"\n)\n\nfunc main() {\n\ts := fuego.NewServer()\n\n\t// Custom OpenAPI options\n\tfuego.Post(s, \"/\", myController\n\t\toption.Description(\"This route does something...\"),\n\t\toption.Summary(\"This is my summary\"),\n\t\toption.Tags(\"MyTag\"), // A tag is set by default according to the return type (can be deactivated)\n\t\toption.Deprecated(), // Marks the route as deprecated in the OpenAPI spec\n\n\t\toption.Query(\"name\", \"Declares a query parameter with default value\", param.Default(\"Carmack\")),\n\t\toption.Header(\"Authorization\", \"Bearer token\", param.Required()),\n\t\toptionPagination,\n\t\toptionCustomBehavior,\n\t)\n\n\ts.Run()\n}\n\nvar optionPagination = option.Group(\n\toption.QueryInt(\"page\", \"Page number\", param.Default(1), param.Example(\"1st page\", 1), param.Example(\"42nd page\", 42)),\n\toption.QueryInt(\"perPage\", \"Number of items per page\"),\n)\n\nvar optionCustomBehavior = func(r *fuego.BaseRoute) {\n\tr.XXX = \"YYY\"\n}\n```\n\nThen, in the controller\n\n```go\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc getAllPets(ctx fuego.ContextNoBody) (*MyResponse, error) {\n\tname := ctx.QueryParam(\"name\")\n\tperPage, _ := ctx.QueryParamIntErr(\"per_page\")\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + name}, nil\n}\n```\n","title":"OpenAPI","version":"0.0.1"},"openapi":"3.1.0","paths":{"/api/v1/audit/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/audit/controller.(*AuditController).GetRecentAuditLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func16`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func17`\n\n---\n\n","operationId":"GET_/api/v1/audit/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get recent audit logs","tags":["api/v1/audit"]}},"/api/v1/auth/2fa-login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).TwoFactorLogin`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/2fa-login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorLoginRequest"}}},"description":"Request body for types.TwoFactorLoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"two factor login","tags":["api/v1/auth"]}},"/api/v1/auth/create-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).CreateUser`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/create-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create user","tags":["api/v1/auth"]}},"/api/v1/auth/disable-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).DisableTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/disable-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"disable two factor","tags":["api/v1/auth"]}},"/api/v1/auth/is-admin-registered":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).IsAdminRegistered`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/auth/is-admin-registered","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is admin registered","tags":["api/v1/auth"]}},"/api/v1/auth/login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Login`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LoginRequest"}}},"description":"Request body for types.LoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"login","tags":["api/v1/auth"]}},"/api/v1/auth/logout":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Logout`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/logout","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LogoutRequest"}}},"description":"Request body for types.LogoutRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"logout","tags":["api/v1/auth"]}},"/api/v1/auth/refresh-token":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).RefreshToken`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/refresh-token","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RefreshTokenRequest"}}},"description":"Request body for types.RefreshTokenRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"refresh token","tags":["api/v1/auth"]}},"/api/v1/auth/register":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Register`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/register","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"register","tags":["api/v1/auth"]}},"/api/v1/auth/request-password-reset":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).GeneratePasswordResetLink`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/request-password-reset","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate password reset link","tags":["api/v1/auth"]}},"/api/v1/auth/reset-password":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).ResetPassword`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/reset-password","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ResetPasswordRequest"}}},"description":"Request body for types.ResetPasswordRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"reset password","tags":["api/v1/auth"]}},"/api/v1/auth/send-verification-email":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SendVerificationEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/send-verification-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"send verification email","tags":["api/v1/auth"]}},"/api/v1/auth/setup-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SetupTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/setup-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"setup two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/verify-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorVerifyRequest"}}},"description":"Request body for types.TwoFactorVerifyRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-email":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/auth/verify-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify email","tags":["api/v1/auth"]}},"/api/v1/container":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListContainers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list containers","tags":["api/v1/container"]}},"/api/v1/container/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListImagesRequest"}}},"description":"Request body for controller.ListImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list images","tags":["api/v1/container"]}},"/api/v1/container/prune/build-cache":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneBuildCache`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/build-cache","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneBuildCacheRequest"}}},"description":"Request body for controller.PruneBuildCacheRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune build cache","tags":["api/v1/container"]}},"/api/v1/container/prune/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneImagesRequest"}}},"description":"Request body for controller.PruneImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune images","tags":["api/v1/container"]}},"/api/v1/container/{container_id}":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RemoveContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"DELETE_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove container","tags":["api/v1/container"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/logs":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainerLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ContainerLogsRequest"}}},"description":"Request body for types.ContainerLogsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container logs","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RestartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"restart container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/start":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/start","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"start container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/stop":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StopContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/stop","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"stop container","tags":["api/v1/container"]}},"/api/v1/deploy/application":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).DeleteApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"DELETE_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDeploymentRequest"}}},"description":"Request body for types.DeleteDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete application","tags":["api/v1/deploy","application"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application by id","tags":["api/v1/deploy","application"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleDeploy`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDeploymentRequest"}}},"description":"Request body for types.CreateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle deploy","tags":["api/v1/deploy","application"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).UpdateApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"PUT_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDeploymentRequest"}}},"description":"Request body for types.UpdateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationDeployments`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationDeploymentsRequest"}}},"description":"Request body for controller.GetApplicationDeploymentsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application deployments","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment by id","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/logs/{application_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/logs/:application_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"application_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/redeploy":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).ReDeployApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/redeploy","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ReDeployApplicationRequest"}}},"description":"Request body for types.ReDeployApplicationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"re deploy application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRestart`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RestartDeploymentRequest"}}},"description":"Request body for types.RestartDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle restart","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/rollback":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRollback`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/rollback","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RollbackDeploymentRequest"}}},"description":"Request body for types.RollbackDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle rollback","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/applications":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplications`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/applications","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationsRequest"}}},"description":"Request body for controller.GetApplicationsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get applications","tags":["api/v1/deploy"]}},"/api/v1/domain":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).DeleteDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"DELETE_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDomainRequest"}}},"description":"Request body for types.DeleteDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete domain","tags":["api/v1/domain"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).CreateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"POST_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDomainRequest"}}},"description":"Request body for types.CreateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create domain","tags":["api/v1/domain"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).UpdateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"PUT_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDomainRequest"}}},"description":"Request body for types.UpdateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update domain","tags":["api/v1/domain"]}},"/api/v1/domain/generate":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GenerateRandomSubDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"GET_/api/v1/domain/generate","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate random sub domain","tags":["api/v1/domain"]}},"/api/v1/domains":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GetDomains`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func6`\n\n---\n\n","operationId":"GET_/api/v1/domains","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get domains","tags":["api/v1/domains"]}},"/api/v1/feature-flags":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).GetFeatureFlags`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get feature flags","tags":["api/v1/feature-flags"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).UpdateFeatureFlag`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"PUT_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFeatureFlagRequest"}}},"description":"Request body for types.UpdateFeatureFlagRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update feature flag","tags":["api/v1/feature-flags"]}},"/api/v1/feature-flags/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).IsFeatureEnabled`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is feature enabled","tags":["api/v1/feature-flags"]}},"/api/v1/file-manager":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).ListFiles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"GET_/api/v1/file-manager","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListFilesRequest"}}},"description":"Request body for controller.ListFilesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list files","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/copy-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CopyDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/copy-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CopyDirectory"}}},"description":"Request body for controller.CopyDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"copy directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/create-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CreateDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/create-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDirectoryRequest"}}},"description":"Request body for controller.CreateDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/delete-directory":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).DeleteDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"DELETE_/api/v1/file-manager/delete-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDirectoryRequest"}}},"description":"Request body for controller.DeleteDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/move-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).MoveDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/move-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/MoveDirectory"}}},"description":"Request body for controller.MoveDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"move directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/upload":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).UploadFile`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/upload","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"upload file","tags":["api/v1/file-manager"]}},"/api/v1/github-connector":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).CreateGithubConnector`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"POST_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateGithubConnectorRequest"}}},"description":"Request body for types.CreateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create github connector","tags":["api/v1/github-connector"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).UpdateGithubConnectorRequest`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"PUT_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateGithubConnectorRequest"}}},"description":"Request body for types.UpdateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update github connector request","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/all":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubConnectors`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/all","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github connectors","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/repositories":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubRepositories`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/repositories","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github repositories","tags":["api/v1/github-connector"]}},"/api/v1/health":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/health.HealthCheck`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"health check","tags":["api/v1/health"]}},"/api/v1/health/versions":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).BasicRoutes.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health/versions","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1","tags":["api/v1/health","versions"]}},"/api/v1/notification/preferences":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetPreferences`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get preferences","tags":["api/v1/notification","preferences"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdatePreference`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdatePreferenceRequest"}}},"description":"Request body for notification.UpdatePreferenceRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update preference","tags":["api/v1/notification","preferences"]}},"/api/v1/notification/smtp":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteSMTPConfigRequest"}}},"description":"Request body for notification.DeleteSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete smtp","tags":["api/v1/notification","smtp"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get smtp","tags":["api/v1/notification","smtp"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).AddSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateSMTPConfigRequest"}}},"description":"Request body for notification.CreateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add smtp","tags":["api/v1/notification","smtp"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateSMTPConfigRequest"}}},"description":"Request body for notification.UpdateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update smtp","tags":["api/v1/notification","smtp"]}},"/api/v1/notification/webhook":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteWebhookConfigRequest"}}},"description":"Request body for notification.DeleteWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete webhook config","tags":["api/v1/notification","webhook"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).CreateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateWebhookConfigRequest"}}},"description":"Request body for notification.CreateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create webhook config","tags":["api/v1/notification","webhook"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateWebhookConfigRequest"}}},"description":"Request body for notification.UpdateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/notification/webhook/{type}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/webhook/:type","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"type","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/organizations":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).DeleteOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"DELETE_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteOrganizationRequest"}}},"description":"Request body for types.DeleteOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete organization","tags":["api/v1/organizations"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).CreateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateOrganizationRequest"}}},"description":"Request body for types.CreateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create organization","tags":["api/v1/organizations"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"PUT_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateOrganizationRequest"}}},"description":"Request body for types.UpdateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/add-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).AddUserToOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/add-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/AddUserToOrganizationRequest"}}},"description":"Request body for types.AddUserToOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add user to organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/remove-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).RemoveUserFromOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/remove-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RemoveUserFromOrganizationRequest"}}},"description":"Request body for types.RemoveUserFromOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove user from organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/resources":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetResources`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/resources","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get resources","tags":["api/v1/organizations"]}},"/api/v1/organizations/roles":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetRoles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/roles","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get roles","tags":["api/v1/organizations"]}},"/api/v1/organizations/update-user-role":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateUserRole`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/update-user-role","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserRoleRequest"}}},"description":"Request body for controller.UpdateUserRoleRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user role","tags":["api/v1/organizations"]}},"/api/v1/organizations/users":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetOrganizationUsers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/users","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetOrganizationUsersRequest"}}},"description":"Request body for controller.GetOrganizationUsersRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get organization users","tags":["api/v1/organizations"]}},"/api/v1/update":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).PerformUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateRequest"}}},"description":"Request body for types.UpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"perform update","tags":["api/v1/update"]}},"/api/v1/update/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).CheckForUpdates`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/update/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"check for updates","tags":["api/v1/update"]}},"/api/v1/user":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserDetails`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user details","tags":["api/v1/user"]}},"/api/v1/user/avatar":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAvatar`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/avatar","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAvatarRequest"}}},"description":"Request body for types.UpdateAvatarRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update avatar","tags":["api/v1/user"]}},"/api/v1/user/name":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateUserName`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/name","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserNameRequest"}}},"description":"Request body for types.UpdateUserNameRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user name","tags":["api/v1/user"]}},"/api/v1/user/organizations":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserOrganizations`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user organizations","tags":["api/v1/user"]}},"/api/v1/user/settings":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetSettings`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/settings","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get settings","tags":["api/v1/user"]}},"/api/v1/user/settings/auto-update":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAutoUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/auto-update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAutoUpdateRequest"}}},"description":"Request body for controller.UpdateAutoUpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update auto update","tags":["api/v1/user"]}},"/api/v1/user/settings/font":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateFont`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/font","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFontRequest"}}},"description":"Request body for controller.UpdateFontRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update font","tags":["api/v1/user"]}},"/api/v1/user/settings/language":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateLanguage`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/language","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateLanguageRequest"}}},"description":"Request body for controller.UpdateLanguageRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update language","tags":["api/v1/user"]}},"/api/v1/user/settings/theme":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateTheme`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/theme","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateThemeRequest"}}},"description":"Request body for controller.UpdateThemeRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update theme","tags":["api/v1/user"]}},"/api/v1/webhook":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleGithubWebhook`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle github webhook","tags":["api/v1/webhook"]}},"/ws":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).WebSocketServer.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/ws","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1"}}},"servers":[{"description":"local server","url":"http://localhost:8080"}],"tags":[{"name":"api/v1/audit"},{"name":"api/v1/auth"},{"name":"api/v1/container"},{"name":"api/v1/deploy"},{"name":"api/v1/domain"},{"name":"api/v1/domains"},{"name":"api/v1/feature-flags"},{"name":"api/v1/file-manager"},{"name":"api/v1/github-connector"},{"name":"api/v1/health"},{"name":"api/v1/notification"},{"name":"api/v1/organizations"},{"name":"api/v1/update"},{"name":"api/v1/user"},{"name":"api/v1/webhook"},{"name":"application"},{"name":"preferences"},{"name":"smtp"},{"name":"versions"},{"name":"webhook"}]} \ No newline at end of file +{"components":{"schemas":{"AddUserToOrganizationRequest":{"description":"AddUserToOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"role_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ContainerLogsRequest":{"description":"ContainerLogsRequest schema","properties":{"follow":{"type":"boolean"},"id":{"type":"string"},"since":{"type":"string"},"stderr":{"type":"boolean"},"stdout":{"type":"boolean"},"tail":{"type":"integer"},"until":{"type":"string"}},"type":"object"},"CopyDirectory":{"description":"CopyDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"CreateDeploymentRequest":{"description":"CreateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"branch":{"type":"string"},"build_pack":{"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"domain":{"type":"string"},"environment":{"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"type":"object"},"name":{"type":"string"},"port":{"type":"integer"},"post_run_command":{"type":"string"},"pre_run_command":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"CreateDirectoryRequest":{"description":"CreateDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"CreateDomainRequest":{"description":"CreateDomainRequest schema","properties":{"name":{"type":"string"},"organization_id":{}},"type":"object"},"CreateGithubConnectorRequest":{"description":"CreateGithubConnectorRequest schema","properties":{"app_id":{"type":"string"},"client_id":{"type":"string"},"client_secret":{"type":"string"},"pem":{"type":"string"},"slug":{"type":"string"},"webhook_secret":{"type":"string"}},"type":"object"},"CreateOrganizationRequest":{"description":"CreateOrganizationRequest schema","properties":{"description":{"type":"string"},"name":{"type":"string"}},"type":"object"},"CreateSMTPConfigRequest":{"description":"CreateSMTPConfigRequest schema","properties":{"from_email":{"type":"string"},"from_name":{"type":"string"},"host":{"type":"string"},"organization_id":{},"password":{"type":"string"},"port":{"type":"integer"},"username":{"type":"string"}},"type":"object"},"CreateWebhookConfigRequest":{"description":"CreateWebhookConfigRequest schema","properties":{"type":{"type":"string"},"webhook_url":{"type":"string"}},"required":["type"],"type":"object"},"DeleteDeploymentRequest":{"description":"DeleteDeploymentRequest schema","properties":{"id":{}},"type":"object"},"DeleteDirectoryRequest":{"description":"DeleteDirectoryRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"DeleteDomainRequest":{"description":"DeleteDomainRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteOrganizationRequest":{"description":"DeleteOrganizationRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"DeleteSMTPConfigRequest":{"description":"DeleteSMTPConfigRequest schema","properties":{"id":{}},"type":"object"},"DeleteWebhookConfigRequest":{"description":"DeleteWebhookConfigRequest schema","properties":{"type":{"type":"string"}},"required":["type"],"type":"object"},"GetApplicationDeploymentsRequest":{"description":"GetApplicationDeploymentsRequest schema","properties":{"id":{"type":"string"},"limit":{"type":"string"},"page":{"type":"string"}},"type":"object"},"GetApplicationsRequest":{"description":"GetApplicationsRequest schema","properties":{"page":{"type":"string"},"page_size":{"type":"string"},"repository":{"type":"string"}},"type":"object"},"GetOrganizationUsersRequest":{"description":"GetOrganizationUsersRequest schema","properties":{"id":{"type":"string"}},"type":"object"},"HTTPError":{"description":"HTTPError schema","properties":{"detail":{"description":"Human readable error message","nullable":true,"type":"string"},"errors":{"items":{"properties":{"more":{"additionalProperties":{},"type":"object"},"name":{"type":"string"},"reason":{"type":"string"}},"type":"object"},"nullable":true,"type":"array"},"instance":{"nullable":true,"type":"string"},"status":{"description":"HTTP status code","example":403,"nullable":true,"type":"integer"},"title":{"description":"Short title of the error","nullable":true,"type":"string"},"type":{"description":"URL of the error type. Can be used to lookup the error in a documentation","nullable":true,"type":"string"}},"type":"object"},"ListFilesRequest":{"description":"ListFilesRequest schema","properties":{"path":{"type":"string"}},"type":"object"},"ListImagesRequest":{"description":"ListImagesRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"container_id":{"nullable":true,"type":"string"},"image_prefix":{"nullable":true,"type":"string"}},"type":"object"},"LoginRequest":{"description":"LoginRequest schema","properties":{"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"LogoutRequest":{"description":"LogoutRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"MoveDirectory":{"description":"MoveDirectory schema","properties":{"from_path":{"type":"string"},"to_path":{"type":"string"}},"type":"object"},"PruneBuildCacheRequest":{"description":"PruneBuildCacheRequest schema","properties":{"all":{"nullable":true,"type":"boolean"},"filters":{"nullable":true,"type":"string"}},"type":"object"},"PruneImagesRequest":{"description":"PruneImagesRequest schema","properties":{"dangling":{"nullable":true,"type":"boolean"},"label":{"nullable":true,"type":"string"},"until":{"nullable":true,"type":"string"}},"type":"object"},"ReDeployApplicationRequest":{"description":"ReDeployApplicationRequest schema","properties":{"force":{"type":"boolean"},"force_without_cache":{"type":"boolean"},"id":{}},"type":"object"},"RefreshTokenRequest":{"description":"RefreshTokenRequest schema","properties":{"refresh_token":{"type":"string"}},"type":"object"},"RegisterRequest":{"description":"RegisterRequest schema","properties":{"email":{"type":"string"},"organization":{"type":"string"},"password":{"type":"string"},"type":{"type":"string"},"username":{"type":"string"}},"type":"object"},"RemoveUserFromOrganizationRequest":{"description":"RemoveUserFromOrganizationRequest schema","properties":{"organization_id":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"ResetPasswordRequest":{"description":"ResetPasswordRequest schema","properties":{"password":{"type":"string"}},"type":"object"},"Response":{"description":"Response schema","properties":{"data":{"nullable":true},"error":{"nullable":true,"type":"string"},"message":{"nullable":true,"type":"string"},"status":{"type":"string"}},"type":"object"},"RestartDeploymentRequest":{"description":"RestartDeploymentRequest schema","properties":{"id":{}},"type":"object"},"RollbackDeploymentRequest":{"description":"RollbackDeploymentRequest schema","properties":{"id":{}},"type":"object"},"TwoFactorLoginRequest":{"description":"TwoFactorLoginRequest schema","properties":{"code":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"}},"type":"object"},"TwoFactorVerifyRequest":{"description":"TwoFactorVerifyRequest schema","properties":{"code":{"type":"string"}},"type":"object"},"UpdateAutoUpdateRequest":{"description":"UpdateAutoUpdateRequest schema","properties":{"auto_update":{"type":"boolean"}},"type":"object"},"UpdateAvatarRequest":{"description":"UpdateAvatarRequest schema","properties":{"avatarData":{"type":"string"}},"type":"object"},"UpdateCheckResponse":{"description":"UpdateCheckResponse schema","properties":{"current_version":{"type":"string"},"environment":{"type":"string"},"last_checked":{"format":"date-time","type":"string"},"latest_version":{"type":"string"},"update_available":{"type":"boolean"}},"type":"object"},"UpdateDeploymentRequest":{"description":"UpdateDeploymentRequest schema","properties":{"base_path":{"nullable":true,"type":"string"},"build_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"dockerfile_path":{"nullable":true,"type":"string"},"environment_variables":{"additionalProperties":{"type":"string"},"nullable":true,"type":"object"},"force":{"nullable":true,"type":"boolean"},"id":{"nullable":true},"name":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"post_run_command":{"nullable":true,"type":"string"},"pre_run_command":{"nullable":true,"type":"string"}},"type":"object"},"UpdateDomainRequest":{"description":"UpdateDomainRequest schema","properties":{"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdateFeatureFlagRequest":{"description":"UpdateFeatureFlagRequest schema","properties":{"feature_name":{"type":"string"},"is_enabled":{"type":"boolean"}},"required":["feature_name"],"type":"object"},"UpdateFontRequest":{"description":"UpdateFontRequest schema","properties":{"font_family":{"type":"string"},"font_size":{"type":"integer"}},"type":"object"},"UpdateGithubConnectorRequest":{"description":"UpdateGithubConnectorRequest schema","properties":{"installation_id":{"type":"string"}},"type":"object"},"UpdateLanguageRequest":{"description":"UpdateLanguageRequest schema","properties":{"language":{"type":"string"}},"type":"object"},"UpdateOrganizationRequest":{"description":"UpdateOrganizationRequest schema","properties":{"description":{"type":"string"},"id":{"type":"string"},"name":{"type":"string"}},"type":"object"},"UpdatePreferenceRequest":{"description":"UpdatePreferenceRequest schema","properties":{"category":{"type":"string"},"enabled":{"type":"boolean"},"type":{"type":"string"}},"required":["category","type"],"type":"object"},"UpdateRequest":{"description":"UpdateRequest schema","properties":{"force":{"type":"boolean"}},"type":"object"},"UpdateResponse":{"description":"UpdateResponse schema","properties":{"message":{"type":"string"},"success":{"type":"boolean"}},"type":"object"},"UpdateSMTPConfigRequest":{"description":"UpdateSMTPConfigRequest schema","properties":{"from_email":{"nullable":true,"type":"string"},"from_name":{"nullable":true,"type":"string"},"host":{"nullable":true,"type":"string"},"id":{},"organization_id":{},"password":{"nullable":true,"type":"string"},"port":{"nullable":true,"type":"integer"},"username":{"nullable":true,"type":"string"}},"type":"object"},"UpdateThemeRequest":{"description":"UpdateThemeRequest schema","properties":{"theme":{"type":"string"}},"type":"object"},"UpdateUserNameRequest":{"description":"UpdateUserNameRequest schema","properties":{"name":{"type":"string"}},"type":"object"},"UpdateUserRoleRequest":{"description":"UpdateUserRoleRequest schema","properties":{"organization_id":{"type":"string"},"role_name":{"type":"string"},"user_id":{"type":"string"}},"type":"object"},"UpdateWebhookConfigRequest":{"description":"UpdateWebhookConfigRequest schema","properties":{"is_active":{"nullable":true,"type":"boolean"},"type":{"type":"string"},"webhook_url":{"nullable":true,"type":"string"}},"required":["type"],"type":"object"},"unknown-interface":{"description":"unknown-interface schema"}},"securitySchemes":{"bearerAuth":{"bearerFormat":"JWT","description":"Enter your JWT token in the format: Bearer \u003ctoken\u003e","scheme":"bearer","type":"http"}}},"info":{"description":"\nThis is the autogenerated OpenAPI documentation for your [Fuego](https://github.com/go-fuego/fuego) API.\n\nBelow is a Fuego Cheatsheet to help you get started. Don't hesitate to check the [Fuego documentation](https://go-fuego.dev) for more details.\n\nHappy coding! 🔥\n\n## Usage\n\n### Route registration\n\n```go\nfunc main() {\n\t// Create a new server\n\ts := fuego.NewServer()\n\n\t// Register some routes\n\tfuego.Post(s, \"/hello\", myController)\n\tfuego.Get(s, \"/myPath\", otherController)\n\tfuego.Put(s, \"/hello\", thirdController)\n\n\tadminRoutes := fuego.Group(s, \"/admin\")\n\tfuego.Use(adminRoutes, myMiddleware) // This middleware (for authentication, etc...) will be available for routes starting by /admin/*, \n\tfuego.Get(adminRoutes, \"/hello\", groupController) // This route will be available at /admin/hello\n\n\t// Start the server\n\ts.Start()\n}\n```\n\n### Basic controller\n\n```go\ntype MyBody struct {\n\tName string `json:\"name\" validate:\"required,max=30\"`\n}\n\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc hello(ctx fuego.ContextWithBody[MyBody]) (*MyResponse, error) {\n\tbody, err := ctx.Body()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + body.Name}, nil\n}\n```\n\n### Add openAPI information to the route\n\n```go\nimport (\n\t\"github.com/go-fuego/fuego\"\n\t\"github.com/go-fuego/fuego/option\"\n\t\"github.com/go-fuego/fuego/param\"\n)\n\nfunc main() {\n\ts := fuego.NewServer()\n\n\t// Custom OpenAPI options\n\tfuego.Post(s, \"/\", myController\n\t\toption.Description(\"This route does something...\"),\n\t\toption.Summary(\"This is my summary\"),\n\t\toption.Tags(\"MyTag\"), // A tag is set by default according to the return type (can be deactivated)\n\t\toption.Deprecated(), // Marks the route as deprecated in the OpenAPI spec\n\n\t\toption.Query(\"name\", \"Declares a query parameter with default value\", param.Default(\"Carmack\")),\n\t\toption.Header(\"Authorization\", \"Bearer token\", param.Required()),\n\t\toptionPagination,\n\t\toptionCustomBehavior,\n\t)\n\n\ts.Run()\n}\n\nvar optionPagination = option.Group(\n\toption.QueryInt(\"page\", \"Page number\", param.Default(1), param.Example(\"1st page\", 1), param.Example(\"42nd page\", 42)),\n\toption.QueryInt(\"perPage\", \"Number of items per page\"),\n)\n\nvar optionCustomBehavior = func(r *fuego.BaseRoute) {\n\tr.XXX = \"YYY\"\n}\n```\n\nThen, in the controller\n\n```go\ntype MyResponse struct {\n\tAnswer string `json:\"answer\"`\n}\n\nfunc getAllPets(ctx fuego.ContextNoBody) (*MyResponse, error) {\n\tname := ctx.QueryParam(\"name\")\n\tperPage, _ := ctx.QueryParamIntErr(\"per_page\")\n\n\treturn \u0026MyResponse{Answer: \"Hello \" + name}, nil\n}\n```\n","title":"OpenAPI","version":"0.0.1"},"openapi":"3.1.0","paths":{"/api/v1/audit/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/audit/controller.(*AuditController).GetRecentAuditLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func16`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func17`\n\n---\n\n","operationId":"GET_/api/v1/audit/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get recent audit logs","tags":["api/v1/audit"]}},"/api/v1/auth/2fa-login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).TwoFactorLogin`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/2fa-login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorLoginRequest"}}},"description":"Request body for types.TwoFactorLoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"two factor login","tags":["api/v1/auth"]}},"/api/v1/auth/create-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).CreateUser`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/create-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create user","tags":["api/v1/auth"]}},"/api/v1/auth/disable-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).DisableTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/disable-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"disable two factor","tags":["api/v1/auth"]}},"/api/v1/auth/is-admin-registered":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).IsAdminRegistered`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/auth/is-admin-registered","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is admin registered","tags":["api/v1/auth"]}},"/api/v1/auth/login":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Login`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/login","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LoginRequest"}}},"description":"Request body for types.LoginRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"login","tags":["api/v1/auth"]}},"/api/v1/auth/logout":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Logout`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/logout","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/LogoutRequest"}}},"description":"Request body for types.LogoutRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"logout","tags":["api/v1/auth"]}},"/api/v1/auth/refresh-token":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).RefreshToken`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/refresh-token","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RefreshTokenRequest"}}},"description":"Request body for types.RefreshTokenRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"refresh token","tags":["api/v1/auth"]}},"/api/v1/auth/register":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).Register`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/auth/register","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}},"description":"Request body for types.RegisterRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"register","tags":["api/v1/auth"]}},"/api/v1/auth/request-password-reset":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).GeneratePasswordResetLink`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/request-password-reset","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate password reset link","tags":["api/v1/auth"]}},"/api/v1/auth/reset-password":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).ResetPassword`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/reset-password","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ResetPasswordRequest"}}},"description":"Request body for types.ResetPasswordRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"reset password","tags":["api/v1/auth"]}},"/api/v1/auth/send-verification-email":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SendVerificationEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/send-verification-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"send verification email","tags":["api/v1/auth"]}},"/api/v1/auth/setup-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).SetupTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/setup-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"setup two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-2fa":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyTwoFactor`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/auth/verify-2fa","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/TwoFactorVerifyRequest"}}},"description":"Request body for types.TwoFactorVerifyRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify two factor","tags":["api/v1/auth"]}},"/api/v1/auth/verify-email":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/auth/controller.(*AuthController).VerifyEmail`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/auth/verify-email","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"verify email","tags":["api/v1/auth"]}},"/api/v1/container":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListContainers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list containers","tags":["api/v1/container"]}},"/api/v1/container/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).ListImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListImagesRequest"}}},"description":"Request body for controller.ListImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list images","tags":["api/v1/container"]}},"/api/v1/container/prune/build-cache":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneBuildCache`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/build-cache","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneBuildCacheRequest"}}},"description":"Request body for controller.PruneBuildCacheRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune build cache","tags":["api/v1/container"]}},"/api/v1/container/prune/images":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).PruneImages`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/prune/images","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/PruneImagesRequest"}}},"description":"Request body for controller.PruneImagesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"prune images","tags":["api/v1/container"]}},"/api/v1/container/{container_id}":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RemoveContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"DELETE_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove container","tags":["api/v1/container"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"GET_/api/v1/container/:container_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/logs":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).GetContainerLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ContainerLogsRequest"}}},"description":"Request body for types.ContainerLogsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get container logs","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).RestartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"restart container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/start":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StartContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/start","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"start container","tags":["api/v1/container"]}},"/api/v1/container/{container_id}/stop":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/container/controller.(*ContainerController).StopContainer`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func19`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func20`\n\n---\n\n","operationId":"POST_/api/v1/container/:container_id/stop","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"container_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"stop container","tags":["api/v1/container"]}},"/api/v1/deploy/application":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).DeleteApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"DELETE_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDeploymentRequest"}}},"description":"Request body for types.DeleteDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete application","tags":["api/v1/deploy","application"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application by id","tags":["api/v1/deploy","application"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleDeploy`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDeploymentRequest"}}},"description":"Request body for types.CreateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle deploy","tags":["api/v1/deploy","application"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).UpdateApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"PUT_/api/v1/deploy/application","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDeploymentRequest"}}},"description":"Request body for types.UpdateDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplicationDeployments`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationDeploymentsRequest"}}},"description":"Request body for controller.GetApplicationDeploymentsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get application deployments","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentById`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment by id","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/deployments/{deployment_id}/logs":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetDeploymentLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/deployments/:deployment_id/logs","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"deployment_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get deployment logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/logs/{application_id}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetLogs`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/application/logs/:application_id","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"application_id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get logs","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/redeploy":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).ReDeployApplication`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/redeploy","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ReDeployApplicationRequest"}}},"description":"Request body for types.ReDeployApplicationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"re deploy application","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/restart":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRestart`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/restart","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RestartDeploymentRequest"}}},"description":"Request body for types.RestartDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle restart","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/application/rollback":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleRollback`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"POST_/api/v1/deploy/application/rollback","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RollbackDeploymentRequest"}}},"description":"Request body for types.RollbackDeploymentRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle rollback","tags":["api/v1/deploy","application"]}},"/api/v1/deploy/applications":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).GetApplications`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func14`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func15`\n\n---\n\n","operationId":"GET_/api/v1/deploy/applications","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetApplicationsRequest"}}},"description":"Request body for controller.GetApplicationsRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get applications","tags":["api/v1/deploy"]}},"/api/v1/domain":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).DeleteDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"DELETE_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDomainRequest"}}},"description":"Request body for types.DeleteDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete domain","tags":["api/v1/domain"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).CreateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"POST_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDomainRequest"}}},"description":"Request body for types.CreateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create domain","tags":["api/v1/domain"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).UpdateDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"PUT_/api/v1/domain","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateDomainRequest"}}},"description":"Request body for types.UpdateDomainRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update domain","tags":["api/v1/domain"]}},"/api/v1/domain/generate":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GenerateRandomSubDomain`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func5`\n\n---\n\n","operationId":"GET_/api/v1/domain/generate","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"generate random sub domain","tags":["api/v1/domain"]}},"/api/v1/domains":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/domain/controller.(*DomainsController).GetDomains`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func4`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func6`\n\n---\n\n","operationId":"GET_/api/v1/domains","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get domains","tags":["api/v1/domains"]}},"/api/v1/feature-flags":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).GetFeatureFlags`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get feature flags","tags":["api/v1/feature-flags"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).UpdateFeatureFlag`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"PUT_/api/v1/feature-flags","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFeatureFlagRequest"}}},"description":"Request body for types.UpdateFeatureFlagRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update feature flag","tags":["api/v1/feature-flags"]}},"/api/v1/feature-flags/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/feature-flags/controller.(*FeatureFlagController).IsFeatureEnabled`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func18`\n\n---\n\n","operationId":"GET_/api/v1/feature-flags/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"is feature enabled","tags":["api/v1/feature-flags"]}},"/api/v1/file-manager":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).ListFiles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"GET_/api/v1/file-manager","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/ListFilesRequest"}}},"description":"Request body for controller.ListFilesRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"list files","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/copy-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CopyDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/copy-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CopyDirectory"}}},"description":"Request body for controller.CopyDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"copy directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/create-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).CreateDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/create-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateDirectoryRequest"}}},"description":"Request body for controller.CreateDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/delete-directory":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).DeleteDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"DELETE_/api/v1/file-manager/delete-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteDirectoryRequest"}}},"description":"Request body for controller.DeleteDirectoryRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/move-directory":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).MoveDirectory`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/move-directory","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/MoveDirectory"}}},"description":"Request body for controller.MoveDirectory","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"move directory","tags":["api/v1/file-manager"]}},"/api/v1/file-manager/upload":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/file-manager/controller.(*FileManagerController).UploadFile`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func12`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func13`\n\n---\n\n","operationId":"POST_/api/v1/file-manager/upload","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"upload file","tags":["api/v1/file-manager"]}},"/api/v1/github-connector":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).CreateGithubConnector`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"POST_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateGithubConnectorRequest"}}},"description":"Request body for types.CreateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create github connector","tags":["api/v1/github-connector"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).UpdateGithubConnectorRequest`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"PUT_/api/v1/github-connector","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateGithubConnectorRequest"}}},"description":"Request body for types.UpdateGithubConnectorRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update github connector request","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/all":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubConnectors`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/all","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github connectors","tags":["api/v1/github-connector"]}},"/api/v1/github-connector/repositories":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/github-connector/controller.(*GithubConnectorController).GetGithubRepositories`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func7`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func8`\n\n---\n\n","operationId":"GET_/api/v1/github-connector/repositories","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get github repositories","tags":["api/v1/github-connector"]}},"/api/v1/health":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/health.HealthCheck`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"health check","tags":["api/v1/health"]}},"/api/v1/health/versions":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).BasicRoutes.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/api/v1/health/versions","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1","tags":["api/v1/health","versions"]}},"/api/v1/notification/preferences":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetPreferences`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get preferences","tags":["api/v1/notification","preferences"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdatePreference`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/preferences","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdatePreferenceRequest"}}},"description":"Request body for notification.UpdatePreferenceRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update preference","tags":["api/v1/notification","preferences"]}},"/api/v1/notification/smtp":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteSMTPConfigRequest"}}},"description":"Request body for notification.DeleteSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete smtp","tags":["api/v1/notification","smtp"]},"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get smtp","tags":["api/v1/notification","smtp"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).AddSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateSMTPConfigRequest"}}},"description":"Request body for notification.CreateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add smtp","tags":["api/v1/notification","smtp"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateSmtp`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/smtp","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateSMTPConfigRequest"}}},"description":"Request body for notification.UpdateSMTPConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update smtp","tags":["api/v1/notification","smtp"]}},"/api/v1/notification/webhook":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).DeleteWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"DELETE_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteWebhookConfigRequest"}}},"description":"Request body for notification.DeleteWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete webhook config","tags":["api/v1/notification","webhook"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).CreateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"POST_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateWebhookConfigRequest"}}},"description":"Request body for notification.CreateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create webhook config","tags":["api/v1/notification","webhook"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).UpdateWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"PUT_/api/v1/notification/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateWebhookConfigRequest"}}},"description":"Request body for notification.UpdateWebhookConfigRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/notification/webhook/{type}":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/notification/controller.(*NotificationController).GetWebhookConfig`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func9`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func10`\n\n---\n\n","operationId":"GET_/api/v1/notification/webhook/:type","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}},{"in":"path","name":"type","required":true,"schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get webhook config","tags":["api/v1/notification","webhook"]}},"/api/v1/organizations":{"delete":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).DeleteOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"DELETE_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/DeleteOrganizationRequest"}}},"description":"Request body for types.DeleteOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"delete organization","tags":["api/v1/organizations"]},"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).CreateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/CreateOrganizationRequest"}}},"description":"Request body for types.CreateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"create organization","tags":["api/v1/organizations"]},"put":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"PUT_/api/v1/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateOrganizationRequest"}}},"description":"Request body for types.UpdateOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/add-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).AddUserToOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/add-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/AddUserToOrganizationRequest"}}},"description":"Request body for types.AddUserToOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"add user to organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/remove-user":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).RemoveUserFromOrganization`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/remove-user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/RemoveUserFromOrganizationRequest"}}},"description":"Request body for types.RemoveUserFromOrganizationRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"remove user from organization","tags":["api/v1/organizations"]}},"/api/v1/organizations/resources":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetResources`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/resources","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get resources","tags":["api/v1/organizations"]}},"/api/v1/organizations/roles":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetRoles`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/roles","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get roles","tags":["api/v1/organizations"]}},"/api/v1/organizations/update-user-role":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).UpdateUserRole`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"POST_/api/v1/organizations/update-user-role","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserRoleRequest"}}},"description":"Request body for controller.UpdateUserRoleRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user role","tags":["api/v1/organizations"]}},"/api/v1/organizations/users":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/organization/controller.(*OrganizationsController).GetOrganizationUsers`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func11`\n\n---\n\n","operationId":"GET_/api/v1/organizations/users","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/GetOrganizationUsersRequest"}}},"description":"Request body for controller.GetOrganizationUsersRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get organization users","tags":["api/v1/organizations"]}},"/api/v1/update":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).PerformUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"POST_/api/v1/update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateRequest"}}},"description":"Request body for types.UpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"perform update","tags":["api/v1/update"]}},"/api/v1/update/check":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/update/controller.(*UpdateController).CheckForUpdates`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/update/check","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}},"application/xml":{"schema":{"$ref":"#/components/schemas/UpdateCheckResponse"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"check for updates","tags":["api/v1/update"]}},"/api/v1/user":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserDetails`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user details","tags":["api/v1/user"]}},"/api/v1/user/avatar":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAvatar`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/avatar","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAvatarRequest"}}},"description":"Request body for types.UpdateAvatarRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update avatar","tags":["api/v1/user"]}},"/api/v1/user/name":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateUserName`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/name","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateUserNameRequest"}}},"description":"Request body for types.UpdateUserNameRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update user name","tags":["api/v1/user"]}},"/api/v1/user/organizations":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetUserOrganizations`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/organizations","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get user organizations","tags":["api/v1/user"]}},"/api/v1/user/settings":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).GetSettings`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"GET_/api/v1/user/settings","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"get settings","tags":["api/v1/user"]}},"/api/v1/user/settings/auto-update":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateAutoUpdate`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/auto-update","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateAutoUpdateRequest"}}},"description":"Request body for controller.UpdateAutoUpdateRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update auto update","tags":["api/v1/user"]}},"/api/v1/user/settings/font":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateFont`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/font","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateFontRequest"}}},"description":"Request body for controller.UpdateFontRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update font","tags":["api/v1/user"]}},"/api/v1/user/settings/language":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateLanguage`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/language","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateLanguageRequest"}}},"description":"Request body for controller.UpdateLanguageRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update language","tags":["api/v1/user"]}},"/api/v1/user/settings/theme":{"patch":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/user/controller.(*UserController).UpdateTheme`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func1`\n- `github.com/raghavyuva/nixopus-api/internal.(*Router).Routes.func2`\n\n---\n\n","operationId":"PATCH_/api/v1/user/settings/theme","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"requestBody":{"content":{"*/*":{"schema":{"$ref":"#/components/schemas/UpdateThemeRequest"}}},"description":"Request body for controller.UpdateThemeRequest","required":true},"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"update theme","tags":["api/v1/user"]}},"/api/v1/webhook":{"post":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal/features/deploy/controller.(*DeployController).HandleGithubWebhook`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"POST_/api/v1/webhook","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Response"}},"application/xml":{"schema":{"$ref":"#/components/schemas/Response"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"handle github webhook","tags":["api/v1/webhook"]}},"/ws":{"get":{"description":"#### Controller: \n\n`github.com/raghavyuva/nixopus-api/internal.(*Router).WebSocketServer.func1`\n\n#### Middlewares:\n\n- `github.com/go-fuego/fuego.defaultLogger.middleware`\n\n---\n\n","operationId":"GET_/ws","parameters":[{"in":"header","name":"Accept","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/unknown-interface"}},"application/xml":{"schema":{"$ref":"#/components/schemas/unknown-interface"}}},"description":"OK"},"400":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Bad Request _(validation or deserialization error)_"},"500":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPError"}},"application/xml":{"schema":{"$ref":"#/components/schemas/HTTPError"}}},"description":"Internal Server Error _(panics)_"},"default":{"description":""}},"summary":"func1"}}},"servers":[{"description":"local server","url":"http://:8080"}],"tags":[{"name":"api/v1/audit"},{"name":"api/v1/auth"},{"name":"api/v1/container"},{"name":"api/v1/deploy"},{"name":"api/v1/domain"},{"name":"api/v1/domains"},{"name":"api/v1/feature-flags"},{"name":"api/v1/file-manager"},{"name":"api/v1/github-connector"},{"name":"api/v1/health"},{"name":"api/v1/notification"},{"name":"api/v1/organizations"},{"name":"api/v1/update"},{"name":"api/v1/user"},{"name":"api/v1/webhook"},{"name":"application"},{"name":"preferences"},{"name":"smtp"},{"name":"versions"},{"name":"webhook"}]} \ No newline at end of file diff --git a/api/internal/routes.go b/api/internal/routes.go index f3fa86c6..578402b7 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -72,11 +72,9 @@ func (router *Router) Routes() { // Build server address based on environment ENV := os.Getenv("ENV") HOST := os.Getenv("HOST") - var serverAddr string = "" + var serverAddr string = ":" + PORT - if ENV == "production" && HOST != "" { - serverAddr = HOST + ":" + PORT - } else { + if ENV == "development" { serverAddr = "localhost:" + PORT } @@ -252,6 +250,8 @@ func (router *Router) Routes() { }) router.ContainerRoutes(containerGroup, containerController) + log.Printf("Server starting on port %s", PORT) + log.Printf("Swagger UI available at: http://localhost:%s/swagger/", PORT) server.Run() } From 861009b8faf2fb3c76afd1da96679361a508e271 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Wed, 2 Jul 2025 04:30:07 +0530 Subject: [PATCH 16/72] pr-review: addressed comments --- api/internal/routes.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/internal/routes.go b/api/internal/routes.go index 578402b7..1b7ad321 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -65,13 +65,8 @@ func (router *Router) Routes() { log.Fatal("Error loading .env file") } PORT := os.Getenv("PORT") - if PORT == "" { - PORT = "8080" - } - // Build server address based on environment ENV := os.Getenv("ENV") - HOST := os.Getenv("HOST") var serverAddr string = ":" + PORT if ENV == "development" { From f475f567858aa97567724ba787ccf7e88aa7a09e Mon Sep 17 00:00:00 2001 From: shravan20 Date: Wed, 2 Jul 2025 04:35:47 +0530 Subject: [PATCH 17/72] pr-review: addressed comments --- api/api/versions.json | 2 +- api/internal/routes.go | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index 90e7b7e6..4774377c 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-07-02T04:28:01.164547+05:30", + "release_date": "2025-07-02T04:34:57.047815+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/routes.go b/api/internal/routes.go index 1b7ad321..f4ded987 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -66,13 +66,6 @@ func (router *Router) Routes() { } PORT := os.Getenv("PORT") - ENV := os.Getenv("ENV") - var serverAddr string = ":" + PORT - - if ENV == "development" { - serverAddr = "localhost:" + PORT - } - docs := api.NewVersionDocumentation() if err := docs.Save("api/versions.json"); err != nil { log.Printf("Warning: Failed to save version documentation: %v", err) @@ -97,7 +90,7 @@ func (router *Router) Routes() { WithDescription("Enter your JWT token in the format: Bearer "), }, }), - fuego.WithAddr(serverAddr), + fuego.WithAddr(":"+PORT), ) apiV1 := api.NewVersion(api.CurrentVersion) From 82a7600fe7a9200ea4a49f04b42ae3ab21e031c8 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Wed, 2 Jul 2025 04:36:44 +0530 Subject: [PATCH 18/72] pr-review: addressed comments --- api/api/versions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/api/versions.json b/api/api/versions.json index 4774377c..d60273d8 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-07-02T04:34:57.047815+05:30", + "release_date": "2025-07-02T04:35:58.036054+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" From f121d381fb3eb5bbe014363152acfc29dddedb38 Mon Sep 17 00:00:00 2001 From: shravan20 Date: Wed, 2 Jul 2025 04:37:46 +0530 Subject: [PATCH 19/72] pr-review: addressed comments --- docker-compose-staging.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose-staging.yml b/docker-compose-staging.yml index d3a3d1e1..55c37387 100644 --- a/docker-compose-staging.yml +++ b/docker-compose-staging.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" services: nixopus-staging-api: @@ -45,7 +45,8 @@ services: networks: - nixopus-network healthcheck: - test: [ "CMD-SHELL", "pg_isready -U ${USERNAME} -d ${DB_NAME} -p ${DB_PORT}" ] + test: + ["CMD-SHELL", "pg_isready -U ${USERNAME} -d ${DB_NAME} -p ${DB_PORT}"] interval: 5s timeout: 5s retries: 5 From 041c911a440bcae4871ccd1a311644a6cc9a8944 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Fri, 4 Jul 2025 16:53:16 +0530 Subject: [PATCH 20/72] feat: supports multiple terminal sessions (limited to 3 max sessions for now) --- api/api/versions.json | 2 +- api/internal/features/terminal/init.go | 35 ++-- api/internal/realtime/init.go | 10 +- api/internal/realtime/terminal_handler.go | 56 ++++-- view/app/terminal/terminal.tsx | 202 +++++++++++++++++----- view/app/terminal/utils/useTerminal.ts | 53 +++--- view/package.json | 1 + view/yarn.lock | 5 + 8 files changed, 249 insertions(+), 115 deletions(-) diff --git a/api/api/versions.json b/api/api/versions.json index 28f73096..b134caad 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T20:48:43.246107+05:30", + "release_date": "2025-07-04T16:49:34.255475+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/features/terminal/init.go b/api/internal/features/terminal/init.go index 19ee9778..534956cf 100644 --- a/api/internal/features/terminal/init.go +++ b/api/internal/features/terminal/init.go @@ -20,9 +20,10 @@ type TermSize struct { } type TerminalMessage struct { - Type string `json:"type"` - Data string `json:"data,omitempty"` - Size *TermSize `json:"size,omitempty"` + TerminalId string `json:"terminal_id"` + Type string `json:"type"` + Data string `json:"data,omitempty"` + Size *TermSize `json:"size,omitempty"` } type Terminal struct { @@ -38,9 +39,11 @@ type Terminal struct { client *goph.Client session *ssh.Session stdin io.WriteCloser + + TerminalId string } -func NewTerminal(conn *websocket.Conn, log *logger.Logger) (*Terminal, error) { +func NewTerminal(conn *websocket.Conn, log *logger.Logger, terminalId string) (*Terminal, error) { ssh_client := sshpkg.NewSSH() terminal := &Terminal{ ssh: ssh_client, @@ -49,6 +52,7 @@ func NewTerminal(conn *websocket.Conn, log *logger.Logger) (*Terminal, error) { outputBuf: make([]byte, 0, 4096), bufferTime: 10 * time.Millisecond, log: *log, + TerminalId: terminalId, } terminal.bufferTick = time.NewTicker(terminal.bufferTime) @@ -163,8 +167,13 @@ func (t *Terminal) readOutput(r io.Reader) { t.outputBuf = append(t.outputBuf, buf[:n]...) }() + msg := TerminalMessage{ + TerminalId: t.TerminalId, + Type: "stdout", + Data: string(buf[:n]), + } t.wsLock.Lock() - err = t.conn.WriteMessage(websocket.TextMessage, buf[:n]) + err = t.conn.WriteJSON(msg) t.wsLock.Unlock() if err != nil { @@ -194,19 +203,15 @@ func (t *Terminal) flushBuffer() { defer t.wsLock.Unlock() if len(t.outputBuf) > 0 { - err := t.conn.WriteJSON(map[string]interface{}{ - "data": map[string]interface{}{ - "output_type": "stdout", - "content": string(t.outputBuf), - "timestamp": time.Now().Unix(), - }, - "topic": "terminal", - }) - + msg := TerminalMessage{ + TerminalId: t.TerminalId, + Type: "stdout", + Data: string(t.outputBuf), + } + err := t.conn.WriteJSON(msg) if err != nil { t.log.Log(logger.Error, "Error writing websocket message", err.Error()) } - t.outputBuf = t.outputBuf[:0] } } diff --git a/api/internal/realtime/init.go b/api/internal/realtime/init.go index 3eacc8c5..761e248e 100644 --- a/api/internal/realtime/init.go +++ b/api/internal/realtime/init.go @@ -49,7 +49,7 @@ type SocketServer struct { ctx context.Context postgres_listener PostgresListener terminalMutex sync.RWMutex - terminals map[*websocket.Conn]*terminal.Terminal + terminals map[*websocket.Conn]map[string]*terminal.Terminal // conn -> terminalId -> terminal session for handling multiple terminal sessions per connection dashboardMonitors map[*websocket.Conn]*dashboard.DashboardMonitor dashboardMutex sync.Mutex applicationMonitors map[*websocket.Conn]*realtime.ApplicationMonitor @@ -73,7 +73,7 @@ func NewSocketServer(deployController *deploy.DeployController, db *bun.DB, ctx ctx: ctx, topics: make(map[string]map[*websocket.Conn]bool), postgres_listener: *pgListener, - terminals: make(map[*websocket.Conn]*terminal.Terminal), + terminals: make(map[*websocket.Conn]map[string]*terminal.Terminal), dashboardMonitors: make(map[*websocket.Conn]*dashboard.DashboardMonitor), applicationMonitors: make(map[*websocket.Conn]*realtime.ApplicationMonitor), } @@ -155,8 +155,10 @@ func (s *SocketServer) handleDisconnect(conn *websocket.Conn) { s.topicsMu.Unlock() s.terminalMutex.Lock() - if term, exists := s.terminals[conn]; exists { - term.Close() + if terminalSessions, exists := s.terminals[conn]; exists { + for _, terminalSession := range terminalSessions { + terminalSession.Close() + } delete(s.terminals, conn) } s.terminalMutex.Unlock() diff --git a/api/internal/realtime/terminal_handler.go b/api/internal/realtime/terminal_handler.go index 092990b0..6ade3058 100644 --- a/api/internal/realtime/terminal_handler.go +++ b/api/internal/realtime/terminal_handler.go @@ -17,26 +17,40 @@ func (s *SocketServer) handleTerminal(conn *websocket.Conn, msg types.Payload) { s.terminalMutex.Lock() defer s.terminalMutex.Unlock() - term, exists := s.terminals[conn] - if exists { - term.WriteMessage(msg.Data.(string)) + dataMap, ok := msg.Data.(map[string]interface{}) + if !ok { + s.sendError(conn, "Invalid terminal data") return } - - newTerminal, err := terminal.NewTerminal(conn, &logger.Logger{}) - if err != nil { - s.sendError(conn, "Failed to start terminal") + terminalId, ok := dataMap["terminalId"].(string) + if !ok { + s.sendError(conn, "Missing terminalId") return } - - if existingTerm, exists := s.terminals[conn]; exists { - existingTerm.WriteMessage(msg.Data.(string)) + input, ok := dataMap["value"].(string) + if !ok { + s.sendError(conn, "Invalid terminal input") return } - s.terminals[conn] = newTerminal - newTerminal.WriteMessage(msg.Data.(string)) - go newTerminal.Start() + // Ensure map exists for this connection + if s.terminals[conn] == nil { + s.terminals[conn] = make(map[string]*terminal.Terminal) + } + + term, exists := s.terminals[conn][terminalId] + if !exists { + newTerminal, err := terminal.NewTerminal(conn, &logger.Logger{}, terminalId) + if err != nil { + s.sendError(conn, "Failed to start terminal") + return + } + s.terminals[conn][terminalId] = newTerminal + go newTerminal.Start() + term = newTerminal + } + + term.WriteMessage(input) } // handleTerminalResize handles the terminal resize. @@ -49,15 +63,21 @@ func (s *SocketServer) handleTerminalResize(conn *websocket.Conn, msg types.Payl s.terminalMutex.Lock() defer s.terminalMutex.Unlock() - term, exists := s.terminals[conn] - if !exists { - s.sendError(conn, "Terminal not started") + data, ok := msg.Data.(map[string]interface{}) + if !ok { + s.sendError(conn, "Invalid resize data") return } - data, ok := msg.Data.(map[string]interface{}) + terminalId, ok := data["terminalId"].(string) if !ok { - s.sendError(conn, "Invalid resize data") + s.sendError(conn, "Missing terminalId") + return + } + + term, exists := s.terminals[conn][terminalId] + if !exists { + s.sendError(conn, "Terminal not started") return } diff --git a/view/app/terminal/terminal.tsx b/view/app/terminal/terminal.tsx index 01d71fb5..98681587 100644 --- a/view/app/terminal/terminal.tsx +++ b/view/app/terminal/terminal.tsx @@ -3,14 +3,16 @@ import React, { useEffect, useState, useRef, useCallback } from 'react'; import '@xterm/xterm/css/xterm.css'; import { useTerminal } from './utils/useTerminal'; import { useContainerReady } from './utils/isContainerReady'; -import { X } from 'lucide-react'; +import { Plus, X } from 'lucide-react'; import { useTranslation } from '@/hooks/use-translation'; import { useFeatureFlags } from '@/hooks/features_provider'; import DisabledFeature from '@/components/features/disabled-feature'; import Skeleton from '@/app/file-manager/components/skeleton/Skeleton'; import { FeatureNames } from '@/types/feature-flags'; -import { AnyPermissionGuard, ResourceGuard } from '@/components/rbac/PermissionGuard'; +import { AnyPermissionGuard } from '@/components/rbac/PermissionGuard'; import { useRBAC } from '@/lib/rbac'; +import { Button } from '@/components/ui/button'; +import { v4 as uuidv4 } from 'uuid'; const globalStyles = ` .xterm-viewport::-webkit-scrollbar { @@ -29,6 +31,66 @@ type TerminalProps = { setFitAddonRef: React.Dispatch>; }; +const TerminalSession: React.FC<{ + isActive: boolean; + isTerminalOpen: boolean; + dimensions: { width: number; height: number }; + canCreate: boolean; + canUpdate: boolean; + setFitAddonRef: React.Dispatch>; + terminalId: string; +}> = ({ + isActive, + isTerminalOpen, + dimensions, + canCreate, + canUpdate, + setFitAddonRef, + terminalId +}) => { + const { terminalRef, fitAddonRef, initializeTerminal, destroyTerminal } = useTerminal( + isTerminalOpen && isActive, + dimensions.width, + dimensions.height, + canCreate || canUpdate, + terminalId + ); + const isContainerReady = useContainerReady( + isTerminalOpen && isActive, + terminalRef as React.RefObject + ); + + useEffect(() => { + if (isTerminalOpen && isActive && isContainerReady) { + initializeTerminal(); + } + }, [isTerminalOpen, isActive, isContainerReady, initializeTerminal]); + + useEffect(() => { + if (fitAddonRef) { + setFitAddonRef(fitAddonRef); + } + }, [fitAddonRef, setFitAddonRef]); + + return ( +
+ ); +}; + export const Terminal: React.FC = ({ isOpen, toggleTerminal, @@ -37,27 +99,17 @@ export const Terminal: React.FC = ({ }) => { const { t } = useTranslation(); const [dimensions, setDimensions] = useState({ width: 0, height: 0 }); + const [sessions, setSessions] = useState([{ id: uuidv4(), label: 'Session 1' }]); + const [activeSessionId, setActiveSessionId] = useState(sessions[0].id); const containerRef = useRef(null); const resizeTimeoutRef = useRef(undefined); const { canAccessResource } = useRBAC(); const canCreate = canAccessResource('terminal', 'create'); const canUpdate = canAccessResource('terminal', 'update'); - - const { terminalRef, fitAddonRef, initializeTerminal, destroyTerminal } = useTerminal( - isTerminalOpen, - dimensions.width, - dimensions.height, - canCreate || canUpdate // Only allow input if user can create or update - ) as { - terminalRef: React.RefObject; - fitAddonRef: any; - initializeTerminal: () => void; - destroyTerminal: () => void; - }; - - const isContainerReady = useContainerReady(isTerminalOpen, terminalRef); const { isFeatureEnabled, isLoading: isFeatureFlagsLoading } = useFeatureFlags(); + const SESSION_LIMIT = 3; + const updateDimensions = useCallback(() => { if (!containerRef.current) return; @@ -91,20 +143,6 @@ export const Terminal: React.FC = ({ }; }, [isTerminalOpen, updateDimensions]); - useEffect(() => { - if (isTerminalOpen && isContainerReady) { - initializeTerminal(); - } else { - destroyTerminal(); - } - }, [isTerminalOpen, isContainerReady, initializeTerminal, destroyTerminal]); - - useEffect(() => { - if (fitAddonRef) { - setFitAddonRef(fitAddonRef); - } - }, [fitAddonRef, setFitAddonRef]); - useEffect(() => { const style = document.createElement('style'); style.textContent = globalStyles; @@ -114,6 +152,33 @@ export const Terminal: React.FC = ({ }; }, []); + const addSession = () => { + if (sessions.length >= SESSION_LIMIT) { + return; + } + const newSession = { + id: uuidv4(), + label: `Session ${sessions.length + 1}` + }; + setSessions((prev) => [...prev, newSession]); + setActiveSessionId(newSession.id); + }; + + const closeSession = (id: string) => { + setSessions((prev) => { + const idx = prev.findIndex((s) => s.id === id); + const newSessions = prev.filter((s) => s.id !== id); + if (id === activeSessionId && newSessions.length > 0) { + setActiveSessionId(newSessions[Math.max(0, idx - 1)].id); + } + return newSessions; + }); + }; + + const switchSession = (id: string) => { + setActiveSessionId(id); + }; + if (isFeatureFlagsLoading) { return ; } @@ -123,7 +188,7 @@ export const Terminal: React.FC = ({ } return ( - } > @@ -137,29 +202,70 @@ export const Terminal: React.FC = ({ {t('terminal.title')} {t('terminal.shortcut')}
-
- + )} +
+ ))} + {sessions.length < SESSION_LIMIT && ( + + )} + + -
+
+ {sessions.map((session) => ( +
+ +
+ ))} +
); diff --git a/view/app/terminal/utils/useTerminal.ts b/view/app/terminal/utils/useTerminal.ts index 26f707bd..206d0b7f 100644 --- a/view/app/terminal/utils/useTerminal.ts +++ b/view/app/terminal/utils/useTerminal.ts @@ -22,7 +22,8 @@ export const useTerminal = ( isTerminalOpen: boolean, width: number, height: number, - allowInput: boolean = true + allowInput: boolean = true, + terminalId: string = 'terminal_id' ) => { const terminalRef = useRef(null); const fitAddonRef = useRef(null); @@ -39,20 +40,14 @@ export const useTerminal = ( if (resizeTimeoutRef.current) { clearTimeout(resizeTimeoutRef.current); } - }, [terminalInstance]); + }, [terminalInstance, terminalId]); useEffect(() => { if (isStopped && terminalInstance) { - sendJsonMessage({ action: 'terminal', data: CTRL_C }); + sendJsonMessage({ action: 'terminal', data: { value: CTRL_C, terminalId } }); setIsStopped(false); } - }, [isStopped, sendJsonMessage, setIsStopped, terminalInstance]); - - useEffect(() => { - if (!isTerminalOpen) { - destroyTerminal(); - } - }, [isTerminalOpen, destroyTerminal]); + }, [isStopped, sendJsonMessage, setIsStopped, terminalInstance, terminalId]); useEffect(() => { if (!message || !terminalInstance) return; @@ -61,23 +56,27 @@ export const useTerminal = ( const parsedMessage = typeof message === 'string' && message.startsWith('{') ? JSON.parse(message) : message; + if (parsedMessage.terminal_id !== terminalId) { + console.log('Message is not for this terminal session'); + return; + } + if (parsedMessage.action === 'error') { console.error('Terminal error:', parsedMessage.data); return; } - if (parsedMessage.data && parsedMessage.data.output_type) { - const { output_type, content } = parsedMessage.data; - if (output_type === OutputType.EXIT) { + if (parsedMessage.type) { + if (parsedMessage.type === OutputType.EXIT) { destroyTerminal(); - } else { - terminalInstance.write(content); + } else if (parsedMessage.data) { + terminalInstance.write(parsedMessage.data); } } } catch (error) { console.error('Error processing WebSocket message:', error); } - }, [message, terminalInstance, destroyTerminal]); + }, [message, terminalInstance, destroyTerminal, terminalId]); const initializeTerminal = useCallback(async () => { if (!terminalRef.current || terminalInstance || !isReady) return; @@ -133,14 +132,14 @@ export const useTerminal = ( terminalRef.current.innerHTML = ''; term.open(terminalRef.current); fitAddon.activate(term); - + if (allowInput) { sendJsonMessage({ action: 'terminal', - data: '\r' + data: { value: '\r', terminalId } }); } - + requestAnimationFrame(() => { fitAddon.fit(); const dimensions = fitAddon.proposeDimensions(); @@ -149,7 +148,8 @@ export const useTerminal = ( action: 'terminal_resize', data: { cols: dimensions.cols, - rows: dimensions.rows + rows: dimensions.rows, + terminalId } }); } @@ -159,7 +159,7 @@ export const useTerminal = ( term.onData((data) => { sendJsonMessage({ action: 'terminal', - data + data: { value: data, terminalId } }); }); } @@ -169,7 +169,8 @@ export const useTerminal = ( action: 'terminal_resize', data: { cols: size.cols, - rows: size.rows + rows: size.rows, + terminalId } }); }); @@ -179,13 +180,7 @@ export const useTerminal = ( } catch (error) { console.error('Error initializing terminal:', error); } - }, [sendJsonMessage, isReady, terminalRef, terminalInstance, allowInput]); - - useEffect(() => { - return () => { - destroyTerminal(); - }; - }, [destroyTerminal]); + }, [sendJsonMessage, isReady, terminalRef, terminalInstance, allowInput, terminalId]); return { terminalRef, diff --git a/view/package.json b/view/package.json index cfec5eb0..a198d8c1 100644 --- a/view/package.json +++ b/view/package.json @@ -60,6 +60,7 @@ "sonner": "^2.0.1", "tailwind-merge": "^3.0.2", "tailwindcss-animate": "^1.0.7", + "uuid": "^11.1.0", "xterm-addon-fit": "^0.8.0", "xterm-addon-web-links": "^0.9.0", "zod": "^3.24.2" diff --git a/view/yarn.lock b/view/yarn.lock index 970feb15..2d4eaf6d 100644 --- a/view/yarn.lock +++ b/view/yarn.lock @@ -4234,6 +4234,11 @@ use-sync-external-store@^1.4.0: resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.5.0.tgz#55122e2a3edd2a6c106174c27485e0fd59bcfca0" integrity sha512-Rb46I4cGGVBmjamjphe8L/UnvJD+uPPtTkNvX5mZgqdbavhI4EbgIWJiIHXJ8bc/i9EQGPRh4DwEURJ552Do0A== +uuid@^11.1.0: + version "11.1.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.1.0.tgz#9549028be1753bb934fc96e2bca09bb4105ae912" + integrity sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A== + victory-vendor@^36.6.8: version "36.9.2" resolved "https://registry.yarnpkg.com/victory-vendor/-/victory-vendor-36.9.2.tgz#668b02a448fa4ea0f788dbf4228b7e64669ff801" From 623e794f7d5a39278f099b61fc908063877e8a16 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Fri, 4 Jul 2025 18:30:43 +0530 Subject: [PATCH 21/72] Revert "test-cases: E2E test cases for Domain and Container flow" --- .../domain/controller/create_domain.go | 15 - .../domain/controller/delete_domain.go | 15 - .../domain/controller/error_helpers.go | 27 - .../features/domain/controller/get_domains.go | 74 +- .../domain/controller/update_domain.go | 15 - api/internal/features/domain/storage/init.go | 31 +- api/internal/routes.go | 2 - .../container/get_container_logs_test.go | 396 -------- .../tests/container/get_container_test.go | 216 ----- .../tests/container/list_containers_test.go | 156 ---- api/internal/tests/domain/domain_flow_test.go | 880 ------------------ api/internal/tests/helper.go | 24 - docker-compose-staging.yml | 5 +- docker-compose-test.yml | 19 - .../self-host/hooks/use_create_deployment.ts | 1 + .../self-host/hooks/use_update_deployment.ts | 2 +- .../domains/components/delete-domain.tsx | 2 +- view/app/settings/domains/page.tsx | 2 +- .../domains/random-subdomain-generator.tsx | 56 -- view/redux/services/settings/domainsApi.ts | 35 +- view/redux/types/domain.ts | 19 - 21 files changed, 37 insertions(+), 1955 deletions(-) delete mode 100644 api/internal/features/domain/controller/error_helpers.go delete mode 100644 api/internal/tests/container/get_container_logs_test.go delete mode 100644 api/internal/tests/container/get_container_test.go delete mode 100644 api/internal/tests/container/list_containers_test.go delete mode 100644 api/internal/tests/domain/domain_flow_test.go delete mode 100644 docker-compose-test.yml delete mode 100644 view/components/domains/random-subdomain-generator.tsx diff --git a/api/internal/features/domain/controller/create_domain.go b/api/internal/features/domain/controller/create_domain.go index 0668b693..2916c951 100644 --- a/api/internal/features/domain/controller/create_domain.go +++ b/api/internal/features/domain/controller/create_domain.go @@ -42,21 +42,6 @@ func (c *DomainsController) CreateDomain(f fuego.ContextWithBody[types.CreateDom if err != nil { c.logger.Log(logger.Error, err.Error(), "") - - if isInvalidDomainError(err) { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusBadRequest, - } - } - - if err == types.ErrDomainAlreadyExists { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusConflict, - } - } - return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/controller/delete_domain.go b/api/internal/features/domain/controller/delete_domain.go index 1890d9d3..ce8703bb 100644 --- a/api/internal/features/domain/controller/delete_domain.go +++ b/api/internal/features/domain/controller/delete_domain.go @@ -31,21 +31,6 @@ func (c *DomainsController) DeleteDomain(f fuego.ContextWithBody[types.DeleteDom err = c.service.DeleteDomain(domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") - - if isInvalidDomainError(err) { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusBadRequest, - } - } - - if err == types.ErrDomainNotFound { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusNotFound, - } - } - return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/controller/error_helpers.go b/api/internal/features/domain/controller/error_helpers.go deleted file mode 100644 index 05e70c0b..00000000 --- a/api/internal/features/domain/controller/error_helpers.go +++ /dev/null @@ -1,27 +0,0 @@ -package controller - -import "github.com/raghavyuva/nixopus-api/internal/features/domain/types" - -func isInvalidDomainError(err error) bool { - switch err { - case types.ErrInvalidDomainID, - types.ErrMissingDomainID, - types.ErrDomainNameInvalid, - types.ErrDomainNameTooLong, - types.ErrDomainNameTooShort, - types.ErrMissingDomainName: - return true - default: - return false - } -} - -func isPermissionError(err error) bool { - switch err { - case types.ErrUserDoesNotBelongToOrganization, - types.ErrPermissionDenied: - return true - default: - return false - } -} diff --git a/api/internal/features/domain/controller/get_domains.go b/api/internal/features/domain/controller/get_domains.go index b964b946..4671d940 100644 --- a/api/internal/features/domain/controller/get_domains.go +++ b/api/internal/features/domain/controller/get_domains.go @@ -7,7 +7,6 @@ import ( "time" "github.com/go-fuego/fuego" - "github.com/google/uuid" "github.com/raghavyuva/nixopus-api/internal/features/domain/types" "github.com/raghavyuva/nixopus-api/internal/features/logger" "github.com/raghavyuva/nixopus-api/internal/utils" @@ -16,46 +15,24 @@ import ( ) func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Response, error) { - w, r := f.Response(), f.Request() + organization_id := f.QueryParam("id") - organization_id := utils.GetOrganizationID(r) - if organization_id == uuid.Nil { - c.logger.Log(logger.Error, "invalid organization id", "") - return nil, fuego.HTTPError{ - Err: types.ErrMissingID, - Status: http.StatusBadRequest, - } - } + w, r := f.Response(), f.Request() user := utils.GetUser(w, r) + if user == nil { - c.logger.Log(logger.Error, "unauthorized user", "") return nil, fuego.HTTPError{ - Err: types.ErrAccessDenied, + Err: nil, Status: http.StatusUnauthorized, } } c.logger.Log(logger.Info, "fetching domains", fmt.Sprintf("organization_id: %s", organization_id)) - domains, err := c.service.GetDomains(organization_id.String(), user.ID) + domains, err := c.service.GetDomains(organization_id, user.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") - - if isPermissionError(err) { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusForbidden, - } - } - - if err == types.ErrDomainNotFound { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusNotFound, - } - } - return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, @@ -72,42 +49,11 @@ func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Res func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*shared_types.Response, error) { w, r := f.Response(), f.Request() - organization_id := utils.GetOrganizationID(r) - if organization_id == uuid.Nil { - c.logger.Log(logger.Error, "invalid organization id", "") - return nil, fuego.HTTPError{ - Err: types.ErrMissingID, - Status: http.StatusBadRequest, - } - } - - user := utils.GetUser(w, r) - if user == nil { - c.logger.Log(logger.Error, "unauthorized user", "") - return nil, fuego.HTTPError{ - Err: types.ErrAccessDenied, - Status: http.StatusUnauthorized, - } - } + organization_id := f.QueryParam("id") - domains, err := c.service.GetDomains(organization_id.String(), user.ID) + domains, err := c.service.GetDomains(organization_id, utils.GetUser(w, r).ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") - - if isPermissionError(err) { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusForbidden, - } - } - - if err == types.ErrDomainNotFound { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusNotFound, - } - } - return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, @@ -115,10 +61,10 @@ func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*sha } if len(domains) == 0 { - c.logger.Log(logger.Error, "no domains available for subdomain generation", "") + c.logger.Log(logger.Error, "no domains available", "") return nil, fuego.HTTPError{ - Err: types.ErrDomainNotFound, - Status: http.StatusNotFound, + Err: nil, + Status: http.StatusBadRequest, } } diff --git a/api/internal/features/domain/controller/update_domain.go b/api/internal/features/domain/controller/update_domain.go index d0a4c7f3..ce25def2 100644 --- a/api/internal/features/domain/controller/update_domain.go +++ b/api/internal/features/domain/controller/update_domain.go @@ -41,21 +41,6 @@ func (c *DomainsController) UpdateDomain(f fuego.ContextWithBody[types.UpdateDom updated, err := c.service.UpdateDomain(domainRequest.Name, user.ID.String(), domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") - - if isInvalidDomainError(err) { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusBadRequest, - } - } - - if err == types.ErrDomainNotFound { - return nil, fuego.HTTPError{ - Err: err, - Status: http.StatusNotFound, - } - } - return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/storage/init.go b/api/internal/features/domain/storage/init.go index f0d7ed9a..e4152799 100644 --- a/api/internal/features/domain/storage/init.go +++ b/api/internal/features/domain/storage/init.go @@ -60,7 +60,7 @@ func (s *DomainStorage) CreateDomain(domain *shared_types.Domain) error { func (s *DomainStorage) GetDomain(id string) (*shared_types.Domain, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", id).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ?", id).Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, types.ErrDomainNotFound @@ -72,13 +72,13 @@ func (s *DomainStorage) GetDomain(id string) (*shared_types.Domain, error) { func (s *DomainStorage) UpdateDomain(ID string, Name string) error { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) if err != nil { return err } domain.Name = Name domain.UpdatedAt = time.Now() - _, err = s.getDB().NewUpdate().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Exec(s.Ctx) + _, err = s.getDB().NewUpdate().Model(&domain).Where("id = ?", ID).Exec(s.Ctx) if err != nil { return err } @@ -86,32 +86,17 @@ func (s *DomainStorage) UpdateDomain(ID string, Name string) error { } func (s *DomainStorage) DeleteDomain(domain *shared_types.Domain) error { - now := time.Now() - result, err := s.getDB().NewUpdate().Model(domain). - Set("deleted_at = ?", now). - Set("updated_at = ?", now). - Where("id = ? AND deleted_at IS NULL", domain.ID). - Exec(s.Ctx) + _, err := s.getDB().NewDelete().Model(domain).Where("id = ?", domain.ID).Exec(s.Ctx) if err != nil { return err } - - rowsAffected, err := result.RowsAffected() - if err != nil { - return err - } - - if rowsAffected == 0 { - return types.ErrDomainNotFound - } - return nil } func (s *DomainStorage) GetDomains(OrganizationID string, UserID uuid.UUID) ([]shared_types.Domain, error) { var domains []shared_types.Domain err := s.getDB().NewSelect().Model(&domains). - Where("organization_id = ? AND deleted_at IS NULL", OrganizationID). + Where("organization_id = ?", OrganizationID). Scan(s.Ctx) if err != nil { return nil, err @@ -122,7 +107,7 @@ func (s *DomainStorage) GetDomains(OrganizationID string, UserID uuid.UUID) ([]s func (s *DomainStorage) GetDomainByName(name string, organizationID uuid.UUID) (*shared_types.Domain, error) { var domain shared_types.Domain err := s.getDB().NewSelect().Model(&domain). - Where("name = ? AND organization_id = ? AND deleted_at IS NULL", name, organizationID). + Where("name = ? AND organization_id = ?", name, organizationID). Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -135,7 +120,7 @@ func (s *DomainStorage) GetDomainByName(name string, organizationID uuid.UUID) ( func (s *DomainStorage) IsDomainExists(ID string) (bool, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { return false, nil @@ -147,7 +132,7 @@ func (s *DomainStorage) IsDomainExists(ID string) (bool, error) { func (s *DomainStorage) GetDomainOwnerByID(ID string) (string, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) if err != nil { return "", err } diff --git a/api/internal/routes.go b/api/internal/routes.go index f0c90737..b4867e7c 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -244,8 +244,6 @@ func (router *Router) Routes() { }) router.ContainerRoutes(containerGroup, containerController) - log.Printf("Server starting on port %s", PORT) - log.Printf("Swagger UI available at: http://localhost:%s/swagger/", PORT) server.Run() } diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go deleted file mode 100644 index 067889bc..00000000 --- a/api/internal/tests/container/get_container_logs_test.go +++ /dev/null @@ -1,396 +0,0 @@ -package container - -import ( - "net/http" - "testing" - - . "github.com/Eun/go-hit" - "github.com/raghavyuva/nixopus-api/internal/tests" - "github.com/raghavyuva/nixopus-api/internal/testutils" -) - -func TestGetContainerLogs(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // Note: First, get a container ID from the list; sue the same for test validation (PSQL test db container) - // Test cases are designed to work with an existing container. - // TODO: Run a script on pre running E2E tests to create a containers & add as DB seeding - var containerID string - Test(t, - Description("Get container id for logs tests"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), - ) - - testCases := []struct { - name string - containerID string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully fetch container logs with valid ID and token", - containerID: containerID, - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should return container logs with valid authentication", - }, - { - name: "Unauthorized request without token", - containerID: containerID, - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - containerID: containerID, - token: "invalid-token", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - containerID: containerID, - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - { - name: "Request with invalid container ID", - containerID: "invalid-container-id", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusInternalServerError, - description: "Should return 500 when container ID doesn't exist", - }, - { - name: "Request with empty container ID", - containerID: "", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusInternalServerError, - description: "Should return 500 when container ID is empty", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - testSteps := []IStep{ - Description(tc.description), - Post(tests.GetContainerLogsURL(tc.containerID)), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - requestBody := map[string]interface{}{ - "id": tc.containerID, - "follow": false, - "tail": 100, - "stdout": true, - "stderr": true, - } - testSteps = append(testSteps, Send().Body().JSON(requestBody)) - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestGetContainerLogsWithFilters(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - var containerID string - Test(t, - Description("Get container ID for logs filter tests"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), - ) - - t.Run("Fetch logs with tail parameter", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": containerID, - "follow": false, - "tail": 50, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should return limited number of log lines when tail parameter is provided"), - Post(tests.GetContainerLogsURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - ) - }) - - t.Run("Fetch logs with since parameter", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": containerID, - "follow": false, - "since": "2024-01-01T00:00:00Z", - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should return logs since specified timestamp"), - Post(tests.GetContainerLogsURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), - ) - }) - - t.Run("Fetch logs with timestamps", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": containerID, - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should return logs with timestamps when timestamps=true"), - Post(tests.GetContainerLogsURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), - ) - }) - - t.Run("Fetch logs with follow parameter", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": containerID, - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should handle follow parameter for streaming logs"), - Post(tests.GetContainerLogsURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - ) - }) -} - -func TestGetContainerLogsErrorHandling(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Malformed authorization header", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": "some-container-id", - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should handle malformed authorization header gracefully"), - Post(tests.GetContainerLogsURL("some-container-id")), - Send().Headers("Authorization").Add("InvalidFormat"), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusUnauthorized), - ) - }) - - t.Run("Empty authorization header", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": "some-container-id", - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should handle empty authorization header"), - Post(tests.GetContainerLogsURL("some-container-id")), - Send().Headers("Authorization").Add(""), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusUnauthorized), - ) - }) - - t.Run("Invalid UUID format for container ID", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": "not-a-uuid", - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should handle invalid UUID format for container ID"), - Post(tests.GetContainerLogsURL("not-a-uuid")), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusInternalServerError), - ) - }) - - t.Run("Non-existent container ID with valid UUID format", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": "123e4567-e89b-12d3-a456-426614174000", - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should return 500 for non-existent container with valid UUID format"), - Post(tests.GetContainerLogsURL("123e4567-e89b-12d3-a456-426614174000")), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusInternalServerError), - ) - }) - - t.Run("Invalid tail parameter", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": "some-container-id", - "follow": false, - "tail": "invalid-number", // should throw an error since tail expects int - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should handle invalid tail parameter gracefully"), - Post(tests.GetContainerLogsURL("some-container-id")), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusBadRequest), - ) - }) - - t.Run("Invalid since parameter", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": "some-container-id", - "follow": false, - "since": "invalid-timestamp", - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should handle invalid since timestamp parameter"), - Post(tests.GetContainerLogsURL("some-container-id")), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusInternalServerError), - ) - }) -} - -func TestGetContainerLogsPermissions(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - var containerID string - Test(t, - Description("Get container ID for permission tests"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), - ) - - t.Run("Access logs with organization member permissions", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": containerID, - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should allow organization members to access container logs"), - Post(tests.GetContainerLogsURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - ) - }) - - t.Run("Cross-organization access attempt", func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": containerID, - "follow": false, - "stdout": true, - "stderr": true, - } - Test(t, - Description("Should deny access to logs from different organization"), - Post(tests.GetContainerLogsURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), - Send().Body().JSON(requestBody), - Expect().Status().Equal(http.StatusForbidden), - ) - }) -} diff --git a/api/internal/tests/container/get_container_test.go b/api/internal/tests/container/get_container_test.go deleted file mode 100644 index 0d11cc62..00000000 --- a/api/internal/tests/container/get_container_test.go +++ /dev/null @@ -1,216 +0,0 @@ -package container - -import ( - "net/http" - "testing" - - . "github.com/Eun/go-hit" - "github.com/raghavyuva/nixopus-api/internal/tests" - "github.com/raghavyuva/nixopus-api/internal/testutils" -) - -func TestGetContainer(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // First, get a container ID from the list - var containerID string - Test(t, - Description("Get container ID for individual container tests"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), - ) - - testCases := []struct { - name string - containerID string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully fetch container with valid ID and token", - containerID: containerID, - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should return container details", - }, - { - name: "Unauthorized request without token", - containerID: containerID, - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Request with invalid container ID", - containerID: "invalid-container-id", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusInternalServerError, - description: "Should return 500 when container ID is invalid/doesnt exist", - }, - { - name: "Request with container ID doesnt exist", - containerID: "1234567890123456789012345678901234567890123456789012345678901234", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusInternalServerError, - description: "Should return 500 when container doesnt exist", - }, - { - name: "Request without organization header", - containerID: containerID, - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - // Skip tests that depend on valid container ID if we couldn't get one - if tc.containerID == containerID && containerID == "" { - t.Skip("No container ID available for testing") - } - - testSteps := []IStep{ - Description(tc.description), - Get(tests.GetContainerURL(tc.containerID)), - } - - // Add authentication header if token is provided - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - // Add organization header if provided - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - // Additional validations for successful response - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Container fetched successfully"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - Expect().Body().JSON().JQ(".data.id").Equal(tc.containerID), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestGetContainerDetailedValidation(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // Get the test container ID specifically - var containerID string - Test(t, - Description("Get test container ID for detailed validation"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(`.data[] | select(.name == "nixopus-test-db-container") | .id`).In(&containerID), - ) - - if containerID == "" { - t.Skip("nixopus-test-db-container not found, skipping detailed validation") - } - - t.Run("Validate complete container structure for test container", func(t *testing.T) { - Test(t, - Description("Should return complete container structure with all expected fields"), - Get(tests.GetContainerURL(containerID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Container fetched successfully"), - Expect().Body().JSON().JQ(".data.name").Equal("nixopus-test-db-container"), - Expect().Body().JSON().JQ(".data.image").Equal("postgres:14-alpine"), - Expect().Body().JSON().JQ(".data.command").NotEqual(""), - Expect().Body().JSON().JQ(".data.status").NotEqual(""), - Expect().Body().JSON().JQ(".data.state").NotEqual(""), - Expect().Body().JSON().JQ(".data.created").NotEqual(""), - Expect().Body().JSON().JQ(".data.labels").NotEqual(nil), - Expect().Body().JSON().JQ(".data.ports").NotEqual(nil), - Expect().Body().JSON().JQ(".data.mounts").NotEqual(nil), - Expect().Body().JSON().JQ(".data.networks").NotEqual(nil), - Expect().Body().JSON().JQ(".data.host_config").NotEqual(nil), - - Expect().Body().JSON().JQ(".data.ports[0].private_port").Equal(float64(5432)), - Expect().Body().JSON().JQ(".data.ports[0].public_port").Equal(float64(5433)), - Expect().Body().JSON().JQ(".data.ports[0].type").Equal("tcp"), - - Expect().Body().JSON().JQ(".data.host_config.memory").NotEqual(nil), - Expect().Body().JSON().JQ(".data.host_config.memory_swap").NotEqual(nil), - Expect().Body().JSON().JQ(".data.host_config.cpu_shares").NotEqual(nil), - ) - }) -} - -func TestGetContainerErrorScenarios(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Container ID with special characters", func(t *testing.T) { - Test(t, - Description("Should handle container ID with special characters"), - Get(tests.GetContainerURL("container-special")), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusInternalServerError), - ) - }) - - t.Run("Empty container ID", func(t *testing.T) { - Test(t, - Description("Should handle empty container ID"), - Get(tests.GetContainerURL("")), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusNotFound), - ) - }) - - t.Run("Very long container ID", func(t *testing.T) { - longID := "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890" - Test(t, - Description("Should handle very long container ID"), - Get(tests.GetContainerURL(longID)), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusInternalServerError), - ) - }) -} diff --git a/api/internal/tests/container/list_containers_test.go b/api/internal/tests/container/list_containers_test.go deleted file mode 100644 index 093dbe32..00000000 --- a/api/internal/tests/container/list_containers_test.go +++ /dev/null @@ -1,156 +0,0 @@ -package container - -import ( - "net/http" - "testing" - - . "github.com/Eun/go-hit" - "github.com/raghavyuva/nixopus-api/internal/tests" - "github.com/raghavyuva/nixopus-api/internal/testutils" -) - -func TestListContainers(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - testCases := []struct { - name string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully fetch containers with valid token", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should return containers list with valid authentication, basically return one container which is DB test container that is up and running", - }, - { - name: "Unauthorized request without token", - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - token: "invalid-token", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - { - name: "Request with invalid organization ID", - token: user.AccessToken, - organizationID: "invalid-org-id", - expectedStatus: http.StatusInternalServerError, - description: "Should return 500 when organization ID format is invalid", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - testSteps := []IStep{ - Description(tc.description), - Get(tests.GetContainersURL()), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Containers fetched successfully"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestListContainersWithSpecificContainer(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Verify test container exists and has expected properties", func(t *testing.T) { - Test(t, - Description("Should find the nixopus-test-db-container and validate its properties"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Containers fetched successfully"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - ) - }) -} - -func TestListContainersErrorHandling(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Malformed authorization header", func(t *testing.T) { - Test(t, - Description("Should handle malformed authorization header gracefully"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("InvalidFormat"), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusUnauthorized), - ) - }) - - t.Run("Empty authorization header", func(t *testing.T) { - Test(t, - Description("Should handle empty authorization header"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add(""), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusUnauthorized), - ) - }) - - t.Run("Bearer token with extra spaces", func(t *testing.T) { - Test(t, - Description("Should handle get containers base case"), - Get(tests.GetContainersURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - ) - }) -} diff --git a/api/internal/tests/domain/domain_flow_test.go b/api/internal/tests/domain/domain_flow_test.go deleted file mode 100644 index c459ccb3..00000000 --- a/api/internal/tests/domain/domain_flow_test.go +++ /dev/null @@ -1,880 +0,0 @@ -package domain - -import ( - "net/http" - "testing" - - . "github.com/Eun/go-hit" - "github.com/raghavyuva/nixopus-api/internal/tests" - "github.com/raghavyuva/nixopus-api/internal/testutils" -) - -func TestCreateDomain(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - testCases := []struct { - name string - domainName string - organizationID string - token string - expectedStatus int - description string - }{ - { - name: "Successfully create domain with valid data", - domainName: "test-domain.nixopus.dev", - organizationID: orgID, - token: user.AccessToken, - expectedStatus: http.StatusOK, - description: "Should create domain successfully with valid data", - }, - { - name: "Create domain with subdomain", - domainName: "api.test-domain.nixopus.dev", - organizationID: orgID, - token: user.AccessToken, - expectedStatus: http.StatusOK, - description: "Should create subdomain successfully", - }, - { - name: "Unauthorized request without token", - domainName: "unauthorized.nixopus.dev", - organizationID: orgID, - token: "", - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - domainName: "invalid-token.nixopus.dev", - organizationID: orgID, - token: "invalid-token", - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - domainName: "no-org.nixopus.dev", - organizationID: "", - token: user.AccessToken, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - { - name: "Create domain with empty name", - domainName: "", - organizationID: orgID, - token: user.AccessToken, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when domain name is empty", - }, - { - name: "Create domain with invalid name format", - domainName: "invalid..domain", - organizationID: orgID, - token: user.AccessToken, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when domain name format is invalid", - }, - { - name: "Create duplicate domain", - domainName: "test-domain.nixopus.dev", // Same as first test case - organizationID: orgID, - token: user.AccessToken, - expectedStatus: http.StatusConflict, - description: "Should return 409 when domain already exists", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - requestBody := map[string]interface{}{ - "name": tc.domainName, - "organization_id": tc.organizationID, - } - - testSteps := []IStep{ - Description(tc.description), - Post(tests.GetDomainURL()), - Send().Body().JSON(requestBody), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domain created successfully"), - Expect().Body().JSON().JQ(".data.id").NotEqual(""), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestGetDomains(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // First, create a test domain - createDomainRequest := map[string]interface{}{ - "name": "list-test.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create a test domain for listing"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createDomainRequest), - Expect().Status().Equal(http.StatusOK), - ) - - testCases := []struct { - name string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully fetch domains with valid token", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should return domains list with valid authentication", - }, - { - name: "Unauthorized request without token", - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - token: "invalid-token", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - { - name: "Cross-organization access attempt", - token: user.AccessToken, - organizationID: "123e4567-e89b-12d3-a456-426614174000", - expectedStatus: http.StatusForbidden, - description: "Should deny access to domains from different organization", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - testSteps := []IStep{ - Description(tc.description), - Get(tests.GetDomainsURL()), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domains fetched successfully"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestUpdateDomain(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // First, create a test domain to update - var domainID string - createDomainRequest := map[string]interface{}{ - "name": "update-test.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create a test domain for updating"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createDomainRequest), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data.id").In(&domainID), - ) - - testCases := []struct { - name string - domainID string - newName string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully update domain with valid data", - domainID: domainID, - newName: "updated-domain.nixopus.dev", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should update domain successfully with valid data", - }, - { - name: "Update domain with subdomain", - domainID: domainID, - newName: "api.updated-domain.nixopus.dev", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should update domain to subdomain successfully", - }, - { - name: "Unauthorized request without token", - domainID: domainID, - newName: "unauthorized-update.nixopus.dev", - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - domainID: domainID, - newName: "invalid-token-update.nixopus.dev", - token: "invalid-token", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - domainID: domainID, - newName: "no-org-update.nixopus.dev", - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - { - name: "Update domain with empty name", - domainID: domainID, - newName: "", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when domain name is empty", - }, - { - name: "Update domain with invalid name format", - domainID: domainID, - newName: "invalid..domain", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when domain name format is invalid", - }, - { - name: "Update non-existent domain", - domainID: "123e4567-e89b-12d3-a456-426614174000", - newName: "non-existent-update.nixopus.dev", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusNotFound, - description: "Should return 404 when domain doesn't exist", - }, - { - name: "Update domain with invalid ID format", - domainID: "invalid-id", - newName: "invalid-id-update.nixopus.dev", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when domain ID format is invalid", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": tc.domainID, - "name": tc.newName, - } - - testSteps := []IStep{ - Description(tc.description), - Put(tests.GetDomainURL()), - Send().Body().JSON(requestBody), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domain updated successfully"), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestDeleteDomain(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // Create test domains for deletion - var domainID1, domainID2 string - - createDomainRequest1 := map[string]interface{}{ - "name": "delete-test1.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create first test domain for deletion"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createDomainRequest1), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data.id").In(&domainID1), - ) - - createDomainRequest2 := map[string]interface{}{ - "name": "delete-test2.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create second test domain for deletion"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createDomainRequest2), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data.id").In(&domainID2), - ) - - testCases := []struct { - name string - domainID string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully delete domain with valid ID", - domainID: domainID1, - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should delete domain successfully with valid ID", - }, - { - name: "Unauthorized request without token", - domainID: domainID2, - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - domainID: domainID2, - token: "invalid-token", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - domainID: domainID2, - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - { - name: "Delete non-existent domain", - domainID: "123e4567-e89b-12d3-a456-426614174000", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusNotFound, - description: "Should return 404 when domain doesn't exist", - }, - { - name: "Delete domain with invalid ID format", - domainID: "invalid-id", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when domain ID format is invalid", - }, - { - name: "Delete already deleted domain", - domainID: domainID1, // Already deleted in first test case so expcected to throw 404 - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusNotFound, - description: "Should return 404 when trying to delete already deleted domain", - }, - { - name: "Successfully delete second domain", - domainID: domainID2, - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should delete second domain successfully", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - requestBody := map[string]interface{}{ - "id": tc.domainID, - } - - testSteps := []IStep{ - Description(tc.description), - Delete(tests.GetDomainURL()), - Send().Body().JSON(requestBody), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domain deleted successfully"), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestGenerateRandomSubDomain(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - // first create a domain then generating subdomains - createRequest := map[string]interface{}{ - "name": "base-domain.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create a base domain for subdomain generation"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createRequest), - Expect().Status().Equal(http.StatusOK), - ) - - testCases := []struct { - name string - token string - organizationID string - expectedStatus int - description string - }{ - { - name: "Successfully generate random subdomain", - token: user.AccessToken, - organizationID: orgID, - expectedStatus: http.StatusOK, - description: "Should generate random subdomain successfully", - }, - { - name: "Unauthorized request without token", - token: "", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when no authentication token is provided", - }, - { - name: "Unauthorized request with invalid token", - token: "invalid-token", - organizationID: orgID, - expectedStatus: http.StatusUnauthorized, - description: "Should return 401 when invalid authentication token is provided", - }, - { - name: "Request without organization header", - token: user.AccessToken, - organizationID: "", - expectedStatus: http.StatusBadRequest, - description: "Should return 400 when organization header is missing", - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - testSteps := []IStep{ - Description(tc.description), - Get(tests.GetDomainGenerateURL()), - } - - if tc.token != "" { - testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) - } - - if tc.organizationID != "" { - testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) - } - - testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) - - if tc.expectedStatus == http.StatusOK { - testSteps = append(testSteps, - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Random subdomain generated successfully"), - Expect().Body().JSON().JQ(".data.subdomain").NotEqual(""), - Expect().Body().JSON().JQ(".data.domain").NotEqual(""), - ) - } - - Test(t, testSteps...) - }) - } -} - -func TestDomainsCRUDFlow(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Validate CRUD flow for domains", func(t *testing.T) { - var domainID string - - // creating a domain - createRequest := map[string]interface{}{ - "name": "crud-flow.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create a new domain"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createRequest), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domain created successfully"), - Store().Response().Body().JSON().JQ(".data.id").In(&domainID), - ) - - // check listing if added once in available or not - Test(t, - Description("Verify domain appears in domains listing"), - Get(tests.GetDomainsURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - Expect().Body().JSON().JQ(".data[0].id").NotEqual(nil), - ) - - updateRequest := map[string]interface{}{ - "id": domainID, - "name": "updated-crud-flow.nixopus.dev", - } - - Test(t, - Description("Update the domain"), - Put(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(updateRequest), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domain updated successfully"), - ) - - // Cross check domain update in listing - Test(t, - Description("Verify domain update appears in domains listing"), - Get(tests.GetDomainsURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".data").NotEqual(nil), - // assert agaisnst the updated domain name - Expect().Body().JSON().JQ(".data[0].name").Equal("updated-crud-flow.nixopus.dev"), - ) - - // Step 5: Delete the domain - deleteRequest := map[string]interface{}{ - "id": domainID, - } - - Test(t, - Description("Step 5: Delete the domain"), - Delete(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(deleteRequest), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - Expect().Body().JSON().JQ(".message").Equal("Domain deleted successfully"), - ) - - // Step 6: Verify domain is removed from listing - Test(t, - Description("Step 6: Verify domain is removed from domains listing"), - Get(tests.GetDomainsURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusOK), - Expect().Body().JSON().JQ(".status").Equal("success"), - // Verify the domain list is empty after deletion (could be null or empty array) - // Just check that the response is successful, domains being null indicates empty list - ) - }) -} - -func TestDomainPermissions(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Domain permissions and organization isolation", func(t *testing.T) { - var domainID string - - // Create a domain in the user' organization - createRequest := map[string]interface{}{ - "name": "permissions-test.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Create domain in user's organization"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createRequest), - Expect().Status().Equal(http.StatusOK), - Store().Response().Body().JSON().JQ(".data.id").In(&domainID), - ) - - // Try to access with different organization ID - Test(t, - Description("Should deny access to domains from different organization"), - Get(tests.GetDomainsURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), - Expect().Status().Equal(http.StatusForbidden), - ) - - // Try to update domain from different organization id - updateRequest := map[string]interface{}{ - "id": domainID, - "name": "unauthorized-update.nixopus.dev", - } - - Test(t, - Description("Should deny domain update from different organization"), - Put(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), - Send().Body().JSON(updateRequest), - Expect().Status().Equal(http.StatusForbidden), - ) - - // Try to delete domain from different organization Id - deleteRequest := map[string]interface{}{ - "id": domainID, - } - - Test(t, - Description("Should deny domain deletion from different organization"), - Delete(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), - Send().Body().JSON(deleteRequest), - Expect().Status().Equal(http.StatusForbidden), - ) - - // Clean up: Delete the domain with correct organization id - Test(t, - Description("Clean up: Delete domain with correct organization"), - Delete(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(deleteRequest), - Expect().Status().Equal(http.StatusOK), - ) - }) -} - -func TestDomainErrorHandling(t *testing.T) { - setup := testutils.NewTestSetup() - user, org, err := setup.GetTestAuthResponse() - if err != nil { - t.Fatalf("failed to get test auth response: %v", err) - } - - orgID := org.ID.String() - - t.Run("Malformed authorization header", func(t *testing.T) { - Test(t, - Description("Should handle malformed authorization header gracefully"), - Get(tests.GetDomainsURL()), - Send().Headers("Authorization").Add("InvalidFormat"), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusUnauthorized), - ) - }) - - t.Run("Empty authorization header", func(t *testing.T) { - Test(t, - Description("Should handle empty authorization header"), - Get(tests.GetDomainsURL()), - Send().Headers("Authorization").Add(""), - Send().Headers("X-Organization-Id").Add(orgID), - Expect().Status().Equal(http.StatusUnauthorized), - ) - }) - - t.Run("Missing Content-Type header for POST requests", func(t *testing.T) { - createRequest := map[string]interface{}{ - "name": "content-type-test.nixopus.dev", - "organization_id": orgID, - } - - Test(t, - Description("Should handle missing Content-Type header"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createRequest), - Expect().Status().Equal(http.StatusOK), - ) - }) - - t.Run("Invalid JSON payload", func(t *testing.T) { - Test(t, - Description("Should handle invalid JSON payload"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().String("{invalid-json}"), - Expect().Status().Equal(http.StatusBadRequest), - ) - }) - - t.Run("Very long domain name", func(t *testing.T) { - longDomainName := "" - for i := 0; i < 300; i++ { - longDomainName += "a" - } - longDomainName += ".nixopus.dev" - - createRequest := map[string]interface{}{ - "name": longDomainName, - "organization_id": orgID, - } - - Test(t, - Description("Should throw an error for very long domain names"), - Post(tests.GetDomainURL()), - Send().Headers("Authorization").Add("Bearer "+user.AccessToken), - Send().Headers("X-Organization-Id").Add(orgID), - Send().Body().JSON(createRequest), - Expect().Status().Equal(http.StatusBadRequest), - ) - }) -} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index 71176885..2272d9e6 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -64,28 +64,4 @@ func GetUserDetailsURL() string { func GetIsAdminRegisteredURL() string { return baseURL + "/auth/is-admin-registered" -} - -func GetContainersURL() string { - return baseURL + "/container" -} - -func GetContainerURL(containerID string) string { - return baseURL + "/container/" + containerID -} - -func GetContainerLogsURL(containerID string) string { - return baseURL + "/container/" + containerID + "/logs" -} - -func GetDomainURL() string { - return baseURL + "/domain" -} - -func GetDomainsURL() string { - return baseURL + "/domains" -} - -func GetDomainGenerateURL() string { - return baseURL + "/domain/generate" } \ No newline at end of file diff --git a/docker-compose-staging.yml b/docker-compose-staging.yml index 55c37387..d3a3d1e1 100644 --- a/docker-compose-staging.yml +++ b/docker-compose-staging.yml @@ -1,4 +1,4 @@ -version: "3.8" +version: '3.8' services: nixopus-staging-api: @@ -45,8 +45,7 @@ services: networks: - nixopus-network healthcheck: - test: - ["CMD-SHELL", "pg_isready -U ${USERNAME} -d ${DB_NAME} -p ${DB_PORT}"] + test: [ "CMD-SHELL", "pg_isready -U ${USERNAME} -d ${DB_NAME} -p ${DB_PORT}" ] interval: 5s timeout: 5s retries: 5 diff --git a/docker-compose-test.yml b/docker-compose-test.yml deleted file mode 100644 index c744dd92..00000000 --- a/docker-compose-test.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3.8" - -services: - nixopus-test-db: - image: postgres:14-alpine - container_name: nixopus-test-db-container - ports: - - "${TEST_DB_PORT:-5433}:5432" - restart: unless-stopped - environment: - - POSTGRES_USER=${TEST_DB_USERNAME:-nixopus} - - POSTGRES_PASSWORD=${TEST_DB_PASSWORD:-nixopus} - - POSTGRES_DB=${TEST_DB_NAME:-nixopus_test} - networks: - - nixopus-network - -networks: - nixopus-network: - driver: bridge diff --git a/view/app/self-host/hooks/use_create_deployment.ts b/view/app/self-host/hooks/use_create_deployment.ts index 97744a60..112e4604 100644 --- a/view/app/self-host/hooks/use_create_deployment.ts +++ b/view/app/self-host/hooks/use_create_deployment.ts @@ -3,6 +3,7 @@ import { z } from 'zod'; import { useEffect } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; +import { useGetAllDomainsQuery } from '@/redux/services/settings/domainsApi'; import { useWebSocket } from '@/hooks/socket-provider'; import { useRouter } from 'next/navigation'; import { useCreateDeploymentMutation } from '@/redux/services/deploy/applicationsApi'; diff --git a/view/app/self-host/hooks/use_update_deployment.ts b/view/app/self-host/hooks/use_update_deployment.ts index 943892f7..f3ff8006 100644 --- a/view/app/self-host/hooks/use_update_deployment.ts +++ b/view/app/self-host/hooks/use_update_deployment.ts @@ -42,7 +42,7 @@ function useUpdateDeployment({ const [updateDeployment, { isLoading }] = useUpdateDeploymentMutation(); const router = useRouter(); const activeOrg = useAppSelector((state) => state.user.activeOrganization); - const { data: domains } = useGetAllDomainsQuery(); + const { data: domains } = useGetAllDomainsQuery(activeOrg?.id); const deploymentFormSchema = z.object({ name: z diff --git a/view/app/settings/domains/components/delete-domain.tsx b/view/app/settings/domains/components/delete-domain.tsx index 00d81f91..2ab438ff 100644 --- a/view/app/settings/domains/components/delete-domain.tsx +++ b/view/app/settings/domains/components/delete-domain.tsx @@ -26,7 +26,7 @@ const DeleteDomain = ({ open, setOpen, id }: DeleteDomainProps) => { const handleDelete = async () => { setIsLoading(true); try { - await deleteDomain({ id }); + await deleteDomain(id); toast.success(t('settings.domains.delete.success')); } catch (error) { toast.error(t('settings.domains.delete.error')); diff --git a/view/app/settings/domains/page.tsx b/view/app/settings/domains/page.tsx index 7f75736a..60bdfcc6 100644 --- a/view/app/settings/domains/page.tsx +++ b/view/app/settings/domains/page.tsx @@ -22,7 +22,7 @@ const Page = () => { data: domains, isLoading, error - } = useGetAllDomainsQuery(); + } = useGetAllDomainsQuery({ organizationId: activeOrg?.id || '' }, { skip: !activeOrg?.id }); const [addDomainDialogOpen, setAddDomainDialogOpen] = React.useState(false); const { isFeatureEnabled, isLoading: isFeatureFlagsLoading } = useFeatureFlags(); diff --git a/view/components/domains/random-subdomain-generator.tsx b/view/components/domains/random-subdomain-generator.tsx deleted file mode 100644 index 9dc831d7..00000000 --- a/view/components/domains/random-subdomain-generator.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from 'react'; -import { useGenerateRandomSubdomainQuery } from '@/redux/services/settings/domainsApi'; -import { Button } from '@/components/ui/button'; -import { toast } from 'sonner'; - -interface RandomSubdomainGeneratorProps { - onSubdomainGenerated?: (subdomain: string) => void; -} - -export const RandomSubdomainGenerator: React.FC = ({ - onSubdomainGenerated -}) => { - const { - data: randomSubdomainData, - isLoading, - error, - refetch - } = useGenerateRandomSubdomainQuery(); - - const handleGenerateSubdomain = async () => { - try { - const result = await refetch(); - if (result.data) { - toast.success(`Generated subdomain: ${result.data.subdomain}`); - onSubdomainGenerated?.(result.data.subdomain); - } - } catch (err) { - toast.error('Failed to generate random subdomain'); - } - }; - - return ( -
- - - {randomSubdomainData && ( -
-

Subdomain: {randomSubdomainData.subdomain}

-

Domain: {randomSubdomainData.domain}

-
- )} - - {error && ( -

- Failed to generate subdomain. Please try again. -

- )} -
- ); -}; diff --git a/view/redux/services/settings/domainsApi.ts b/view/redux/services/settings/domainsApi.ts index f5747327..02f4426d 100644 --- a/view/redux/services/settings/domainsApi.ts +++ b/view/redux/services/settings/domainsApi.ts @@ -1,22 +1,16 @@ import { DOMAIN_SETTINGS } from '@/redux/api-conf'; import { createApi } from '@reduxjs/toolkit/query/react'; import { baseQueryWithReauth } from '@/redux/base-query'; -import { - Domain, - RandomSubdomainResponse, - CreateDomainRequest, - UpdateDomainRequest, - DeleteDomainRequest -} from '@/redux/types/domain'; +import { Domain } from '@/redux/types/domain'; export const domainsApi = createApi({ reducerPath: 'domainsApi', baseQuery: baseQueryWithReauth, tagTypes: ['Domains'], endpoints: (builder) => ({ - getAllDomains: builder.query({ - query: () => ({ - url: DOMAIN_SETTINGS.GET_DOMAINS, + getAllDomains: builder.query({ + query: ({ organizationId }) => ({ + url: DOMAIN_SETTINGS.GET_DOMAINS + `?id=${organizationId}`, method: 'GET' }), providesTags: [{ type: 'Domains', id: 'LIST' }], @@ -24,18 +18,18 @@ export const domainsApi = createApi({ return response.data; } }), - createDomain: builder.mutation<{ id: string }, CreateDomainRequest>({ + createDomain: builder.mutation({ query: (data) => ({ url: DOMAIN_SETTINGS.ADD_DOMAIN, method: 'POST', body: data }), invalidatesTags: [{ type: 'Domains', id: 'LIST' }], - transformResponse: (response: { data: { id: string } }) => { + transformResponse: (response: { data: null }) => { return response.data; } }), - updateDomain: builder.mutation({ + updateDomain: builder.mutation({ query: (data) => ({ url: DOMAIN_SETTINGS.UPDATE_DOMAIN, method: 'PUT', @@ -46,25 +40,22 @@ export const domainsApi = createApi({ return response.data; } }), - deleteDomain: builder.mutation({ - query: (data) => ({ + deleteDomain: builder.mutation({ + query: (id) => ({ url: DOMAIN_SETTINGS.DELETE_DOMAIN, method: 'DELETE', - body: data + body: { id } }), invalidatesTags: [{ type: 'Domains', id: 'LIST' }], transformResponse: (response: { data: null }) => { return response.data; } }), - generateRandomSubdomain: builder.query({ - query: () => ({ + generateRandomSubdomain: builder.query({ + query: (id) => ({ url: DOMAIN_SETTINGS.GENERATE_RANDOM_SUBDOMAIN, method: 'GET' - }), - transformResponse: (response: { data: RandomSubdomainResponse }) => { - return response.data; - } + }) }) }) }); diff --git a/view/redux/types/domain.ts b/view/redux/types/domain.ts index a90d0247..2a15ce98 100644 --- a/view/redux/types/domain.ts +++ b/view/redux/types/domain.ts @@ -4,22 +4,3 @@ export interface Domain { created_at: string; updated_at: string; } - -export interface RandomSubdomainResponse { - subdomain: string; - domain: string; -} - -export interface CreateDomainRequest { - name: string; - organization_id: string; -} - -export interface UpdateDomainRequest { - name: string; - id: string; -} - -export interface DeleteDomainRequest { - id: string; -} From 75089c96318cc4ce82b0acd54d7ed7892726b8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Sat, 5 Jul 2025 20:52:21 +0530 Subject: [PATCH 22/72] test: E2E for Domain and Container Management (#267) --- .../domain/controller/create_domain.go | 15 + .../domain/controller/delete_domain.go | 15 + .../domain/controller/error_helpers.go | 27 + .../features/domain/controller/get_domains.go | 74 +- .../domain/controller/update_domain.go | 15 + api/internal/features/domain/storage/init.go | 31 +- api/internal/routes.go | 2 + .../container/get_container_logs_test.go | 396 ++++++++ .../tests/container/get_container_test.go | 216 +++++ .../tests/container/list_containers_test.go | 156 ++++ api/internal/tests/domain/domain_flow_test.go | 880 ++++++++++++++++++ api/internal/tests/helper.go | 24 + docker-compose-staging.yml | 5 +- docker-compose-test.yml | 19 + .../self-host/hooks/use_create_deployment.ts | 1 - .../self-host/hooks/use_update_deployment.ts | 2 +- .../domains/components/delete-domain.tsx | 2 +- view/app/settings/domains/page.tsx | 2 +- .../domains/random-subdomain-generator.tsx | 56 ++ view/redux/services/settings/domainsApi.ts | 35 +- view/redux/types/domain.ts | 19 + 21 files changed, 1955 insertions(+), 37 deletions(-) create mode 100644 api/internal/features/domain/controller/error_helpers.go create mode 100644 api/internal/tests/container/get_container_logs_test.go create mode 100644 api/internal/tests/container/get_container_test.go create mode 100644 api/internal/tests/container/list_containers_test.go create mode 100644 api/internal/tests/domain/domain_flow_test.go create mode 100644 docker-compose-test.yml create mode 100644 view/components/domains/random-subdomain-generator.tsx diff --git a/api/internal/features/domain/controller/create_domain.go b/api/internal/features/domain/controller/create_domain.go index 2916c951..0668b693 100644 --- a/api/internal/features/domain/controller/create_domain.go +++ b/api/internal/features/domain/controller/create_domain.go @@ -42,6 +42,21 @@ func (c *DomainsController) CreateDomain(f fuego.ContextWithBody[types.CreateDom if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isInvalidDomainError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusBadRequest, + } + } + + if err == types.ErrDomainAlreadyExists { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusConflict, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/controller/delete_domain.go b/api/internal/features/domain/controller/delete_domain.go index ce8703bb..1890d9d3 100644 --- a/api/internal/features/domain/controller/delete_domain.go +++ b/api/internal/features/domain/controller/delete_domain.go @@ -31,6 +31,21 @@ func (c *DomainsController) DeleteDomain(f fuego.ContextWithBody[types.DeleteDom err = c.service.DeleteDomain(domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isInvalidDomainError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusBadRequest, + } + } + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/controller/error_helpers.go b/api/internal/features/domain/controller/error_helpers.go new file mode 100644 index 00000000..05e70c0b --- /dev/null +++ b/api/internal/features/domain/controller/error_helpers.go @@ -0,0 +1,27 @@ +package controller + +import "github.com/raghavyuva/nixopus-api/internal/features/domain/types" + +func isInvalidDomainError(err error) bool { + switch err { + case types.ErrInvalidDomainID, + types.ErrMissingDomainID, + types.ErrDomainNameInvalid, + types.ErrDomainNameTooLong, + types.ErrDomainNameTooShort, + types.ErrMissingDomainName: + return true + default: + return false + } +} + +func isPermissionError(err error) bool { + switch err { + case types.ErrUserDoesNotBelongToOrganization, + types.ErrPermissionDenied: + return true + default: + return false + } +} diff --git a/api/internal/features/domain/controller/get_domains.go b/api/internal/features/domain/controller/get_domains.go index 4671d940..b964b946 100644 --- a/api/internal/features/domain/controller/get_domains.go +++ b/api/internal/features/domain/controller/get_domains.go @@ -7,6 +7,7 @@ import ( "time" "github.com/go-fuego/fuego" + "github.com/google/uuid" "github.com/raghavyuva/nixopus-api/internal/features/domain/types" "github.com/raghavyuva/nixopus-api/internal/features/logger" "github.com/raghavyuva/nixopus-api/internal/utils" @@ -15,24 +16,46 @@ import ( ) func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Response, error) { - organization_id := f.QueryParam("id") - w, r := f.Response(), f.Request() - user := utils.GetUser(w, r) + organization_id := utils.GetOrganizationID(r) + if organization_id == uuid.Nil { + c.logger.Log(logger.Error, "invalid organization id", "") + return nil, fuego.HTTPError{ + Err: types.ErrMissingID, + Status: http.StatusBadRequest, + } + } + user := utils.GetUser(w, r) if user == nil { + c.logger.Log(logger.Error, "unauthorized user", "") return nil, fuego.HTTPError{ - Err: nil, + Err: types.ErrAccessDenied, Status: http.StatusUnauthorized, } } c.logger.Log(logger.Info, "fetching domains", fmt.Sprintf("organization_id: %s", organization_id)) - domains, err := c.service.GetDomains(organization_id, user.ID) + domains, err := c.service.GetDomains(organization_id.String(), user.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isPermissionError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusForbidden, + } + } + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, @@ -49,11 +72,42 @@ func (c *DomainsController) GetDomains(f fuego.ContextNoBody) (*shared_types.Res func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*shared_types.Response, error) { w, r := f.Response(), f.Request() - organization_id := f.QueryParam("id") + organization_id := utils.GetOrganizationID(r) + if organization_id == uuid.Nil { + c.logger.Log(logger.Error, "invalid organization id", "") + return nil, fuego.HTTPError{ + Err: types.ErrMissingID, + Status: http.StatusBadRequest, + } + } + + user := utils.GetUser(w, r) + if user == nil { + c.logger.Log(logger.Error, "unauthorized user", "") + return nil, fuego.HTTPError{ + Err: types.ErrAccessDenied, + Status: http.StatusUnauthorized, + } + } - domains, err := c.service.GetDomains(organization_id, utils.GetUser(w, r).ID) + domains, err := c.service.GetDomains(organization_id.String(), user.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isPermissionError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusForbidden, + } + } + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, @@ -61,10 +115,10 @@ func (c *DomainsController) GenerateRandomSubDomain(f fuego.ContextNoBody) (*sha } if len(domains) == 0 { - c.logger.Log(logger.Error, "no domains available", "") + c.logger.Log(logger.Error, "no domains available for subdomain generation", "") return nil, fuego.HTTPError{ - Err: nil, - Status: http.StatusBadRequest, + Err: types.ErrDomainNotFound, + Status: http.StatusNotFound, } } diff --git a/api/internal/features/domain/controller/update_domain.go b/api/internal/features/domain/controller/update_domain.go index ce25def2..d0a4c7f3 100644 --- a/api/internal/features/domain/controller/update_domain.go +++ b/api/internal/features/domain/controller/update_domain.go @@ -41,6 +41,21 @@ func (c *DomainsController) UpdateDomain(f fuego.ContextWithBody[types.UpdateDom updated, err := c.service.UpdateDomain(domainRequest.Name, user.ID.String(), domainRequest.ID) if err != nil { c.logger.Log(logger.Error, err.Error(), "") + + if isInvalidDomainError(err) { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusBadRequest, + } + } + + if err == types.ErrDomainNotFound { + return nil, fuego.HTTPError{ + Err: err, + Status: http.StatusNotFound, + } + } + return nil, fuego.HTTPError{ Err: err, Status: http.StatusInternalServerError, diff --git a/api/internal/features/domain/storage/init.go b/api/internal/features/domain/storage/init.go index e4152799..f0d7ed9a 100644 --- a/api/internal/features/domain/storage/init.go +++ b/api/internal/features/domain/storage/init.go @@ -60,7 +60,7 @@ func (s *DomainStorage) CreateDomain(domain *shared_types.Domain) error { func (s *DomainStorage) GetDomain(id string) (*shared_types.Domain, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", id).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", id).Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { return nil, types.ErrDomainNotFound @@ -72,13 +72,13 @@ func (s *DomainStorage) GetDomain(id string) (*shared_types.Domain, error) { func (s *DomainStorage) UpdateDomain(ID string, Name string) error { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) if err != nil { return err } domain.Name = Name domain.UpdatedAt = time.Now() - _, err = s.getDB().NewUpdate().Model(&domain).Where("id = ?", ID).Exec(s.Ctx) + _, err = s.getDB().NewUpdate().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Exec(s.Ctx) if err != nil { return err } @@ -86,17 +86,32 @@ func (s *DomainStorage) UpdateDomain(ID string, Name string) error { } func (s *DomainStorage) DeleteDomain(domain *shared_types.Domain) error { - _, err := s.getDB().NewDelete().Model(domain).Where("id = ?", domain.ID).Exec(s.Ctx) + now := time.Now() + result, err := s.getDB().NewUpdate().Model(domain). + Set("deleted_at = ?", now). + Set("updated_at = ?", now). + Where("id = ? AND deleted_at IS NULL", domain.ID). + Exec(s.Ctx) if err != nil { return err } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return err + } + + if rowsAffected == 0 { + return types.ErrDomainNotFound + } + return nil } func (s *DomainStorage) GetDomains(OrganizationID string, UserID uuid.UUID) ([]shared_types.Domain, error) { var domains []shared_types.Domain err := s.getDB().NewSelect().Model(&domains). - Where("organization_id = ?", OrganizationID). + Where("organization_id = ? AND deleted_at IS NULL", OrganizationID). Scan(s.Ctx) if err != nil { return nil, err @@ -107,7 +122,7 @@ func (s *DomainStorage) GetDomains(OrganizationID string, UserID uuid.UUID) ([]s func (s *DomainStorage) GetDomainByName(name string, organizationID uuid.UUID) (*shared_types.Domain, error) { var domain shared_types.Domain err := s.getDB().NewSelect().Model(&domain). - Where("name = ? AND organization_id = ?", name, organizationID). + Where("name = ? AND organization_id = ? AND deleted_at IS NULL", name, organizationID). Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { @@ -120,7 +135,7 @@ func (s *DomainStorage) GetDomainByName(name string, organizationID uuid.UUID) ( func (s *DomainStorage) IsDomainExists(ID string) (bool, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) if err != nil { if errors.Is(err, sql.ErrNoRows) { return false, nil @@ -132,7 +147,7 @@ func (s *DomainStorage) IsDomainExists(ID string) (bool, error) { func (s *DomainStorage) GetDomainOwnerByID(ID string) (string, error) { var domain shared_types.Domain - err := s.getDB().NewSelect().Model(&domain).Where("id = ?", ID).Scan(s.Ctx) + err := s.getDB().NewSelect().Model(&domain).Where("id = ? AND deleted_at IS NULL", ID).Scan(s.Ctx) if err != nil { return "", err } diff --git a/api/internal/routes.go b/api/internal/routes.go index b4867e7c..f0c90737 100644 --- a/api/internal/routes.go +++ b/api/internal/routes.go @@ -244,6 +244,8 @@ func (router *Router) Routes() { }) router.ContainerRoutes(containerGroup, containerController) + log.Printf("Server starting on port %s", PORT) + log.Printf("Swagger UI available at: http://localhost:%s/swagger/", PORT) server.Run() } diff --git a/api/internal/tests/container/get_container_logs_test.go b/api/internal/tests/container/get_container_logs_test.go new file mode 100644 index 00000000..067889bc --- /dev/null +++ b/api/internal/tests/container/get_container_logs_test.go @@ -0,0 +1,396 @@ +package container + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetContainerLogs(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // Note: First, get a container ID from the list; sue the same for test validation (PSQL test db container) + // Test cases are designed to work with an existing container. + // TODO: Run a script on pre running E2E tests to create a containers & add as DB seeding + var containerID string + Test(t, + Description("Get container id for logs tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + testCases := []struct { + name string + containerID string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch container logs with valid ID and token", + containerID: containerID, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return container logs with valid authentication", + }, + { + name: "Unauthorized request without token", + containerID: containerID, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + containerID: containerID, + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + containerID: containerID, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Request with invalid container ID", + containerID: "invalid-container-id", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container ID doesn't exist", + }, + { + name: "Request with empty container ID", + containerID: "", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container ID is empty", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetContainerLogsURL(tc.containerID)), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + requestBody := map[string]interface{}{ + "id": tc.containerID, + "follow": false, + "tail": 100, + "stdout": true, + "stderr": true, + } + testSteps = append(testSteps, Send().Body().JSON(requestBody)) + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetContainerLogsWithFilters(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + var containerID string + Test(t, + Description("Get container ID for logs filter tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + t.Run("Fetch logs with tail parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "tail": 50, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return limited number of log lines when tail parameter is provided"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + }) + + t.Run("Fetch logs with since parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "since": "2024-01-01T00:00:00Z", + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return logs since specified timestamp"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + ) + }) + + t.Run("Fetch logs with timestamps", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return logs with timestamps when timestamps=true"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container logs fetched successfully"), + ) + }) + + t.Run("Fetch logs with follow parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle follow parameter for streaming logs"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + ) + }) +} + +func TestGetContainerLogsErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle malformed authorization header gracefully"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle empty authorization header"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Invalid UUID format for container ID", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "not-a-uuid", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle invalid UUID format for container ID"), + Post(tests.GetContainerLogsURL("not-a-uuid")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) + + t.Run("Non-existent container ID with valid UUID format", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "123e4567-e89b-12d3-a456-426614174000", + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should return 500 for non-existent container with valid UUID format"), + Post(tests.GetContainerLogsURL("123e4567-e89b-12d3-a456-426614174000")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) + + t.Run("Invalid tail parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "tail": "invalid-number", // should throw an error since tail expects int + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle invalid tail parameter gracefully"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) + + t.Run("Invalid since parameter", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": "some-container-id", + "follow": false, + "since": "invalid-timestamp", + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should handle invalid since timestamp parameter"), + Post(tests.GetContainerLogsURL("some-container-id")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) +} + +func TestGetContainerLogsPermissions(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + var containerID string + Test(t, + Description("Get container ID for permission tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + t.Run("Access logs with organization member permissions", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should allow organization members to access container logs"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + ) + }) + + t.Run("Cross-organization access attempt", func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": containerID, + "follow": false, + "stdout": true, + "stderr": true, + } + Test(t, + Description("Should deny access to logs from different organization"), + Post(tests.GetContainerLogsURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(requestBody), + Expect().Status().Equal(http.StatusForbidden), + ) + }) +} diff --git a/api/internal/tests/container/get_container_test.go b/api/internal/tests/container/get_container_test.go new file mode 100644 index 00000000..0d11cc62 --- /dev/null +++ b/api/internal/tests/container/get_container_test.go @@ -0,0 +1,216 @@ +package container + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetContainer(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, get a container ID from the list + var containerID string + Test(t, + Description("Get container ID for individual container tests"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data[0].id").In(&containerID), + ) + + testCases := []struct { + name string + containerID string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch container with valid ID and token", + containerID: containerID, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return container details", + }, + { + name: "Unauthorized request without token", + containerID: containerID, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Request with invalid container ID", + containerID: "invalid-container-id", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container ID is invalid/doesnt exist", + }, + { + name: "Request with container ID doesnt exist", + containerID: "1234567890123456789012345678901234567890123456789012345678901234", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when container doesnt exist", + }, + { + name: "Request without organization header", + containerID: containerID, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // Skip tests that depend on valid container ID if we couldn't get one + if tc.containerID == containerID && containerID == "" { + t.Skip("No container ID available for testing") + } + + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetContainerURL(tc.containerID)), + } + + // Add authentication header if token is provided + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + // Add organization header if provided + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + // Additional validations for successful response + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + Expect().Body().JSON().JQ(".data.id").Equal(tc.containerID), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetContainerDetailedValidation(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // Get the test container ID specifically + var containerID string + Test(t, + Description("Get test container ID for detailed validation"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(`.data[] | select(.name == "nixopus-test-db-container") | .id`).In(&containerID), + ) + + if containerID == "" { + t.Skip("nixopus-test-db-container not found, skipping detailed validation") + } + + t.Run("Validate complete container structure for test container", func(t *testing.T) { + Test(t, + Description("Should return complete container structure with all expected fields"), + Get(tests.GetContainerURL(containerID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Container fetched successfully"), + Expect().Body().JSON().JQ(".data.name").Equal("nixopus-test-db-container"), + Expect().Body().JSON().JQ(".data.image").Equal("postgres:14-alpine"), + Expect().Body().JSON().JQ(".data.command").NotEqual(""), + Expect().Body().JSON().JQ(".data.status").NotEqual(""), + Expect().Body().JSON().JQ(".data.state").NotEqual(""), + Expect().Body().JSON().JQ(".data.created").NotEqual(""), + Expect().Body().JSON().JQ(".data.labels").NotEqual(nil), + Expect().Body().JSON().JQ(".data.ports").NotEqual(nil), + Expect().Body().JSON().JQ(".data.mounts").NotEqual(nil), + Expect().Body().JSON().JQ(".data.networks").NotEqual(nil), + Expect().Body().JSON().JQ(".data.host_config").NotEqual(nil), + + Expect().Body().JSON().JQ(".data.ports[0].private_port").Equal(float64(5432)), + Expect().Body().JSON().JQ(".data.ports[0].public_port").Equal(float64(5433)), + Expect().Body().JSON().JQ(".data.ports[0].type").Equal("tcp"), + + Expect().Body().JSON().JQ(".data.host_config.memory").NotEqual(nil), + Expect().Body().JSON().JQ(".data.host_config.memory_swap").NotEqual(nil), + Expect().Body().JSON().JQ(".data.host_config.cpu_shares").NotEqual(nil), + ) + }) +} + +func TestGetContainerErrorScenarios(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Container ID with special characters", func(t *testing.T) { + Test(t, + Description("Should handle container ID with special characters"), + Get(tests.GetContainerURL("container-special")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) + + t.Run("Empty container ID", func(t *testing.T) { + Test(t, + Description("Should handle empty container ID"), + Get(tests.GetContainerURL("")), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusNotFound), + ) + }) + + t.Run("Very long container ID", func(t *testing.T) { + longID := "abcdefghijklmnopqrstuvwxyz1234567890abcdefghijklmnopqrstuvwxyz1234567890" + Test(t, + Description("Should handle very long container ID"), + Get(tests.GetContainerURL(longID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusInternalServerError), + ) + }) +} diff --git a/api/internal/tests/container/list_containers_test.go b/api/internal/tests/container/list_containers_test.go new file mode 100644 index 00000000..093dbe32 --- /dev/null +++ b/api/internal/tests/container/list_containers_test.go @@ -0,0 +1,156 @@ +package container + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestListContainers(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch containers with valid token", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return containers list with valid authentication, basically return one container which is DB test container that is up and running", + }, + { + name: "Unauthorized request without token", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Request with invalid organization ID", + token: user.AccessToken, + organizationID: "invalid-org-id", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when organization ID format is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetContainersURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Containers fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestListContainersWithSpecificContainer(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Verify test container exists and has expected properties", func(t *testing.T) { + Test(t, + Description("Should find the nixopus-test-db-container and validate its properties"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Containers fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + }) +} + +func TestListContainersErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + Test(t, + Description("Should handle malformed authorization header gracefully"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + Test(t, + Description("Should handle empty authorization header"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Bearer token with extra spaces", func(t *testing.T) { + Test(t, + Description("Should handle get containers base case"), + Get(tests.GetContainersURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + ) + }) +} diff --git a/api/internal/tests/domain/domain_flow_test.go b/api/internal/tests/domain/domain_flow_test.go new file mode 100644 index 00000000..c459ccb3 --- /dev/null +++ b/api/internal/tests/domain/domain_flow_test.go @@ -0,0 +1,880 @@ +package domain + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestCreateDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + domainName string + organizationID string + token string + expectedStatus int + description string + }{ + { + name: "Successfully create domain with valid data", + domainName: "test-domain.nixopus.dev", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusOK, + description: "Should create domain successfully with valid data", + }, + { + name: "Create domain with subdomain", + domainName: "api.test-domain.nixopus.dev", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusOK, + description: "Should create subdomain successfully", + }, + { + name: "Unauthorized request without token", + domainName: "unauthorized.nixopus.dev", + organizationID: orgID, + token: "", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + domainName: "invalid-token.nixopus.dev", + organizationID: orgID, + token: "invalid-token", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + domainName: "no-org.nixopus.dev", + organizationID: "", + token: user.AccessToken, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Create domain with empty name", + domainName: "", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name is empty", + }, + { + name: "Create domain with invalid name format", + domainName: "invalid..domain", + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name format is invalid", + }, + { + name: "Create duplicate domain", + domainName: "test-domain.nixopus.dev", // Same as first test case + organizationID: orgID, + token: user.AccessToken, + expectedStatus: http.StatusConflict, + description: "Should return 409 when domain already exists", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "name": tc.domainName, + "organization_id": tc.organizationID, + } + + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetDomainURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain created successfully"), + Expect().Body().JSON().JQ(".data.id").NotEqual(""), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetDomains(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, create a test domain + createDomainRequest := map[string]interface{}{ + "name": "list-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a test domain for listing"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest), + Expect().Status().Equal(http.StatusOK), + ) + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch domains with valid token", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return domains list with valid authentication", + }, + { + name: "Unauthorized request without token", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Cross-organization access attempt", + token: user.AccessToken, + organizationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusForbidden, + description: "Should deny access to domains from different organization", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetDomainsURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domains fetched successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestUpdateDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, create a test domain to update + var domainID string + createDomainRequest := map[string]interface{}{ + "name": "update-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a test domain for updating"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID), + ) + + testCases := []struct { + name string + domainID string + newName string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully update domain with valid data", + domainID: domainID, + newName: "updated-domain.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should update domain successfully with valid data", + }, + { + name: "Update domain with subdomain", + domainID: domainID, + newName: "api.updated-domain.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should update domain to subdomain successfully", + }, + { + name: "Unauthorized request without token", + domainID: domainID, + newName: "unauthorized-update.nixopus.dev", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + domainID: domainID, + newName: "invalid-token-update.nixopus.dev", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + domainID: domainID, + newName: "no-org-update.nixopus.dev", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Update domain with empty name", + domainID: domainID, + newName: "", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name is empty", + }, + { + name: "Update domain with invalid name format", + domainID: domainID, + newName: "invalid..domain", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain name format is invalid", + }, + { + name: "Update non-existent domain", + domainID: "123e4567-e89b-12d3-a456-426614174000", + newName: "non-existent-update.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusNotFound, + description: "Should return 404 when domain doesn't exist", + }, + { + name: "Update domain with invalid ID format", + domainID: "invalid-id", + newName: "invalid-id-update.nixopus.dev", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain ID format is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": tc.domainID, + "name": tc.newName, + } + + testSteps := []IStep{ + Description(tc.description), + Put(tests.GetDomainURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain updated successfully"), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestDeleteDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // Create test domains for deletion + var domainID1, domainID2 string + + createDomainRequest1 := map[string]interface{}{ + "name": "delete-test1.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create first test domain for deletion"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest1), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID1), + ) + + createDomainRequest2 := map[string]interface{}{ + "name": "delete-test2.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create second test domain for deletion"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createDomainRequest2), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID2), + ) + + testCases := []struct { + name string + domainID string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully delete domain with valid ID", + domainID: domainID1, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should delete domain successfully with valid ID", + }, + { + name: "Unauthorized request without token", + domainID: domainID2, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + domainID: domainID2, + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + domainID: domainID2, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + { + name: "Delete non-existent domain", + domainID: "123e4567-e89b-12d3-a456-426614174000", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusNotFound, + description: "Should return 404 when domain doesn't exist", + }, + { + name: "Delete domain with invalid ID format", + domainID: "invalid-id", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain ID format is invalid", + }, + { + name: "Delete already deleted domain", + domainID: domainID1, // Already deleted in first test case so expcected to throw 404 + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusNotFound, + description: "Should return 404 when trying to delete already deleted domain", + }, + { + name: "Successfully delete second domain", + domainID: domainID2, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should delete second domain successfully", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "id": tc.domainID, + } + + testSteps := []IStep{ + Description(tc.description), + Delete(tests.GetDomainURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain deleted successfully"), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGenerateRandomSubDomain(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // first create a domain then generating subdomains + createRequest := map[string]interface{}{ + "name": "base-domain.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a base domain for subdomain generation"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + ) + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully generate random subdomain", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should generate random subdomain successfully", + }, + { + name: "Unauthorized request without token", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization header is missing", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetDomainGenerateURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Random subdomain generated successfully"), + Expect().Body().JSON().JQ(".data.subdomain").NotEqual(""), + Expect().Body().JSON().JQ(".data.domain").NotEqual(""), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestDomainsCRUDFlow(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Validate CRUD flow for domains", func(t *testing.T) { + var domainID string + + // creating a domain + createRequest := map[string]interface{}{ + "name": "crud-flow.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create a new domain"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain created successfully"), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID), + ) + + // check listing if added once in available or not + Test(t, + Description("Verify domain appears in domains listing"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + Expect().Body().JSON().JQ(".data[0].id").NotEqual(nil), + ) + + updateRequest := map[string]interface{}{ + "id": domainID, + "name": "updated-crud-flow.nixopus.dev", + } + + Test(t, + Description("Update the domain"), + Put(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(updateRequest), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain updated successfully"), + ) + + // Cross check domain update in listing + Test(t, + Description("Verify domain update appears in domains listing"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + // assert agaisnst the updated domain name + Expect().Body().JSON().JQ(".data[0].name").Equal("updated-crud-flow.nixopus.dev"), + ) + + // Step 5: Delete the domain + deleteRequest := map[string]interface{}{ + "id": domainID, + } + + Test(t, + Description("Step 5: Delete the domain"), + Delete(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(deleteRequest), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Domain deleted successfully"), + ) + + // Step 6: Verify domain is removed from listing + Test(t, + Description("Step 6: Verify domain is removed from domains listing"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + // Verify the domain list is empty after deletion (could be null or empty array) + // Just check that the response is successful, domains being null indicates empty list + ) + }) +} + +func TestDomainPermissions(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Domain permissions and organization isolation", func(t *testing.T) { + var domainID string + + // Create a domain in the user' organization + createRequest := map[string]interface{}{ + "name": "permissions-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Create domain in user's organization"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + Store().Response().Body().JSON().JQ(".data.id").In(&domainID), + ) + + // Try to access with different organization ID + Test(t, + Description("Should deny access to domains from different organization"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Try to update domain from different organization id + updateRequest := map[string]interface{}{ + "id": domainID, + "name": "unauthorized-update.nixopus.dev", + } + + Test(t, + Description("Should deny domain update from different organization"), + Put(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(updateRequest), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Try to delete domain from different organization Id + deleteRequest := map[string]interface{}{ + "id": domainID, + } + + Test(t, + Description("Should deny domain deletion from different organization"), + Delete(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(deleteRequest), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Clean up: Delete the domain with correct organization id + Test(t, + Description("Clean up: Delete domain with correct organization"), + Delete(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(deleteRequest), + Expect().Status().Equal(http.StatusOK), + ) + }) +} + +func TestDomainErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + Test(t, + Description("Should handle malformed authorization header gracefully"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + Test(t, + Description("Should handle empty authorization header"), + Get(tests.GetDomainsURL()), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Missing Content-Type header for POST requests", func(t *testing.T) { + createRequest := map[string]interface{}{ + "name": "content-type-test.nixopus.dev", + "organization_id": orgID, + } + + Test(t, + Description("Should handle missing Content-Type header"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusOK), + ) + }) + + t.Run("Invalid JSON payload", func(t *testing.T) { + Test(t, + Description("Should handle invalid JSON payload"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().String("{invalid-json}"), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) + + t.Run("Very long domain name", func(t *testing.T) { + longDomainName := "" + for i := 0; i < 300; i++ { + longDomainName += "a" + } + longDomainName += ".nixopus.dev" + + createRequest := map[string]interface{}{ + "name": longDomainName, + "organization_id": orgID, + } + + Test(t, + Description("Should throw an error for very long domain names"), + Post(tests.GetDomainURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(createRequest), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) +} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index 2272d9e6..71176885 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -64,4 +64,28 @@ func GetUserDetailsURL() string { func GetIsAdminRegisteredURL() string { return baseURL + "/auth/is-admin-registered" +} + +func GetContainersURL() string { + return baseURL + "/container" +} + +func GetContainerURL(containerID string) string { + return baseURL + "/container/" + containerID +} + +func GetContainerLogsURL(containerID string) string { + return baseURL + "/container/" + containerID + "/logs" +} + +func GetDomainURL() string { + return baseURL + "/domain" +} + +func GetDomainsURL() string { + return baseURL + "/domains" +} + +func GetDomainGenerateURL() string { + return baseURL + "/domain/generate" } \ No newline at end of file diff --git a/docker-compose-staging.yml b/docker-compose-staging.yml index d3a3d1e1..55c37387 100644 --- a/docker-compose-staging.yml +++ b/docker-compose-staging.yml @@ -1,4 +1,4 @@ -version: '3.8' +version: "3.8" services: nixopus-staging-api: @@ -45,7 +45,8 @@ services: networks: - nixopus-network healthcheck: - test: [ "CMD-SHELL", "pg_isready -U ${USERNAME} -d ${DB_NAME} -p ${DB_PORT}" ] + test: + ["CMD-SHELL", "pg_isready -U ${USERNAME} -d ${DB_NAME} -p ${DB_PORT}"] interval: 5s timeout: 5s retries: 5 diff --git a/docker-compose-test.yml b/docker-compose-test.yml new file mode 100644 index 00000000..c744dd92 --- /dev/null +++ b/docker-compose-test.yml @@ -0,0 +1,19 @@ +version: "3.8" + +services: + nixopus-test-db: + image: postgres:14-alpine + container_name: nixopus-test-db-container + ports: + - "${TEST_DB_PORT:-5433}:5432" + restart: unless-stopped + environment: + - POSTGRES_USER=${TEST_DB_USERNAME:-nixopus} + - POSTGRES_PASSWORD=${TEST_DB_PASSWORD:-nixopus} + - POSTGRES_DB=${TEST_DB_NAME:-nixopus_test} + networks: + - nixopus-network + +networks: + nixopus-network: + driver: bridge diff --git a/view/app/self-host/hooks/use_create_deployment.ts b/view/app/self-host/hooks/use_create_deployment.ts index 112e4604..97744a60 100644 --- a/view/app/self-host/hooks/use_create_deployment.ts +++ b/view/app/self-host/hooks/use_create_deployment.ts @@ -3,7 +3,6 @@ import { z } from 'zod'; import { useEffect } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; -import { useGetAllDomainsQuery } from '@/redux/services/settings/domainsApi'; import { useWebSocket } from '@/hooks/socket-provider'; import { useRouter } from 'next/navigation'; import { useCreateDeploymentMutation } from '@/redux/services/deploy/applicationsApi'; diff --git a/view/app/self-host/hooks/use_update_deployment.ts b/view/app/self-host/hooks/use_update_deployment.ts index f3ff8006..943892f7 100644 --- a/view/app/self-host/hooks/use_update_deployment.ts +++ b/view/app/self-host/hooks/use_update_deployment.ts @@ -42,7 +42,7 @@ function useUpdateDeployment({ const [updateDeployment, { isLoading }] = useUpdateDeploymentMutation(); const router = useRouter(); const activeOrg = useAppSelector((state) => state.user.activeOrganization); - const { data: domains } = useGetAllDomainsQuery(activeOrg?.id); + const { data: domains } = useGetAllDomainsQuery(); const deploymentFormSchema = z.object({ name: z diff --git a/view/app/settings/domains/components/delete-domain.tsx b/view/app/settings/domains/components/delete-domain.tsx index 2ab438ff..00d81f91 100644 --- a/view/app/settings/domains/components/delete-domain.tsx +++ b/view/app/settings/domains/components/delete-domain.tsx @@ -26,7 +26,7 @@ const DeleteDomain = ({ open, setOpen, id }: DeleteDomainProps) => { const handleDelete = async () => { setIsLoading(true); try { - await deleteDomain(id); + await deleteDomain({ id }); toast.success(t('settings.domains.delete.success')); } catch (error) { toast.error(t('settings.domains.delete.error')); diff --git a/view/app/settings/domains/page.tsx b/view/app/settings/domains/page.tsx index 60bdfcc6..7f75736a 100644 --- a/view/app/settings/domains/page.tsx +++ b/view/app/settings/domains/page.tsx @@ -22,7 +22,7 @@ const Page = () => { data: domains, isLoading, error - } = useGetAllDomainsQuery({ organizationId: activeOrg?.id || '' }, { skip: !activeOrg?.id }); + } = useGetAllDomainsQuery(); const [addDomainDialogOpen, setAddDomainDialogOpen] = React.useState(false); const { isFeatureEnabled, isLoading: isFeatureFlagsLoading } = useFeatureFlags(); diff --git a/view/components/domains/random-subdomain-generator.tsx b/view/components/domains/random-subdomain-generator.tsx new file mode 100644 index 00000000..9dc831d7 --- /dev/null +++ b/view/components/domains/random-subdomain-generator.tsx @@ -0,0 +1,56 @@ +import React from 'react'; +import { useGenerateRandomSubdomainQuery } from '@/redux/services/settings/domainsApi'; +import { Button } from '@/components/ui/button'; +import { toast } from 'sonner'; + +interface RandomSubdomainGeneratorProps { + onSubdomainGenerated?: (subdomain: string) => void; +} + +export const RandomSubdomainGenerator: React.FC = ({ + onSubdomainGenerated +}) => { + const { + data: randomSubdomainData, + isLoading, + error, + refetch + } = useGenerateRandomSubdomainQuery(); + + const handleGenerateSubdomain = async () => { + try { + const result = await refetch(); + if (result.data) { + toast.success(`Generated subdomain: ${result.data.subdomain}`); + onSubdomainGenerated?.(result.data.subdomain); + } + } catch (err) { + toast.error('Failed to generate random subdomain'); + } + }; + + return ( +
+ + + {randomSubdomainData && ( +
+

Subdomain: {randomSubdomainData.subdomain}

+

Domain: {randomSubdomainData.domain}

+
+ )} + + {error && ( +

+ Failed to generate subdomain. Please try again. +

+ )} +
+ ); +}; diff --git a/view/redux/services/settings/domainsApi.ts b/view/redux/services/settings/domainsApi.ts index 02f4426d..f5747327 100644 --- a/view/redux/services/settings/domainsApi.ts +++ b/view/redux/services/settings/domainsApi.ts @@ -1,16 +1,22 @@ import { DOMAIN_SETTINGS } from '@/redux/api-conf'; import { createApi } from '@reduxjs/toolkit/query/react'; import { baseQueryWithReauth } from '@/redux/base-query'; -import { Domain } from '@/redux/types/domain'; +import { + Domain, + RandomSubdomainResponse, + CreateDomainRequest, + UpdateDomainRequest, + DeleteDomainRequest +} from '@/redux/types/domain'; export const domainsApi = createApi({ reducerPath: 'domainsApi', baseQuery: baseQueryWithReauth, tagTypes: ['Domains'], endpoints: (builder) => ({ - getAllDomains: builder.query({ - query: ({ organizationId }) => ({ - url: DOMAIN_SETTINGS.GET_DOMAINS + `?id=${organizationId}`, + getAllDomains: builder.query({ + query: () => ({ + url: DOMAIN_SETTINGS.GET_DOMAINS, method: 'GET' }), providesTags: [{ type: 'Domains', id: 'LIST' }], @@ -18,18 +24,18 @@ export const domainsApi = createApi({ return response.data; } }), - createDomain: builder.mutation({ + createDomain: builder.mutation<{ id: string }, CreateDomainRequest>({ query: (data) => ({ url: DOMAIN_SETTINGS.ADD_DOMAIN, method: 'POST', body: data }), invalidatesTags: [{ type: 'Domains', id: 'LIST' }], - transformResponse: (response: { data: null }) => { + transformResponse: (response: { data: { id: string } }) => { return response.data; } }), - updateDomain: builder.mutation({ + updateDomain: builder.mutation({ query: (data) => ({ url: DOMAIN_SETTINGS.UPDATE_DOMAIN, method: 'PUT', @@ -40,22 +46,25 @@ export const domainsApi = createApi({ return response.data; } }), - deleteDomain: builder.mutation({ - query: (id) => ({ + deleteDomain: builder.mutation({ + query: (data) => ({ url: DOMAIN_SETTINGS.DELETE_DOMAIN, method: 'DELETE', - body: { id } + body: data }), invalidatesTags: [{ type: 'Domains', id: 'LIST' }], transformResponse: (response: { data: null }) => { return response.data; } }), - generateRandomSubdomain: builder.query({ - query: (id) => ({ + generateRandomSubdomain: builder.query({ + query: () => ({ url: DOMAIN_SETTINGS.GENERATE_RANDOM_SUBDOMAIN, method: 'GET' - }) + }), + transformResponse: (response: { data: RandomSubdomainResponse }) => { + return response.data; + } }) }) }); diff --git a/view/redux/types/domain.ts b/view/redux/types/domain.ts index 2a15ce98..a90d0247 100644 --- a/view/redux/types/domain.ts +++ b/view/redux/types/domain.ts @@ -4,3 +4,22 @@ export interface Domain { created_at: string; updated_at: string; } + +export interface RandomSubdomainResponse { + subdomain: string; + domain: string; +} + +export interface CreateDomainRequest { + name: string; + organization_id: string; +} + +export interface UpdateDomainRequest { + name: string; + id: string; +} + +export interface DeleteDomainRequest { + id: string; +} From c8b67dadaf734ab077d6c3bd9825c927c61aca6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Sat, 5 Jul 2025 21:15:46 +0530 Subject: [PATCH 23/72] test: E2E test-cases for feature flag flow (#269) --- .gitignore | 1 + api/api/versions.json | 2 +- .../tests/feature-flags/feature_flags_test.go | 699 ++++++++++++++++++ api/internal/tests/helper.go | 10 +- 4 files changed, 710 insertions(+), 2 deletions(-) create mode 100644 api/internal/tests/feature-flags/feature_flags_test.go diff --git a/.gitignore b/.gitignore index 5e11e4fa..89ee350c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ docs/.vitepress/cache .env.staging !api/.env.sample **.log +.vscode diff --git a/api/api/versions.json b/api/api/versions.json index 28f73096..cd003558 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-06-30T20:48:43.246107+05:30", + "release_date": "2025-07-05T10:51:37.94673+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/tests/feature-flags/feature_flags_test.go b/api/internal/tests/feature-flags/feature_flags_test.go new file mode 100644 index 00000000..77462e4e --- /dev/null +++ b/api/internal/tests/feature-flags/feature_flags_test.go @@ -0,0 +1,699 @@ +package feature_flags + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetFeatureFlags(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "successfully fetch feature flags with valid token", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "given valid credentials, get all the feature flags for organization", + }, + { + name: "deny unauthorized access", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "return unauthorized error without token", + }, + { + name: "unauthorized with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "throw unauthorized error with invalid token or expired", + }, + { + name: "request without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "throws error when organization header is missing from request", + }, + { + name: "request with invalid organization ID", + token: user.AccessToken, + organizationID: "invalid-org-id", + expectedStatus: http.StatusInternalServerError, + description: "throws 500 error when organization ID is invalid format", + }, + { + name: "cross organization access denied", + token: user.AccessToken, + organizationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusForbidden, + description: "should deny access to feature flags from different organization that user is not part of", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetFeatureFlagsURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Feature flags retrieved successfully"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + Expect().Body().JSON().JQ(".data | map(select(.feature_name == \"terminal\")) | length").Equal(1), + Expect().Body().JSON().JQ(".data | map(select(.feature_name == \"container\")) | length").Equal(1), + Expect().Body().JSON().JQ(".data | map(select(.feature_name == \"domain\")) | length").Equal(1), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestUpdateFeatureFlag(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, ensure feature flags exist by fetching them + Test(t, + Description("Initialize feature flags by fetching them"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + ) + + testCases := []struct { + name string + featureName string + isEnabled bool + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "sucessfully enable terminal feature flag", + featureName: "terminal", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "should enable terminal feature flag successfully", + }, + { + name: "Successfully disable terminal feature flag", + featureName: "terminal", + isEnabled: false, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "should disable terminal feature flag successfully", + }, + { + name: "update container feature flag", + featureName: "container", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "should update container feature flag successfully", + }, + { + name: "update domain feature flag", + featureName: "domain", + isEnabled: false, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "should update domain feature flag successfully", + }, + { + name: "update file_manager feature flag", + featureName: "file_manager", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "should update file_manager feature flag successfully", + }, + { + name: "update notifications feature flag", + featureName: "notifications", + isEnabled: false, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "should update notifications feature flag successfully", + }, + { + name: "successfully update monitoring feature flag", + featureName: "monitoring", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "updates monitoring feature flag successfully", + }, + { + name: "update github_connector feature flag", + featureName: "github_connector", + isEnabled: false, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "update github_connector feature flag successfully", + }, + { + name: "update audit feature flag", + featureName: "audit", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "update audit feature flag successfully", + }, + { + name: "update self_hosted feature flag", + featureName: "self_hosted", + isEnabled: false, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "update self_hosted feature flag successfully", + }, + { + name: "unauthorized request without token", + featureName: "terminal", + isEnabled: true, + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "throw 401 when no authentication token is provided", + }, + { + name: "unauthorized request with invalid token", + featureName: "terminal", + isEnabled: true, + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "throw 401 when invalid authentication token is provided", + }, + { + name: "request without organization header", + featureName: "terminal", + isEnabled: true, + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "throw 400 when organization header is missing", + }, + { + name: "on update of non-existent feature flag, create new one", + featureName: "non_existent_feature", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "create new feature flag for non-existent feature name", + }, + { + name: "update feature flag with empty name", + featureName: "", + isEnabled: true, + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusBadRequest, + description: "throws 400 when feature name is empty", + }, + { + name: "cross-organization update attempt", + featureName: "terminal", + isEnabled: true, + token: user.AccessToken, + organizationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusForbidden, + description: "throw error for updating feature flags from different organization", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + requestBody := map[string]interface{}{ + "feature_name": tc.featureName, + "is_enabled": tc.isEnabled, + } + + testSteps := []IStep{ + Description(tc.description), + Put(tests.GetFeatureFlagsURL()), + Send().Body().JSON(requestBody), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Feature flag updated successfully"), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestIsFeatureEnabled(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + // First, ensure feature flags exist and set known states + Test(t, + Description("Initialize feature flags"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + ) + + // Enable terminal feature for testing + Test(t, + Description("enable terminal feature for testing"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "terminal", + "is_enabled": true, + }), + Expect().Status().Equal(http.StatusOK), + ) + + // Disable container feature for testing + Test(t, + Description("disable container feature for testing"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "container", + "is_enabled": false, + }), + Expect().Status().Equal(http.StatusOK), + ) + + testCases := []struct { + name string + featureName string + token string + organizationID string + expectedStatus int + expectedResult bool + description string + }{ + { + name: "Check enabled feature (terminal)", + featureName: "terminal", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + expectedResult: true, + description: "return true for enabled terminal feature", + }, + { + name: "Check disabled feature (container)", + featureName: "container", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + expectedResult: false, + description: " return false for disabled container feature", + }, + { + name: "Check non-existent feature", + featureName: "non_existent_feature", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, // API returns default enabled state instead of 404 + expectedResult: true, // Default state is enabled + description: "return default enabled state for non-existent feature", + }, + { + name: "Unauthorized request without token", + featureName: "terminal", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "throw 401 when no authentication token is provided", + }, + { + name: "Unauthorized request with invalid token", + featureName: "terminal", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "throw 401 when invalid authentication token is provided", + }, + { + name: "Request without organization header", + featureName: "terminal", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "throw 400 when organization header is missing", + }, + { + name: "Check feature with empty name", + featureName: "", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, // API returns default state instead of 400 + expectedResult: true, // Default state when no feature name provided + description: "return default state when feature name is empty", + }, + { + name: "Cross-organization feature check", + featureName: "terminal", + token: user.AccessToken, + organizationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusForbidden, + description: "deny checking feature flags from different organization", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + url := tests.GetFeatureFlagCheckURL() + if tc.featureName != "" { + url += "?feature_name=" + tc.featureName + } + + testSteps := []IStep{ + Description(tc.description), + Get(url), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-Id").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".data.is_enabled").Equal(tc.expectedResult), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestFeatureFlagsCRUDFlow(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Validate CRUD flow for feature flags", func(t *testing.T) { + // Step 1: Get initial feature flags (should create defaults) + Test(t, + Description("Step 1: Get initial feature flags - should create defaults"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + + // Step 2: Check initial state of terminal feature (should be enabled by default) + Test(t, + Description("Step 2: Check initial state of terminal feature"), + Get(tests.GetFeatureFlagCheckURL()+"?feature_name=terminal"), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".data.is_enabled").Equal(true), + ) + + // Step 3: Disable terminal feature + Test(t, + Description("Step 3: Disable terminal feature"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "terminal", + "is_enabled": false, + }), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + ) + + // Step 4: Verify terminal feature is now disabled + Test(t, + Description("Step 4: Verify terminal feature is now disabled"), + Get(tests.GetFeatureFlagCheckURL()+"?feature_name=terminal"), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".data.is_enabled").Equal(false), + ) + + // Step 5: Re-enable terminal feature + Test(t, + Description("Step 5: Re-enable terminal feature"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "terminal", + "is_enabled": true, + }), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".status").Equal("success"), + ) + + // Step 6: Verify terminal feature is enabled again + Test(t, + Description("Step 6: Verify terminal feature is enabled again"), + Get(tests.GetFeatureFlagCheckURL()+"?feature_name=terminal"), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".data.is_enabled").Equal(true), + ) + + // Step 7: Get all feature flags and verify terminal is in the list and enabled + Test(t, + Description("Step 7: Get all feature flags and verify terminal state"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + Expect().Body().JSON().JQ(".data | map(select(.feature_name == \"terminal\")) | .[0].is_enabled").Equal(true), + ) + }) +} + +func TestFeatureFlagPermissions(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Feature flag permissions and organization isolation", func(t *testing.T) { + // Initialize feature flags in user's organization + Test(t, + Description("Initialize feature flags in user's organization"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusOK), + ) + + // Try to access feature flags with different organization ID + Test(t, + Description("deny access to feature flags from different organization"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Try to update feature flag from different organization + Test(t, + Description("deny feature flag update from different organization"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "terminal", + "is_enabled": false, + }), + Expect().Status().Equal(http.StatusForbidden), + ) + + // Try to check feature flag from different organization + Test(t, + Description("deny feature flag check from different organization"), + Get(tests.GetFeatureFlagCheckURL()+"?feature_name=terminal"), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add("123e4567-e89b-12d3-a456-426614174000"), + Expect().Status().Equal(http.StatusForbidden), + ) + }) +} + +func TestFeatureFlagErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + Test(t, + Description("handle malformed authorization header gracefully"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + Test(t, + Description("handle empty authorization header"), + Get(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-Id").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Missing Content-Type header for PUT requests", func(t *testing.T) { + Test(t, + Description("handle missing Content-Type header"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "terminal", + "is_enabled": true, + }), + Expect().Status().Equal(http.StatusOK), + ) + }) + + t.Run("Invalid JSON payload", func(t *testing.T) { + Test(t, + Description("handle invalid JSON payload"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().String("{invalid-json}"), + Expect().Status().Equal(http.StatusBadRequest), + ) + }) + + t.Run("Very long feature name", func(t *testing.T) { + longFeatureName := "" + for i := 0; i < 300; i++ { + longFeatureName += "a" + } + + Test(t, + Description("handle very long feature names"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": longFeatureName, + "is_enabled": true, + }), + Expect().Status().Equal(http.StatusInternalServerError), // Database returns 500 for varchar length constraint + ) + }) + + t.Run("Special characters in feature name", func(t *testing.T) { + Test(t, + Description("handle special characters in feature name"), + Put(tests.GetFeatureFlagsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-Id").Add(orgID), + Send().Body().JSON(map[string]interface{}{ + "feature_name": "feature@#$%^&*()", + "is_enabled": true, + }), + Expect().Status().Equal(http.StatusOK), + ) + }) +} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index 71176885..07b2ce2c 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -88,4 +88,12 @@ func GetDomainsURL() string { func GetDomainGenerateURL() string { return baseURL + "/domain/generate" -} \ No newline at end of file +} + +func GetFeatureFlagsURL() string { + return baseURL + "/feature-flags" +} + +func GetFeatureFlagCheckURL() string { + return baseURL + "/feature-flags/check" +} From 6e4866ef48e253281fb1f784bfd550a523c32ecb Mon Sep 17 00:00:00 2001 From: shravan20 Date: Sun, 6 Jul 2025 15:28:10 +0530 Subject: [PATCH 24/72] docs: details on migrations --- api/api/versions.json | 2 +- assets/db-schema.png | Bin 0 -> 226529 bytes docs/.vitepress/config.mts | 8 + docs/migrations/index.md | 321 +++++++++++++++++++++++++++++ docs/migrations/quick-reference.md | 210 +++++++++++++++++++ docs/migrations/templates.md | 307 +++++++++++++++++++++++++++ 6 files changed, 847 insertions(+), 1 deletion(-) create mode 100644 assets/db-schema.png create mode 100644 docs/migrations/index.md create mode 100644 docs/migrations/quick-reference.md create mode 100644 docs/migrations/templates.md diff --git a/api/api/versions.json b/api/api/versions.json index cd003558..22f4b10f 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-07-05T10:51:37.94673+05:30", + "release_date": "2025-07-05T21:25:27.672646+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/assets/db-schema.png b/assets/db-schema.png new file mode 100644 index 0000000000000000000000000000000000000000..a103b456b0cddb5553efdfb12e33556a6ee0ac79 GIT binary patch literal 226529 zcmafb1ymJZ_cmS99Rio`1_|lz?p8oby1S&irIBuw?vMrn2?1#Yq`Ui@tG{@CzqS6a zYk;|T&dfPy&pvxU``P;#uB<49f<%Y}0Re#`BQ3590Rbll0Rf$l00(@7Fy+Jo0RgFH zDJG^YBPIq?cC>qA`PK{qf;QeJPEHQ$6@D=3R6>YaS=54;kZ`(P&on_qqYveqqy%;Nj~=Tk*>3QA3IKPn$lfwWqe zjPUblWSKP&#}fHf+)GxvEpG0|c7q;<7UTX!kJ`0LnaEl)`+e@Vc+7K>p3S79?cwpf zlnAEI!;9(WR^$VzkdqdeOSTe0{C=L4+YCKE)27shB&9r6SC@4VC zgQX4u8EOdu1DrtuKZL*!@In$oAmD+&n81&CF4W&w;ly&G|2~J#2R9T^6O)kv{;HWc znwi-;S=c#W`~L_69yM#JuI;R?AkSxFXT$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25/72] docs: details on migrations --- docs/migrations/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migrations/index.md b/docs/migrations/index.md index eb7acfce..384fffd1 100644 --- a/docs/migrations/index.md +++ b/docs/migrations/index.md @@ -86,7 +86,7 @@ CREATE TABLE migrations ( ); ``` -![](../../assets/db-schema.png) +![db-schema](https://raw.githubusercontent.com/shravan20/nixopus/refs/heads/master/assets/db-schema.png) ### Transaction Safety From cf111d8bea73b270e569ab649abc72f636be8f39 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 9 Jul 2025 16:09:59 +0530 Subject: [PATCH 26/72] feat: nixopus cli project init and add link for cli documentation --- .gitignore | 43 ++++++ cli/__init__.py | 1 + cli/commands/__init__.py | 0 cli/commands/test.py | 14 ++ cli/commands/version.py | 14 ++ cli/core/__init__.py | 0 cli/core/config.py | 7 + cli/core/version.py | 23 +++ cli/main.py | 34 +++++ cli/pyproject.toml | 34 +++++ cli/tests/__init__.py | 0 cli/tests/test_commands_version.py | 120 ++++++++++++++++ cli/tests/version.py | 134 +++++++++++++++++ cli/utils/__init__.py | 0 docs/.vitepress/config.mts | 9 ++ docs/cli/commands.md | 125 ++++++++++++++++ docs/cli/development.md | 221 +++++++++++++++++++++++++++++ docs/cli/index.md | 28 ++++ docs/cli/installation.md | 133 +++++++++++++++++ 19 files changed, 940 insertions(+) create mode 100644 cli/__init__.py create mode 100644 cli/commands/__init__.py create mode 100644 cli/commands/test.py create mode 100644 cli/commands/version.py create mode 100644 cli/core/__init__.py create mode 100644 cli/core/config.py create mode 100644 cli/core/version.py create mode 100644 cli/main.py create mode 100644 cli/pyproject.toml create mode 100644 cli/tests/__init__.py create mode 100644 cli/tests/test_commands_version.py create mode 100644 cli/tests/version.py create mode 100644 cli/utils/__init__.py create mode 100644 docs/cli/commands.md create mode 100644 docs/cli/development.md create mode 100644 docs/cli/index.md create mode 100644 docs/cli/installation.md diff --git a/.gitignore b/.gitignore index 89ee350c..d3d3286e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,46 @@ docs/.vitepress/cache !api/.env.sample **.log .vscode + +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +venv/ +env/ +ENV/ +env.bak/ +venv.bak/ +.venv/ + +.idea/ + +.pytest_cache/ +.coverage +htmlcov/ + +.ipynb_checkpoints + +.env.local +.env.development.local +.env.test.local +.env.production.local diff --git a/cli/__init__.py b/cli/__init__.py new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/cli/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/cli/commands/__init__.py b/cli/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/commands/test.py b/cli/commands/test.py new file mode 100644 index 00000000..f04894ae --- /dev/null +++ b/cli/commands/test.py @@ -0,0 +1,14 @@ +import subprocess +import typer +from core.config import is_development + +def test_command(target: str = typer.Argument(None, help="Test target (e.g., version)")): + if not is_development(): + typer.echo("Test command is only available in DEVELOPMENT environment.") + raise typer.Exit(1) + cmd = ["venv/bin/python", "-m", "pytest"] + if target: + cmd.append(f"tests/{target}.py") + typer.echo(f"Running: {' '.join(cmd)}") + result = subprocess.run(cmd) + raise typer.Exit(result.returncode) \ No newline at end of file diff --git a/cli/commands/version.py b/cli/commands/version.py new file mode 100644 index 00000000..6a6107cf --- /dev/null +++ b/cli/commands/version.py @@ -0,0 +1,14 @@ +import typer +from core.version import display_version + + +def version_command(): + """Show version information""" + display_version() + + +def version_callback(value: bool): + """Callback for version options (-v, --version)""" + if value: + version_command() + raise typer.Exit() \ No newline at end of file diff --git a/cli/core/__init__.py b/cli/core/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/core/config.py b/cli/core/config.py new file mode 100644 index 00000000..359271cf --- /dev/null +++ b/cli/core/config.py @@ -0,0 +1,7 @@ +import os + +def get_env(default="PRODUCTION"): + return os.environ.get("ENV", default) + +def is_development(): + return get_env().upper() == "DEVELOPMENT" \ No newline at end of file diff --git a/cli/core/version.py b/cli/core/version.py new file mode 100644 index 00000000..c198ecbc --- /dev/null +++ b/cli/core/version.py @@ -0,0 +1,23 @@ +from rich.console import Console +from rich.panel import Panel +from rich.text import Text +from importlib.metadata import version + +console = Console() + +def display_version(): + """Display the version of the CLI""" + cli_version = version('nixopus') + + version_text = Text() + version_text.append("NixOpus CLI", style="bold blue") + version_text.append(f" v{cli_version}", style="green") + + panel = Panel( + version_text, + title="[bold white]Version Info[/bold white]", + border_style="blue", + padding=(0, 1) + ) + + console.print(panel) \ No newline at end of file diff --git a/cli/main.py b/cli/main.py new file mode 100644 index 00000000..778f7b35 --- /dev/null +++ b/cli/main.py @@ -0,0 +1,34 @@ +import typer +from commands.version import version_command, version_callback +from commands.test import test_command + +app = typer.Typer( + name="nixopus", + help="NixOpus CLI - A powerful deployment and management tool", + add_completion=False, +) + +@app.callback() +def main( + version: bool = typer.Option( + None, + "--version", + "-v", + callback=version_callback, + help="Show version information" + ) +): + pass + +@app.command() +def version(): + """Show version information""" + version_command() + +@app.command() +def test(target: str = typer.Argument(None, help="Test target (e.g., version)")): + """Run tests (only in DEVELOPMENT environment)""" + test_command(target) + +if __name__ == "__main__": + app() diff --git a/cli/pyproject.toml b/cli/pyproject.toml new file mode 100644 index 00000000..77a3e882 --- /dev/null +++ b/cli/pyproject.toml @@ -0,0 +1,34 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "nixopus" +version = "0.1.0" +description = "A CLI for Nixopus" +authors = [ + { name = "NixOpus", email = "raghavyuva@gmail.com" } +] +dependencies = [ + "typer>=0.9.0", + "rich>=13.0.0" +] + +[project.scripts] +nixopus = "cli.main:main" + +[project.optional-dependencies] +dev = [ + "pytest>=7.0.0", + "pytest-cov>=4.0.0" +] + +[tool.setuptools.packages.find] +where = ["."] + +[tool.pytest.ini_options] +testpaths = ["tests"] +python_files = ["test_*.py"] +python_classes = ["Test*"] +python_functions = ["test_*"] +addopts = "-v --cov=core --cov=utils --cov-report=term-missing" \ No newline at end of file diff --git a/cli/tests/__init__.py b/cli/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/tests/test_commands_version.py b/cli/tests/test_commands_version.py new file mode 100644 index 00000000..f1716d74 --- /dev/null +++ b/cli/tests/test_commands_version.py @@ -0,0 +1,120 @@ +import pytest +from unittest.mock import patch, MagicMock +from commands.version import version_command, version_callback +import typer + + +class TestVersionCommand: + """Test cases for the version_command function""" + + @patch('commands.version.display_version') + def test_version_command_calls_display_version(self, mock_display_version): + """Test that version_command calls display_version""" + version_command() + + mock_display_version.assert_called_once() + + @patch('commands.version.display_version') + def test_version_command_returns_none(self, mock_display_version): + """Test that version_command returns None""" + result = version_command() + + assert result is None + mock_display_version.assert_called_once() + + +class TestVersionCallback: + """Test cases for the version_callback function""" + + @patch('commands.version.version_command') + def test_version_callback_with_true_value(self, mock_version_command): + """Test version_callback with True value calls version_command and exits""" + with pytest.raises(typer.Exit): + version_callback(True) + + mock_version_command.assert_called_once() + + @patch('commands.version.version_command') + def test_version_callback_with_false_value(self, mock_version_command): + """Test version_callback with False value does nothing""" + result = version_callback(False) + + assert result is None + mock_version_command.assert_not_called() + + @patch('commands.version.version_command') + def test_version_callback_with_none_value(self, mock_version_command): + """Test version_callback with None value does nothing""" + result = version_callback(None) + + assert result is None + mock_version_command.assert_not_called() + + @patch('commands.version.version_command') + def test_version_callback_exits_after_version_command(self, mock_version_command): + """Test that version_callback raises typer.Exit after calling version_command""" + mock_version_command.return_value = None + + with pytest.raises(typer.Exit): + version_callback(True) + + mock_version_command.assert_called_once() + + @patch('commands.version.version_command') + def test_version_callback_handles_version_command_exception(self, mock_version_command): + """Test that version_callback still exits even if version_command raises an exception""" + mock_version_command.side_effect = Exception("Version command error") + + with pytest.raises(Exception, match="Version command error"): + version_callback(True) + + mock_version_command.assert_called_once() + + +class TestVersionCommandIntegration: + """Integration test cases for version commands""" + + @patch('commands.version.display_version') + def test_version_command_integration(self, mock_display_version): + """Integration test for version_command calling display_version""" + version_command() + + mock_display_version.assert_called_once() + + @patch('commands.version.version_command') + @patch('commands.version.display_version') + def test_version_callback_integration(self, mock_display_version, mock_version_command): + """Integration test for version_callback calling version_command""" + mock_version_command.side_effect = lambda: mock_display_version() + + with pytest.raises(typer.Exit): + version_callback(True) + + mock_version_command.assert_called_once() + mock_display_version.assert_called_once() + + +class TestVersionFunctionSignatures: + """Test cases for function signatures and behavior""" + + def test_version_command_is_callable(self): + """Test that version_command is a callable function""" + assert callable(version_command) + + def test_version_callback_is_callable(self): + """Test that version_callback is a callable function""" + assert callable(version_callback) + + def test_version_command_no_parameters(self): + """Test that version_command takes no parameters""" + import inspect + sig = inspect.signature(version_command) + assert len(sig.parameters) == 0 + + def test_version_callback_parameter(self): + """Test that version_callback takes one parameter""" + import inspect + sig = inspect.signature(version_callback) + assert len(sig.parameters) == 1 + assert 'value' in sig.parameters + assert sig.parameters['value'].annotation == bool \ No newline at end of file diff --git a/cli/tests/version.py b/cli/tests/version.py new file mode 100644 index 00000000..f5ec7b9b --- /dev/null +++ b/cli/tests/version.py @@ -0,0 +1,134 @@ +import pytest +from unittest.mock import patch, MagicMock +from importlib.metadata import version +from core.version import display_version + + +class TestDisplayVersion: + """Test cases for the display_version function""" + + @patch('core.version.console') + @patch('core.version.version') + def test_display_version_success(self, mock_version, mock_console): + """Test successful version display""" + mock_version.return_value = "1.0.0" + + display_version() + + mock_version.assert_called_once_with('nixopus') + mock_console.print.assert_called_once() + + call_args = mock_console.print.call_args[0][0] + assert call_args.title == "[bold white]Version Info[/bold white]" + assert call_args.border_style == "blue" + assert call_args.padding == (0, 1) + + @patch('core.version.console') + @patch('core.version.version') + def test_display_version_with_different_versions(self, mock_version, mock_console): + """Test version display with different version numbers""" + test_versions = ["0.1.0", "2.3.4", "1.0.0-beta"] + + for test_version in test_versions: + mock_version.return_value = test_version + mock_console.reset_mock() + + display_version() + + mock_version.assert_called_with('nixopus') + mock_console.print.assert_called_once() + + @patch('core.version.console') + @patch('core.version.version') + def test_display_version_panel_content(self, mock_version, mock_console): + """Test that panel contains correct text content""" + mock_version.return_value = "1.2.3" + + display_version() + + call_args = mock_console.print.call_args[0][0] + panel_content = call_args.renderable + + assert "NixOpus CLI" in str(panel_content) + assert "v1.2.3" in str(panel_content) + + @patch('core.version.console') + @patch('core.version.version') + def test_display_version_handles_version_error(self, mock_version, mock_console): + """Test handling of version import error""" + mock_version.side_effect = Exception("Version not found") + + with pytest.raises(Exception): + display_version() + + mock_version.assert_called_once_with('nixopus') + + @patch('core.version.console') + @patch('core.version.version') + def test_display_version_console_error_handling(self, mock_version, mock_console): + """Test handling of console print errors""" + mock_version.return_value = "1.0.0" + mock_console.print.side_effect = Exception("Console error") + + with pytest.raises(Exception): + display_version() + + mock_version.assert_called_once_with('nixopus') + mock_console.print.assert_called_once() + + +class TestVersionModuleImports: + """Test cases for module imports and dependencies""" + + def test_import_metadata_version(self): + """Test that importlib.metadata.version is available""" + try: + from importlib.metadata import version + assert callable(version) + except ImportError: + pytest.skip("importlib.metadata not available") + + def test_rich_console_import(self): + """Test that rich.console.Console is available""" + try: + from rich.console import Console + assert callable(Console) + except ImportError: + pytest.skip("rich.console not available") + + def test_rich_panel_import(self): + """Test that rich.panel.Panel is available""" + try: + from rich.panel import Panel + assert callable(Panel) + except ImportError: + pytest.skip("rich.panel not available") + + def test_rich_text_import(self): + """Test that rich.text.Text is available""" + try: + from rich.text import Text + assert callable(Text) + except ImportError: + pytest.skip("rich.text not available") + + +class TestVersionFunctionSignature: + """Test cases for function signature and behavior""" + + def test_display_version_is_callable(self): + """Test that display_version is a callable function""" + assert callable(display_version) + + def test_display_version_no_parameters(self): + """Test that display_version takes no parameters""" + import inspect + sig = inspect.signature(display_version) + assert len(sig.parameters) == 0 + + def test_display_version_returns_none(self): + """Test that display_version returns None""" + with patch('core.version.console'): + with patch('core.version.version', return_value="1.0.0"): + result = display_version() + assert result is None diff --git a/cli/utils/__init__.py b/cli/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index d0f80163..ecdc8cd8 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -77,6 +77,15 @@ export default withMermaid( { text: "Notifications", link: "/notifications/index.md" } ] }, + { + text: 'CLI', + items: [ + { text: 'Overview', link: '/cli/index.md' }, + { text: 'Installation', link: '/cli/installation.md' }, + { text: 'Commands', link: '/cli/commands.md' }, + { text: 'Development', link: '/cli/development.md' } + ] + }, { text: 'Blog', items: [ diff --git a/docs/cli/commands.md b/docs/cli/commands.md new file mode 100644 index 00000000..7ea7d95b --- /dev/null +++ b/docs/cli/commands.md @@ -0,0 +1,125 @@ +# CLI Commands Reference + +This guide provides detailed documentation for all available NixOpus CLI commands. + +## Command Overview + +The NixOpus CLI provides essential commands for managing your NixOpus deployments: + +| Command | Description | Usage | +|---------|-------------|-------| +| `version` | Display CLI version | `nixopus version` | +| `test` | Run CLI tests | `nixopus test [target]` | + +## Core Commands + +Core commands provide essential functionality for the CLI. + +### `version` + +Display the current version of the NixOpus CLI. + +**Usage:** +```bash +nixopus version +nixopus --version +nixopus -v +``` + +**Options:** +- `-v, --version`: Show version information and exit + +**Example Output:** +``` +┌───────────────── Version Info ─────────────────┐ +│ NixOpus CLI v0.1.0 │ +└─────────────────────────────────────────────────┘ +``` + +**Aliases:** `-v`, `--version` + +**Description:** +The version command displays the current version of the NixOpus CLI using rich formatting. The version information is retrieved from the package metadata and displayed in a styled panel. + +--- + +## Development Commands + +Development commands are available only in development environments and help with CLI development and testing. + +### `test` + +Run tests for the CLI components. This command is only available in development environments. + +**Usage:** +```bash +nixopus test [target] +``` + +**Parameters:** +- `target` (optional): Specific test target (e.g., "version") + +**Environment Requirements:** +- Requires `ENV=DEVELOPMENT` environment variable + +**Examples:** +```bash +# Run all tests +nixopus test + +# Run specific test file +nixopus test version +``` + +**Description:** +The test command runs the CLI test suite using pytest. It can run all tests or target specific test files. This command is restricted to development environments for security reasons. + +**Error Handling:** +- If not in development environment: Shows error message and exits +- If target file doesn't exist: pytest will handle the error + +**Output:** +``` +Running: venv/bin/python -m pytest tests/version.py +``` + +--- + +## Command Help + +Get help for any command: + +```bash +# General help +nixopus --help + +# Command-specific help +nixopus version --help +nixopus test --help +``` + +## Command Structure + +All CLI commands follow a consistent structure: + +1. **Command Name**: Descriptive, action-oriented names +2. **Parameters**: Optional arguments for command customization +3. **Options**: Flags for additional functionality +4. **Environment**: Some commands require specific environment settings + +## Error Handling + +The CLI provides clear error messages for common issues: + +- **Invalid Commands**: Shows help and available commands +- **Missing Parameters**: Displays parameter requirements +- **Environment Errors**: Clear messages about environment requirements +- **Permission Errors**: Guidance on fixing permission issues + +## Exit Codes + +Commands return appropriate exit codes: + +- `0`: Success +- `1`: General error +- `2`: Usage error (invalid arguments) diff --git a/docs/cli/development.md b/docs/cli/development.md new file mode 100644 index 00000000..26c3a7ae --- /dev/null +++ b/docs/cli/development.md @@ -0,0 +1,221 @@ +# CLI Development Guide + +This guide provides detailed information for contributing to the Nixopus CLI development. + +## Project Structure + +``` +cli/ +├── main.py # Main CLI entry point +├── pyproject.toml # Project configuration +├── commands/ # Command implementations +│ ├── version.py # Version command +│ └── test.py # Test command +├── core/ # Core functionality +│ ├── config.py # Configuration utilities +│ └── version.py # Version display logic +├── utils/ # Utility functions +└── tests/ # Test files + ├── test_commands_version.py + └── version.py +``` + +## Development Setup + +1. **Clone and Install** + ```bash + git clone https://github.com/your-org/nixopus.git + cd nixopus/cli + pip install -e ".[dev]" + ``` + +2. **Verify Installation** + ```bash + nixopus version + pytest + ``` + +## Adding New Commands + +### Step 1: Create Command File + +Create a new file in the `commands/` directory: + +```python +# commands/new_command.py +import typer + +def new_command(): + """Description of the new command""" + # Command implementation + pass +``` + +### Step 2: Register Command + +Import and register the command in `main.py`: + +```python +from commands.new_command import new_command + +@app.command() +def new(): + """Description of the new command""" + new_command() +``` + +### Step 3: Add Tests + +Create corresponding test files in the `tests/` directory: + +```python +# tests/test_commands_new.py +import pytest +from typer.testing import CliRunner +from cli.main import app + +runner = CliRunner() + +def test_new_command(): + result = runner.invoke(app, ["new"]) + assert result.exit_code == 0 +``` + +### Step 4: Update Documentation + +Add the command to the appropriate table in the [Commands Reference](commands.md). + +## Testing + +### Running Tests + +```bash +# Run all tests +pytest + +# Run with coverage +pytest --cov=core --cov=utils --cov-report=term-missing + +# Run specific test +pytest tests/test_commands_version.py + +# Run with verbose output +pytest -v +``` + +### Test Structure + +Tests are organized in the `tests/` directory: + +- **Command Tests**: Test individual command functionality +- **Core Tests**: Test core utility functions +- **Integration Tests**: Test command interactions + +### Writing Tests + +Follow these guidelines: + +1. **Test Command Execution** + ```python + def test_version_command(): + result = runner.invoke(app, ["version"]) + assert result.exit_code == 0 + assert "Nixopus CLI" in result.stdout + ``` + +2. **Test Error Cases** + ```python + def test_test_command_development_only(): + result = runner.invoke(app, ["test"]) + assert result.exit_code == 1 + assert "DEVELOPMENT" in result.stdout + ``` + +3. **Test Parameters** + ```python + def test_test_command_with_target(): + with patch('commands.test.is_development', return_value=True): + result = runner.invoke(app, ["test", "version"]) + assert result.exit_code == 0 + ``` + +## Code Standards + +### General Guidelines + +1. **Follow existing patterns**: Match the structure of existing commands +2. **Keep functions short**: Focus on single responsibility +3. **Use type hints**: Add type annotations where helpful +4. **Follow DRY principles**: Avoid code duplication +5. **Clean code**: Write readable, maintainable code + +### Command Guidelines + +1. **Descriptive names**: Use clear, action-oriented command names +2. **Help text**: Provide helpful descriptions for all commands +3. **Error handling**: Handle errors gracefully with clear messages +4. **Exit codes**: Return appropriate exit codes (0 for success, 1 for error) + +### Documentation Guidelines + +1. **Update command docs**: Add new commands to [Commands Reference](commands.md) +2. **Include examples**: Provide usage examples for all commands +3. **Document parameters**: Explain all parameters and options +4. **Specify requirements**: Note any environment or dependency requirements + +## Dependencies + +### Core Dependencies +- **typer**: Modern CLI framework for Python +- **rich**: Rich text and beautiful formatting in the terminal + +### Development Dependencies +- **pytest**: Testing framework +- **pytest-cov**: Coverage reporting for pytest + +## Environment Configuration + +The CLI supports different environments through the `ENV` environment variable: + +- `PRODUCTION` (default): Production environment +- `DEVELOPMENT`: Development environment (enables test commands) + +Set the environment: +```bash +export ENV=DEVELOPMENT +``` + +## Contributing Process + +1. **Create a branch** + ```bash + git checkout -b feature/new-command + ``` + +2. **Make changes** + - Add new command files + - Update main.py + - Add tests + - Update documentation + +3. **Run tests** + ```bash + pytest + ``` + +4. **Commit changes** + ```bash + git add . + git commit -m "Add new command: description" + ``` + +5. **Submit pull request** + +## Testing Guidelines + +- Write tests for all new commands +- Use pytest for testing +- Maintain good test coverage +- Test both success and error scenarios +- Test command help and usage +- Test environment-specific behavior \ No newline at end of file diff --git a/docs/cli/index.md b/docs/cli/index.md new file mode 100644 index 00000000..34bbe2bd --- /dev/null +++ b/docs/cli/index.md @@ -0,0 +1,28 @@ +# Nixopus CLI + +The Nixopus CLI is a powerful command-line interface for managing and deploying applications with Nixopus. Built with Python and Typer, it provides an intuitive way to interact with the Nixopus platform. + +## Quick Start + +Get started with the Nixopus CLI check [Installation Guide](installation.md) on how to setup nixopus cli + +```bash +nixopus --help +nixopus version +``` + +## Commands Overview + +The Nixopus CLI provides essential commands for managing your Nixopus deployments: + +| Command | Description | Usage | +|---------|-------------|-------| +| `version` | Display CLI version | `nixopus version` | + +For detailed command documentation, see the [Commands Reference](commands.md). + +## Next Steps + +- [Installation Guide](installation.md) - Complete setup instructions +- [Commands Reference](commands.md) - Detailed command usage +- [Development Guide](development.md) - Contributing to the CLI \ No newline at end of file diff --git a/docs/cli/installation.md b/docs/cli/installation.md new file mode 100644 index 00000000..711e74ad --- /dev/null +++ b/docs/cli/installation.md @@ -0,0 +1,133 @@ +# CLI Installation Guide + +This guide provides detailed instructions for installing and setting up the Nixopus CLI. + +## Prerequisites + +Before installing the Nixopus CLI, ensure you have: + +- **Python 3.8 or higher** +- **pip** (Python package installer) +- **Git** (for cloning the repository) + +### Check Python Version + +```bash +python3 --version +``` + +### Check pip Installation + +```bash +pip --version +``` + +## Installation Methods + +### Method 1: Install from Source (Recommended) + +1. **Clone the Repository** + ```bash + git clone https://github.com/raghavyuva/nixopus.git + cd nixopus + ``` + +2. **Navigate to CLI Directory** + ```bash + cd cli + ``` + +3. **Install in Development Mode** + ```bash + pip install -e . + ``` + +### Method 2: Install Dependencies + +For development work, install additional dependencies: + +```bash +pip install -e ".[dev]" +``` + +This installs: +- **pytest**: Testing framework +- **pytest-cov**: Coverage reporting + +## Verification + +After installation, verify the CLI is working: + +```bash +nixopus --help + +nixopus version +``` + +Expected output: +``` +┌───────────────── Version Info ───────────────── ┐ +│ Nixopus CLI version │ +└─────────────────────────────────────────────────┘ +``` + +## Troubleshooting + +### Common Issues + +1. **Command Not Found** + - Ensure you're in the correct directory (`cli/`) + - Verify Python and pip are properly installed + - Try reinstalling: `pip install -e .` + +2. **Permission Errors** + - Use `pip install -e . --user` for user installation + - Or use a virtual environment + +3. **Import Errors** + - Check that all dependencies are installed + - Verify Python version compatibility + +### Virtual Environment (Optional) + +For isolated installation: + +```bash +python3 -m venv venv + +# Activate virtual environment +source venv/bin/activate # On macOS/Linux +# or +venv\Scripts\activate # On Windows + +# Install CLI +pip install -e . +``` + +## Development Setup + +For contributors who want to develop the CLI: + +1. **Clone and Install** + ```bash + git clone https://github.com/raghavyuva/nixopus.git + cd nixopus/cli + pip install -e ".[dev]" + ``` + +2. **Run Tests** + ```bash + pytest + ``` + +3. **Check Coverage** + ```bash + pytest --cov=core --cov=utils --cov-report=term-missing + ``` + +## Next Steps + +After successful installation: + +- [Commands Reference](../cli/commands.md) - Learn available commands +- [Development Guide](../cli/development.md) - Contribute to the CLI \ No newline at end of file From 4a9872998b1667b7afddccc259050df1df765bf9 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 9 Jul 2025 17:38:59 +0530 Subject: [PATCH 27/72] refactor: folder structure organization --- cli/commands/preflight/__init__.py | 0 cli/commands/preflight/command.py | 9 +++ cli/commands/preflight/messages.py | 2 + cli/commands/test/__init__.py | 0 cli/commands/test/command.py | 14 ++++ cli/commands/test/messages.py | 1 + cli/commands/version.py | 14 ---- cli/commands/version/__init__.py | 0 cli/commands/version/command.py | 19 +++++ cli/core/test/__init__.py | 0 cli/core/test/test.py | 14 ++++ cli/core/{ => version}/version.py | 2 +- cli/main.py | 30 ++++---- cli/tests/test_commands_version.py | 111 ++++++++++++++--------------- cli/tests/version.py | 28 ++++---- cli/utils/message.py | 6 ++ docs/cli/commands.md | 34 +++++++-- docs/cli/development.md | 69 ++++++++++-------- 18 files changed, 217 insertions(+), 136 deletions(-) create mode 100644 cli/commands/preflight/__init__.py create mode 100644 cli/commands/preflight/command.py create mode 100644 cli/commands/preflight/messages.py create mode 100644 cli/commands/test/__init__.py create mode 100644 cli/commands/test/command.py create mode 100644 cli/commands/test/messages.py delete mode 100644 cli/commands/version.py create mode 100644 cli/commands/version/__init__.py create mode 100644 cli/commands/version/command.py create mode 100644 cli/core/test/__init__.py create mode 100644 cli/core/test/test.py rename cli/core/{ => version}/version.py (90%) create mode 100644 cli/utils/message.py diff --git a/cli/commands/preflight/__init__.py b/cli/commands/preflight/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/commands/preflight/command.py b/cli/commands/preflight/command.py new file mode 100644 index 00000000..f2608a8e --- /dev/null +++ b/cli/commands/preflight/command.py @@ -0,0 +1,9 @@ +import typer +from .messages import running_preflight_checks + +preflight_app = typer.Typer() + +@preflight_app.command() +def check(): + """Run all preflight checks""" + typer.echo(running_preflight_checks) \ No newline at end of file diff --git a/cli/commands/preflight/messages.py b/cli/commands/preflight/messages.py new file mode 100644 index 00000000..4f6b39dd --- /dev/null +++ b/cli/commands/preflight/messages.py @@ -0,0 +1,2 @@ +preflight_check_app_help = "Checks to ensure the system is ready for nixopus self-hosting" +running_preflight_checks = "Running preflight checks..." \ No newline at end of file diff --git a/cli/commands/test/__init__.py b/cli/commands/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/commands/test/command.py b/cli/commands/test/command.py new file mode 100644 index 00000000..3fd9cbe6 --- /dev/null +++ b/cli/commands/test/command.py @@ -0,0 +1,14 @@ +import typer +from core.test.test import test_command +from .messages import test_app_help + +test_app = typer.Typer( + help=test_app_help, + invoke_without_command=True +) + +@test_app.callback() +def test_callback(ctx: typer.Context, target: str = typer.Argument(None, help="Test target (e.g., version)")): + """Run tests (only in DEVELOPMENT environment)""" + if ctx.invoked_subcommand is None: + test_command(target) \ No newline at end of file diff --git a/cli/commands/test/messages.py b/cli/commands/test/messages.py new file mode 100644 index 00000000..66893af0 --- /dev/null +++ b/cli/commands/test/messages.py @@ -0,0 +1 @@ +test_app_help = "Run tests (only in DEVELOPMENT environment)" \ No newline at end of file diff --git a/cli/commands/version.py b/cli/commands/version.py deleted file mode 100644 index 6a6107cf..00000000 --- a/cli/commands/version.py +++ /dev/null @@ -1,14 +0,0 @@ -import typer -from core.version import display_version - - -def version_command(): - """Show version information""" - display_version() - - -def version_callback(value: bool): - """Callback for version options (-v, --version)""" - if value: - version_command() - raise typer.Exit() \ No newline at end of file diff --git a/cli/commands/version/__init__.py b/cli/commands/version/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/commands/version/command.py b/cli/commands/version/command.py new file mode 100644 index 00000000..be80fc13 --- /dev/null +++ b/cli/commands/version/command.py @@ -0,0 +1,19 @@ +import typer +from core.version.version import display_version +from utils.message import application_version_help + +version_app = typer.Typer( + help=application_version_help, + invoke_without_command=True +) + +@version_app.callback() +def version_callback(ctx: typer.Context): + """Show version information (default)""" + if ctx.invoked_subcommand is None: + display_version() + +def main_version_callback(value: bool): + if value: + display_version() + raise typer.Exit() \ No newline at end of file diff --git a/cli/core/test/__init__.py b/cli/core/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/core/test/test.py b/cli/core/test/test.py new file mode 100644 index 00000000..2cd2215c --- /dev/null +++ b/cli/core/test/test.py @@ -0,0 +1,14 @@ +import typer +import subprocess +from core.config import is_development + +def test_command(target: str = typer.Argument(None, help="Test target (e.g., version)")): + if not is_development(): + typer.echo("Test command is only available in DEVELOPMENT environment.") + raise typer.Exit(1) + cmd = ["venv/bin/python", "-m", "pytest"] + if target: + cmd.append(f"tests/{target}.py") + typer.echo(f"Running: {' '.join(cmd)}") + result = subprocess.run(cmd) + raise typer.Exit(result.returncode) \ No newline at end of file diff --git a/cli/core/version.py b/cli/core/version/version.py similarity index 90% rename from cli/core/version.py rename to cli/core/version/version.py index c198ecbc..c775717a 100644 --- a/cli/core/version.py +++ b/cli/core/version/version.py @@ -10,7 +10,7 @@ def display_version(): cli_version = version('nixopus') version_text = Text() - version_text.append("NixOpus CLI", style="bold blue") + version_text.append("Nixopus CLI", style="bold blue") version_text.append(f" v{cli_version}", style="green") panel = Panel( diff --git a/cli/main.py b/cli/main.py index 778f7b35..08fc5d10 100644 --- a/cli/main.py +++ b/cli/main.py @@ -1,11 +1,13 @@ import typer -from commands.version import version_command, version_callback -from commands.test import test_command +from commands.version.command import version_app, main_version_callback +from commands.preflight.command import preflight_app +from commands.test.command import test_app +from utils.message import application_name, application_description, application_no_args_is_help, application_add_completion, application_version_help app = typer.Typer( - name="nixopus", - help="NixOpus CLI - A powerful deployment and management tool", - add_completion=False, + name=application_name, + help=application_description, + add_completion=application_add_completion, ) @app.callback() @@ -14,21 +16,15 @@ def main( None, "--version", "-v", - callback=version_callback, - help="Show version information" - ) + callback=main_version_callback, + help=application_version_help, + ) ): pass -@app.command() -def version(): - """Show version information""" - version_command() - -@app.command() -def test(target: str = typer.Argument(None, help="Test target (e.g., version)")): - """Run tests (only in DEVELOPMENT environment)""" - test_command(target) +app.add_typer(test_app, name="test") +app.add_typer(preflight_app, name="preflight") +app.add_typer(version_app, name="version") if __name__ == "__main__": app() diff --git a/cli/tests/test_commands_version.py b/cli/tests/test_commands_version.py index f1716d74..5781508b 100644 --- a/cli/tests/test_commands_version.py +++ b/cli/tests/test_commands_version.py @@ -1,96 +1,92 @@ import pytest from unittest.mock import patch, MagicMock -from commands.version import version_command, version_callback +from commands.version.command import version_callback, main_version_callback import typer class TestVersionCommand: - """Test cases for the version_command function""" + """Test cases for the main_version_callback function""" - @patch('commands.version.display_version') + @patch('commands.version.command.display_version') def test_version_command_calls_display_version(self, mock_display_version): - """Test that version_command calls display_version""" - version_command() + """Test that main_version_callback calls display_version""" + with pytest.raises(typer.Exit): + main_version_callback(True) mock_display_version.assert_called_once() - @patch('commands.version.display_version') + @patch('commands.version.command.display_version') def test_version_command_returns_none(self, mock_display_version): - """Test that version_command returns None""" - result = version_command() + """Test that main_version_callback exits after calling display_version""" + with pytest.raises(typer.Exit): + main_version_callback(True) - assert result is None mock_display_version.assert_called_once() class TestVersionCallback: """Test cases for the version_callback function""" - @patch('commands.version.version_command') - def test_version_callback_with_true_value(self, mock_version_command): - """Test version_callback with True value calls version_command and exits""" + @patch('commands.version.command.display_version') + def test_version_callback_with_true_value(self, mock_display_version): + """Test version_callback with True value calls display_version and exits""" with pytest.raises(typer.Exit): - version_callback(True) + main_version_callback(True) - mock_version_command.assert_called_once() + mock_display_version.assert_called_once() - @patch('commands.version.version_command') - def test_version_callback_with_false_value(self, mock_version_command): - """Test version_callback with False value does nothing""" - result = version_callback(False) + @patch('commands.version.command.display_version') + def test_version_callback_with_false_value(self, mock_display_version): + """Test main_version_callback with False value does nothing""" + main_version_callback(False) - assert result is None - mock_version_command.assert_not_called() + mock_display_version.assert_not_called() - @patch('commands.version.version_command') - def test_version_callback_with_none_value(self, mock_version_command): - """Test version_callback with None value does nothing""" - result = version_callback(None) + @patch('commands.version.command.display_version') + def test_version_callback_with_none_value(self, mock_display_version): + """Test main_version_callback with None value does nothing""" + main_version_callback(None) - assert result is None - mock_version_command.assert_not_called() + mock_display_version.assert_not_called() - @patch('commands.version.version_command') - def test_version_callback_exits_after_version_command(self, mock_version_command): - """Test that version_callback raises typer.Exit after calling version_command""" - mock_version_command.return_value = None + @patch('commands.version.command.display_version') + def test_version_callback_exits_after_version_command(self, mock_display_version): + """Test that main_version_callback raises typer.Exit after calling display_version""" + mock_display_version.return_value = None with pytest.raises(typer.Exit): - version_callback(True) + main_version_callback(True) - mock_version_command.assert_called_once() + mock_display_version.assert_called_once() - @patch('commands.version.version_command') - def test_version_callback_handles_version_command_exception(self, mock_version_command): - """Test that version_callback still exits even if version_command raises an exception""" - mock_version_command.side_effect = Exception("Version command error") + @patch('commands.version.command.display_version') + def test_version_callback_handles_version_command_exception(self, mock_display_version): + """Test that main_version_callback still exits even if display_version raises an exception""" + mock_display_version.side_effect = Exception("Display version error") - with pytest.raises(Exception, match="Version command error"): - version_callback(True) + with pytest.raises(Exception, match="Display version error"): + main_version_callback(True) - mock_version_command.assert_called_once() + mock_display_version.assert_called_once() class TestVersionCommandIntegration: """Integration test cases for version commands""" - @patch('commands.version.display_version') + @patch('commands.version.command.display_version') def test_version_command_integration(self, mock_display_version): - """Integration test for version_command calling display_version""" - version_command() + """Integration test for main_version_callback calling display_version""" + with pytest.raises(typer.Exit): + main_version_callback(True) mock_display_version.assert_called_once() - @patch('commands.version.version_command') - @patch('commands.version.display_version') - def test_version_callback_integration(self, mock_display_version, mock_version_command): - """Integration test for version_callback calling version_command""" - mock_version_command.side_effect = lambda: mock_display_version() - + @patch('commands.version.command.display_version') + def test_version_callback_integration(self, mock_display_version): + """Integration test for main_version_callback calling display_version""" with pytest.raises(typer.Exit): - version_callback(True) + main_version_callback(True) - mock_version_command.assert_called_once() mock_display_version.assert_called_once() @@ -98,23 +94,24 @@ class TestVersionFunctionSignatures: """Test cases for function signatures and behavior""" def test_version_command_is_callable(self): - """Test that version_command is a callable function""" - assert callable(version_command) + """Test that main_version_callback is a callable function""" + assert callable(main_version_callback) def test_version_callback_is_callable(self): """Test that version_callback is a callable function""" assert callable(version_callback) def test_version_command_no_parameters(self): - """Test that version_command takes no parameters""" + """Test that main_version_callback takes one parameter""" import inspect - sig = inspect.signature(version_command) - assert len(sig.parameters) == 0 + sig = inspect.signature(main_version_callback) + assert len(sig.parameters) == 1 + assert 'value' in sig.parameters + assert sig.parameters['value'].annotation == bool def test_version_callback_parameter(self): """Test that version_callback takes one parameter""" import inspect sig = inspect.signature(version_callback) assert len(sig.parameters) == 1 - assert 'value' in sig.parameters - assert sig.parameters['value'].annotation == bool \ No newline at end of file + assert 'ctx' in sig.parameters \ No newline at end of file diff --git a/cli/tests/version.py b/cli/tests/version.py index f5ec7b9b..b7d89fb6 100644 --- a/cli/tests/version.py +++ b/cli/tests/version.py @@ -1,14 +1,14 @@ import pytest from unittest.mock import patch, MagicMock from importlib.metadata import version -from core.version import display_version +from core.version.version import display_version class TestDisplayVersion: """Test cases for the display_version function""" - @patch('core.version.console') - @patch('core.version.version') + @patch('core.version.version.console') + @patch('core.version.version.version') def test_display_version_success(self, mock_version, mock_console): """Test successful version display""" mock_version.return_value = "1.0.0" @@ -23,8 +23,8 @@ def test_display_version_success(self, mock_version, mock_console): assert call_args.border_style == "blue" assert call_args.padding == (0, 1) - @patch('core.version.console') - @patch('core.version.version') + @patch('core.version.version.console') + @patch('core.version.version.version') def test_display_version_with_different_versions(self, mock_version, mock_console): """Test version display with different version numbers""" test_versions = ["0.1.0", "2.3.4", "1.0.0-beta"] @@ -38,8 +38,8 @@ def test_display_version_with_different_versions(self, mock_version, mock_consol mock_version.assert_called_with('nixopus') mock_console.print.assert_called_once() - @patch('core.version.console') - @patch('core.version.version') + @patch('core.version.version.console') + @patch('core.version.version.version') def test_display_version_panel_content(self, mock_version, mock_console): """Test that panel contains correct text content""" mock_version.return_value = "1.2.3" @@ -49,11 +49,11 @@ def test_display_version_panel_content(self, mock_version, mock_console): call_args = mock_console.print.call_args[0][0] panel_content = call_args.renderable - assert "NixOpus CLI" in str(panel_content) + assert "Nixopus CLI" in str(panel_content) assert "v1.2.3" in str(panel_content) - @patch('core.version.console') - @patch('core.version.version') + @patch('core.version.version.console') + @patch('core.version.version.version') def test_display_version_handles_version_error(self, mock_version, mock_console): """Test handling of version import error""" mock_version.side_effect = Exception("Version not found") @@ -63,8 +63,8 @@ def test_display_version_handles_version_error(self, mock_version, mock_console) mock_version.assert_called_once_with('nixopus') - @patch('core.version.console') - @patch('core.version.version') + @patch('core.version.version.console') + @patch('core.version.version.version') def test_display_version_console_error_handling(self, mock_version, mock_console): """Test handling of console print errors""" mock_version.return_value = "1.0.0" @@ -128,7 +128,7 @@ def test_display_version_no_parameters(self): def test_display_version_returns_none(self): """Test that display_version returns None""" - with patch('core.version.console'): - with patch('core.version.version', return_value="1.0.0"): + with patch('core.version.version.console'): + with patch('core.version.version.version', return_value="1.0.0"): result = display_version() assert result is None diff --git a/cli/utils/message.py b/cli/utils/message.py new file mode 100644 index 00000000..3361c618 --- /dev/null +++ b/cli/utils/message.py @@ -0,0 +1,6 @@ +# Global messages for the application +application_name = "nixopus" +application_description = "Nixopus CLI - A powerful deployment and management tool" +application_no_args_is_help = True +application_add_completion = False +application_version_help = "Show version information" \ No newline at end of file diff --git a/docs/cli/commands.md b/docs/cli/commands.md index 7ea7d95b..3c52d1d9 100644 --- a/docs/cli/commands.md +++ b/docs/cli/commands.md @@ -1,15 +1,16 @@ # CLI Commands Reference -This guide provides detailed documentation for all available NixOpus CLI commands. +This guide provides detailed documentation for all available Nixopus CLI commands. ## Command Overview -The NixOpus CLI provides essential commands for managing your NixOpus deployments: +The Nixopus CLI provides essential commands for managing your Nixopus deployments: | Command | Description | Usage | |---------|-------------|-------| | `version` | Display CLI version | `nixopus version` | | `test` | Run CLI tests | `nixopus test [target]` | +| `preflight` | Run system readiness checks | `nixopus preflight check` | ## Core Commands @@ -17,7 +18,7 @@ Core commands provide essential functionality for the CLI. ### `version` -Display the current version of the NixOpus CLI. +Display the current version of the Nixopus CLI. **Usage:** ```bash @@ -32,14 +33,36 @@ nixopus -v **Example Output:** ``` ┌───────────────── Version Info ─────────────────┐ -│ NixOpus CLI v0.1.0 │ +│ Nixopus CLI v0.1.0 │ └─────────────────────────────────────────────────┘ ``` **Aliases:** `-v`, `--version` **Description:** -The version command displays the current version of the NixOpus CLI using rich formatting. The version information is retrieved from the package metadata and displayed in a styled panel. +The version command displays the current version of the Nixopus CLI using rich formatting. The version information is retrieved from the package metadata and displayed in a styled panel. + +--- + +### `preflight` + +Run system readiness checks to ensure the environment is properly configured for Nixopus self-hosting. + +**Usage:** +```bash +nixopus preflight check +``` + +**Subcommands:** +- `check`: Run all preflight checks + +**Description:** +The preflight command performs system checks to ensure your environment is ready for Nixopus self-hosting. This includes verifying system requirements, dependencies, and configuration. + +**Example Output:** +``` +Running preflight checks... +``` --- @@ -96,6 +119,7 @@ nixopus --help # Command-specific help nixopus version --help nixopus test --help +nixopus preflight --help ``` ## Command Structure diff --git a/docs/cli/development.md b/docs/cli/development.md index 26c3a7ae..7a0dc203 100644 --- a/docs/cli/development.md +++ b/docs/cli/development.md @@ -9,15 +9,15 @@ cli/ ├── main.py # Main CLI entry point ├── pyproject.toml # Project configuration ├── commands/ # Command implementations -│ ├── version.py # Version command -│ └── test.py # Test command -├── core/ # Core functionality -│ ├── config.py # Configuration utilities -│ └── version.py # Version display logic -├── utils/ # Utility functions -└── tests/ # Test files - ├── test_commands_version.py - └── version.py +│ ├── version/ # Version command module +│ ├── test/ # Test command module +│ └── preflight/ # Preflight command module +├── core/ # Core functionality +│ ├── config.py # Configuration utilities +│ ├── version/ # Version display logic +│ └── test/ # Test functionality +├── utils/ # Utility functions +└── tests/ # Test files ``` ## Development Setup @@ -37,18 +37,32 @@ cli/ ## Adding New Commands -### Step 1: Create Command File +### Step 1: Create Command Module -Create a new file in the `commands/` directory: +Create a new directory in the `commands/` directory with the following structure: ```python -# commands/new_command.py +# commands/new_command/__init__.py +# Empty file to make it a module + +# commands/new_command/command.py import typer +from .messages import new_command_help + +new_command_app = typer.Typer( + help=new_command_help, + invoke_without_command=True +) -def new_command(): +@new_command_app.callback() +def new_command_callback(ctx: typer.Context): """Description of the new command""" - # Command implementation - pass + if ctx.invoked_subcommand is None: + # Main command logic here + pass + +# commands/new_command/messages.py +new_command_help = "Description of the new command" ``` ### Step 2: Register Command @@ -56,12 +70,9 @@ def new_command(): Import and register the command in `main.py`: ```python -from commands.new_command import new_command +from commands.new_command.command import new_command_app -@app.command() -def new(): - """Description of the new command""" - new_command() +app.add_typer(new_command_app, name="new-command") ``` ### Step 3: Add Tests @@ -69,7 +80,7 @@ def new(): Create corresponding test files in the `tests/` directory: ```python -# tests/test_commands_new.py +# tests/test_commands_new_command.py import pytest from typer.testing import CliRunner from cli.main import app @@ -77,7 +88,7 @@ from cli.main import app runner = CliRunner() def test_new_command(): - result = runner.invoke(app, ["new"]) + result = runner.invoke(app, ["new-command"]) assert result.exit_code == 0 ``` @@ -151,10 +162,12 @@ Follow these guidelines: ### Command Guidelines -1. **Descriptive names**: Use clear, action-oriented command names -2. **Help text**: Provide helpful descriptions for all commands -3. **Error handling**: Handle errors gracefully with clear messages -4. **Exit codes**: Return appropriate exit codes (0 for success, 1 for error) +1. **Use Typer apps**: Structure commands as Typer applications +2. **Separate messages**: Keep command messages in separate files +3. **Descriptive names**: Use clear, action-oriented command names +4. **Help text**: Provide helpful descriptions for all commands +5. **Error handling**: Handle errors gracefully with clear messages +6. **Exit codes**: Return appropriate exit codes (0 for success, 1 for error) ### Documentation Guidelines @@ -193,8 +206,8 @@ export ENV=DEVELOPMENT ``` 2. **Make changes** - - Add new command files - - Update main.py + - Add new command module with proper structure + - Update main.py to register the command - Add tests - Update documentation From 0196a65aa5a27684133687d44d9cc3431ee60639 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 9 Jul 2025 17:49:00 +0530 Subject: [PATCH 28/72] fix: add EOL --- cli/__init__.py | 2 +- cli/commands/__init__.py | 1 + cli/commands/preflight/__init__.py | 1 + cli/commands/preflight/command.py | 2 +- cli/commands/preflight/messages.py | 2 +- cli/commands/test.py | 14 -------------- cli/commands/test/__init__.py | 1 + cli/commands/test/command.py | 2 +- cli/commands/test/messages.py | 2 +- cli/commands/version/__init__.py | 1 + cli/commands/version/command.py | 2 +- cli/core/__init__.py | 1 + cli/core/config.py | 2 +- cli/core/test/__init__.py | 1 + cli/core/test/test.py | 2 +- cli/core/version/version.py | 2 +- cli/pyproject.toml | 4 ++-- cli/tests/__init__.py | 1 + cli/tests/test_commands_version.py | 2 +- cli/utils/__init__.py | 1 + cli/utils/message.py | 2 +- 21 files changed, 21 insertions(+), 27 deletions(-) delete mode 100644 cli/commands/test.py diff --git a/cli/__init__.py b/cli/__init__.py index 0519ecba..64647441 100644 --- a/cli/__init__.py +++ b/cli/__init__.py @@ -1 +1 @@ - \ No newline at end of file +# cli main module diff --git a/cli/commands/__init__.py b/cli/commands/__init__.py index e69de29b..0aac0e26 100644 --- a/cli/commands/__init__.py +++ b/cli/commands/__init__.py @@ -0,0 +1 @@ +# cli commands module diff --git a/cli/commands/preflight/__init__.py b/cli/commands/preflight/__init__.py index e69de29b..0209b0a0 100644 --- a/cli/commands/preflight/__init__.py +++ b/cli/commands/preflight/__init__.py @@ -0,0 +1 @@ +# cli commands preflight module diff --git a/cli/commands/preflight/command.py b/cli/commands/preflight/command.py index f2608a8e..df9d6e29 100644 --- a/cli/commands/preflight/command.py +++ b/cli/commands/preflight/command.py @@ -6,4 +6,4 @@ @preflight_app.command() def check(): """Run all preflight checks""" - typer.echo(running_preflight_checks) \ No newline at end of file + typer.echo(running_preflight_checks) diff --git a/cli/commands/preflight/messages.py b/cli/commands/preflight/messages.py index 4f6b39dd..a95fcc5d 100644 --- a/cli/commands/preflight/messages.py +++ b/cli/commands/preflight/messages.py @@ -1,2 +1,2 @@ preflight_check_app_help = "Checks to ensure the system is ready for nixopus self-hosting" -running_preflight_checks = "Running preflight checks..." \ No newline at end of file +running_preflight_checks = "Running preflight checks..." diff --git a/cli/commands/test.py b/cli/commands/test.py deleted file mode 100644 index f04894ae..00000000 --- a/cli/commands/test.py +++ /dev/null @@ -1,14 +0,0 @@ -import subprocess -import typer -from core.config import is_development - -def test_command(target: str = typer.Argument(None, help="Test target (e.g., version)")): - if not is_development(): - typer.echo("Test command is only available in DEVELOPMENT environment.") - raise typer.Exit(1) - cmd = ["venv/bin/python", "-m", "pytest"] - if target: - cmd.append(f"tests/{target}.py") - typer.echo(f"Running: {' '.join(cmd)}") - result = subprocess.run(cmd) - raise typer.Exit(result.returncode) \ No newline at end of file diff --git a/cli/commands/test/__init__.py b/cli/commands/test/__init__.py index e69de29b..13f8dbb2 100644 --- a/cli/commands/test/__init__.py +++ b/cli/commands/test/__init__.py @@ -0,0 +1 @@ +# cli commands test module diff --git a/cli/commands/test/command.py b/cli/commands/test/command.py index 3fd9cbe6..29df8096 100644 --- a/cli/commands/test/command.py +++ b/cli/commands/test/command.py @@ -11,4 +11,4 @@ def test_callback(ctx: typer.Context, target: str = typer.Argument(None, help="Test target (e.g., version)")): """Run tests (only in DEVELOPMENT environment)""" if ctx.invoked_subcommand is None: - test_command(target) \ No newline at end of file + test_command(target) diff --git a/cli/commands/test/messages.py b/cli/commands/test/messages.py index 66893af0..f4caa568 100644 --- a/cli/commands/test/messages.py +++ b/cli/commands/test/messages.py @@ -1 +1 @@ -test_app_help = "Run tests (only in DEVELOPMENT environment)" \ No newline at end of file +test_app_help = "Run tests (only in DEVELOPMENT environment)" diff --git a/cli/commands/version/__init__.py b/cli/commands/version/__init__.py index e69de29b..37cb5757 100644 --- a/cli/commands/version/__init__.py +++ b/cli/commands/version/__init__.py @@ -0,0 +1 @@ +# cli commands version module diff --git a/cli/commands/version/command.py b/cli/commands/version/command.py index be80fc13..83cc0211 100644 --- a/cli/commands/version/command.py +++ b/cli/commands/version/command.py @@ -16,4 +16,4 @@ def version_callback(ctx: typer.Context): def main_version_callback(value: bool): if value: display_version() - raise typer.Exit() \ No newline at end of file + raise typer.Exit() diff --git a/cli/core/__init__.py b/cli/core/__init__.py index e69de29b..92ca5160 100644 --- a/cli/core/__init__.py +++ b/cli/core/__init__.py @@ -0,0 +1 @@ +# cli core module diff --git a/cli/core/config.py b/cli/core/config.py index 359271cf..9152d192 100644 --- a/cli/core/config.py +++ b/cli/core/config.py @@ -4,4 +4,4 @@ def get_env(default="PRODUCTION"): return os.environ.get("ENV", default) def is_development(): - return get_env().upper() == "DEVELOPMENT" \ No newline at end of file + return get_env().upper() == "DEVELOPMENT" diff --git a/cli/core/test/__init__.py b/cli/core/test/__init__.py index e69de29b..26ebd1cc 100644 --- a/cli/core/test/__init__.py +++ b/cli/core/test/__init__.py @@ -0,0 +1 @@ +# cli core test module diff --git a/cli/core/test/test.py b/cli/core/test/test.py index 2cd2215c..6aa00cd9 100644 --- a/cli/core/test/test.py +++ b/cli/core/test/test.py @@ -11,4 +11,4 @@ def test_command(target: str = typer.Argument(None, help="Test target (e.g., ver cmd.append(f"tests/{target}.py") typer.echo(f"Running: {' '.join(cmd)}") result = subprocess.run(cmd) - raise typer.Exit(result.returncode) \ No newline at end of file + raise typer.Exit(result.returncode) diff --git a/cli/core/version/version.py b/cli/core/version/version.py index c775717a..df6af201 100644 --- a/cli/core/version/version.py +++ b/cli/core/version/version.py @@ -20,4 +20,4 @@ def display_version(): padding=(0, 1) ) - console.print(panel) \ No newline at end of file + console.print(panel) diff --git a/cli/pyproject.toml b/cli/pyproject.toml index 77a3e882..ebaa315b 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -7,7 +7,7 @@ name = "nixopus" version = "0.1.0" description = "A CLI for Nixopus" authors = [ - { name = "NixOpus", email = "raghavyuva@gmail.com" } + { name = "Nixopus", email = "raghavyuva@gmail.com" } ] dependencies = [ "typer>=0.9.0", @@ -31,4 +31,4 @@ testpaths = ["tests"] python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] -addopts = "-v --cov=core --cov=utils --cov-report=term-missing" \ No newline at end of file +addopts = "-v --cov=core --cov=utils --cov-report=term-missing" diff --git a/cli/tests/__init__.py b/cli/tests/__init__.py index e69de29b..c6c429dc 100644 --- a/cli/tests/__init__.py +++ b/cli/tests/__init__.py @@ -0,0 +1 @@ +# cli tests module diff --git a/cli/tests/test_commands_version.py b/cli/tests/test_commands_version.py index 5781508b..7b6f519e 100644 --- a/cli/tests/test_commands_version.py +++ b/cli/tests/test_commands_version.py @@ -114,4 +114,4 @@ def test_version_callback_parameter(self): import inspect sig = inspect.signature(version_callback) assert len(sig.parameters) == 1 - assert 'ctx' in sig.parameters \ No newline at end of file + assert 'ctx' in sig.parameters diff --git a/cli/utils/__init__.py b/cli/utils/__init__.py index e69de29b..78f19b1d 100644 --- a/cli/utils/__init__.py +++ b/cli/utils/__init__.py @@ -0,0 +1 @@ +# cli utils module diff --git a/cli/utils/message.py b/cli/utils/message.py index 3361c618..2c622f4e 100644 --- a/cli/utils/message.py +++ b/cli/utils/message.py @@ -3,4 +3,4 @@ application_description = "Nixopus CLI - A powerful deployment and management tool" application_no_args_is_help = True application_add_completion = False -application_version_help = "Show version information" \ No newline at end of file +application_version_help = "Show version information" From e28a4846a429ec551383122fa558a95d5518d6a0 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 9 Jul 2025 21:29:13 +0530 Subject: [PATCH 29/72] chore: address review comments --- .gitignore | 3 ++ cli/Makefile | 54 ++++++++++++++++++++++++++++++++ cli/pyproject.toml | 69 ++++++++++++++++++++++++++++------------- docs/cli/development.md | 46 +++++++++++++++++++++------ 4 files changed, 142 insertions(+), 30 deletions(-) create mode 100644 cli/Makefile diff --git a/.gitignore b/.gitignore index d3d3286e..98b16cb4 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ htmlcov/ .env.development.local .env.test.local .env.production.local + +# Poetry +poetry.lock diff --git a/cli/Makefile b/cli/Makefile new file mode 100644 index 00000000..c47bca80 --- /dev/null +++ b/cli/Makefile @@ -0,0 +1,54 @@ +.PHONY: help install install-dev test test-cov lint clean format check build publish dev run + +help: + @echo "Available commands:" + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +install: + poetry install + +install-dev: + poetry install --with dev + +test: + poetry run pytest + +test-cov: + poetry run pytest --cov=core --cov=utils --cov-report=term-missing --cov-report=html + +test-watch: + poetry run pytest-watch + +lint: + poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + +format: + poetry run black . + poetry run isort . + +check: + $(MAKE) lint + $(MAKE) test + +clean: + rm -rf build/ + rm -rf dist/ + rm -rf *.egg-info/ + rm -rf .pytest_cache/ + rm -rf htmlcov/ + rm -rf .coverage + find . -type d -name __pycache__ -delete + find . -type f -name "*.pyc" -delete + +build: + poetry build + +publish: + poetry publish + +dev: + poetry shell + +run: + poetry run nixopus \ No newline at end of file diff --git a/cli/pyproject.toml b/cli/pyproject.toml index ebaa315b..6a894e1d 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -1,30 +1,30 @@ -[build-system] -requires = ["setuptools", "wheel"] -build-backend = "setuptools.build_meta" - -[project] +[tool.poetry] name = "nixopus" version = "0.1.0" description = "A CLI for Nixopus" -authors = [ - { name = "Nixopus", email = "raghavyuva@gmail.com" } -] -dependencies = [ - "typer>=0.9.0", - "rich>=13.0.0" -] +authors = ["Nixopus "] +readme = "README.md" +packages = [{include = "cli"}] -[project.scripts] -nixopus = "cli.main:main" +[tool.poetry.dependencies] +python = "^3.9.0" +typer = "^0.16.0" +rich = "^14.0.0" + +[tool.poetry.group.dev.dependencies] +pytest = "^8.4.1" +pytest-cov = "^6.2.1" +pytest-watch = "^4.2.0" +flake8 = "^7.3.0" +black = "^25.1.0" +isort = "^6.0.1" -[project.optional-dependencies] -dev = [ - "pytest>=7.0.0", - "pytest-cov>=4.0.0" -] +[tool.poetry.scripts] +nixopus = "cli.main:main" -[tool.setuptools.packages.find] -where = ["."] +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] testpaths = ["tests"] @@ -32,3 +32,30 @@ python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] addopts = "-v --cov=core --cov=utils --cov-report=term-missing" + +[tool.black] +line-length = 127 +target-version = ['py38'] +include = '\.pyi?$' +extend-exclude = ''' +/( + # directories + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | build + | dist +)/ +''' + +[tool.isort] +profile = "black" +line_length = 127 +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true +ensure_newline_before_comments = true diff --git a/docs/cli/development.md b/docs/cli/development.md index 7a0dc203..86a29e3b 100644 --- a/docs/cli/development.md +++ b/docs/cli/development.md @@ -24,15 +24,20 @@ cli/ 1. **Clone and Install** ```bash - git clone https://github.com/your-org/nixopus.git + git clone https://github.com/raghavyuva/nixopus.git cd nixopus/cli - pip install -e ".[dev]" + make install ``` 2. **Verify Installation** ```bash - nixopus version - pytest + make version + make test + ``` + +3. **Available Commands** + ```bash + make help ``` ## Adding New Commands @@ -102,16 +107,19 @@ Add the command to the appropriate table in the [Commands Reference](commands.md ```bash # Run all tests -pytest +make test # Run with coverage -pytest --cov=core --cov=utils --cov-report=term-missing +make test-cov + +# Run tests in watch mode +make test-watch # Run specific test -pytest tests/test_commands_version.py +poetry run pytest tests/test_commands_version.py # Run with verbose output -pytest -v +poetry run pytest -v ``` ### Test Structure @@ -213,7 +221,7 @@ export ENV=DEVELOPMENT 3. **Run tests** ```bash - pytest + make test ``` 4. **Commit changes** @@ -224,6 +232,26 @@ export ENV=DEVELOPMENT 5. **Submit pull request** +## Makefile Commands + +The project includes a Makefile with common development tasks: + +```bash +make help +make install +make install-dev +make test +make test-cov +make test-watch +make lint +make format +make clean +make build +make publish +make dev +make run +``` + ## Testing Guidelines - Write tests for all new commands From 2b5c3733719fd87f757d37a35b7ad61e0d270bd4 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 9 Jul 2025 21:30:04 +0530 Subject: [PATCH 30/72] chore: add EOL to makefile --- cli/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/Makefile b/cli/Makefile index c47bca80..703c7cd4 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -51,4 +51,4 @@ dev: poetry shell run: - poetry run nixopus \ No newline at end of file + poetry run nixopus From 23e502ffa6b5ca32c52067199c4c98d0a6605f71 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 10 Jul 2025 13:19:35 +0530 Subject: [PATCH 31/72] feat: preflight checks for port availability --- cli/Makefile | 2 +- cli/commands/preflight/command.py | 38 ++++++++++- cli/commands/preflight/messages.py | 6 ++ cli/commands/preflight/port.py | 66 ++++++++++++++++++ cli/core/preflight/port.py | 11 +++ cli/pyproject.toml | 1 + cli/tests/port.py | 105 +++++++++++++++++++++++++++++ cli/utils/logger.py | 49 ++++++++++++++ cli/utils/message.py | 9 +++ 9 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 cli/commands/preflight/port.py create mode 100644 cli/core/preflight/port.py create mode 100644 cli/tests/port.py create mode 100644 cli/utils/logger.py diff --git a/cli/Makefile b/cli/Makefile index 703c7cd4..f6bc2373 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -8,7 +8,7 @@ install: poetry install install-dev: - poetry install --with dev + poetry install --with dev --no-root test: poetry run pytest diff --git a/cli/commands/preflight/command.py b/cli/commands/preflight/command.py index df9d6e29..dd9f7023 100644 --- a/cli/commands/preflight/command.py +++ b/cli/commands/preflight/command.py @@ -1,9 +1,41 @@ import typer from .messages import running_preflight_checks +from .port import PortConfig, PortCheckResult +from utils.logger import Logger -preflight_app = typer.Typer() +preflight_app = typer.Typer(no_args_is_help=False) + +@preflight_app.callback(invoke_without_command=True) +def preflight_callback(ctx: typer.Context): + """Preflight checks for system compatibility""" + if ctx.invoked_subcommand is None: + ctx.invoke(check) @preflight_app.command() -def check(): +def check( + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text,json"), +): """Run all preflight checks""" - typer.echo(running_preflight_checks) + logger = Logger(verbose=verbose) + logger.info(PortConfig.format(running_preflight_checks, output)) + +@preflight_app.command() +def ports( + ports: list[int] = typer.Argument(..., help="The list of ports to check"), + host: str = typer.Option("localhost", "--host", "-h", help="The host to check"), + timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each port check"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), +) -> list[PortCheckResult]: + """Check if list of ports are available on a host""" + try: + logger = Logger(verbose=verbose) + logger.debug(f"Checking ports: {ports}") + config = PortConfig(ports=ports, host=host, timeout=timeout, verbose=verbose) + results = PortConfig.check_ports(config) + logger.success(PortConfig.format(results, output)) + return results + except Exception as e: + logger.error(f"Error checking ports: {e}") + raise typer.Exit(1) diff --git a/cli/commands/preflight/messages.py b/cli/commands/preflight/messages.py index a95fcc5d..41820c4b 100644 --- a/cli/commands/preflight/messages.py +++ b/cli/commands/preflight/messages.py @@ -1,2 +1,8 @@ preflight_check_app_help = "Checks to ensure the system is ready for nixopus self-hosting" running_preflight_checks = "Running preflight checks..." +check_ports = "Checking if ports are available..." +ports_list_contains_less_than_1_port = "Ports list contains less than 1 port" +ports_list_contains_values_outside_range_1_65535 = "Ports list contains values outside the range 1-65535" +ports_list_contains_non_integer_values = "Ports list contains non-integer values" +available = "available" +not_available = "not available" diff --git a/cli/commands/preflight/port.py b/cli/commands/preflight/port.py new file mode 100644 index 00000000..542e2f7c --- /dev/null +++ b/cli/commands/preflight/port.py @@ -0,0 +1,66 @@ +import re, json +from typing import List, TypedDict, Union, Any +from pydantic import BaseModel, Field, field_validator +from .messages import available, not_available +from core.preflight.port import is_port_available +from utils.logger import Logger + +class PortCheckResult(TypedDict): + port: int + status: str + host: str | None + error: str | None + is_available: bool + +class PortConfig(BaseModel): + ports: List[int] = Field(..., min_length=1, max_length=65535, description="List of ports to check") + host: str = Field("localhost", min_length=1, description="Host to check") + timeout: int = Field(1, gt=0, le=60, description="Timeout in seconds") + verbose: bool = Field(False, description="Verbose output") + + @field_validator('host') + @classmethod + def validate_host(cls, v: str) -> str: + """Validate host is localhost, valid IP address, or domain name""" + if v.lower() == "localhost": + return v + + # IP address validation regex + ip_pattern = r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' + if re.match(ip_pattern, v): + return v + + # Domain name validation regex + domain_pattern = r'^[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*$' + if re.match(domain_pattern, v): + return v + + raise ValueError("Host must be 'localhost', a valid IP address, or a valid domain name") + + @staticmethod + def format(data: Union[str, List[PortCheckResult], Any], output_type: str) -> str: + """Format output based on output type""" + if output_type == "json": + return json.dumps(data, indent=4) + elif output_type == "text" and isinstance(data, list): + return "\n".join([f"Port {item['port']}: {item['status']}" for item in data]) + else: + return str(data) + + @staticmethod + def check_ports(config: "PortConfig") -> List[PortCheckResult]: + """Check if ports are available""" + logger = Logger(verbose=config.verbose) + results = [] + for port in config.ports: + logger.debug(f"Checking port {port} on host {config.host}") + status = available if is_port_available(config.host, port, config.timeout) else not_available + result = { + "port": port, + "status": status, + "host": config.host if config.verbose else None, + "error": None, + "is_available": status == available + } + results.append(result) + return results diff --git a/cli/core/preflight/port.py b/cli/core/preflight/port.py new file mode 100644 index 00000000..fb3ad84d --- /dev/null +++ b/cli/core/preflight/port.py @@ -0,0 +1,11 @@ +import socket + +def is_port_available(host: str, port: int, timeout: int = 1) -> bool: + """Check if a port is available on the specified host""" + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + sock.settimeout(timeout) + result = sock.connect_ex((host, port)) + return result != 0 + except Exception: + return False \ No newline at end of file diff --git a/cli/pyproject.toml b/cli/pyproject.toml index 6a894e1d..e83c8686 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -10,6 +10,7 @@ packages = [{include = "cli"}] python = "^3.9.0" typer = "^0.16.0" rich = "^14.0.0" +pydantic = "^2.0.0" [tool.poetry.group.dev.dependencies] pytest = "^8.4.1" diff --git a/cli/tests/port.py b/cli/tests/port.py new file mode 100644 index 00000000..a7035018 --- /dev/null +++ b/cli/tests/port.py @@ -0,0 +1,105 @@ +import pytest +from typing import List +from cli.commands.preflight.port import PortConfig, PortCheckResult + +class TestPort: + def test_valid_ports(self): + ports = [80, 443, 8080] + config = PortConfig(ports=ports) + assert config.ports == [80, 443, 8080] + + def test_empty_ports_list(self): + with pytest.raises(ValueError): + PortConfig(ports=[]) + + def test_valid_host_localhost(self): + config = PortConfig(ports=[80], host="localhost") + assert config.host == "localhost" + + def test_valid_host_ipv4(self): + config = PortConfig(ports=[80], host="192.168.1.1") + assert config.host == "192.168.1.1" + + def test_valid_host_ipv4_loopback(self): + config = PortConfig(ports=[80], host="127.0.0.1") + assert config.host == "127.0.0.1" + + def test_valid_host_domain(self): + config = PortConfig(ports=[80], host="example.com") + assert config.host == "example.com" + + def test_valid_host_subdomain(self): + config = PortConfig(ports=[80], host="api.example.com") + assert config.host == "api.example.com" + + def test_valid_host_domain_with_hyphens(self): + config = PortConfig(ports=[80], host="my-domain.com") + assert config.host == "my-domain.com" + + def test_invalid_host_invalid_ip(self): + with pytest.raises(ValueError, match="Host must be 'localhost', a valid IP address, or a valid domain name"): + PortConfig(ports=[80], host="256.256.256.256") + + def test_invalid_host_empty(self): + with pytest.raises(ValueError): + PortConfig(ports=[80], host="") + + def test_invalid_host_invalid_domain(self): + with pytest.raises(ValueError, match="Host must be 'localhost', a valid IP address, or a valid domain name"): + PortConfig(ports=[80], host="invalid..domain") + + def test_check_ports_basic(self): + config = PortConfig(ports=[80, 443], host="localhost", timeout=1, verbose=False) + results = PortConfig.check_ports(config) + assert len(results) == 2 + assert all("port" in result for result in results) + assert all("status" in result for result in results) + assert all(result["host"] is None for result in results) + assert all(result["error"] is None for result in results) + assert all(result["is_available"] is True for result in results) + + def test_check_ports_verbose(self): + config = PortConfig(ports=[80, 443], host="localhost", timeout=1, verbose=True) + results = PortConfig.check_ports(config) + assert len(results) == 2 + assert all("port" in result for result in results) + assert all("status" in result for result in results) + assert all("host" in result for result in results) + assert all(result["host"] == "localhost" for result in results) + assert all(result["error"] is None for result in results) + assert all(result["is_available"] is True for result in results) + +def test_port_check_result_type(): + """Test that PortCheckResult has correct structure""" + result: PortCheckResult = { + "port": 8080, + "status": "available", + "host": "localhost", + "error": None, + "is_available": True + } + + assert isinstance(result["port"], int) + assert isinstance(result["status"], str) + assert isinstance(result["host"], str) or result["host"] is None + assert isinstance(result["error"], str) or result["error"] is None + assert isinstance(result["is_available"], bool) + +def test_check_ports_return_type(): + """Test that check_ports returns correct type""" + config = PortConfig(ports=[8080, 3000], host="localhost", timeout=1, verbose=False) + results: List[PortCheckResult] = PortConfig.check_ports(config) + + assert isinstance(results, list) + for result in results: + assert isinstance(result, dict) + assert "port" in result + assert "status" in result + assert "host" in result + assert "error" in result + assert "is_available" in result + assert isinstance(result["port"], int) + assert isinstance(result["status"], str) + assert isinstance(result["host"], str) or result["host"] is None + assert isinstance(result["error"], str) or result["error"] is None + assert isinstance(result["is_available"], bool) diff --git a/cli/utils/logger.py b/cli/utils/logger.py new file mode 100644 index 00000000..5f3c2f45 --- /dev/null +++ b/cli/utils/logger.py @@ -0,0 +1,49 @@ +import typer +from .message import INFO_MESSAGE, DEBUG_MESSAGE, WARNING_MESSAGE, ERROR_MESSAGE, SUCCESS_MESSAGE, HIGHLIGHT_MESSAGE + +class Logger: + """Wrapper for typer.secho to log messages to the console""" + + def __init__(self, verbose: bool = False, quiet: bool = False): + if verbose and quiet: + raise ValueError("Cannot have both verbose and quiet options enabled") + self.verbose = verbose + self.quiet = quiet + + def _should_print(self, require_verbose: bool = False) -> bool: + """Helper method to determine if message should be printed""" + if self.quiet: + return False + if require_verbose and not self.verbose: + return False + return True + + def info(self, message: str) -> None: + """Prints an info message""" + if self._should_print(): + typer.secho(INFO_MESSAGE.format(message=message), fg=typer.colors.BLUE) + + def debug(self, message: str) -> None: + """Prints a debug message if verbose is enabled""" + if self._should_print(require_verbose=True): + typer.secho(DEBUG_MESSAGE.format(message=message), fg=typer.colors.CYAN) + + def warning(self, message: str) -> None: + """Prints a warning message""" + if self._should_print(): + typer.secho(WARNING_MESSAGE.format(message=message), fg=typer.colors.YELLOW) + + def error(self, message: str) -> None: + """Prints an error message""" + if self._should_print(): + typer.secho(ERROR_MESSAGE.format(message=message), fg=typer.colors.RED) + + def success(self, message: str) -> None: + """Prints a success message""" + if self._should_print(): + typer.secho(SUCCESS_MESSAGE.format(message=message), fg=typer.colors.GREEN) + + def highlight(self, message: str) -> None: + """Prints a highlighted message""" + if self._should_print(): + typer.secho(HIGHLIGHT_MESSAGE.format(message=message), fg=typer.colors.MAGENTA) \ No newline at end of file diff --git a/cli/utils/message.py b/cli/utils/message.py index 2c622f4e..d5ccacd1 100644 --- a/cli/utils/message.py +++ b/cli/utils/message.py @@ -1,6 +1,15 @@ # Global messages for the application + +# Application application_name = "nixopus" application_description = "Nixopus CLI - A powerful deployment and management tool" application_no_args_is_help = True application_add_completion = False application_version_help = "Show version information" + +INFO_MESSAGE = "INFO: {message}" +DEBUG_MESSAGE = "DEBUG: {message}" +WARNING_MESSAGE = "WARNING: {message}" +ERROR_MESSAGE = "ERROR: {message}" +SUCCESS_MESSAGE = "SUCCESS: {message}" +HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" \ No newline at end of file From 5a525b0e8336795222436bf685143bf93ae638db Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 10 Jul 2025 15:01:08 +0530 Subject: [PATCH 32/72] fix: parallel process port checking --- cli/commands/preflight/messages.py | 2 ++ cli/commands/preflight/port.py | 34 ++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cli/commands/preflight/messages.py b/cli/commands/preflight/messages.py index 41820c4b..fc7f2e26 100644 --- a/cli/commands/preflight/messages.py +++ b/cli/commands/preflight/messages.py @@ -6,3 +6,5 @@ ports_list_contains_non_integer_values = "Ports list contains non-integer values" available = "available" not_available = "not available" +error_checking_port = "Error checking port {port}: {error}" +host_must_be_localhost_or_valid_ip_or_domain = "Host must be 'localhost', a valid IP address, or a valid domain name" \ No newline at end of file diff --git a/cli/commands/preflight/port.py b/cli/commands/preflight/port.py index 542e2f7c..b4ec3c9c 100644 --- a/cli/commands/preflight/port.py +++ b/cli/commands/preflight/port.py @@ -1,7 +1,8 @@ import re, json from typing import List, TypedDict, Union, Any +from concurrent.futures import ThreadPoolExecutor, as_completed from pydantic import BaseModel, Field, field_validator -from .messages import available, not_available +from .messages import available, not_available, error_checking_port, host_must_be_localhost_or_valid_ip_or_domain from core.preflight.port import is_port_available from utils.logger import Logger @@ -35,7 +36,7 @@ def validate_host(cls, v: str) -> str: if re.match(domain_pattern, v): return v - raise ValueError("Host must be 'localhost', a valid IP address, or a valid domain name") + raise ValueError(host_must_be_localhost_or_valid_ip_or_domain) @staticmethod def format(data: Union[str, List[PortCheckResult], Any], output_type: str) -> str: @@ -52,15 +53,36 @@ def check_ports(config: "PortConfig") -> List[PortCheckResult]: """Check if ports are available""" logger = Logger(verbose=config.verbose) results = [] - for port in config.ports: + + def check_single_port(port: int) -> PortCheckResult: + """Check availability of a single port""" logger.debug(f"Checking port {port} on host {config.host}") status = available if is_port_available(config.host, port, config.timeout) else not_available - result = { + return { "port": port, "status": status, "host": config.host if config.verbose else None, "error": None, "is_available": status == available } - results.append(result) - return results + + max_workers = min(len(config.ports), 50) + with ThreadPoolExecutor(max_workers=max_workers) as executor: + port_futures = {executor.submit(check_single_port, port): port for port in config.ports} + + for future in as_completed(port_futures): + try: + result = future.result() + results.append(result) + except Exception as e: + port = port_futures[future] + logger.error(error_checking_port.format(port=port, error=str(e))) + results.append({ + "port": port, + "status": not_available, + "host": config.host if config.verbose else None, + "error": str(e), + "is_available": False + }) + + return sorted(results, key=lambda x: x["port"]) From a4810cebfc7a43623ce7739b4e2f12131736e08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Sun, 13 Jul 2025 14:41:08 +0530 Subject: [PATCH 33/72] test-cases: E2E for `deploy` flow (#275) --- api/api/versions.json | 2 +- .../features/auth/service/register.go | 5 + api/internal/features/auth/storage/user.go | 42 ++++ api/internal/features/auth/types/auth.go | 1 + .../tests/deploy/create_application_test.go | 216 ++++++++++++++++++ .../tests/deploy/delete_application_test.go | 103 +++++++++ .../get_application_deployments_test.go | 126 ++++++++++ .../tests/deploy/get_application_logs_test.go | 128 +++++++++++ .../tests/deploy/get_application_test.go | 98 ++++++++ .../tests/deploy/get_applications_test.go | 133 +++++++++++ .../tests/deploy/get_deployment_by_id_test.go | 128 +++++++++++ .../tests/deploy/get_deployment_logs_test.go | 128 +++++++++++ .../tests/deploy/redeploy_application_test.go | 130 +++++++++++ .../tests/deploy/restart_application_test.go | 103 +++++++++ .../tests/deploy/rollback_application_test.go | 103 +++++++++ .../tests/deploy/update_application_test.go | 141 ++++++++++++ api/internal/tests/helper.go | 36 +++ 17 files changed, 1622 insertions(+), 1 deletion(-) create mode 100644 api/internal/tests/deploy/create_application_test.go create mode 100644 api/internal/tests/deploy/delete_application_test.go create mode 100644 api/internal/tests/deploy/get_application_deployments_test.go create mode 100644 api/internal/tests/deploy/get_application_logs_test.go create mode 100644 api/internal/tests/deploy/get_application_test.go create mode 100644 api/internal/tests/deploy/get_applications_test.go create mode 100644 api/internal/tests/deploy/get_deployment_by_id_test.go create mode 100644 api/internal/tests/deploy/get_deployment_logs_test.go create mode 100644 api/internal/tests/deploy/redeploy_application_test.go create mode 100644 api/internal/tests/deploy/restart_application_test.go create mode 100644 api/internal/tests/deploy/rollback_application_test.go create mode 100644 api/internal/tests/deploy/update_application_test.go diff --git a/api/api/versions.json b/api/api/versions.json index 22f4b10f..c9a8d8a6 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-07-05T21:25:27.672646+05:30", + "release_date": "2025-07-10T02:54:43.011943+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/api/internal/features/auth/service/register.go b/api/internal/features/auth/service/register.go index 14670b26..21e00727 100644 --- a/api/internal/features/auth/service/register.go +++ b/api/internal/features/auth/service/register.go @@ -29,6 +29,11 @@ func (c *AuthService) Register(registrationRequest types.RegisterRequest, userTy return types.AuthResponse{}, types.ErrUserWithEmailAlreadyExists } + if dbUser, err := c.storage.FindUserByUsername(registrationRequest.Username); err == nil && dbUser.ID != uuid.Nil { + c.logger.Log(logger.Error, types.ErrUserWithUsernameAlreadyExists.Error(), "") + return types.AuthResponse{}, types.ErrUserWithUsernameAlreadyExists + } + hashedPassword, err := utils.HashPassword(registrationRequest.Password) if err != nil { c.logger.Log(logger.Error, types.ErrFailedToHashPassword.Error(), err.Error()) diff --git a/api/internal/features/auth/storage/user.go b/api/internal/features/auth/storage/user.go index 9e6403e6..4f348790 100644 --- a/api/internal/features/auth/storage/user.go +++ b/api/internal/features/auth/storage/user.go @@ -22,6 +22,7 @@ type UserStorage struct { type AuthRepository interface { FindUserByEmail(email string) (*types.User, error) + FindUserByUsername(username string) (*types.User, error) FindUserByID(id string) (*types.User, error) CreateUser(user *types.User) error UpdateUser(user *types.User) error @@ -94,6 +95,47 @@ func (u *UserStorage) FindUserByEmail(email string) (*types.User, error) { return user, nil } +// FindUserByUsername finds a user by username in the database. +// +// The function returns an error if the user does not exist or if the query +// fails. +func (u *UserStorage) FindUserByUsername(username string) (*types.User, error) { + user := &types.User{} + err := u.getDB().NewSelect(). + Model(user). + Where("username = ?", username). + Relation("Organizations"). + Scan(u.Ctx) + if err != nil { + return nil, err + } + + err = u.getDB().NewSelect(). + Model(&user.OrganizationUsers). + Where("user_id = ?", user.ID). + Relation("Role"). + Relation("Organization"). + Scan(u.Ctx) + if err != nil { + return nil, err + } + + for i, orgUser := range user.OrganizationUsers { + if orgUser.Role != nil { + err = u.getDB().NewSelect(). + Model(&user.OrganizationUsers[i].Role.Permissions). + Join("JOIN role_permissions AS rp ON rp.permission_id = p.id"). + Where("rp.role_id = ?", orgUser.Role.ID). + Scan(u.Ctx) + if err != nil { + return nil, err + } + } + } + + return user, nil +} + // FindUserByID finds a user by id in the database. // // The function returns an error if the user does not exist or if the query diff --git a/api/internal/features/auth/types/auth.go b/api/internal/features/auth/types/auth.go index 26ab3afe..2b6817e0 100644 --- a/api/internal/features/auth/types/auth.go +++ b/api/internal/features/auth/types/auth.go @@ -85,6 +85,7 @@ var ( ErrFailedToDecodeRequest = errors.New("failed to decode request body") ErrMissingRequiredFields = errors.New("missing required fields") ErrUserWithEmailAlreadyExists = errors.New("user with email already exists") + ErrUserWithUsernameAlreadyExists = errors.New("user with username already exists") ErrFailedToRegisterUser = errors.New("failed to register user") ErrFailedToHashPassword = errors.New("failed to hash password") ErrFailedToCreateToken = errors.New("failed to create token") diff --git a/api/internal/tests/deploy/create_application_test.go b/api/internal/tests/deploy/create_application_test.go new file mode 100644 index 00000000..ee2cf82a --- /dev/null +++ b/api/internal/tests/deploy/create_application_test.go @@ -0,0 +1,216 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/features/deploy/types" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" + shared_types "github.com/raghavyuva/nixopus-api/internal/types" +) + +func TestCreateApplication(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + request types.CreateDeploymentRequest + expectedStatus int + description string + }{ + { + name: "Successfully create application with valid data", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + BuildVariables: map[string]string{ + "NODE_ENV": "development", + }, + EnvironmentVariables: map[string]string{ + "PORT": "3000", + }, + }, + expectedStatus: http.StatusOK, // API returns 200 not 201 + description: "Should create application successfully with valid data", + }, + { + name: "Create application without authentication", + token: "", + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Create application with invalid token", + token: "invalid-token", + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Create application without organization header", + token: user.AccessToken, + organizationID: "", + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Create application with missing name", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when name is missing", + }, + { + name: "Create application with missing domain", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when domain is missing", + }, + { + name: "Create application with missing repository", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when repository is missing", + }, + { + name: "Create application with missing port", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when port is missing", + }, + { + name: "Create application with invalid environment", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: "invalid", + BuildPack: shared_types.DockerFile, + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusInternalServerError, // API returns 500 for invalid enum values + description: "Should return 500 when environment is invalid", + }, + { + name: "Create application with invalid build pack", + token: user.AccessToken, + organizationID: orgID, + request: types.CreateDeploymentRequest{ + Name: "test-app", + Domain: "test-app.example.com", + Environment: shared_types.Development, + BuildPack: "invalid", + Repository: "https://github.com/test/test-app.git", + Branch: "main", + Port: 3000, + }, + expectedStatus: http.StatusInternalServerError, // API returns 500 for invalid enum values + description: "Should return 500 when build pack is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetDeployApplicationURL()), + Send().Body().JSON(tc.request), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/deploy/delete_application_test.go b/api/internal/tests/deploy/delete_application_test.go new file mode 100644 index 00000000..a250294a --- /dev/null +++ b/api/internal/tests/deploy/delete_application_test.go @@ -0,0 +1,103 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/google/uuid" + "github.com/raghavyuva/nixopus-api/internal/features/deploy/types" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestDeleteApplication(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := uuid.New() + + testCases := []struct { + name string + token string + organizationID string + request types.DeleteDeploymentRequest + expectedStatus int + description string + }{ + { + name: "Delete application without authentication", + token: "", + organizationID: orgID, + request: types.DeleteDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Delete application with invalid token", + token: "invalid-token", + organizationID: orgID, + request: types.DeleteDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Delete application without organization header", + token: user.AccessToken, + organizationID: "", + request: types.DeleteDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Delete application with missing ID", + token: user.AccessToken, + organizationID: orgID, + request: types.DeleteDeploymentRequest{}, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application ID is missing", + }, + { + name: "Delete application that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + request: types.DeleteDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application doesn't exist", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Delete(tests.GetDeployApplicationURL()), + Send().Body().JSON(tc.request), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/deploy/get_application_deployments_test.go b/api/internal/tests/deploy/get_application_deployments_test.go new file mode 100644 index 00000000..fff441ad --- /dev/null +++ b/api/internal/tests/deploy/get_application_deployments_test.go @@ -0,0 +1,126 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetApplicationDeployments(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + applicationID string + expectedStatus int + description string + }{ + { + name: "Get application deployments without authentication", + token: "", + organizationID: orgID, + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Get application deployments with invalid token", + token: "invalid-token", + organizationID: orgID, + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Get application deployments without organization header", + token: user.AccessToken, + organizationID: "", + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Get application deployments with invalid application ID", + token: user.AccessToken, + organizationID: orgID, + applicationID: "invalid-uuid", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application ID format is invalid", + }, + { + name: "Get application deployments for non-existent application", + token: user.AccessToken, + organizationID: orgID, + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application doesn't exist", + }, + { + name: "Get application deployments with missing application ID", + token: user.AccessToken, + organizationID: orgID, + applicationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application ID is missing", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + var url string + if tc.applicationID != "" { + url = tests.GetDeployApplicationDeploymentsURL() + "?application_id=" + tc.applicationID + } else { + url = tests.GetDeployApplicationDeploymentsURL() + } + + testSteps := []IStep{ + Description(tc.description), + Get(url), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} + +func TestGetApplicationDeploymentsSuccess(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Get deployments with valid application ID should return structure", func(t *testing.T) { + Test(t, + Description("Should return deployments structure even if empty"), + Get(tests.GetDeployApplicationDeploymentsURL()+"?application_id=123e4567-e89b-12d3-a456-426614174000"), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().OneOf(http.StatusOK, http.StatusBadRequest), // Either OK with empty list or 400 if app doesn't exist + ) + }) +} diff --git a/api/internal/tests/deploy/get_application_logs_test.go b/api/internal/tests/deploy/get_application_logs_test.go new file mode 100644 index 00000000..337e670f --- /dev/null +++ b/api/internal/tests/deploy/get_application_logs_test.go @@ -0,0 +1,128 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetApplicationLogs(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := "123e4567-e89b-12d3-a456-426614174000" + + testCases := []struct { + name string + token string + organizationID string + applicationID string + expectedStatus int + description string + }{ + { + name: "Get application logs without authentication", + token: "", + organizationID: orgID, + applicationID: testApplicationID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Get application logs with invalid token", + token: "invalid-token", + organizationID: orgID, + applicationID: testApplicationID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Get application logs without organization header", + token: user.AccessToken, + organizationID: "", + applicationID: testApplicationID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Get application logs with invalid application ID format", + token: user.AccessToken, + organizationID: orgID, + applicationID: "invalid-uuid", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application ID format is invalid", + }, + { + name: "Get application logs for non-existent application", + token: user.AccessToken, + organizationID: orgID, + applicationID: testApplicationID, + expectedStatus: http.StatusOK, + description: "Should return 200 with empty logs when application doesn't exist", + }, + { + name: "Get application logs with empty application ID", + token: user.AccessToken, + organizationID: orgID, + applicationID: "", + expectedStatus: http.StatusNotFound, + description: "Should return 404 when application ID is empty", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + var url string + if tc.applicationID != "" { + url = tests.GetDeployApplicationLogsURL(tc.applicationID) + } else { + url = tests.GetDeployApplicationLogsURL("") // This will result in malformed URL + } + + testSteps := []IStep{ + Description(tc.description), + Get(url), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} + +func TestGetApplicationLogsSuccess(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := "123e4567-e89b-12d3-a456-426614174000" + + t.Run("Get application logs with valid format", func(t *testing.T) { + Test(t, + Description("Should attempt to fetch application logs with valid UUID format"), + Get(tests.GetDeployApplicationLogsURL(testApplicationID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().OneOf(http.StatusOK, http.StatusNotFound), // Either OK with logs or 404 if application doesn't exist + ) + }) +} diff --git a/api/internal/tests/deploy/get_application_test.go b/api/internal/tests/deploy/get_application_test.go new file mode 100644 index 00000000..3001a0a0 --- /dev/null +++ b/api/internal/tests/deploy/get_application_test.go @@ -0,0 +1,98 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetApplicationByID(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + applicationID string + expectedStatus int + description string + }{ + { + name: "Get application by ID without authentication", + token: "", + organizationID: orgID, + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Get application by ID with invalid token", + token: "invalid-token", + organizationID: orgID, + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Get application by ID without organization header", + token: user.AccessToken, + organizationID: "", + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Get application by ID with invalid application ID", + token: user.AccessToken, + organizationID: orgID, + applicationID: "invalid-uuid", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application ID format is invalid", + }, + { + name: "Get application by ID that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + applicationID: "123e4567-e89b-12d3-a456-426614174000", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application doesn't exist", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + var url string + if tc.applicationID != "" { + url = tests.GetDeployApplicationURL() + "?id=" + tc.applicationID + } else { + url = tests.GetDeployApplicationURL() + } + + testSteps := []IStep{ + Description(tc.description), + Get(url), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/deploy/get_applications_test.go b/api/internal/tests/deploy/get_applications_test.go new file mode 100644 index 00000000..14710176 --- /dev/null +++ b/api/internal/tests/deploy/get_applications_test.go @@ -0,0 +1,133 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetApplications(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + testCases := []struct { + name string + token string + organizationID string + expectedStatus int + description string + }{ + { + name: "Successfully fetch applications with valid token", + token: user.AccessToken, + organizationID: orgID, + expectedStatus: http.StatusOK, + description: "Should return applications list with valid authentication", + }, + { + name: "Get applications without authentication", + token: "", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Get applications with invalid token", + token: "invalid-token", + organizationID: orgID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Get applications without organization header", + token: user.AccessToken, + organizationID: "", + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Get applications with invalid organization ID", + token: user.AccessToken, + organizationID: "invalid-org-id", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when organization ID format is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Get(tests.GetDeployApplicationsURL()), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + if tc.expectedStatus == http.StatusOK { + testSteps = append(testSteps, + Expect().Body().JSON().JQ(".status").Equal("success"), + Expect().Body().JSON().JQ(".message").Equal("Applications"), // API returns "Applications" not "Applications fetched successfully" + Expect().Body().JSON().JQ(".data").NotEqual(nil), + ) + } + + Test(t, testSteps...) + }) + } +} + +func TestGetApplicationsErrorHandling(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + + t.Run("Malformed authorization header", func(t *testing.T) { + Test(t, + Description("Should handle malformed authorization header gracefully"), + Get(tests.GetDeployApplicationsURL()), + Send().Headers("Authorization").Add("InvalidFormat"), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Empty authorization header", func(t *testing.T) { + Test(t, + Description("Should handle empty authorization header"), + Get(tests.GetDeployApplicationsURL()), + Send().Headers("Authorization").Add(""), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().Equal(http.StatusUnauthorized), + ) + }) + + t.Run("Bearer token with extra spaces", func(t *testing.T) { + Test(t, + Description("Should handle get applications base case"), + Get(tests.GetDeployApplicationsURL()), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().Equal(http.StatusOK), + ) + }) +} diff --git a/api/internal/tests/deploy/get_deployment_by_id_test.go b/api/internal/tests/deploy/get_deployment_by_id_test.go new file mode 100644 index 00000000..0be2d6a6 --- /dev/null +++ b/api/internal/tests/deploy/get_deployment_by_id_test.go @@ -0,0 +1,128 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetDeploymentByID(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testDeploymentID := "123e4567-e89b-12d3-a456-426614174000" + + testCases := []struct { + name string + token string + organizationID string + deploymentID string + expectedStatus int + description string + }{ + { + name: "Get deployment by ID without authentication", + token: "", + organizationID: orgID, + deploymentID: testDeploymentID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Get deployment by ID with invalid token", + token: "invalid-token", + organizationID: orgID, + deploymentID: testDeploymentID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Get deployment by ID without organization header", + token: user.AccessToken, + organizationID: "", + deploymentID: testDeploymentID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Get deployment by ID with invalid deployment ID format", + token: user.AccessToken, + organizationID: orgID, + deploymentID: "invalid-uuid", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when deployment ID format is invalid", + }, + { + name: "Get deployment by ID that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + deploymentID: testDeploymentID, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when deployment doesn't exist", + }, + { + name: "Get deployment by ID with empty deployment ID", + token: user.AccessToken, + organizationID: orgID, + deploymentID: "", + expectedStatus: http.StatusNotFound, + description: "Should return 404 when deployment ID is empty", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + var url string + if tc.deploymentID != "" { + url = tests.GetDeployApplicationDeploymentByIDURL(tc.deploymentID) + } else { + url = tests.GetDeployApplicationDeploymentByIDURL("") // This will result in malformed URL + } + + testSteps := []IStep{ + Description(tc.description), + Get(url), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} + +func TestGetDeploymentByIDSuccess(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testDeploymentID := "123e4567-e89b-12d3-a456-426614174000" + + t.Run("Get deployment by valid ID format", func(t *testing.T) { + Test(t, + Description("Should attempt to fetch deployment with valid UUID format"), + Get(tests.GetDeployApplicationDeploymentByIDURL(testDeploymentID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().OneOf(http.StatusOK, http.StatusInternalServerError), // Either OK if exists or 500 if not + ) + }) +} diff --git a/api/internal/tests/deploy/get_deployment_logs_test.go b/api/internal/tests/deploy/get_deployment_logs_test.go new file mode 100644 index 00000000..bae50224 --- /dev/null +++ b/api/internal/tests/deploy/get_deployment_logs_test.go @@ -0,0 +1,128 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestGetDeploymentLogs(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testDeploymentID := "123e4567-e89b-12d3-a456-426614174000" + + testCases := []struct { + name string + token string + organizationID string + deploymentID string + expectedStatus int + description string + }{ + { + name: "Get deployment logs without authentication", + token: "", + organizationID: orgID, + deploymentID: testDeploymentID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Get deployment logs with invalid token", + token: "invalid-token", + organizationID: orgID, + deploymentID: testDeploymentID, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Get deployment logs without organization header", + token: user.AccessToken, + organizationID: "", + deploymentID: testDeploymentID, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Get deployment logs with invalid deployment ID format", + token: user.AccessToken, + organizationID: orgID, + deploymentID: "invalid-uuid", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when deployment ID format is invalid", + }, + { + name: "Get deployment logs for non-existent deployment", + token: user.AccessToken, + organizationID: orgID, + deploymentID: testDeploymentID, + expectedStatus: http.StatusOK, + description: "Should return 200 with empty logs when deployment doesn't exist", + }, + { + name: "Get deployment logs with empty deployment ID", + token: user.AccessToken, + organizationID: orgID, + deploymentID: "", + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when deployment ID is empty", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + var url string + if tc.deploymentID != "" { + url = tests.GetDeployApplicationDeploymentLogsURL(tc.deploymentID) + } else { + url = tests.GetDeployApplicationDeploymentLogsURL("") // This will result in malformed URL + } + + testSteps := []IStep{ + Description(tc.description), + Get(url), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} + +func TestGetDeploymentLogsSuccess(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testDeploymentID := "123e4567-e89b-12d3-a456-426614174000" + + t.Run("Get deployment logs with valid format", func(t *testing.T) { + Test(t, + Description("Should attempt to fetch deployment logs with valid UUID format"), + Get(tests.GetDeployApplicationDeploymentLogsURL(testDeploymentID)), + Send().Headers("Authorization").Add("Bearer "+user.AccessToken), + Send().Headers("X-Organization-ID").Add(orgID), + Expect().Status().OneOf(http.StatusOK, http.StatusNotFound), // Either OK with logs or 404 if deployment doesn't exist + ) + }) +} diff --git a/api/internal/tests/deploy/redeploy_application_test.go b/api/internal/tests/deploy/redeploy_application_test.go new file mode 100644 index 00000000..c098dfd9 --- /dev/null +++ b/api/internal/tests/deploy/redeploy_application_test.go @@ -0,0 +1,130 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/google/uuid" + "github.com/raghavyuva/nixopus-api/internal/features/deploy/types" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestRedeployApplication(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := uuid.New() + + testCases := []struct { + name string + token string + organizationID string + request types.ReDeployApplicationRequest + expectedStatus int + description string + }{ + { + name: "Redeploy application without authentication", + token: "", + organizationID: orgID, + request: types.ReDeployApplicationRequest{ + ID: testApplicationID, + Force: false, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Redeploy application with invalid token", + token: "invalid-token", + organizationID: orgID, + request: types.ReDeployApplicationRequest{ + ID: testApplicationID, + Force: false, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Redeploy application without organization header", + token: user.AccessToken, + organizationID: "", + request: types.ReDeployApplicationRequest{ + ID: testApplicationID, + Force: false, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Redeploy application with missing ID", + token: user.AccessToken, + organizationID: orgID, + request: types.ReDeployApplicationRequest{}, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application ID is missing", + }, + { + name: "Redeploy application that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + request: types.ReDeployApplicationRequest{ + ID: testApplicationID, + Force: false, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application doesn't exist", + }, + { + name: "Redeploy application with force flag", + token: user.AccessToken, + organizationID: orgID, + request: types.ReDeployApplicationRequest{ + ID: testApplicationID, + Force: true, + }, + expectedStatus: http.StatusInternalServerError, // API returns 500 since app doesn't exist + description: "Should redeploy application with force flag", + }, + { + name: "Redeploy application with force without cache", + token: user.AccessToken, + organizationID: orgID, + request: types.ReDeployApplicationRequest{ + ID: testApplicationID, + Force: true, + ForceWithoutCache: true, + }, + expectedStatus: http.StatusInternalServerError, // API returns 500 since app doesn't exist + description: "Should redeploy application with force without cache", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetDeployApplicationRedeployURL()), + Send().Body().JSON(tc.request), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/deploy/restart_application_test.go b/api/internal/tests/deploy/restart_application_test.go new file mode 100644 index 00000000..011aaabf --- /dev/null +++ b/api/internal/tests/deploy/restart_application_test.go @@ -0,0 +1,103 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/google/uuid" + "github.com/raghavyuva/nixopus-api/internal/features/deploy/types" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestRestartApplication(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := uuid.New() + + testCases := []struct { + name string + token string + organizationID string + request types.RestartDeploymentRequest + expectedStatus int + description string + }{ + { + name: "Restart application without authentication", + token: "", + organizationID: orgID, + request: types.RestartDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Restart application with invalid token", + token: "invalid-token", + organizationID: orgID, + request: types.RestartDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Restart application without organization header", + token: user.AccessToken, + organizationID: "", + request: types.RestartDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Restart application with missing ID", + token: user.AccessToken, + organizationID: orgID, + request: types.RestartDeploymentRequest{}, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application ID is missing", + }, + { + name: "Restart application that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + request: types.RestartDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application doesn't exist", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetDeployApplicationRestartURL()), + Send().Body().JSON(tc.request), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/deploy/rollback_application_test.go b/api/internal/tests/deploy/rollback_application_test.go new file mode 100644 index 00000000..280d1034 --- /dev/null +++ b/api/internal/tests/deploy/rollback_application_test.go @@ -0,0 +1,103 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/google/uuid" + "github.com/raghavyuva/nixopus-api/internal/features/deploy/types" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestRollbackApplication(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := uuid.New() + + testCases := []struct { + name string + token string + organizationID string + request types.RollbackDeploymentRequest + expectedStatus int + description string + }{ + { + name: "Rollback application without authentication", + token: "", + organizationID: orgID, + request: types.RollbackDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Rollback application with invalid token", + token: "invalid-token", + organizationID: orgID, + request: types.RollbackDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Rollback application without organization header", + token: user.AccessToken, + organizationID: "", + request: types.RollbackDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Rollback application with missing ID", + token: user.AccessToken, + organizationID: orgID, + request: types.RollbackDeploymentRequest{}, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when application ID is missing", + }, + { + name: "Rollback application that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + request: types.RollbackDeploymentRequest{ + ID: testApplicationID, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application doesn't exist", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Post(tests.GetDeployApplicationRollbackURL()), + Send().Body().JSON(tc.request), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/deploy/update_application_test.go b/api/internal/tests/deploy/update_application_test.go new file mode 100644 index 00000000..87ee0eda --- /dev/null +++ b/api/internal/tests/deploy/update_application_test.go @@ -0,0 +1,141 @@ +package deploy + +import ( + "net/http" + "testing" + + . "github.com/Eun/go-hit" + "github.com/google/uuid" + "github.com/raghavyuva/nixopus-api/internal/features/deploy/types" + "github.com/raghavyuva/nixopus-api/internal/tests" + "github.com/raghavyuva/nixopus-api/internal/testutils" +) + +func TestUpdateApplication(t *testing.T) { + setup := testutils.NewTestSetup() + user, org, err := setup.GetTestAuthResponse() + if err != nil { + t.Fatalf("failed to get test auth response: %v", err) + } + + orgID := org.ID.String() + testApplicationID := uuid.New() + + testCases := []struct { + name string + token string + organizationID string + request types.UpdateDeploymentRequest + expectedStatus int + description string + }{ + { + name: "Update application without authentication", + token: "", + organizationID: orgID, + request: types.UpdateDeploymentRequest{ + ID: testApplicationID, + Name: "updated-app", + Port: 3001, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when no authentication token is provided", + }, + { + name: "Update application with invalid token", + token: "invalid-token", + organizationID: orgID, + request: types.UpdateDeploymentRequest{ + ID: testApplicationID, + Name: "updated-app", + Port: 3001, + }, + expectedStatus: http.StatusUnauthorized, + description: "Should return 401 when invalid authentication token is provided", + }, + { + name: "Update application without organization header", + token: user.AccessToken, + organizationID: "", + request: types.UpdateDeploymentRequest{ + ID: testApplicationID, + Name: "updated-app", + Port: 3001, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when organization ID is not provided", + }, + { + name: "Update application with missing ID", + token: user.AccessToken, + organizationID: orgID, + request: types.UpdateDeploymentRequest{ + Name: "updated-app", + Port: 3001, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application ID is missing", + }, + { + name: "Update application that doesn't exist", + token: user.AccessToken, + organizationID: orgID, + request: types.UpdateDeploymentRequest{ + ID: testApplicationID, + Name: "updated-app", + Port: 3001, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when application doesn't exist", + }, + { + name: "Update application with valid data", + token: user.AccessToken, + organizationID: orgID, + request: types.UpdateDeploymentRequest{ + ID: testApplicationID, + Name: "updated-app", + Port: 3001, + EnvironmentVariables: map[string]string{ + "NODE_ENV": "production", + }, + }, + expectedStatus: http.StatusInternalServerError, + description: "Should return 500 when trying to update non-existent application", + }, + { + name: "Update application with invalid port", + token: user.AccessToken, + organizationID: orgID, + request: types.UpdateDeploymentRequest{ + ID: testApplicationID, + Name: "updated-app", + Port: -1, + }, + expectedStatus: http.StatusBadRequest, + description: "Should return 400 when port is invalid", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + testSteps := []IStep{ + Description(tc.description), + Put(tests.GetDeployApplicationURL()), + Send().Body().JSON(tc.request), + } + + if tc.token != "" { + testSteps = append(testSteps, Send().Headers("Authorization").Add("Bearer "+tc.token)) + } + + if tc.organizationID != "" { + testSteps = append(testSteps, Send().Headers("X-Organization-ID").Add(tc.organizationID)) + } + + testSteps = append(testSteps, Expect().Status().Equal(int64(tc.expectedStatus))) + + Test(t, testSteps...) + }) + } +} diff --git a/api/internal/tests/helper.go b/api/internal/tests/helper.go index 07b2ce2c..b91115ad 100644 --- a/api/internal/tests/helper.go +++ b/api/internal/tests/helper.go @@ -97,3 +97,39 @@ func GetFeatureFlagsURL() string { func GetFeatureFlagCheckURL() string { return baseURL + "/feature-flags/check" } + +func GetDeployApplicationURL() string { + return baseURL + "/deploy/application" +} + +func GetDeployApplicationsURL() string { + return baseURL + "/deploy/applications" +} + +func GetDeployApplicationRedeployURL() string { + return baseURL + "/deploy/application/redeploy" +} + +func GetDeployApplicationRestartURL() string { + return baseURL + "/deploy/application/restart" +} + +func GetDeployApplicationRollbackURL() string { + return baseURL + "/deploy/application/rollback" +} + +func GetDeployApplicationDeploymentsURL() string { + return baseURL + "/deploy/application/deployments" +} + +func GetDeployApplicationDeploymentByIDURL(deploymentID string) string { + return baseURL + "/deploy/application/deployments/" + deploymentID +} + +func GetDeployApplicationDeploymentLogsURL(deploymentID string) string { + return baseURL + "/deploy/application/deployments/" + deploymentID + "/logs" +} + +func GetDeployApplicationLogsURL(applicationID string) string { + return baseURL + "/deploy/application/logs/" + applicationID +} From e159b2a594e3bd445c1612c08e6ed1f4d19ffe76 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Sun, 13 Jul 2025 16:59:47 +0530 Subject: [PATCH 34/72] feat: cli command for checking dependency on a system (#276) * feat: nixopus preflight dependency checker * chore: update function name from check_single_dependency to check_dependency * refactor: CLI Project Structure (#277) * refactor: cli folder structure and update imports accordingly * refactor: finalized cli project structure * chore: update preflight to have common shared logger protocol * feat : Install Command to Clone the Nixopus Git Repository (#279) --- cli/README.md | 1 + cli/app/__init__.py | 0 cli/{ => app}/commands/__init__.py | 0 cli/app/commands/install/clone.py | 231 +++++++++ cli/app/commands/install/command.py | 51 ++ cli/app/commands/install/messages.py | 31 ++ cli/app/commands/install/run.py | 9 + cli/app/commands/install/tests/test_clone.py | 450 ++++++++++++++++++ cli/{ => app}/commands/preflight/__init__.py | 0 cli/app/commands/preflight/command.py | 67 +++ cli/app/commands/preflight/deps.py | 162 +++++++ cli/{ => app}/commands/preflight/messages.py | 10 +- cli/app/commands/preflight/port.py | 114 +++++ cli/app/commands/preflight/tests/test_deps.py | 405 ++++++++++++++++ .../commands/preflight/tests/test_port.py} | 11 +- cli/{ => app}/commands/test/__init__.py | 0 cli/{ => app}/commands/test/command.py | 5 +- cli/app/commands/test/messages.py | 3 + cli/app/commands/test/test.py | 21 + cli/{ => app}/commands/version/__init__.py | 0 cli/{ => app}/commands/version/command.py | 10 +- .../commands/version/tests/test_version.py | 171 +++++++ cli/app/commands/version/version.py | 25 + cli/{ => app}/main.py | 10 +- cli/{ => app}/utils/__init__.py | 0 cli/app/utils/config.py | 11 + cli/app/utils/lib.py | 129 +++++ cli/{ => app}/utils/logger.py | 0 cli/{ => app}/utils/message.py | 5 +- cli/app/utils/output_formatter.py | 48 ++ cli/app/utils/protocols.py | 15 + cli/app/utils/tests/test_processor.py | 81 ++++ cli/commands/preflight/command.py | 41 -- cli/commands/preflight/port.py | 88 ---- cli/commands/test/messages.py | 1 - cli/core/__init__.py | 1 - cli/core/config.py | 7 - cli/core/preflight/port.py | 11 - cli/core/test/__init__.py | 1 - cli/core/test/test.py | 14 - cli/core/version/version.py | 23 - cli/pyproject.toml | 6 +- cli/tests/__init__.py | 1 - cli/tests/test_commands_version.py | 117 ----- cli/tests/version.py | 134 ------ 45 files changed, 2062 insertions(+), 459 deletions(-) create mode 100644 cli/README.md create mode 100644 cli/app/__init__.py rename cli/{ => app}/commands/__init__.py (100%) create mode 100644 cli/app/commands/install/clone.py create mode 100644 cli/app/commands/install/command.py create mode 100644 cli/app/commands/install/messages.py create mode 100644 cli/app/commands/install/run.py create mode 100644 cli/app/commands/install/tests/test_clone.py rename cli/{ => app}/commands/preflight/__init__.py (100%) create mode 100644 cli/app/commands/preflight/command.py create mode 100644 cli/app/commands/preflight/deps.py rename cli/{ => app}/commands/preflight/messages.py (54%) create mode 100644 cli/app/commands/preflight/port.py create mode 100644 cli/app/commands/preflight/tests/test_deps.py rename cli/{tests/port.py => app/commands/preflight/tests/test_port.py} (91%) rename cli/{ => app}/commands/test/__init__.py (100%) rename cli/{ => app}/commands/test/command.py (77%) create mode 100644 cli/app/commands/test/messages.py create mode 100644 cli/app/commands/test/test.py rename cli/{ => app}/commands/version/__init__.py (100%) rename cli/{ => app}/commands/version/command.py (59%) create mode 100644 cli/app/commands/version/tests/test_version.py create mode 100644 cli/app/commands/version/version.py rename cli/{ => app}/main.py (56%) rename cli/{ => app}/utils/__init__.py (100%) create mode 100644 cli/app/utils/config.py create mode 100644 cli/app/utils/lib.py rename cli/{ => app}/utils/logger.py (100%) rename cli/{ => app}/utils/message.py (72%) create mode 100644 cli/app/utils/output_formatter.py create mode 100644 cli/app/utils/protocols.py create mode 100644 cli/app/utils/tests/test_processor.py delete mode 100644 cli/commands/preflight/command.py delete mode 100644 cli/commands/preflight/port.py delete mode 100644 cli/commands/test/messages.py delete mode 100644 cli/core/__init__.py delete mode 100644 cli/core/config.py delete mode 100644 cli/core/preflight/port.py delete mode 100644 cli/core/test/__init__.py delete mode 100644 cli/core/test/test.py delete mode 100644 cli/core/version/version.py delete mode 100644 cli/tests/__init__.py delete mode 100644 cli/tests/test_commands_version.py delete mode 100644 cli/tests/version.py diff --git a/cli/README.md b/cli/README.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/cli/README.md @@ -0,0 +1 @@ + diff --git a/cli/app/__init__.py b/cli/app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/commands/__init__.py b/cli/app/commands/__init__.py similarity index 100% rename from cli/commands/__init__.py rename to cli/app/commands/__init__.py diff --git a/cli/app/commands/install/clone.py b/cli/app/commands/install/clone.py new file mode 100644 index 00000000..b52c2b2c --- /dev/null +++ b/cli/app/commands/install/clone.py @@ -0,0 +1,231 @@ +import subprocess +import os +from typing import Protocol, Optional +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.lib import DirectoryManager +from app.utils.output_formatter import OutputFormatter +from .messages import ( + path_already_exists_use_force, + executing_command, + successfully_cloned, + git_clone_failed, + unexpected_error_during_clone, + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_repository, + dry_run_branch, + dry_run_target_path, + dry_run_force_mode, + path_exists_will_overwrite, + path_exists_would_fail, + target_path_not_exists, + end_dry_run, + cloning_repo_into_path, + invalid_repository_url, + invalid_path, + invalid_repo, + prerequisites_validation_failed, + failed_to_prepare_target_directory +) + +class GitCloneProtocol(Protocol): + def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bool, str]: + ... + +class GitCommandBuilder: + @staticmethod + def build_clone_command(repo: str, path: str, branch: str = None) -> list[str]: + cmd = ["git", "clone"] + if branch: + cmd.extend(["-b", branch]) + cmd.extend([repo, path]) + return cmd + +class CloneFormatter: + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, result: "CloneResult", output: str) -> str: + if result.success: + message = successfully_cloned.format(repo=result.repo, path=result.path) + output_message = self.output_formatter.create_success_message(message, result.model_dump()) + else: + error = result.error or "Unknown error" + output_message = self.output_formatter.create_error_message(error, result.model_dump()) + + return self.output_formatter.format_output(output_message, output) + + def format_dry_run(self, config: "CloneConfig") -> str: + cmd = GitCommandBuilder.build_clone_command(config.repo, config.path, config.branch) + + output = [] + output.append(dry_run_mode) + output.append(dry_run_command_would_be_executed) + output.append(dry_run_command.format(command=' '.join(cmd))) + output.append(dry_run_repository.format(repo=config.repo)) + output.append(dry_run_branch.format(branch=config.branch or "default")) + output.append(dry_run_target_path.format(path=config.path)) + output.append(dry_run_force_mode.format(force=config.force)) + + self._add_path_status_message(output, config.path, config.force) + + output.append(end_dry_run) + return "\n".join(output) + + def _add_path_status_message(self, output: list[str], path: str, force: bool) -> None: + if os.path.exists(path): + if force: + output.append(path_exists_will_overwrite.format(path=path)) + else: + output.append(path_exists_would_fail.format(path=path)) + else: + output.append(target_path_not_exists.format(path=path)) + +class GitClone: + def __init__(self, logger: LoggerProtocol): + self.logger = logger + + def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bool, str]: + cmd = GitCommandBuilder.build_clone_command(repo, path, branch) + + try: + self.logger.info(executing_command.format(command=' '.join(cmd))) + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + self.logger.success(successfully_cloned.format(repo=repo, path=path)) + return True, None + except subprocess.CalledProcessError as e: + self.logger.error(git_clone_failed.format(error=e.stderr)) + return False, e.stderr + except Exception as e: + self.logger.error(unexpected_error_during_clone.format(error=e)) + return False, str(e) + +class CloneResult(BaseModel): + repo: str + path: str + branch: Optional[str] + force: bool + verbose: bool + output: str + success: bool = False + error: Optional[str] = None + +class CloneConfig(BaseModel): + repo: str = Field(..., min_length=1, description="Repository URL to clone") + branch: Optional[str] = Field("master", description="Branch to clone") + path: str = Field(..., min_length=1, description="Target path for cloning") + force: bool = Field(False, description="Force overwrite if path exists") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format: text, json") + dry_run: bool = Field(False, description="Dry run mode") + + @field_validator("repo") + @classmethod + def validate_repo(cls, repo: str) -> str: + stripped_repo = repo.strip() + if not stripped_repo: + raise ValueError(invalid_repo) + + if not cls._is_valid_repo_format(stripped_repo): + raise ValueError(invalid_repository_url) + return stripped_repo + + @staticmethod + def _is_valid_repo_format(repo: str) -> bool: + return ( + repo.startswith(('http://', 'https://', 'git://', 'ssh://')) or + (repo.endswith('.git') and not repo.startswith('github.com:')) or + ('@' in repo and ':' in repo and repo.count('@') == 1) + ) + + @field_validator("path") + @classmethod + def validate_path(cls, path: str) -> str: + stripped_path = path.strip() + if not stripped_path: + raise ValueError(invalid_path) + return stripped_path + + @field_validator("branch") + @classmethod + def validate_branch(cls, branch: str) -> Optional[str]: + if not branch: + return None + stripped_branch = branch.strip() + if not stripped_branch: + return None + return stripped_branch + +class CloneService: + def __init__(self, config: CloneConfig, logger: LoggerProtocol = None, cloner: GitCloneProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.cloner = cloner or GitClone(self.logger) + self.formatter = CloneFormatter() + self.dir_manager = DirectoryManager() + + def _prepare_target_directory(self) -> bool: + if self.config.force and os.path.exists(self.config.path): + return self.dir_manager.remove_directory( + self.config.path, + self.logger + ) + return True + + def _validate_prerequisites(self) -> bool: + if self.dir_manager.path_exists_and_not_force(self.config.path, self.config.force): + self.logger.error(path_already_exists_use_force.format(path=self.config.path)) + return False + return True + + def _create_result(self, success: bool, error: str = None) -> CloneResult: + return CloneResult( + repo=self.config.repo, + path=self.config.path, + branch=self.config.branch, + force=self.config.force, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def clone(self) -> CloneResult: + self.logger.debug(cloning_repo_into_path.format(repo=self.config.repo, path=self.config.path)) + + if not self._validate_prerequisites(): + return self._create_result(False, prerequisites_validation_failed) + + if not self._prepare_target_directory(): + return self._create_result(False, failed_to_prepare_target_directory) + + success, error = self.cloner.clone_repository( + self.config.repo, + self.config.path, + self.config.branch + ) + + return self._create_result(success, error) + + def clone_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.clone() + return self.formatter.format_output(result, self.config.output) + +class Clone: + def __init__(self, logger: LoggerProtocol = None): + self.logger = logger + self.formatter = CloneFormatter() + + def clone(self, config: CloneConfig) -> CloneResult: + service = CloneService(config, logger=self.logger) + return service.clone() + + def format_output(self, result: CloneResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py new file mode 100644 index 00000000..fd89c97e --- /dev/null +++ b/cli/app/commands/install/command.py @@ -0,0 +1,51 @@ +import typer +from .run import Install +from .clone import Clone, CloneConfig +from app.utils.logger import Logger + +install_app = typer.Typer( + help="Install Nixopus", + invoke_without_command=True +) + +@install_app.callback() +def install_callback(ctx: typer.Context): + """Install Nixopus""" + if ctx.invoked_subcommand is None: + install = Install() + install.run() + +def main_install_callback(value: bool): + if value: + install = Install() + install.run() + raise typer.Exit() + +@install_app.command() +def clone( + repo: str = typer.Option("https://github.com/raghavyuva/nixopus", help="The repository to clone"), + branch: str = typer.Option("master", help="The branch to clone"), + path: str = typer.Option("/etc/nixopus", help="The path to clone the repository to"), + force: bool = typer.Option(False, help="Force the clone"), + verbose: bool = typer.Option(False, help="Verbose output"), + output: str = typer.Option("text", help="Output format, text, json"), + dry_run: bool = typer.Option(False, help="Dry run"), +): + """Clone a repository""" + try: + logger = Logger(verbose=verbose) + config = CloneConfig( + repo=repo, + branch=branch, + path=path, + force=force, + verbose=verbose, + output=output, + dry_run=dry_run + ) + clone_operation = Clone(logger=logger) + result = clone_operation.clone(config) + logger.success(result.output) + except Exception as e: + logger.error(e) + raise typer.Exit(1) diff --git a/cli/app/commands/install/messages.py b/cli/app/commands/install/messages.py new file mode 100644 index 00000000..9b6c829c --- /dev/null +++ b/cli/app/commands/install/messages.py @@ -0,0 +1,31 @@ +path_already_exists_use_force = "Path {path} already exists. Use --force to overwrite." +executing_command = "Executing: {command}" +successfully_cloned = "Successfully cloned {repo} to {path}" +git_clone_failed = "Git clone failed: {error}" +unexpected_error_during_clone = "Unexpected error during clone: {error}" +dry_run_mode = "=== DRY RUN MODE ===" +dry_run_command_would_be_executed = "The following command would be executed:" +dry_run_command = "Command: {command}" +dry_run_repository = "Repository: {repo}" +dry_run_branch = "Branch: {branch}" +dry_run_target_path = "Target path: {path}" +dry_run_force_mode = "Force mode: {force}" +git_not_available = "Git is not available on the system" +git_available = "Git is available on the system" +path_exists_will_overwrite = "Path {path} exists and will be overwritten (force mode)" +path_exists_would_fail = "Path {path} exists - clone would fail without --force" +target_path_not_exists = "Target path {path} does not exist" +end_dry_run = "=== END DRY RUN ===" +cloning_repo_into_path = "Cloning {repo} into {path}" +installing_nixopus = "Installing nixopus" +invalid_repository_url = "Invalid repository URL format" +invalid_target_path = "Invalid target path format" +invalid_branch = "Invalid branch format" +invalid_output_format = "Invalid output format" +invalid_dry_run = "Invalid dry run format" +invalid_force = "Invalid force format" +invalid_verbose = "Invalid verbose format" +invalid_repo = "Invalid repository format" +invalid_path = "Invalid path format" +prerequisites_validation_failed = "Prerequisites validation failed" +failed_to_prepare_target_directory = "Failed to prepare target directory" diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py new file mode 100644 index 00000000..1f41b872 --- /dev/null +++ b/cli/app/commands/install/run.py @@ -0,0 +1,9 @@ +from app.utils.protocols import LoggerProtocol +from .messages import installing_nixopus + +class Install: + def __init__(self, logger: LoggerProtocol): + self.logger = logger + + def run(self): + self.logger.debug(installing_nixopus) diff --git a/cli/app/commands/install/tests/test_clone.py b/cli/app/commands/install/tests/test_clone.py new file mode 100644 index 00000000..562699db --- /dev/null +++ b/cli/app/commands/install/tests/test_clone.py @@ -0,0 +1,450 @@ +import pytest +import subprocess +from unittest.mock import Mock, patch, MagicMock +from pydantic import ValidationError + +from app.commands.install.clone import ( + GitCommandBuilder, + CloneFormatter, + GitClone, + CloneResult, + CloneConfig, + CloneService, + Clone +) +from app.utils.lib import DirectoryManager +from app.utils.logger import Logger + + +class TestGitCommandBuilder: + def test_build_clone_command_without_branch(self): + cmd = GitCommandBuilder.build_clone_command("https://github.com/user/repo", "/path/to/clone") + assert cmd == ["git", "clone", "https://github.com/user/repo", "/path/to/clone"] + + def test_build_clone_command_with_branch(self): + cmd = GitCommandBuilder.build_clone_command("https://github.com/user/repo", "/path/to/clone", "main") + assert cmd == ["git", "clone", "-b", "main", "https://github.com/user/repo", "/path/to/clone"] + + def test_build_clone_command_with_empty_branch(self): + cmd = GitCommandBuilder.build_clone_command("https://github.com/user/repo", "/path/to/clone", "") + assert cmd == ["git", "clone", "https://github.com/user/repo", "/path/to/clone"] + + +class TestCloneFormatter: + def setup_method(self): + self.formatter = CloneFormatter() + + def test_format_output_success(self): + result = CloneResult( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=False, + output="text", + success=True + ) + formatted = self.formatter.format_output(result, "text") + assert "Successfully cloned" in formatted + assert "https://github.com/user/repo" in formatted + assert "/path/to/clone" in formatted + + def test_format_output_failure(self): + result = CloneResult( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=False, + output="text", + success=False, + error="Repository not found" + ) + formatted = self.formatter.format_output(result, "text") + assert "Error: Repository not found" in formatted + + def test_format_output_json(self): + result = CloneResult( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=False, + output="json", + success=True + ) + formatted = self.formatter.format_output(result, "json") + import json + data = json.loads(formatted) + assert data["success"] is True + assert data["message"] == "Successfully cloned https://github.com/user/repo to /path/to/clone" + + def test_format_output_invalid(self): + result = CloneResult( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=False, + output="invalid", + success=True + ) + with pytest.raises(ValueError): + self.formatter.format_output(result, "invalid") + + @patch('os.path.exists') + def test_format_dry_run(self, mock_exists): + mock_exists.return_value = False + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=True, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert "=== DRY RUN MODE ===" in formatted + assert "git clone -b main https://github.com/user/repo /path/to/clone" in formatted + assert "Force mode: True" in formatted + + @patch('os.path.exists') + def test_format_dry_run_path_exists_force(self, mock_exists): + mock_exists.return_value = True + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=True, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert "will be overwritten" in formatted + + @patch('os.path.exists') + def test_format_dry_run_path_exists_no_force(self, mock_exists): + mock_exists.return_value = True + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert "would fail without --force" in formatted + + +class TestGitClone: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.git_clone = GitClone(self.logger) + + @patch('subprocess.run') + def test_clone_repository_success(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone", "main") + + assert success is True + assert error is None + self.logger.info.assert_called_once() + self.logger.success.assert_called_once() + + @patch('subprocess.run') + def test_clone_repository_without_branch(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["git", "clone", "https://github.com/user/repo", "/path/to/clone"] + + @patch('subprocess.run') + def test_clone_repository_failure(self, mock_run): + mock_run.side_effect = subprocess.CalledProcessError(1, "git clone", stderr="Repository not found") + + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone") + + assert success is False + assert error == "Repository not found" + self.logger.error.assert_called_once() + + @patch('subprocess.run') + def test_clone_repository_unexpected_error(self, mock_run): + mock_run.side_effect = Exception("Unexpected error") + + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone") + + assert success is False + assert error == "Unexpected error" + self.logger.error.assert_called_once() + + +class TestCloneConfig: + def test_valid_config(self): + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main" + ) + assert config.repo == "https://github.com/user/repo" + assert config.path == "/path/to/clone" + assert config.branch == "main" + assert config.force is False + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + + def test_valid_repo_formats(self): + valid_repos = [ + "https://github.com/user/repo", + "http://github.com/user/repo", + "git://github.com/user/repo", + "ssh://github.com/user/repo", + "git@github.com:user/repo.git", + "https://github.com/user/repo.git" + ] + + for repo in valid_repos: + config = CloneConfig(repo=repo, path="/path/to/clone") + assert config.repo == repo + + def test_invalid_repo_formats(self): + invalid_repos = [ + "", + " ", + "github.com:user/repo", + "invalid://github.com/user/repo" + ] + + for repo in invalid_repos: + with pytest.raises(ValidationError): + CloneConfig(repo=repo, path="/path/to/clone") + + def test_empty_repo(self): + with pytest.raises(ValidationError): + CloneConfig(repo="", path="/path/to/clone") + + def test_empty_path(self): + with pytest.raises(ValidationError): + CloneConfig(repo="https://github.com/user/repo", path="") + + def test_branch_validation(self): + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch=" " + ) + assert config.branch is None + + def test_is_valid_repo_format(self): + valid_repos = [ + "https://github.com/user/repo", + "http://github.com/user/repo", + "git@github.com:user/repo.git", + "https://github.com/user/repo.git" + ] + + for repo in valid_repos: + assert CloneConfig._is_valid_repo_format(repo) is True + + invalid_repos = [ + "github.com:user/repo", + "invalid://github.com/user/repo" + ] + + for repo in invalid_repos: + assert CloneConfig._is_valid_repo_format(repo) is False + + +class TestDirectoryManager: + def setup_method(self): + self.logger = Mock(spec=Logger) + + @patch('shutil.rmtree') + def test_remove_directory_success(self, mock_rmtree): + success = DirectoryManager.remove_directory("/path/to/remove", self.logger) + + assert success is True + mock_rmtree.assert_called_once_with("/path/to/remove") + self.logger.info.assert_called_once() + + @patch('shutil.rmtree') + def test_remove_directory_failure(self, mock_rmtree): + mock_rmtree.side_effect = Exception("Permission denied") + + success = DirectoryManager.remove_directory("/path/to/remove", self.logger) + + assert success is False + self.logger.error.assert_called_once() + + @patch('os.path.exists') + def test_path_exists_and_not_force_true(self, mock_exists): + mock_exists.return_value = True + + result = DirectoryManager.path_exists_and_not_force("/path/to/check", False) + + assert result is True + + @patch('os.path.exists') + def test_path_exists_and_not_force_false_when_force(self, mock_exists): + mock_exists.return_value = True + + result = DirectoryManager.path_exists_and_not_force("/path/to/check", True) + + assert result is False + + @patch('os.path.exists') + def test_path_exists_and_not_force_false_when_not_exists(self, mock_exists): + mock_exists.return_value = False + + result = DirectoryManager.path_exists_and_not_force("/path/to/check", False) + + assert result is False + + +class TestCloneService: + def setup_method(self): + self.config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main" + ) + self.logger = Mock(spec=Logger) + self.cloner = Mock(spec=GitClone) + self.service = CloneService(self.config, self.logger, self.cloner) + + def test_create_result_success(self): + result = self.service._create_result(True) + + assert result.repo == self.config.repo + assert result.path == self.config.path + assert result.branch == self.config.branch + assert result.success is True + assert result.error is None + + def test_create_result_failure(self): + result = self.service._create_result(False, "Test error") + + assert result.success is False + assert result.error == "Test error" + + @patch('os.path.exists') + def test_validate_prerequisites_success(self, mock_exists): + mock_exists.return_value = False + + result = self.service._validate_prerequisites() + + assert result is True + + @patch('os.path.exists') + def test_validate_prerequisites_path_exists_no_force(self, mock_exists): + mock_exists.return_value = True + + result = self.service._validate_prerequisites() + + assert result is False + self.logger.error.assert_called_once() + + @patch('os.path.exists') + def test_prepare_target_directory_force_success(self, mock_exists): + self.service.config.force = True + mock_exists.return_value = True + self.service.dir_manager.remove_directory = Mock(return_value=True) + + result = self.service._prepare_target_directory() + + assert result is True + self.service.dir_manager.remove_directory.assert_called_once_with(self.config.path, self.logger) + + @patch('os.path.exists') + def test_prepare_target_directory_force_failure(self, mock_exists): + self.service.config.force = True + mock_exists.return_value = True + self.service.dir_manager.remove_directory = Mock(return_value=False) + + result = self.service._prepare_target_directory() + + assert result is False + self.service.dir_manager.remove_directory.assert_called_once_with(self.config.path, self.logger) + + def test_clone_success(self): + self.cloner.clone_repository.return_value = (True, None) + + result = self.service.clone() + + assert result.success is True + self.cloner.clone_repository.assert_called_once_with( + self.config.repo, + self.config.path, + self.config.branch + ) + + def test_clone_failure(self): + self.cloner.clone_repository.return_value = (False, "Test error") + + result = self.service.clone() + + assert result.success is False + assert result.error == "Test error" + + def test_clone_and_format_dry_run(self): + self.config.dry_run = True + + result = self.service.clone_and_format() + + assert "=== DRY RUN MODE ===" in result + + def test_clone_and_format_success(self): + self.cloner.clone_repository.return_value = (True, None) + + result = self.service.clone_and_format() + + assert "Successfully cloned" in result + + +class TestClone: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.clone = Clone(self.logger) + + def test_clone_success(self): + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main" + ) + + with patch.object(CloneService, 'clone') as mock_clone: + mock_result = CloneResult( + repo=config.repo, + path=config.path, + branch=config.branch, + force=config.force, + verbose=config.verbose, + output=config.output, + success=True + ) + mock_clone.return_value = mock_result + + result = self.clone.clone(config) + + assert result.success is True + + def test_format_output(self): + result = CloneResult( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=False, + output="text", + success=True + ) + + formatted = self.clone.format_output(result, "text") + + assert "Successfully cloned" in formatted diff --git a/cli/commands/preflight/__init__.py b/cli/app/commands/preflight/__init__.py similarity index 100% rename from cli/commands/preflight/__init__.py rename to cli/app/commands/preflight/__init__.py diff --git a/cli/app/commands/preflight/command.py b/cli/app/commands/preflight/command.py new file mode 100644 index 00000000..94d9b55c --- /dev/null +++ b/cli/app/commands/preflight/command.py @@ -0,0 +1,67 @@ +import typer +from .messages import error_checking_deps, error_checking_ports +from .port import PortConfig, PortService +from .deps import Deps, DepsConfig +from app.utils.lib import HostInformation +from app.utils.logger import Logger + +preflight_app = typer.Typer(no_args_is_help=False) + +@preflight_app.callback(invoke_without_command=True) +def preflight_callback(ctx: typer.Context): + """Preflight checks for system compatibility""" + if ctx.invoked_subcommand is None: + ctx.invoke(check) + +@preflight_app.command() +def check( + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text,json"), +): + """Run all preflight checks""" + pass + +@preflight_app.command() +def ports( + ports: list[int] = typer.Argument(..., help="The list of ports to check"), + host: str = typer.Option("localhost", "--host", "-h", help="The host to check"), + timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each port check"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), +) -> None: + """Check if list of ports are available on a host""" + try: + logger = Logger(verbose=verbose) + logger.debug(f"Checking ports: {ports}") + config = PortConfig(ports=ports, host=host, timeout=timeout, verbose=verbose) + port_service = PortService(config, logger=logger) + results = port_service.check_ports() + logger.success(port_service.formatter.format_output(results, output)) + except Exception as e: + logger.error(error_checking_ports.format(error=e)) + raise typer.Exit(1) + +@preflight_app.command() +def deps( + deps: list[str] = typer.Argument(..., help="The list of dependencies to check"), + timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each dependency check"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), +) -> None: + """Check if list of dependencies are available on the system""" + try: + logger = Logger(verbose=verbose) + config = DepsConfig( + deps=deps, + timeout=timeout, + verbose=verbose, + output=output, + os=HostInformation.get_os_name(), + package_manager=HostInformation.get_package_manager() + ) + deps_checker = Deps(logger=logger) + results = deps_checker.check(config) + logger.success(deps_checker.format_output(results, output)) + except Exception as e: + logger.error(error_checking_deps.format(error=e)) + raise typer.Exit(1) diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py new file mode 100644 index 00000000..938f051e --- /dev/null +++ b/cli/app/commands/preflight/deps.py @@ -0,0 +1,162 @@ +import subprocess +from typing import Protocol, Optional +from pydantic import BaseModel, Field, field_validator +from app.utils.lib import Supported, ParallelProcessor +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from .messages import invalid_os, invalid_package_manager, error_checking_dependency, timeout_checking_dependency + +class DependencyCheckerProtocol(Protocol): + def check_dependency(self, dep: str) -> bool: + ... + +class DependencyChecker: + def __init__(self, timeout: int, logger: LoggerProtocol): + self.timeout = timeout + self.logger = logger + + def check_dependency(self, dep: str) -> bool: + self.logger.debug(f"Checking dependency: {dep}") + + try: + result = subprocess.run( + ["command", "-v", dep], + capture_output=True, + text=True, + timeout=self.timeout + ) + return result.returncode == 0 + + except subprocess.TimeoutExpired: + self.logger.error(timeout_checking_dependency.format(dep=dep)) + return False + except Exception as e: + self.logger.error(error_checking_dependency.format(dep=dep, error=e)) + return False + +class DependencyValidator: + def validate_os(self, os: str) -> str: + if not Supported.os(os): + raise ValueError(invalid_os.format(os=os)) + return os + + def validate_package_manager(self, package_manager: str) -> str: + if not Supported.package_manager(package_manager): + raise ValueError(invalid_package_manager.format(package_manager=package_manager)) + return package_manager + +class DependencyFormatter: + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, results: list["DepsCheckResult"], output: str) -> str: + if not results: + return self.output_formatter.format_output( + self.output_formatter.create_success_message("No dependencies to check"), + output + ) + + messages = [] + for result in results: + if result.is_available: + message = f"{result.dependency} is available" + messages.append(self.output_formatter.create_success_message(message, result.model_dump())) + else: + error = f"{result.dependency} is not available" + messages.append(self.output_formatter.create_error_message(error, result.model_dump())) + + return self.output_formatter.format_output(messages, output) + +class DepsCheckResult(BaseModel): + dependency:str + timeout: int + verbose: bool + output: str + os: str + package_manager: str + is_available: bool = False + error: Optional[str] = None + +class DepsConfig(BaseModel): + deps: list[str] = Field(..., min_length=1, description="The list of dependencies to check") + timeout: int = Field(1, gt=0, le=60, description="The timeout in seconds") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format, text, json") + os: str = Field(..., description=f"The operating system to check, available: {Supported.get_os()}") + package_manager: str = Field(..., description="The package manager to use") + + @field_validator("os") + @classmethod + def validate_os(cls, os: str) -> str: + validator = DependencyValidator() + return validator.validate_os(os) + + @field_validator("package_manager") + @classmethod + def validate_package_manager(cls, package_manager: str) -> str: + validator = DependencyValidator() + return validator.validate_package_manager(package_manager) + +class DepsService: + def __init__(self, config: DepsConfig, logger: LoggerProtocol = None, checker: DependencyCheckerProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.checker = checker or DependencyChecker(config.timeout, self.logger) + self.formatter = DependencyFormatter() + + def _create_result(self, dep: str, is_available: bool, error: str = None) -> DepsCheckResult: + return DepsCheckResult( + dependency=dep, + timeout=self.config.timeout, + verbose=self.config.verbose, + output=self.config.output, + os=self.config.os, + package_manager=self.config.package_manager, + is_available=is_available, + error=error + ) + + def _check_dependency(self, dep: str) -> DepsCheckResult: + try: + is_available = self.checker.check_dependency(dep) + return self._create_result(dep, is_available) + except Exception as e: + return self._create_result(dep, False, str(e)) + + def check_dependencies(self) -> list[DepsCheckResult]: + self.logger.debug(f"Checking dependencies: {self.config.deps}") + + def process_dep(dep: str) -> DepsCheckResult: + return self._check_dependency(dep) + + def error_handler(dep: str, error: Exception) -> DepsCheckResult: + self.logger.error(error_checking_dependency.format(dep=dep, error=error)) + return self._create_result(dep, False, str(error)) + + results = ParallelProcessor.process_items( + items=self.config.deps, + processor_func=process_dep, + max_workers=min(len(self.config.deps), 50), + error_handler=error_handler + ) + + return results + + def check_and_format(self) -> str: + results = self.check_dependencies() + return self.formatter.format_output(results, self.config.output) + +class Deps: + def __init__(self, logger: LoggerProtocol = None): + self.logger = logger + self.validator = DependencyValidator() + self.formatter = DependencyFormatter() + + def check(self, config: DepsConfig) -> list[DepsCheckResult]: + service = DepsService(config, logger=self.logger) + return service.check_dependencies() + + def format_output(self, results: list[DepsCheckResult], output: str) -> str: + return self.formatter.format_output(results, output) + \ No newline at end of file diff --git a/cli/commands/preflight/messages.py b/cli/app/commands/preflight/messages.py similarity index 54% rename from cli/commands/preflight/messages.py rename to cli/app/commands/preflight/messages.py index fc7f2e26..3fd2a452 100644 --- a/cli/commands/preflight/messages.py +++ b/cli/app/commands/preflight/messages.py @@ -7,4 +7,12 @@ available = "available" not_available = "not available" error_checking_port = "Error checking port {port}: {error}" -host_must_be_localhost_or_valid_ip_or_domain = "Host must be 'localhost', a valid IP address, or a valid domain name" \ No newline at end of file +host_must_be_localhost_or_valid_ip_or_domain = "Host must be 'localhost', a valid IP address, or a valid domain name" +invalid_distribution = "Invalid distribution: {distribution}" +invalid_os = "Invalid OS: {os}" +invalid_package_manager = "Invalid package manager: {package_manager}" +error_checking_deps = "Error checking dependencies: {error}" +error_checking_ports = "Error checking ports: {error}" +invalid_output_format = "Invalid output format: {output}" +error_checking_dependency = "Error checking dependency {dep}: {error}" +timeout_checking_dependency = "Timeout checking dependency: {dep}" diff --git a/cli/app/commands/preflight/port.py b/cli/app/commands/preflight/port.py new file mode 100644 index 00000000..c2436c06 --- /dev/null +++ b/cli/app/commands/preflight/port.py @@ -0,0 +1,114 @@ +import re, socket +from typing import List, TypedDict, Union, Any, Optional, Protocol +from pydantic import BaseModel, Field, field_validator +from .messages import available, not_available, error_checking_port, host_must_be_localhost_or_valid_ip_or_domain +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.lib import ParallelProcessor +from app.utils.output_formatter import OutputFormatter + +class PortCheckerProtocol(Protocol): + def check_port(self, port: int, config: "PortConfig") -> "PortCheckResult": + ... + +class PortCheckResult(TypedDict): + port: int + status: str + host: Optional[str] + error: Optional[str] + is_available: bool + +class PortConfig(BaseModel): + ports: List[int] = Field(..., min_length=1, max_length=65535, description="List of ports to check") + host: str = Field("localhost", min_length=1, description="Host to check") + timeout: int = Field(1, gt=0, le=60, description="Timeout in seconds") + verbose: bool = Field(False, description="Verbose output") + + @field_validator('host') + @classmethod + def validate_host(cls, v: str) -> str: + if v.lower() == "localhost": + return v + ip_pattern = r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' + if re.match(ip_pattern, v): + return v + domain_pattern = r'^[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*$' + if re.match(domain_pattern, v): + return v + raise ValueError(host_must_be_localhost_or_valid_ip_or_domain) + +class PortFormatter: + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, data: Union[str, List[PortCheckResult], Any], output_type: str) -> str: + if isinstance(data, list): + messages = [] + for item in data: + if item.get('is_available', False): + message = f"Port {item['port']}: {item['status']}" + messages.append(self.output_formatter.create_success_message(message, item)) + else: + error = f"Port {item['port']}: {item['status']}" + messages.append(self.output_formatter.create_error_message(error, item)) + return self.output_formatter.format_output(messages, output_type) + else: + return str(data) + +class PortChecker: + def __init__(self, logger: LoggerProtocol, timeout: int): + self.logger = logger + self.timeout = timeout + + def is_port_available(self, host: str, port: int) -> bool: + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: + sock.settimeout(self.timeout) + result = sock.connect_ex((host, port)) + return result != 0 + except Exception: + return False + + def check_port(self, port: int, config: PortConfig) -> PortCheckResult: + self.logger.debug(f"Checking port {port} on host {config.host}") + try: + status = available if self.is_port_available(config.host, port) else not_available + return self._create_result(port, config, status) + except Exception as e: + self.logger.error(error_checking_port.format(port=port, error=str(e))) + return self._create_result(port, config, not_available, str(e)) + + def _create_result(self, port: int, config: PortConfig, status: str, error: Optional[str] = None) -> PortCheckResult: + return { + "port": port, + "status": status, + "host": config.host if config.verbose else None, + "error": error, + "is_available": status == available + } + +class PortService: + def __init__(self, config: PortConfig, logger: LoggerProtocol = None, checker: PortCheckerProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.checker = checker or PortChecker(self.logger, config.timeout) + self.formatter = PortFormatter() + + def check_ports(self) -> List[PortCheckResult]: + self.logger.debug(f"Checking ports: {self.config.ports}") + def process_port(port: int) -> PortCheckResult: + return self.checker.check_port(port, self.config) + def error_handler(port: int, error: Exception) -> PortCheckResult: + self.logger.error(error_checking_port.format(port=port, error=str(error))) + return self.checker._create_result(port, self.config, not_available, str(error)) + results = ParallelProcessor.process_items( + items=self.config.ports, + processor_func=process_port, + max_workers=min(len(self.config.ports), 50), + error_handler=error_handler + ) + return sorted(results, key=lambda x: x["port"]) + + def check_and_format(self, output_type: str) -> str: + results = self.check_ports() + return self.formatter.format_output(results, output_type) diff --git a/cli/app/commands/preflight/tests/test_deps.py b/cli/app/commands/preflight/tests/test_deps.py new file mode 100644 index 00000000..d01d8f69 --- /dev/null +++ b/cli/app/commands/preflight/tests/test_deps.py @@ -0,0 +1,405 @@ +import unittest +from unittest.mock import Mock, patch, MagicMock +import subprocess +import json +from typing import List + +from app.commands.preflight.deps import ( + DependencyChecker, + DependencyValidator, + DependencyFormatter, + DepsCheckResult, + DepsConfig, + DepsService, + Deps +) +from app.utils.lib import Supported +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol + + +class MockLogger: + def __init__(self): + self.debug_calls = [] + self.error_calls = [] + self.info_calls = [] + self.warning_calls = [] + self.success_calls = [] + self.highlight_calls = [] + + def debug(self, message: str) -> None: + self.debug_calls.append(message) + + def error(self, message: str) -> None: + self.error_calls.append(message) + + def info(self, message: str) -> None: + self.info_calls.append(message) + + def warning(self, message: str) -> None: + self.warning_calls.append(message) + + def success(self, message: str) -> None: + self.success_calls.append(message) + + def highlight(self, message: str) -> None: + self.highlight_calls.append(message) + + +class TestDependencyChecker(unittest.TestCase): + + def setUp(self): + self.mock_logger = MockLogger() + self.checker = DependencyChecker(timeout=5, logger=self.mock_logger) + + @patch('subprocess.run') + def test_check_dependency_available(self, mock_run): + mock_result = Mock() + mock_result.returncode = 0 + mock_run.return_value = mock_result + + result = self.checker.check_dependency("docker") + + self.assertTrue(result) + mock_run.assert_called_once_with( + ["command", "-v", "docker"], + capture_output=True, + text=True, + timeout=5 + ) + self.assertEqual(len(self.mock_logger.debug_calls), 1) + self.assertIn("docker", self.mock_logger.debug_calls[0]) + + @patch('subprocess.run') + def test_check_dependency_not_available(self, mock_run): + mock_result = Mock() + mock_result.returncode = 1 + mock_run.return_value = mock_result + + result = self.checker.check_dependency("nonexistent") + + self.assertFalse(result) + mock_run.assert_called_once_with( + ["command", "-v", "nonexistent"], + capture_output=True, + text=True, + timeout=5 + ) + + @patch('subprocess.run') + def test_check_dependency_timeout(self, mock_run): + mock_run.side_effect = subprocess.TimeoutExpired("command", 5) + + result = self.checker.check_dependency("slow_command") + + self.assertFalse(result) + self.assertEqual(len(self.mock_logger.error_calls), 1) + self.assertIn("slow_command", self.mock_logger.error_calls[0]) + + @patch('subprocess.run') + def test_check_dependency_exception(self, mock_run): + mock_run.side_effect = Exception("Test exception") + + result = self.checker.check_dependency("failing_command") + + self.assertFalse(result) + self.assertEqual(len(self.mock_logger.error_calls), 1) + self.assertIn("failing_command", self.mock_logger.error_calls[0]) + + +class TestDependencyValidator(unittest.TestCase): + + def setUp(self): + self.validator = DependencyValidator() + + def test_validate_os_valid(self): + result = self.validator.validate_os("linux") + self.assertEqual(result, "linux") + + result = self.validator.validate_os("darwin") + self.assertEqual(result, "darwin") + + def test_validate_os_invalid(self): + with self.assertRaises(ValueError) as context: + self.validator.validate_os("windows") + + self.assertIn("windows", str(context.exception)) + + def test_validate_package_manager_valid(self): + valid_managers = ["apt", "yum", "dnf", "pacman", "apk", "brew"] + for manager in valid_managers: + result = self.validator.validate_package_manager(manager) + self.assertEqual(result, manager) + + def test_validate_package_manager_invalid(self): + with self.assertRaises(ValueError) as context: + self.validator.validate_package_manager("invalid_manager") + + self.assertIn("invalid_manager", str(context.exception)) + + +class TestDependencyFormatter(unittest.TestCase): + + def setUp(self): + self.formatter = DependencyFormatter() + self.sample_results = [ + DepsCheckResult( + dependency="docker", + timeout=5, + verbose=False, + output="text", + os="linux", + package_manager="apt", + is_available=True + ), + DepsCheckResult( + dependency="kubectl", + timeout=5, + verbose=False, + output="text", + os="linux", + package_manager="apt", + is_available=False + ) + ] + + def test_format_output_text(self): + result = self.formatter.format_output(self.sample_results, "text") + self.assertIn("docker is available", result) + self.assertIn("kubectl is not available", result) + + def test_format_output_json(self): + result = self.formatter.format_output(self.sample_results, "json") + parsed = json.loads(result) + self.assertEqual(len(parsed), 2) + self.assertTrue(parsed[0]["success"]) + self.assertFalse(parsed[1]["success"]) + + def test_format_output_invalid(self): + with self.assertRaises(ValueError): + self.formatter.format_output(self.sample_results, "invalid") + + +class TestDepsCheckResult(unittest.TestCase): + + def test_deps_check_result_creation(self): + result = DepsCheckResult( + dependency="docker", + timeout=5, + verbose=True, + output="json", + os="linux", + package_manager="apt", + is_available=True, + error=None + ) + + self.assertEqual(result.dependency, "docker") + self.assertEqual(result.timeout, 5) + self.assertTrue(result.verbose) + self.assertEqual(result.output, "json") + self.assertEqual(result.os, "linux") + self.assertEqual(result.package_manager, "apt") + self.assertTrue(result.is_available) + self.assertIsNone(result.error) + + def test_deps_check_result_with_error(self): + result = DepsCheckResult( + dependency="failing_dep", + timeout=5, + verbose=False, + output="text", + os="darwin", + package_manager="brew", + is_available=False, + error="Command not found" + ) + + self.assertFalse(result.is_available) + self.assertEqual(result.error, "Command not found") + + +class TestDepsConfig(unittest.TestCase): + + def test_valid_config(self): + config = DepsConfig( + deps=["docker", "kubectl"], + timeout=10, + verbose=True, + output="json", + os="linux", + package_manager="apt" + ) + + self.assertEqual(config.deps, ["docker", "kubectl"]) + self.assertEqual(config.timeout, 10) + self.assertTrue(config.verbose) + self.assertEqual(config.output, "json") + self.assertEqual(config.os, "linux") + self.assertEqual(config.package_manager, "apt") + + def test_config_validation_os(self): + with self.assertRaises(ValueError): + DepsConfig( + deps=["docker"], + os="invalid_os", + package_manager="apt" + ) + + def test_config_validation_package_manager(self): + with self.assertRaises(ValueError): + DepsConfig( + deps=["docker"], + os="linux", + package_manager="invalid_manager" + ) + + def test_config_timeout_validation(self): + with self.assertRaises(ValueError): + DepsConfig( + deps=["docker"], + timeout=0, + os="linux", + package_manager="apt" + ) + + with self.assertRaises(ValueError): + DepsConfig( + deps=["docker"], + timeout=61, + os="linux", + package_manager="apt" + ) + + def test_config_deps_validation(self): + with self.assertRaises(ValueError): + DepsConfig( + deps=[], + os="linux", + package_manager="apt" + ) + + +class TestDepsService(unittest.TestCase): + + def setUp(self): + self.config = DepsConfig( + deps=["docker", "kubectl"], + timeout=5, + verbose=False, + output="text", + os="linux", + package_manager="apt" + ) + self.mock_logger = MockLogger() + self.mock_checker = Mock() + self.service = DepsService( + config=self.config, + logger=self.mock_logger, + checker=self.mock_checker + ) + + def test_create_result(self): + result = self.service._create_result("docker", True) + + self.assertEqual(result.dependency, "docker") + self.assertEqual(result.timeout, 5) + self.assertFalse(result.verbose) + self.assertEqual(result.output, "text") + self.assertEqual(result.os, "linux") + self.assertEqual(result.package_manager, "apt") + self.assertTrue(result.is_available) + self.assertIsNone(result.error) + + def test_create_result_with_error(self): + result = self.service._create_result("failing_dep", False, "Command not found") + + self.assertFalse(result.is_available) + self.assertEqual(result.error, "Command not found") + + def test_check_single_dependency_success(self): + self.mock_checker.check_dependency.return_value = True + + result = self.service._check_dependency("docker") + + self.assertTrue(result.is_available) + self.mock_checker.check_dependency.assert_called_once_with("docker") + + def test_check_single_dependency_failure(self): + self.mock_checker.check_dependency.return_value = False + + result = self.service._check_dependency("nonexistent") + + self.assertFalse(result.is_available) + self.mock_checker.check_dependency.assert_called_once_with("nonexistent") + + def test_check_single_dependency_exception(self): + self.mock_checker.check_dependency.side_effect = Exception("Test error") + + result = self.service._check_dependency("failing_dep") + + self.assertFalse(result.is_available) + self.assertEqual(result.error, "Test error") + + @patch('app.commands.preflight.deps.ParallelProcessor') + def test_check_dependencies(self, mock_parallel_processor): + mock_results = [ + self.service._create_result("docker", True), + self.service._create_result("kubectl", False) + ] + mock_parallel_processor.process_items.return_value = mock_results + + results = self.service.check_dependencies() + + self.assertEqual(len(results), 2) + mock_parallel_processor.process_items.assert_called_once() + + def test_check_and_format(self): + mock_results = [ + self.service._create_result("docker", True), + self.service._create_result("kubectl", False) + ] + + with patch.object(self.service, 'check_dependencies', return_value=mock_results): + result = self.service.check_and_format() + + self.assertIn("docker is available", result) + self.assertIn("kubectl is not available", result) + + +class TestDeps(unittest.TestCase): + + def setUp(self): + self.mock_logger = MockLogger() + self.deps = Deps(logger=self.mock_logger) + + def test_check(self): + config = DepsConfig( + deps=["docker"], + os="linux", + package_manager="apt" + ) + + with patch('app.commands.preflight.deps.DepsService') as mock_service_class: + mock_service = Mock() + mock_results = [Mock()] + mock_service.check_dependencies.return_value = mock_results + mock_service_class.return_value = mock_service + + results = self.deps.check(config) + + self.assertEqual(results, mock_results) + mock_service_class.assert_called_once_with(config, logger=self.mock_logger) + + def test_format_output(self): + mock_results = [Mock()] + + with patch.object(self.deps.formatter, 'format_output', return_value="formatted") as mock_format: + result = self.deps.format_output(mock_results, "text") + + self.assertEqual(result, "formatted") + mock_format.assert_called_once_with(mock_results, "text") + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/cli/tests/port.py b/cli/app/commands/preflight/tests/test_port.py similarity index 91% rename from cli/tests/port.py rename to cli/app/commands/preflight/tests/test_port.py index a7035018..55e5eca9 100644 --- a/cli/tests/port.py +++ b/cli/app/commands/preflight/tests/test_port.py @@ -1,6 +1,6 @@ import pytest from typing import List -from cli.commands.preflight.port import PortConfig, PortCheckResult +from app.commands.preflight.port import PortConfig, PortCheckResult, PortService class TestPort: def test_valid_ports(self): @@ -50,7 +50,8 @@ def test_invalid_host_invalid_domain(self): def test_check_ports_basic(self): config = PortConfig(ports=[80, 443], host="localhost", timeout=1, verbose=False) - results = PortConfig.check_ports(config) + port_service = PortService(config) + results = port_service.check_ports() assert len(results) == 2 assert all("port" in result for result in results) assert all("status" in result for result in results) @@ -60,7 +61,8 @@ def test_check_ports_basic(self): def test_check_ports_verbose(self): config = PortConfig(ports=[80, 443], host="localhost", timeout=1, verbose=True) - results = PortConfig.check_ports(config) + port_service = PortService(config) + results = port_service.check_ports() assert len(results) == 2 assert all("port" in result for result in results) assert all("status" in result for result in results) @@ -88,7 +90,8 @@ def test_port_check_result_type(): def test_check_ports_return_type(): """Test that check_ports returns correct type""" config = PortConfig(ports=[8080, 3000], host="localhost", timeout=1, verbose=False) - results: List[PortCheckResult] = PortConfig.check_ports(config) + port_service = PortService(config) + results: List[PortCheckResult] = port_service.check_ports() assert isinstance(results, list) for result in results: diff --git a/cli/commands/test/__init__.py b/cli/app/commands/test/__init__.py similarity index 100% rename from cli/commands/test/__init__.py rename to cli/app/commands/test/__init__.py diff --git a/cli/commands/test/command.py b/cli/app/commands/test/command.py similarity index 77% rename from cli/commands/test/command.py rename to cli/app/commands/test/command.py index 29df8096..2da72a5d 100644 --- a/cli/commands/test/command.py +++ b/cli/app/commands/test/command.py @@ -1,5 +1,5 @@ import typer -from core.test.test import test_command +from .test import TestCommand from .messages import test_app_help test_app = typer.Typer( @@ -11,4 +11,5 @@ def test_callback(ctx: typer.Context, target: str = typer.Argument(None, help="Test target (e.g., version)")): """Run tests (only in DEVELOPMENT environment)""" if ctx.invoked_subcommand is None: - test_command(target) + test_command = TestCommand() + test_command.run(target) diff --git a/cli/app/commands/test/messages.py b/cli/app/commands/test/messages.py new file mode 100644 index 00000000..5dcc633c --- /dev/null +++ b/cli/app/commands/test/messages.py @@ -0,0 +1,3 @@ +test_app_help = "Run tests (only in DEVELOPMENT environment)" +development_only_error = "Test command is only available in DEVELOPMENT environment." +running_command = "Running: {command}" diff --git a/cli/app/commands/test/test.py b/cli/app/commands/test/test.py new file mode 100644 index 00000000..574b0376 --- /dev/null +++ b/cli/app/commands/test/test.py @@ -0,0 +1,21 @@ +import typer +import subprocess +from app.utils.config import Config +from app.utils.logger import Logger +from .messages import development_only_error, running_command + +class TestCommand: + def __init__(self): + self.config = Config() + self.logger = Logger() + + def run(self, target: str = typer.Argument(None, help="Test target (e.g., version)")): + if not self.config.is_development(): + self.logger.error(development_only_error) + raise typer.Exit(1) + cmd = ["make", "test"] + if target: + cmd.append(f"test-{target}") + self.logger.info(running_command.format(command=' '.join(cmd))) + result = subprocess.run(cmd) + raise typer.Exit(result.returncode) diff --git a/cli/commands/version/__init__.py b/cli/app/commands/version/__init__.py similarity index 100% rename from cli/commands/version/__init__.py rename to cli/app/commands/version/__init__.py diff --git a/cli/commands/version/command.py b/cli/app/commands/version/command.py similarity index 59% rename from cli/commands/version/command.py rename to cli/app/commands/version/command.py index 83cc0211..9573f9a6 100644 --- a/cli/commands/version/command.py +++ b/cli/app/commands/version/command.py @@ -1,6 +1,6 @@ import typer -from core.version.version import display_version -from utils.message import application_version_help +from .version import VersionCommand +from app.utils.message import application_version_help version_app = typer.Typer( help=application_version_help, @@ -11,9 +11,11 @@ def version_callback(ctx: typer.Context): """Show version information (default)""" if ctx.invoked_subcommand is None: - display_version() + version_command = VersionCommand() + version_command.run() def main_version_callback(value: bool): if value: - display_version() + version_command = VersionCommand() + version_command.run() raise typer.Exit() diff --git a/cli/app/commands/version/tests/test_version.py b/cli/app/commands/version/tests/test_version.py new file mode 100644 index 00000000..5958368f --- /dev/null +++ b/cli/app/commands/version/tests/test_version.py @@ -0,0 +1,171 @@ +import pytest +from unittest.mock import patch, MagicMock +from importlib.metadata import version +from app.commands.version.version import VersionCommand + + +class TestVersionCommand: + """Test cases for the VersionCommand class""" + + @patch('app.commands.version.version.Console') + @patch('app.commands.version.version.version') + def test_version_command_success(self, mock_version, mock_console_class): + """Test successful version display""" + mock_version.return_value = "1.0.0" + mock_console = MagicMock() + mock_console_class.return_value = mock_console + + version_command = VersionCommand() + version_command.run() + + mock_version.assert_called_once_with('nixopus') + mock_console.print.assert_called_once() + + call_args = mock_console.print.call_args[0][0] + assert call_args.title == "[bold white]Version Info[/bold white]" + assert call_args.border_style == "blue" + assert call_args.padding == (0, 1) + + @patch('app.commands.version.version.Console') + @patch('app.commands.version.version.version') + def test_version_command_with_different_versions(self, mock_version, mock_console_class): + """Test version display with different version numbers""" + test_versions = ["0.1.0", "2.3.4", "1.0.0-beta"] + mock_console = MagicMock() + mock_console_class.return_value = mock_console + + for test_version in test_versions: + mock_version.return_value = test_version + mock_console.reset_mock() + + version_command = VersionCommand() + version_command.run() + + mock_version.assert_called_with('nixopus') + mock_console.print.assert_called_once() + + @patch('app.commands.version.version.Console') + @patch('app.commands.version.version.version') + def test_version_command_panel_content(self, mock_version, mock_console_class): + """Test that panel contains correct text content""" + mock_version.return_value = "1.2.3" + mock_console = MagicMock() + mock_console_class.return_value = mock_console + + version_command = VersionCommand() + version_command.run() + + call_args = mock_console.print.call_args[0][0] + panel_content = call_args.renderable + + assert "Nixopus CLI" in str(panel_content) + assert "v1.2.3" in str(panel_content) + + @patch('app.commands.version.version.Console') + @patch('app.commands.version.version.version') + def test_version_command_handles_version_error(self, mock_version, mock_console_class): + """Test handling of version import error""" + mock_version.side_effect = Exception("Version not found") + mock_console = MagicMock() + mock_console_class.return_value = mock_console + + with pytest.raises(Exception): + version_command = VersionCommand() + version_command.run() + + mock_version.assert_called_once_with('nixopus') + + @patch('app.commands.version.version.Console') + @patch('app.commands.version.version.version') + def test_version_command_console_error_handling(self, mock_version, mock_console_class): + """Test handling of console print errors""" + mock_version.return_value = "1.0.0" + mock_console = MagicMock() + mock_console.print.side_effect = Exception("Console error") + mock_console_class.return_value = mock_console + + with pytest.raises(Exception): + version_command = VersionCommand() + version_command.run() + + mock_version.assert_called_once_with('nixopus') + mock_console.print.assert_called_once() + + +class TestVersionCommandClass: + """Test cases for VersionCommand class structure""" + + def test_version_command_initialization(self): + """Test that VersionCommand can be instantiated""" + with patch('app.commands.version.version.Console'): + version_command = VersionCommand() + assert hasattr(version_command, 'console') + + def test_version_command_run_method(self): + """Test that VersionCommand has a run method""" + with patch('app.commands.version.version.Console'): + version_command = VersionCommand() + assert hasattr(version_command, 'run') + assert callable(version_command.run) + + def test_version_command_run_returns_none(self): + """Test that run method returns None""" + with patch('app.commands.version.version.Console'): + with patch('app.commands.version.version.version', return_value="1.0.0"): + version_command = VersionCommand() + result = version_command.run() + assert result is None + + +class TestVersionModuleImports: + """Test cases for module imports and dependencies""" + + def test_import_metadata_version(self): + """Test that importlib.metadata.version is available""" + try: + from importlib.metadata import version + assert callable(version) + except ImportError: + pytest.skip("importlib.metadata not available") + + def test_rich_console_import(self): + """Test that rich.console.Console is available""" + try: + from rich.console import Console + assert callable(Console) + except ImportError: + pytest.skip("rich.console not available") + + def test_rich_panel_import(self): + """Test that rich.panel.Panel is available""" + try: + from rich.panel import Panel + assert callable(Panel) + except ImportError: + pytest.skip("rich.panel not available") + + def test_rich_text_import(self): + """Test that rich.text.Text is available""" + try: + from rich.text import Text + assert callable(Text) + except ImportError: + pytest.skip("rich.text not available") + + +class TestVersionCommandSignature: + """Test cases for class method signature and behavior""" + + def test_version_command_is_instantiable(self): + """Test that VersionCommand can be instantiated""" + with patch('app.commands.version.version.Console'): + version_command = VersionCommand() + assert isinstance(version_command, VersionCommand) + + def test_run_method_no_parameters(self): + """Test that run method takes no parameters""" + import inspect + with patch('app.commands.version.version.Console'): + version_command = VersionCommand() + sig = inspect.signature(version_command.run) + assert len(sig.parameters) == 0 diff --git a/cli/app/commands/version/version.py b/cli/app/commands/version/version.py new file mode 100644 index 00000000..30dc531a --- /dev/null +++ b/cli/app/commands/version/version.py @@ -0,0 +1,25 @@ +from rich.console import Console +from rich.panel import Panel +from rich.text import Text +from importlib.metadata import version + +class VersionCommand: + def __init__(self): + self.console = Console() + + def run(self): + """Display the version of the CLI""" + cli_version = version('nixopus') + + version_text = Text() + version_text.append("Nixopus CLI", style="bold blue") + version_text.append(f" v{cli_version}", style="green") + + panel = Panel( + version_text, + title="[bold white]Version Info[/bold white]", + border_style="blue", + padding=(0, 1) + ) + + self.console.print(panel) diff --git a/cli/main.py b/cli/app/main.py similarity index 56% rename from cli/main.py rename to cli/app/main.py index 08fc5d10..cc18cecb 100644 --- a/cli/main.py +++ b/cli/app/main.py @@ -1,8 +1,9 @@ import typer -from commands.version.command import version_app, main_version_callback -from commands.preflight.command import preflight_app -from commands.test.command import test_app -from utils.message import application_name, application_description, application_no_args_is_help, application_add_completion, application_version_help +from app.commands.version.command import version_app, main_version_callback +from app.commands.preflight.command import preflight_app +from app.commands.test.command import test_app +from app.commands.install.command import install_app +from app.utils.message import application_name, application_description, application_add_completion, application_version_help app = typer.Typer( name=application_name, @@ -25,6 +26,7 @@ def main( app.add_typer(test_app, name="test") app.add_typer(preflight_app, name="preflight") app.add_typer(version_app, name="version") +app.add_typer(install_app, name="install") if __name__ == "__main__": app() diff --git a/cli/utils/__init__.py b/cli/app/utils/__init__.py similarity index 100% rename from cli/utils/__init__.py rename to cli/app/utils/__init__.py diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py new file mode 100644 index 00000000..87a34e5f --- /dev/null +++ b/cli/app/utils/config.py @@ -0,0 +1,11 @@ +import os + +class Config: + def __init__(self, default_env="PRODUCTION"): + self.default_env = default_env + + def get_env(self): + return os.environ.get("ENV", self.default_env) + + def is_development(self): + return self.get_env().upper() == "DEVELOPMENT" diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py new file mode 100644 index 00000000..32e4970f --- /dev/null +++ b/cli/app/utils/lib.py @@ -0,0 +1,129 @@ +from enum import Enum +import platform +import subprocess +import os +import shutil +from typing import TypeVar, Callable, List +from concurrent.futures import ThreadPoolExecutor, as_completed +from app.utils.message import REMOVED_DIRECTORY_MESSAGE, FAILED_TO_REMOVE_DIRECTORY_MESSAGE + +T = TypeVar('T') +R = TypeVar('R') + +class SupportedOS(str, Enum): + LINUX = "linux" + MACOS = "darwin" + +class SupportedDistribution(str, Enum): + DEBIAN = "debian" + UBUNTU = "ubuntu" + CENTOS = "centos" + FEDORA = "fedora" + ALPINE = "alpine" + +class SupportedPackageManager(str, Enum): + APT = "apt" + YUM = "yum" + DNF = "dnf" + PACMAN = "pacman" + APK = "apk" + BREW = "brew" + +class Supported: + @staticmethod + def os(os_name: str) -> bool: + return os_name in [os.value for os in SupportedOS] + + @staticmethod + def distribution(distribution: str) -> bool: + return distribution in [dist.value for dist in SupportedDistribution] + + @staticmethod + def package_manager(package_manager: str) -> bool: + return package_manager in [pm.value for pm in SupportedPackageManager] + + @staticmethod + def get_os(): + return [os.value for os in SupportedOS] + + @staticmethod + def get_distributions(): + return [dist.value for dist in SupportedDistribution] + +class HostInformation: + @staticmethod + def get_os_name(): + return platform.system().lower() + + @staticmethod + def get_package_manager(): + os_name = HostInformation.get_os_name() + + if os_name == SupportedOS.MACOS.value: + return SupportedPackageManager.BREW.value + + package_managers = [pm.value for pm in SupportedPackageManager if pm != SupportedPackageManager.BREW] + + for pm in package_managers: + if HostInformation.command_exists(pm): + return pm + + return None + + @staticmethod + def command_exists(command): + try: + result = subprocess.run(["command", "-v", command], + capture_output=True, text=True, check=False) + return result.returncode == 0 + except Exception: + return False + +class ParallelProcessor: + @staticmethod + def process_items( + items: List[T], + processor_func: Callable[[T], R], + max_workers: int = 50, + error_handler: Callable[[T, Exception], R] = None + ) -> List[R]: + if not items: + return [] + + results = [] + max_workers = min(len(items), max_workers) + + with ThreadPoolExecutor(max_workers=max_workers) as executor: + futures = {executor.submit(processor_func, item): item for item in items} + + for future in as_completed(futures): + try: + result = future.result() + results.append(result) + except Exception as e: + item = futures[future] + if error_handler: + error_result = error_handler(item, e) + results.append(error_result) + return results + +class DirectoryManager: + @staticmethod + def path_exists(path: str) -> bool: + return os.path.exists(path) + + @staticmethod + def path_exists_and_not_force(path: str, force: bool) -> bool: + return os.path.exists(path) and not force + + @staticmethod + def remove_directory(path: str, logger=None) -> bool: + try: + shutil.rmtree(path) + if logger: + logger.info(REMOVED_DIRECTORY_MESSAGE.format(path=path)) + return True + except Exception as e: + if logger: + logger.error(FAILED_TO_REMOVE_DIRECTORY_MESSAGE.format(path=path, error=e)) + return False diff --git a/cli/utils/logger.py b/cli/app/utils/logger.py similarity index 100% rename from cli/utils/logger.py rename to cli/app/utils/logger.py diff --git a/cli/utils/message.py b/cli/app/utils/message.py similarity index 72% rename from cli/utils/message.py rename to cli/app/utils/message.py index d5ccacd1..825d3fc5 100644 --- a/cli/utils/message.py +++ b/cli/app/utils/message.py @@ -6,10 +6,11 @@ application_no_args_is_help = True application_add_completion = False application_version_help = "Show version information" - INFO_MESSAGE = "INFO: {message}" DEBUG_MESSAGE = "DEBUG: {message}" WARNING_MESSAGE = "WARNING: {message}" ERROR_MESSAGE = "ERROR: {message}" SUCCESS_MESSAGE = "SUCCESS: {message}" -HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" \ No newline at end of file +HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" +REMOVED_DIRECTORY_MESSAGE = "Removed existing directory: {path}" +FAILED_TO_REMOVE_DIRECTORY_MESSAGE = "Failed to remove directory: {path}" \ No newline at end of file diff --git a/cli/app/utils/output_formatter.py b/cli/app/utils/output_formatter.py new file mode 100644 index 00000000..bb349e6a --- /dev/null +++ b/cli/app/utils/output_formatter.py @@ -0,0 +1,48 @@ +import json +from typing import Any, Dict, Optional +from pydantic import BaseModel + +class OutputMessage(BaseModel): + success: bool + message: str + data: Optional[Dict[str, Any]] = None + error: Optional[str] = None + +class OutputFormatter: + def __init__(self, invalid_output_format_msg: str = "Invalid output format"): + self.invalid_output_format_msg = invalid_output_format_msg + + def format_text(self, result: Any) -> str: + if isinstance(result, OutputMessage): + if result.success: + return result.message + else: + return f"Error: {result.error or 'Unknown error'}" + elif isinstance(result, list): + return "\n".join([self.format_text(item) for item in result]) + else: + return str(result) + + def format_json(self, result: Any) -> str: + if isinstance(result, OutputMessage): + return json.dumps(result.model_dump(), indent=2) + elif isinstance(result, list): + return json.dumps([item.model_dump() if hasattr(item, 'model_dump') else item for item in result], indent=2) + elif isinstance(result, BaseModel): + return json.dumps(result.model_dump(), indent=2) + else: + return json.dumps(result, indent=2) + + def format_output(self, result: Any, output: str) -> str: + if output == "text": + return self.format_text(result) + elif output == "json": + return self.format_json(result) + else: + raise ValueError(self.invalid_output_format_msg) + + def create_success_message(self, message: str, data: Optional[Dict[str, Any]] = None) -> OutputMessage: + return OutputMessage(success=True, message=message, data=data) + + def create_error_message(self, error: str, data: Optional[Dict[str, Any]] = None) -> OutputMessage: + return OutputMessage(success=False, message="", error=error, data=data) diff --git a/cli/app/utils/protocols.py b/cli/app/utils/protocols.py new file mode 100644 index 00000000..0e64e135 --- /dev/null +++ b/cli/app/utils/protocols.py @@ -0,0 +1,15 @@ +from typing import Protocol + +class LoggerProtocol(Protocol): + def debug(self, message: str) -> None: + ... + def info(self, message: str) -> None: + ... + def warning(self, message: str) -> None: + ... + def error(self, message: str) -> None: + ... + def success(self, message: str) -> None: + ... + def highlight(self, message: str) -> None: + ... \ No newline at end of file diff --git a/cli/app/utils/tests/test_processor.py b/cli/app/utils/tests/test_processor.py new file mode 100644 index 00000000..7101862d --- /dev/null +++ b/cli/app/utils/tests/test_processor.py @@ -0,0 +1,81 @@ +import unittest +import time +from app.utils.lib import ParallelProcessor + +class TestParallelProcessor(unittest.TestCase): + + def test_basic_processing(self): + """Test basic parallel processing functionality""" + def square(x): + return x * x + + items = [1, 2, 3, 4, 5] + results = ParallelProcessor.process_items(items, square) + + # Results are in completion order, not input order + self.assertEqual(len(results), 5) + self.assertEqual(set(results), {1, 4, 9, 16, 25}) + + def test_error_handling(self): + """Test error handling in parallel processing""" + def process_with_error(x): + if x == 3: + raise ValueError("Test error") + return x * 2 + + def error_handler(item, error): + return f"Error processing {item}: {str(error)}" + + items = [1, 2, 3, 4, 5] + results = ParallelProcessor.process_items( + items, + process_with_error, + error_handler=error_handler + ) + + self.assertEqual(len(results), 5) + # Check that we have the expected results (order may vary) + expected_results = {2, 4, 8, 10} # 1*2, 2*2, 4*2, 5*2 + error_results = [r for r in results if "Error processing 3" in str(r)] + normal_results = [r for r in results if isinstance(r, int)] + + self.assertEqual(len(error_results), 1) + self.assertEqual(set(normal_results), expected_results) + + def test_timeout_behavior(self): + """Test that processing respects timeout behavior""" + def slow_process(x): + time.sleep(0.1) + return x * 2 + + items = list(range(10)) + start_time = time.time() + results = ParallelProcessor.process_items(items, slow_process, max_workers=5) + end_time = time.time() + + self.assertEqual(len(results), 10) + # Results are in completion order, not input order + self.assertEqual(set(results), {0, 2, 4, 6, 8, 10, 12, 14, 16, 18}) + + # With 5 workers and 10 items taking 0.1s each, should complete in ~0.2s + # (2 batches of 5 items each) + self.assertLess(end_time - start_time, 0.5) + + def test_empty_list(self): + """Test processing empty list""" + def process(x): + return x * 2 + + results = ParallelProcessor.process_items([], process) + self.assertEqual(results, []) + + def test_single_item(self): + """Test processing single item""" + def process(x): + return x * 2 + + results = ParallelProcessor.process_items([5], process) + self.assertEqual(results, [10]) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/cli/commands/preflight/command.py b/cli/commands/preflight/command.py deleted file mode 100644 index dd9f7023..00000000 --- a/cli/commands/preflight/command.py +++ /dev/null @@ -1,41 +0,0 @@ -import typer -from .messages import running_preflight_checks -from .port import PortConfig, PortCheckResult -from utils.logger import Logger - -preflight_app = typer.Typer(no_args_is_help=False) - -@preflight_app.callback(invoke_without_command=True) -def preflight_callback(ctx: typer.Context): - """Preflight checks for system compatibility""" - if ctx.invoked_subcommand is None: - ctx.invoke(check) - -@preflight_app.command() -def check( - verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), - output: str = typer.Option("text", "--output", "-o", help="Output format, text,json"), -): - """Run all preflight checks""" - logger = Logger(verbose=verbose) - logger.info(PortConfig.format(running_preflight_checks, output)) - -@preflight_app.command() -def ports( - ports: list[int] = typer.Argument(..., help="The list of ports to check"), - host: str = typer.Option("localhost", "--host", "-h", help="The host to check"), - timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each port check"), - verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), - output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), -) -> list[PortCheckResult]: - """Check if list of ports are available on a host""" - try: - logger = Logger(verbose=verbose) - logger.debug(f"Checking ports: {ports}") - config = PortConfig(ports=ports, host=host, timeout=timeout, verbose=verbose) - results = PortConfig.check_ports(config) - logger.success(PortConfig.format(results, output)) - return results - except Exception as e: - logger.error(f"Error checking ports: {e}") - raise typer.Exit(1) diff --git a/cli/commands/preflight/port.py b/cli/commands/preflight/port.py deleted file mode 100644 index b4ec3c9c..00000000 --- a/cli/commands/preflight/port.py +++ /dev/null @@ -1,88 +0,0 @@ -import re, json -from typing import List, TypedDict, Union, Any -from concurrent.futures import ThreadPoolExecutor, as_completed -from pydantic import BaseModel, Field, field_validator -from .messages import available, not_available, error_checking_port, host_must_be_localhost_or_valid_ip_or_domain -from core.preflight.port import is_port_available -from utils.logger import Logger - -class PortCheckResult(TypedDict): - port: int - status: str - host: str | None - error: str | None - is_available: bool - -class PortConfig(BaseModel): - ports: List[int] = Field(..., min_length=1, max_length=65535, description="List of ports to check") - host: str = Field("localhost", min_length=1, description="Host to check") - timeout: int = Field(1, gt=0, le=60, description="Timeout in seconds") - verbose: bool = Field(False, description="Verbose output") - - @field_validator('host') - @classmethod - def validate_host(cls, v: str) -> str: - """Validate host is localhost, valid IP address, or domain name""" - if v.lower() == "localhost": - return v - - # IP address validation regex - ip_pattern = r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' - if re.match(ip_pattern, v): - return v - - # Domain name validation regex - domain_pattern = r'^[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*$' - if re.match(domain_pattern, v): - return v - - raise ValueError(host_must_be_localhost_or_valid_ip_or_domain) - - @staticmethod - def format(data: Union[str, List[PortCheckResult], Any], output_type: str) -> str: - """Format output based on output type""" - if output_type == "json": - return json.dumps(data, indent=4) - elif output_type == "text" and isinstance(data, list): - return "\n".join([f"Port {item['port']}: {item['status']}" for item in data]) - else: - return str(data) - - @staticmethod - def check_ports(config: "PortConfig") -> List[PortCheckResult]: - """Check if ports are available""" - logger = Logger(verbose=config.verbose) - results = [] - - def check_single_port(port: int) -> PortCheckResult: - """Check availability of a single port""" - logger.debug(f"Checking port {port} on host {config.host}") - status = available if is_port_available(config.host, port, config.timeout) else not_available - return { - "port": port, - "status": status, - "host": config.host if config.verbose else None, - "error": None, - "is_available": status == available - } - - max_workers = min(len(config.ports), 50) - with ThreadPoolExecutor(max_workers=max_workers) as executor: - port_futures = {executor.submit(check_single_port, port): port for port in config.ports} - - for future in as_completed(port_futures): - try: - result = future.result() - results.append(result) - except Exception as e: - port = port_futures[future] - logger.error(error_checking_port.format(port=port, error=str(e))) - results.append({ - "port": port, - "status": not_available, - "host": config.host if config.verbose else None, - "error": str(e), - "is_available": False - }) - - return sorted(results, key=lambda x: x["port"]) diff --git a/cli/commands/test/messages.py b/cli/commands/test/messages.py deleted file mode 100644 index f4caa568..00000000 --- a/cli/commands/test/messages.py +++ /dev/null @@ -1 +0,0 @@ -test_app_help = "Run tests (only in DEVELOPMENT environment)" diff --git a/cli/core/__init__.py b/cli/core/__init__.py deleted file mode 100644 index 92ca5160..00000000 --- a/cli/core/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# cli core module diff --git a/cli/core/config.py b/cli/core/config.py deleted file mode 100644 index 9152d192..00000000 --- a/cli/core/config.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -def get_env(default="PRODUCTION"): - return os.environ.get("ENV", default) - -def is_development(): - return get_env().upper() == "DEVELOPMENT" diff --git a/cli/core/preflight/port.py b/cli/core/preflight/port.py deleted file mode 100644 index fb3ad84d..00000000 --- a/cli/core/preflight/port.py +++ /dev/null @@ -1,11 +0,0 @@ -import socket - -def is_port_available(host: str, port: int, timeout: int = 1) -> bool: - """Check if a port is available on the specified host""" - try: - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: - sock.settimeout(timeout) - result = sock.connect_ex((host, port)) - return result != 0 - except Exception: - return False \ No newline at end of file diff --git a/cli/core/test/__init__.py b/cli/core/test/__init__.py deleted file mode 100644 index 26ebd1cc..00000000 --- a/cli/core/test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# cli core test module diff --git a/cli/core/test/test.py b/cli/core/test/test.py deleted file mode 100644 index 6aa00cd9..00000000 --- a/cli/core/test/test.py +++ /dev/null @@ -1,14 +0,0 @@ -import typer -import subprocess -from core.config import is_development - -def test_command(target: str = typer.Argument(None, help="Test target (e.g., version)")): - if not is_development(): - typer.echo("Test command is only available in DEVELOPMENT environment.") - raise typer.Exit(1) - cmd = ["venv/bin/python", "-m", "pytest"] - if target: - cmd.append(f"tests/{target}.py") - typer.echo(f"Running: {' '.join(cmd)}") - result = subprocess.run(cmd) - raise typer.Exit(result.returncode) diff --git a/cli/core/version/version.py b/cli/core/version/version.py deleted file mode 100644 index df6af201..00000000 --- a/cli/core/version/version.py +++ /dev/null @@ -1,23 +0,0 @@ -from rich.console import Console -from rich.panel import Panel -from rich.text import Text -from importlib.metadata import version - -console = Console() - -def display_version(): - """Display the version of the CLI""" - cli_version = version('nixopus') - - version_text = Text() - version_text.append("Nixopus CLI", style="bold blue") - version_text.append(f" v{cli_version}", style="green") - - panel = Panel( - version_text, - title="[bold white]Version Info[/bold white]", - border_style="blue", - padding=(0, 1) - ) - - console.print(panel) diff --git a/cli/pyproject.toml b/cli/pyproject.toml index e83c8686..eb202668 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "A CLI for Nixopus" authors = ["Nixopus "] readme = "README.md" -packages = [{include = "cli"}] +packages = [{include = "app"}] [tool.poetry.dependencies] python = "^3.9.0" @@ -21,7 +21,7 @@ black = "^25.1.0" isort = "^6.0.1" [tool.poetry.scripts] -nixopus = "cli.main:main" +nixopus = "app.main:app" [build-system] requires = ["poetry-core"] @@ -32,7 +32,7 @@ testpaths = ["tests"] python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] -addopts = "-v --cov=core --cov=utils --cov-report=term-missing" +addopts = "-v --cov=app --cov-report=term-missing" [tool.black] line-length = 127 diff --git a/cli/tests/__init__.py b/cli/tests/__init__.py deleted file mode 100644 index c6c429dc..00000000 --- a/cli/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# cli tests module diff --git a/cli/tests/test_commands_version.py b/cli/tests/test_commands_version.py deleted file mode 100644 index 7b6f519e..00000000 --- a/cli/tests/test_commands_version.py +++ /dev/null @@ -1,117 +0,0 @@ -import pytest -from unittest.mock import patch, MagicMock -from commands.version.command import version_callback, main_version_callback -import typer - - -class TestVersionCommand: - """Test cases for the main_version_callback function""" - - @patch('commands.version.command.display_version') - def test_version_command_calls_display_version(self, mock_display_version): - """Test that main_version_callback calls display_version""" - with pytest.raises(typer.Exit): - main_version_callback(True) - - mock_display_version.assert_called_once() - - @patch('commands.version.command.display_version') - def test_version_command_returns_none(self, mock_display_version): - """Test that main_version_callback exits after calling display_version""" - with pytest.raises(typer.Exit): - main_version_callback(True) - - mock_display_version.assert_called_once() - - -class TestVersionCallback: - """Test cases for the version_callback function""" - - @patch('commands.version.command.display_version') - def test_version_callback_with_true_value(self, mock_display_version): - """Test version_callback with True value calls display_version and exits""" - with pytest.raises(typer.Exit): - main_version_callback(True) - - mock_display_version.assert_called_once() - - @patch('commands.version.command.display_version') - def test_version_callback_with_false_value(self, mock_display_version): - """Test main_version_callback with False value does nothing""" - main_version_callback(False) - - mock_display_version.assert_not_called() - - @patch('commands.version.command.display_version') - def test_version_callback_with_none_value(self, mock_display_version): - """Test main_version_callback with None value does nothing""" - main_version_callback(None) - - mock_display_version.assert_not_called() - - @patch('commands.version.command.display_version') - def test_version_callback_exits_after_version_command(self, mock_display_version): - """Test that main_version_callback raises typer.Exit after calling display_version""" - mock_display_version.return_value = None - - with pytest.raises(typer.Exit): - main_version_callback(True) - - mock_display_version.assert_called_once() - - @patch('commands.version.command.display_version') - def test_version_callback_handles_version_command_exception(self, mock_display_version): - """Test that main_version_callback still exits even if display_version raises an exception""" - mock_display_version.side_effect = Exception("Display version error") - - with pytest.raises(Exception, match="Display version error"): - main_version_callback(True) - - mock_display_version.assert_called_once() - - -class TestVersionCommandIntegration: - """Integration test cases for version commands""" - - @patch('commands.version.command.display_version') - def test_version_command_integration(self, mock_display_version): - """Integration test for main_version_callback calling display_version""" - with pytest.raises(typer.Exit): - main_version_callback(True) - - mock_display_version.assert_called_once() - - @patch('commands.version.command.display_version') - def test_version_callback_integration(self, mock_display_version): - """Integration test for main_version_callback calling display_version""" - with pytest.raises(typer.Exit): - main_version_callback(True) - - mock_display_version.assert_called_once() - - -class TestVersionFunctionSignatures: - """Test cases for function signatures and behavior""" - - def test_version_command_is_callable(self): - """Test that main_version_callback is a callable function""" - assert callable(main_version_callback) - - def test_version_callback_is_callable(self): - """Test that version_callback is a callable function""" - assert callable(version_callback) - - def test_version_command_no_parameters(self): - """Test that main_version_callback takes one parameter""" - import inspect - sig = inspect.signature(main_version_callback) - assert len(sig.parameters) == 1 - assert 'value' in sig.parameters - assert sig.parameters['value'].annotation == bool - - def test_version_callback_parameter(self): - """Test that version_callback takes one parameter""" - import inspect - sig = inspect.signature(version_callback) - assert len(sig.parameters) == 1 - assert 'ctx' in sig.parameters diff --git a/cli/tests/version.py b/cli/tests/version.py deleted file mode 100644 index b7d89fb6..00000000 --- a/cli/tests/version.py +++ /dev/null @@ -1,134 +0,0 @@ -import pytest -from unittest.mock import patch, MagicMock -from importlib.metadata import version -from core.version.version import display_version - - -class TestDisplayVersion: - """Test cases for the display_version function""" - - @patch('core.version.version.console') - @patch('core.version.version.version') - def test_display_version_success(self, mock_version, mock_console): - """Test successful version display""" - mock_version.return_value = "1.0.0" - - display_version() - - mock_version.assert_called_once_with('nixopus') - mock_console.print.assert_called_once() - - call_args = mock_console.print.call_args[0][0] - assert call_args.title == "[bold white]Version Info[/bold white]" - assert call_args.border_style == "blue" - assert call_args.padding == (0, 1) - - @patch('core.version.version.console') - @patch('core.version.version.version') - def test_display_version_with_different_versions(self, mock_version, mock_console): - """Test version display with different version numbers""" - test_versions = ["0.1.0", "2.3.4", "1.0.0-beta"] - - for test_version in test_versions: - mock_version.return_value = test_version - mock_console.reset_mock() - - display_version() - - mock_version.assert_called_with('nixopus') - mock_console.print.assert_called_once() - - @patch('core.version.version.console') - @patch('core.version.version.version') - def test_display_version_panel_content(self, mock_version, mock_console): - """Test that panel contains correct text content""" - mock_version.return_value = "1.2.3" - - display_version() - - call_args = mock_console.print.call_args[0][0] - panel_content = call_args.renderable - - assert "Nixopus CLI" in str(panel_content) - assert "v1.2.3" in str(panel_content) - - @patch('core.version.version.console') - @patch('core.version.version.version') - def test_display_version_handles_version_error(self, mock_version, mock_console): - """Test handling of version import error""" - mock_version.side_effect = Exception("Version not found") - - with pytest.raises(Exception): - display_version() - - mock_version.assert_called_once_with('nixopus') - - @patch('core.version.version.console') - @patch('core.version.version.version') - def test_display_version_console_error_handling(self, mock_version, mock_console): - """Test handling of console print errors""" - mock_version.return_value = "1.0.0" - mock_console.print.side_effect = Exception("Console error") - - with pytest.raises(Exception): - display_version() - - mock_version.assert_called_once_with('nixopus') - mock_console.print.assert_called_once() - - -class TestVersionModuleImports: - """Test cases for module imports and dependencies""" - - def test_import_metadata_version(self): - """Test that importlib.metadata.version is available""" - try: - from importlib.metadata import version - assert callable(version) - except ImportError: - pytest.skip("importlib.metadata not available") - - def test_rich_console_import(self): - """Test that rich.console.Console is available""" - try: - from rich.console import Console - assert callable(Console) - except ImportError: - pytest.skip("rich.console not available") - - def test_rich_panel_import(self): - """Test that rich.panel.Panel is available""" - try: - from rich.panel import Panel - assert callable(Panel) - except ImportError: - pytest.skip("rich.panel not available") - - def test_rich_text_import(self): - """Test that rich.text.Text is available""" - try: - from rich.text import Text - assert callable(Text) - except ImportError: - pytest.skip("rich.text not available") - - -class TestVersionFunctionSignature: - """Test cases for function signature and behavior""" - - def test_display_version_is_callable(self): - """Test that display_version is a callable function""" - assert callable(display_version) - - def test_display_version_no_parameters(self): - """Test that display_version takes no parameters""" - import inspect - sig = inspect.signature(display_version) - assert len(sig.parameters) == 0 - - def test_display_version_returns_none(self): - """Test that display_version returns None""" - with patch('core.version.version.console'): - with patch('core.version.version.version', return_value="1.0.0"): - result = display_version() - assert result is None From bb9521fbbf5676f4eaddb230e556aa78e9c171e5 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Mon, 14 Jul 2025 23:09:00 +0530 Subject: [PATCH 35/72] feat : service management CLI command (#283) * feat: nixopus preflight dependency checker * chore: update function name from check_single_dependency to check_dependency * refactor: CLI Project Structure (#277) * refactor: cli folder structure and update imports accordingly * refactor: finalized cli project structure * chore: update preflight to have common shared logger protocol * feat : Install Command to Clone the Nixopus Git Repository (#279) * feat: add command for ssh key management for nixopus * feat: nixopus service commands outline scaffloding * feat: nixopus service management commands * fix : failing tests on install commands (#285) * fix: test failures * feat : configuration management cli commands (#284) * feat: add commands and test files for managing configurations * feat: cli command for managing nixopus proxy services (#286) --- cli/app/commands/conf/__init__.py | 0 cli/app/commands/conf/base.py | 215 +++++++++ cli/app/commands/conf/command.py | 112 +++++ cli/app/commands/conf/delete.py | 142 ++++++ cli/app/commands/conf/list.py | 129 +++++ cli/app/commands/conf/messages.py | 30 ++ cli/app/commands/conf/set.py | 146 ++++++ cli/app/commands/conf/tests/__init__.py | 1 + cli/app/commands/conf/tests/test_base.py | 420 ++++++++++++++++ cli/app/commands/conf/tests/test_delete.py | 343 ++++++++++++++ cli/app/commands/conf/tests/test_list.py | 311 ++++++++++++ cli/app/commands/conf/tests/test_set.py | 357 ++++++++++++++ cli/app/commands/install/clone.py | 8 +- cli/app/commands/install/command.py | 51 +- cli/app/commands/install/messages.py | 29 ++ cli/app/commands/install/ssh.py | 365 ++++++++++++++ cli/app/commands/install/tests/test_ssh.py | 299 ++++++++++++ cli/app/commands/proxy/__init__.py | 3 + cli/app/commands/proxy/base.py | 195 ++++++++ cli/app/commands/proxy/command.py | 106 +++++ cli/app/commands/proxy/load.py | 135 ++++++ cli/app/commands/proxy/messages.py | 41 ++ cli/app/commands/proxy/status.py | 117 +++++ cli/app/commands/proxy/stop.py | 111 +++++ cli/app/commands/proxy/tests/test_load.py | 27 ++ cli/app/commands/proxy/tests/test_status.py | 18 + cli/app/commands/proxy/tests/test_stop.py | 18 + cli/app/commands/service/__init__.py | 1 + cli/app/commands/service/base.py | 169 +++++++ cli/app/commands/service/command.py | 152 ++++++ cli/app/commands/service/down.py | 118 +++++ cli/app/commands/service/messages.py | 24 + cli/app/commands/service/ps.py | 113 +++++ cli/app/commands/service/restart.py | 113 +++++ cli/app/commands/service/tests/__init__.py | 1 + cli/app/commands/service/tests/test_base.py | 325 +++++++++++++ cli/app/commands/service/tests/test_down.py | 441 +++++++++++++++++ cli/app/commands/service/tests/test_ps.py | 447 ++++++++++++++++++ .../commands/service/tests/test_restart.py | 447 ++++++++++++++++++ cli/app/commands/service/tests/test_up.py | 447 ++++++++++++++++++ cli/app/commands/service/up.py | 123 +++++ cli/app/main.py | 10 +- cli/app/utils/lib.py | 76 ++- cli/app/utils/protocols.py | 6 +- 44 files changed, 6728 insertions(+), 14 deletions(-) create mode 100644 cli/app/commands/conf/__init__.py create mode 100644 cli/app/commands/conf/base.py create mode 100644 cli/app/commands/conf/command.py create mode 100644 cli/app/commands/conf/delete.py create mode 100644 cli/app/commands/conf/list.py create mode 100644 cli/app/commands/conf/messages.py create mode 100644 cli/app/commands/conf/set.py create mode 100644 cli/app/commands/conf/tests/__init__.py create mode 100644 cli/app/commands/conf/tests/test_base.py create mode 100644 cli/app/commands/conf/tests/test_delete.py create mode 100644 cli/app/commands/conf/tests/test_list.py create mode 100644 cli/app/commands/conf/tests/test_set.py create mode 100644 cli/app/commands/install/ssh.py create mode 100644 cli/app/commands/install/tests/test_ssh.py create mode 100644 cli/app/commands/proxy/__init__.py create mode 100644 cli/app/commands/proxy/base.py create mode 100644 cli/app/commands/proxy/command.py create mode 100644 cli/app/commands/proxy/load.py create mode 100644 cli/app/commands/proxy/messages.py create mode 100644 cli/app/commands/proxy/status.py create mode 100644 cli/app/commands/proxy/stop.py create mode 100644 cli/app/commands/proxy/tests/test_load.py create mode 100644 cli/app/commands/proxy/tests/test_status.py create mode 100644 cli/app/commands/proxy/tests/test_stop.py create mode 100644 cli/app/commands/service/__init__.py create mode 100644 cli/app/commands/service/base.py create mode 100644 cli/app/commands/service/command.py create mode 100644 cli/app/commands/service/down.py create mode 100644 cli/app/commands/service/messages.py create mode 100644 cli/app/commands/service/ps.py create mode 100644 cli/app/commands/service/restart.py create mode 100644 cli/app/commands/service/tests/__init__.py create mode 100644 cli/app/commands/service/tests/test_base.py create mode 100644 cli/app/commands/service/tests/test_down.py create mode 100644 cli/app/commands/service/tests/test_ps.py create mode 100644 cli/app/commands/service/tests/test_restart.py create mode 100644 cli/app/commands/service/tests/test_up.py create mode 100644 cli/app/commands/service/up.py diff --git a/cli/app/commands/conf/__init__.py b/cli/app/commands/conf/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/conf/base.py b/cli/app/commands/conf/base.py new file mode 100644 index 00000000..cb97f493 --- /dev/null +++ b/cli/app/commands/conf/base.py @@ -0,0 +1,215 @@ +import os +import shutil +import tempfile +from typing import Protocol, Optional, Generic, TypeVar, Dict +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from .messages import ( + file_read_failed, + file_write_failed, + file_not_found, + invalid_line_warning, + backup_created, + backup_removed, + backup_remove_failed, + backup_restore_attempt, + backup_restore_success, + backup_restore_failed, + backup_creation_failed, + invalid_service, + backup_file_not_found +) + +TConfig = TypeVar('TConfig', bound=BaseModel) +TResult = TypeVar('TResult', bound=BaseModel) + +class EnvironmentServiceProtocol(Protocol): + def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[str, str], str]: + ... + + def set_config(self, service: str, key: str, value: str, env_file: str = None) -> tuple[bool, str]: + ... + + def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[bool, str]: + ... + +class BaseEnvironmentManager: + def __init__(self, logger: LoggerProtocol): + self.logger = logger + + def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[str]]: + try: + if not os.path.exists(file_path): + return False, {}, file_not_found.format(path=file_path) + + config = {} + with open(file_path, 'r') as f: + for line_num, line in enumerate(f, 1): + line = line.strip() + if not line or line.startswith('#'): + continue + + if '=' not in line: + self.logger.warning(invalid_line_warning.format( + line_num=line_num, file_path=file_path, line=line + )) + continue + + key, value = line.split('=', 1) + config[key.strip()] = value.strip() + + return True, config, None + except Exception as e: + return False, {}, file_read_failed.format(error=e) + + def _create_backup(self, file_path: str) -> tuple[bool, Optional[str], Optional[str]]: + if not os.path.exists(file_path): + return True, None, None + + try: + backup_path = f"{file_path}.backup" + shutil.copy2(file_path, backup_path) + return True, backup_path, None + except Exception as e: + return False, None, backup_creation_failed.format(error=e) + + def _restore_backup(self, backup_path: str, file_path: str) -> tuple[bool, Optional[str]]: + try: + if os.path.exists(backup_path): + shutil.copy2(backup_path, file_path) + os.remove(backup_path) + return True, None + return False, backup_file_not_found.format(path=backup_path) + except Exception as e: + return False, backup_restore_failed.format(error=e) + + def _atomic_write(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: + temp_path = None + try: + os.makedirs(os.path.dirname(file_path), exist_ok=True) + + with tempfile.NamedTemporaryFile(mode='w', delete=False, dir=os.path.dirname(file_path)) as temp_file: + for key, value in sorted(config.items()): + temp_file.write(f"{key}={value}\n") + temp_file.flush() + try: + os.fsync(temp_file.fileno()) + except (OSError, AttributeError): + pass + temp_path = temp_file.name + + os.replace(temp_path, file_path) + return True, None + except Exception as e: + if temp_path and os.path.exists(temp_path): + try: + os.unlink(temp_path) + except: + pass + return False, file_write_failed.format(error=e) + + def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: + backup_created_flag = False + backup_path = None + + try: + success, backup_path, error = self._create_backup(file_path) + if not success: + return False, error + + backup_created_flag = True + self.logger.info(backup_created.format(backup_path=backup_path)) + + success, error = self._atomic_write(file_path, config) + if not success: + if backup_created_flag and backup_path: + self.logger.warning(backup_restore_attempt) + restore_success, restore_error = self._restore_backup(backup_path, file_path) + if restore_success: + self.logger.info(backup_restore_success) + else: + self.logger.error(backup_restore_failed.format(error=restore_error)) + return False, error + + if backup_created_flag and backup_path and os.path.exists(backup_path): + try: + os.remove(backup_path) + self.logger.info(backup_removed) + except Exception as e: + self.logger.warning(backup_remove_failed.format(error=e)) + + return True, None + + except Exception as e: + return False, file_write_failed.format(error=e) + + def get_service_env_file(self, service: str, env_file: Optional[str] = None) -> str: + if env_file: + return env_file + + if service == "api": + return "/etc/nixopus/source/api/.env" + elif service == "view": + return "/etc/nixopus/source/view/.env" + else: + raise ValueError(invalid_service.format(service=service)) + +class BaseConfig(BaseModel): + service: str = Field("api", description="The name of the service to manage configuration for") + key: Optional[str] = Field(None, description="The configuration key") + value: Optional[str] = Field(None, description="The configuration value") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format: text, json") + dry_run: bool = Field(False, description="Dry run mode") + env_file: Optional[str] = Field(None, description="Path to the environment file") + + @field_validator("env_file") + @classmethod + def validate_env_file(cls, env_file: str) -> Optional[str]: + if not env_file: + return None + stripped_env_file = env_file.strip() + if not stripped_env_file: + return None + if not os.path.exists(stripped_env_file): + raise ValueError(file_not_found.format(path=stripped_env_file)) + return stripped_env_file + +class BaseResult(BaseModel): + service: str + key: Optional[str] = None + value: Optional[str] = None + config: Dict[str, str] = Field(default_factory=dict) + verbose: bool + output: str + success: bool = False + error: Optional[str] = None + +class BaseService(Generic[TConfig, TResult]): + def __init__(self, config: TConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.environment_service = environment_service + self.formatter = None + + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> TResult: + raise NotImplementedError + + def execute(self) -> TResult: + raise NotImplementedError + + def execute_and_format(self) -> str: + raise NotImplementedError + +class BaseAction(Generic[TConfig, TResult]): + def __init__(self, logger: LoggerProtocol = None): + self.logger = logger + self.formatter = None + + def execute(self, config: TConfig) -> TResult: + raise NotImplementedError + + def format_output(self, result: TResult, output: str) -> str: + raise NotImplementedError diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py new file mode 100644 index 00000000..bb90ed35 --- /dev/null +++ b/cli/app/commands/conf/command.py @@ -0,0 +1,112 @@ +import typer +from app.utils.logger import Logger +from .list import List, ListConfig +from .set import Set, SetConfig +from .delete import Delete, DeleteConfig + +conf_app = typer.Typer(help="Manage configuration") + +@conf_app.command() +def list( + service: str = typer.Option("api", "--service", "-s", help="The name of the service to list configuration for, e.g api,view"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), +): + """List all configuration""" + logger = Logger(verbose=verbose) + + try: + config = ListConfig( + service=service, + verbose=verbose, + output=output, + dry_run=dry_run, + env_file=env_file + ) + + list_action = List(logger=logger) + result = list_action.list(config) + + if result.success: + logger.success(list_action.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@conf_app.command() +def delete( + service: str = typer.Option("api", "--service", "-s", help="The name of the service to delete configuration for, e.g api,view"), + key: str = typer.Option(None, "--key", "-k", help="The key of the configuration to delete"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), +): + """Delete a configuration""" + logger = Logger(verbose=verbose) + + try: + config = DeleteConfig( + service=service, + key=key, + verbose=verbose, + output=output, + dry_run=dry_run, + env_file=env_file + ) + + delete_action = Delete(logger=logger) + result = delete_action.delete(config) + + if result.success: + logger.success(delete_action.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@conf_app.command() +def set( + service: str = typer.Option("api", "--service", "-s", help="The name of the service to set configuration for, e.g api,view"), + key: str = typer.Option(None, "--key", "-k", help="The key of the configuration to set"), + value: str = typer.Option(None, "--value", "-v", help="The value of the configuration to set"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), +): + """Set a configuration""" + logger = Logger(verbose=verbose) + + try: + config = SetConfig( + service=service, + key=key, + value=value, + verbose=verbose, + output=output, + dry_run=dry_run, + env_file=env_file + ) + + set_action = Set(logger=logger) + result = set_action.set(config) + + if result.success: + logger.success(set_action.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) diff --git a/cli/app/commands/conf/delete.py b/cli/app/commands/conf/delete.py new file mode 100644 index 00000000..f906f0c3 --- /dev/null +++ b/cli/app/commands/conf/delete.py @@ -0,0 +1,142 @@ +from typing import Protocol, Optional, Dict +from pydantic import BaseModel, Field + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from .base import ( + BaseEnvironmentManager, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + configuration_deleted, + configuration_delete_failed, + key_required_delete, + dry_run_mode, + dry_run_delete_config, + end_dry_run, + config_key_not_found +) + +class EnvironmentServiceProtocol(Protocol): + def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[bool, str]: + ... + +class EnvironmentManager(BaseEnvironmentManager): + def delete_config(self, service: str, key: str, env_file: Optional[str] = None) -> tuple[bool, Optional[str]]: + file_path = self.get_service_env_file(service, env_file) + + success, config, error = self.read_env_file(file_path) + if not success: + return False, error + + if key not in config: + return False, config_key_not_found.format(key=key) + + del config[key] + return self.write_env_file(file_path, config) + +class DeleteResult(BaseResult): + pass + +class DeleteConfig(BaseConfig): + key: str = Field(..., description="The key of the configuration to delete") + +class DeleteService(BaseService[DeleteConfig, DeleteResult]): + def __init__(self, config: DeleteConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + super().__init__(config, logger, environment_service) + self.environment_service = environment_service or EnvironmentManager(self.logger) + + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> DeleteResult: + return DeleteResult( + service=self.config.service, + key=self.config.key, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error, + config=config_dict or {} + ) + + def delete(self) -> DeleteResult: + return self.execute() + + def execute(self) -> DeleteResult: + if not self.config.key: + return self._create_result(False, error=key_required_delete) + + if self.config.dry_run: + return self._create_result(True) + + success, error = self.environment_service.delete_config( + self.config.service, self.config.key, self.config.env_file + ) + + if success: + self.logger.info(configuration_deleted.format( + service=self.config.service, key=self.config.key + )) + return self._create_result(True) + else: + self.logger.error(configuration_delete_failed.format( + service=self.config.service, error=error + )) + return self._create_result(False, error=error) + + def delete_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self._format_dry_run() + + result = self.execute() + return self._format_output(result, self.config.output) + + def _format_dry_run(self) -> str: + lines = [dry_run_mode] + lines.append(dry_run_delete_config.format( + service=self.config.service, + key=self.config.key + )) + lines.append(end_dry_run) + return "\n".join(lines) + + def _format_output(self, result: DeleteResult, output_format: str) -> str: + if output_format == "json": + return self._format_json(result) + else: + return self._format_text(result) + + def _format_json(self, result: DeleteResult) -> str: + import json + output = { + "service": result.service, + "key": result.key, + "success": result.success, + "error": result.error + } + return json.dumps(output, indent=2) + + def _format_text(self, result: DeleteResult) -> str: + if not result.success: + return configuration_delete_failed.format(service=result.service, error=result.error) + + return configuration_deleted.format(service=result.service, key=result.key) + +class Delete(BaseAction[DeleteConfig, DeleteResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + + def delete(self, config: DeleteConfig) -> DeleteResult: + return self.execute(config) + + def execute(self, config: DeleteConfig) -> DeleteResult: + service = DeleteService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: DeleteResult, output: str) -> str: + service = DeleteService(result, logger=self.logger) + return service._format_output(result, output) diff --git a/cli/app/commands/conf/list.py b/cli/app/commands/conf/list.py new file mode 100644 index 00000000..104d89ea --- /dev/null +++ b/cli/app/commands/conf/list.py @@ -0,0 +1,129 @@ +from typing import Protocol, Optional, Dict +from pydantic import BaseModel, Field + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from .base import ( + BaseEnvironmentManager, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + configuration_listed, + configuration_list_failed, + no_configuration_found, + dry_run_mode, + dry_run_list_config, + end_dry_run +) + +class EnvironmentServiceProtocol(Protocol): + def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[str, str], str]: + ... + +class EnvironmentManager(BaseEnvironmentManager): + def list_config(self, service: str, env_file: Optional[str] = None) -> tuple[bool, Dict[str, str], Optional[str]]: + file_path = self.get_service_env_file(service, env_file) + return self.read_env_file(file_path) + +class ListResult(BaseResult): + pass + +class ListConfig(BaseConfig): + pass + +class ListService(BaseService[ListConfig, ListResult]): + def __init__(self, config: ListConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + super().__init__(config, logger, environment_service) + self.environment_service = environment_service or EnvironmentManager(self.logger) + + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> ListResult: + return ListResult( + service=self.config.service, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error, + config=config_dict or {} + ) + + def list(self) -> ListResult: + return self.execute() + + def execute(self) -> ListResult: + if self.config.dry_run: + return self._create_result(True) + + success, config_dict, error = self.environment_service.list_config( + self.config.service, self.config.env_file + ) + + if success: + self.logger.info(configuration_listed.format(service=self.config.service)) + return self._create_result(True, config_dict=config_dict) + else: + self.logger.error(configuration_list_failed.format( + service=self.config.service, error=error + )) + return self._create_result(False, error=error) + + def list_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self._format_dry_run() + + result = self.execute() + return self._format_output(result, self.config.output) + + def _format_dry_run(self) -> str: + lines = [dry_run_mode] + lines.append(dry_run_list_config.format(service=self.config.service)) + lines.append(end_dry_run) + return "\n".join(lines) + + def _format_output(self, result: ListResult, output_format: str) -> str: + if output_format == "json": + return self._format_json(result) + else: + return self._format_text(result) + + def _format_json(self, result: ListResult) -> str: + import json + output = { + "service": result.service, + "success": result.success, + "error": result.error, + "config": result.config + } + return json.dumps(output, indent=2) + + def _format_text(self, result: ListResult) -> str: + if not result.success: + return configuration_list_failed.format(service=result.service, error=result.error) + + if result.config: + lines = [configuration_listed.format(service=result.service)] + for key, value in sorted(result.config.items()): + lines.append(f" {key}={value}") + return "\n".join(lines) + + return no_configuration_found.format(service=result.service) + +class List(BaseAction[ListConfig, ListResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + + def list(self, config: ListConfig) -> ListResult: + return self.execute(config) + + def execute(self, config: ListConfig) -> ListResult: + service = ListService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: ListResult, output: str) -> str: + service = ListService(result, logger=self.logger) + return service._format_output(result, output) diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py new file mode 100644 index 00000000..97e6a6f5 --- /dev/null +++ b/cli/app/commands/conf/messages.py @@ -0,0 +1,30 @@ +configuration_listed = "Configuration listed successfully for service: {service}" +configuration_list_failed = "Failed to list configuration for service: {service}: {error}" +no_configuration_found = "No configuration found for service: {service}" +configuration_set = "Configuration set successfully: {key}={value} for service: {service}" +configuration_set_failed = "Failed to set configuration for service: {service}: {error}" +key_required = "Key is required for set operation" +value_required = "Value is required for set operation" +configuration_deleted = "Configuration deleted successfully: {key} for service: {service}" +configuration_delete_failed = "Failed to delete configuration for service: {service}: {error}" +key_not_found = "Configuration key '{key}' not found for service: {service}" +key_required_delete = "Key is required for delete operation" +dry_run_mode = "DRY RUN MODE - No changes will be made" +dry_run_list_config = "Would list configuration for service: {service}" +dry_run_set_config = "Would set configuration: {key}={value} for service: {service}" +dry_run_delete_config = "Would delete configuration: {key} for service: {service}" +end_dry_run = "DRY RUN COMPLETE" +file_read_failed = "Failed to read environment file: {error}" +file_write_failed = "Failed to write environment file: {error}" +file_not_found = "Environment file not found: {path}" +invalid_line_warning = "Invalid line {line_num} in {file_path}: {line}" +backup_created = "Backup created: {backup_path}" +backup_removed = "Backup removed after successful write" +backup_remove_failed = "Failed to remove backup: {error}" +backup_restore_attempt = "Attempting to restore from backup due to error" +backup_restore_success = "Successfully restored from backup" +backup_restore_failed = "Failed to restore from backup: {error}" +backup_creation_failed = "Failed to create backup: {error}" +invalid_service = "Invalid service: {service}" +config_key_not_found = "Configuration key '{key}' not found" +backup_file_not_found = "Backup file not found" diff --git a/cli/app/commands/conf/set.py b/cli/app/commands/conf/set.py new file mode 100644 index 00000000..10946bce --- /dev/null +++ b/cli/app/commands/conf/set.py @@ -0,0 +1,146 @@ +from typing import Protocol, Optional, Dict +from pydantic import BaseModel, Field + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from .base import ( + BaseEnvironmentManager, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + configuration_set, + configuration_set_failed, + key_required, + value_required, + dry_run_mode, + dry_run_set_config, + end_dry_run +) + +class EnvironmentServiceProtocol(Protocol): + def set_config(self, service: str, key: str, value: str, env_file: str = None) -> tuple[bool, str]: + ... + +class EnvironmentManager(BaseEnvironmentManager): + def set_config(self, service: str, key: str, value: str, env_file: Optional[str] = None) -> tuple[bool, Optional[str]]: + file_path = self.get_service_env_file(service, env_file) + + success, config, error = self.read_env_file(file_path) + if not success: + return False, error + + config[key] = value + return self.write_env_file(file_path, config) + +class SetResult(BaseResult): + pass + +class SetConfig(BaseConfig): + key: str = Field(..., description="The key of the configuration to set") + value: str = Field(..., description="The value of the configuration to set") + +class SetService(BaseService[SetConfig, SetResult]): + def __init__(self, config: SetConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + super().__init__(config, logger, environment_service) + self.environment_service = environment_service or EnvironmentManager(self.logger) + + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> SetResult: + return SetResult( + service=self.config.service, + key=self.config.key, + value=self.config.value, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error, + config=config_dict or {} + ) + + def set(self) -> SetResult: + return self.execute() + + def execute(self) -> SetResult: + if not self.config.key: + return self._create_result(False, error=key_required) + + if not self.config.value: + return self._create_result(False, error=value_required) + + if self.config.dry_run: + return self._create_result(True) + + success, error = self.environment_service.set_config( + self.config.service, self.config.key, self.config.value, self.config.env_file + ) + + if success: + self.logger.info(configuration_set.format( + service=self.config.service, key=self.config.key, value=self.config.value + )) + return self._create_result(True) + else: + self.logger.error(configuration_set_failed.format( + service=self.config.service, error=error + )) + return self._create_result(False, error=error) + + def set_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self._format_dry_run() + + result = self.execute() + return self._format_output(result, self.config.output) + + def _format_dry_run(self) -> str: + lines = [dry_run_mode] + lines.append(dry_run_set_config.format( + service=self.config.service, + key=self.config.key, + value=self.config.value + )) + lines.append(end_dry_run) + return "\n".join(lines) + + def _format_output(self, result: SetResult, output_format: str) -> str: + if output_format == "json": + return self._format_json(result) + else: + return self._format_text(result) + + def _format_json(self, result: SetResult) -> str: + import json + output = { + "service": result.service, + "key": result.key, + "value": result.value, + "success": result.success, + "error": result.error + } + return json.dumps(output, indent=2) + + def _format_text(self, result: SetResult) -> str: + if not result.success: + return configuration_set_failed.format(service=result.service, error=result.error) + + return configuration_set.format(service=result.service, key=result.key, value=result.value) + +class Set(BaseAction[SetConfig, SetResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + + def set(self, config: SetConfig) -> SetResult: + return self.execute(config) + + def execute(self, config: SetConfig) -> SetResult: + service = SetService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: SetResult, output: str) -> str: + service = SetService(result, logger=self.logger) + return service._format_output(result, output) \ No newline at end of file diff --git a/cli/app/commands/conf/tests/__init__.py b/cli/app/commands/conf/tests/__init__.py new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/cli/app/commands/conf/tests/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/cli/app/commands/conf/tests/test_base.py b/cli/app/commands/conf/tests/test_base.py new file mode 100644 index 00000000..e61bd781 --- /dev/null +++ b/cli/app/commands/conf/tests/test_base.py @@ -0,0 +1,420 @@ +import pytest +import os +import tempfile +import shutil +from unittest.mock import Mock, patch, mock_open +from pydantic import ValidationError + +from app.commands.conf.base import ( + BaseEnvironmentManager, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from app.utils.logger import Logger + + +class TestBaseEnvironmentManager: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.manager = BaseEnvironmentManager(self.logger) + + @patch('os.path.exists') + def test_read_env_file_exists(self, mock_exists): + mock_exists.return_value = True + + with patch('builtins.open', mock_open(read_data="KEY1=value1\nKEY2=value2\n")): + success, config, error = self.manager.read_env_file("/path/to/.env") + + assert success is True + assert config == {"KEY1": "value1", "KEY2": "value2"} + assert error is None + + @patch('os.path.exists') + def test_read_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + + success, config, error = self.manager.read_env_file("/path/to/.env") + + assert success is False + assert config == {} + assert "Environment file not found" in error + + @patch('os.path.exists') + def test_read_env_file_with_comments_and_empty_lines(self, mock_exists): + mock_exists.return_value = True + + content = "# Comment line\nKEY1=value1\n\nKEY2=value2\n# Another comment" + with patch('builtins.open', mock_open(read_data=content)): + success, config, error = self.manager.read_env_file("/path/to/.env") + + assert success is True + assert config == {"KEY1": "value1", "KEY2": "value2"} + assert error is None + + @patch('os.path.exists') + def test_read_env_file_with_invalid_line(self, mock_exists): + mock_exists.return_value = True + + content = "KEY1=value1\nINVALID_LINE\nKEY2=value2" + with patch('builtins.open', mock_open(read_data=content)): + success, config, error = self.manager.read_env_file("/path/to/.env") + + assert success is True + assert config == {"KEY1": "value1", "KEY2": "value2"} + assert error is None + self.logger.warning.assert_called_once() + + @patch('os.path.exists') + def test_create_backup_file_exists(self, mock_exists): + mock_exists.return_value = True + + with patch('shutil.copy2') as mock_copy: + success, backup_path, error = self.manager._create_backup("/path/to/.env") + + assert success is True + assert backup_path == "/path/to/.env.backup" + assert error is None + mock_copy.assert_called_once_with("/path/to/.env", "/path/to/.env.backup") + + @patch('os.path.exists') + def test_create_backup_file_not_exists(self, mock_exists): + mock_exists.return_value = False + + success, backup_path, error = self.manager._create_backup("/path/to/.env") + + assert success is True + assert backup_path is None + assert error is None + + @patch('os.path.exists') + def test_create_backup_failure(self, mock_exists): + mock_exists.return_value = True + + with patch('shutil.copy2', side_effect=Exception("Copy failed")): + success, backup_path, error = self.manager._create_backup("/path/to/.env") + + assert success is False + assert backup_path is None + assert "Failed to create backup" in error + + @patch('os.path.exists') + def test_restore_backup_success(self, mock_exists): + mock_exists.return_value = True + + with patch('shutil.copy2') as mock_copy: + with patch('os.remove') as mock_remove: + success, error = self.manager._restore_backup("/path/to/.env.backup", "/path/to/.env") + + assert success is True + assert error is None + mock_copy.assert_called_once_with("/path/to/.env.backup", "/path/to/.env") + mock_remove.assert_called_once_with("/path/to/.env.backup") + + @patch('os.path.exists') + def test_restore_backup_not_exists(self, mock_exists): + mock_exists.return_value = False + + success, error = self.manager._restore_backup("/path/to/.env.backup", "/path/to/.env") + + assert success is False + assert error == "Backup file not found" + + @patch('os.path.exists') + def test_restore_backup_failure(self, mock_exists): + mock_exists.return_value = True + + with patch('shutil.copy2', side_effect=Exception("Copy failed")): + success, error = self.manager._restore_backup("/path/to/.env.backup", "/path/to/.env") + + assert success is False + assert "Failed to restore from backup" in error + + @patch('os.makedirs') + @patch('tempfile.NamedTemporaryFile') + @patch('os.replace') + @patch('os.fsync') + def test_atomic_write_success(self, mock_fsync, mock_replace, mock_tempfile, mock_makedirs): + config = {"KEY2": "value2", "KEY1": "value1"} + + mock_temp = Mock() + mock_temp.name = "/tmp/temp_file" + mock_temp.fileno.return_value = 123 + mock_tempfile.return_value.__enter__.return_value = mock_temp + mock_tempfile.return_value.__exit__.return_value = None + + success, error = self.manager._atomic_write("/path/to/.env", config) + + assert success is True + assert error is None + mock_makedirs.assert_called_once_with("/path/to", exist_ok=True) + mock_temp.write.assert_called() + mock_temp.flush.assert_called_once() + mock_temp.fileno.assert_called_once() + mock_replace.assert_called_once_with("/tmp/temp_file", "/path/to/.env") + + @patch('os.makedirs') + @patch('tempfile.NamedTemporaryFile') + def test_atomic_write_failure(self, mock_tempfile, mock_makedirs): + config = {"KEY1": "value1"} + + mock_tempfile.side_effect = Exception("Temp file creation failed") + + success, error = self.manager._atomic_write("/path/to/.env", config) + + assert success is False + assert "Failed to write environment file" in error + + @patch('os.makedirs') + @patch('tempfile.NamedTemporaryFile') + @patch('os.replace') + @patch('os.fsync') + def test_atomic_write_simple(self, mock_fsync, mock_replace, mock_tempfile, mock_makedirs): + config = {"KEY1": "value1"} + + mock_temp = Mock() + mock_temp.name = "/tmp/temp_file" + mock_temp.fileno.return_value = 123 + mock_tempfile.return_value.__enter__.return_value = mock_temp + mock_tempfile.return_value.__exit__.return_value = None + + success, error = self.manager._atomic_write("/path/to/.env", config) + + assert success is True + assert error is None + + @patch('os.path.exists') + @patch('shutil.copy2') + @patch('tempfile.NamedTemporaryFile') + @patch('os.replace') + @patch('os.fsync') + @patch('os.makedirs') + def test_write_env_file_success_with_backup(self, mock_makedirs, mock_fsync, mock_replace, mock_tempfile, mock_copy, mock_exists): + mock_exists.return_value = True + config = {"KEY2": "value2", "KEY1": "value1"} + + mock_temp = Mock() + mock_temp.name = "/tmp/temp_file" + mock_temp.fileno.return_value = 123 + mock_tempfile.return_value.__enter__.return_value = mock_temp + mock_tempfile.return_value.__exit__.return_value = None + + with patch('os.remove') as mock_remove: + success, error = self.manager.write_env_file("/path/to/.env", config) + + assert success is True + assert error is None + mock_copy.assert_called_once_with("/path/to/.env", "/path/to/.env.backup") + mock_remove.assert_called_once_with("/path/to/.env.backup") + self.logger.info.assert_called() + + @patch('os.path.exists') + @patch('tempfile.NamedTemporaryFile') + @patch('os.replace') + @patch('os.fsync') + @patch('os.makedirs') + def test_write_env_file_success_no_backup_needed(self, mock_makedirs, mock_fsync, mock_replace, mock_tempfile, mock_exists): + mock_exists.return_value = False + config = {"KEY1": "value1"} + + mock_temp = Mock() + mock_temp.name = "/tmp/temp_file" + mock_temp.fileno.return_value = 123 + mock_tempfile.return_value.__enter__.return_value = mock_temp + mock_tempfile.return_value.__exit__.return_value = None + + success, error = self.manager.write_env_file("/path/to/.env", config) + + assert success is True + assert error is None + mock_replace.assert_called_once_with("/tmp/temp_file", "/path/to/.env") + + @patch('os.path.exists') + @patch('shutil.copy2') + def test_write_env_file_backup_failure(self, mock_copy, mock_exists): + mock_exists.return_value = True + mock_copy.side_effect = Exception("Backup failed") + config = {"KEY1": "value1"} + + success, error = self.manager.write_env_file("/path/to/.env", config) + + assert success is False + assert "Failed to create backup" in error + + @patch('os.path.exists') + @patch('shutil.copy2') + @patch('tempfile.NamedTemporaryFile') + def test_write_env_file_write_failure_with_restore(self, mock_tempfile, mock_copy, mock_exists): + mock_exists.return_value = True + config = {"KEY1": "value1"} + + mock_tempfile.side_effect = Exception("Write failed") + + with patch.object(self.manager, '_restore_backup') as mock_restore: + mock_restore.return_value = (True, None) + + success, error = self.manager.write_env_file("/path/to/.env", config) + + assert success is False + assert "Failed to write environment file" in error + mock_restore.assert_called_once_with("/path/to/.env.backup", "/path/to/.env") + self.logger.warning.assert_called() + self.logger.info.assert_called() + + def test_get_service_env_file_with_custom_env_file(self): + env_file = self.manager.get_service_env_file("api", "/custom/.env") + assert env_file == "/custom/.env" + + def test_get_service_env_file_api_service(self): + env_file = self.manager.get_service_env_file("api") + assert env_file == "/etc/nixopus/source/api/.env" + + def test_get_service_env_file_view_service(self): + env_file = self.manager.get_service_env_file("view") + assert env_file == "/etc/nixopus/source/view/.env" + + def test_get_service_env_file_invalid_service(self): + with pytest.raises(ValueError, match="Invalid service: invalid"): + self.manager.get_service_env_file("invalid") + + +class TestBaseConfig: + def test_valid_config_default(self): + config = BaseConfig() + assert config.service == "api" + assert config.key is None + assert config.value is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.env_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = BaseConfig( + service="view", + key="TEST_KEY", + value="test_value", + verbose=True, + output="json", + dry_run=True, + env_file="/path/to/.env" + ) + assert config.service == "view" + assert config.key == "TEST_KEY" + assert config.value == "test_value" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_exists(self, mock_exists): + mock_exists.return_value = True + config = BaseConfig(env_file="/path/to/.env") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + BaseConfig(env_file="/path/to/.env") + + def test_validate_env_file_none(self): + config = BaseConfig(env_file=None) + assert config.env_file is None + + def test_validate_env_file_empty(self): + config = BaseConfig(env_file="") + assert config.env_file is None + + def test_validate_env_file_whitespace(self): + config = BaseConfig(env_file=" ") + assert config.env_file is None + + def test_validate_env_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = BaseConfig(env_file=" /path/to/.env ") + assert config.env_file == "/path/to/.env" + + +class TestBaseResult: + def test_base_result_default(self): + result = BaseResult( + service="api", + verbose=False, + output="text" + ) + assert result.service == "api" + assert result.key is None + assert result.value is None + assert result.config == {} + assert result.verbose is False + assert result.output == "text" + assert result.success is False + assert result.error is None + + def test_base_result_custom(self): + result = BaseResult( + service="view", + key="TEST_KEY", + value="test_value", + config={"KEY1": "value1"}, + verbose=True, + output="json", + success=True, + error="test error" + ) + assert result.service == "view" + assert result.key == "TEST_KEY" + assert result.value == "test_value" + assert result.config == {"KEY1": "value1"} + assert result.verbose is True + assert result.output == "json" + assert result.success is True + assert result.error == "test error" + + +class TestBaseService: + def setup_method(self): + self.config = BaseConfig() + self.logger = Mock(spec=Logger) + self.environment_service = Mock() + + def test_base_service_init(self): + service = BaseService(self.config, self.logger, self.environment_service) + assert service.config == self.config + assert service.logger == self.logger + assert service.environment_service == self.environment_service + assert service.formatter is None + + def test_base_service_init_defaults(self): + service = BaseService(self.config) + assert service.config == self.config + assert service.logger is not None + assert service.environment_service is None + assert service.formatter is None + + +class TestBaseAction: + def setup_method(self): + self.logger = Mock(spec=Logger) + + def test_base_action_init(self): + action = BaseAction(self.logger) + assert action.logger == self.logger + assert action.formatter is None + + def test_base_action_init_default(self): + action = BaseAction() + assert action.logger is None + assert action.formatter is None + + +def mock_open(read_data=""): + """Helper function to create a mock open function""" + from unittest.mock import mock_open as _mock_open + return _mock_open(read_data=read_data) diff --git a/cli/app/commands/conf/tests/test_delete.py b/cli/app/commands/conf/tests/test_delete.py new file mode 100644 index 00000000..fde46141 --- /dev/null +++ b/cli/app/commands/conf/tests/test_delete.py @@ -0,0 +1,343 @@ +import pytest +import json +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.conf.delete import ( + EnvironmentManager, + DeleteResult, + DeleteConfig, + DeleteService, + Delete +) +from app.commands.conf.messages import ( + configuration_deleted, + configuration_delete_failed, + key_required_delete, + dry_run_mode, + dry_run_delete_config, + end_dry_run +) +from app.utils.logger import Logger + + +class TestEnvironmentManager: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.manager = EnvironmentManager(self.logger) + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + def test_delete_config_success(self, mock_write_env_file, mock_read_env_file): + mock_read_env_file.return_value = (True, {"KEY1": "value1", "KEY2": "value2"}, None) + mock_write_env_file.return_value = (True, None) + + success, error = self.manager.delete_config("api", "KEY1") + + assert success is True + assert error is None + mock_read_env_file.assert_called_once_with("/etc/nixopus/source/api/.env") + mock_write_env_file.assert_called_once_with("/etc/nixopus/source/api/.env", {"KEY2": "value2"}) + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + def test_delete_config_read_failure(self, mock_read_env_file): + mock_read_env_file.return_value = (False, {}, "File not found") + + success, error = self.manager.delete_config("api", "KEY1") + + assert success is False + assert error == "File not found" + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + def test_delete_config_key_not_found(self, mock_read_env_file): + mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) + + success, error = self.manager.delete_config("api", "KEY2") + + assert success is False + assert "Configuration key 'KEY2' not found" in error + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + def test_delete_config_write_failure(self, mock_write_env_file, mock_read_env_file): + mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) + mock_write_env_file.return_value = (False, "Write error") + + success, error = self.manager.delete_config("api", "KEY1") + + assert success is False + assert error == "Write error" + + @patch('app.commands.conf.base.BaseEnvironmentManager.get_service_env_file') + def test_delete_config_with_custom_env_file(self, mock_get_service_env_file): + mock_get_service_env_file.return_value = "/custom/.env" + + with patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') as mock_read: + with patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') as mock_write: + mock_read.return_value = (True, {"KEY1": "value1"}, None) + mock_write.return_value = (True, None) + + self.manager.delete_config("api", "KEY1", "/custom/.env") + + mock_get_service_env_file.assert_called_once_with("api", "/custom/.env") + + +class TestDeleteConfig: + def test_valid_config_default(self): + config = DeleteConfig(key="TEST_KEY") + assert config.service == "api" + assert config.key == "TEST_KEY" + assert config.value is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.env_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = DeleteConfig( + service="view", + key="TEST_KEY", + verbose=True, + output="json", + dry_run=True, + env_file="/path/to/.env" + ) + assert config.service == "view" + assert config.key == "TEST_KEY" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.env_file == "/path/to/.env" + + +class TestDeleteResult: + def test_delete_result_default(self): + result = DeleteResult( + service="api", + key="TEST_KEY", + verbose=False, + output="text" + ) + assert result.service == "api" + assert result.key == "TEST_KEY" + assert result.value is None + assert result.config == {} + assert result.verbose is False + assert result.output == "text" + assert result.success is False + assert result.error is None + + def test_delete_result_success(self): + result = DeleteResult( + service="view", + key="TEST_KEY", + config={"KEY1": "value1"}, + verbose=True, + output="json", + success=True + ) + assert result.service == "view" + assert result.key == "TEST_KEY" + assert result.config == {"KEY1": "value1"} + assert result.verbose is True + assert result.output == "json" + assert result.success is True + + +class TestDeleteService: + def setup_method(self): + self.config = DeleteConfig(key="TEST_KEY") + self.logger = Mock(spec=Logger) + self.environment_service = Mock() + self.service = DeleteService(self.config, self.logger, self.environment_service) + + def test_delete_service_init(self): + assert self.service.config == self.config + assert self.service.logger == self.logger + assert self.service.environment_service == self.environment_service + + def test_delete_service_init_defaults(self): + service = DeleteService(self.config) + assert service.config == self.config + assert service.logger is not None + assert service.environment_service is not None + + def test_create_result_success(self): + result = self.service._create_result(True, config_dict={"KEY1": "value1"}) + + assert result.service == "api" + assert result.key == "TEST_KEY" + assert result.config == {"KEY1": "value1"} + assert result.success is True + assert result.error is None + + def test_create_result_failure(self): + result = self.service._create_result(False, error="Test error") + + assert result.service == "api" + assert result.key == "TEST_KEY" + assert result.config == {} + assert result.success is False + assert result.error == "Test error" + + def test_delete_missing_key(self): + self.config.key = None + + result = self.service.delete() + + assert result.success is False + assert result.error == key_required_delete + + def test_delete_success(self): + self.environment_service.delete_config.return_value = (True, None) + + result = self.service.delete() + + assert result.success is True + assert result.error is None + self.logger.info.assert_called_once_with(configuration_deleted.format( + service="api", key="TEST_KEY" + )) + self.environment_service.delete_config.assert_called_once_with( + "api", "TEST_KEY", None + ) + + def test_delete_failure(self): + self.environment_service.delete_config.return_value = (False, "Delete error") + + result = self.service.delete() + + assert result.success is False + assert result.error == "Delete error" + self.logger.error.assert_called_once_with(configuration_delete_failed.format( + service="api", error="Delete error" + )) + + def test_delete_dry_run(self): + self.config.dry_run = True + + result = self.service.delete() + + assert result.success is True + assert result.error is None + self.environment_service.delete_config.assert_not_called() + + def test_delete_and_format_success(self): + self.environment_service.delete_config.return_value = (True, None) + + output = self.service.delete_and_format() + + assert configuration_deleted.format(service="api", key="TEST_KEY") in output + + def test_delete_and_format_failure(self): + self.environment_service.delete_config.return_value = (False, "Delete error") + + output = self.service.delete_and_format() + + assert configuration_delete_failed.format(service="api", error="Delete error") in output + + def test_delete_and_format_dry_run(self): + self.config.dry_run = True + + output = self.service.delete_and_format() + + assert dry_run_mode in output + assert dry_run_delete_config.format( + service="api", key="TEST_KEY" + ) in output + assert end_dry_run in output + + def test_format_output_json(self): + result = DeleteResult( + service="api", + key="TEST_KEY", + success=True, + verbose=False, + output="json" + ) + + output = self.service._format_output(result, "json") + data = json.loads(output) + + assert data["service"] == "api" + assert data["key"] == "TEST_KEY" + assert data["success"] is True + + def test_format_output_text_success(self): + result = DeleteResult( + service="api", + key="TEST_KEY", + success=True, + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert configuration_deleted.format(service="api", key="TEST_KEY") in output + + def test_format_output_text_failure(self): + result = DeleteResult( + service="api", + key="TEST_KEY", + success=False, + error="Test error", + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert configuration_delete_failed.format(service="api", error="Test error") in output + + +class TestDelete: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.action = Delete(self.logger) + + def test_delete_action_init(self): + assert self.action.logger == self.logger + + def test_delete_action_init_default(self): + action = Delete() + assert action.logger is None + + def test_delete_success(self): + config = DeleteConfig(key="TEST_KEY") + + with patch('app.commands.conf.delete.DeleteService') as mock_service_class: + mock_service = Mock() + mock_service.execute.return_value = DeleteResult( + service="api", + key="TEST_KEY", + success=True, + verbose=False, + output="text" + ) + mock_service_class.return_value = mock_service + + result = self.action.delete(config) + + assert result.success is True + assert result.key == "TEST_KEY" + + def test_format_output(self): + result = DeleteResult( + service="api", + key="TEST_KEY", + success=True, + verbose=False, + output="text" + ) + + with patch('app.commands.conf.delete.DeleteService') as mock_service_class: + mock_service = Mock() + mock_service._format_output.return_value = "formatted output" + mock_service_class.return_value = mock_service + + output = self.action.format_output(result, "text") + + assert output == "formatted output" diff --git a/cli/app/commands/conf/tests/test_list.py b/cli/app/commands/conf/tests/test_list.py new file mode 100644 index 00000000..61c696c6 --- /dev/null +++ b/cli/app/commands/conf/tests/test_list.py @@ -0,0 +1,311 @@ +import pytest +import json +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.conf.list import ( + EnvironmentManager, + ListResult, + ListConfig, + ListService, + List +) +from app.commands.conf.messages import ( + configuration_listed, + configuration_list_failed, + no_configuration_found, + dry_run_mode, + dry_run_list_config, + end_dry_run +) +from app.utils.logger import Logger + + +class TestEnvironmentManager: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.manager = EnvironmentManager(self.logger) + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + def test_list_config_success(self, mock_read_env_file): + mock_read_env_file.return_value = (True, {"KEY1": "value1", "KEY2": "value2"}, None) + + success, config, error = self.manager.list_config("api") + + assert success is True + assert config == {"KEY1": "value1", "KEY2": "value2"} + assert error is None + mock_read_env_file.assert_called_once_with("/etc/nixopus/source/api/.env") + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + def test_list_config_failure(self, mock_read_env_file): + mock_read_env_file.return_value = (False, {}, "File not found") + + success, config, error = self.manager.list_config("api") + + assert success is False + assert config == {} + assert error == "File not found" + + @patch('app.commands.conf.base.BaseEnvironmentManager.get_service_env_file') + def test_list_config_with_custom_env_file(self, mock_get_service_env_file): + mock_get_service_env_file.return_value = "/custom/.env" + + self.manager.list_config("api", "/custom/.env") + + mock_get_service_env_file.assert_called_once_with("api", "/custom/.env") + + +class TestListConfig: + def test_valid_config_default(self): + config = ListConfig() + assert config.service == "api" + assert config.key is None + assert config.value is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.env_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = ListConfig( + service="view", + verbose=True, + output="json", + dry_run=True, + env_file="/path/to/.env" + ) + assert config.service == "view" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.env_file == "/path/to/.env" + + +class TestListResult: + def test_list_result_default(self): + result = ListResult( + service="api", + verbose=False, + output="text" + ) + assert result.service == "api" + assert result.key is None + assert result.value is None + assert result.config == {} + assert result.verbose is False + assert result.output == "text" + assert result.success is False + assert result.error is None + + def test_list_result_with_config(self): + result = ListResult( + service="view", + config={"KEY1": "value1", "KEY2": "value2"}, + verbose=True, + output="json", + success=True + ) + assert result.service == "view" + assert result.config == {"KEY1": "value1", "KEY2": "value2"} + assert result.verbose is True + assert result.output == "json" + assert result.success is True + + +class TestListService: + def setup_method(self): + self.config = ListConfig() + self.logger = Mock(spec=Logger) + self.environment_service = Mock() + self.service = ListService(self.config, self.logger, self.environment_service) + + def test_list_service_init(self): + assert self.service.config == self.config + assert self.service.logger == self.logger + assert self.service.environment_service == self.environment_service + + def test_list_service_init_defaults(self): + service = ListService(self.config) + assert service.config == self.config + assert service.logger is not None + assert service.environment_service is not None + + def test_create_result_success(self): + result = self.service._create_result(True, config_dict={"KEY1": "value1"}) + + assert result.service == "api" + assert result.config == {"KEY1": "value1"} + assert result.success is True + assert result.error is None + + def test_create_result_failure(self): + result = self.service._create_result(False, error="Test error") + + assert result.service == "api" + assert result.config == {} + assert result.success is False + assert result.error == "Test error" + + def test_list_success(self): + self.environment_service.list_config.return_value = (True, {"KEY1": "value1"}, None) + + result = self.service.list() + + assert result.success is True + assert result.config == {"KEY1": "value1"} + assert result.error is None + self.logger.info.assert_called_once_with(configuration_listed.format(service="api")) + + def test_list_failure(self): + self.environment_service.list_config.return_value = (False, {}, "File not found") + + result = self.service.list() + + assert result.success is False + assert result.error == "File not found" + self.logger.error.assert_called_once_with(configuration_list_failed.format( + service="api", error="File not found" + )) + + def test_list_dry_run(self): + self.config.dry_run = True + + result = self.service.list() + + assert result.success is True + assert result.error is None + self.environment_service.list_config.assert_not_called() + + def test_list_and_format_success(self): + self.environment_service.list_config.return_value = (True, {"KEY1": "value1"}, None) + + output = self.service.list_and_format() + + assert configuration_listed.format(service="api") in output + assert " KEY1=value1" in output + + def test_list_and_format_failure(self): + self.environment_service.list_config.return_value = (False, {}, "File not found") + + output = self.service.list_and_format() + + assert configuration_list_failed.format(service="api", error="File not found") in output + + def test_list_and_format_dry_run(self): + self.config.dry_run = True + + output = self.service.list_and_format() + + assert dry_run_mode in output + assert dry_run_list_config.format(service="api") in output + assert end_dry_run in output + + def test_format_output_json(self): + result = ListResult( + service="api", + config={"KEY1": "value1"}, + success=True, + verbose=False, + output="json" + ) + + output = self.service._format_output(result, "json") + data = json.loads(output) + + assert data["service"] == "api" + assert data["success"] is True + assert data["config"] == {"KEY1": "value1"} + + def test_format_output_text_success(self): + result = ListResult( + service="api", + config={"KEY1": "value1", "KEY2": "value2"}, + success=True, + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert configuration_listed.format(service="api") in output + assert " KEY1=value1" in output + assert " KEY2=value2" in output + + def test_format_output_text_failure(self): + result = ListResult( + service="api", + success=False, + error="Test error", + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert configuration_list_failed.format(service="api", error="Test error") in output + + def test_format_output_text_no_config(self): + result = ListResult( + service="api", + config={}, + success=True, + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert no_configuration_found.format(service="api") in output + + +class TestList: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.action = List(self.logger) + + def test_list_action_init(self): + assert self.action.logger == self.logger + + def test_list_action_init_default(self): + action = List() + assert action.logger is None + + def test_list_success(self): + config = ListConfig(service="api") + + with patch('app.commands.conf.list.ListService') as mock_service_class: + mock_service = Mock() + mock_service.execute.return_value = ListResult( + service="api", + config={"KEY1": "value1"}, + success=True, + verbose=False, + output="text" + ) + mock_service_class.return_value = mock_service + + result = self.action.list(config) + + assert result.success is True + assert result.config == {"KEY1": "value1"} + + def test_format_output(self): + result = ListResult( + service="api", + config={"KEY1": "value1"}, + success=True, + verbose=False, + output="text" + ) + + with patch('app.commands.conf.list.ListService') as mock_service_class: + mock_service = Mock() + mock_service._format_output.return_value = "formatted output" + mock_service_class.return_value = mock_service + + output = self.action.format_output(result, "text") + + assert output == "formatted output" diff --git a/cli/app/commands/conf/tests/test_set.py b/cli/app/commands/conf/tests/test_set.py new file mode 100644 index 00000000..97fa9d78 --- /dev/null +++ b/cli/app/commands/conf/tests/test_set.py @@ -0,0 +1,357 @@ +import pytest +import json +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.conf.set import ( + EnvironmentManager, + SetResult, + SetConfig, + SetService, + Set +) +from app.commands.conf.messages import ( + configuration_set, + configuration_set_failed, + key_required, + value_required, + dry_run_mode, + dry_run_set_config, + end_dry_run +) +from app.utils.logger import Logger + + +class TestEnvironmentManager: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.manager = EnvironmentManager(self.logger) + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + def test_set_config_success(self, mock_write_env_file, mock_read_env_file): + mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) + mock_write_env_file.return_value = (True, None) + + success, error = self.manager.set_config("api", "KEY2", "value2") + + assert success is True + assert error is None + mock_read_env_file.assert_called_once_with("/etc/nixopus/source/api/.env") + mock_write_env_file.assert_called_once_with("/etc/nixopus/source/api/.env", {"KEY1": "value1", "KEY2": "value2"}) + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + def test_set_config_read_failure(self, mock_read_env_file): + mock_read_env_file.return_value = (False, {}, "File not found") + + success, error = self.manager.set_config("api", "KEY1", "value1") + + assert success is False + assert error == "File not found" + + @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + def test_set_config_write_failure(self, mock_write_env_file, mock_read_env_file): + mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) + mock_write_env_file.return_value = (False, "Write error") + + success, error = self.manager.set_config("api", "KEY2", "value2") + + assert success is False + assert error == "Write error" + + @patch('app.commands.conf.base.BaseEnvironmentManager.get_service_env_file') + def test_set_config_with_custom_env_file(self, mock_get_service_env_file): + mock_get_service_env_file.return_value = "/custom/.env" + + with patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') as mock_read: + with patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') as mock_write: + mock_read.return_value = (True, {}, None) + mock_write.return_value = (True, None) + + self.manager.set_config("api", "KEY1", "value1", "/custom/.env") + + mock_get_service_env_file.assert_called_once_with("api", "/custom/.env") + + +class TestSetConfig: + def test_valid_config_default(self): + config = SetConfig(key="TEST_KEY", value="test_value") + assert config.service == "api" + assert config.key == "TEST_KEY" + assert config.value == "test_value" + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.env_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = SetConfig( + service="view", + key="TEST_KEY", + value="test_value", + verbose=True, + output="json", + dry_run=True, + env_file="/path/to/.env" + ) + assert config.service == "view" + assert config.key == "TEST_KEY" + assert config.value == "test_value" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.env_file == "/path/to/.env" + + +class TestSetResult: + def test_set_result_default(self): + result = SetResult( + service="api", + key="TEST_KEY", + value="test_value", + verbose=False, + output="text" + ) + assert result.service == "api" + assert result.key == "TEST_KEY" + assert result.value == "test_value" + assert result.config == {} + assert result.verbose is False + assert result.output == "text" + assert result.success is False + assert result.error is None + + def test_set_result_success(self): + result = SetResult( + service="view", + key="TEST_KEY", + value="test_value", + config={"KEY1": "value1"}, + verbose=True, + output="json", + success=True + ) + assert result.service == "view" + assert result.key == "TEST_KEY" + assert result.value == "test_value" + assert result.config == {"KEY1": "value1"} + assert result.verbose is True + assert result.output == "json" + assert result.success is True + + +class TestSetService: + def setup_method(self): + self.config = SetConfig(key="TEST_KEY", value="test_value") + self.logger = Mock(spec=Logger) + self.environment_service = Mock() + self.service = SetService(self.config, self.logger, self.environment_service) + + def test_set_service_init(self): + assert self.service.config == self.config + assert self.service.logger == self.logger + assert self.service.environment_service == self.environment_service + + def test_set_service_init_defaults(self): + service = SetService(self.config) + assert service.config == self.config + assert service.logger is not None + assert service.environment_service is not None + + def test_create_result_success(self): + result = self.service._create_result(True, config_dict={"KEY1": "value1"}) + + assert result.service == "api" + assert result.key == "TEST_KEY" + assert result.value == "test_value" + assert result.config == {"KEY1": "value1"} + assert result.success is True + assert result.error is None + + def test_create_result_failure(self): + result = self.service._create_result(False, error="Test error") + + assert result.service == "api" + assert result.key == "TEST_KEY" + assert result.value == "test_value" + assert result.config == {} + assert result.success is False + assert result.error == "Test error" + + def test_set_missing_key(self): + self.config.key = None + + result = self.service.set() + + assert result.success is False + assert result.error == key_required + + def test_set_missing_value(self): + self.config.value = None + + result = self.service.set() + + assert result.success is False + assert result.error == value_required + + def test_set_success(self): + self.environment_service.set_config.return_value = (True, None) + + result = self.service.set() + + assert result.success is True + assert result.error is None + self.logger.info.assert_called_once_with(configuration_set.format( + service="api", key="TEST_KEY", value="test_value" + )) + self.environment_service.set_config.assert_called_once_with( + "api", "TEST_KEY", "test_value", None + ) + + def test_set_failure(self): + self.environment_service.set_config.return_value = (False, "Write error") + + result = self.service.set() + + assert result.success is False + assert result.error == "Write error" + self.logger.error.assert_called_once_with(configuration_set_failed.format( + service="api", error="Write error" + )) + + def test_set_dry_run(self): + self.config.dry_run = True + + result = self.service.set() + + assert result.success is True + assert result.error is None + self.environment_service.set_config.assert_not_called() + + def test_set_and_format_success(self): + self.environment_service.set_config.return_value = (True, None) + + output = self.service.set_and_format() + + assert configuration_set.format(service="api", key="TEST_KEY", value="test_value") in output + + def test_set_and_format_failure(self): + self.environment_service.set_config.return_value = (False, "Write error") + + output = self.service.set_and_format() + + assert configuration_set_failed.format(service="api", error="Write error") in output + + def test_set_and_format_dry_run(self): + self.config.dry_run = True + + output = self.service.set_and_format() + + assert dry_run_mode in output + assert dry_run_set_config.format( + service="api", key="TEST_KEY", value="test_value" + ) in output + assert end_dry_run in output + + def test_format_output_json(self): + result = SetResult( + service="api", + key="TEST_KEY", + value="test_value", + success=True, + verbose=False, + output="json" + ) + + output = self.service._format_output(result, "json") + data = json.loads(output) + + assert data["service"] == "api" + assert data["key"] == "TEST_KEY" + assert data["value"] == "test_value" + assert data["success"] is True + + def test_format_output_text_success(self): + result = SetResult( + service="api", + key="TEST_KEY", + value="test_value", + success=True, + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert configuration_set.format(service="api", key="TEST_KEY", value="test_value") in output + + def test_format_output_text_failure(self): + result = SetResult( + service="api", + key="TEST_KEY", + value="test_value", + success=False, + error="Test error", + verbose=False, + output="text" + ) + + output = self.service._format_output(result, "text") + + assert configuration_set_failed.format(service="api", error="Test error") in output + + +class TestSet: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.action = Set(self.logger) + + def test_set_action_init(self): + assert self.action.logger == self.logger + + def test_set_action_init_default(self): + action = Set() + assert action.logger is None + + def test_set_success(self): + config = SetConfig(key="TEST_KEY", value="test_value") + + with patch('app.commands.conf.set.SetService') as mock_service_class: + mock_service = Mock() + mock_service.execute.return_value = SetResult( + service="api", + key="TEST_KEY", + value="test_value", + success=True, + verbose=False, + output="text" + ) + mock_service_class.return_value = mock_service + + result = self.action.set(config) + + assert result.success is True + assert result.key == "TEST_KEY" + assert result.value == "test_value" + + def test_format_output(self): + result = SetResult( + service="api", + key="TEST_KEY", + value="test_value", + success=True, + verbose=False, + output="text" + ) + + with patch('app.commands.conf.set.SetService') as mock_service_class: + mock_service = Mock() + mock_service._format_output.return_value = "formatted output" + mock_service_class.return_value = mock_service + + output = self.action.format_output(result, "text") + + assert output == "formatted output" diff --git a/cli/app/commands/install/clone.py b/cli/app/commands/install/clone.py index b52c2b2c..67e8ab8a 100644 --- a/cli/app/commands/install/clone.py +++ b/cli/app/commands/install/clone.py @@ -29,7 +29,9 @@ invalid_path, invalid_repo, prerequisites_validation_failed, - failed_to_prepare_target_directory + failed_to_prepare_target_directory, + unknown_error, + default_branch ) class GitCloneProtocol(Protocol): @@ -54,7 +56,7 @@ def format_output(self, result: "CloneResult", output: str) -> str: message = successfully_cloned.format(repo=result.repo, path=result.path) output_message = self.output_formatter.create_success_message(message, result.model_dump()) else: - error = result.error or "Unknown error" + error = result.error or unknown_error output_message = self.output_formatter.create_error_message(error, result.model_dump()) return self.output_formatter.format_output(output_message, output) @@ -67,7 +69,7 @@ def format_dry_run(self, config: "CloneConfig") -> str: output.append(dry_run_command_would_be_executed) output.append(dry_run_command.format(command=' '.join(cmd))) output.append(dry_run_repository.format(repo=config.repo)) - output.append(dry_run_branch.format(branch=config.branch or "default")) + output.append(dry_run_branch.format(branch=config.branch or default_branch)) output.append(dry_run_target_path.format(path=config.path)) output.append(dry_run_force_mode.format(force=config.force)) diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index fd89c97e..8620376b 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -1,6 +1,7 @@ import typer from .run import Install from .clone import Clone, CloneConfig +from .ssh import SSH, SSHConfig from app.utils.logger import Logger install_app = typer.Typer( @@ -23,13 +24,13 @@ def main_install_callback(value: bool): @install_app.command() def clone( - repo: str = typer.Option("https://github.com/raghavyuva/nixopus", help="The repository to clone"), - branch: str = typer.Option("master", help="The branch to clone"), - path: str = typer.Option("/etc/nixopus", help="The path to clone the repository to"), - force: bool = typer.Option(False, help="Force the clone"), - verbose: bool = typer.Option(False, help="Verbose output"), - output: str = typer.Option("text", help="Output format, text, json"), - dry_run: bool = typer.Option(False, help="Dry run"), + repo: str = typer.Option("https://github.com/raghavyuva/nixopus", "--repo", "-r", help="The repository to clone"), + branch: str = typer.Option("master", "--branch", "-b", help="The branch to clone"), + path: str = typer.Option("/etc/nixopus", "--path", "-p", help="The path to clone the repository to"), + force: bool = typer.Option(False, "--force", "-f", help="Force the clone"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), ): """Clone a repository""" try: @@ -49,3 +50,39 @@ def clone( except Exception as e: logger.error(e) raise typer.Exit(1) + +def ssh( + path: str = typer.Option("~/.ssh/nixopus_ed25519", "--path", "-p", help="The SSH key path to generate"), + key_type: str = typer.Option("ed25519", "--key-type", "-t", help="The SSH key type (rsa, ed25519, ecdsa)"), + key_size: int = typer.Option(4096, "--key-size", "-s", help="The SSH key size"), + passphrase: str = typer.Option(None, "--passphrase", "-P", help="The passphrase to use for the SSH key"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + force: bool = typer.Option(False, "--force", "-f", help="Force overwrite existing SSH key"), + set_permissions: bool = typer.Option(True, "--set-permissions", "-S", help="Set proper file permissions"), + add_to_authorized_keys: bool = typer.Option(False, "--add-to-authorized-keys", "-a", help="Add public key to authorized_keys"), + create_ssh_directory: bool = typer.Option(True, "--create-ssh-directory", "-c", help="Create .ssh directory if it doesn't exist"), +): + """Generate an SSH key pair with proper permissions and optional authorized_keys integration""" + try: + logger = Logger(verbose=verbose) + config = SSHConfig( + path=path, + key_type=key_type, + key_size=key_size, + passphrase=passphrase, + verbose=verbose, + output=output, + dry_run=dry_run, + force=force, + set_permissions=set_permissions, + add_to_authorized_keys=add_to_authorized_keys, + create_ssh_directory=create_ssh_directory + ) + ssh_operation = SSH(logger=logger) + result = ssh_operation.generate(config) + logger.success(result.output) + except Exception as e: + logger.error(e) + raise typer.Exit(1) diff --git a/cli/app/commands/install/messages.py b/cli/app/commands/install/messages.py index 9b6c829c..08613072 100644 --- a/cli/app/commands/install/messages.py +++ b/cli/app/commands/install/messages.py @@ -29,3 +29,32 @@ invalid_path = "Invalid path format" prerequisites_validation_failed = "Prerequisites validation failed" failed_to_prepare_target_directory = "Failed to prepare target directory" +successfully_added_ssh_key = "Successfully generated SSH key: {key}" +ssh_key_add_failed = "SSH key generation failed: {error}" +unexpected_error_during_ssh_add = "Unexpected error during SSH key generation: {error}" +dry_run_ssh_key = "SSH key path: {key}" +dry_run_passphrase = "Passphrase: {passphrase}" +adding_ssh_key = "Generating SSH key: {key}" +invalid_ssh_key_path = "Invalid SSH key path format" +invalid_passphrase = "Invalid passphrase format" +ssh_key_not_found = "SSH key not found: {key}" +failed_to_add_ssh_key = "Failed to generate SSH key" +executing_ssh_keygen = "Executing ssh-keygen: {command}" +successfully_generated_ssh_key = "Successfully generated SSH key: {key}" +ssh_keygen_failed = "SSH key generation failed: {error}" +unexpected_error_during_ssh_keygen = "Unexpected error during SSH key generation: {error}" +generating_ssh_key = "Generating SSH key: {key}" +invalid_key_type = "Invalid key type format" +invalid_key_size = "Invalid key size format" +setting_permissions = "Setting proper file permissions" +adding_to_authorized_keys = "Adding public key to authorized_keys" +ssh_directory_created = "Created SSH directory: {dir}" +permissions_set_successfully = "File permissions set successfully" +authorized_keys_updated = "Public key added to authorized_keys" +ssh_key_already_exists = "SSH key already exists: {path}. Use --force to overwrite." +failed_to_add_ssh_key = "Failed to add SSH key to authorized_keys" +failed_to_read_public_key = "Failed to read public key" +failed_to_append_to_authorized_keys = "Failed to append to authorized_keys" +failed_to_add_to_authorized_keys = "Failed to add to authorized_keys: {error}" +unknown_error = "Unknown error" +default_branch = "default" diff --git a/cli/app/commands/install/ssh.py b/cli/app/commands/install/ssh.py new file mode 100644 index 00000000..a89ad1d9 --- /dev/null +++ b/cli/app/commands/install/ssh.py @@ -0,0 +1,365 @@ +import subprocess +import os +from typing import Protocol, Optional +from pydantic import BaseModel, Field, field_validator +import stat + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.lib import FileManager +from app.utils.output_formatter import OutputFormatter +from .messages import ( + executing_ssh_keygen, + successfully_generated_ssh_key, + ssh_keygen_failed, + unexpected_error_during_ssh_keygen, + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_ssh_key, + dry_run_passphrase, + dry_run_force_mode, + end_dry_run, + generating_ssh_key, + invalid_ssh_key_path, + prerequisites_validation_failed, + invalid_key_type, + invalid_key_size, + adding_to_authorized_keys, + authorized_keys_updated, + ssh_key_already_exists, + failed_to_read_public_key, + failed_to_append_to_authorized_keys, + failed_to_add_to_authorized_keys, + unknown_error +) + +class SSHKeyProtocol(Protocol): + def generate_ssh_key(self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> tuple[bool, str]: + ... + +class SSHCommandBuilder: + @staticmethod + def build_ssh_keygen_command(path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> list[str]: + cmd = ["ssh-keygen", "-t", key_type, "-f", path, "-N"] + + if key_type in ["rsa", "dsa", "ecdsa"]: + cmd.extend(["-b", str(key_size)]) + + if passphrase: + cmd.append(passphrase) + else: + cmd.append("") + return cmd + +class SSHFormatter: + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, result: "SSHResult", output: str) -> str: + if result.success: + message = successfully_generated_ssh_key.format(key=result.path) + output_message = self.output_formatter.create_success_message(message, result.model_dump()) + else: + error = result.error or unknown_error + output_message = self.output_formatter.create_error_message(error, result.model_dump()) + + return self.output_formatter.format_output(output_message, output) + + def format_dry_run(self, config: "SSHConfig") -> str: + cmd = SSHCommandBuilder.build_ssh_keygen_command(config.path, config.key_type, config.key_size, config.passphrase) + + output = [] + output.append(dry_run_mode) + output.append(dry_run_command_would_be_executed) + output.append(dry_run_command.format(command=' '.join(cmd))) + output.append(dry_run_ssh_key.format(key=config.path)) + output.append(f"Key type: {config.key_type}") + output.append(f"Key size: {config.key_size}") + if config.passphrase: + output.append(dry_run_passphrase.format(passphrase="***")) + output.append(dry_run_force_mode.format(force=config.force)) + output.append(end_dry_run) + return "\n".join(output) + +class SSHKeyManager: + def __init__(self, logger: LoggerProtocol): + self.file_manager = FileManager() + self.logger = logger + + def _check_ssh_keygen_availability(self) -> tuple[bool, str]: + try: + result = subprocess.run(["ssh-keygen", "-h"], capture_output=True, text=True, check=False) + return result.returncode == 0, None + except Exception as e: + return False, f"ssh-keygen not found: {e}" + + def _check_ssh_keygen_version(self) -> tuple[bool, str]: + try: + result = subprocess.run(["ssh-keygen", "-V"], capture_output=True, text=True, check=False) + if result.returncode == 0: + self.logger.debug(f"SSH keygen version: {result.stdout.strip()}") + return True, None + except Exception: + return True, None + + def generate_ssh_key(self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> tuple[bool, str]: + available, error = self._check_ssh_keygen_availability() + if not available: + return False, error + + self._check_ssh_keygen_version() + + cmd = SSHCommandBuilder.build_ssh_keygen_command(path, key_type, key_size, passphrase) + + try: + self.logger.info(executing_ssh_keygen.format(command=' '.join(cmd))) + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + self.logger.success(successfully_generated_ssh_key.format(key=path)) + return True, None + except subprocess.CalledProcessError as e: + error_msg = e.stderr.strip() if e.stderr else str(e) + self.logger.error(ssh_keygen_failed.format(error=error_msg)) + return False, error_msg + except Exception as e: + self.logger.error(unexpected_error_during_ssh_keygen.format(error=e)) + return False, str(e) + + def set_key_permissions(self, private_key_path: str, public_key_path: str) -> tuple[bool, str]: + try: + private_success, private_error = self.file_manager.set_permissions( + private_key_path, + stat.S_IRUSR | stat.S_IWUSR, + self.logger + ) + if not private_success: + return False, private_error + + public_success, public_error = self.file_manager.set_permissions( + public_key_path, + stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, + self.logger + ) + if not public_success: + return False, public_error + + return True, None + except Exception as e: + return False, f"Failed to set permissions: {e}" + + def create_ssh_directory(self, ssh_dir: str) -> tuple[bool, str]: + try: + return self.file_manager.create_directory( + ssh_dir, + stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, + self.logger + ) + except Exception as e: + return False, f"Failed to create SSH directory: {e}" + + def add_to_authorized_keys(self, public_key_path: str) -> tuple[bool, str]: + try: + self.logger.debug(adding_to_authorized_keys) + + success, content, error = self.file_manager.read_file_content(public_key_path, self.logger) + if not success: + return False, error or failed_to_read_public_key + + ssh_dir = self.file_manager.expand_user_path("~/.ssh") + authorized_keys_path = os.path.join(ssh_dir, "authorized_keys") + + if not os.path.exists(ssh_dir): + success, error = self.create_ssh_directory(ssh_dir) + if not success: + return False, error + + if not os.path.exists(authorized_keys_path): + try: + with open(authorized_keys_path, 'w') as f: + pass + os.chmod(authorized_keys_path, stat.S_IRUSR | stat.S_IWUSR) + except Exception as e: + return False, f"Failed to create authorized_keys file: {e}" + + success, error = self.file_manager.append_to_file(authorized_keys_path, content, self.logger) + if not success: + return False, error or failed_to_append_to_authorized_keys + + self.logger.debug(authorized_keys_updated) + return True, None + except Exception as e: + error_msg = failed_to_add_to_authorized_keys.format(error=e) + self.logger.error(error_msg) + return False, error_msg + +class SSHResult(BaseModel): + path: str + key_type: str + key_size: int + passphrase: Optional[str] + force: bool + verbose: bool + output: str + success: bool = False + error: Optional[str] = None + set_permissions: bool = True + add_to_authorized_keys: bool = False + create_ssh_directory: bool = True + +class SSHConfig(BaseModel): + path: str = Field(..., min_length=1, description="SSH key path to generate") + key_type: str = Field("rsa", description="SSH key type (rsa, ed25519, ecdsa)") + key_size: int = Field(4096, description="SSH key size") + passphrase: Optional[str] = Field(None, description="Passphrase for the SSH key") + force: bool = Field(False, description="Force overwrite existing SSH key") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format: text, json") + dry_run: bool = Field(False, description="Dry run mode") + set_permissions: bool = Field(True, description="Set proper file permissions") + add_to_authorized_keys: bool = Field(False, description="Add public key to authorized_keys") + create_ssh_directory: bool = Field(True, description="Create .ssh directory if it doesn't exist") + + @field_validator("path") + @classmethod + def validate_path(cls, path: str) -> str: + stripped_path = path.strip() + if not stripped_path: + raise ValueError(invalid_ssh_key_path) + + if not cls._is_valid_key_path(stripped_path): + raise ValueError(invalid_ssh_key_path) + return stripped_path + + @staticmethod + def _is_valid_key_path(key_path: str) -> bool: + return ( + key_path.startswith(('~', '/', './')) or + os.path.isabs(key_path) or + key_path.endswith(('.pem', '.key', '_rsa', '_ed25519')) + ) + + @field_validator("key_type") + @classmethod + def validate_key_type(cls, key_type: str) -> str: + valid_types = ["rsa", "ed25519", "ecdsa", "dsa"] + if key_type.lower() not in valid_types: + raise ValueError(invalid_key_type) + return key_type.lower() + + @field_validator("key_size") + @classmethod + def validate_key_size(cls, key_size: int, info) -> int: + key_type = info.data.get("key_type", "rsa") + + if key_type == "ed25519": + return 256 + elif key_type == "ecdsa": + if key_size not in [256, 384, 521]: + raise ValueError(invalid_key_size) + elif key_type == "dsa": + if key_size != 1024: + raise ValueError(invalid_key_size) + else: + if key_size < 1024 or key_size > 16384: + raise ValueError(invalid_key_size) + + return key_size + + @field_validator("passphrase") + @classmethod + def validate_passphrase(cls, passphrase: str) -> Optional[str]: + if not passphrase: + return None + stripped_passphrase = passphrase.strip() + if not stripped_passphrase: + return None + return stripped_passphrase + +class SSHService: + def __init__(self, config: SSHConfig, logger: LoggerProtocol = None, ssh_manager: SSHKeyProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.ssh_manager = ssh_manager or SSHKeyManager(self.logger) + self.formatter = SSHFormatter() + self.file_manager = FileManager() + + def _validate_prerequisites(self) -> bool: + expanded_key_path = self.file_manager.expand_user_path(self.config.path) + if os.path.exists(expanded_key_path) and not self.config.force: + self.logger.error(ssh_key_already_exists.format(path=self.config.path)) + return False + return True + + def _create_result(self, success: bool, error: str = None) -> SSHResult: + return SSHResult( + path=self.config.path, + key_type=self.config.key_type, + key_size=self.config.key_size, + passphrase=self.config.passphrase, + force=self.config.force, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error, + set_permissions=self.config.set_permissions, + add_to_authorized_keys=self.config.add_to_authorized_keys, + create_ssh_directory=self.config.create_ssh_directory + ) + + def generate_ssh_key(self) -> SSHResult: + self.logger.debug(generating_ssh_key.format(key=self.config.path)) + + if not self._validate_prerequisites(): + return self._create_result(False, prerequisites_validation_failed) + + if self.config.dry_run: + dry_run_output = self.formatter.format_dry_run(self.config) + return self._create_result(True, dry_run_output) + + expanded_path = self.file_manager.expand_user_path(self.config.path) + ssh_dir = self.file_manager.get_directory_path(expanded_path) + + if self.config.create_ssh_directory: + success, error = self.ssh_manager.create_ssh_directory(ssh_dir) + if not success: + return self._create_result(False, error) + + success, error = self.ssh_manager.generate_ssh_key( + self.config.path, + self.config.key_type, + self.config.key_size, + self.config.passphrase + ) + + if not success: + return self._create_result(False, error) + + if self.config.set_permissions: + public_key_path = self.file_manager.get_public_key_path(expanded_path) + success, error = self.ssh_manager.set_key_permissions(expanded_path, public_key_path) + if not success: + return self._create_result(False, error) + + if self.config.add_to_authorized_keys: + public_key_path = self.file_manager.get_public_key_path(expanded_path) + success, error = self.ssh_manager.add_to_authorized_keys(public_key_path) + if not success: + return self._create_result(False, error) + + return self._create_result(True) + + def generate_and_format(self) -> str: + result = self.generate_ssh_key() + return self.formatter.format_output(result, self.config.output) + +class SSH: + def __init__(self, logger: LoggerProtocol = None): + self.logger = logger or Logger() + + def generate(self, config: SSHConfig) -> SSHResult: + service = SSHService(config, self.logger) + return service.generate_ssh_key() + + def format_output(self, result: SSHResult, output: str) -> str: + formatter = SSHFormatter() + return formatter.format_output(result, output) diff --git a/cli/app/commands/install/tests/test_ssh.py b/cli/app/commands/install/tests/test_ssh.py new file mode 100644 index 00000000..2c04c0a5 --- /dev/null +++ b/cli/app/commands/install/tests/test_ssh.py @@ -0,0 +1,299 @@ +import unittest +from unittest.mock import Mock, patch, MagicMock +import tempfile +import os +from app.commands.install.ssh import SSH, SSHConfig, SSHKeyManager, SSHCommandBuilder + +class TestSSHKeyGeneration(unittest.TestCase): + def setUp(self): + self.mock_logger = Mock() + self.temp_dir = tempfile.mkdtemp() + self.test_key_path = os.path.join(self.temp_dir, "test_key") + + def tearDown(self): + import shutil + shutil.rmtree(self.temp_dir) + + def test_ssh_command_builder_rsa(self): + cmd = SSHCommandBuilder.build_ssh_keygen_command( + self.test_key_path, "rsa", 4096, "testpass" + ) + expected = ["ssh-keygen", "-t", "rsa", "-f", self.test_key_path, "-N", "-b", "4096", "testpass"] + self.assertEqual(cmd, expected) + + def test_ssh_command_builder_ed25519_no_passphrase(self): + cmd = SSHCommandBuilder.build_ssh_keygen_command( + self.test_key_path, "ed25519", 256 + ) + expected = ["ssh-keygen", "-t", "ed25519", "-f", self.test_key_path, "-N", ""] + self.assertEqual(cmd, expected) + + def test_ssh_command_builder_ecdsa(self): + cmd = SSHCommandBuilder.build_ssh_keygen_command( + self.test_key_path, "ecdsa", 256 + ) + expected = ["ssh-keygen", "-t", "ecdsa", "-f", self.test_key_path, "-N", "-b", "256", ""] + self.assertEqual(cmd, expected) + + def test_ssh_command_builder_dsa(self): + cmd = SSHCommandBuilder.build_ssh_keygen_command( + self.test_key_path, "dsa", 1024 + ) + expected = ["ssh-keygen", "-t", "dsa", "-f", self.test_key_path, "-N", "-b", "1024", ""] + self.assertEqual(cmd, expected) + + def test_ssh_config_validation_valid_key_type(self): + config = SSHConfig( + path=self.test_key_path, + key_type="ed25519", + key_size=256 + ) + self.assertEqual(config.key_type, "ed25519") + + def test_ssh_config_validation_invalid_key_type(self): + with self.assertRaises(ValueError): + SSHConfig( + path=self.test_key_path, + key_type="invalid_type", + key_size=256 + ) + + def test_ssh_config_validation_valid_key_size(self): + config = SSHConfig( + path=self.test_key_path, + key_type="rsa", + key_size=4096 + ) + self.assertEqual(config.key_size, 4096) + + def test_ssh_config_validation_invalid_key_size(self): + with self.assertRaises(ValueError): + SSHConfig( + path=self.test_key_path, + key_type="rsa", + key_size=512 + ) + + def test_ssh_config_ed25519_key_size_always_256(self): + config = SSHConfig( + path=self.test_key_path, + key_type="ed25519", + key_size=512 + ) + self.assertEqual(config.key_size, 256) + + @patch('subprocess.run') + def test_ssh_key_manager_availability_check_success(self, mock_run): + mock_result = Mock() + mock_result.returncode = 0 + mock_run.return_value = mock_result + + manager = SSHKeyManager(self.mock_logger) + available, error = manager._check_ssh_keygen_availability() + + self.assertTrue(available) + self.assertIsNone(error) + mock_run.assert_called_once_with(["ssh-keygen", "-h"], capture_output=True, text=True, check=False) + + @patch('subprocess.run') + def test_ssh_key_manager_availability_check_failure(self, mock_run): + mock_result = Mock() + mock_result.returncode = 1 + mock_run.return_value = mock_result + + manager = SSHKeyManager(self.mock_logger) + available, error = manager._check_ssh_keygen_availability() + + self.assertFalse(available) + self.assertIsNone(error) + + @patch('subprocess.run') + def test_ssh_key_manager_version_check(self, mock_run): + mock_result = Mock() + mock_result.returncode = 0 + mock_result.stdout = "OpenSSH_8.9p1" + mock_run.return_value = mock_result + + manager = SSHKeyManager(self.mock_logger) + success, error = manager._check_ssh_keygen_version() + + self.assertTrue(success) + self.assertIsNone(error) + self.mock_logger.debug.assert_called_with("SSH keygen version: OpenSSH_8.9p1") + + @patch('subprocess.run') + def test_ssh_key_manager_success(self, mock_run): + mock_avail_result = Mock() + mock_avail_result.returncode = 0 + + mock_version_result = Mock() + mock_version_result.returncode = 0 + mock_version_result.stdout = "OpenSSH_8.9p1" + + mock_gen_result = Mock() + mock_gen_result.returncode = 0 + + mock_run.side_effect = [mock_avail_result, mock_version_result, mock_gen_result] + + manager = SSHKeyManager(self.mock_logger) + success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) + + self.assertTrue(success) + self.assertIsNone(error) + self.assertEqual(mock_run.call_count, 3) + + @patch('subprocess.run') + def test_ssh_key_manager_failure(self, mock_run): + from subprocess import CalledProcessError + + mock_avail_result = Mock() + mock_avail_result.returncode = 0 + + mock_version_result = Mock() + mock_version_result.returncode = 0 + mock_run.side_effect = [mock_avail_result, mock_version_result, CalledProcessError(1, "ssh-keygen", stderr="Permission denied")] + + manager = SSHKeyManager(self.mock_logger) + success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) + + self.assertFalse(success) + self.assertEqual(error, "Permission denied") + + @patch('subprocess.run') + def test_ssh_key_manager_availability_failure(self, mock_run): + mock_result = Mock() + mock_result.returncode = 1 + mock_run.return_value = mock_result + + manager = SSHKeyManager(self.mock_logger) + success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) + + self.assertFalse(success) + self.assertIsNone(error) + + def test_ssh_service_dry_run(self): + config = SSHConfig( + path=self.test_key_path, + key_type="ed25519", + key_size=256, + dry_run=True + ) + + ssh = SSH(self.mock_logger) + result = ssh.generate(config) + + self.assertTrue(result.success) + self.assertIsNotNone(result.error) + self.assertIn("DRY RUN MODE", result.error) + + @patch('subprocess.run') + def test_ssh_service_force_overwrite(self, mock_run): + from subprocess import CalledProcessError + + with open(self.test_key_path, 'w') as f: + f.write("existing key") + + mock_avail_result = Mock() + mock_avail_result.returncode = 0 + + mock_version_result = Mock() + mock_version_result.returncode = 0 + + mock_run.side_effect = [mock_avail_result, mock_version_result, CalledProcessError(1, "ssh-keygen", stderr="ssh-keygen failed")] + + config = SSHConfig( + path=self.test_key_path, + key_type="ed25519", + key_size=256, + force=True + ) + + ssh = SSH(self.mock_logger) + result = ssh.generate(config) + + self.assertFalse(result.success) + self.assertIn("ssh-keygen", result.error) + + @patch('subprocess.run') + def test_ssh_key_manager_with_permissions(self, mock_run): + mock_result = Mock() + mock_result.returncode = 0 + mock_run.return_value = mock_result + + manager = SSHKeyManager(self.mock_logger) + + with open(self.test_key_path, 'w') as f: + f.write("private key content") + + with open(f"{self.test_key_path}.pub", 'w') as f: + f.write("public key content") + + success, error = manager.set_key_permissions(self.test_key_path, f"{self.test_key_path}.pub") + + self.assertTrue(success) + self.assertIsNone(error) + + def test_ssh_key_manager_create_ssh_directory(self): + manager = SSHKeyManager(self.mock_logger) + test_ssh_dir = os.path.join(self.temp_dir, "test_ssh") + + success, error = manager.create_ssh_directory(test_ssh_dir) + + self.assertTrue(success) + self.assertIsNone(error) + self.assertTrue(os.path.exists(test_ssh_dir)) + + @patch('builtins.open', create=True) + def test_ssh_key_manager_add_to_authorized_keys(self, mock_open): + manager = SSHKeyManager(self.mock_logger) + + public_key_path = f"{self.test_key_path}.pub" + with open(public_key_path, 'w') as f: + f.write("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... test@example.com") + + success, error = manager.add_to_authorized_keys(public_key_path) + + self.assertTrue(success) + self.assertIsNone(error) + + def test_ssh_config_with_new_options(self): + config = SSHConfig( + path=self.test_key_path, + key_type="ed25519", + key_size=256, + set_permissions=True, + add_to_authorized_keys=True, + create_ssh_directory=True + ) + + self.assertTrue(config.set_permissions) + self.assertTrue(config.add_to_authorized_keys) + self.assertTrue(config.create_ssh_directory) + + def test_ssh_config_ed25519_key_size_validation(self): + config = SSHConfig( + path=self.test_key_path, + key_type="ed25519", + key_size=512 + ) + self.assertEqual(config.key_size, 256) + + def test_ssh_config_ecdsa_key_size_validation(self): + valid_sizes = [256, 384, 521] + for size in valid_sizes: + config = SSHConfig( + path=self.test_key_path, + key_type="ecdsa", + key_size=size + ) + self.assertEqual(config.key_size, size) + + with self.assertRaises(ValueError): + SSHConfig( + path=self.test_key_path, + key_type="ecdsa", + key_size=512 + ) + +if __name__ == '__main__': + unittest.main() diff --git a/cli/app/commands/proxy/__init__.py b/cli/app/commands/proxy/__init__.py new file mode 100644 index 00000000..7254999f --- /dev/null +++ b/cli/app/commands/proxy/__init__.py @@ -0,0 +1,3 @@ +from .command import proxy_app + +__all__ = ["proxy_app"] diff --git a/cli/app/commands/proxy/base.py b/cli/app/commands/proxy/base.py new file mode 100644 index 00000000..b40c57da --- /dev/null +++ b/cli/app/commands/proxy/base.py @@ -0,0 +1,195 @@ +import subprocess +import os +import json +import requests +from typing import Protocol, Optional, Generic, TypeVar +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from .messages import ( + info_caddy_running, + caddy_status_code_error, + caddy_connection_failed, + info_config_loaded, + caddy_load_failed, + info_caddy_stopped, + config_file_not_found, + invalid_json_config +) + +TConfig = TypeVar('TConfig', bound=BaseModel) +TResult = TypeVar('TResult', bound=BaseModel) + +CADDY_BASE_URL = "http://localhost:{port}" +CADDY_CONFIG_ENDPOINT = "/config/" +CADDY_LOAD_ENDPOINT = "/load" +CADDY_STOP_ENDPOINT = "/stop" + +class CaddyServiceProtocol(Protocol): + def check_status(self, port: int = 2019) -> tuple[bool, str]: + ... + + def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: + ... + + def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: + ... + +class BaseCaddyCommandBuilder: + @staticmethod + def build_status_command(port: int = 2019) -> list[str]: + return ["curl", "-X", "GET", f"{CADDY_BASE_URL.format(port=port)}{CADDY_CONFIG_ENDPOINT}"] + + @staticmethod + def build_load_command(config_file: str, port: int = 2019) -> list[str]: + return ["curl", "-X", "POST", f"{CADDY_BASE_URL.format(port=port)}{CADDY_LOAD_ENDPOINT}", + "-H", "Content-Type: application/json", + "-d", f"@{config_file}"] + + @staticmethod + def build_stop_command(port: int = 2019) -> list[str]: + return ["curl", "-X", "POST", f"{CADDY_BASE_URL.format(port=port)}{CADDY_STOP_ENDPOINT}"] + +class BaseFormatter: + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, result: TResult, output: str, success_message: str, error_message: str) -> str: + if result.success: + message = success_message.format(port=result.proxy_port) + output_message = self.output_formatter.create_success_message(message, result.model_dump()) + else: + error = result.error or "Unknown error occurred" + output_message = self.output_formatter.create_error_message(error, result.model_dump()) + + return self.output_formatter.format_output(output_message, output) + + def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dict) -> str: + if hasattr(command_builder, 'build_status_command'): + cmd = command_builder.build_status_command(getattr(config, 'proxy_port', 2019)) + elif hasattr(command_builder, 'build_load_command'): + cmd = command_builder.build_load_command(getattr(config, 'config_file', ''), getattr(config, 'proxy_port', 2019)) + elif hasattr(command_builder, 'build_stop_command'): + cmd = command_builder.build_stop_command(getattr(config, 'proxy_port', 2019)) + else: + cmd = command_builder.build_command(config) + + output = [] + output.append(dry_run_messages["mode"]) + output.append(dry_run_messages["command_would_be_executed"]) + output.append(f"{dry_run_messages['command']} {' '.join(cmd)}") + output.append(f"{dry_run_messages['port']} {getattr(config, 'proxy_port', 2019)}") + + if hasattr(config, 'config_file') and getattr(config, 'config_file', None): + output.append(f"{dry_run_messages['config_file']} {getattr(config, 'config_file')}") + + output.append(dry_run_messages["end"]) + return "\n".join(output) + +class BaseCaddyService: + def __init__(self, logger: LoggerProtocol): + self.logger = logger + + def _get_caddy_url(self, port: int, endpoint: str) -> str: + return f"{CADDY_BASE_URL.format(port=port)}{endpoint}" + + def check_status(self, port: int = 2019) -> tuple[bool, str]: + try: + url = self._get_caddy_url(port, CADDY_CONFIG_ENDPOINT) + response = requests.get(url, timeout=5) + if response.status_code == 200: + return True, info_caddy_running + else: + return False, caddy_status_code_error.format(code=response.status_code) + except requests.exceptions.RequestException as e: + return False, caddy_connection_failed.format(error=str(e)) + except Exception as e: + return False, f"Unexpected error: {str(e)}" + + def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: + try: + with open(config_file, 'r') as f: + config_data = json.load(f) + + url = self._get_caddy_url(port, CADDY_LOAD_ENDPOINT) + response = requests.post( + url, + json=config_data, + headers={'Content-Type': 'application/json'}, + timeout=10 + ) + + if response.status_code == 200: + return True, info_config_loaded + else: + return False, caddy_load_failed.format(code=response.status_code, response=response.text) + except FileNotFoundError: + return False, config_file_not_found.format(file=config_file) + except json.JSONDecodeError as e: + return False, invalid_json_config.format(error=str(e)) + except requests.exceptions.RequestException as e: + return False, caddy_connection_failed.format(error=str(e)) + except Exception as e: + return False, f"Unexpected error: {str(e)}" + + def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: + try: + url = self._get_caddy_url(port, CADDY_STOP_ENDPOINT) + response = requests.post(url, timeout=5) + if response.status_code == 200: + return True, info_caddy_stopped + else: + return False, f"Failed to stop Caddy: {response.status_code}" + except requests.exceptions.RequestException as e: + return False, caddy_connection_failed.format(error=str(e)) + except Exception as e: + return False, f"Unexpected error: {str(e)}" + +class BaseConfig(BaseModel): + proxy_port: int = Field(2019, description="Caddy admin port") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format: text, json") + dry_run: bool = Field(False, description="Dry run mode") + + @field_validator("proxy_port") + @classmethod + def validate_proxy_port(cls, port: int) -> int: + if port < 1 or port > 65535: + raise ValueError("Port must be between 1 and 65535") + return port + +class BaseResult(BaseModel): + proxy_port: int + verbose: bool + output: str + success: bool = False + error: Optional[str] = None + +class BaseService(Generic[TConfig, TResult]): + def __init__(self, config: TConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.caddy_service = caddy_service + self.formatter = None + + def _create_result(self, success: bool, error: str = None) -> TResult: + raise NotImplementedError + + def execute(self) -> TResult: + raise NotImplementedError + + def execute_and_format(self) -> str: + raise NotImplementedError + +class BaseAction(Generic[TConfig, TResult]): + def __init__(self, logger: LoggerProtocol = None): + self.logger = logger + self.formatter = None + + def execute(self, config: TConfig) -> TResult: + raise NotImplementedError + + def format_output(self, result: TResult, output: str) -> str: + raise NotImplementedError diff --git a/cli/app/commands/proxy/command.py b/cli/app/commands/proxy/command.py new file mode 100644 index 00000000..c10bbc0d --- /dev/null +++ b/cli/app/commands/proxy/command.py @@ -0,0 +1,106 @@ +import typer +from app.utils.logger import Logger +from .load import Load, LoadConfig +from .status import Status, StatusConfig +from .stop import Stop, StopConfig + +proxy_app = typer.Typer( + name="proxy", + help="Manage Nixopus proxy (Caddy) configuration", +) + +@proxy_app.command() +def load( + proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), + dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), + config_file: str = typer.Option(None, "--config-file", "-c", help="Path to Caddy config file"), +): + """Load Caddy proxy configuration""" + logger = Logger(verbose=verbose) + + try: + config = LoadConfig( + proxy_port=proxy_port, + verbose=verbose, + output=output, + dry_run=dry_run, + config_file=config_file + ) + + load_service = Load(logger=logger) + result = load_service.load(config) + + if result.success: + logger.success(load_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@proxy_app.command() +def status( + proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), + dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), +): + """Check Caddy proxy status""" + logger = Logger(verbose=verbose) + + try: + config = StatusConfig( + proxy_port=proxy_port, + verbose=verbose, + output=output, + dry_run=dry_run + ) + + status_service = Status(logger=logger) + result = status_service.status(config) + + if result.success: + logger.success(status_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@proxy_app.command() +def stop( + proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), + dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), +): + """Stop Caddy proxy""" + logger = Logger(verbose=verbose) + + try: + config = StopConfig( + proxy_port=proxy_port, + verbose=verbose, + output=output, + dry_run=dry_run + ) + + stop_service = Stop(logger=logger) + result = stop_service.stop(config) + + if result.success: + logger.success(stop_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + diff --git a/cli/app/commands/proxy/load.py b/cli/app/commands/proxy/load.py new file mode 100644 index 00000000..4c7d355c --- /dev/null +++ b/cli/app/commands/proxy/load.py @@ -0,0 +1,135 @@ +import os +from typing import Protocol, Optional +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from .base import ( + BaseCaddyCommandBuilder, + BaseFormatter, + BaseCaddyService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_port, + dry_run_config_file, + end_dry_run, + proxy_initialized_successfully, + proxy_init_failed, + config_file_required, + debug_init_proxy, +) + +class CaddyServiceProtocol(Protocol): + def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: + ... + +class CaddyCommandBuilder(BaseCaddyCommandBuilder): + @staticmethod + def build_load_command(config_file: str, port: int = 2019) -> list[str]: + return BaseCaddyCommandBuilder.build_load_command(config_file, port) + +class LoadFormatter(BaseFormatter): + def format_output(self, result: "LoadResult", output: str) -> str: + return super().format_output(result, output, proxy_initialized_successfully, proxy_init_failed) + + def format_dry_run(self, config: "LoadConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "port": dry_run_port, + "config_file": dry_run_config_file, + "end": end_dry_run + } + return super().format_dry_run(config, CaddyCommandBuilder(), dry_run_messages) + +class CaddyService(BaseCaddyService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger) + + def load_config_file(self, config_file: str, port: int = 2019) -> tuple[bool, str]: + return self.load_config(config_file, port) + +class LoadResult(BaseResult): + config_file: Optional[str] + +class LoadConfig(BaseConfig): + config_file: Optional[str] = Field(None, description="Path to Caddy config file") + + @field_validator("config_file") + @classmethod + def validate_config_file(cls, config_file: str) -> Optional[str]: + if not config_file: + return None + stripped_config_file = config_file.strip() + if not stripped_config_file: + return None + if not os.path.exists(stripped_config_file): + raise ValueError(f"Configuration file not found: {stripped_config_file}") + return stripped_config_file + +class LoadService(BaseService[LoadConfig, LoadResult]): + def __init__(self, config: LoadConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): + super().__init__(config, logger, caddy_service) + self.caddy_service = caddy_service or CaddyService(self.logger) + self.formatter = LoadFormatter() + + def _create_result(self, success: bool, error: str = None) -> LoadResult: + return LoadResult( + proxy_port=self.config.proxy_port, + config_file=self.config.config_file, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def load(self) -> LoadResult: + return self.execute() + + def execute(self) -> LoadResult: + self.logger.debug(debug_init_proxy.format(port=self.config.proxy_port)) + + if not self.config.config_file: + self.logger.error(config_file_required) + return self._create_result(False, config_file_required) + + success, error = self.caddy_service.load_config_file( + self.config.config_file, + self.config.proxy_port + ) + + return self._create_result(success, error) + + def load_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Load(BaseAction[LoadConfig, LoadResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = LoadFormatter() + + def load(self, config: LoadConfig) -> LoadResult: + return self.execute(config) + + def execute(self, config: LoadConfig) -> LoadResult: + service = LoadService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: LoadResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/proxy/messages.py b/cli/app/commands/proxy/messages.py new file mode 100644 index 00000000..214fc1a7 --- /dev/null +++ b/cli/app/commands/proxy/messages.py @@ -0,0 +1,41 @@ +# Dry run messages +dry_run_mode = "🔍 DRY RUN MODE" +dry_run_command_would_be_executed = "The following command would be executed:" +dry_run_command = "Command:" +dry_run_port = "Port:" +dry_run_config_file = "Config file:" +end_dry_run = "--- End of dry run ---" + +# Success messages +proxy_initialized_successfully = "Caddy proxy initialized successfully on port {port}" +proxy_status_running = "Caddy proxy is running on port {port}" +proxy_reloaded_successfully = "Caddy proxy configuration reloaded successfully on port {port}" +proxy_stopped_successfully = "Caddy proxy stopped successfully on port {port}" + +# Error messages +proxy_init_failed = "Failed to initialize Caddy proxy" +proxy_status_stopped = "Caddy proxy is not running on port {port}" +proxy_status_failed = "Failed to check Caddy proxy status" +proxy_reload_failed = "Failed to reload Caddy proxy configuration" +proxy_stop_failed = "Failed to stop Caddy proxy" + +# Validation messages +config_file_required = "Configuration file is required" +config_file_not_found = "Configuration file not found: {file}" +invalid_json_config = "Invalid JSON in configuration file: {error}" + +# Connection messages +caddy_connection_failed = "Failed to connect to Caddy: {error}" +caddy_status_code_error = "Caddy returned status code: {code}" +caddy_load_failed = "Failed to load configuration: {code} - {response}" + +# Debug messages +debug_init_proxy = "Initializing Caddy proxy on port: {port}" +debug_check_status = "Checking Caddy proxy status on port: {port}" +debug_reload_config = "Reloading Caddy proxy configuration on port: {port}" +debug_stop_proxy = "Stopping Caddy proxy on port: {port}" + +# Info messages +info_caddy_running = "Caddy is running" +info_config_loaded = "Configuration loaded successfully" +info_caddy_stopped = "Caddy stopped successfully" \ No newline at end of file diff --git a/cli/app/commands/proxy/status.py b/cli/app/commands/proxy/status.py new file mode 100644 index 00000000..7ecdb764 --- /dev/null +++ b/cli/app/commands/proxy/status.py @@ -0,0 +1,117 @@ +from typing import Protocol +from pydantic import BaseModel + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from .base import ( + BaseCaddyCommandBuilder, + BaseFormatter, + BaseCaddyService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_port, + end_dry_run, + proxy_status_running, + proxy_status_stopped, + proxy_status_failed, + debug_check_status, +) + +class CaddyServiceProtocol(Protocol): + def check_status(self, port: int = 2019) -> tuple[bool, str]: + ... + +class CaddyCommandBuilder(BaseCaddyCommandBuilder): + @staticmethod + def build_status_command(port: int = 2019) -> list[str]: + return BaseCaddyCommandBuilder.build_status_command(port) + +class StatusFormatter(BaseFormatter): + def format_output(self, result: "StatusResult", output: str) -> str: + if result.success: + message = proxy_status_running.format(port=result.proxy_port) + else: + message = proxy_status_stopped.format(port=result.proxy_port) + + return super().format_output(result, output, message, proxy_status_failed) + + def format_dry_run(self, config: "StatusConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "port": dry_run_port, + "end": end_dry_run + } + return super().format_dry_run(config, CaddyCommandBuilder(), dry_run_messages) + +class CaddyService(BaseCaddyService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger) + + def get_status(self, port: int = 2019) -> tuple[bool, str]: + return self.check_status(port) + +class StatusResult(BaseResult): + pass + +class StatusConfig(BaseConfig): + pass + +class StatusService(BaseService[StatusConfig, StatusResult]): + def __init__(self, config: StatusConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): + super().__init__(config, logger, caddy_service) + self.caddy_service = caddy_service or CaddyService(self.logger) + self.formatter = StatusFormatter() + + def _create_result(self, success: bool, error: str = None) -> StatusResult: + return StatusResult( + proxy_port=self.config.proxy_port, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def status(self) -> StatusResult: + return self.execute() + + def execute(self) -> StatusResult: + self.logger.debug(debug_check_status.format(port=self.config.proxy_port)) + + success, error = self.caddy_service.get_status(self.config.proxy_port) + + return self._create_result(success, error) + + def status_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Status(BaseAction[StatusConfig, StatusResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = StatusFormatter() + + def status(self, config: StatusConfig) -> StatusResult: + return self.execute(config) + + def execute(self, config: StatusConfig) -> StatusResult: + service = StatusService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: StatusResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/proxy/stop.py b/cli/app/commands/proxy/stop.py new file mode 100644 index 00000000..4a29a38d --- /dev/null +++ b/cli/app/commands/proxy/stop.py @@ -0,0 +1,111 @@ +from typing import Protocol +from pydantic import BaseModel + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from .base import ( + BaseCaddyCommandBuilder, + BaseFormatter, + BaseCaddyService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_port, + end_dry_run, + proxy_stopped_successfully, + proxy_stop_failed, + debug_stop_proxy, +) + +class CaddyServiceProtocol(Protocol): + def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: + ... + +class CaddyCommandBuilder(BaseCaddyCommandBuilder): + @staticmethod + def build_stop_command(port: int = 2019) -> list[str]: + return BaseCaddyCommandBuilder.build_stop_command(port) + +class StopFormatter(BaseFormatter): + def format_output(self, result: "StopResult", output: str) -> str: + return super().format_output(result, output, proxy_stopped_successfully, proxy_stop_failed) + + def format_dry_run(self, config: "StopConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "port": dry_run_port, + "end": end_dry_run + } + return super().format_dry_run(config, CaddyCommandBuilder(), dry_run_messages) + +class CaddyService(BaseCaddyService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger) + + def stop_caddy(self, port: int = 2019) -> tuple[bool, str]: + return self.stop_proxy(port) + +class StopResult(BaseResult): + pass + +class StopConfig(BaseConfig): + pass + +class StopService(BaseService[StopConfig, StopResult]): + def __init__(self, config: StopConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): + super().__init__(config, logger, caddy_service) + self.caddy_service = caddy_service or CaddyService(self.logger) + self.formatter = StopFormatter() + + def _create_result(self, success: bool, error: str = None) -> StopResult: + return StopResult( + proxy_port=self.config.proxy_port, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def stop(self) -> StopResult: + return self.execute() + + def execute(self) -> StopResult: + self.logger.debug(debug_stop_proxy.format(port=self.config.proxy_port)) + + success, error = self.caddy_service.stop_caddy(self.config.proxy_port) + + return self._create_result(success, error) + + def stop_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Stop(BaseAction[StopConfig, StopResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = StopFormatter() + + def stop(self, config: StopConfig) -> StopResult: + return self.execute(config) + + def execute(self, config: StopConfig) -> StopResult: + service = StopService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: StopResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/proxy/tests/test_load.py b/cli/app/commands/proxy/tests/test_load.py new file mode 100644 index 00000000..6a89f146 --- /dev/null +++ b/cli/app/commands/proxy/tests/test_load.py @@ -0,0 +1,27 @@ +import pytest +from typer.testing import CliRunner +from app.commands.proxy.command import proxy_app +from unittest.mock import patch + +runner = CliRunner() + +def test_load_success(tmp_path): + config_file = tmp_path / "caddy.json" + config_file.write_text("{}") + with patch("app.commands.proxy.load.CaddyService.load_config_file", return_value=(True, "ok")): + result = runner.invoke(proxy_app, ["load", "--config-file", str(config_file)]) + assert result.exit_code == 0 + assert "successfully" in result.output + +def test_load_missing_config(): + result = runner.invoke(proxy_app, ["load"]) + assert result.exit_code != 0 + assert "Configuration file is required" in result.output + +def test_load_error(tmp_path): + config_file = tmp_path / "caddy.json" + config_file.write_text("{}") + with patch("app.commands.proxy.load.CaddyService.load_config_file", return_value=(False, "fail")): + result = runner.invoke(proxy_app, ["load", "--config-file", str(config_file)]) + assert result.exit_code != 0 + assert "fail" in result.output diff --git a/cli/app/commands/proxy/tests/test_status.py b/cli/app/commands/proxy/tests/test_status.py new file mode 100644 index 00000000..ad85b0ee --- /dev/null +++ b/cli/app/commands/proxy/tests/test_status.py @@ -0,0 +1,18 @@ +import pytest +from typer.testing import CliRunner +from app.commands.proxy.command import proxy_app +from unittest.mock import patch + +runner = CliRunner() + +def test_status_running(): + with patch("app.commands.proxy.status.CaddyService.get_status", return_value=(True, "Caddy is running")): + result = runner.invoke(proxy_app, ["status"]) + assert result.exit_code == 0 + assert "running" in result.output + +def test_status_not_running(): + with patch("app.commands.proxy.status.CaddyService.get_status", return_value=(False, "not running")): + result = runner.invoke(proxy_app, ["status"]) + assert result.exit_code != 0 + assert "not running" in result.output \ No newline at end of file diff --git a/cli/app/commands/proxy/tests/test_stop.py b/cli/app/commands/proxy/tests/test_stop.py new file mode 100644 index 00000000..66bea3ed --- /dev/null +++ b/cli/app/commands/proxy/tests/test_stop.py @@ -0,0 +1,18 @@ +import pytest +from typer.testing import CliRunner +from app.commands.proxy.command import proxy_app +from unittest.mock import patch + +runner = CliRunner() + +def test_stop_success(): + with patch("app.commands.proxy.stop.CaddyService.stop_caddy", return_value=(True, "Caddy stopped successfully")): + result = runner.invoke(proxy_app, ["stop"]) + assert result.exit_code == 0 + assert "stopped successfully" in result.output + +def test_stop_error(): + with patch("app.commands.proxy.stop.CaddyService.stop_caddy", return_value=(False, "fail")): + result = runner.invoke(proxy_app, ["stop"]) + assert result.exit_code != 0 + assert "fail" in result.output \ No newline at end of file diff --git a/cli/app/commands/service/__init__.py b/cli/app/commands/service/__init__.py new file mode 100644 index 00000000..8f616615 --- /dev/null +++ b/cli/app/commands/service/__init__.py @@ -0,0 +1 @@ +# Service package \ No newline at end of file diff --git a/cli/app/commands/service/base.py b/cli/app/commands/service/base.py new file mode 100644 index 00000000..bcc70c93 --- /dev/null +++ b/cli/app/commands/service/base.py @@ -0,0 +1,169 @@ +import subprocess +import os +from typing import Protocol, Optional, Generic, TypeVar +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter + +TConfig = TypeVar('TConfig', bound=BaseModel) +TResult = TypeVar('TResult', bound=BaseModel) + +class DockerServiceProtocol(Protocol): + def execute_services(self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs) -> tuple[bool, str]: + ... + +class BaseDockerCommandBuilder: + @staticmethod + def build_command(action: str, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs) -> list[str]: + cmd = ["docker", "compose"] + if compose_file: + cmd.extend(["-f", compose_file]) + cmd.append(action) + + if action == "up" and kwargs.get("detach", True): + cmd.append("-d") + + if env_file: + cmd.extend(["--env-file", env_file]) + + if name != "all": + cmd.append(name) + + return cmd + +class BaseFormatter: + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, result: TResult, output: str, success_message: str, error_message: str) -> str: + if result.success: + message = success_message.format(services=result.name) + output_message = self.output_formatter.create_success_message(message, result.model_dump()) + else: + error = result.error or "Unknown error occurred" + output_message = self.output_formatter.create_error_message(error, result.model_dump()) + + return self.output_formatter.format_output(output_message, output) + + def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dict) -> str: + if hasattr(command_builder, 'build_up_command'): + cmd = command_builder.build_up_command(getattr(config, 'name', 'all'), getattr(config, 'detach', True), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) + elif hasattr(command_builder, 'build_down_command'): + cmd = command_builder.build_down_command(getattr(config, 'name', 'all'), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) + elif hasattr(command_builder, 'build_ps_command'): + cmd = command_builder.build_ps_command(getattr(config, 'name', 'all'), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) + elif hasattr(command_builder, 'build_restart_command'): + cmd = command_builder.build_restart_command(getattr(config, 'name', 'all'), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) + else: + cmd = command_builder.build_command(config) + + output = [] + output.append(dry_run_messages["mode"]) + output.append(dry_run_messages["command_would_be_executed"]) + output.append(f"{dry_run_messages['command']} {' '.join(cmd)}") + output.append(f"{dry_run_messages['service']} {getattr(config, 'name', 'all')}") + + if hasattr(config, 'detach'): + output.append(f"{dry_run_messages.get('detach_mode', 'Detach mode:')} {getattr(config, 'detach', True)}") + + if getattr(config, 'env_file', None): + output.append(f"{dry_run_messages['env_file']} {getattr(config, 'env_file')}") + + output.append(dry_run_messages["end"]) + return "\n".join(output) + +class BaseDockerService: + def __init__(self, logger: LoggerProtocol, action: str): + self.logger = logger + self.action = action + + def _past_tense(self): + if self.action == "up": + return "upped" + elif self.action == "down": + return "downed" + return f"{self.action}ed" + + def execute_services(self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs) -> tuple[bool, str]: + cmd = BaseDockerCommandBuilder.build_command(self.action, name, env_file, compose_file, **kwargs) + + try: + self.logger.info(f"{self.action.capitalize()}ing services: {name}") + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + self.logger.success(f"Services {self._past_tense()} successfully: {name}") + return True, None + except subprocess.CalledProcessError as e: + self.logger.error(f"Service {self.action} failed: {e.stderr}") + return False, e.stderr + except Exception as e: + self.logger.error(f"Unexpected error during {self.action}: {e}") + return False, str(e) + +class BaseConfig(BaseModel): + name: str = Field("all", description="Name of the service") + env_file: Optional[str] = Field(None, description="Path to environment file") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format: text, json") + dry_run: bool = Field(False, description="Dry run mode") + compose_file: Optional[str] = Field(None, description="Path to the compose file") + + @field_validator("env_file") + @classmethod + def validate_env_file(cls, env_file: str) -> Optional[str]: + if not env_file: + return None + stripped_env_file = env_file.strip() + if not stripped_env_file: + return None + if not os.path.exists(stripped_env_file): + raise ValueError(f"Environment file not found: {stripped_env_file}") + return stripped_env_file + + @field_validator("compose_file") + @classmethod + def validate_compose_file(cls, compose_file: str) -> Optional[str]: + if not compose_file: + return None + stripped_compose_file = compose_file.strip() + if not stripped_compose_file: + return None + if not os.path.exists(stripped_compose_file): + raise ValueError(f"Compose file not found: {stripped_compose_file}") + return stripped_compose_file + +class BaseResult(BaseModel): + name: str + env_file: Optional[str] + verbose: bool + output: str + success: bool = False + error: Optional[str] = None + +class BaseService(Generic[TConfig, TResult]): + def __init__(self, config: TConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.docker_service = docker_service + self.formatter = None + + def _create_result(self, success: bool, error: str = None) -> TResult: + raise NotImplementedError + + def execute(self) -> TResult: + raise NotImplementedError + + def execute_and_format(self) -> str: + raise NotImplementedError + +class BaseAction(Generic[TConfig, TResult]): + def __init__(self, logger: LoggerProtocol = None): + self.logger = logger + self.formatter = None + + def execute(self, config: TConfig) -> TResult: + raise NotImplementedError + + def format_output(self, result: TResult, output: str) -> str: + raise NotImplementedError diff --git a/cli/app/commands/service/command.py b/cli/app/commands/service/command.py new file mode 100644 index 00000000..a71e99ed --- /dev/null +++ b/cli/app/commands/service/command.py @@ -0,0 +1,152 @@ +import typer +from app.utils.logger import Logger +from .up import Up, UpConfig +from .down import Down, DownConfig +from .ps import Ps, PsConfig +from .restart import Restart, RestartConfig + +service_app = typer.Typer( + help="Manage Nixopus services" +) + +@service_app.command() +def up( + name: str = typer.Option("all", "--name", "-n", help="The name of the service to start, defaults to all"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), + detach: bool = typer.Option(False, "--detach", "-d", help="Detach from the service and run in the background"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), +): + """Start Nixopus services""" + logger = Logger(verbose=verbose) + + try: + config = UpConfig( + name=name, + detach=detach, + env_file=env_file, + verbose=verbose, + output=output, + dry_run=dry_run, + compose_file=compose_file + ) + + up_service = Up(logger=logger) + result = up_service.up(config) + + if result.success: + logger.success(up_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@service_app.command() +def down( + name: str = typer.Option("all", "--name", "-n", help="The name of the service to stop, defaults to all"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), +): + """Stop Nixopus services""" + logger = Logger(verbose=verbose) + + try: + config = DownConfig( + name=name, + env_file=env_file, + verbose=verbose, + output=output, + dry_run=dry_run, + compose_file=compose_file + ) + + down_service = Down(logger=logger) + result = down_service.down(config) + + if result.success: + logger.success(down_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@service_app.command() +def ps( + name: str = typer.Option("all", "--name", "-n", help="The name of the service to show, defaults to all"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), +): + """Show status of Nixopus services""" + logger = Logger(verbose=verbose) + + try: + config = PsConfig( + name=name, + env_file=env_file, + verbose=verbose, + output=output, + dry_run=dry_run, + compose_file=compose_file + ) + + ps_service = Ps(logger=logger) + result = ps_service.ps(config) + + if result.success: + logger.success(ps_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) + +@service_app.command() +def restart( + name: str = typer.Option("all", "--name", "-n", help="The name of the service to restart, defaults to all"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), +): + """Restart Nixopus services""" + logger = Logger(verbose=verbose) + + try: + config = RestartConfig( + name=name, + env_file=env_file, + verbose=verbose, + output=output, + dry_run=dry_run, + compose_file=compose_file + ) + + restart_service = Restart(logger=logger) + result = restart_service.restart(config) + + if result.success: + logger.success(restart_service.format_output(result, output)) + else: + logger.error(result.error) + raise typer.Exit(1) + + except Exception as e: + logger.error(str(e)) + raise typer.Exit(1) diff --git a/cli/app/commands/service/down.py b/cli/app/commands/service/down.py new file mode 100644 index 00000000..a00ce2bb --- /dev/null +++ b/cli/app/commands/service/down.py @@ -0,0 +1,118 @@ +import subprocess +import os +from typing import Protocol, Optional +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from .base import ( + BaseDockerCommandBuilder, + BaseFormatter, + BaseDockerService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_service, + dry_run_env_file, + end_dry_run, + services_stopped_successfully, + service_stop_failed, +) + +class DockerServiceProtocol(Protocol): + def stop_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + ... + +class DockerCommandBuilder(BaseDockerCommandBuilder): + @staticmethod + def build_down_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: + return BaseDockerCommandBuilder.build_command("down", name, env_file, compose_file) + +class DownFormatter(BaseFormatter): + def format_output(self, result: "DownResult", output: str) -> str: + return super().format_output(result, output, services_stopped_successfully, service_stop_failed) + + def format_dry_run(self, config: "DownConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "service": dry_run_service, + "env_file": dry_run_env_file, + "end": end_dry_run + } + return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + +class DockerService(BaseDockerService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger, "down") + + def stop_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + return self.execute_services(name, env_file, compose_file) + +class DownResult(BaseResult): + pass + +class DownConfig(BaseConfig): + pass + +class DownService(BaseService[DownConfig, DownResult]): + def __init__(self, config: DownConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): + super().__init__(config, logger, docker_service) + self.docker_service = docker_service or DockerService(self.logger) + self.formatter = DownFormatter() + + def _create_result(self, success: bool, error: str = None) -> DownResult: + return DownResult( + name=self.config.name, + env_file=self.config.env_file, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def down(self) -> DownResult: + return self.execute() + + def execute(self) -> DownResult: + self.logger.debug(f"Stopping services: {self.config.name}") + + success, error = self.docker_service.stop_services( + self.config.name, + self.config.env_file, + self.config.compose_file + ) + + return self._create_result(success, error) + + def down_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Down(BaseAction[DownConfig, DownResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = DownFormatter() + + def down(self, config: DownConfig) -> DownResult: + return self.execute(config) + + def execute(self, config: DownConfig) -> DownResult: + service = DownService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: DownResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/service/messages.py b/cli/app/commands/service/messages.py new file mode 100644 index 00000000..aab9e9e2 --- /dev/null +++ b/cli/app/commands/service/messages.py @@ -0,0 +1,24 @@ +dry_run_mode = "=== DRY RUN MODE ===" +dry_run_command_would_be_executed = "The following commands would be executed:" +dry_run_command = "Command:" +dry_run_service = "Service:" +dry_run_detach_mode = "Detach mode:" +dry_run_env_file = "Environment file:" +end_dry_run = "=== END DRY RUN ===" +starting_services = "Starting services: {services}" +services_started_successfully = "Services started successfully: {services}" +service_start_failed = "Service start failed: {error}" +unexpected_error_during_start = "Unexpected error during start: {error}" +stopping_services = "Stopping services: {services}" +services_stopped_successfully = "Services stopped successfully: {services}" +service_stop_failed = "Service stop failed: {error}" +unexpected_error_during_stop = "Unexpected error during stop: {error}" +checking_services = "Checking status of services: {services}" +services_status_retrieved = "Services status retrieved successfully: {services}" +service_status_failed = "Service status check failed: {error}" +unexpected_error_during_status = "Unexpected error during status check: {error}" +restarting_services = "Restarting services: {services}" +services_restarted_successfully = "Services restarted successfully: {services}" +service_restart_failed = "Service restart failed: {error}" +unexpected_error_during_restart = "Unexpected error during restart: {error}" +unknown_error = "Unknown error occurred" diff --git a/cli/app/commands/service/ps.py b/cli/app/commands/service/ps.py new file mode 100644 index 00000000..01f0d98c --- /dev/null +++ b/cli/app/commands/service/ps.py @@ -0,0 +1,113 @@ +from typing import Optional +from pydantic import Field + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol, DockerServiceProtocol +from .base import ( + BaseDockerCommandBuilder, + BaseFormatter, + BaseDockerService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_service, + dry_run_env_file, + end_dry_run, + services_status_retrieved, + service_status_failed, + unknown_error +) + +class DockerCommandBuilder(BaseDockerCommandBuilder): + @staticmethod + def build_ps_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: + return BaseDockerCommandBuilder.build_command("ps", name, env_file, compose_file) + +class PsFormatter(BaseFormatter): + def format_output(self, result: "PsResult", output: str) -> str: + return super().format_output(result, output, services_status_retrieved, service_status_failed) + + def format_dry_run(self, config: "PsConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "service": dry_run_service, + "env_file": dry_run_env_file, + "end": end_dry_run + } + return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + +class DockerService(BaseDockerService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger, "ps") + + def show_services_status(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + return self.execute_services(name, env_file, compose_file) + +class PsResult(BaseResult): + pass + +class PsConfig(BaseConfig): + pass + +class PsService(BaseService[PsConfig, PsResult]): + def __init__(self, config: PsConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): + super().__init__(config, logger, docker_service) + self.docker_service = docker_service or DockerService(self.logger) + self.formatter = PsFormatter() + + def _create_result(self, success: bool, error: str = None) -> PsResult: + return PsResult( + name=self.config.name, + env_file=self.config.env_file, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def ps(self) -> PsResult: + return self.execute() + + def execute(self) -> PsResult: + self.logger.debug(f"Checking status of services: {self.config.name}") + + success, error = self.docker_service.show_services_status( + self.config.name, + self.config.env_file, + self.config.compose_file + ) + + return self._create_result(success, error) + + def ps_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Ps(BaseAction[PsConfig, PsResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = PsFormatter() + + def ps(self, config: PsConfig) -> PsResult: + return self.execute(config) + + def execute(self, config: PsConfig) -> PsResult: + service = PsService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: PsResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/service/restart.py b/cli/app/commands/service/restart.py new file mode 100644 index 00000000..fec6c119 --- /dev/null +++ b/cli/app/commands/service/restart.py @@ -0,0 +1,113 @@ +from typing import Optional +from pydantic import Field + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol, DockerServiceProtocol +from .base import ( + BaseDockerCommandBuilder, + BaseFormatter, + BaseDockerService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_service, + dry_run_env_file, + end_dry_run, + services_restarted_successfully, + service_restart_failed, + unknown_error +) + +class DockerCommandBuilder(BaseDockerCommandBuilder): + @staticmethod + def build_restart_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: + return BaseDockerCommandBuilder.build_command("restart", name, env_file, compose_file) + +class RestartFormatter(BaseFormatter): + def format_output(self, result: "RestartResult", output: str) -> str: + return super().format_output(result, output, services_restarted_successfully, service_restart_failed) + + def format_dry_run(self, config: "RestartConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "service": dry_run_service, + "env_file": dry_run_env_file, + "end": end_dry_run + } + return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + +class DockerService(BaseDockerService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger, "restart") + + def restart_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + return self.execute_services(name, env_file, compose_file) + +class RestartResult(BaseResult): + pass + +class RestartConfig(BaseConfig): + pass + +class RestartService(BaseService[RestartConfig, RestartResult]): + def __init__(self, config: RestartConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): + super().__init__(config, logger, docker_service) + self.docker_service = docker_service or DockerService(self.logger) + self.formatter = RestartFormatter() + + def _create_result(self, success: bool, error: str = None) -> RestartResult: + return RestartResult( + name=self.config.name, + env_file=self.config.env_file, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def restart(self) -> RestartResult: + return self.execute() + + def execute(self) -> RestartResult: + self.logger.debug(f"Restarting services: {self.config.name}") + + success, error = self.docker_service.restart_services( + self.config.name, + self.config.env_file, + self.config.compose_file + ) + + return self._create_result(success, error) + + def restart_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Restart(BaseAction[RestartConfig, RestartResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = RestartFormatter() + + def restart(self, config: RestartConfig) -> RestartResult: + return self.execute(config) + + def execute(self, config: RestartConfig) -> RestartResult: + service = RestartService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: RestartResult, output: str) -> str: + return self.formatter.format_output(result, output) \ No newline at end of file diff --git a/cli/app/commands/service/tests/__init__.py b/cli/app/commands/service/tests/__init__.py new file mode 100644 index 00000000..5998a075 --- /dev/null +++ b/cli/app/commands/service/tests/__init__.py @@ -0,0 +1 @@ +# Tests package \ No newline at end of file diff --git a/cli/app/commands/service/tests/test_base.py b/cli/app/commands/service/tests/test_base.py new file mode 100644 index 00000000..2ee247c5 --- /dev/null +++ b/cli/app/commands/service/tests/test_base.py @@ -0,0 +1,325 @@ +import pytest +import subprocess +import os +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.service.base import ( + BaseDockerCommandBuilder, + BaseFormatter, + BaseDockerService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from app.utils.logger import Logger +from app.commands.service.up import UpConfig + + +class TestBaseDockerCommandBuilder: + def test_build_command_up_default(self): + cmd = BaseDockerCommandBuilder.build_command("up", "all", None, None, detach=True) + assert cmd == ["docker", "compose", "up", "-d"] + + def test_build_command_up_with_service(self): + cmd = BaseDockerCommandBuilder.build_command("up", "web", None, None, detach=True) + assert cmd == ["docker", "compose", "up", "-d", "web"] + + def test_build_command_up_without_detach(self): + cmd = BaseDockerCommandBuilder.build_command("up", "all", None, None, detach=False) + assert cmd == ["docker", "compose", "up"] + + def test_build_command_down_default(self): + cmd = BaseDockerCommandBuilder.build_command("down", "all", None, None) + assert cmd == ["docker", "compose", "down"] + + def test_build_command_down_with_service(self): + cmd = BaseDockerCommandBuilder.build_command("down", "web", None, None) + assert cmd == ["docker", "compose", "down", "web"] + + def test_build_command_with_env_file(self): + cmd = BaseDockerCommandBuilder.build_command("up", "all", "/path/to/.env", None, detach=True) + assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] + + def test_build_command_with_compose_file(self): + cmd = BaseDockerCommandBuilder.build_command("up", "all", None, "/path/to/docker-compose.yml", detach=True) + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] + + def test_build_command_with_all_parameters(self): + cmd = BaseDockerCommandBuilder.build_command("up", "web", "/path/to/.env", "/path/to/docker-compose.yml", detach=False) + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "--env-file", "/path/to/.env", "web"] + + +class TestBaseFormatter: + def setup_method(self): + self.formatter = BaseFormatter() + + def test_format_output_success(self): + result = BaseResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + formatted = self.formatter.format_output(result, "text", "Services started: {services}", "Service failed: {error}") + assert "Services started: web" in formatted + + def test_format_output_failure(self): + result = BaseResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=False, + error="Service not found" + ) + formatted = self.formatter.format_output(result, "text", "Services started: {services}", "Service failed: {error}") + assert "Service not found" in formatted + + def test_format_output_json(self): + result = BaseResult( + name="web", + env_file=None, + verbose=False, + output="json", + success=True + ) + formatted = self.formatter.format_output(result, "json", "Services started: {services}", "Service failed: {error}") + import json + data = json.loads(formatted) + assert data["success"] is True + assert "Services started: web" in data["message"] + + def test_format_dry_run(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = UpConfig( + name="web", + env_file="/path/to/.env", + dry_run=True, + detach=True + ) + + class MockCommandBuilder: + def build_up_command(self, name, detach, env_file, compose_file): + return ["docker", "compose", "up", "-d", "web"] + + dry_run_messages = { + "mode": "=== DRY RUN MODE ===", + "command_would_be_executed": "The following commands would be executed:", + "command": "Command:", + "service": "Service:", + "env_file": "Environment file:", + "detach_mode": "Detach mode:", + "end": "=== END DRY RUN ===" + } + + formatted = self.formatter.format_dry_run(config, MockCommandBuilder(), dry_run_messages) + assert "=== DRY RUN MODE ===" in formatted + assert "Command:" in formatted + assert "Service: web" in formatted + assert "Environment file: /path/to/.env" in formatted + assert "Detach mode: True" in formatted + + +class TestBaseDockerService: + def setup_method(self): + self.logger = Mock(spec=Logger) + + @patch('subprocess.run') + def test_execute_services_success(self, mock_run): + mock_run.return_value = Mock(returncode=0) + docker_service = BaseDockerService(self.logger, "up") + + success, error = docker_service.execute_services("web") + + assert success is True + assert error is None + self.logger.info.assert_called_once_with("Uping services: web") + self.logger.success.assert_called_once_with("Services upped successfully: web") + + @patch('subprocess.run') + def test_execute_services_failure(self, mock_run): + mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose", stderr="Service not found") + docker_service = BaseDockerService(self.logger, "down") + + success, error = docker_service.execute_services("web") + + assert success is False + assert error == "Service not found" + self.logger.error.assert_called_once_with("Service down failed: Service not found") + + @patch('subprocess.run') + def test_execute_services_unexpected_error(self, mock_run): + mock_run.side_effect = Exception("Unexpected error") + docker_service = BaseDockerService(self.logger, "up") + + success, error = docker_service.execute_services("web") + + assert success is False + assert error == "Unexpected error" + self.logger.error.assert_called_once_with("Unexpected error during up: Unexpected error") + + +class TestBaseConfig: + def test_valid_config_default(self): + config = BaseConfig() + assert config.name == "all" + assert config.env_file is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.compose_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = BaseConfig( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + dry_run=True, + compose_file="/path/to/docker-compose.yml" + ) + assert config.name == "web" + assert config.env_file == "/path/to/.env" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_env_file_exists(self, mock_exists): + mock_exists.return_value = True + config = BaseConfig(env_file="/path/to/.env") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + BaseConfig(env_file="/path/to/.env") + + def test_validate_env_file_none(self): + config = BaseConfig(env_file=None) + assert config.env_file is None + + def test_validate_env_file_empty(self): + config = BaseConfig(env_file="") + assert config.env_file is None + + def test_validate_env_file_whitespace(self): + config = BaseConfig(env_file=" ") + assert config.env_file is None + + def test_validate_env_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = BaseConfig(env_file=" /path/to/.env ") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_compose_file_exists(self, mock_exists): + mock_exists.return_value = True + config = BaseConfig(compose_file="/path/to/docker-compose.yml") + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_compose_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + BaseConfig(compose_file="/path/to/docker-compose.yml") + + def test_validate_compose_file_none(self): + config = BaseConfig(compose_file=None) + assert config.compose_file is None + + def test_validate_compose_file_empty(self): + config = BaseConfig(compose_file="") + assert config.compose_file is None + + def test_validate_compose_file_whitespace(self): + config = BaseConfig(compose_file=" ") + assert config.compose_file is None + + def test_validate_compose_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = BaseConfig(compose_file=" /path/to/docker-compose.yml ") + assert config.compose_file == "/path/to/docker-compose.yml" + + +class TestBaseResult: + def test_base_result_creation(self): + result = BaseResult( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + success=True, + error=None + ) + + assert result.name == "web" + assert result.env_file == "/path/to/.env" + assert result.verbose is True + assert result.output == "json" + assert result.success is True + assert result.error is None + + def test_base_result_default_success(self): + result = BaseResult( + name="web", + env_file=None, + verbose=False, + output="text" + ) + + assert result.name == "web" + assert result.success is False + assert result.error is None + + +class TestBaseService: + def setup_method(self): + self.config = BaseConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + self.logger = Mock(spec=Logger) + self.docker_service = Mock() + self.service = BaseService(self.config, self.logger, self.docker_service) + + def test_create_result_not_implemented(self): + with pytest.raises(NotImplementedError): + self.service._create_result(True) + + def test_execute_not_implemented(self): + with pytest.raises(NotImplementedError): + self.service.execute() + + def test_execute_and_format_not_implemented(self): + with pytest.raises(NotImplementedError): + self.service.execute_and_format() + + +class TestBaseAction: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.action = BaseAction(self.logger) + + def test_execute_not_implemented(self): + config = BaseConfig(name="web") + with pytest.raises(NotImplementedError): + self.action.execute(config) + + def test_format_output_not_implemented(self): + result = BaseResult(name="web", env_file=None, verbose=False, output="text") + with pytest.raises(NotImplementedError): + self.action.format_output(result, "text") diff --git a/cli/app/commands/service/tests/test_down.py b/cli/app/commands/service/tests/test_down.py new file mode 100644 index 00000000..d1696843 --- /dev/null +++ b/cli/app/commands/service/tests/test_down.py @@ -0,0 +1,441 @@ +import pytest +import subprocess +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.service.down import ( + DockerCommandBuilder, + DownFormatter, + DockerService, + DownResult, + DownConfig, + DownService, + Down +) +from app.commands.service.messages import ( + dry_run_mode, + dry_run_command, + dry_run_service, + dry_run_env_file, + services_stopped_successfully, +) +from app.utils.logger import Logger + + +class TestDockerCommandBuilder: + def test_build_down_command_default(self): + cmd = DockerCommandBuilder.build_down_command() + assert cmd == ["docker", "compose", "down"] + + def test_build_down_command_with_service_name(self): + cmd = DockerCommandBuilder.build_down_command("web") + assert cmd == ["docker", "compose", "down", "web"] + + def test_build_down_command_with_env_file(self): + cmd = DockerCommandBuilder.build_down_command("all", "/path/to/.env") + assert cmd == ["docker", "compose", "down", "--env-file", "/path/to/.env"] + + def test_build_down_command_with_compose_file(self): + cmd = DockerCommandBuilder.build_down_command("all", None, "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down"] + + def test_build_down_command_with_all_parameters(self): + cmd = DockerCommandBuilder.build_down_command("api", "/path/to/.env", "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down", "--env-file", "/path/to/.env", "api"] + + +class TestDownFormatter: + def setup_method(self): + self.formatter = DownFormatter() + + def test_format_output_success(self): + result = DownResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + formatted = self.formatter.format_output(result, "text") + expected_message = services_stopped_successfully.format(services="web") + assert expected_message in formatted + + def test_format_output_failure(self): + result = DownResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=False, + error="Service not found" + ) + formatted = self.formatter.format_output(result, "text") + assert "Service not found" in formatted + + def test_format_output_json(self): + result = DownResult( + name="web", + env_file=None, + verbose=False, + output="json", + success=True + ) + formatted = self.formatter.format_output(result, "json") + import json + data = json.loads(formatted) + assert data["success"] is True + expected_message = services_stopped_successfully.format(services="web") + assert expected_message in data["message"] + + def test_format_output_invalid(self): + result = DownResult( + name="web", + env_file=None, + verbose=False, + output="invalid", + success=True + ) + with pytest.raises(ValueError): + self.formatter.format_output(result, "invalid") + + def test_format_dry_run_default(self): + config = DownConfig( + name="all", + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_mode in formatted + assert dry_run_command in formatted + assert dry_run_service.format(service="all") in formatted + + def test_format_dry_run_with_service(self): + config = DownConfig( + name="web", + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_service.format(service="web") in formatted + + def test_format_dry_run_with_env_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = DownConfig( + name="all", + env_file="/path/to/.env", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_env_file.format(env_file="/path/to/.env") in formatted + + def test_format_dry_run_with_compose_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = DownConfig( + name="all", + compose_file="/path/to/docker-compose.yml", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert "Command:" in formatted + + +class TestDockerService: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.docker_service = DockerService(self.logger) + + @patch('subprocess.run') + def test_stop_services_success(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.stop_services("web") + + assert success is True + assert error is None + self.logger.info.assert_called_once_with("Downing services: web") + self.logger.success.assert_called_once_with("Services downed successfully: web") + + @patch('subprocess.run') + def test_stop_services_with_env_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.stop_services("all", "/path/to/.env") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "down", "--env-file", "/path/to/.env"] + + @patch('subprocess.run') + def test_stop_services_with_compose_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.stop_services("all", None, "/path/to/docker-compose.yml") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down"] + + @patch('subprocess.run') + def test_stop_services_failure(self, mock_run): + mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose down", stderr="Service not found") + + success, error = self.docker_service.stop_services("web") + + assert success is False + assert error == "Service not found" + expected_error = "Service down failed: Service not found" + self.logger.error.assert_called_once_with(expected_error) + + @patch('subprocess.run') + def test_stop_services_unexpected_error(self, mock_run): + mock_run.side_effect = Exception("Unexpected error") + + success, error = self.docker_service.stop_services("web") + + assert success is False + assert error == "Unexpected error" + expected_error = "Unexpected error during down: Unexpected error" + self.logger.error.assert_called_once_with(expected_error) + + +class TestDownConfig: + def test_valid_config_default(self): + config = DownConfig() + assert config.name == "all" + assert config.env_file is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.compose_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = DownConfig( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + dry_run=True, + compose_file="/path/to/docker-compose.yml" + ) + assert config.name == "web" + assert config.env_file == "/path/to/.env" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_env_file_exists(self, mock_exists): + mock_exists.return_value = True + config = DownConfig(env_file="/path/to/.env") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + DownConfig(env_file="/path/to/.env") + + def test_validate_env_file_none(self): + config = DownConfig(env_file=None) + assert config.env_file is None + + def test_validate_env_file_empty(self): + config = DownConfig(env_file="") + assert config.env_file is None + + def test_validate_env_file_whitespace(self): + config = DownConfig(env_file=" ") + assert config.env_file is None + + def test_validate_env_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = DownConfig(env_file=" /path/to/.env ") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_compose_file_exists(self, mock_exists): + mock_exists.return_value = True + config = DownConfig(compose_file="/path/to/docker-compose.yml") + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_compose_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + DownConfig(compose_file="/path/to/docker-compose.yml") + + def test_validate_compose_file_none(self): + config = DownConfig(compose_file=None) + assert config.compose_file is None + + def test_validate_compose_file_empty(self): + config = DownConfig(compose_file="") + assert config.compose_file is None + + def test_validate_compose_file_whitespace(self): + config = DownConfig(compose_file=" ") + assert config.compose_file is None + + def test_validate_compose_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = DownConfig(compose_file=" /path/to/docker-compose.yml ") + assert config.compose_file == "/path/to/docker-compose.yml" + + +class TestDownService: + def setup_method(self): + self.config = DownConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + self.logger = Mock(spec=Logger) + self.docker_service = Mock() + self.service = DownService(self.config, self.logger, self.docker_service) + + def test_create_result_success(self): + result = self.service._create_result(True) + assert result.name == "web" + assert result.success is True + assert result.error is None + assert result.output == "text" + assert result.verbose is False + + def test_create_result_failure(self): + result = self.service._create_result(False, "Service not found") + assert result.success is False + assert result.error == "Service not found" + + def test_down_success(self): + self.docker_service.stop_services.return_value = (True, None) + + result = self.service.down() + + assert result.success is True + assert result.error is None + self.docker_service.stop_services.assert_called_once_with("web", None, None) + + def test_down_failure(self): + self.docker_service.stop_services.return_value = (False, "Service not found") + + result = self.service.down() + + assert result.success is False + assert result.error == "Service not found" + + def test_down_and_format_dry_run(self): + self.config.dry_run = True + formatted = self.service.down_and_format() + assert dry_run_mode in formatted + assert dry_run_command in formatted + + def test_down_and_format_success(self): + self.docker_service.stop_services.return_value = (True, None) + formatted = self.service.down_and_format() + expected_message = services_stopped_successfully.format(services="web") + assert expected_message in formatted + + +class TestDown: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.down = Down(self.logger) + + def test_down_success(self): + config = DownConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + + with patch('app.commands.service.down.DockerService') as mock_docker_service_class: + mock_docker_service = Mock() + mock_docker_service.stop_services.return_value = (True, None) + mock_docker_service_class.return_value = mock_docker_service + + result = self.down.down(config) + + assert result.success is True + assert result.error is None + assert result.name == "web" + + def test_down_failure(self): + config = DownConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + + with patch('app.commands.service.down.DockerService') as mock_docker_service_class: + mock_docker_service = Mock() + mock_docker_service.stop_services.return_value = (False, "Service not found") + mock_docker_service_class.return_value = mock_docker_service + + result = self.down.down(config) + + assert result.success is False + assert result.error == "Service not found" + + def test_format_output(self): + result = DownResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + + formatted = self.down.format_output(result, "text") + expected_message = services_stopped_successfully.format(services="web") + assert expected_message in formatted + + +class TestDownResult: + def test_down_result_creation(self): + result = DownResult( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + success=True, + error=None + ) + + assert result.name == "web" + assert result.env_file == "/path/to/.env" + assert result.verbose is True + assert result.output == "json" + assert result.success is True + assert result.error is None + + def test_down_result_default_success(self): + result = DownResult( + name="web", + env_file=None, + verbose=False, + output="text" + ) + + assert result.name == "web" + assert result.success is False + assert result.error is None diff --git a/cli/app/commands/service/tests/test_ps.py b/cli/app/commands/service/tests/test_ps.py new file mode 100644 index 00000000..5262748a --- /dev/null +++ b/cli/app/commands/service/tests/test_ps.py @@ -0,0 +1,447 @@ +import pytest +import subprocess +import os +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.service.ps import ( + DockerCommandBuilder, + PsFormatter, + DockerService, + PsResult, + PsConfig, + PsService, + Ps +) +from app.commands.service.messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_service, + dry_run_env_file, + end_dry_run, + services_status_retrieved, + service_status_failed, + unknown_error +) +from app.utils.logger import Logger + + +class TestDockerCommandBuilder: + def test_build_ps_command_default(self): + cmd = DockerCommandBuilder.build_ps_command() + assert cmd == ["docker", "compose", "ps"] + + def test_build_ps_command_with_service_name(self): + cmd = DockerCommandBuilder.build_ps_command("web") + assert cmd == ["docker", "compose", "ps", "web"] + + def test_build_ps_command_with_env_file(self): + cmd = DockerCommandBuilder.build_ps_command("all", "/path/to/.env") + assert cmd == ["docker", "compose", "ps", "--env-file", "/path/to/.env"] + + def test_build_ps_command_with_compose_file(self): + cmd = DockerCommandBuilder.build_ps_command("all", None, "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps"] + + def test_build_ps_command_with_all_parameters(self): + cmd = DockerCommandBuilder.build_ps_command("api", "/path/to/.env", "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps", "--env-file", "/path/to/.env", "api"] + + +class TestPsFormatter: + def setup_method(self): + self.formatter = PsFormatter() + + def test_format_output_success(self): + result = PsResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + formatted = self.formatter.format_output(result, "text") + expected_message = services_status_retrieved.format(services="web") + assert expected_message in formatted + + def test_format_output_failure(self): + result = PsResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=False, + error="Service not found" + ) + formatted = self.formatter.format_output(result, "text") + assert "Service not found" in formatted + + def test_format_output_json(self): + result = PsResult( + name="web", + env_file=None, + verbose=False, + output="json", + success=True + ) + formatted = self.formatter.format_output(result, "json") + import json + data = json.loads(formatted) + assert data["success"] is True + expected_message = services_status_retrieved.format(services="web") + assert expected_message in data["message"] + + def test_format_output_invalid(self): + result = PsResult( + name="web", + env_file=None, + verbose=False, + output="invalid", + success=True + ) + with pytest.raises(ValueError): + self.formatter.format_output(result, "invalid") + + def test_format_dry_run_default(self): + config = PsConfig( + name="all", + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_mode in formatted + assert dry_run_command in formatted + assert dry_run_service.format(service="all") in formatted + + def test_format_dry_run_with_service(self): + config = PsConfig( + name="web", + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_service.format(service="web") in formatted + + def test_format_dry_run_with_env_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = PsConfig( + name="all", + env_file="/path/to/.env", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_env_file.format(env_file="/path/to/.env") in formatted + + def test_format_dry_run_with_compose_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = PsConfig( + name="all", + compose_file="/path/to/docker-compose.yml", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert "Command:" in formatted + + +class TestDockerService: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.docker_service = DockerService(self.logger) + + @patch('subprocess.run') + def test_show_services_status_success(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.show_services_status("web") + + assert success is True + assert error is None + self.logger.info.assert_called_once_with("Psing services: web") + self.logger.success.assert_called_once_with("Services psed successfully: web") + + @patch('subprocess.run') + def test_show_services_status_with_env_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.show_services_status("all", "/path/to/.env") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "ps", "--env-file", "/path/to/.env"] + + @patch('subprocess.run') + def test_show_services_status_with_compose_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.show_services_status("all", None, "/path/to/docker-compose.yml") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps"] + + @patch('subprocess.run') + def test_show_services_status_failure(self, mock_run): + mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose ps", stderr="Service not found") + + success, error = self.docker_service.show_services_status("web") + + assert success is False + assert error == "Service not found" + expected_error = "Service ps failed: Service not found" + self.logger.error.assert_called_once_with(expected_error) + + @patch('subprocess.run') + def test_show_services_status_unexpected_error(self, mock_run): + mock_run.side_effect = Exception("Unexpected error") + + success, error = self.docker_service.show_services_status("web") + + assert success is False + assert error == "Unexpected error" + expected_error = "Unexpected error during ps: Unexpected error" + self.logger.error.assert_called_once_with(expected_error) + + +class TestPsConfig: + def test_valid_config_default(self): + config = PsConfig() + assert config.name == "all" + assert config.env_file is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.compose_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = PsConfig( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + dry_run=True, + compose_file="/path/to/docker-compose.yml" + ) + assert config.name == "web" + assert config.env_file == "/path/to/.env" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_env_file_exists(self, mock_exists): + mock_exists.return_value = True + config = PsConfig(env_file="/path/to/.env") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + PsConfig(env_file="/path/to/.env") + + def test_validate_env_file_none(self): + config = PsConfig(env_file=None) + assert config.env_file is None + + def test_validate_env_file_empty(self): + config = PsConfig(env_file="") + assert config.env_file is None + + def test_validate_env_file_whitespace(self): + config = PsConfig(env_file=" ") + assert config.env_file is None + + def test_validate_env_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = PsConfig(env_file=" /path/to/.env ") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_compose_file_exists(self, mock_exists): + mock_exists.return_value = True + config = PsConfig(compose_file="/path/to/docker-compose.yml") + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_compose_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + PsConfig(compose_file="/path/to/docker-compose.yml") + + def test_validate_compose_file_none(self): + config = PsConfig(compose_file=None) + assert config.compose_file is None + + def test_validate_compose_file_empty(self): + config = PsConfig(compose_file="") + assert config.compose_file is None + + def test_validate_compose_file_whitespace(self): + config = PsConfig(compose_file=" ") + assert config.compose_file is None + + def test_validate_compose_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = PsConfig(compose_file=" /path/to/docker-compose.yml ") + assert config.compose_file == "/path/to/docker-compose.yml" + + +class TestPsService: + def setup_method(self): + self.config = PsConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + self.logger = Mock(spec=Logger) + self.docker_service = Mock() + self.service = PsService(self.config, self.logger, self.docker_service) + + def test_create_result_success(self): + result = self.service._create_result(True) + assert result.name == "web" + assert result.success is True + assert result.error is None + assert result.output == "text" + assert result.verbose is False + + def test_create_result_failure(self): + result = self.service._create_result(False, "Service not found") + assert result.success is False + assert result.error == "Service not found" + + def test_ps_success(self): + self.docker_service.show_services_status.return_value = (True, None) + + result = self.service.ps() + + assert result.success is True + assert result.error is None + self.docker_service.show_services_status.assert_called_once_with("web", None, None) + + def test_ps_failure(self): + self.docker_service.show_services_status.return_value = (False, "Service not found") + + result = self.service.ps() + + assert result.success is False + assert result.error == "Service not found" + + def test_ps_and_format_dry_run(self): + self.config.dry_run = True + formatted = self.service.ps_and_format() + assert dry_run_mode in formatted + assert dry_run_command in formatted + + def test_ps_and_format_success(self): + self.docker_service.show_services_status.return_value = (True, None) + formatted = self.service.ps_and_format() + expected_message = services_status_retrieved.format(services="web") + assert expected_message in formatted + + +class TestPs: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.ps = Ps(self.logger) + + def test_ps_success(self): + config = PsConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + + with patch("app.commands.service.ps.PsService.execute", return_value=PsResult( + name=config.name, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=True + )): + result = self.ps.ps(config) + assert result.success is True + + def test_ps_failure(self): + config = PsConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + + with patch("app.commands.service.ps.PsService.execute", return_value=PsResult( + name=config.name, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=False, + error="Service not found" + )): + result = self.ps.ps(config) + assert result.success is False + assert result.error == "Service not found" + + def test_format_output(self): + result = PsResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + + formatted = self.ps.format_output(result, "text") + expected_message = services_status_retrieved.format(services="web") + assert expected_message in formatted + + +class TestPsResult: + def test_ps_result_creation(self): + result = PsResult( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + success=True, + error=None + ) + + assert result.name == "web" + assert result.env_file == "/path/to/.env" + assert result.verbose is True + assert result.output == "json" + assert result.success is True + assert result.error is None + + def test_ps_result_default_success(self): + result = PsResult( + name="web", + env_file=None, + verbose=False, + output="text" + ) + + assert result.name == "web" + assert result.success is False + assert result.error is None diff --git a/cli/app/commands/service/tests/test_restart.py b/cli/app/commands/service/tests/test_restart.py new file mode 100644 index 00000000..700a373b --- /dev/null +++ b/cli/app/commands/service/tests/test_restart.py @@ -0,0 +1,447 @@ +import pytest +import subprocess +import os +from unittest.mock import Mock, patch +from pydantic import ValidationError + +from app.commands.service.restart import ( + DockerCommandBuilder, + RestartFormatter, + DockerService, + RestartResult, + RestartConfig, + RestartService, + Restart +) +from app.commands.service.messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_service, + dry_run_env_file, + end_dry_run, + services_restarted_successfully, + service_restart_failed, + unknown_error +) +from app.utils.logger import Logger + + +class TestDockerCommandBuilder: + def test_build_restart_command_default(self): + cmd = DockerCommandBuilder.build_restart_command() + assert cmd == ["docker", "compose", "restart"] + + def test_build_restart_command_with_service_name(self): + cmd = DockerCommandBuilder.build_restart_command("web") + assert cmd == ["docker", "compose", "restart", "web"] + + def test_build_restart_command_with_env_file(self): + cmd = DockerCommandBuilder.build_restart_command("all", "/path/to/.env") + assert cmd == ["docker", "compose", "restart", "--env-file", "/path/to/.env"] + + def test_build_restart_command_with_compose_file(self): + cmd = DockerCommandBuilder.build_restart_command("all", None, "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart"] + + def test_build_restart_command_with_all_parameters(self): + cmd = DockerCommandBuilder.build_restart_command("api", "/path/to/.env", "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart", "--env-file", "/path/to/.env", "api"] + + +class TestRestartFormatter: + def setup_method(self): + self.formatter = RestartFormatter() + + def test_format_output_success(self): + result = RestartResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + formatted = self.formatter.format_output(result, "text") + expected_message = services_restarted_successfully.format(services="web") + assert expected_message in formatted + + def test_format_output_failure(self): + result = RestartResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=False, + error="Service not found" + ) + formatted = self.formatter.format_output(result, "text") + assert "Service not found" in formatted + + def test_format_output_json(self): + result = RestartResult( + name="web", + env_file=None, + verbose=False, + output="json", + success=True + ) + formatted = self.formatter.format_output(result, "json") + import json + data = json.loads(formatted) + assert data["success"] is True + expected_message = services_restarted_successfully.format(services="web") + assert expected_message in data["message"] + + def test_format_output_invalid(self): + result = RestartResult( + name="web", + env_file=None, + verbose=False, + output="invalid", + success=True + ) + with pytest.raises(ValueError): + self.formatter.format_output(result, "invalid") + + def test_format_dry_run_default(self): + config = RestartConfig( + name="all", + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_mode in formatted + assert dry_run_command in formatted + assert dry_run_service.format(service="all") in formatted + + def test_format_dry_run_with_service(self): + config = RestartConfig( + name="web", + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_service.format(service="web") in formatted + + def test_format_dry_run_with_env_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = RestartConfig( + name="all", + env_file="/path/to/.env", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_env_file.format(env_file="/path/to/.env") in formatted + + def test_format_dry_run_with_compose_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = RestartConfig( + name="all", + compose_file="/path/to/docker-compose.yml", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert "Command:" in formatted + + +class TestDockerService: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.docker_service = DockerService(self.logger) + + @patch('subprocess.run') + def test_restart_services_success(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.restart_services("web") + + assert success is True + assert error is None + self.logger.info.assert_called_once_with("Restarting services: web") + self.logger.success.assert_called_once_with("Services restarted successfully: web") + + @patch('subprocess.run') + def test_restart_services_with_env_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.restart_services("all", "/path/to/.env") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "restart", "--env-file", "/path/to/.env"] + + @patch('subprocess.run') + def test_restart_services_with_compose_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.restart_services("all", None, "/path/to/docker-compose.yml") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart"] + + @patch('subprocess.run') + def test_restart_services_failure(self, mock_run): + mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose restart", stderr="Service not found") + + success, error = self.docker_service.restart_services("web") + + assert success is False + assert error == "Service not found" + expected_error = "Service restart failed: Service not found" + self.logger.error.assert_called_once_with(expected_error) + + @patch('subprocess.run') + def test_restart_services_unexpected_error(self, mock_run): + mock_run.side_effect = Exception("Unexpected error") + + success, error = self.docker_service.restart_services("web") + + assert success is False + assert error == "Unexpected error" + expected_error = "Unexpected error during restart: Unexpected error" + self.logger.error.assert_called_once_with(expected_error) + + +class TestRestartConfig: + def test_valid_config_default(self): + config = RestartConfig() + assert config.name == "all" + assert config.env_file is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + assert config.compose_file is None + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = RestartConfig( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + dry_run=True, + compose_file="/path/to/docker-compose.yml" + ) + assert config.name == "web" + assert config.env_file == "/path/to/.env" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_env_file_exists(self, mock_exists): + mock_exists.return_value = True + config = RestartConfig(env_file="/path/to/.env") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + RestartConfig(env_file="/path/to/.env") + + def test_validate_env_file_none(self): + config = RestartConfig(env_file=None) + assert config.env_file is None + + def test_validate_env_file_empty(self): + config = RestartConfig(env_file="") + assert config.env_file is None + + def test_validate_env_file_whitespace(self): + config = RestartConfig(env_file=" ") + assert config.env_file is None + + def test_validate_env_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = RestartConfig(env_file=" /path/to/.env ") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_compose_file_exists(self, mock_exists): + mock_exists.return_value = True + config = RestartConfig(compose_file="/path/to/docker-compose.yml") + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_compose_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + RestartConfig(compose_file="/path/to/docker-compose.yml") + + def test_validate_compose_file_none(self): + config = RestartConfig(compose_file=None) + assert config.compose_file is None + + def test_validate_compose_file_empty(self): + config = RestartConfig(compose_file="") + assert config.compose_file is None + + def test_validate_compose_file_whitespace(self): + config = RestartConfig(compose_file=" ") + assert config.compose_file is None + + def test_validate_compose_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = RestartConfig(compose_file=" /path/to/docker-compose.yml ") + assert config.compose_file == "/path/to/docker-compose.yml" + + +class TestRestartService: + def setup_method(self): + self.config = RestartConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + self.logger = Mock(spec=Logger) + self.docker_service = Mock() + self.service = RestartService(self.config, self.logger, self.docker_service) + + def test_create_result_success(self): + result = self.service._create_result(True) + assert result.name == "web" + assert result.success is True + assert result.error is None + assert result.output == "text" + assert result.verbose is False + + def test_create_result_failure(self): + result = self.service._create_result(False, "Service not found") + assert result.success is False + assert result.error == "Service not found" + + def test_restart_success(self): + self.docker_service.restart_services.return_value = (True, None) + + result = self.service.restart() + + assert result.success is True + assert result.error is None + self.docker_service.restart_services.assert_called_once_with("web", None, None) + + def test_restart_failure(self): + self.docker_service.restart_services.return_value = (False, "Service not found") + + result = self.service.restart() + + assert result.success is False + assert result.error == "Service not found" + + def test_restart_and_format_dry_run(self): + self.config.dry_run = True + formatted = self.service.restart_and_format() + assert dry_run_mode in formatted + assert dry_run_command in formatted + + def test_restart_and_format_success(self): + self.docker_service.restart_services.return_value = (True, None) + formatted = self.service.restart_and_format() + expected_message = services_restarted_successfully.format(services="web") + assert expected_message in formatted + + +class TestRestart: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.restart = Restart(self.logger) + + def test_restart_success(self): + config = RestartConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + + with patch("app.commands.service.restart.RestartService.execute", return_value=RestartResult( + name=config.name, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=True + )): + result = self.restart.restart(config) + assert result.success is True + + def test_restart_failure(self): + config = RestartConfig( + name="web", + env_file=None, + verbose=False, + output="text", + dry_run=False + ) + + with patch("app.commands.service.restart.RestartService.execute", return_value=RestartResult( + name=config.name, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=False, + error="Service not found" + )): + result = self.restart.restart(config) + assert result.success is False + assert result.error == "Service not found" + + def test_format_output(self): + result = RestartResult( + name="web", + env_file=None, + verbose=False, + output="text", + success=True + ) + + formatted = self.restart.format_output(result, "text") + expected_message = services_restarted_successfully.format(services="web") + assert expected_message in formatted + + +class TestRestartResult: + def test_restart_result_creation(self): + result = RestartResult( + name="web", + env_file="/path/to/.env", + verbose=True, + output="json", + success=True, + error=None + ) + + assert result.name == "web" + assert result.env_file == "/path/to/.env" + assert result.verbose is True + assert result.output == "json" + assert result.success is True + assert result.error is None + + def test_restart_result_default_success(self): + result = RestartResult( + name="web", + env_file=None, + verbose=False, + output="text" + ) + + assert result.name == "web" + assert result.success is False + assert result.error is None diff --git a/cli/app/commands/service/tests/test_up.py b/cli/app/commands/service/tests/test_up.py new file mode 100644 index 00000000..dd27c213 --- /dev/null +++ b/cli/app/commands/service/tests/test_up.py @@ -0,0 +1,447 @@ +import pytest +import subprocess +import os +from unittest.mock import Mock, patch, MagicMock +from pydantic import ValidationError + +from app.commands.service.up import ( + DockerCommandBuilder, + UpFormatter, + DockerService, + UpResult, + UpConfig, + UpService, + Up +) +from app.commands.service.messages import ( + dry_run_mode, + dry_run_command, + dry_run_service, + dry_run_detach_mode, + dry_run_env_file, + services_started_successfully, +) +from app.utils.logger import Logger + + +class TestDockerCommandBuilder: + def test_build_up_command_default(self): + cmd = DockerCommandBuilder.build_up_command() + assert cmd == ["docker", "compose", "up", "-d"] + + def test_build_up_command_with_service_name(self): + cmd = DockerCommandBuilder.build_up_command("web") + assert cmd == ["docker", "compose", "up", "-d", "web"] + + def test_build_up_command_without_detach(self): + cmd = DockerCommandBuilder.build_up_command("all", detach=False) + assert cmd == ["docker", "compose", "up"] + + def test_build_up_command_with_env_file(self): + cmd = DockerCommandBuilder.build_up_command("all", True, "/path/to/.env") + assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] + + def test_build_up_command_with_compose_file(self): + cmd = DockerCommandBuilder.build_up_command("all", True, None, "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] + + def test_build_up_command_with_all_parameters(self): + cmd = DockerCommandBuilder.build_up_command("api", False, "/path/to/.env", "/path/to/docker-compose.yml") + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "--env-file", "/path/to/.env", "api"] + + +class TestUpFormatter: + def setup_method(self): + self.formatter = UpFormatter() + + def test_format_output_success(self): + result = UpResult( + name="web", + detach=True, + env_file=None, + verbose=False, + output="text", + success=True + ) + formatted = self.formatter.format_output(result, "text") + expected_message = services_started_successfully.format(services="web") + assert expected_message in formatted + + def test_format_output_failure(self): + result = UpResult( + name="web", + detach=True, + env_file=None, + verbose=False, + output="text", + success=False, + error="Service not found" + ) + formatted = self.formatter.format_output(result, "text") + assert "Service not found" in formatted + + def test_format_output_json(self): + result = UpResult( + name="web", + detach=True, + env_file=None, + verbose=False, + output="json", + success=True + ) + formatted = self.formatter.format_output(result, "json") + import json + data = json.loads(formatted) + assert data["success"] is True + expected_message = services_started_successfully.format(services="web") + assert expected_message in data["message"] + + def test_format_output_invalid(self): + result = UpResult( + name="web", + detach=True, + env_file=None, + verbose=False, + output="invalid", + success=True + ) + with pytest.raises(ValueError): + self.formatter.format_output(result, "invalid") + + def test_format_dry_run_default(self): + config = UpConfig( + name="all", + detach=True, + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_mode in formatted + assert dry_run_command in formatted + assert dry_run_service.format(service="all") in formatted + assert dry_run_detach_mode.format(detach=True) in formatted + + def test_format_dry_run_with_service(self): + config = UpConfig( + name="web", + detach=False, + env_file=None, + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_service.format(service="web") in formatted + assert dry_run_detach_mode.format(detach=False) in formatted + + def test_format_dry_run_with_env_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = UpConfig( + name="all", + detach=True, + env_file="/path/to/.env", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert dry_run_env_file.format(env_file="/path/to/.env") in formatted + + def test_format_dry_run_with_compose_file(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = UpConfig( + name="all", + detach=True, + compose_file="/path/to/docker-compose.yml", + dry_run=True + ) + formatted = self.formatter.format_dry_run(config) + assert dry_run_command in formatted + assert "Command:" in formatted + + +class TestDockerService: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.docker_service = DockerService(self.logger) + + @patch('subprocess.run') + def test_start_services_success(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.start_services("web") + + assert success is True + assert error is None + self.logger.info.assert_called_once_with("Uping services: web") + self.logger.success.assert_called_once_with("Services upped successfully: web") + + @patch('subprocess.run') + def test_start_services_with_env_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.start_services("all", True, "/path/to/.env") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] + + @patch('subprocess.run') + def test_start_services_with_compose_file(self, mock_run): + mock_run.return_value = Mock(returncode=0) + + success, error = self.docker_service.start_services("all", True, None, "/path/to/docker-compose.yml") + + assert success is True + assert error is None + mock_run.assert_called_once() + cmd = mock_run.call_args[0][0] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] + + @patch('subprocess.run') + def test_start_services_failure(self, mock_run): + mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose", stderr="Service not found") + success, error = self.docker_service.start_services("web") + assert success is False + assert error == "Service not found" + expected_error = "Service up failed: Service not found" + self.logger.error.assert_called_once_with(expected_error) + + @patch('subprocess.run') + def test_start_services_unexpected_error(self, mock_run): + mock_run.side_effect = Exception("Unexpected error") + success, error = self.docker_service.start_services("web") + assert success is False + assert error == "Unexpected error" + expected_error = "Unexpected error during up: Unexpected error" + self.logger.error.assert_called_once_with(expected_error) + + +class TestUpConfig: + def test_valid_config_default(self): + config = UpConfig() + assert config.name == "all" + assert config.detach is True + assert config.env_file is None + assert config.verbose is False + assert config.output == "text" + assert config.dry_run is False + + def test_valid_config_custom(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = UpConfig( + name="web", + detach=False, + env_file="/path/to/.env", + verbose=True, + output="json", + dry_run=True, + compose_file="/path/to/docker-compose.yml" + ) + assert config.name == "web" + assert config.detach is False + assert config.env_file == "/path/to/.env" + assert config.verbose is True + assert config.output == "json" + assert config.dry_run is True + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_env_file_exists(self, mock_exists): + mock_exists.return_value = True + config = UpConfig(env_file="/path/to/.env") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_env_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + UpConfig(env_file="/path/to/.env") + + def test_validate_env_file_none(self): + config = UpConfig(env_file=None) + assert config.env_file is None + + def test_validate_env_file_empty(self): + config = UpConfig(env_file="") + assert config.env_file is None + + def test_validate_env_file_whitespace(self): + config = UpConfig(env_file=" ") + assert config.env_file is None + + def test_validate_env_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = UpConfig(env_file=" /path/to/.env ") + assert config.env_file == "/path/to/.env" + + @patch('os.path.exists') + def test_validate_compose_file_exists(self, mock_exists): + mock_exists.return_value = True + config = UpConfig(compose_file="/path/to/docker-compose.yml") + assert config.compose_file == "/path/to/docker-compose.yml" + + @patch('os.path.exists') + def test_validate_compose_file_not_exists(self, mock_exists): + mock_exists.return_value = False + with pytest.raises(ValidationError): + UpConfig(compose_file="/path/to/docker-compose.yml") + + def test_validate_compose_file_none(self): + config = UpConfig(compose_file=None) + assert config.compose_file is None + + def test_validate_compose_file_empty(self): + config = UpConfig(compose_file="") + assert config.compose_file is None + + def test_validate_compose_file_whitespace(self): + config = UpConfig(compose_file=" ") + assert config.compose_file is None + + def test_validate_compose_file_stripped(self): + with patch('os.path.exists') as mock_exists: + mock_exists.return_value = True + config = UpConfig(compose_file=" /path/to/docker-compose.yml ") + assert config.compose_file == "/path/to/docker-compose.yml" + + +class TestUpService: + def setup_method(self): + self.config = UpConfig( + name="web", + detach=True, + env_file=None, + compose_file=None + ) + self.logger = Mock(spec=Logger) + self.docker_service = Mock() + self.service = UpService(self.config, self.logger, self.docker_service) + + def test_create_result_success(self): + result = self.service._create_result(True) + + assert result.name == self.config.name + assert result.detach == self.config.detach + assert result.env_file == self.config.env_file + assert result.verbose == self.config.verbose + assert result.output == self.config.output + assert result.success is True + assert result.error is None + + def test_create_result_failure(self): + result = self.service._create_result(False, "Test error") + + assert result.success is False + assert result.error == "Test error" + + def test_up_success(self): + self.docker_service.start_services.return_value = (True, None) + + result = self.service.up() + + assert result.success is True + self.docker_service.start_services.assert_called_once_with( + self.config.name, + self.config.detach, + self.config.env_file, + self.config.compose_file + ) + + def test_up_failure(self): + self.docker_service.start_services.return_value = (False, "Test error") + + result = self.service.up() + + assert result.success is False + assert result.error == "Test error" + + def test_up_and_format_dry_run(self): + self.config.dry_run = True + + result = self.service.up_and_format() + + assert dry_run_mode in result + + def test_up_and_format_success(self): + self.docker_service.start_services.return_value = (True, None) + + result = self.service.up_and_format() + + expected_message = services_started_successfully.format(services="web") + assert expected_message in result + + +class TestUp: + def setup_method(self): + self.logger = Mock(spec=Logger) + self.up = Up(self.logger) + + def test_up_success(self): + config = UpConfig( + name="web", + detach=True, + env_file=None + ) + with patch("app.commands.service.up.UpService.execute", return_value=UpResult( + name=config.name, + detach=config.detach, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=True + )): + result = self.up.up(config) + assert result.success is True + + def test_format_output(self): + result = UpResult( + name="web", + detach=True, + env_file=None, + verbose=False, + output="text", + success=True + ) + + formatted = self.up.format_output(result, "text") + + expected_message = services_started_successfully.format(services="web") + assert expected_message in formatted + + +class TestUpResult: + def test_up_result_creation(self): + result = UpResult( + name="web", + detach=True, + env_file="/path/to/.env", + verbose=True, + output="json", + success=True, + error=None + ) + + assert result.name == "web" + assert result.detach is True + assert result.env_file == "/path/to/.env" + assert result.verbose is True + assert result.output == "json" + assert result.success is True + assert result.error is None + + def test_up_result_default_success(self): + result = UpResult( + name="web", + detach=True, + env_file=None, + verbose=False, + output="text" + ) + + assert result.success is False + assert result.error is None diff --git a/cli/app/commands/service/up.py b/cli/app/commands/service/up.py new file mode 100644 index 00000000..afbe642b --- /dev/null +++ b/cli/app/commands/service/up.py @@ -0,0 +1,123 @@ +import subprocess +import os +from typing import Protocol, Optional +from pydantic import BaseModel, Field, field_validator + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from .base import ( + BaseDockerCommandBuilder, + BaseFormatter, + BaseDockerService, + BaseConfig, + BaseResult, + BaseService, + BaseAction +) +from .messages import ( + dry_run_mode, + dry_run_command_would_be_executed, + dry_run_command, + dry_run_service, + dry_run_detach_mode, + dry_run_env_file, + end_dry_run, + services_started_successfully, + service_start_failed, +) + +class DockerServiceProtocol(Protocol): + def start_services(self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + ... + +class DockerCommandBuilder(BaseDockerCommandBuilder): + @staticmethod + def build_up_command(name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None) -> list[str]: + return BaseDockerCommandBuilder.build_command("up", name, env_file, compose_file, detach=detach) + +class UpFormatter(BaseFormatter): + def format_output(self, result: "UpResult", output: str) -> str: + return super().format_output(result, output, services_started_successfully, service_start_failed) + + def format_dry_run(self, config: "UpConfig") -> str: + dry_run_messages = { + "mode": dry_run_mode, + "command_would_be_executed": dry_run_command_would_be_executed, + "command": dry_run_command, + "service": dry_run_service, + "detach_mode": dry_run_detach_mode, + "env_file": dry_run_env_file, + "end": end_dry_run + } + return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + +class DockerService(BaseDockerService): + def __init__(self, logger: LoggerProtocol): + super().__init__(logger, "up") + + def start_services(self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + return self.execute_services(name, env_file, compose_file, detach=detach) + +class UpResult(BaseResult): + detach: bool + +class UpConfig(BaseConfig): + detach: bool = Field(True, description="Run services in detached mode") + +class UpService(BaseService[UpConfig, UpResult]): + def __init__(self, config: UpConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): + super().__init__(config, logger, docker_service) + self.docker_service = docker_service or DockerService(self.logger) + self.formatter = UpFormatter() + + def _create_result(self, success: bool, error: str = None) -> UpResult: + return UpResult( + name=self.config.name, + detach=self.config.detach, + env_file=self.config.env_file, + verbose=self.config.verbose, + output=self.config.output, + success=success, + error=error + ) + + def up(self) -> UpResult: + return self.execute() + + def execute(self) -> UpResult: + self.logger.debug(f"Starting services: {self.config.name}") + + success, error = self.docker_service.start_services( + self.config.name, + self.config.detach, + self.config.env_file, + self.config.compose_file + ) + + return self._create_result(success, error) + + def up_and_format(self) -> str: + return self.execute_and_format() + + def execute_and_format(self) -> str: + if self.config.dry_run: + return self.formatter.format_dry_run(self.config) + + result = self.execute() + return self.formatter.format_output(result, self.config.output) + +class Up(BaseAction[UpConfig, UpResult]): + def __init__(self, logger: LoggerProtocol = None): + super().__init__(logger) + self.formatter = UpFormatter() + + def up(self, config: UpConfig) -> UpResult: + return self.execute(config) + + def execute(self, config: UpConfig) -> UpResult: + service = UpService(config, logger=self.logger) + return service.execute() + + def format_output(self, result: UpResult, output: str) -> str: + return self.formatter.format_output(result, output) diff --git a/cli/app/main.py b/cli/app/main.py index cc18cecb..b5378300 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -3,6 +3,9 @@ from app.commands.preflight.command import preflight_app from app.commands.test.command import test_app from app.commands.install.command import install_app +from app.commands.service.command import service_app +from app.commands.conf.command import conf_app +from app.commands.proxy.command import proxy_app from app.utils.message import application_name, application_description, application_add_completion, application_version_help app = typer.Typer( @@ -23,10 +26,13 @@ def main( ): pass -app.add_typer(test_app, name="test") app.add_typer(preflight_app, name="preflight") -app.add_typer(version_app, name="version") +app.add_typer(conf_app, name="conf") +app.add_typer(service_app, name="service") +app.add_typer(proxy_app, name="proxy") app.add_typer(install_app, name="install") +app.add_typer(version_app, name="version") +app.add_typer(test_app, name="test") if __name__ == "__main__": app() diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py index 32e4970f..a67cfdc8 100644 --- a/cli/app/utils/lib.py +++ b/cli/app/utils/lib.py @@ -3,7 +3,8 @@ import subprocess import os import shutil -from typing import TypeVar, Callable, List +import stat +from typing import TypeVar, Callable, List, Optional, Tuple from concurrent.futures import ThreadPoolExecutor, as_completed from app.utils.message import REMOVED_DIRECTORY_MESSAGE, FAILED_TO_REMOVE_DIRECTORY_MESSAGE @@ -127,3 +128,76 @@ def remove_directory(path: str, logger=None) -> bool: if logger: logger.error(FAILED_TO_REMOVE_DIRECTORY_MESSAGE.format(path=path, error=e)) return False + +class FileManager: + @staticmethod + def set_permissions(file_path: str, mode: int, logger=None) -> Tuple[bool, Optional[str]]: + try: + if logger: + logger.debug(f"Setting permissions {oct(mode)} on {file_path}") + + os.chmod(file_path, mode) + + if logger: + logger.debug("File permissions set successfully") + return True, None + except Exception as e: + error_msg = f"Failed to set permissions on {file_path}: {e}" + if logger: + logger.error(error_msg) + return False, error_msg + + @staticmethod + def create_directory(path: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, logger=None) -> Tuple[bool, Optional[str]]: + try: + if not os.path.exists(path): + os.makedirs(path, mode=mode) + if logger: + logger.debug(f"Created directory: {path}") + return True, None + except Exception as e: + error_msg = f"Failed to create directory {path}: {e}" + if logger: + logger.error(error_msg) + return False, error_msg + + @staticmethod + def append_to_file(file_path: str, content: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, logger=None) -> Tuple[bool, Optional[str]]: + try: + with open(file_path, 'a') as f: + f.write(f"\n{content}\n") + + FileManager.set_permissions(file_path, mode, logger) + + if logger: + logger.debug(f"Content appended to {file_path}") + return True, None + except Exception as e: + error_msg = f"Failed to append to {file_path}: {e}" + if logger: + logger.error(error_msg) + return False, error_msg + + @staticmethod + def read_file_content(file_path: str, logger=None) -> Tuple[bool, Optional[str], Optional[str]]: + try: + with open(file_path, 'r') as f: + content = f.read().strip() + return True, content, None + except Exception as e: + error_msg = f"Failed to read {file_path}: {e}" + if logger: + logger.error(error_msg) + return False, None, error_msg + + @staticmethod + def expand_user_path(path: str) -> str: + return os.path.expanduser(path) + + @staticmethod + def get_directory_path(file_path: str) -> str: + return os.path.dirname(file_path) + + @staticmethod + def get_public_key_path(private_key_path: str) -> str: + return f"{private_key_path}.pub" diff --git a/cli/app/utils/protocols.py b/cli/app/utils/protocols.py index 0e64e135..c93869ee 100644 --- a/cli/app/utils/protocols.py +++ b/cli/app/utils/protocols.py @@ -12,4 +12,8 @@ def error(self, message: str) -> None: def success(self, message: str) -> None: ... def highlight(self, message: str) -> None: - ... \ No newline at end of file + ... + +class DockerServiceProtocol(Protocol): + def execute_services(self, name: str, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + ... From ee5103033c2e9136a54a1c56a68db0f26358a0ea Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Tue, 15 Jul 2025 07:47:59 +0530 Subject: [PATCH 36/72] fix: add missing dependency requests to project toml deps array --- cli/pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/pyproject.toml b/cli/pyproject.toml index eb202668..9a62858f 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -11,6 +11,7 @@ python = "^3.9.0" typer = "^0.16.0" rich = "^14.0.0" pydantic = "^2.0.0" +requests = "^2.32.3" [tool.poetry.group.dev.dependencies] pytest = "^8.4.1" From 21da783fb34250ad5a9efc9c75efacff4cbea7f2 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Tue, 15 Jul 2025 07:50:10 +0530 Subject: [PATCH 37/72] style: format cli with black --- cli/app/commands/conf/base.py | 111 +++--- cli/app/commands/conf/command.py | 68 ++-- cli/app/commands/conf/delete.py | 102 +++--- cli/app/commands/conf/list.py | 87 +++-- cli/app/commands/conf/messages.py | 2 +- cli/app/commands/conf/set.py | 94 +++-- cli/app/commands/conf/tests/__init__.py | 1 - cli/app/commands/conf/tests/test_base.py | 284 ++++++++------- cli/app/commands/conf/tests/test_delete.py | 249 +++++-------- cli/app/commands/conf/tests/test_list.py | 215 +++++------- cli/app/commands/conf/tests/test_set.py | 239 +++++-------- cli/app/commands/install/clone.py | 128 +++---- cli/app/commands/install/command.py | 35 +- cli/app/commands/install/run.py | 2 + cli/app/commands/install/ssh.py | 188 +++++----- cli/app/commands/install/tests/test_clone.py | 278 +++++++-------- cli/app/commands/install/tests/test_ssh.py | 260 ++++++-------- cli/app/commands/preflight/command.py | 18 +- cli/app/commands/preflight/deps.py | 75 ++-- cli/app/commands/preflight/port.py | 50 ++- cli/app/commands/preflight/tests/test_deps.py | 262 ++++++-------- cli/app/commands/preflight/tests/test_port.py | 21 +- cli/app/commands/proxy/base.py | 123 ++++--- cli/app/commands/proxy/command.py | 52 ++- cli/app/commands/proxy/load.py | 80 +++-- cli/app/commands/proxy/messages.py | 2 +- cli/app/commands/proxy/status.py | 67 ++-- cli/app/commands/proxy/stop.py | 65 ++-- cli/app/commands/proxy/tests/test_load.py | 9 +- cli/app/commands/proxy/tests/test_status.py | 8 +- cli/app/commands/proxy/tests/test_stop.py | 8 +- cli/app/commands/service/__init__.py | 2 +- cli/app/commands/service/base.py | 101 +++--- cli/app/commands/service/command.py | 69 ++-- cli/app/commands/service/down.py | 73 ++-- cli/app/commands/service/ps.py | 67 ++-- cli/app/commands/service/restart.py | 69 ++-- cli/app/commands/service/tests/__init__.py | 2 +- cli/app/commands/service/tests/test_base.py | 186 ++++------ cli/app/commands/service/tests/test_down.py | 281 ++++++--------- cli/app/commands/service/tests/test_ps.py | 313 ++++++----------- .../commands/service/tests/test_restart.py | 330 +++++++----------- cli/app/commands/service/tests/test_up.py | 295 ++++++---------- cli/app/commands/service/up.py | 78 +++-- cli/app/commands/test/command.py | 11 +- cli/app/commands/test/test.py | 10 +- cli/app/commands/version/command.py | 11 +- .../commands/version/tests/test_version.py | 81 +++-- cli/app/commands/version/version.py | 19 +- cli/app/main.py | 17 +- cli/app/utils/config.py | 7 +- cli/app/utils/lib.py | 92 ++--- cli/app/utils/logger.py | 6 +- cli/app/utils/message.py | 2 +- cli/app/utils/output_formatter.py | 17 +- cli/app/utils/protocols.py | 23 +- cli/app/utils/tests/test_processor.py | 52 +-- 57 files changed, 2404 insertions(+), 2993 deletions(-) diff --git a/cli/app/commands/conf/base.py b/cli/app/commands/conf/base.py index cb97f493..a3143fb5 100644 --- a/cli/app/commands/conf/base.py +++ b/cli/app/commands/conf/base.py @@ -1,80 +1,79 @@ import os import shutil import tempfile -from typing import Protocol, Optional, Generic, TypeVar, Dict +from typing import Dict, Generic, Optional, Protocol, TypeVar + from pydantic import BaseModel, Field, field_validator from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol + from .messages import ( - file_read_failed, - file_write_failed, - file_not_found, - invalid_line_warning, backup_created, - backup_removed, + backup_creation_failed, + backup_file_not_found, backup_remove_failed, + backup_removed, backup_restore_attempt, - backup_restore_success, backup_restore_failed, - backup_creation_failed, + backup_restore_success, + file_not_found, + file_read_failed, + file_write_failed, + invalid_line_warning, invalid_service, - backup_file_not_found ) -TConfig = TypeVar('TConfig', bound=BaseModel) -TResult = TypeVar('TResult', bound=BaseModel) +TConfig = TypeVar("TConfig", bound=BaseModel) +TResult = TypeVar("TResult", bound=BaseModel) + class EnvironmentServiceProtocol(Protocol): - def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[str, str], str]: - ... - - def set_config(self, service: str, key: str, value: str, env_file: str = None) -> tuple[bool, str]: - ... - - def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[bool, str]: - ... + def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[str, str], str]: ... + + def set_config(self, service: str, key: str, value: str, env_file: str = None) -> tuple[bool, str]: ... + + def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[bool, str]: ... + class BaseEnvironmentManager: def __init__(self, logger: LoggerProtocol): self.logger = logger - + def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[str]]: try: if not os.path.exists(file_path): return False, {}, file_not_found.format(path=file_path) - + config = {} - with open(file_path, 'r') as f: + with open(file_path, "r") as f: for line_num, line in enumerate(f, 1): line = line.strip() - if not line or line.startswith('#'): + if not line or line.startswith("#"): continue - - if '=' not in line: - self.logger.warning(invalid_line_warning.format( - line_num=line_num, file_path=file_path, line=line - )) + + if "=" not in line: + self.logger.warning(invalid_line_warning.format(line_num=line_num, file_path=file_path, line=line)) continue - - key, value = line.split('=', 1) + + key, value = line.split("=", 1) config[key.strip()] = value.strip() - + return True, config, None except Exception as e: return False, {}, file_read_failed.format(error=e) - + def _create_backup(self, file_path: str) -> tuple[bool, Optional[str], Optional[str]]: if not os.path.exists(file_path): return True, None, None - + try: backup_path = f"{file_path}.backup" shutil.copy2(file_path, backup_path) return True, backup_path, None except Exception as e: return False, None, backup_creation_failed.format(error=e) - + def _restore_backup(self, backup_path: str, file_path: str) -> tuple[bool, Optional[str]]: try: if os.path.exists(backup_path): @@ -84,13 +83,13 @@ def _restore_backup(self, backup_path: str, file_path: str) -> tuple[bool, Optio return False, backup_file_not_found.format(path=backup_path) except Exception as e: return False, backup_restore_failed.format(error=e) - + def _atomic_write(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: temp_path = None try: os.makedirs(os.path.dirname(file_path), exist_ok=True) - - with tempfile.NamedTemporaryFile(mode='w', delete=False, dir=os.path.dirname(file_path)) as temp_file: + + with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=os.path.dirname(file_path)) as temp_file: for key, value in sorted(config.items()): temp_file.write(f"{key}={value}\n") temp_file.flush() @@ -99,7 +98,7 @@ def _atomic_write(self, file_path: str, config: Dict[str, str]) -> tuple[bool, O except (OSError, AttributeError): pass temp_path = temp_file.name - + os.replace(temp_path, file_path) return True, None except Exception as e: @@ -109,19 +108,19 @@ def _atomic_write(self, file_path: str, config: Dict[str, str]) -> tuple[bool, O except: pass return False, file_write_failed.format(error=e) - + def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: backup_created_flag = False backup_path = None - + try: success, backup_path, error = self._create_backup(file_path) if not success: return False, error - + backup_created_flag = True self.logger.info(backup_created.format(backup_path=backup_path)) - + success, error = self._atomic_write(file_path, config) if not success: if backup_created_flag and backup_path: @@ -132,23 +131,23 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, else: self.logger.error(backup_restore_failed.format(error=restore_error)) return False, error - + if backup_created_flag and backup_path and os.path.exists(backup_path): try: os.remove(backup_path) self.logger.info(backup_removed) except Exception as e: self.logger.warning(backup_remove_failed.format(error=e)) - + return True, None - + except Exception as e: return False, file_write_failed.format(error=e) - + def get_service_env_file(self, service: str, env_file: Optional[str] = None) -> str: if env_file: return env_file - + if service == "api": return "/etc/nixopus/source/api/.env" elif service == "view": @@ -156,6 +155,7 @@ def get_service_env_file(self, service: str, env_file: Optional[str] = None) -> else: raise ValueError(invalid_service.format(service=service)) + class BaseConfig(BaseModel): service: str = Field("api", description="The name of the service to manage configuration for") key: Optional[str] = Field(None, description="The configuration key") @@ -164,7 +164,7 @@ class BaseConfig(BaseModel): output: str = Field("text", description="Output format: text, json") dry_run: bool = Field(False, description="Dry run mode") env_file: Optional[str] = Field(None, description="Path to the environment file") - + @field_validator("env_file") @classmethod def validate_env_file(cls, env_file: str) -> Optional[str]: @@ -177,6 +177,7 @@ def validate_env_file(cls, env_file: str) -> Optional[str]: raise ValueError(file_not_found.format(path=stripped_env_file)) return stripped_env_file + class BaseResult(BaseModel): service: str key: Optional[str] = None @@ -187,29 +188,31 @@ class BaseResult(BaseModel): success: bool = False error: Optional[str] = None + class BaseService(Generic[TConfig, TResult]): def __init__(self, config: TConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) self.environment_service = environment_service self.formatter = None - + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> TResult: raise NotImplementedError - + def execute(self) -> TResult: raise NotImplementedError - + def execute_and_format(self) -> str: raise NotImplementedError + class BaseAction(Generic[TConfig, TResult]): def __init__(self, logger: LoggerProtocol = None): self.logger = logger self.formatter = None - + def execute(self, config: TConfig) -> TResult: raise NotImplementedError - + def format_output(self, result: TResult, output: str) -> str: - raise NotImplementedError + raise NotImplementedError diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py index bb90ed35..c935940b 100644 --- a/cli/app/commands/conf/command.py +++ b/cli/app/commands/conf/command.py @@ -1,14 +1,19 @@ import typer + from app.utils.logger import Logger + +from .delete import Delete, DeleteConfig from .list import List, ListConfig from .set import Set, SetConfig -from .delete import Delete, DeleteConfig conf_app = typer.Typer(help="Manage configuration") + @conf_app.command() def list( - service: str = typer.Option("api", "--service", "-s", help="The name of the service to list configuration for, e.g api,view"), + service: str = typer.Option( + "api", "--service", "-s", help="The name of the service to list configuration for, e.g api,view" + ), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), @@ -16,32 +21,29 @@ def list( ): """List all configuration""" logger = Logger(verbose=verbose) - + try: - config = ListConfig( - service=service, - verbose=verbose, - output=output, - dry_run=dry_run, - env_file=env_file - ) - + config = ListConfig(service=service, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file) + list_action = List(logger=logger) result = list_action.list(config) - + if result.success: logger.success(list_action.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @conf_app.command() def delete( - service: str = typer.Option("api", "--service", "-s", help="The name of the service to delete configuration for, e.g api,view"), + service: str = typer.Option( + "api", "--service", "-s", help="The name of the service to delete configuration for, e.g api,view" + ), key: str = typer.Option(None, "--key", "-k", help="The key of the configuration to delete"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), @@ -50,33 +52,29 @@ def delete( ): """Delete a configuration""" logger = Logger(verbose=verbose) - + try: - config = DeleteConfig( - service=service, - key=key, - verbose=verbose, - output=output, - dry_run=dry_run, - env_file=env_file - ) - + config = DeleteConfig(service=service, key=key, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file) + delete_action = Delete(logger=logger) result = delete_action.delete(config) - + if result.success: logger.success(delete_action.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @conf_app.command() def set( - service: str = typer.Option("api", "--service", "-s", help="The name of the service to set configuration for, e.g api,view"), + service: str = typer.Option( + "api", "--service", "-s", help="The name of the service to set configuration for, e.g api,view" + ), key: str = typer.Option(None, "--key", "-k", help="The key of the configuration to set"), value: str = typer.Option(None, "--value", "-v", help="The value of the configuration to set"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), @@ -86,27 +84,21 @@ def set( ): """Set a configuration""" logger = Logger(verbose=verbose) - + try: config = SetConfig( - service=service, - key=key, - value=value, - verbose=verbose, - output=output, - dry_run=dry_run, - env_file=env_file + service=service, key=key, value=value, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file ) - + set_action = Set(logger=logger) result = set_action.set(config) - + if result.success: logger.success(set_action.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/conf/delete.py b/cli/app/commands/conf/delete.py index f906f0c3..b56dbb4c 100644 --- a/cli/app/commands/conf/delete.py +++ b/cli/app/commands/conf/delete.py @@ -1,54 +1,56 @@ -from typing import Protocol, Optional, Dict +from typing import Dict, Optional, Protocol + from pydantic import BaseModel, Field from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol -from .base import ( - BaseEnvironmentManager, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) + +from .base import BaseAction, BaseConfig, BaseEnvironmentManager, BaseResult, BaseService from .messages import ( - configuration_deleted, + config_key_not_found, configuration_delete_failed, - key_required_delete, - dry_run_mode, + configuration_deleted, dry_run_delete_config, + dry_run_mode, end_dry_run, - config_key_not_found + key_required_delete, ) + class EnvironmentServiceProtocol(Protocol): - def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[bool, str]: - ... + def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[bool, str]: ... + class EnvironmentManager(BaseEnvironmentManager): def delete_config(self, service: str, key: str, env_file: Optional[str] = None) -> tuple[bool, Optional[str]]: file_path = self.get_service_env_file(service, env_file) - + success, config, error = self.read_env_file(file_path) if not success: return False, error - + if key not in config: return False, config_key_not_found.format(key=key) - + del config[key] return self.write_env_file(file_path, config) + class DeleteResult(BaseResult): pass + class DeleteConfig(BaseConfig): key: str = Field(..., description="The key of the configuration to delete") + class DeleteService(BaseService[DeleteConfig, DeleteResult]): - def __init__(self, config: DeleteConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + def __init__( + self, config: DeleteConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None + ): super().__init__(config, logger, environment_service) self.environment_service = environment_service or EnvironmentManager(self.logger) - + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> DeleteResult: return DeleteResult( service=self.config.service, @@ -57,86 +59,74 @@ def _create_result(self, success: bool, error: str = None, config_dict: Dict[str output=self.config.output, success=success, error=error, - config=config_dict or {} + config=config_dict or {}, ) - + def delete(self) -> DeleteResult: return self.execute() - + def execute(self) -> DeleteResult: if not self.config.key: return self._create_result(False, error=key_required_delete) - + if self.config.dry_run: return self._create_result(True) - - success, error = self.environment_service.delete_config( - self.config.service, self.config.key, self.config.env_file - ) - + + success, error = self.environment_service.delete_config(self.config.service, self.config.key, self.config.env_file) + if success: - self.logger.info(configuration_deleted.format( - service=self.config.service, key=self.config.key - )) + self.logger.info(configuration_deleted.format(service=self.config.service, key=self.config.key)) return self._create_result(True) else: - self.logger.error(configuration_delete_failed.format( - service=self.config.service, error=error - )) + self.logger.error(configuration_delete_failed.format(service=self.config.service, error=error)) return self._create_result(False, error=error) - + def delete_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self._format_dry_run() - + result = self.execute() return self._format_output(result, self.config.output) - + def _format_dry_run(self) -> str: lines = [dry_run_mode] - lines.append(dry_run_delete_config.format( - service=self.config.service, - key=self.config.key - )) + lines.append(dry_run_delete_config.format(service=self.config.service, key=self.config.key)) lines.append(end_dry_run) return "\n".join(lines) - + def _format_output(self, result: DeleteResult, output_format: str) -> str: if output_format == "json": return self._format_json(result) else: return self._format_text(result) - + def _format_json(self, result: DeleteResult) -> str: import json - output = { - "service": result.service, - "key": result.key, - "success": result.success, - "error": result.error - } + + output = {"service": result.service, "key": result.key, "success": result.success, "error": result.error} return json.dumps(output, indent=2) - + def _format_text(self, result: DeleteResult) -> str: if not result.success: return configuration_delete_failed.format(service=result.service, error=result.error) - + return configuration_deleted.format(service=result.service, key=result.key) + class Delete(BaseAction[DeleteConfig, DeleteResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) - + def delete(self, config: DeleteConfig) -> DeleteResult: return self.execute(config) - + def execute(self, config: DeleteConfig) -> DeleteResult: service = DeleteService(config, logger=self.logger) return service.execute() - + def format_output(self, result: DeleteResult, output: str) -> str: service = DeleteService(result, logger=self.logger) - return service._format_output(result, output) + return service._format_output(result, output) diff --git a/cli/app/commands/conf/list.py b/cli/app/commands/conf/list.py index 104d89ea..5f799fe3 100644 --- a/cli/app/commands/conf/list.py +++ b/cli/app/commands/conf/list.py @@ -1,44 +1,46 @@ -from typing import Protocol, Optional, Dict +from typing import Dict, Optional, Protocol + from pydantic import BaseModel, Field from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol -from .base import ( - BaseEnvironmentManager, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) + +from .base import BaseAction, BaseConfig, BaseEnvironmentManager, BaseResult, BaseService from .messages import ( - configuration_listed, configuration_list_failed, - no_configuration_found, - dry_run_mode, + configuration_listed, dry_run_list_config, - end_dry_run + dry_run_mode, + end_dry_run, + no_configuration_found, ) + class EnvironmentServiceProtocol(Protocol): - def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[str, str], str]: - ... + def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[str, str], str]: ... + class EnvironmentManager(BaseEnvironmentManager): def list_config(self, service: str, env_file: Optional[str] = None) -> tuple[bool, Dict[str, str], Optional[str]]: file_path = self.get_service_env_file(service, env_file) return self.read_env_file(file_path) + class ListResult(BaseResult): pass + class ListConfig(BaseConfig): pass + class ListService(BaseService[ListConfig, ListResult]): - def __init__(self, config: ListConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + def __init__( + self, config: ListConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None + ): super().__init__(config, logger, environment_service) self.environment_service = environment_service or EnvironmentManager(self.logger) - + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> ListResult: return ListResult( service=self.config.service, @@ -46,84 +48,77 @@ def _create_result(self, success: bool, error: str = None, config_dict: Dict[str output=self.config.output, success=success, error=error, - config=config_dict or {} + config=config_dict or {}, ) - + def list(self) -> ListResult: return self.execute() - + def execute(self) -> ListResult: if self.config.dry_run: return self._create_result(True) - - success, config_dict, error = self.environment_service.list_config( - self.config.service, self.config.env_file - ) - + + success, config_dict, error = self.environment_service.list_config(self.config.service, self.config.env_file) + if success: self.logger.info(configuration_listed.format(service=self.config.service)) return self._create_result(True, config_dict=config_dict) else: - self.logger.error(configuration_list_failed.format( - service=self.config.service, error=error - )) + self.logger.error(configuration_list_failed.format(service=self.config.service, error=error)) return self._create_result(False, error=error) - + def list_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self._format_dry_run() - + result = self.execute() return self._format_output(result, self.config.output) - + def _format_dry_run(self) -> str: lines = [dry_run_mode] lines.append(dry_run_list_config.format(service=self.config.service)) lines.append(end_dry_run) return "\n".join(lines) - + def _format_output(self, result: ListResult, output_format: str) -> str: if output_format == "json": return self._format_json(result) else: return self._format_text(result) - + def _format_json(self, result: ListResult) -> str: import json - output = { - "service": result.service, - "success": result.success, - "error": result.error, - "config": result.config - } + + output = {"service": result.service, "success": result.success, "error": result.error, "config": result.config} return json.dumps(output, indent=2) - + def _format_text(self, result: ListResult) -> str: if not result.success: return configuration_list_failed.format(service=result.service, error=result.error) - + if result.config: lines = [configuration_listed.format(service=result.service)] for key, value in sorted(result.config.items()): lines.append(f" {key}={value}") return "\n".join(lines) - + return no_configuration_found.format(service=result.service) + class List(BaseAction[ListConfig, ListResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) - + def list(self, config: ListConfig) -> ListResult: return self.execute(config) - + def execute(self, config: ListConfig) -> ListResult: service = ListService(config, logger=self.logger) return service.execute() - + def format_output(self, result: ListResult, output: str) -> str: service = ListService(result, logger=self.logger) - return service._format_output(result, output) + return service._format_output(result, output) diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py index 97e6a6f5..20c3d6c1 100644 --- a/cli/app/commands/conf/messages.py +++ b/cli/app/commands/conf/messages.py @@ -27,4 +27,4 @@ backup_creation_failed = "Failed to create backup: {error}" invalid_service = "Invalid service: {service}" config_key_not_found = "Configuration key '{key}' not found" -backup_file_not_found = "Backup file not found" +backup_file_not_found = "Backup file not found" diff --git a/cli/app/commands/conf/set.py b/cli/app/commands/conf/set.py index 10946bce..a78adf6a 100644 --- a/cli/app/commands/conf/set.py +++ b/cli/app/commands/conf/set.py @@ -1,52 +1,54 @@ -from typing import Protocol, Optional, Dict +from typing import Dict, Optional, Protocol + from pydantic import BaseModel, Field from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol -from .base import ( - BaseEnvironmentManager, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) + +from .base import BaseAction, BaseConfig, BaseEnvironmentManager, BaseResult, BaseService from .messages import ( configuration_set, configuration_set_failed, - key_required, - value_required, dry_run_mode, dry_run_set_config, - end_dry_run + end_dry_run, + key_required, + value_required, ) + class EnvironmentServiceProtocol(Protocol): - def set_config(self, service: str, key: str, value: str, env_file: str = None) -> tuple[bool, str]: - ... + def set_config(self, service: str, key: str, value: str, env_file: str = None) -> tuple[bool, str]: ... + class EnvironmentManager(BaseEnvironmentManager): def set_config(self, service: str, key: str, value: str, env_file: Optional[str] = None) -> tuple[bool, Optional[str]]: file_path = self.get_service_env_file(service, env_file) - + success, config, error = self.read_env_file(file_path) if not success: return False, error - + config[key] = value return self.write_env_file(file_path, config) + class SetResult(BaseResult): pass + class SetConfig(BaseConfig): key: str = Field(..., description="The key of the configuration to set") value: str = Field(..., description="The value of the configuration to set") + class SetService(BaseService[SetConfig, SetResult]): - def __init__(self, config: SetConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None): + def __init__( + self, config: SetConfig, logger: LoggerProtocol = None, environment_service: EnvironmentServiceProtocol = None + ): super().__init__(config, logger, environment_service) self.environment_service = environment_service or EnvironmentManager(self.logger) - + def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> SetResult: return SetResult( service=self.config.service, @@ -56,91 +58,87 @@ def _create_result(self, success: bool, error: str = None, config_dict: Dict[str output=self.config.output, success=success, error=error, - config=config_dict or {} + config=config_dict or {}, ) - + def set(self) -> SetResult: return self.execute() - + def execute(self) -> SetResult: if not self.config.key: return self._create_result(False, error=key_required) - + if not self.config.value: return self._create_result(False, error=value_required) - + if self.config.dry_run: return self._create_result(True) - + success, error = self.environment_service.set_config( self.config.service, self.config.key, self.config.value, self.config.env_file ) - + if success: - self.logger.info(configuration_set.format( - service=self.config.service, key=self.config.key, value=self.config.value - )) + self.logger.info( + configuration_set.format(service=self.config.service, key=self.config.key, value=self.config.value) + ) return self._create_result(True) else: - self.logger.error(configuration_set_failed.format( - service=self.config.service, error=error - )) + self.logger.error(configuration_set_failed.format(service=self.config.service, error=error)) return self._create_result(False, error=error) - + def set_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self._format_dry_run() - + result = self.execute() return self._format_output(result, self.config.output) - + def _format_dry_run(self) -> str: lines = [dry_run_mode] - lines.append(dry_run_set_config.format( - service=self.config.service, - key=self.config.key, - value=self.config.value - )) + lines.append(dry_run_set_config.format(service=self.config.service, key=self.config.key, value=self.config.value)) lines.append(end_dry_run) return "\n".join(lines) - + def _format_output(self, result: SetResult, output_format: str) -> str: if output_format == "json": return self._format_json(result) else: return self._format_text(result) - + def _format_json(self, result: SetResult) -> str: import json + output = { "service": result.service, "key": result.key, "value": result.value, "success": result.success, - "error": result.error + "error": result.error, } return json.dumps(output, indent=2) - + def _format_text(self, result: SetResult) -> str: if not result.success: return configuration_set_failed.format(service=result.service, error=result.error) - + return configuration_set.format(service=result.service, key=result.key, value=result.value) + class Set(BaseAction[SetConfig, SetResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) - + def set(self, config: SetConfig) -> SetResult: return self.execute(config) - + def execute(self, config: SetConfig) -> SetResult: service = SetService(config, logger=self.logger) return service.execute() - + def format_output(self, result: SetResult, output: str) -> str: service = SetService(result, logger=self.logger) - return service._format_output(result, output) \ No newline at end of file + return service._format_output(result, output) diff --git a/cli/app/commands/conf/tests/__init__.py b/cli/app/commands/conf/tests/__init__.py index 0519ecba..e69de29b 100644 --- a/cli/app/commands/conf/tests/__init__.py +++ b/cli/app/commands/conf/tests/__init__.py @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/cli/app/commands/conf/tests/test_base.py b/cli/app/commands/conf/tests/test_base.py index e61bd781..9a81e086 100644 --- a/cli/app/commands/conf/tests/test_base.py +++ b/cli/app/commands/conf/tests/test_base.py @@ -1,17 +1,12 @@ -import pytest import os -import tempfile import shutil -from unittest.mock import Mock, patch, mock_open +import tempfile +from unittest.mock import Mock, mock_open, patch + +import pytest from pydantic import ValidationError -from app.commands.conf.base import ( - BaseEnvironmentManager, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.commands.conf.base import BaseAction, BaseConfig, BaseEnvironmentManager, BaseResult, BaseService from app.utils.logger import Logger @@ -19,133 +14,133 @@ class TestBaseEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) self.manager = BaseEnvironmentManager(self.logger) - - @patch('os.path.exists') + + @patch("os.path.exists") def test_read_env_file_exists(self, mock_exists): mock_exists.return_value = True - - with patch('builtins.open', mock_open(read_data="KEY1=value1\nKEY2=value2\n")): + + with patch("builtins.open", mock_open(read_data="KEY1=value1\nKEY2=value2\n")): success, config, error = self.manager.read_env_file("/path/to/.env") - + assert success is True assert config == {"KEY1": "value1", "KEY2": "value2"} assert error is None - - @patch('os.path.exists') + + @patch("os.path.exists") def test_read_env_file_not_exists(self, mock_exists): mock_exists.return_value = False - + success, config, error = self.manager.read_env_file("/path/to/.env") - + assert success is False assert config == {} assert "Environment file not found" in error - - @patch('os.path.exists') + + @patch("os.path.exists") def test_read_env_file_with_comments_and_empty_lines(self, mock_exists): mock_exists.return_value = True - + content = "# Comment line\nKEY1=value1\n\nKEY2=value2\n# Another comment" - with patch('builtins.open', mock_open(read_data=content)): + with patch("builtins.open", mock_open(read_data=content)): success, config, error = self.manager.read_env_file("/path/to/.env") - + assert success is True assert config == {"KEY1": "value1", "KEY2": "value2"} assert error is None - - @patch('os.path.exists') + + @patch("os.path.exists") def test_read_env_file_with_invalid_line(self, mock_exists): mock_exists.return_value = True - + content = "KEY1=value1\nINVALID_LINE\nKEY2=value2" - with patch('builtins.open', mock_open(read_data=content)): + with patch("builtins.open", mock_open(read_data=content)): success, config, error = self.manager.read_env_file("/path/to/.env") - + assert success is True assert config == {"KEY1": "value1", "KEY2": "value2"} assert error is None self.logger.warning.assert_called_once() - - @patch('os.path.exists') + + @patch("os.path.exists") def test_create_backup_file_exists(self, mock_exists): mock_exists.return_value = True - - with patch('shutil.copy2') as mock_copy: + + with patch("shutil.copy2") as mock_copy: success, backup_path, error = self.manager._create_backup("/path/to/.env") - + assert success is True assert backup_path == "/path/to/.env.backup" assert error is None mock_copy.assert_called_once_with("/path/to/.env", "/path/to/.env.backup") - - @patch('os.path.exists') + + @patch("os.path.exists") def test_create_backup_file_not_exists(self, mock_exists): mock_exists.return_value = False - + success, backup_path, error = self.manager._create_backup("/path/to/.env") - + assert success is True assert backup_path is None assert error is None - - @patch('os.path.exists') + + @patch("os.path.exists") def test_create_backup_failure(self, mock_exists): mock_exists.return_value = True - - with patch('shutil.copy2', side_effect=Exception("Copy failed")): + + with patch("shutil.copy2", side_effect=Exception("Copy failed")): success, backup_path, error = self.manager._create_backup("/path/to/.env") - + assert success is False assert backup_path is None assert "Failed to create backup" in error - - @patch('os.path.exists') + + @patch("os.path.exists") def test_restore_backup_success(self, mock_exists): mock_exists.return_value = True - - with patch('shutil.copy2') as mock_copy: - with patch('os.remove') as mock_remove: + + with patch("shutil.copy2") as mock_copy: + with patch("os.remove") as mock_remove: success, error = self.manager._restore_backup("/path/to/.env.backup", "/path/to/.env") - + assert success is True assert error is None mock_copy.assert_called_once_with("/path/to/.env.backup", "/path/to/.env") mock_remove.assert_called_once_with("/path/to/.env.backup") - - @patch('os.path.exists') + + @patch("os.path.exists") def test_restore_backup_not_exists(self, mock_exists): mock_exists.return_value = False - + success, error = self.manager._restore_backup("/path/to/.env.backup", "/path/to/.env") - + assert success is False assert error == "Backup file not found" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_restore_backup_failure(self, mock_exists): mock_exists.return_value = True - - with patch('shutil.copy2', side_effect=Exception("Copy failed")): + + with patch("shutil.copy2", side_effect=Exception("Copy failed")): success, error = self.manager._restore_backup("/path/to/.env.backup", "/path/to/.env") - + assert success is False assert "Failed to restore from backup" in error - - @patch('os.makedirs') - @patch('tempfile.NamedTemporaryFile') - @patch('os.replace') - @patch('os.fsync') + + @patch("os.makedirs") + @patch("tempfile.NamedTemporaryFile") + @patch("os.replace") + @patch("os.fsync") def test_atomic_write_success(self, mock_fsync, mock_replace, mock_tempfile, mock_makedirs): config = {"KEY2": "value2", "KEY1": "value1"} - + mock_temp = Mock() mock_temp.name = "/tmp/temp_file" mock_temp.fileno.return_value = 123 mock_tempfile.return_value.__enter__.return_value = mock_temp mock_tempfile.return_value.__exit__.return_value = None - + success, error = self.manager._atomic_write("/path/to/.env", config) - + assert success is True assert error is None mock_makedirs.assert_called_once_with("/path/to", exist_ok=True) @@ -153,127 +148,131 @@ def test_atomic_write_success(self, mock_fsync, mock_replace, mock_tempfile, moc mock_temp.flush.assert_called_once() mock_temp.fileno.assert_called_once() mock_replace.assert_called_once_with("/tmp/temp_file", "/path/to/.env") - - @patch('os.makedirs') - @patch('tempfile.NamedTemporaryFile') + + @patch("os.makedirs") + @patch("tempfile.NamedTemporaryFile") def test_atomic_write_failure(self, mock_tempfile, mock_makedirs): config = {"KEY1": "value1"} - + mock_tempfile.side_effect = Exception("Temp file creation failed") - + success, error = self.manager._atomic_write("/path/to/.env", config) - + assert success is False assert "Failed to write environment file" in error - - @patch('os.makedirs') - @patch('tempfile.NamedTemporaryFile') - @patch('os.replace') - @patch('os.fsync') + + @patch("os.makedirs") + @patch("tempfile.NamedTemporaryFile") + @patch("os.replace") + @patch("os.fsync") def test_atomic_write_simple(self, mock_fsync, mock_replace, mock_tempfile, mock_makedirs): config = {"KEY1": "value1"} - + mock_temp = Mock() mock_temp.name = "/tmp/temp_file" mock_temp.fileno.return_value = 123 mock_tempfile.return_value.__enter__.return_value = mock_temp mock_tempfile.return_value.__exit__.return_value = None - + success, error = self.manager._atomic_write("/path/to/.env", config) - + assert success is True assert error is None - - @patch('os.path.exists') - @patch('shutil.copy2') - @patch('tempfile.NamedTemporaryFile') - @patch('os.replace') - @patch('os.fsync') - @patch('os.makedirs') - def test_write_env_file_success_with_backup(self, mock_makedirs, mock_fsync, mock_replace, mock_tempfile, mock_copy, mock_exists): + + @patch("os.path.exists") + @patch("shutil.copy2") + @patch("tempfile.NamedTemporaryFile") + @patch("os.replace") + @patch("os.fsync") + @patch("os.makedirs") + def test_write_env_file_success_with_backup( + self, mock_makedirs, mock_fsync, mock_replace, mock_tempfile, mock_copy, mock_exists + ): mock_exists.return_value = True config = {"KEY2": "value2", "KEY1": "value1"} - + mock_temp = Mock() mock_temp.name = "/tmp/temp_file" mock_temp.fileno.return_value = 123 mock_tempfile.return_value.__enter__.return_value = mock_temp mock_tempfile.return_value.__exit__.return_value = None - - with patch('os.remove') as mock_remove: + + with patch("os.remove") as mock_remove: success, error = self.manager.write_env_file("/path/to/.env", config) - + assert success is True assert error is None mock_copy.assert_called_once_with("/path/to/.env", "/path/to/.env.backup") mock_remove.assert_called_once_with("/path/to/.env.backup") self.logger.info.assert_called() - - @patch('os.path.exists') - @patch('tempfile.NamedTemporaryFile') - @patch('os.replace') - @patch('os.fsync') - @patch('os.makedirs') - def test_write_env_file_success_no_backup_needed(self, mock_makedirs, mock_fsync, mock_replace, mock_tempfile, mock_exists): + + @patch("os.path.exists") + @patch("tempfile.NamedTemporaryFile") + @patch("os.replace") + @patch("os.fsync") + @patch("os.makedirs") + def test_write_env_file_success_no_backup_needed( + self, mock_makedirs, mock_fsync, mock_replace, mock_tempfile, mock_exists + ): mock_exists.return_value = False config = {"KEY1": "value1"} - + mock_temp = Mock() mock_temp.name = "/tmp/temp_file" mock_temp.fileno.return_value = 123 mock_tempfile.return_value.__enter__.return_value = mock_temp mock_tempfile.return_value.__exit__.return_value = None - + success, error = self.manager.write_env_file("/path/to/.env", config) - + assert success is True assert error is None mock_replace.assert_called_once_with("/tmp/temp_file", "/path/to/.env") - - @patch('os.path.exists') - @patch('shutil.copy2') + + @patch("os.path.exists") + @patch("shutil.copy2") def test_write_env_file_backup_failure(self, mock_copy, mock_exists): mock_exists.return_value = True mock_copy.side_effect = Exception("Backup failed") config = {"KEY1": "value1"} - + success, error = self.manager.write_env_file("/path/to/.env", config) - + assert success is False assert "Failed to create backup" in error - - @patch('os.path.exists') - @patch('shutil.copy2') - @patch('tempfile.NamedTemporaryFile') + + @patch("os.path.exists") + @patch("shutil.copy2") + @patch("tempfile.NamedTemporaryFile") def test_write_env_file_write_failure_with_restore(self, mock_tempfile, mock_copy, mock_exists): mock_exists.return_value = True config = {"KEY1": "value1"} - + mock_tempfile.side_effect = Exception("Write failed") - - with patch.object(self.manager, '_restore_backup') as mock_restore: + + with patch.object(self.manager, "_restore_backup") as mock_restore: mock_restore.return_value = (True, None) - + success, error = self.manager.write_env_file("/path/to/.env", config) - + assert success is False assert "Failed to write environment file" in error mock_restore.assert_called_once_with("/path/to/.env.backup", "/path/to/.env") self.logger.warning.assert_called() self.logger.info.assert_called() - + def test_get_service_env_file_with_custom_env_file(self): env_file = self.manager.get_service_env_file("api", "/custom/.env") assert env_file == "/custom/.env" - + def test_get_service_env_file_api_service(self): env_file = self.manager.get_service_env_file("api") assert env_file == "/etc/nixopus/source/api/.env" - + def test_get_service_env_file_view_service(self): env_file = self.manager.get_service_env_file("view") assert env_file == "/etc/nixopus/source/view/.env" - + def test_get_service_env_file_invalid_service(self): with pytest.raises(ValueError, match="Invalid service: invalid"): self.manager.get_service_env_file("invalid") @@ -289,9 +288,9 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.env_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = BaseConfig( service="view", @@ -300,7 +299,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - env_file="/path/to/.env" + env_file="/path/to/.env", ) assert config.service == "view" assert config.key == "TEST_KEY" @@ -309,33 +308,33 @@ def test_valid_config_custom(self): assert config.output == "json" assert config.dry_run is True assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_exists(self, mock_exists): mock_exists.return_value = True config = BaseConfig(env_file="/path/to/.env") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): BaseConfig(env_file="/path/to/.env") - + def test_validate_env_file_none(self): config = BaseConfig(env_file=None) assert config.env_file is None - + def test_validate_env_file_empty(self): config = BaseConfig(env_file="") assert config.env_file is None - + def test_validate_env_file_whitespace(self): config = BaseConfig(env_file=" ") assert config.env_file is None - + def test_validate_env_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = BaseConfig(env_file=" /path/to/.env ") assert config.env_file == "/path/to/.env" @@ -343,11 +342,7 @@ def test_validate_env_file_stripped(self): class TestBaseResult: def test_base_result_default(self): - result = BaseResult( - service="api", - verbose=False, - output="text" - ) + result = BaseResult(service="api", verbose=False, output="text") assert result.service == "api" assert result.key is None assert result.value is None @@ -356,7 +351,7 @@ def test_base_result_default(self): assert result.output == "text" assert result.success is False assert result.error is None - + def test_base_result_custom(self): result = BaseResult( service="view", @@ -366,7 +361,7 @@ def test_base_result_custom(self): verbose=True, output="json", success=True, - error="test error" + error="test error", ) assert result.service == "view" assert result.key == "TEST_KEY" @@ -383,14 +378,14 @@ def setup_method(self): self.config = BaseConfig() self.logger = Mock(spec=Logger) self.environment_service = Mock() - + def test_base_service_init(self): service = BaseService(self.config, self.logger, self.environment_service) assert service.config == self.config assert service.logger == self.logger assert service.environment_service == self.environment_service assert service.formatter is None - + def test_base_service_init_defaults(self): service = BaseService(self.config) assert service.config == self.config @@ -402,12 +397,12 @@ def test_base_service_init_defaults(self): class TestBaseAction: def setup_method(self): self.logger = Mock(spec=Logger) - + def test_base_action_init(self): action = BaseAction(self.logger) assert action.logger == self.logger assert action.formatter is None - + def test_base_action_init_default(self): action = BaseAction() assert action.logger is None @@ -417,4 +412,5 @@ def test_base_action_init_default(self): def mock_open(read_data=""): """Helper function to create a mock open function""" from unittest.mock import mock_open as _mock_open - return _mock_open(read_data=read_data) + + return _mock_open(read_data=read_data) diff --git a/cli/app/commands/conf/tests/test_delete.py b/cli/app/commands/conf/tests/test_delete.py index fde46141..99a22a4c 100644 --- a/cli/app/commands/conf/tests/test_delete.py +++ b/cli/app/commands/conf/tests/test_delete.py @@ -1,22 +1,17 @@ -import pytest import json from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError -from app.commands.conf.delete import ( - EnvironmentManager, - DeleteResult, - DeleteConfig, - DeleteService, - Delete -) +from app.commands.conf.delete import Delete, DeleteConfig, DeleteResult, DeleteService, EnvironmentManager from app.commands.conf.messages import ( - configuration_deleted, configuration_delete_failed, - key_required_delete, - dry_run_mode, + configuration_deleted, dry_run_delete_config, - end_dry_run + dry_run_mode, + end_dry_run, + key_required_delete, ) from app.utils.logger import Logger @@ -25,60 +20,60 @@ class TestEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) self.manager = EnvironmentManager(self.logger) - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') - @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") + @patch("app.commands.conf.base.BaseEnvironmentManager.write_env_file") def test_delete_config_success(self, mock_write_env_file, mock_read_env_file): mock_read_env_file.return_value = (True, {"KEY1": "value1", "KEY2": "value2"}, None) mock_write_env_file.return_value = (True, None) - + success, error = self.manager.delete_config("api", "KEY1") - + assert success is True assert error is None mock_read_env_file.assert_called_once_with("/etc/nixopus/source/api/.env") mock_write_env_file.assert_called_once_with("/etc/nixopus/source/api/.env", {"KEY2": "value2"}) - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") def test_delete_config_read_failure(self, mock_read_env_file): mock_read_env_file.return_value = (False, {}, "File not found") - + success, error = self.manager.delete_config("api", "KEY1") - + assert success is False assert error == "File not found" - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") def test_delete_config_key_not_found(self, mock_read_env_file): mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) - + success, error = self.manager.delete_config("api", "KEY2") - + assert success is False assert "Configuration key 'KEY2' not found" in error - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') - @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") + @patch("app.commands.conf.base.BaseEnvironmentManager.write_env_file") def test_delete_config_write_failure(self, mock_write_env_file, mock_read_env_file): mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) mock_write_env_file.return_value = (False, "Write error") - + success, error = self.manager.delete_config("api", "KEY1") - + assert success is False assert error == "Write error" - - @patch('app.commands.conf.base.BaseEnvironmentManager.get_service_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.get_service_env_file") def test_delete_config_with_custom_env_file(self, mock_get_service_env_file): mock_get_service_env_file.return_value = "/custom/.env" - - with patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') as mock_read: - with patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') as mock_write: + + with patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") as mock_read: + with patch("app.commands.conf.base.BaseEnvironmentManager.write_env_file") as mock_write: mock_read.return_value = (True, {"KEY1": "value1"}, None) mock_write.return_value = (True, None) - + self.manager.delete_config("api", "KEY1", "/custom/.env") - + mock_get_service_env_file.assert_called_once_with("api", "/custom/.env") @@ -92,17 +87,12 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.env_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = DeleteConfig( - service="view", - key="TEST_KEY", - verbose=True, - output="json", - dry_run=True, - env_file="/path/to/.env" + service="view", key="TEST_KEY", verbose=True, output="json", dry_run=True, env_file="/path/to/.env" ) assert config.service == "view" assert config.key == "TEST_KEY" @@ -114,12 +104,7 @@ def test_valid_config_custom(self): class TestDeleteResult: def test_delete_result_default(self): - result = DeleteResult( - service="api", - key="TEST_KEY", - verbose=False, - output="text" - ) + result = DeleteResult(service="api", key="TEST_KEY", verbose=False, output="text") assert result.service == "api" assert result.key == "TEST_KEY" assert result.value is None @@ -128,15 +113,10 @@ def test_delete_result_default(self): assert result.output == "text" assert result.success is False assert result.error is None - + def test_delete_result_success(self): result = DeleteResult( - service="view", - key="TEST_KEY", - config={"KEY1": "value1"}, - verbose=True, - output="json", - success=True + service="view", key="TEST_KEY", config={"KEY1": "value1"}, verbose=True, output="json", success=True ) assert result.service == "view" assert result.key == "TEST_KEY" @@ -152,144 +132,117 @@ def setup_method(self): self.logger = Mock(spec=Logger) self.environment_service = Mock() self.service = DeleteService(self.config, self.logger, self.environment_service) - + def test_delete_service_init(self): assert self.service.config == self.config assert self.service.logger == self.logger assert self.service.environment_service == self.environment_service - + def test_delete_service_init_defaults(self): service = DeleteService(self.config) assert service.config == self.config assert service.logger is not None assert service.environment_service is not None - + def test_create_result_success(self): result = self.service._create_result(True, config_dict={"KEY1": "value1"}) - + assert result.service == "api" assert result.key == "TEST_KEY" assert result.config == {"KEY1": "value1"} assert result.success is True assert result.error is None - + def test_create_result_failure(self): result = self.service._create_result(False, error="Test error") - + assert result.service == "api" assert result.key == "TEST_KEY" assert result.config == {} assert result.success is False assert result.error == "Test error" - + def test_delete_missing_key(self): self.config.key = None - + result = self.service.delete() - + assert result.success is False assert result.error == key_required_delete - + def test_delete_success(self): self.environment_service.delete_config.return_value = (True, None) - + result = self.service.delete() - + assert result.success is True assert result.error is None - self.logger.info.assert_called_once_with(configuration_deleted.format( - service="api", key="TEST_KEY" - )) - self.environment_service.delete_config.assert_called_once_with( - "api", "TEST_KEY", None - ) - + self.logger.info.assert_called_once_with(configuration_deleted.format(service="api", key="TEST_KEY")) + self.environment_service.delete_config.assert_called_once_with("api", "TEST_KEY", None) + def test_delete_failure(self): self.environment_service.delete_config.return_value = (False, "Delete error") - + result = self.service.delete() - + assert result.success is False assert result.error == "Delete error" - self.logger.error.assert_called_once_with(configuration_delete_failed.format( - service="api", error="Delete error" - )) - + self.logger.error.assert_called_once_with(configuration_delete_failed.format(service="api", error="Delete error")) + def test_delete_dry_run(self): self.config.dry_run = True - + result = self.service.delete() - + assert result.success is True assert result.error is None self.environment_service.delete_config.assert_not_called() - + def test_delete_and_format_success(self): self.environment_service.delete_config.return_value = (True, None) - + output = self.service.delete_and_format() - + assert configuration_deleted.format(service="api", key="TEST_KEY") in output - + def test_delete_and_format_failure(self): self.environment_service.delete_config.return_value = (False, "Delete error") - + output = self.service.delete_and_format() - + assert configuration_delete_failed.format(service="api", error="Delete error") in output - + def test_delete_and_format_dry_run(self): self.config.dry_run = True - + output = self.service.delete_and_format() - + assert dry_run_mode in output - assert dry_run_delete_config.format( - service="api", key="TEST_KEY" - ) in output + assert dry_run_delete_config.format(service="api", key="TEST_KEY") in output assert end_dry_run in output - + def test_format_output_json(self): - result = DeleteResult( - service="api", - key="TEST_KEY", - success=True, - verbose=False, - output="json" - ) - + result = DeleteResult(service="api", key="TEST_KEY", success=True, verbose=False, output="json") + output = self.service._format_output(result, "json") data = json.loads(output) - + assert data["service"] == "api" assert data["key"] == "TEST_KEY" assert data["success"] is True - + def test_format_output_text_success(self): - result = DeleteResult( - service="api", - key="TEST_KEY", - success=True, - verbose=False, - output="text" - ) - + result = DeleteResult(service="api", key="TEST_KEY", success=True, verbose=False, output="text") + output = self.service._format_output(result, "text") - + assert configuration_deleted.format(service="api", key="TEST_KEY") in output - + def test_format_output_text_failure(self): - result = DeleteResult( - service="api", - key="TEST_KEY", - success=False, - error="Test error", - verbose=False, - output="text" - ) - + result = DeleteResult(service="api", key="TEST_KEY", success=False, error="Test error", verbose=False, output="text") + output = self.service._format_output(result, "text") - + assert configuration_delete_failed.format(service="api", error="Test error") in output @@ -297,47 +250,37 @@ class TestDelete: def setup_method(self): self.logger = Mock(spec=Logger) self.action = Delete(self.logger) - + def test_delete_action_init(self): assert self.action.logger == self.logger - + def test_delete_action_init_default(self): action = Delete() assert action.logger is None - + def test_delete_success(self): config = DeleteConfig(key="TEST_KEY") - - with patch('app.commands.conf.delete.DeleteService') as mock_service_class: + + with patch("app.commands.conf.delete.DeleteService") as mock_service_class: mock_service = Mock() mock_service.execute.return_value = DeleteResult( - service="api", - key="TEST_KEY", - success=True, - verbose=False, - output="text" + service="api", key="TEST_KEY", success=True, verbose=False, output="text" ) mock_service_class.return_value = mock_service - + result = self.action.delete(config) - + assert result.success is True assert result.key == "TEST_KEY" - + def test_format_output(self): - result = DeleteResult( - service="api", - key="TEST_KEY", - success=True, - verbose=False, - output="text" - ) - - with patch('app.commands.conf.delete.DeleteService') as mock_service_class: + result = DeleteResult(service="api", key="TEST_KEY", success=True, verbose=False, output="text") + + with patch("app.commands.conf.delete.DeleteService") as mock_service_class: mock_service = Mock() mock_service._format_output.return_value = "formatted output" mock_service_class.return_value = mock_service - + output = self.action.format_output(result, "text") - - assert output == "formatted output" + + assert output == "formatted output" diff --git a/cli/app/commands/conf/tests/test_list.py b/cli/app/commands/conf/tests/test_list.py index 61c696c6..26bb47d7 100644 --- a/cli/app/commands/conf/tests/test_list.py +++ b/cli/app/commands/conf/tests/test_list.py @@ -1,22 +1,17 @@ -import pytest import json from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError -from app.commands.conf.list import ( - EnvironmentManager, - ListResult, - ListConfig, - ListService, - List -) +from app.commands.conf.list import EnvironmentManager, List, ListConfig, ListResult, ListService from app.commands.conf.messages import ( - configuration_listed, configuration_list_failed, - no_configuration_found, - dry_run_mode, + configuration_listed, dry_run_list_config, - end_dry_run + dry_run_mode, + end_dry_run, + no_configuration_found, ) from app.utils.logger import Logger @@ -25,34 +20,34 @@ class TestEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) self.manager = EnvironmentManager(self.logger) - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") def test_list_config_success(self, mock_read_env_file): mock_read_env_file.return_value = (True, {"KEY1": "value1", "KEY2": "value2"}, None) - + success, config, error = self.manager.list_config("api") - + assert success is True assert config == {"KEY1": "value1", "KEY2": "value2"} assert error is None mock_read_env_file.assert_called_once_with("/etc/nixopus/source/api/.env") - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") def test_list_config_failure(self, mock_read_env_file): mock_read_env_file.return_value = (False, {}, "File not found") - + success, config, error = self.manager.list_config("api") - + assert success is False assert config == {} assert error == "File not found" - - @patch('app.commands.conf.base.BaseEnvironmentManager.get_service_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.get_service_env_file") def test_list_config_with_custom_env_file(self, mock_get_service_env_file): mock_get_service_env_file.return_value = "/custom/.env" - + self.manager.list_config("api", "/custom/.env") - + mock_get_service_env_file.assert_called_once_with("api", "/custom/.env") @@ -66,17 +61,11 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.env_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = ListConfig( - service="view", - verbose=True, - output="json", - dry_run=True, - env_file="/path/to/.env" - ) + config = ListConfig(service="view", verbose=True, output="json", dry_run=True, env_file="/path/to/.env") assert config.service == "view" assert config.verbose is True assert config.output == "json" @@ -86,11 +75,7 @@ def test_valid_config_custom(self): class TestListResult: def test_list_result_default(self): - result = ListResult( - service="api", - verbose=False, - output="text" - ) + result = ListResult(service="api", verbose=False, output="text") assert result.service == "api" assert result.key is None assert result.value is None @@ -99,14 +84,10 @@ def test_list_result_default(self): assert result.output == "text" assert result.success is False assert result.error is None - + def test_list_result_with_config(self): result = ListResult( - service="view", - config={"KEY1": "value1", "KEY2": "value2"}, - verbose=True, - output="json", - success=True + service="view", config={"KEY1": "value1", "KEY2": "value2"}, verbose=True, output="json", success=True ) assert result.service == "view" assert result.config == {"KEY1": "value1", "KEY2": "value2"} @@ -121,143 +102,119 @@ def setup_method(self): self.logger = Mock(spec=Logger) self.environment_service = Mock() self.service = ListService(self.config, self.logger, self.environment_service) - + def test_list_service_init(self): assert self.service.config == self.config assert self.service.logger == self.logger assert self.service.environment_service == self.environment_service - + def test_list_service_init_defaults(self): service = ListService(self.config) assert service.config == self.config assert service.logger is not None assert service.environment_service is not None - + def test_create_result_success(self): result = self.service._create_result(True, config_dict={"KEY1": "value1"}) - + assert result.service == "api" assert result.config == {"KEY1": "value1"} assert result.success is True assert result.error is None - + def test_create_result_failure(self): result = self.service._create_result(False, error="Test error") - + assert result.service == "api" assert result.config == {} assert result.success is False assert result.error == "Test error" - + def test_list_success(self): self.environment_service.list_config.return_value = (True, {"KEY1": "value1"}, None) - + result = self.service.list() - + assert result.success is True assert result.config == {"KEY1": "value1"} assert result.error is None self.logger.info.assert_called_once_with(configuration_listed.format(service="api")) - + def test_list_failure(self): self.environment_service.list_config.return_value = (False, {}, "File not found") - + result = self.service.list() - + assert result.success is False assert result.error == "File not found" - self.logger.error.assert_called_once_with(configuration_list_failed.format( - service="api", error="File not found" - )) - + self.logger.error.assert_called_once_with(configuration_list_failed.format(service="api", error="File not found")) + def test_list_dry_run(self): self.config.dry_run = True - + result = self.service.list() - + assert result.success is True assert result.error is None self.environment_service.list_config.assert_not_called() - + def test_list_and_format_success(self): self.environment_service.list_config.return_value = (True, {"KEY1": "value1"}, None) - + output = self.service.list_and_format() - + assert configuration_listed.format(service="api") in output assert " KEY1=value1" in output - + def test_list_and_format_failure(self): self.environment_service.list_config.return_value = (False, {}, "File not found") - + output = self.service.list_and_format() - + assert configuration_list_failed.format(service="api", error="File not found") in output - + def test_list_and_format_dry_run(self): self.config.dry_run = True - + output = self.service.list_and_format() - + assert dry_run_mode in output assert dry_run_list_config.format(service="api") in output assert end_dry_run in output - + def test_format_output_json(self): - result = ListResult( - service="api", - config={"KEY1": "value1"}, - success=True, - verbose=False, - output="json" - ) - + result = ListResult(service="api", config={"KEY1": "value1"}, success=True, verbose=False, output="json") + output = self.service._format_output(result, "json") data = json.loads(output) - + assert data["service"] == "api" assert data["success"] is True assert data["config"] == {"KEY1": "value1"} - + def test_format_output_text_success(self): result = ListResult( - service="api", - config={"KEY1": "value1", "KEY2": "value2"}, - success=True, - verbose=False, - output="text" + service="api", config={"KEY1": "value1", "KEY2": "value2"}, success=True, verbose=False, output="text" ) - + output = self.service._format_output(result, "text") - + assert configuration_listed.format(service="api") in output assert " KEY1=value1" in output assert " KEY2=value2" in output - + def test_format_output_text_failure(self): - result = ListResult( - service="api", - success=False, - error="Test error", - verbose=False, - output="text" - ) - + result = ListResult(service="api", success=False, error="Test error", verbose=False, output="text") + output = self.service._format_output(result, "text") - + assert configuration_list_failed.format(service="api", error="Test error") in output - + def test_format_output_text_no_config(self): - result = ListResult( - service="api", - config={}, - success=True, - verbose=False, - output="text" - ) - + result = ListResult(service="api", config={}, success=True, verbose=False, output="text") + output = self.service._format_output(result, "text") - + assert no_configuration_found.format(service="api") in output @@ -265,47 +222,37 @@ class TestList: def setup_method(self): self.logger = Mock(spec=Logger) self.action = List(self.logger) - + def test_list_action_init(self): assert self.action.logger == self.logger - + def test_list_action_init_default(self): action = List() assert action.logger is None - + def test_list_success(self): config = ListConfig(service="api") - - with patch('app.commands.conf.list.ListService') as mock_service_class: + + with patch("app.commands.conf.list.ListService") as mock_service_class: mock_service = Mock() mock_service.execute.return_value = ListResult( - service="api", - config={"KEY1": "value1"}, - success=True, - verbose=False, - output="text" + service="api", config={"KEY1": "value1"}, success=True, verbose=False, output="text" ) mock_service_class.return_value = mock_service - + result = self.action.list(config) - + assert result.success is True assert result.config == {"KEY1": "value1"} - + def test_format_output(self): - result = ListResult( - service="api", - config={"KEY1": "value1"}, - success=True, - verbose=False, - output="text" - ) - - with patch('app.commands.conf.list.ListService') as mock_service_class: + result = ListResult(service="api", config={"KEY1": "value1"}, success=True, verbose=False, output="text") + + with patch("app.commands.conf.list.ListService") as mock_service_class: mock_service = Mock() mock_service._format_output.return_value = "formatted output" mock_service_class.return_value = mock_service - + output = self.action.format_output(result, "text") - - assert output == "formatted output" + + assert output == "formatted output" diff --git a/cli/app/commands/conf/tests/test_set.py b/cli/app/commands/conf/tests/test_set.py index 97fa9d78..ce84b86c 100644 --- a/cli/app/commands/conf/tests/test_set.py +++ b/cli/app/commands/conf/tests/test_set.py @@ -1,24 +1,19 @@ -import pytest import json from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError -from app.commands.conf.set import ( - EnvironmentManager, - SetResult, - SetConfig, - SetService, - Set -) from app.commands.conf.messages import ( configuration_set, configuration_set_failed, - key_required, - value_required, dry_run_mode, dry_run_set_config, - end_dry_run + end_dry_run, + key_required, + value_required, ) +from app.commands.conf.set import EnvironmentManager, Set, SetConfig, SetResult, SetService from app.utils.logger import Logger @@ -26,51 +21,51 @@ class TestEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) self.manager = EnvironmentManager(self.logger) - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') - @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") + @patch("app.commands.conf.base.BaseEnvironmentManager.write_env_file") def test_set_config_success(self, mock_write_env_file, mock_read_env_file): mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) mock_write_env_file.return_value = (True, None) - + success, error = self.manager.set_config("api", "KEY2", "value2") - + assert success is True assert error is None mock_read_env_file.assert_called_once_with("/etc/nixopus/source/api/.env") mock_write_env_file.assert_called_once_with("/etc/nixopus/source/api/.env", {"KEY1": "value1", "KEY2": "value2"}) - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") def test_set_config_read_failure(self, mock_read_env_file): mock_read_env_file.return_value = (False, {}, "File not found") - + success, error = self.manager.set_config("api", "KEY1", "value1") - + assert success is False assert error == "File not found" - - @patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') - @patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") + @patch("app.commands.conf.base.BaseEnvironmentManager.write_env_file") def test_set_config_write_failure(self, mock_write_env_file, mock_read_env_file): mock_read_env_file.return_value = (True, {"KEY1": "value1"}, None) mock_write_env_file.return_value = (False, "Write error") - + success, error = self.manager.set_config("api", "KEY2", "value2") - + assert success is False assert error == "Write error" - - @patch('app.commands.conf.base.BaseEnvironmentManager.get_service_env_file') + + @patch("app.commands.conf.base.BaseEnvironmentManager.get_service_env_file") def test_set_config_with_custom_env_file(self, mock_get_service_env_file): mock_get_service_env_file.return_value = "/custom/.env" - - with patch('app.commands.conf.base.BaseEnvironmentManager.read_env_file') as mock_read: - with patch('app.commands.conf.base.BaseEnvironmentManager.write_env_file') as mock_write: + + with patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") as mock_read: + with patch("app.commands.conf.base.BaseEnvironmentManager.write_env_file") as mock_write: mock_read.return_value = (True, {}, None) mock_write.return_value = (True, None) - + self.manager.set_config("api", "KEY1", "value1", "/custom/.env") - + mock_get_service_env_file.assert_called_once_with("api", "/custom/.env") @@ -84,9 +79,9 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.env_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = SetConfig( service="view", @@ -95,7 +90,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - env_file="/path/to/.env" + env_file="/path/to/.env", ) assert config.service == "view" assert config.key == "TEST_KEY" @@ -108,13 +103,7 @@ def test_valid_config_custom(self): class TestSetResult: def test_set_result_default(self): - result = SetResult( - service="api", - key="TEST_KEY", - value="test_value", - verbose=False, - output="text" - ) + result = SetResult(service="api", key="TEST_KEY", value="test_value", verbose=False, output="text") assert result.service == "api" assert result.key == "TEST_KEY" assert result.value == "test_value" @@ -123,7 +112,7 @@ def test_set_result_default(self): assert result.output == "text" assert result.success is False assert result.error is None - + def test_set_result_success(self): result = SetResult( service="view", @@ -132,7 +121,7 @@ def test_set_result_success(self): config={"KEY1": "value1"}, verbose=True, output="json", - success=True + success=True, ) assert result.service == "view" assert result.key == "TEST_KEY" @@ -149,158 +138,130 @@ def setup_method(self): self.logger = Mock(spec=Logger) self.environment_service = Mock() self.service = SetService(self.config, self.logger, self.environment_service) - + def test_set_service_init(self): assert self.service.config == self.config assert self.service.logger == self.logger assert self.service.environment_service == self.environment_service - + def test_set_service_init_defaults(self): service = SetService(self.config) assert service.config == self.config assert service.logger is not None assert service.environment_service is not None - + def test_create_result_success(self): result = self.service._create_result(True, config_dict={"KEY1": "value1"}) - + assert result.service == "api" assert result.key == "TEST_KEY" assert result.value == "test_value" assert result.config == {"KEY1": "value1"} assert result.success is True assert result.error is None - + def test_create_result_failure(self): result = self.service._create_result(False, error="Test error") - + assert result.service == "api" assert result.key == "TEST_KEY" assert result.value == "test_value" assert result.config == {} assert result.success is False assert result.error == "Test error" - + def test_set_missing_key(self): self.config.key = None - + result = self.service.set() - + assert result.success is False assert result.error == key_required - + def test_set_missing_value(self): self.config.value = None - + result = self.service.set() - + assert result.success is False assert result.error == value_required - + def test_set_success(self): self.environment_service.set_config.return_value = (True, None) - + result = self.service.set() - + assert result.success is True assert result.error is None - self.logger.info.assert_called_once_with(configuration_set.format( - service="api", key="TEST_KEY", value="test_value" - )) - self.environment_service.set_config.assert_called_once_with( - "api", "TEST_KEY", "test_value", None - ) - + self.logger.info.assert_called_once_with(configuration_set.format(service="api", key="TEST_KEY", value="test_value")) + self.environment_service.set_config.assert_called_once_with("api", "TEST_KEY", "test_value", None) + def test_set_failure(self): self.environment_service.set_config.return_value = (False, "Write error") - + result = self.service.set() - + assert result.success is False assert result.error == "Write error" - self.logger.error.assert_called_once_with(configuration_set_failed.format( - service="api", error="Write error" - )) - + self.logger.error.assert_called_once_with(configuration_set_failed.format(service="api", error="Write error")) + def test_set_dry_run(self): self.config.dry_run = True - + result = self.service.set() - + assert result.success is True assert result.error is None self.environment_service.set_config.assert_not_called() - + def test_set_and_format_success(self): self.environment_service.set_config.return_value = (True, None) - + output = self.service.set_and_format() - + assert configuration_set.format(service="api", key="TEST_KEY", value="test_value") in output - + def test_set_and_format_failure(self): self.environment_service.set_config.return_value = (False, "Write error") - + output = self.service.set_and_format() - + assert configuration_set_failed.format(service="api", error="Write error") in output - + def test_set_and_format_dry_run(self): self.config.dry_run = True - + output = self.service.set_and_format() - + assert dry_run_mode in output - assert dry_run_set_config.format( - service="api", key="TEST_KEY", value="test_value" - ) in output + assert dry_run_set_config.format(service="api", key="TEST_KEY", value="test_value") in output assert end_dry_run in output - + def test_format_output_json(self): - result = SetResult( - service="api", - key="TEST_KEY", - value="test_value", - success=True, - verbose=False, - output="json" - ) - + result = SetResult(service="api", key="TEST_KEY", value="test_value", success=True, verbose=False, output="json") + output = self.service._format_output(result, "json") data = json.loads(output) - + assert data["service"] == "api" assert data["key"] == "TEST_KEY" assert data["value"] == "test_value" assert data["success"] is True - + def test_format_output_text_success(self): - result = SetResult( - service="api", - key="TEST_KEY", - value="test_value", - success=True, - verbose=False, - output="text" - ) - + result = SetResult(service="api", key="TEST_KEY", value="test_value", success=True, verbose=False, output="text") + output = self.service._format_output(result, "text") - + assert configuration_set.format(service="api", key="TEST_KEY", value="test_value") in output - + def test_format_output_text_failure(self): result = SetResult( - service="api", - key="TEST_KEY", - value="test_value", - success=False, - error="Test error", - verbose=False, - output="text" + service="api", key="TEST_KEY", value="test_value", success=False, error="Test error", verbose=False, output="text" ) - + output = self.service._format_output(result, "text") - + assert configuration_set_failed.format(service="api", error="Test error") in output @@ -308,50 +269,38 @@ class TestSet: def setup_method(self): self.logger = Mock(spec=Logger) self.action = Set(self.logger) - + def test_set_action_init(self): assert self.action.logger == self.logger - + def test_set_action_init_default(self): action = Set() assert action.logger is None - + def test_set_success(self): config = SetConfig(key="TEST_KEY", value="test_value") - - with patch('app.commands.conf.set.SetService') as mock_service_class: + + with patch("app.commands.conf.set.SetService") as mock_service_class: mock_service = Mock() mock_service.execute.return_value = SetResult( - service="api", - key="TEST_KEY", - value="test_value", - success=True, - verbose=False, - output="text" + service="api", key="TEST_KEY", value="test_value", success=True, verbose=False, output="text" ) mock_service_class.return_value = mock_service - + result = self.action.set(config) - + assert result.success is True assert result.key == "TEST_KEY" assert result.value == "test_value" - + def test_format_output(self): - result = SetResult( - service="api", - key="TEST_KEY", - value="test_value", - success=True, - verbose=False, - output="text" - ) - - with patch('app.commands.conf.set.SetService') as mock_service_class: + result = SetResult(service="api", key="TEST_KEY", value="test_value", success=True, verbose=False, output="text") + + with patch("app.commands.conf.set.SetService") as mock_service_class: mock_service = Mock() mock_service._format_output.return_value = "formatted output" mock_service_class.return_value = mock_service - + output = self.action.format_output(result, "text") - - assert output == "formatted output" + + assert output == "formatted output" diff --git a/cli/app/commands/install/clone.py b/cli/app/commands/install/clone.py index 67e8ab8a..3c6ee3a0 100644 --- a/cli/app/commands/install/clone.py +++ b/cli/app/commands/install/clone.py @@ -1,42 +1,45 @@ -import subprocess import os -from typing import Protocol, Optional +import subprocess +from typing import Optional, Protocol + from pydantic import BaseModel, Field, field_validator -from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.lib import DirectoryManager +from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter +from app.utils.protocols import LoggerProtocol + from .messages import ( - path_already_exists_use_force, - executing_command, - successfully_cloned, - git_clone_failed, - unexpected_error_during_clone, - dry_run_mode, - dry_run_command_would_be_executed, + cloning_repo_into_path, + default_branch, + dry_run_branch, dry_run_command, + dry_run_command_would_be_executed, + dry_run_force_mode, + dry_run_mode, dry_run_repository, - dry_run_branch, dry_run_target_path, - dry_run_force_mode, - path_exists_will_overwrite, - path_exists_would_fail, - target_path_not_exists, end_dry_run, - cloning_repo_into_path, - invalid_repository_url, + executing_command, + failed_to_prepare_target_directory, + git_clone_failed, invalid_path, invalid_repo, + invalid_repository_url, + path_already_exists_use_force, + path_exists_will_overwrite, + path_exists_would_fail, prerequisites_validation_failed, - failed_to_prepare_target_directory, + successfully_cloned, + target_path_not_exists, + unexpected_error_during_clone, unknown_error, - default_branch ) + class GitCloneProtocol(Protocol): - def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bool, str]: - ... + def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bool, str]: ... + class GitCommandBuilder: @staticmethod @@ -47,10 +50,11 @@ def build_clone_command(repo: str, path: str, branch: str = None) -> list[str]: cmd.extend([repo, path]) return cmd + class CloneFormatter: def __init__(self): self.output_formatter = OutputFormatter() - + def format_output(self, result: "CloneResult", output: str) -> str: if result.success: message = successfully_cloned.format(repo=result.repo, path=result.path) @@ -58,26 +62,26 @@ def format_output(self, result: "CloneResult", output: str) -> str: else: error = result.error or unknown_error output_message = self.output_formatter.create_error_message(error, result.model_dump()) - + return self.output_formatter.format_output(output_message, output) - + def format_dry_run(self, config: "CloneConfig") -> str: cmd = GitCommandBuilder.build_clone_command(config.repo, config.path, config.branch) - + output = [] output.append(dry_run_mode) output.append(dry_run_command_would_be_executed) - output.append(dry_run_command.format(command=' '.join(cmd))) + output.append(dry_run_command.format(command=" ".join(cmd))) output.append(dry_run_repository.format(repo=config.repo)) output.append(dry_run_branch.format(branch=config.branch or default_branch)) output.append(dry_run_target_path.format(path=config.path)) output.append(dry_run_force_mode.format(force=config.force)) - + self._add_path_status_message(output, config.path, config.force) - + output.append(end_dry_run) return "\n".join(output) - + def _add_path_status_message(self, output: list[str], path: str, force: bool) -> None: if os.path.exists(path): if force: @@ -87,15 +91,16 @@ def _add_path_status_message(self, output: list[str], path: str, force: bool) -> else: output.append(target_path_not_exists.format(path=path)) + class GitClone: def __init__(self, logger: LoggerProtocol): self.logger = logger - + def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bool, str]: cmd = GitCommandBuilder.build_clone_command(repo, path, branch) - + try: - self.logger.info(executing_command.format(command=' '.join(cmd))) + self.logger.info(executing_command.format(command=" ".join(cmd))) result = subprocess.run(cmd, capture_output=True, text=True, check=True) self.logger.success(successfully_cloned.format(repo=repo, path=path)) return True, None @@ -106,6 +111,7 @@ def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bo self.logger.error(unexpected_error_during_clone.format(error=e)) return False, str(e) + class CloneResult(BaseModel): repo: str path: str @@ -116,6 +122,7 @@ class CloneResult(BaseModel): success: bool = False error: Optional[str] = None + class CloneConfig(BaseModel): repo: str = Field(..., min_length=1, description="Repository URL to clone") branch: Optional[str] = Field("master", description="Branch to clone") @@ -124,26 +131,26 @@ class CloneConfig(BaseModel): verbose: bool = Field(False, description="Verbose output") output: str = Field("text", description="Output format: text, json") dry_run: bool = Field(False, description="Dry run mode") - + @field_validator("repo") @classmethod def validate_repo(cls, repo: str) -> str: stripped_repo = repo.strip() if not stripped_repo: raise ValueError(invalid_repo) - + if not cls._is_valid_repo_format(stripped_repo): raise ValueError(invalid_repository_url) return stripped_repo - + @staticmethod def _is_valid_repo_format(repo: str) -> bool: return ( - repo.startswith(('http://', 'https://', 'git://', 'ssh://')) or - (repo.endswith('.git') and not repo.startswith('github.com:')) or - ('@' in repo and ':' in repo and repo.count('@') == 1) + repo.startswith(("http://", "https://", "git://", "ssh://")) + or (repo.endswith(".git") and not repo.startswith("github.com:")) + or ("@" in repo and ":" in repo and repo.count("@") == 1) ) - + @field_validator("path") @classmethod def validate_path(cls, path: str) -> str: @@ -151,7 +158,7 @@ def validate_path(cls, path: str) -> str: if not stripped_path: raise ValueError(invalid_path) return stripped_path - + @field_validator("branch") @classmethod def validate_branch(cls, branch: str) -> Optional[str]: @@ -162,6 +169,7 @@ def validate_branch(cls, branch: str) -> Optional[str]: return None return stripped_branch + class CloneService: def __init__(self, config: CloneConfig, logger: LoggerProtocol = None, cloner: GitCloneProtocol = None): self.config = config @@ -169,21 +177,18 @@ def __init__(self, config: CloneConfig, logger: LoggerProtocol = None, cloner: G self.cloner = cloner or GitClone(self.logger) self.formatter = CloneFormatter() self.dir_manager = DirectoryManager() - + def _prepare_target_directory(self) -> bool: if self.config.force and os.path.exists(self.config.path): - return self.dir_manager.remove_directory( - self.config.path, - self.logger - ) + return self.dir_manager.remove_directory(self.config.path, self.logger) return True - + def _validate_prerequisites(self) -> bool: if self.dir_manager.path_exists_and_not_force(self.config.path, self.config.force): self.logger.error(path_already_exists_use_force.format(path=self.config.path)) return False return True - + def _create_result(self, success: bool, error: str = None) -> CloneResult: return CloneResult( repo=self.config.repo, @@ -193,41 +198,38 @@ def _create_result(self, success: bool, error: str = None) -> CloneResult: verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def clone(self) -> CloneResult: self.logger.debug(cloning_repo_into_path.format(repo=self.config.repo, path=self.config.path)) - + if not self._validate_prerequisites(): return self._create_result(False, prerequisites_validation_failed) - + if not self._prepare_target_directory(): return self._create_result(False, failed_to_prepare_target_directory) - - success, error = self.cloner.clone_repository( - self.config.repo, - self.config.path, - self.config.branch - ) - + + success, error = self.cloner.clone_repository(self.config.repo, self.config.path, self.config.branch) + return self._create_result(success, error) - + def clone_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.clone() return self.formatter.format_output(result, self.config.output) + class Clone: def __init__(self, logger: LoggerProtocol = None): self.logger = logger self.formatter = CloneFormatter() - + def clone(self, config: CloneConfig) -> CloneResult: service = CloneService(config, logger=self.logger) return service.clone() - + def format_output(self, result: CloneResult, output: str) -> str: return self.formatter.format_output(result, output) diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index 8620376b..b0f38032 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -1,13 +1,13 @@ import typer -from .run import Install + +from app.utils.logger import Logger + from .clone import Clone, CloneConfig +from .run import Install from .ssh import SSH, SSHConfig -from app.utils.logger import Logger -install_app = typer.Typer( - help="Install Nixopus", - invoke_without_command=True -) +install_app = typer.Typer(help="Install Nixopus", invoke_without_command=True) + @install_app.callback() def install_callback(ctx: typer.Context): @@ -16,12 +16,14 @@ def install_callback(ctx: typer.Context): install = Install() install.run() + def main_install_callback(value: bool): if value: install = Install() install.run() raise typer.Exit() + @install_app.command() def clone( repo: str = typer.Option("https://github.com/raghavyuva/nixopus", "--repo", "-r", help="The repository to clone"), @@ -35,15 +37,7 @@ def clone( """Clone a repository""" try: logger = Logger(verbose=verbose) - config = CloneConfig( - repo=repo, - branch=branch, - path=path, - force=force, - verbose=verbose, - output=output, - dry_run=dry_run - ) + config = CloneConfig(repo=repo, branch=branch, path=path, force=force, verbose=verbose, output=output, dry_run=dry_run) clone_operation = Clone(logger=logger) result = clone_operation.clone(config) logger.success(result.output) @@ -51,6 +45,7 @@ def clone( logger.error(e) raise typer.Exit(1) + def ssh( path: str = typer.Option("~/.ssh/nixopus_ed25519", "--path", "-p", help="The SSH key path to generate"), key_type: str = typer.Option("ed25519", "--key-type", "-t", help="The SSH key type (rsa, ed25519, ecdsa)"), @@ -61,8 +56,12 @@ def ssh( dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), force: bool = typer.Option(False, "--force", "-f", help="Force overwrite existing SSH key"), set_permissions: bool = typer.Option(True, "--set-permissions", "-S", help="Set proper file permissions"), - add_to_authorized_keys: bool = typer.Option(False, "--add-to-authorized-keys", "-a", help="Add public key to authorized_keys"), - create_ssh_directory: bool = typer.Option(True, "--create-ssh-directory", "-c", help="Create .ssh directory if it doesn't exist"), + add_to_authorized_keys: bool = typer.Option( + False, "--add-to-authorized-keys", "-a", help="Add public key to authorized_keys" + ), + create_ssh_directory: bool = typer.Option( + True, "--create-ssh-directory", "-c", help="Create .ssh directory if it doesn't exist" + ), ): """Generate an SSH key pair with proper permissions and optional authorized_keys integration""" try: @@ -78,7 +77,7 @@ def ssh( force=force, set_permissions=set_permissions, add_to_authorized_keys=add_to_authorized_keys, - create_ssh_directory=create_ssh_directory + create_ssh_directory=create_ssh_directory, ) ssh_operation = SSH(logger=logger) result = ssh_operation.generate(config) diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py index 1f41b872..94bf02e9 100644 --- a/cli/app/commands/install/run.py +++ b/cli/app/commands/install/run.py @@ -1,6 +1,8 @@ from app.utils.protocols import LoggerProtocol + from .messages import installing_nixopus + class Install: def __init__(self, logger: LoggerProtocol): self.logger = logger diff --git a/cli/app/commands/install/ssh.py b/cli/app/commands/install/ssh.py index a89ad1d9..a78e61d2 100644 --- a/cli/app/commands/install/ssh.py +++ b/cli/app/commands/install/ssh.py @@ -1,61 +1,67 @@ -import subprocess import os -from typing import Protocol, Optional -from pydantic import BaseModel, Field, field_validator import stat +import subprocess +from typing import Optional, Protocol + +from pydantic import BaseModel, Field, field_validator -from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.lib import FileManager +from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter +from app.utils.protocols import LoggerProtocol + from .messages import ( - executing_ssh_keygen, - successfully_generated_ssh_key, - ssh_keygen_failed, - unexpected_error_during_ssh_keygen, - dry_run_mode, - dry_run_command_would_be_executed, + adding_to_authorized_keys, + authorized_keys_updated, dry_run_command, - dry_run_ssh_key, - dry_run_passphrase, + dry_run_command_would_be_executed, dry_run_force_mode, + dry_run_mode, + dry_run_passphrase, + dry_run_ssh_key, end_dry_run, + executing_ssh_keygen, + failed_to_add_to_authorized_keys, + failed_to_append_to_authorized_keys, + failed_to_read_public_key, generating_ssh_key, + invalid_key_size, + invalid_key_type, invalid_ssh_key_path, prerequisites_validation_failed, - invalid_key_type, - invalid_key_size, - adding_to_authorized_keys, - authorized_keys_updated, ssh_key_already_exists, - failed_to_read_public_key, - failed_to_append_to_authorized_keys, - failed_to_add_to_authorized_keys, - unknown_error + ssh_keygen_failed, + successfully_generated_ssh_key, + unexpected_error_during_ssh_keygen, + unknown_error, ) + class SSHKeyProtocol(Protocol): - def generate_ssh_key(self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> tuple[bool, str]: - ... + def generate_ssh_key( + self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None + ) -> tuple[bool, str]: ... + class SSHCommandBuilder: @staticmethod def build_ssh_keygen_command(path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> list[str]: cmd = ["ssh-keygen", "-t", key_type, "-f", path, "-N"] - + if key_type in ["rsa", "dsa", "ecdsa"]: cmd.extend(["-b", str(key_size)]) - + if passphrase: cmd.append(passphrase) else: cmd.append("") return cmd + class SSHFormatter: def __init__(self): self.output_formatter = OutputFormatter() - + def format_output(self, result: "SSHResult", output: str) -> str: if result.success: message = successfully_generated_ssh_key.format(key=result.path) @@ -63,16 +69,16 @@ def format_output(self, result: "SSHResult", output: str) -> str: else: error = result.error or unknown_error output_message = self.output_formatter.create_error_message(error, result.model_dump()) - + return self.output_formatter.format_output(output_message, output) - + def format_dry_run(self, config: "SSHConfig") -> str: cmd = SSHCommandBuilder.build_ssh_keygen_command(config.path, config.key_type, config.key_size, config.passphrase) - + output = [] output.append(dry_run_mode) output.append(dry_run_command_would_be_executed) - output.append(dry_run_command.format(command=' '.join(cmd))) + output.append(dry_run_command.format(command=" ".join(cmd))) output.append(dry_run_ssh_key.format(key=config.path)) output.append(f"Key type: {config.key_type}") output.append(f"Key size: {config.key_size}") @@ -82,18 +88,19 @@ def format_dry_run(self, config: "SSHConfig") -> str: output.append(end_dry_run) return "\n".join(output) + class SSHKeyManager: def __init__(self, logger: LoggerProtocol): self.file_manager = FileManager() self.logger = logger - + def _check_ssh_keygen_availability(self) -> tuple[bool, str]: try: result = subprocess.run(["ssh-keygen", "-h"], capture_output=True, text=True, check=False) return result.returncode == 0, None except Exception as e: return False, f"ssh-keygen not found: {e}" - + def _check_ssh_keygen_version(self) -> tuple[bool, str]: try: result = subprocess.run(["ssh-keygen", "-V"], capture_output=True, text=True, check=False) @@ -102,18 +109,20 @@ def _check_ssh_keygen_version(self) -> tuple[bool, str]: return True, None except Exception: return True, None - - def generate_ssh_key(self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> tuple[bool, str]: + + def generate_ssh_key( + self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None + ) -> tuple[bool, str]: available, error = self._check_ssh_keygen_availability() if not available: return False, error - + self._check_ssh_keygen_version() - + cmd = SSHCommandBuilder.build_ssh_keygen_command(path, key_type, key_size, passphrase) - + try: - self.logger.info(executing_ssh_keygen.format(command=' '.join(cmd))) + self.logger.info(executing_ssh_keygen.format(command=" ".join(cmd))) result = subprocess.run(cmd, capture_output=True, text=True, check=True) self.logger.success(successfully_generated_ssh_key.format(key=path)) return True, None @@ -124,67 +133,59 @@ def generate_ssh_key(self, path: str, key_type: str = "rsa", key_size: int = 409 except Exception as e: self.logger.error(unexpected_error_during_ssh_keygen.format(error=e)) return False, str(e) - + def set_key_permissions(self, private_key_path: str, public_key_path: str) -> tuple[bool, str]: try: private_success, private_error = self.file_manager.set_permissions( - private_key_path, - stat.S_IRUSR | stat.S_IWUSR, - self.logger + private_key_path, stat.S_IRUSR | stat.S_IWUSR, self.logger ) if not private_success: return False, private_error - + public_success, public_error = self.file_manager.set_permissions( - public_key_path, - stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, - self.logger + public_key_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, self.logger ) if not public_success: return False, public_error - + return True, None except Exception as e: return False, f"Failed to set permissions: {e}" - + def create_ssh_directory(self, ssh_dir: str) -> tuple[bool, str]: try: - return self.file_manager.create_directory( - ssh_dir, - stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, - self.logger - ) + return self.file_manager.create_directory(ssh_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, self.logger) except Exception as e: return False, f"Failed to create SSH directory: {e}" - + def add_to_authorized_keys(self, public_key_path: str) -> tuple[bool, str]: try: self.logger.debug(adding_to_authorized_keys) - + success, content, error = self.file_manager.read_file_content(public_key_path, self.logger) if not success: return False, error or failed_to_read_public_key - + ssh_dir = self.file_manager.expand_user_path("~/.ssh") authorized_keys_path = os.path.join(ssh_dir, "authorized_keys") - + if not os.path.exists(ssh_dir): success, error = self.create_ssh_directory(ssh_dir) if not success: return False, error - + if not os.path.exists(authorized_keys_path): try: - with open(authorized_keys_path, 'w') as f: - pass + with open(authorized_keys_path, "w") as f: + pass os.chmod(authorized_keys_path, stat.S_IRUSR | stat.S_IWUSR) except Exception as e: return False, f"Failed to create authorized_keys file: {e}" - + success, error = self.file_manager.append_to_file(authorized_keys_path, content, self.logger) if not success: return False, error or failed_to_append_to_authorized_keys - + self.logger.debug(authorized_keys_updated) return True, None except Exception as e: @@ -192,6 +193,7 @@ def add_to_authorized_keys(self, public_key_path: str) -> tuple[bool, str]: self.logger.error(error_msg) return False, error_msg + class SSHResult(BaseModel): path: str key_type: str @@ -206,6 +208,7 @@ class SSHResult(BaseModel): add_to_authorized_keys: bool = False create_ssh_directory: bool = True + class SSHConfig(BaseModel): path: str = Field(..., min_length=1, description="SSH key path to generate") key_type: str = Field("rsa", description="SSH key type (rsa, ed25519, ecdsa)") @@ -218,26 +221,26 @@ class SSHConfig(BaseModel): set_permissions: bool = Field(True, description="Set proper file permissions") add_to_authorized_keys: bool = Field(False, description="Add public key to authorized_keys") create_ssh_directory: bool = Field(True, description="Create .ssh directory if it doesn't exist") - + @field_validator("path") @classmethod def validate_path(cls, path: str) -> str: stripped_path = path.strip() if not stripped_path: raise ValueError(invalid_ssh_key_path) - + if not cls._is_valid_key_path(stripped_path): raise ValueError(invalid_ssh_key_path) return stripped_path - + @staticmethod def _is_valid_key_path(key_path: str) -> bool: return ( - key_path.startswith(('~', '/', './')) or - os.path.isabs(key_path) or - key_path.endswith(('.pem', '.key', '_rsa', '_ed25519')) + key_path.startswith(("~", "/", "./")) + or os.path.isabs(key_path) + or key_path.endswith((".pem", ".key", "_rsa", "_ed25519")) ) - + @field_validator("key_type") @classmethod def validate_key_type(cls, key_type: str) -> str: @@ -245,12 +248,12 @@ def validate_key_type(cls, key_type: str) -> str: if key_type.lower() not in valid_types: raise ValueError(invalid_key_type) return key_type.lower() - + @field_validator("key_size") @classmethod def validate_key_size(cls, key_size: int, info) -> int: key_type = info.data.get("key_type", "rsa") - + if key_type == "ed25519": return 256 elif key_type == "ecdsa": @@ -262,9 +265,9 @@ def validate_key_size(cls, key_size: int, info) -> int: else: if key_size < 1024 or key_size > 16384: raise ValueError(invalid_key_size) - + return key_size - + @field_validator("passphrase") @classmethod def validate_passphrase(cls, passphrase: str) -> Optional[str]: @@ -275,6 +278,7 @@ def validate_passphrase(cls, passphrase: str) -> Optional[str]: return None return stripped_passphrase + class SSHService: def __init__(self, config: SSHConfig, logger: LoggerProtocol = None, ssh_manager: SSHKeyProtocol = None): self.config = config @@ -282,14 +286,14 @@ def __init__(self, config: SSHConfig, logger: LoggerProtocol = None, ssh_manager self.ssh_manager = ssh_manager or SSHKeyManager(self.logger) self.formatter = SSHFormatter() self.file_manager = FileManager() - + def _validate_prerequisites(self) -> bool: expanded_key_path = self.file_manager.expand_user_path(self.config.path) if os.path.exists(expanded_key_path) and not self.config.force: self.logger.error(ssh_key_already_exists.format(path=self.config.path)) return False return True - + def _create_result(self, success: bool, error: str = None) -> SSHResult: return SSHResult( path=self.config.path, @@ -303,63 +307,61 @@ def _create_result(self, success: bool, error: str = None) -> SSHResult: error=error, set_permissions=self.config.set_permissions, add_to_authorized_keys=self.config.add_to_authorized_keys, - create_ssh_directory=self.config.create_ssh_directory + create_ssh_directory=self.config.create_ssh_directory, ) - + def generate_ssh_key(self) -> SSHResult: self.logger.debug(generating_ssh_key.format(key=self.config.path)) - + if not self._validate_prerequisites(): return self._create_result(False, prerequisites_validation_failed) - + if self.config.dry_run: dry_run_output = self.formatter.format_dry_run(self.config) return self._create_result(True, dry_run_output) - + expanded_path = self.file_manager.expand_user_path(self.config.path) ssh_dir = self.file_manager.get_directory_path(expanded_path) - + if self.config.create_ssh_directory: success, error = self.ssh_manager.create_ssh_directory(ssh_dir) if not success: return self._create_result(False, error) - + success, error = self.ssh_manager.generate_ssh_key( - self.config.path, - self.config.key_type, - self.config.key_size, - self.config.passphrase + self.config.path, self.config.key_type, self.config.key_size, self.config.passphrase ) - + if not success: return self._create_result(False, error) - + if self.config.set_permissions: public_key_path = self.file_manager.get_public_key_path(expanded_path) success, error = self.ssh_manager.set_key_permissions(expanded_path, public_key_path) if not success: return self._create_result(False, error) - + if self.config.add_to_authorized_keys: public_key_path = self.file_manager.get_public_key_path(expanded_path) success, error = self.ssh_manager.add_to_authorized_keys(public_key_path) if not success: return self._create_result(False, error) - + return self._create_result(True) - + def generate_and_format(self) -> str: result = self.generate_ssh_key() return self.formatter.format_output(result, self.config.output) + class SSH: def __init__(self, logger: LoggerProtocol = None): self.logger = logger or Logger() - + def generate(self, config: SSHConfig) -> SSHResult: service = SSHService(config, self.logger) return service.generate_ssh_key() - + def format_output(self, result: SSHResult, output: str) -> str: formatter = SSHFormatter() return formatter.format_output(result, output) diff --git a/cli/app/commands/install/tests/test_clone.py b/cli/app/commands/install/tests/test_clone.py index 562699db..5eca6c4d 100644 --- a/cli/app/commands/install/tests/test_clone.py +++ b/cli/app/commands/install/tests/test_clone.py @@ -1,16 +1,17 @@ -import pytest import subprocess -from unittest.mock import Mock, patch, MagicMock +from unittest.mock import MagicMock, Mock, patch + +import pytest from pydantic import ValidationError from app.commands.install.clone import ( - GitCommandBuilder, + Clone, + CloneConfig, CloneFormatter, - GitClone, CloneResult, - CloneConfig, CloneService, - Clone + GitClone, + GitCommandBuilder, ) from app.utils.lib import DirectoryManager from app.utils.logger import Logger @@ -20,11 +21,11 @@ class TestGitCommandBuilder: def test_build_clone_command_without_branch(self): cmd = GitCommandBuilder.build_clone_command("https://github.com/user/repo", "/path/to/clone") assert cmd == ["git", "clone", "https://github.com/user/repo", "/path/to/clone"] - + def test_build_clone_command_with_branch(self): cmd = GitCommandBuilder.build_clone_command("https://github.com/user/repo", "/path/to/clone", "main") assert cmd == ["git", "clone", "-b", "main", "https://github.com/user/repo", "/path/to/clone"] - + def test_build_clone_command_with_empty_branch(self): cmd = GitCommandBuilder.build_clone_command("https://github.com/user/repo", "/path/to/clone", "") assert cmd == ["git", "clone", "https://github.com/user/repo", "/path/to/clone"] @@ -33,7 +34,7 @@ def test_build_clone_command_with_empty_branch(self): class TestCloneFormatter: def setup_method(self): self.formatter = CloneFormatter() - + def test_format_output_success(self): result = CloneResult( repo="https://github.com/user/repo", @@ -42,13 +43,13 @@ def test_format_output_success(self): force=False, verbose=False, output="text", - success=True + success=True, ) formatted = self.formatter.format_output(result, "text") assert "Successfully cloned" in formatted assert "https://github.com/user/repo" in formatted assert "/path/to/clone" in formatted - + def test_format_output_failure(self): result = CloneResult( repo="https://github.com/user/repo", @@ -58,11 +59,11 @@ def test_format_output_failure(self): verbose=False, output="text", success=False, - error="Repository not found" + error="Repository not found", ) formatted = self.formatter.format_output(result, "text") assert "Error: Repository not found" in formatted - + def test_format_output_json(self): result = CloneResult( repo="https://github.com/user/repo", @@ -71,14 +72,15 @@ def test_format_output_json(self): force=False, verbose=False, output="json", - success=True + success=True, ) formatted = self.formatter.format_output(result, "json") import json + data = json.loads(formatted) assert data["success"] is True assert data["message"] == "Successfully cloned https://github.com/user/repo to /path/to/clone" - + def test_format_output_invalid(self): result = CloneResult( repo="https://github.com/user/repo", @@ -87,48 +89,36 @@ def test_format_output_invalid(self): force=False, verbose=False, output="invalid", - success=True + success=True, ) with pytest.raises(ValueError): self.formatter.format_output(result, "invalid") - - @patch('os.path.exists') + + @patch("os.path.exists") def test_format_dry_run(self, mock_exists): mock_exists.return_value = False config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch="main", - force=True, - dry_run=True + repo="https://github.com/user/repo", path="/path/to/clone", branch="main", force=True, dry_run=True ) formatted = self.formatter.format_dry_run(config) assert "=== DRY RUN MODE ===" in formatted assert "git clone -b main https://github.com/user/repo /path/to/clone" in formatted assert "Force mode: True" in formatted - - @patch('os.path.exists') + + @patch("os.path.exists") def test_format_dry_run_path_exists_force(self, mock_exists): mock_exists.return_value = True config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch="main", - force=True, - dry_run=True + repo="https://github.com/user/repo", path="/path/to/clone", branch="main", force=True, dry_run=True ) formatted = self.formatter.format_dry_run(config) assert "will be overwritten" in formatted - - @patch('os.path.exists') + + @patch("os.path.exists") def test_format_dry_run_path_exists_no_force(self, mock_exists): mock_exists.return_value = True config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch="main", - force=False, - dry_run=True + repo="https://github.com/user/repo", path="/path/to/clone", branch="main", force=False, dry_run=True ) formatted = self.formatter.format_dry_run(config) assert "would fail without --force" in formatted @@ -138,46 +128,46 @@ class TestGitClone: def setup_method(self): self.logger = Mock(spec=Logger) self.git_clone = GitClone(self.logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_clone_repository_success(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone", "main") - + assert success is True assert error is None self.logger.info.assert_called_once() self.logger.success.assert_called_once() - - @patch('subprocess.run') + + @patch("subprocess.run") def test_clone_repository_without_branch(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["git", "clone", "https://github.com/user/repo", "/path/to/clone"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_clone_repository_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "git clone", stderr="Repository not found") - + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone") - + assert success is False assert error == "Repository not found" self.logger.error.assert_called_once() - - @patch('subprocess.run') + + @patch("subprocess.run") def test_clone_repository_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") - + success, error = self.git_clone.clone_repository("https://github.com/user/repo", "/path/to/clone") - + assert success is False assert error == "Unexpected error" self.logger.error.assert_called_once() @@ -185,11 +175,7 @@ def test_clone_repository_unexpected_error(self, mock_run): class TestCloneConfig: def test_valid_config(self): - config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch="main" - ) + config = CloneConfig(repo="https://github.com/user/repo", path="/path/to/clone", branch="main") assert config.repo == "https://github.com/user/repo" assert config.path == "/path/to/clone" assert config.branch == "main" @@ -197,7 +183,7 @@ def test_valid_config(self): assert config.verbose is False assert config.output == "text" assert config.dry_run is False - + def test_valid_repo_formats(self): valid_repos = [ "https://github.com/user/repo", @@ -205,57 +191,45 @@ def test_valid_repo_formats(self): "git://github.com/user/repo", "ssh://github.com/user/repo", "git@github.com:user/repo.git", - "https://github.com/user/repo.git" + "https://github.com/user/repo.git", ] - + for repo in valid_repos: config = CloneConfig(repo=repo, path="/path/to/clone") assert config.repo == repo - + def test_invalid_repo_formats(self): - invalid_repos = [ - "", - " ", - "github.com:user/repo", - "invalid://github.com/user/repo" - ] - + invalid_repos = ["", " ", "github.com:user/repo", "invalid://github.com/user/repo"] + for repo in invalid_repos: with pytest.raises(ValidationError): CloneConfig(repo=repo, path="/path/to/clone") - + def test_empty_repo(self): with pytest.raises(ValidationError): CloneConfig(repo="", path="/path/to/clone") - + def test_empty_path(self): with pytest.raises(ValidationError): CloneConfig(repo="https://github.com/user/repo", path="") - + def test_branch_validation(self): - config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch=" " - ) + config = CloneConfig(repo="https://github.com/user/repo", path="/path/to/clone", branch=" ") assert config.branch is None - + def test_is_valid_repo_format(self): valid_repos = [ "https://github.com/user/repo", "http://github.com/user/repo", "git@github.com:user/repo.git", - "https://github.com/user/repo.git" + "https://github.com/user/repo.git", ] - + for repo in valid_repos: assert CloneConfig._is_valid_repo_format(repo) is True - - invalid_repos = [ - "github.com:user/repo", - "invalid://github.com/user/repo" - ] - + + invalid_repos = ["github.com:user/repo", "invalid://github.com/user/repo"] + for repo in invalid_repos: assert CloneConfig._is_valid_repo_format(repo) is False @@ -263,93 +237,89 @@ def test_is_valid_repo_format(self): class TestDirectoryManager: def setup_method(self): self.logger = Mock(spec=Logger) - - @patch('shutil.rmtree') + + @patch("shutil.rmtree") def test_remove_directory_success(self, mock_rmtree): success = DirectoryManager.remove_directory("/path/to/remove", self.logger) - + assert success is True mock_rmtree.assert_called_once_with("/path/to/remove") self.logger.info.assert_called_once() - - @patch('shutil.rmtree') + + @patch("shutil.rmtree") def test_remove_directory_failure(self, mock_rmtree): mock_rmtree.side_effect = Exception("Permission denied") - + success = DirectoryManager.remove_directory("/path/to/remove", self.logger) - + assert success is False self.logger.error.assert_called_once() - - @patch('os.path.exists') + + @patch("os.path.exists") def test_path_exists_and_not_force_true(self, mock_exists): mock_exists.return_value = True - + result = DirectoryManager.path_exists_and_not_force("/path/to/check", False) - + assert result is True - - @patch('os.path.exists') + + @patch("os.path.exists") def test_path_exists_and_not_force_false_when_force(self, mock_exists): mock_exists.return_value = True - + result = DirectoryManager.path_exists_and_not_force("/path/to/check", True) - + assert result is False - - @patch('os.path.exists') + + @patch("os.path.exists") def test_path_exists_and_not_force_false_when_not_exists(self, mock_exists): mock_exists.return_value = False - + result = DirectoryManager.path_exists_and_not_force("/path/to/check", False) - + assert result is False class TestCloneService: def setup_method(self): - self.config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch="main" - ) + self.config = CloneConfig(repo="https://github.com/user/repo", path="/path/to/clone", branch="main") self.logger = Mock(spec=Logger) self.cloner = Mock(spec=GitClone) self.service = CloneService(self.config, self.logger, self.cloner) - + def test_create_result_success(self): result = self.service._create_result(True) - + assert result.repo == self.config.repo assert result.path == self.config.path assert result.branch == self.config.branch assert result.success is True assert result.error is None - + def test_create_result_failure(self): result = self.service._create_result(False, "Test error") - + assert result.success is False assert result.error == "Test error" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_prerequisites_success(self, mock_exists): mock_exists.return_value = False - + result = self.service._validate_prerequisites() - + assert result is True - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_prerequisites_path_exists_no_force(self, mock_exists): mock_exists.return_value = True - + result = self.service._validate_prerequisites() - + assert result is False self.logger.error.assert_called_once() - - @patch('os.path.exists') + + @patch("os.path.exists") def test_prepare_target_directory_force_success(self, mock_exists): self.service.config.force = True mock_exists.return_value = True @@ -360,7 +330,7 @@ def test_prepare_target_directory_force_success(self, mock_exists): assert result is True self.service.dir_manager.remove_directory.assert_called_once_with(self.config.path, self.logger) - @patch('os.path.exists') + @patch("os.path.exists") def test_prepare_target_directory_force_failure(self, mock_exists): self.service.config.force = True mock_exists.return_value = True @@ -370,39 +340,35 @@ def test_prepare_target_directory_force_failure(self, mock_exists): assert result is False self.service.dir_manager.remove_directory.assert_called_once_with(self.config.path, self.logger) - + def test_clone_success(self): self.cloner.clone_repository.return_value = (True, None) - + result = self.service.clone() - + assert result.success is True - self.cloner.clone_repository.assert_called_once_with( - self.config.repo, - self.config.path, - self.config.branch - ) - + self.cloner.clone_repository.assert_called_once_with(self.config.repo, self.config.path, self.config.branch) + def test_clone_failure(self): self.cloner.clone_repository.return_value = (False, "Test error") - + result = self.service.clone() - + assert result.success is False assert result.error == "Test error" - + def test_clone_and_format_dry_run(self): self.config.dry_run = True - + result = self.service.clone_and_format() - + assert "=== DRY RUN MODE ===" in result - + def test_clone_and_format_success(self): self.cloner.clone_repository.return_value = (True, None) - + result = self.service.clone_and_format() - + assert "Successfully cloned" in result @@ -410,15 +376,11 @@ class TestClone: def setup_method(self): self.logger = Mock(spec=Logger) self.clone = Clone(self.logger) - + def test_clone_success(self): - config = CloneConfig( - repo="https://github.com/user/repo", - path="/path/to/clone", - branch="main" - ) - - with patch.object(CloneService, 'clone') as mock_clone: + config = CloneConfig(repo="https://github.com/user/repo", path="/path/to/clone", branch="main") + + with patch.object(CloneService, "clone") as mock_clone: mock_result = CloneResult( repo=config.repo, path=config.path, @@ -426,14 +388,14 @@ def test_clone_success(self): force=config.force, verbose=config.verbose, output=config.output, - success=True + success=True, ) mock_clone.return_value = mock_result - + result = self.clone.clone(config) - + assert result.success is True - + def test_format_output(self): result = CloneResult( repo="https://github.com/user/repo", @@ -442,9 +404,9 @@ def test_format_output(self): force=False, verbose=False, output="text", - success=True + success=True, ) - + formatted = self.clone.format_output(result, "text") - - assert "Successfully cloned" in formatted + + assert "Successfully cloned" in formatted diff --git a/cli/app/commands/install/tests/test_ssh.py b/cli/app/commands/install/tests/test_ssh.py index 2c04c0a5..bbad4786 100644 --- a/cli/app/commands/install/tests/test_ssh.py +++ b/cli/app/commands/install/tests/test_ssh.py @@ -1,261 +1,234 @@ -import unittest -from unittest.mock import Mock, patch, MagicMock -import tempfile import os -from app.commands.install.ssh import SSH, SSHConfig, SSHKeyManager, SSHCommandBuilder +import tempfile +import unittest +from unittest.mock import MagicMock, Mock, patch + +from app.commands.install.ssh import SSH, SSHCommandBuilder, SSHConfig, SSHKeyManager + class TestSSHKeyGeneration(unittest.TestCase): def setUp(self): self.mock_logger = Mock() self.temp_dir = tempfile.mkdtemp() self.test_key_path = os.path.join(self.temp_dir, "test_key") - + def tearDown(self): import shutil + shutil.rmtree(self.temp_dir) - + def test_ssh_command_builder_rsa(self): - cmd = SSHCommandBuilder.build_ssh_keygen_command( - self.test_key_path, "rsa", 4096, "testpass" - ) + cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "rsa", 4096, "testpass") expected = ["ssh-keygen", "-t", "rsa", "-f", self.test_key_path, "-N", "-b", "4096", "testpass"] self.assertEqual(cmd, expected) - + def test_ssh_command_builder_ed25519_no_passphrase(self): - cmd = SSHCommandBuilder.build_ssh_keygen_command( - self.test_key_path, "ed25519", 256 - ) + cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "ed25519", 256) expected = ["ssh-keygen", "-t", "ed25519", "-f", self.test_key_path, "-N", ""] self.assertEqual(cmd, expected) - + def test_ssh_command_builder_ecdsa(self): - cmd = SSHCommandBuilder.build_ssh_keygen_command( - self.test_key_path, "ecdsa", 256 - ) + cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "ecdsa", 256) expected = ["ssh-keygen", "-t", "ecdsa", "-f", self.test_key_path, "-N", "-b", "256", ""] self.assertEqual(cmd, expected) - + def test_ssh_command_builder_dsa(self): - cmd = SSHCommandBuilder.build_ssh_keygen_command( - self.test_key_path, "dsa", 1024 - ) + cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "dsa", 1024) expected = ["ssh-keygen", "-t", "dsa", "-f", self.test_key_path, "-N", "-b", "1024", ""] self.assertEqual(cmd, expected) - + def test_ssh_config_validation_valid_key_type(self): - config = SSHConfig( - path=self.test_key_path, - key_type="ed25519", - key_size=256 - ) + config = SSHConfig(path=self.test_key_path, key_type="ed25519", key_size=256) self.assertEqual(config.key_type, "ed25519") - + def test_ssh_config_validation_invalid_key_type(self): with self.assertRaises(ValueError): - SSHConfig( - path=self.test_key_path, - key_type="invalid_type", - key_size=256 - ) - + SSHConfig(path=self.test_key_path, key_type="invalid_type", key_size=256) + def test_ssh_config_validation_valid_key_size(self): - config = SSHConfig( - path=self.test_key_path, - key_type="rsa", - key_size=4096 - ) + config = SSHConfig(path=self.test_key_path, key_type="rsa", key_size=4096) self.assertEqual(config.key_size, 4096) - + def test_ssh_config_validation_invalid_key_size(self): with self.assertRaises(ValueError): - SSHConfig( - path=self.test_key_path, - key_type="rsa", - key_size=512 - ) - + SSHConfig(path=self.test_key_path, key_type="rsa", key_size=512) + def test_ssh_config_ed25519_key_size_always_256(self): - config = SSHConfig( - path=self.test_key_path, - key_type="ed25519", - key_size=512 - ) + config = SSHConfig(path=self.test_key_path, key_type="ed25519", key_size=512) self.assertEqual(config.key_size, 256) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_availability_check_success(self, mock_run): mock_result = Mock() mock_result.returncode = 0 mock_run.return_value = mock_result - + manager = SSHKeyManager(self.mock_logger) available, error = manager._check_ssh_keygen_availability() - + self.assertTrue(available) self.assertIsNone(error) mock_run.assert_called_once_with(["ssh-keygen", "-h"], capture_output=True, text=True, check=False) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_availability_check_failure(self, mock_run): mock_result = Mock() mock_result.returncode = 1 mock_run.return_value = mock_result - + manager = SSHKeyManager(self.mock_logger) available, error = manager._check_ssh_keygen_availability() - + self.assertFalse(available) self.assertIsNone(error) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_version_check(self, mock_run): mock_result = Mock() mock_result.returncode = 0 mock_result.stdout = "OpenSSH_8.9p1" mock_run.return_value = mock_result - + manager = SSHKeyManager(self.mock_logger) success, error = manager._check_ssh_keygen_version() - + self.assertTrue(success) self.assertIsNone(error) self.mock_logger.debug.assert_called_with("SSH keygen version: OpenSSH_8.9p1") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_success(self, mock_run): mock_avail_result = Mock() mock_avail_result.returncode = 0 - + mock_version_result = Mock() mock_version_result.returncode = 0 mock_version_result.stdout = "OpenSSH_8.9p1" - + mock_gen_result = Mock() mock_gen_result.returncode = 0 - + mock_run.side_effect = [mock_avail_result, mock_version_result, mock_gen_result] - + manager = SSHKeyManager(self.mock_logger) success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) - + self.assertTrue(success) self.assertIsNone(error) self.assertEqual(mock_run.call_count, 3) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_failure(self, mock_run): from subprocess import CalledProcessError - + mock_avail_result = Mock() mock_avail_result.returncode = 0 - + mock_version_result = Mock() mock_version_result.returncode = 0 - mock_run.side_effect = [mock_avail_result, mock_version_result, CalledProcessError(1, "ssh-keygen", stderr="Permission denied")] - + mock_run.side_effect = [ + mock_avail_result, + mock_version_result, + CalledProcessError(1, "ssh-keygen", stderr="Permission denied"), + ] + manager = SSHKeyManager(self.mock_logger) success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) - + self.assertFalse(success) self.assertEqual(error, "Permission denied") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_availability_failure(self, mock_run): mock_result = Mock() mock_result.returncode = 1 mock_run.return_value = mock_result - + manager = SSHKeyManager(self.mock_logger) success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) - + self.assertFalse(success) self.assertIsNone(error) - + def test_ssh_service_dry_run(self): - config = SSHConfig( - path=self.test_key_path, - key_type="ed25519", - key_size=256, - dry_run=True - ) - + config = SSHConfig(path=self.test_key_path, key_type="ed25519", key_size=256, dry_run=True) + ssh = SSH(self.mock_logger) result = ssh.generate(config) - + self.assertTrue(result.success) self.assertIsNotNone(result.error) self.assertIn("DRY RUN MODE", result.error) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_service_force_overwrite(self, mock_run): from subprocess import CalledProcessError - - with open(self.test_key_path, 'w') as f: + + with open(self.test_key_path, "w") as f: f.write("existing key") - + mock_avail_result = Mock() mock_avail_result.returncode = 0 - + mock_version_result = Mock() mock_version_result.returncode = 0 - - mock_run.side_effect = [mock_avail_result, mock_version_result, CalledProcessError(1, "ssh-keygen", stderr="ssh-keygen failed")] - - config = SSHConfig( - path=self.test_key_path, - key_type="ed25519", - key_size=256, - force=True - ) - + + mock_run.side_effect = [ + mock_avail_result, + mock_version_result, + CalledProcessError(1, "ssh-keygen", stderr="ssh-keygen failed"), + ] + + config = SSHConfig(path=self.test_key_path, key_type="ed25519", key_size=256, force=True) + ssh = SSH(self.mock_logger) result = ssh.generate(config) - + self.assertFalse(result.success) self.assertIn("ssh-keygen", result.error) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_ssh_key_manager_with_permissions(self, mock_run): mock_result = Mock() mock_result.returncode = 0 mock_run.return_value = mock_result - + manager = SSHKeyManager(self.mock_logger) - - with open(self.test_key_path, 'w') as f: + + with open(self.test_key_path, "w") as f: f.write("private key content") - - with open(f"{self.test_key_path}.pub", 'w') as f: + + with open(f"{self.test_key_path}.pub", "w") as f: f.write("public key content") - + success, error = manager.set_key_permissions(self.test_key_path, f"{self.test_key_path}.pub") - + self.assertTrue(success) self.assertIsNone(error) - + def test_ssh_key_manager_create_ssh_directory(self): manager = SSHKeyManager(self.mock_logger) test_ssh_dir = os.path.join(self.temp_dir, "test_ssh") - + success, error = manager.create_ssh_directory(test_ssh_dir) - + self.assertTrue(success) self.assertIsNone(error) self.assertTrue(os.path.exists(test_ssh_dir)) - - @patch('builtins.open', create=True) + + @patch("builtins.open", create=True) def test_ssh_key_manager_add_to_authorized_keys(self, mock_open): manager = SSHKeyManager(self.mock_logger) - + public_key_path = f"{self.test_key_path}.pub" - with open(public_key_path, 'w') as f: + with open(public_key_path, "w") as f: f.write("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... test@example.com") - + success, error = manager.add_to_authorized_keys(public_key_path) - + self.assertTrue(success) self.assertIsNone(error) - + def test_ssh_config_with_new_options(self): config = SSHConfig( path=self.test_key_path, @@ -263,37 +236,26 @@ def test_ssh_config_with_new_options(self): key_size=256, set_permissions=True, add_to_authorized_keys=True, - create_ssh_directory=True + create_ssh_directory=True, ) - + self.assertTrue(config.set_permissions) self.assertTrue(config.add_to_authorized_keys) self.assertTrue(config.create_ssh_directory) - + def test_ssh_config_ed25519_key_size_validation(self): - config = SSHConfig( - path=self.test_key_path, - key_type="ed25519", - key_size=512 - ) + config = SSHConfig(path=self.test_key_path, key_type="ed25519", key_size=512) self.assertEqual(config.key_size, 256) - + def test_ssh_config_ecdsa_key_size_validation(self): valid_sizes = [256, 384, 521] for size in valid_sizes: - config = SSHConfig( - path=self.test_key_path, - key_type="ecdsa", - key_size=size - ) + config = SSHConfig(path=self.test_key_path, key_type="ecdsa", key_size=size) self.assertEqual(config.key_size, size) - + with self.assertRaises(ValueError): - SSHConfig( - path=self.test_key_path, - key_type="ecdsa", - key_size=512 - ) - -if __name__ == '__main__': - unittest.main() + SSHConfig(path=self.test_key_path, key_type="ecdsa", key_size=512) + + +if __name__ == "__main__": + unittest.main() diff --git a/cli/app/commands/preflight/command.py b/cli/app/commands/preflight/command.py index 94d9b55c..2d4db61f 100644 --- a/cli/app/commands/preflight/command.py +++ b/cli/app/commands/preflight/command.py @@ -1,18 +1,22 @@ import typer -from .messages import error_checking_deps, error_checking_ports -from .port import PortConfig, PortService -from .deps import Deps, DepsConfig + from app.utils.lib import HostInformation from app.utils.logger import Logger +from .deps import Deps, DepsConfig +from .messages import error_checking_deps, error_checking_ports +from .port import PortConfig, PortService + preflight_app = typer.Typer(no_args_is_help=False) + @preflight_app.callback(invoke_without_command=True) def preflight_callback(ctx: typer.Context): """Preflight checks for system compatibility""" if ctx.invoked_subcommand is None: ctx.invoke(check) + @preflight_app.command() def check( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), @@ -21,6 +25,7 @@ def check( """Run all preflight checks""" pass + @preflight_app.command() def ports( ports: list[int] = typer.Argument(..., help="The list of ports to check"), @@ -41,7 +46,8 @@ def ports( logger.error(error_checking_ports.format(error=e)) raise typer.Exit(1) -@preflight_app.command() + +@preflight_app.command() def deps( deps: list[str] = typer.Argument(..., help="The list of dependencies to check"), timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each dependency check"), @@ -50,14 +56,14 @@ def deps( ) -> None: """Check if list of dependencies are available on the system""" try: - logger = Logger(verbose=verbose) + logger = Logger(verbose=verbose) config = DepsConfig( deps=deps, timeout=timeout, verbose=verbose, output=output, os=HostInformation.get_os_name(), - package_manager=HostInformation.get_package_manager() + package_manager=HostInformation.get_package_manager(), ) deps_checker = Deps(logger=logger) results = deps_checker.check(config) diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py index 938f051e..b7fbdb90 100644 --- a/cli/app/commands/preflight/deps.py +++ b/cli/app/commands/preflight/deps.py @@ -1,33 +1,32 @@ import subprocess -from typing import Protocol, Optional +from typing import Optional, Protocol + from pydantic import BaseModel, Field, field_validator -from app.utils.lib import Supported, ParallelProcessor + +from app.utils.lib import ParallelProcessor, Supported from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter -from .messages import invalid_os, invalid_package_manager, error_checking_dependency, timeout_checking_dependency +from app.utils.protocols import LoggerProtocol + +from .messages import error_checking_dependency, invalid_os, invalid_package_manager, timeout_checking_dependency + class DependencyCheckerProtocol(Protocol): - def check_dependency(self, dep: str) -> bool: - ... + def check_dependency(self, dep: str) -> bool: ... + class DependencyChecker: def __init__(self, timeout: int, logger: LoggerProtocol): self.timeout = timeout self.logger = logger - + def check_dependency(self, dep: str) -> bool: self.logger.debug(f"Checking dependency: {dep}") - + try: - result = subprocess.run( - ["command", "-v", dep], - capture_output=True, - text=True, - timeout=self.timeout - ) + result = subprocess.run(["command", "-v", dep], capture_output=True, text=True, timeout=self.timeout) return result.returncode == 0 - + except subprocess.TimeoutExpired: self.logger.error(timeout_checking_dependency.format(dep=dep)) return False @@ -35,28 +34,29 @@ def check_dependency(self, dep: str) -> bool: self.logger.error(error_checking_dependency.format(dep=dep, error=e)) return False + class DependencyValidator: def validate_os(self, os: str) -> str: if not Supported.os(os): raise ValueError(invalid_os.format(os=os)) return os - + def validate_package_manager(self, package_manager: str) -> str: if not Supported.package_manager(package_manager): raise ValueError(invalid_package_manager.format(package_manager=package_manager)) return package_manager + class DependencyFormatter: def __init__(self): self.output_formatter = OutputFormatter() - + def format_output(self, results: list["DepsCheckResult"], output: str) -> str: if not results: return self.output_formatter.format_output( - self.output_formatter.create_success_message("No dependencies to check"), - output + self.output_formatter.create_success_message("No dependencies to check"), output ) - + messages = [] for result in results: if result.is_available: @@ -65,11 +65,12 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: else: error = f"{result.dependency} is not available" messages.append(self.output_formatter.create_error_message(error, result.model_dump())) - + return self.output_formatter.format_output(messages, output) + class DepsCheckResult(BaseModel): - dependency:str + dependency: str timeout: int verbose: bool output: str @@ -78,6 +79,7 @@ class DepsCheckResult(BaseModel): is_available: bool = False error: Optional[str] = None + class DepsConfig(BaseModel): deps: list[str] = Field(..., min_length=1, description="The list of dependencies to check") timeout: int = Field(1, gt=0, le=60, description="The timeout in seconds") @@ -85,26 +87,27 @@ class DepsConfig(BaseModel): output: str = Field("text", description="Output format, text, json") os: str = Field(..., description=f"The operating system to check, available: {Supported.get_os()}") package_manager: str = Field(..., description="The package manager to use") - + @field_validator("os") @classmethod def validate_os(cls, os: str) -> str: validator = DependencyValidator() return validator.validate_os(os) - + @field_validator("package_manager") @classmethod def validate_package_manager(cls, package_manager: str) -> str: validator = DependencyValidator() return validator.validate_package_manager(package_manager) + class DepsService: def __init__(self, config: DepsConfig, logger: LoggerProtocol = None, checker: DependencyCheckerProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) self.checker = checker or DependencyChecker(config.timeout, self.logger) self.formatter = DependencyFormatter() - + def _create_result(self, dep: str, is_available: bool, error: str = None) -> DepsCheckResult: return DepsCheckResult( dependency=dep, @@ -114,49 +117,49 @@ def _create_result(self, dep: str, is_available: bool, error: str = None) -> Dep os=self.config.os, package_manager=self.config.package_manager, is_available=is_available, - error=error + error=error, ) - + def _check_dependency(self, dep: str) -> DepsCheckResult: try: is_available = self.checker.check_dependency(dep) return self._create_result(dep, is_available) except Exception as e: return self._create_result(dep, False, str(e)) - + def check_dependencies(self) -> list[DepsCheckResult]: self.logger.debug(f"Checking dependencies: {self.config.deps}") - + def process_dep(dep: str) -> DepsCheckResult: return self._check_dependency(dep) - + def error_handler(dep: str, error: Exception) -> DepsCheckResult: self.logger.error(error_checking_dependency.format(dep=dep, error=error)) return self._create_result(dep, False, str(error)) - + results = ParallelProcessor.process_items( items=self.config.deps, processor_func=process_dep, max_workers=min(len(self.config.deps), 50), - error_handler=error_handler + error_handler=error_handler, ) - + return results - + def check_and_format(self) -> str: results = self.check_dependencies() return self.formatter.format_output(results, self.config.output) + class Deps: def __init__(self, logger: LoggerProtocol = None): self.logger = logger self.validator = DependencyValidator() self.formatter = DependencyFormatter() - + def check(self, config: DepsConfig) -> list[DepsCheckResult]: service = DepsService(config, logger=self.logger) return service.check_dependencies() def format_output(self, results: list[DepsCheckResult], output: str) -> str: return self.formatter.format_output(results, output) - \ No newline at end of file diff --git a/cli/app/commands/preflight/port.py b/cli/app/commands/preflight/port.py index c2436c06..cdecd57e 100644 --- a/cli/app/commands/preflight/port.py +++ b/cli/app/commands/preflight/port.py @@ -1,15 +1,20 @@ -import re, socket -from typing import List, TypedDict, Union, Any, Optional, Protocol +import re +import socket +from typing import Any, List, Optional, Protocol, TypedDict, Union + from pydantic import BaseModel, Field, field_validator -from .messages import available, not_available, error_checking_port, host_must_be_localhost_or_valid_ip_or_domain -from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol + from app.utils.lib import ParallelProcessor +from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter +from app.utils.protocols import LoggerProtocol + +from .messages import available, error_checking_port, host_must_be_localhost_or_valid_ip_or_domain, not_available + class PortCheckerProtocol(Protocol): - def check_port(self, port: int, config: "PortConfig") -> "PortCheckResult": - ... + def check_port(self, port: int, config: "PortConfig") -> "PortCheckResult": ... + class PortCheckResult(TypedDict): port: int @@ -18,34 +23,36 @@ class PortCheckResult(TypedDict): error: Optional[str] is_available: bool + class PortConfig(BaseModel): ports: List[int] = Field(..., min_length=1, max_length=65535, description="List of ports to check") host: str = Field("localhost", min_length=1, description="Host to check") timeout: int = Field(1, gt=0, le=60, description="Timeout in seconds") verbose: bool = Field(False, description="Verbose output") - @field_validator('host') + @field_validator("host") @classmethod def validate_host(cls, v: str) -> str: if v.lower() == "localhost": return v - ip_pattern = r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$' + ip_pattern = r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" if re.match(ip_pattern, v): return v - domain_pattern = r'^[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*$' + domain_pattern = r"^[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)*$" if re.match(domain_pattern, v): return v raise ValueError(host_must_be_localhost_or_valid_ip_or_domain) + class PortFormatter: def __init__(self): self.output_formatter = OutputFormatter() - + def format_output(self, data: Union[str, List[PortCheckResult], Any], output_type: str) -> str: if isinstance(data, list): messages = [] for item in data: - if item.get('is_available', False): + if item.get("is_available", False): message = f"Port {item['port']}: {item['status']}" messages.append(self.output_formatter.create_success_message(message, item)) else: @@ -55,11 +62,12 @@ def format_output(self, data: Union[str, List[PortCheckResult], Any], output_typ else: return str(data) + class PortChecker: def __init__(self, logger: LoggerProtocol, timeout: int): self.logger = logger self.timeout = timeout - + def is_port_available(self, host: str, port: int) -> bool: try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: @@ -68,7 +76,7 @@ def is_port_available(self, host: str, port: int) -> bool: return result != 0 except Exception: return False - + def check_port(self, port: int, config: PortConfig) -> PortCheckResult: self.logger.debug(f"Checking port {port} on host {config.host}") try: @@ -77,38 +85,42 @@ def check_port(self, port: int, config: PortConfig) -> PortCheckResult: except Exception as e: self.logger.error(error_checking_port.format(port=port, error=str(e))) return self._create_result(port, config, not_available, str(e)) - + def _create_result(self, port: int, config: PortConfig, status: str, error: Optional[str] = None) -> PortCheckResult: return { "port": port, "status": status, "host": config.host if config.verbose else None, "error": error, - "is_available": status == available + "is_available": status == available, } + class PortService: def __init__(self, config: PortConfig, logger: LoggerProtocol = None, checker: PortCheckerProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) self.checker = checker or PortChecker(self.logger, config.timeout) self.formatter = PortFormatter() - + def check_ports(self) -> List[PortCheckResult]: self.logger.debug(f"Checking ports: {self.config.ports}") + def process_port(port: int) -> PortCheckResult: return self.checker.check_port(port, self.config) + def error_handler(port: int, error: Exception) -> PortCheckResult: self.logger.error(error_checking_port.format(port=port, error=str(error))) return self.checker._create_result(port, self.config, not_available, str(error)) + results = ParallelProcessor.process_items( items=self.config.ports, processor_func=process_port, max_workers=min(len(self.config.ports), 50), - error_handler=error_handler + error_handler=error_handler, ) return sorted(results, key=lambda x: x["port"]) - + def check_and_format(self, output_type: str) -> str: results = self.check_ports() return self.formatter.format_output(results, output_type) diff --git a/cli/app/commands/preflight/tests/test_deps.py b/cli/app/commands/preflight/tests/test_deps.py index d01d8f69..0c2e0cf5 100644 --- a/cli/app/commands/preflight/tests/test_deps.py +++ b/cli/app/commands/preflight/tests/test_deps.py @@ -1,17 +1,17 @@ -import unittest -from unittest.mock import Mock, patch, MagicMock -import subprocess import json +import subprocess +import unittest from typing import List +from unittest.mock import MagicMock, Mock, patch from app.commands.preflight.deps import ( DependencyChecker, - DependencyValidator, DependencyFormatter, + DependencyValidator, + Deps, DepsCheckResult, DepsConfig, DepsService, - Deps ) from app.utils.lib import Supported from app.utils.logger import Logger @@ -26,120 +26,110 @@ def __init__(self): self.warning_calls = [] self.success_calls = [] self.highlight_calls = [] - + def debug(self, message: str) -> None: self.debug_calls.append(message) - + def error(self, message: str) -> None: self.error_calls.append(message) - + def info(self, message: str) -> None: self.info_calls.append(message) - + def warning(self, message: str) -> None: self.warning_calls.append(message) - + def success(self, message: str) -> None: self.success_calls.append(message) - + def highlight(self, message: str) -> None: self.highlight_calls.append(message) class TestDependencyChecker(unittest.TestCase): - + def setUp(self): self.mock_logger = MockLogger() self.checker = DependencyChecker(timeout=5, logger=self.mock_logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_check_dependency_available(self, mock_run): mock_result = Mock() mock_result.returncode = 0 mock_run.return_value = mock_result - + result = self.checker.check_dependency("docker") - + self.assertTrue(result) - mock_run.assert_called_once_with( - ["command", "-v", "docker"], - capture_output=True, - text=True, - timeout=5 - ) + mock_run.assert_called_once_with(["command", "-v", "docker"], capture_output=True, text=True, timeout=5) self.assertEqual(len(self.mock_logger.debug_calls), 1) self.assertIn("docker", self.mock_logger.debug_calls[0]) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_check_dependency_not_available(self, mock_run): mock_result = Mock() mock_result.returncode = 1 mock_run.return_value = mock_result - + result = self.checker.check_dependency("nonexistent") - + self.assertFalse(result) - mock_run.assert_called_once_with( - ["command", "-v", "nonexistent"], - capture_output=True, - text=True, - timeout=5 - ) - - @patch('subprocess.run') + mock_run.assert_called_once_with(["command", "-v", "nonexistent"], capture_output=True, text=True, timeout=5) + + @patch("subprocess.run") def test_check_dependency_timeout(self, mock_run): mock_run.side_effect = subprocess.TimeoutExpired("command", 5) - + result = self.checker.check_dependency("slow_command") - + self.assertFalse(result) self.assertEqual(len(self.mock_logger.error_calls), 1) self.assertIn("slow_command", self.mock_logger.error_calls[0]) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_check_dependency_exception(self, mock_run): mock_run.side_effect = Exception("Test exception") - + result = self.checker.check_dependency("failing_command") - + self.assertFalse(result) self.assertEqual(len(self.mock_logger.error_calls), 1) self.assertIn("failing_command", self.mock_logger.error_calls[0]) class TestDependencyValidator(unittest.TestCase): - + def setUp(self): self.validator = DependencyValidator() - + def test_validate_os_valid(self): result = self.validator.validate_os("linux") self.assertEqual(result, "linux") - + result = self.validator.validate_os("darwin") self.assertEqual(result, "darwin") - + def test_validate_os_invalid(self): with self.assertRaises(ValueError) as context: self.validator.validate_os("windows") - + self.assertIn("windows", str(context.exception)) - + def test_validate_package_manager_valid(self): valid_managers = ["apt", "yum", "dnf", "pacman", "apk", "brew"] for manager in valid_managers: result = self.validator.validate_package_manager(manager) self.assertEqual(result, manager) - + def test_validate_package_manager_invalid(self): with self.assertRaises(ValueError) as context: self.validator.validate_package_manager("invalid_manager") - + self.assertIn("invalid_manager", str(context.exception)) class TestDependencyFormatter(unittest.TestCase): - + def setUp(self): self.formatter = DependencyFormatter() self.sample_results = [ @@ -150,7 +140,7 @@ def setUp(self): output="text", os="linux", package_manager="apt", - is_available=True + is_available=True, ), DepsCheckResult( dependency="kubectl", @@ -159,29 +149,29 @@ def setUp(self): output="text", os="linux", package_manager="apt", - is_available=False - ) + is_available=False, + ), ] - + def test_format_output_text(self): result = self.formatter.format_output(self.sample_results, "text") self.assertIn("docker is available", result) self.assertIn("kubectl is not available", result) - + def test_format_output_json(self): result = self.formatter.format_output(self.sample_results, "json") parsed = json.loads(result) self.assertEqual(len(parsed), 2) self.assertTrue(parsed[0]["success"]) self.assertFalse(parsed[1]["success"]) - + def test_format_output_invalid(self): with self.assertRaises(ValueError): self.formatter.format_output(self.sample_results, "invalid") class TestDepsCheckResult(unittest.TestCase): - + def test_deps_check_result_creation(self): result = DepsCheckResult( dependency="docker", @@ -191,9 +181,9 @@ def test_deps_check_result_creation(self): os="linux", package_manager="apt", is_available=True, - error=None + error=None, ) - + self.assertEqual(result.dependency, "docker") self.assertEqual(result.timeout, 5) self.assertTrue(result.verbose) @@ -202,7 +192,7 @@ def test_deps_check_result_creation(self): self.assertEqual(result.package_manager, "apt") self.assertTrue(result.is_available) self.assertIsNone(result.error) - + def test_deps_check_result_with_error(self): result = DepsCheckResult( dependency="failing_dep", @@ -212,96 +202,60 @@ def test_deps_check_result_with_error(self): os="darwin", package_manager="brew", is_available=False, - error="Command not found" + error="Command not found", ) - + self.assertFalse(result.is_available) self.assertEqual(result.error, "Command not found") class TestDepsConfig(unittest.TestCase): - + def test_valid_config(self): config = DepsConfig( - deps=["docker", "kubectl"], - timeout=10, - verbose=True, - output="json", - os="linux", - package_manager="apt" + deps=["docker", "kubectl"], timeout=10, verbose=True, output="json", os="linux", package_manager="apt" ) - + self.assertEqual(config.deps, ["docker", "kubectl"]) self.assertEqual(config.timeout, 10) self.assertTrue(config.verbose) self.assertEqual(config.output, "json") self.assertEqual(config.os, "linux") self.assertEqual(config.package_manager, "apt") - + def test_config_validation_os(self): with self.assertRaises(ValueError): - DepsConfig( - deps=["docker"], - os="invalid_os", - package_manager="apt" - ) - + DepsConfig(deps=["docker"], os="invalid_os", package_manager="apt") + def test_config_validation_package_manager(self): with self.assertRaises(ValueError): - DepsConfig( - deps=["docker"], - os="linux", - package_manager="invalid_manager" - ) - + DepsConfig(deps=["docker"], os="linux", package_manager="invalid_manager") + def test_config_timeout_validation(self): with self.assertRaises(ValueError): - DepsConfig( - deps=["docker"], - timeout=0, - os="linux", - package_manager="apt" - ) - + DepsConfig(deps=["docker"], timeout=0, os="linux", package_manager="apt") + with self.assertRaises(ValueError): - DepsConfig( - deps=["docker"], - timeout=61, - os="linux", - package_manager="apt" - ) - + DepsConfig(deps=["docker"], timeout=61, os="linux", package_manager="apt") + def test_config_deps_validation(self): with self.assertRaises(ValueError): - DepsConfig( - deps=[], - os="linux", - package_manager="apt" - ) + DepsConfig(deps=[], os="linux", package_manager="apt") class TestDepsService(unittest.TestCase): - + def setUp(self): self.config = DepsConfig( - deps=["docker", "kubectl"], - timeout=5, - verbose=False, - output="text", - os="linux", - package_manager="apt" + deps=["docker", "kubectl"], timeout=5, verbose=False, output="text", os="linux", package_manager="apt" ) self.mock_logger = MockLogger() self.mock_checker = Mock() - self.service = DepsService( - config=self.config, - logger=self.mock_logger, - checker=self.mock_checker - ) - + self.service = DepsService(config=self.config, logger=self.mock_logger, checker=self.mock_checker) + def test_create_result(self): result = self.service._create_result("docker", True) - + self.assertEqual(result.dependency, "docker") self.assertEqual(result.timeout, 5) self.assertFalse(result.verbose) @@ -310,96 +264,86 @@ def test_create_result(self): self.assertEqual(result.package_manager, "apt") self.assertTrue(result.is_available) self.assertIsNone(result.error) - + def test_create_result_with_error(self): result = self.service._create_result("failing_dep", False, "Command not found") - + self.assertFalse(result.is_available) self.assertEqual(result.error, "Command not found") - + def test_check_single_dependency_success(self): self.mock_checker.check_dependency.return_value = True - + result = self.service._check_dependency("docker") - + self.assertTrue(result.is_available) self.mock_checker.check_dependency.assert_called_once_with("docker") - + def test_check_single_dependency_failure(self): self.mock_checker.check_dependency.return_value = False - + result = self.service._check_dependency("nonexistent") - + self.assertFalse(result.is_available) self.mock_checker.check_dependency.assert_called_once_with("nonexistent") - + def test_check_single_dependency_exception(self): self.mock_checker.check_dependency.side_effect = Exception("Test error") - + result = self.service._check_dependency("failing_dep") - + self.assertFalse(result.is_available) self.assertEqual(result.error, "Test error") - - @patch('app.commands.preflight.deps.ParallelProcessor') + + @patch("app.commands.preflight.deps.ParallelProcessor") def test_check_dependencies(self, mock_parallel_processor): - mock_results = [ - self.service._create_result("docker", True), - self.service._create_result("kubectl", False) - ] + mock_results = [self.service._create_result("docker", True), self.service._create_result("kubectl", False)] mock_parallel_processor.process_items.return_value = mock_results - + results = self.service.check_dependencies() - + self.assertEqual(len(results), 2) mock_parallel_processor.process_items.assert_called_once() - + def test_check_and_format(self): - mock_results = [ - self.service._create_result("docker", True), - self.service._create_result("kubectl", False) - ] - - with patch.object(self.service, 'check_dependencies', return_value=mock_results): + mock_results = [self.service._create_result("docker", True), self.service._create_result("kubectl", False)] + + with patch.object(self.service, "check_dependencies", return_value=mock_results): result = self.service.check_and_format() - + self.assertIn("docker is available", result) self.assertIn("kubectl is not available", result) class TestDeps(unittest.TestCase): - + def setUp(self): self.mock_logger = MockLogger() self.deps = Deps(logger=self.mock_logger) - + def test_check(self): - config = DepsConfig( - deps=["docker"], - os="linux", - package_manager="apt" - ) - - with patch('app.commands.preflight.deps.DepsService') as mock_service_class: + config = DepsConfig(deps=["docker"], os="linux", package_manager="apt") + + with patch("app.commands.preflight.deps.DepsService") as mock_service_class: mock_service = Mock() mock_results = [Mock()] mock_service.check_dependencies.return_value = mock_results mock_service_class.return_value = mock_service - + results = self.deps.check(config) - + self.assertEqual(results, mock_results) mock_service_class.assert_called_once_with(config, logger=self.mock_logger) - + def test_format_output(self): mock_results = [Mock()] - - with patch.object(self.deps.formatter, 'format_output', return_value="formatted") as mock_format: + + with patch.object(self.deps.formatter, "format_output", return_value="formatted") as mock_format: result = self.deps.format_output(mock_results, "text") - + self.assertEqual(result, "formatted") mock_format.assert_called_once_with(mock_results, "text") -if __name__ == '__main__': - unittest.main() \ No newline at end of file +if __name__ == "__main__": + unittest.main() diff --git a/cli/app/commands/preflight/tests/test_port.py b/cli/app/commands/preflight/tests/test_port.py index 55e5eca9..d1d98a15 100644 --- a/cli/app/commands/preflight/tests/test_port.py +++ b/cli/app/commands/preflight/tests/test_port.py @@ -1,6 +1,9 @@ -import pytest from typing import List -from app.commands.preflight.port import PortConfig, PortCheckResult, PortService + +import pytest + +from app.commands.preflight.port import PortCheckResult, PortConfig, PortService + class TestPort: def test_valid_ports(self): @@ -71,28 +74,24 @@ def test_check_ports_verbose(self): assert all(result["error"] is None for result in results) assert all(result["is_available"] is True for result in results) + def test_port_check_result_type(): """Test that PortCheckResult has correct structure""" - result: PortCheckResult = { - "port": 8080, - "status": "available", - "host": "localhost", - "error": None, - "is_available": True - } - + result: PortCheckResult = {"port": 8080, "status": "available", "host": "localhost", "error": None, "is_available": True} + assert isinstance(result["port"], int) assert isinstance(result["status"], str) assert isinstance(result["host"], str) or result["host"] is None assert isinstance(result["error"], str) or result["error"] is None assert isinstance(result["is_available"], bool) + def test_check_ports_return_type(): """Test that check_ports returns correct type""" config = PortConfig(ports=[8080, 3000], host="localhost", timeout=1, verbose=False) port_service = PortService(config) results: List[PortCheckResult] = port_service.check_ports() - + assert isinstance(results, list) for result in results: assert isinstance(result, dict) diff --git a/cli/app/commands/proxy/base.py b/cli/app/commands/proxy/base.py index b40c57da..3b65a758 100644 --- a/cli/app/commands/proxy/base.py +++ b/cli/app/commands/proxy/base.py @@ -1,61 +1,70 @@ -import subprocess -import os import json +import os +import subprocess +from typing import Generic, Optional, Protocol, TypeVar + import requests -from typing import Protocol, Optional, Generic, TypeVar from pydantic import BaseModel, Field, field_validator from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter +from app.utils.protocols import LoggerProtocol + from .messages import ( - info_caddy_running, - caddy_status_code_error, caddy_connection_failed, - info_config_loaded, caddy_load_failed, - info_caddy_stopped, + caddy_status_code_error, config_file_not_found, - invalid_json_config + info_caddy_running, + info_caddy_stopped, + info_config_loaded, + invalid_json_config, ) -TConfig = TypeVar('TConfig', bound=BaseModel) -TResult = TypeVar('TResult', bound=BaseModel) +TConfig = TypeVar("TConfig", bound=BaseModel) +TResult = TypeVar("TResult", bound=BaseModel) CADDY_BASE_URL = "http://localhost:{port}" CADDY_CONFIG_ENDPOINT = "/config/" CADDY_LOAD_ENDPOINT = "/load" CADDY_STOP_ENDPOINT = "/stop" + class CaddyServiceProtocol(Protocol): - def check_status(self, port: int = 2019) -> tuple[bool, str]: - ... - - def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: - ... - - def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: - ... + def check_status(self, port: int = 2019) -> tuple[bool, str]: ... + + def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: ... + + def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: ... + class BaseCaddyCommandBuilder: @staticmethod def build_status_command(port: int = 2019) -> list[str]: return ["curl", "-X", "GET", f"{CADDY_BASE_URL.format(port=port)}{CADDY_CONFIG_ENDPOINT}"] - + @staticmethod def build_load_command(config_file: str, port: int = 2019) -> list[str]: - return ["curl", "-X", "POST", f"{CADDY_BASE_URL.format(port=port)}{CADDY_LOAD_ENDPOINT}", - "-H", "Content-Type: application/json", - "-d", f"@{config_file}"] - + return [ + "curl", + "-X", + "POST", + f"{CADDY_BASE_URL.format(port=port)}{CADDY_LOAD_ENDPOINT}", + "-H", + "Content-Type: application/json", + "-d", + f"@{config_file}", + ] + @staticmethod def build_stop_command(port: int = 2019) -> list[str]: return ["curl", "-X", "POST", f"{CADDY_BASE_URL.format(port=port)}{CADDY_STOP_ENDPOINT}"] + class BaseFormatter: def __init__(self): self.output_formatter = OutputFormatter() - + def format_output(self, result: TResult, output: str, success_message: str, error_message: str) -> str: if result.success: message = success_message.format(port=result.proxy_port) @@ -63,38 +72,39 @@ def format_output(self, result: TResult, output: str, success_message: str, erro else: error = result.error or "Unknown error occurred" output_message = self.output_formatter.create_error_message(error, result.model_dump()) - + return self.output_formatter.format_output(output_message, output) - + def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dict) -> str: - if hasattr(command_builder, 'build_status_command'): - cmd = command_builder.build_status_command(getattr(config, 'proxy_port', 2019)) - elif hasattr(command_builder, 'build_load_command'): - cmd = command_builder.build_load_command(getattr(config, 'config_file', ''), getattr(config, 'proxy_port', 2019)) - elif hasattr(command_builder, 'build_stop_command'): - cmd = command_builder.build_stop_command(getattr(config, 'proxy_port', 2019)) + if hasattr(command_builder, "build_status_command"): + cmd = command_builder.build_status_command(getattr(config, "proxy_port", 2019)) + elif hasattr(command_builder, "build_load_command"): + cmd = command_builder.build_load_command(getattr(config, "config_file", ""), getattr(config, "proxy_port", 2019)) + elif hasattr(command_builder, "build_stop_command"): + cmd = command_builder.build_stop_command(getattr(config, "proxy_port", 2019)) else: cmd = command_builder.build_command(config) - + output = [] output.append(dry_run_messages["mode"]) output.append(dry_run_messages["command_would_be_executed"]) output.append(f"{dry_run_messages['command']} {' '.join(cmd)}") output.append(f"{dry_run_messages['port']} {getattr(config, 'proxy_port', 2019)}") - - if hasattr(config, 'config_file') and getattr(config, 'config_file', None): + + if hasattr(config, "config_file") and getattr(config, "config_file", None): output.append(f"{dry_run_messages['config_file']} {getattr(config, 'config_file')}") - + output.append(dry_run_messages["end"]) return "\n".join(output) + class BaseCaddyService: def __init__(self, logger: LoggerProtocol): self.logger = logger - + def _get_caddy_url(self, port: int, endpoint: str) -> str: return f"{CADDY_BASE_URL.format(port=port)}{endpoint}" - + def check_status(self, port: int = 2019) -> tuple[bool, str]: try: url = self._get_caddy_url(port, CADDY_CONFIG_ENDPOINT) @@ -107,20 +117,15 @@ def check_status(self, port: int = 2019) -> tuple[bool, str]: return False, caddy_connection_failed.format(error=str(e)) except Exception as e: return False, f"Unexpected error: {str(e)}" - + def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: try: - with open(config_file, 'r') as f: + with open(config_file, "r") as f: config_data = json.load(f) - + url = self._get_caddy_url(port, CADDY_LOAD_ENDPOINT) - response = requests.post( - url, - json=config_data, - headers={'Content-Type': 'application/json'}, - timeout=10 - ) - + response = requests.post(url, json=config_data, headers={"Content-Type": "application/json"}, timeout=10) + if response.status_code == 200: return True, info_config_loaded else: @@ -133,7 +138,7 @@ def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: return False, caddy_connection_failed.format(error=str(e)) except Exception as e: return False, f"Unexpected error: {str(e)}" - + def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: try: url = self._get_caddy_url(port, CADDY_STOP_ENDPOINT) @@ -147,12 +152,13 @@ def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: except Exception as e: return False, f"Unexpected error: {str(e)}" + class BaseConfig(BaseModel): proxy_port: int = Field(2019, description="Caddy admin port") verbose: bool = Field(False, description="Verbose output") output: str = Field("text", description="Output format: text, json") dry_run: bool = Field(False, description="Dry run mode") - + @field_validator("proxy_port") @classmethod def validate_proxy_port(cls, port: int) -> int: @@ -160,6 +166,7 @@ def validate_proxy_port(cls, port: int) -> int: raise ValueError("Port must be between 1 and 65535") return port + class BaseResult(BaseModel): proxy_port: int verbose: bool @@ -167,29 +174,31 @@ class BaseResult(BaseModel): success: bool = False error: Optional[str] = None + class BaseService(Generic[TConfig, TResult]): def __init__(self, config: TConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) self.caddy_service = caddy_service self.formatter = None - + def _create_result(self, success: bool, error: str = None) -> TResult: raise NotImplementedError - + def execute(self) -> TResult: raise NotImplementedError - + def execute_and_format(self) -> str: raise NotImplementedError + class BaseAction(Generic[TConfig, TResult]): def __init__(self, logger: LoggerProtocol = None): self.logger = logger self.formatter = None - + def execute(self, config: TConfig) -> TResult: raise NotImplementedError - + def format_output(self, result: TResult, output: str) -> str: - raise NotImplementedError + raise NotImplementedError diff --git a/cli/app/commands/proxy/command.py b/cli/app/commands/proxy/command.py index c10bbc0d..7d3d4714 100644 --- a/cli/app/commands/proxy/command.py +++ b/cli/app/commands/proxy/command.py @@ -1,5 +1,7 @@ import typer + from app.utils.logger import Logger + from .load import Load, LoadConfig from .status import Status, StatusConfig from .stop import Stop, StopConfig @@ -9,6 +11,7 @@ help="Manage Nixopus proxy (Caddy) configuration", ) + @proxy_app.command() def load( proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), @@ -19,29 +22,24 @@ def load( ): """Load Caddy proxy configuration""" logger = Logger(verbose=verbose) - + try: - config = LoadConfig( - proxy_port=proxy_port, - verbose=verbose, - output=output, - dry_run=dry_run, - config_file=config_file - ) - + config = LoadConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run, config_file=config_file) + load_service = Load(logger=logger) result = load_service.load(config) - + if result.success: logger.success(load_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @proxy_app.command() def status( proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), @@ -51,28 +49,24 @@ def status( ): """Check Caddy proxy status""" logger = Logger(verbose=verbose) - + try: - config = StatusConfig( - proxy_port=proxy_port, - verbose=verbose, - output=output, - dry_run=dry_run - ) - + config = StatusConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run) + status_service = Status(logger=logger) result = status_service.status(config) - + if result.success: logger.success(status_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @proxy_app.command() def stop( proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), @@ -82,25 +76,19 @@ def stop( ): """Stop Caddy proxy""" logger = Logger(verbose=verbose) - + try: - config = StopConfig( - proxy_port=proxy_port, - verbose=verbose, - output=output, - dry_run=dry_run - ) - + config = StopConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run) + stop_service = Stop(logger=logger) result = stop_service.stop(config) - + if result.success: logger.success(stop_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) - diff --git a/cli/app/commands/proxy/load.py b/cli/app/commands/proxy/load.py index 4c7d355c..853db4d8 100644 --- a/cli/app/commands/proxy/load.py +++ b/cli/app/commands/proxy/load.py @@ -1,45 +1,41 @@ import os -from typing import Protocol, Optional +from typing import Optional, Protocol + from pydantic import BaseModel, Field, field_validator from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter -from .base import ( - BaseCaddyCommandBuilder, - BaseFormatter, - BaseCaddyService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.utils.protocols import LoggerProtocol + +from .base import BaseAction, BaseCaddyCommandBuilder, BaseCaddyService, BaseConfig, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, + config_file_required, + debug_init_proxy, dry_run_command, - dry_run_port, + dry_run_command_would_be_executed, dry_run_config_file, + dry_run_mode, + dry_run_port, end_dry_run, - proxy_initialized_successfully, proxy_init_failed, - config_file_required, - debug_init_proxy, + proxy_initialized_successfully, ) + class CaddyServiceProtocol(Protocol): - def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: - ... + def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: ... + class CaddyCommandBuilder(BaseCaddyCommandBuilder): @staticmethod def build_load_command(config_file: str, port: int = 2019) -> list[str]: return BaseCaddyCommandBuilder.build_load_command(config_file, port) + class LoadFormatter(BaseFormatter): def format_output(self, result: "LoadResult", output: str) -> str: return super().format_output(result, output, proxy_initialized_successfully, proxy_init_failed) - + def format_dry_run(self, config: "LoadConfig") -> str: dry_run_messages = { "mode": dry_run_mode, @@ -47,23 +43,26 @@ def format_dry_run(self, config: "LoadConfig") -> str: "command": dry_run_command, "port": dry_run_port, "config_file": dry_run_config_file, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, CaddyCommandBuilder(), dry_run_messages) + class CaddyService(BaseCaddyService): def __init__(self, logger: LoggerProtocol): super().__init__(logger) - + def load_config_file(self, config_file: str, port: int = 2019) -> tuple[bool, str]: return self.load_config(config_file, port) + class LoadResult(BaseResult): config_file: Optional[str] + class LoadConfig(BaseConfig): config_file: Optional[str] = Field(None, description="Path to Caddy config file") - + @field_validator("config_file") @classmethod def validate_config_file(cls, config_file: str) -> Optional[str]: @@ -76,12 +75,13 @@ def validate_config_file(cls, config_file: str) -> Optional[str]: raise ValueError(f"Configuration file not found: {stripped_config_file}") return stripped_config_file + class LoadService(BaseService[LoadConfig, LoadResult]): def __init__(self, config: LoadConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): super().__init__(config, logger, caddy_service) self.caddy_service = caddy_service or CaddyService(self.logger) self.formatter = LoadFormatter() - + def _create_result(self, success: bool, error: str = None) -> LoadResult: return LoadResult( proxy_port=self.config.proxy_port, @@ -89,47 +89,45 @@ def _create_result(self, success: bool, error: str = None) -> LoadResult: verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def load(self) -> LoadResult: return self.execute() - + def execute(self) -> LoadResult: self.logger.debug(debug_init_proxy.format(port=self.config.proxy_port)) - + if not self.config.config_file: self.logger.error(config_file_required) return self._create_result(False, config_file_required) - - success, error = self.caddy_service.load_config_file( - self.config.config_file, - self.config.proxy_port - ) - + + success, error = self.caddy_service.load_config_file(self.config.config_file, self.config.proxy_port) + return self._create_result(success, error) - + def load_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Load(BaseAction[LoadConfig, LoadResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = LoadFormatter() - + def load(self, config: LoadConfig) -> LoadResult: return self.execute(config) - + def execute(self, config: LoadConfig) -> LoadResult: service = LoadService(config, logger=self.logger) return service.execute() - + def format_output(self, result: LoadResult, output: str) -> str: - return self.formatter.format_output(result, output) + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/proxy/messages.py b/cli/app/commands/proxy/messages.py index 214fc1a7..f53860a0 100644 --- a/cli/app/commands/proxy/messages.py +++ b/cli/app/commands/proxy/messages.py @@ -38,4 +38,4 @@ # Info messages info_caddy_running = "Caddy is running" info_config_loaded = "Configuration loaded successfully" -info_caddy_stopped = "Caddy stopped successfully" \ No newline at end of file +info_caddy_stopped = "Caddy stopped successfully" diff --git a/cli/app/commands/proxy/status.py b/cli/app/commands/proxy/status.py index 7ecdb764..ae03d45f 100644 --- a/cli/app/commands/proxy/status.py +++ b/cli/app/commands/proxy/status.py @@ -1,117 +1,118 @@ from typing import Protocol + from pydantic import BaseModel from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter -from .base import ( - BaseCaddyCommandBuilder, - BaseFormatter, - BaseCaddyService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.utils.protocols import LoggerProtocol + +from .base import BaseAction, BaseCaddyCommandBuilder, BaseCaddyService, BaseConfig, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, + debug_check_status, dry_run_command, + dry_run_command_would_be_executed, + dry_run_mode, dry_run_port, end_dry_run, + proxy_status_failed, proxy_status_running, proxy_status_stopped, - proxy_status_failed, - debug_check_status, ) + class CaddyServiceProtocol(Protocol): - def check_status(self, port: int = 2019) -> tuple[bool, str]: - ... + def check_status(self, port: int = 2019) -> tuple[bool, str]: ... + class CaddyCommandBuilder(BaseCaddyCommandBuilder): @staticmethod def build_status_command(port: int = 2019) -> list[str]: return BaseCaddyCommandBuilder.build_status_command(port) + class StatusFormatter(BaseFormatter): def format_output(self, result: "StatusResult", output: str) -> str: if result.success: message = proxy_status_running.format(port=result.proxy_port) else: message = proxy_status_stopped.format(port=result.proxy_port) - + return super().format_output(result, output, message, proxy_status_failed) - + def format_dry_run(self, config: "StatusConfig") -> str: dry_run_messages = { "mode": dry_run_mode, "command_would_be_executed": dry_run_command_would_be_executed, "command": dry_run_command, "port": dry_run_port, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, CaddyCommandBuilder(), dry_run_messages) + class CaddyService(BaseCaddyService): def __init__(self, logger: LoggerProtocol): super().__init__(logger) - + def get_status(self, port: int = 2019) -> tuple[bool, str]: return self.check_status(port) + class StatusResult(BaseResult): pass + class StatusConfig(BaseConfig): pass + class StatusService(BaseService[StatusConfig, StatusResult]): def __init__(self, config: StatusConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): super().__init__(config, logger, caddy_service) self.caddy_service = caddy_service or CaddyService(self.logger) self.formatter = StatusFormatter() - + def _create_result(self, success: bool, error: str = None) -> StatusResult: return StatusResult( proxy_port=self.config.proxy_port, verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def status(self) -> StatusResult: return self.execute() - + def execute(self) -> StatusResult: self.logger.debug(debug_check_status.format(port=self.config.proxy_port)) - + success, error = self.caddy_service.get_status(self.config.proxy_port) - + return self._create_result(success, error) - + def status_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Status(BaseAction[StatusConfig, StatusResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = StatusFormatter() - + def status(self, config: StatusConfig) -> StatusResult: return self.execute(config) - + def execute(self, config: StatusConfig) -> StatusResult: service = StatusService(config, logger=self.logger) return service.execute() - + def format_output(self, result: StatusResult, output: str) -> str: - return self.formatter.format_output(result, output) + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/proxy/stop.py b/cli/app/commands/proxy/stop.py index 4a29a38d..6907783a 100644 --- a/cli/app/commands/proxy/stop.py +++ b/cli/app/commands/proxy/stop.py @@ -1,111 +1,112 @@ from typing import Protocol + from pydantic import BaseModel from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter -from .base import ( - BaseCaddyCommandBuilder, - BaseFormatter, - BaseCaddyService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.utils.protocols import LoggerProtocol + +from .base import BaseAction, BaseCaddyCommandBuilder, BaseCaddyService, BaseConfig, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, + debug_stop_proxy, dry_run_command, + dry_run_command_would_be_executed, + dry_run_mode, dry_run_port, end_dry_run, - proxy_stopped_successfully, proxy_stop_failed, - debug_stop_proxy, + proxy_stopped_successfully, ) + class CaddyServiceProtocol(Protocol): - def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: - ... + def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: ... + class CaddyCommandBuilder(BaseCaddyCommandBuilder): @staticmethod def build_stop_command(port: int = 2019) -> list[str]: return BaseCaddyCommandBuilder.build_stop_command(port) + class StopFormatter(BaseFormatter): def format_output(self, result: "StopResult", output: str) -> str: return super().format_output(result, output, proxy_stopped_successfully, proxy_stop_failed) - + def format_dry_run(self, config: "StopConfig") -> str: dry_run_messages = { "mode": dry_run_mode, "command_would_be_executed": dry_run_command_would_be_executed, "command": dry_run_command, "port": dry_run_port, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, CaddyCommandBuilder(), dry_run_messages) + class CaddyService(BaseCaddyService): def __init__(self, logger: LoggerProtocol): super().__init__(logger) - + def stop_caddy(self, port: int = 2019) -> tuple[bool, str]: return self.stop_proxy(port) + class StopResult(BaseResult): pass + class StopConfig(BaseConfig): pass + class StopService(BaseService[StopConfig, StopResult]): def __init__(self, config: StopConfig, logger: LoggerProtocol = None, caddy_service: CaddyServiceProtocol = None): super().__init__(config, logger, caddy_service) self.caddy_service = caddy_service or CaddyService(self.logger) self.formatter = StopFormatter() - + def _create_result(self, success: bool, error: str = None) -> StopResult: return StopResult( proxy_port=self.config.proxy_port, verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def stop(self) -> StopResult: return self.execute() - + def execute(self) -> StopResult: self.logger.debug(debug_stop_proxy.format(port=self.config.proxy_port)) - + success, error = self.caddy_service.stop_caddy(self.config.proxy_port) - + return self._create_result(success, error) - + def stop_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Stop(BaseAction[StopConfig, StopResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = StopFormatter() - + def stop(self, config: StopConfig) -> StopResult: return self.execute(config) - + def execute(self, config: StopConfig) -> StopResult: service = StopService(config, logger=self.logger) return service.execute() - + def format_output(self, result: StopResult, output: str) -> str: - return self.formatter.format_output(result, output) + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/proxy/tests/test_load.py b/cli/app/commands/proxy/tests/test_load.py index 6a89f146..5c28d937 100644 --- a/cli/app/commands/proxy/tests/test_load.py +++ b/cli/app/commands/proxy/tests/test_load.py @@ -1,10 +1,13 @@ +from unittest.mock import patch + import pytest from typer.testing import CliRunner + from app.commands.proxy.command import proxy_app -from unittest.mock import patch runner = CliRunner() + def test_load_success(tmp_path): config_file = tmp_path / "caddy.json" config_file.write_text("{}") @@ -13,15 +16,17 @@ def test_load_success(tmp_path): assert result.exit_code == 0 assert "successfully" in result.output + def test_load_missing_config(): result = runner.invoke(proxy_app, ["load"]) assert result.exit_code != 0 assert "Configuration file is required" in result.output + def test_load_error(tmp_path): config_file = tmp_path / "caddy.json" config_file.write_text("{}") with patch("app.commands.proxy.load.CaddyService.load_config_file", return_value=(False, "fail")): result = runner.invoke(proxy_app, ["load", "--config-file", str(config_file)]) assert result.exit_code != 0 - assert "fail" in result.output + assert "fail" in result.output diff --git a/cli/app/commands/proxy/tests/test_status.py b/cli/app/commands/proxy/tests/test_status.py index ad85b0ee..8ea54456 100644 --- a/cli/app/commands/proxy/tests/test_status.py +++ b/cli/app/commands/proxy/tests/test_status.py @@ -1,18 +1,22 @@ +from unittest.mock import patch + import pytest from typer.testing import CliRunner + from app.commands.proxy.command import proxy_app -from unittest.mock import patch runner = CliRunner() + def test_status_running(): with patch("app.commands.proxy.status.CaddyService.get_status", return_value=(True, "Caddy is running")): result = runner.invoke(proxy_app, ["status"]) assert result.exit_code == 0 assert "running" in result.output + def test_status_not_running(): with patch("app.commands.proxy.status.CaddyService.get_status", return_value=(False, "not running")): result = runner.invoke(proxy_app, ["status"]) assert result.exit_code != 0 - assert "not running" in result.output \ No newline at end of file + assert "not running" in result.output diff --git a/cli/app/commands/proxy/tests/test_stop.py b/cli/app/commands/proxy/tests/test_stop.py index 66bea3ed..b9547dbd 100644 --- a/cli/app/commands/proxy/tests/test_stop.py +++ b/cli/app/commands/proxy/tests/test_stop.py @@ -1,18 +1,22 @@ +from unittest.mock import patch + import pytest from typer.testing import CliRunner + from app.commands.proxy.command import proxy_app -from unittest.mock import patch runner = CliRunner() + def test_stop_success(): with patch("app.commands.proxy.stop.CaddyService.stop_caddy", return_value=(True, "Caddy stopped successfully")): result = runner.invoke(proxy_app, ["stop"]) assert result.exit_code == 0 assert "stopped successfully" in result.output + def test_stop_error(): with patch("app.commands.proxy.stop.CaddyService.stop_caddy", return_value=(False, "fail")): result = runner.invoke(proxy_app, ["stop"]) assert result.exit_code != 0 - assert "fail" in result.output \ No newline at end of file + assert "fail" in result.output diff --git a/cli/app/commands/service/__init__.py b/cli/app/commands/service/__init__.py index 8f616615..cbcf0995 100644 --- a/cli/app/commands/service/__init__.py +++ b/cli/app/commands/service/__init__.py @@ -1 +1 @@ -# Service package \ No newline at end of file +# Service package diff --git a/cli/app/commands/service/base.py b/cli/app/commands/service/base.py index bcc70c93..2baaa1c5 100644 --- a/cli/app/commands/service/base.py +++ b/cli/app/commands/service/base.py @@ -1,18 +1,22 @@ -import subprocess import os -from typing import Protocol, Optional, Generic, TypeVar +import subprocess +from typing import Generic, Optional, Protocol, TypeVar + from pydantic import BaseModel, Field, field_validator from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter +from app.utils.protocols import LoggerProtocol + +TConfig = TypeVar("TConfig", bound=BaseModel) +TResult = TypeVar("TResult", bound=BaseModel) -TConfig = TypeVar('TConfig', bound=BaseModel) -TResult = TypeVar('TResult', bound=BaseModel) class DockerServiceProtocol(Protocol): - def execute_services(self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs) -> tuple[bool, str]: - ... + def execute_services( + self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs + ) -> tuple[bool, str]: ... + class BaseDockerCommandBuilder: @staticmethod @@ -21,22 +25,23 @@ def build_command(action: str, name: str = "all", env_file: str = None, compose_ if compose_file: cmd.extend(["-f", compose_file]) cmd.append(action) - + if action == "up" and kwargs.get("detach", True): cmd.append("-d") - + if env_file: cmd.extend(["--env-file", env_file]) - + if name != "all": cmd.append(name) - + return cmd + class BaseFormatter: def __init__(self): self.output_formatter = OutputFormatter() - + def format_output(self, result: TResult, output: str, success_message: str, error_message: str) -> str: if result.success: message = success_message.format(services=result.name) @@ -44,41 +49,53 @@ def format_output(self, result: TResult, output: str, success_message: str, erro else: error = result.error or "Unknown error occurred" output_message = self.output_formatter.create_error_message(error, result.model_dump()) - + return self.output_formatter.format_output(output_message, output) - + def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dict) -> str: - if hasattr(command_builder, 'build_up_command'): - cmd = command_builder.build_up_command(getattr(config, 'name', 'all'), getattr(config, 'detach', True), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) - elif hasattr(command_builder, 'build_down_command'): - cmd = command_builder.build_down_command(getattr(config, 'name', 'all'), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) - elif hasattr(command_builder, 'build_ps_command'): - cmd = command_builder.build_ps_command(getattr(config, 'name', 'all'), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) - elif hasattr(command_builder, 'build_restart_command'): - cmd = command_builder.build_restart_command(getattr(config, 'name', 'all'), getattr(config, 'env_file', None), getattr(config, 'compose_file', None)) + if hasattr(command_builder, "build_up_command"): + cmd = command_builder.build_up_command( + getattr(config, "name", "all"), + getattr(config, "detach", True), + getattr(config, "env_file", None), + getattr(config, "compose_file", None), + ) + elif hasattr(command_builder, "build_down_command"): + cmd = command_builder.build_down_command( + getattr(config, "name", "all"), getattr(config, "env_file", None), getattr(config, "compose_file", None) + ) + elif hasattr(command_builder, "build_ps_command"): + cmd = command_builder.build_ps_command( + getattr(config, "name", "all"), getattr(config, "env_file", None), getattr(config, "compose_file", None) + ) + elif hasattr(command_builder, "build_restart_command"): + cmd = command_builder.build_restart_command( + getattr(config, "name", "all"), getattr(config, "env_file", None), getattr(config, "compose_file", None) + ) else: cmd = command_builder.build_command(config) - + output = [] output.append(dry_run_messages["mode"]) output.append(dry_run_messages["command_would_be_executed"]) output.append(f"{dry_run_messages['command']} {' '.join(cmd)}") output.append(f"{dry_run_messages['service']} {getattr(config, 'name', 'all')}") - - if hasattr(config, 'detach'): + + if hasattr(config, "detach"): output.append(f"{dry_run_messages.get('detach_mode', 'Detach mode:')} {getattr(config, 'detach', True)}") - - if getattr(config, 'env_file', None): + + if getattr(config, "env_file", None): output.append(f"{dry_run_messages['env_file']} {getattr(config, 'env_file')}") - + output.append(dry_run_messages["end"]) return "\n".join(output) + class BaseDockerService: def __init__(self, logger: LoggerProtocol, action: str): self.logger = logger self.action = action - + def _past_tense(self): if self.action == "up": return "upped" @@ -86,9 +103,11 @@ def _past_tense(self): return "downed" return f"{self.action}ed" - def execute_services(self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs) -> tuple[bool, str]: + def execute_services( + self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs + ) -> tuple[bool, str]: cmd = BaseDockerCommandBuilder.build_command(self.action, name, env_file, compose_file, **kwargs) - + try: self.logger.info(f"{self.action.capitalize()}ing services: {name}") result = subprocess.run(cmd, capture_output=True, text=True, check=True) @@ -101,6 +120,7 @@ def execute_services(self, name: str = "all", env_file: str = None, compose_file self.logger.error(f"Unexpected error during {self.action}: {e}") return False, str(e) + class BaseConfig(BaseModel): name: str = Field("all", description="Name of the service") env_file: Optional[str] = Field(None, description="Path to environment file") @@ -108,7 +128,7 @@ class BaseConfig(BaseModel): output: str = Field("text", description="Output format: text, json") dry_run: bool = Field(False, description="Dry run mode") compose_file: Optional[str] = Field(None, description="Path to the compose file") - + @field_validator("env_file") @classmethod def validate_env_file(cls, env_file: str) -> Optional[str]: @@ -120,7 +140,7 @@ def validate_env_file(cls, env_file: str) -> Optional[str]: if not os.path.exists(stripped_env_file): raise ValueError(f"Environment file not found: {stripped_env_file}") return stripped_env_file - + @field_validator("compose_file") @classmethod def validate_compose_file(cls, compose_file: str) -> Optional[str]: @@ -133,6 +153,7 @@ def validate_compose_file(cls, compose_file: str) -> Optional[str]: raise ValueError(f"Compose file not found: {stripped_compose_file}") return stripped_compose_file + class BaseResult(BaseModel): name: str env_file: Optional[str] @@ -141,29 +162,31 @@ class BaseResult(BaseModel): success: bool = False error: Optional[str] = None + class BaseService(Generic[TConfig, TResult]): def __init__(self, config: TConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) self.docker_service = docker_service self.formatter = None - + def _create_result(self, success: bool, error: str = None) -> TResult: raise NotImplementedError - + def execute(self) -> TResult: raise NotImplementedError - + def execute_and_format(self) -> str: raise NotImplementedError + class BaseAction(Generic[TConfig, TResult]): def __init__(self, logger: LoggerProtocol = None): self.logger = logger self.formatter = None - + def execute(self, config: TConfig) -> TResult: raise NotImplementedError - + def format_output(self, result: TResult, output: str) -> str: - raise NotImplementedError + raise NotImplementedError diff --git a/cli/app/commands/service/command.py b/cli/app/commands/service/command.py index a71e99ed..0747330f 100644 --- a/cli/app/commands/service/command.py +++ b/cli/app/commands/service/command.py @@ -1,13 +1,14 @@ import typer + from app.utils.logger import Logger -from .up import Up, UpConfig + from .down import Down, DownConfig from .ps import Ps, PsConfig from .restart import Restart, RestartConfig +from .up import Up, UpConfig + +service_app = typer.Typer(help="Manage Nixopus services") -service_app = typer.Typer( - help="Manage Nixopus services" -) @service_app.command() def up( @@ -21,7 +22,7 @@ def up( ): """Start Nixopus services""" logger = Logger(verbose=verbose) - + try: config = UpConfig( name=name, @@ -30,22 +31,23 @@ def up( verbose=verbose, output=output, dry_run=dry_run, - compose_file=compose_file + compose_file=compose_file, ) - + up_service = Up(logger=logger) result = up_service.up(config) - + if result.success: logger.success(up_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @service_app.command() def down( name: str = typer.Option("all", "--name", "-n", help="The name of the service to stop, defaults to all"), @@ -57,30 +59,26 @@ def down( ): """Stop Nixopus services""" logger = Logger(verbose=verbose) - - try: + + try: config = DownConfig( - name=name, - env_file=env_file, - verbose=verbose, - output=output, - dry_run=dry_run, - compose_file=compose_file + name=name, env_file=env_file, verbose=verbose, output=output, dry_run=dry_run, compose_file=compose_file ) - + down_service = Down(logger=logger) result = down_service.down(config) - + if result.success: logger.success(down_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @service_app.command() def ps( name: str = typer.Option("all", "--name", "-n", help="The name of the service to show, defaults to all"), @@ -92,30 +90,26 @@ def ps( ): """Show status of Nixopus services""" logger = Logger(verbose=verbose) - + try: config = PsConfig( - name=name, - env_file=env_file, - verbose=verbose, - output=output, - dry_run=dry_run, - compose_file=compose_file + name=name, env_file=env_file, verbose=verbose, output=output, dry_run=dry_run, compose_file=compose_file ) - + ps_service = Ps(logger=logger) result = ps_service.ps(config) - + if result.success: logger.success(ps_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) + @service_app.command() def restart( name: str = typer.Option("all", "--name", "-n", help="The name of the service to restart, defaults to all"), @@ -127,26 +121,21 @@ def restart( ): """Restart Nixopus services""" logger = Logger(verbose=verbose) - + try: config = RestartConfig( - name=name, - env_file=env_file, - verbose=verbose, - output=output, - dry_run=dry_run, - compose_file=compose_file + name=name, env_file=env_file, verbose=verbose, output=output, dry_run=dry_run, compose_file=compose_file ) - + restart_service = Restart(logger=logger) result = restart_service.restart(config) - + if result.success: logger.success(restart_service.format_output(result, output)) else: logger.error(result.error) raise typer.Exit(1) - + except Exception as e: logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/service/down.py b/cli/app/commands/service/down.py index a00ce2bb..8495051b 100644 --- a/cli/app/commands/service/down.py +++ b/cli/app/commands/service/down.py @@ -1,43 +1,39 @@ -import subprocess import os -from typing import Protocol, Optional +import subprocess +from typing import Optional, Protocol + from pydantic import BaseModel, Field, field_validator from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol -from .base import ( - BaseDockerCommandBuilder, - BaseFormatter, - BaseDockerService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) + +from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, dry_run_command, - dry_run_service, + dry_run_command_would_be_executed, dry_run_env_file, + dry_run_mode, + dry_run_service, end_dry_run, - services_stopped_successfully, service_stop_failed, + services_stopped_successfully, ) + class DockerServiceProtocol(Protocol): - def stop_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: - ... + def stop_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: ... + class DockerCommandBuilder(BaseDockerCommandBuilder): @staticmethod def build_down_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: return BaseDockerCommandBuilder.build_command("down", name, env_file, compose_file) + class DownFormatter(BaseFormatter): def format_output(self, result: "DownResult", output: str) -> str: return super().format_output(result, output, services_stopped_successfully, service_stop_failed) - + def format_dry_run(self, config: "DownConfig") -> str: dry_run_messages = { "mode": dry_run_mode, @@ -45,29 +41,33 @@ def format_dry_run(self, config: "DownConfig") -> str: "command": dry_run_command, "service": dry_run_service, "env_file": dry_run_env_file, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + class DockerService(BaseDockerService): def __init__(self, logger: LoggerProtocol): super().__init__(logger, "down") - + def stop_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: return self.execute_services(name, env_file, compose_file) + class DownResult(BaseResult): pass + class DownConfig(BaseConfig): pass + class DownService(BaseService[DownConfig, DownResult]): def __init__(self, config: DownConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): super().__init__(config, logger, docker_service) self.docker_service = docker_service or DockerService(self.logger) self.formatter = DownFormatter() - + def _create_result(self, success: bool, error: str = None) -> DownResult: return DownResult( name=self.config.name, @@ -75,44 +75,41 @@ def _create_result(self, success: bool, error: str = None) -> DownResult: verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def down(self) -> DownResult: return self.execute() - + def execute(self) -> DownResult: self.logger.debug(f"Stopping services: {self.config.name}") - - success, error = self.docker_service.stop_services( - self.config.name, - self.config.env_file, - self.config.compose_file - ) - + + success, error = self.docker_service.stop_services(self.config.name, self.config.env_file, self.config.compose_file) + return self._create_result(success, error) - + def down_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Down(BaseAction[DownConfig, DownResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = DownFormatter() - + def down(self, config: DownConfig) -> DownResult: return self.execute(config) - + def execute(self, config: DownConfig) -> DownResult: service = DownService(config, logger=self.logger) return service.execute() - + def format_output(self, result: DownResult, output: str) -> str: - return self.formatter.format_output(result, output) + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/service/ps.py b/cli/app/commands/service/ps.py index 01f0d98c..79c29dec 100644 --- a/cli/app/commands/service/ps.py +++ b/cli/app/commands/service/ps.py @@ -1,38 +1,34 @@ from typing import Optional + from pydantic import Field from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol, DockerServiceProtocol -from .base import ( - BaseDockerCommandBuilder, - BaseFormatter, - BaseDockerService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.utils.protocols import DockerServiceProtocol, LoggerProtocol + +from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, dry_run_command, - dry_run_service, + dry_run_command_would_be_executed, dry_run_env_file, + dry_run_mode, + dry_run_service, end_dry_run, - services_status_retrieved, service_status_failed, - unknown_error + services_status_retrieved, + unknown_error, ) + class DockerCommandBuilder(BaseDockerCommandBuilder): @staticmethod def build_ps_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: return BaseDockerCommandBuilder.build_command("ps", name, env_file, compose_file) + class PsFormatter(BaseFormatter): def format_output(self, result: "PsResult", output: str) -> str: return super().format_output(result, output, services_status_retrieved, service_status_failed) - + def format_dry_run(self, config: "PsConfig") -> str: dry_run_messages = { "mode": dry_run_mode, @@ -40,29 +36,33 @@ def format_dry_run(self, config: "PsConfig") -> str: "command": dry_run_command, "service": dry_run_service, "env_file": dry_run_env_file, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + class DockerService(BaseDockerService): def __init__(self, logger: LoggerProtocol): super().__init__(logger, "ps") - + def show_services_status(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: return self.execute_services(name, env_file, compose_file) + class PsResult(BaseResult): pass + class PsConfig(BaseConfig): pass + class PsService(BaseService[PsConfig, PsResult]): def __init__(self, config: PsConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): super().__init__(config, logger, docker_service) self.docker_service = docker_service or DockerService(self.logger) self.formatter = PsFormatter() - + def _create_result(self, success: bool, error: str = None) -> PsResult: return PsResult( name=self.config.name, @@ -70,44 +70,43 @@ def _create_result(self, success: bool, error: str = None) -> PsResult: verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def ps(self) -> PsResult: return self.execute() - + def execute(self) -> PsResult: self.logger.debug(f"Checking status of services: {self.config.name}") - + success, error = self.docker_service.show_services_status( - self.config.name, - self.config.env_file, - self.config.compose_file + self.config.name, self.config.env_file, self.config.compose_file ) - + return self._create_result(success, error) - + def ps_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Ps(BaseAction[PsConfig, PsResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = PsFormatter() - + def ps(self, config: PsConfig) -> PsResult: return self.execute(config) - + def execute(self, config: PsConfig) -> PsResult: service = PsService(config, logger=self.logger) return service.execute() - + def format_output(self, result: PsResult, output: str) -> str: - return self.formatter.format_output(result, output) + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/service/restart.py b/cli/app/commands/service/restart.py index fec6c119..c9eb7f92 100644 --- a/cli/app/commands/service/restart.py +++ b/cli/app/commands/service/restart.py @@ -1,38 +1,34 @@ from typing import Optional + from pydantic import Field from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol, DockerServiceProtocol -from .base import ( - BaseDockerCommandBuilder, - BaseFormatter, - BaseDockerService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.utils.protocols import DockerServiceProtocol, LoggerProtocol + +from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, dry_run_command, - dry_run_service, + dry_run_command_would_be_executed, dry_run_env_file, + dry_run_mode, + dry_run_service, end_dry_run, - services_restarted_successfully, service_restart_failed, - unknown_error + services_restarted_successfully, + unknown_error, ) + class DockerCommandBuilder(BaseDockerCommandBuilder): @staticmethod def build_restart_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: return BaseDockerCommandBuilder.build_command("restart", name, env_file, compose_file) + class RestartFormatter(BaseFormatter): def format_output(self, result: "RestartResult", output: str) -> str: return super().format_output(result, output, services_restarted_successfully, service_restart_failed) - + def format_dry_run(self, config: "RestartConfig") -> str: dry_run_messages = { "mode": dry_run_mode, @@ -40,29 +36,33 @@ def format_dry_run(self, config: "RestartConfig") -> str: "command": dry_run_command, "service": dry_run_service, "env_file": dry_run_env_file, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + class DockerService(BaseDockerService): def __init__(self, logger: LoggerProtocol): super().__init__(logger, "restart") - + def restart_services(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: return self.execute_services(name, env_file, compose_file) + class RestartResult(BaseResult): pass + class RestartConfig(BaseConfig): pass + class RestartService(BaseService[RestartConfig, RestartResult]): def __init__(self, config: RestartConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): super().__init__(config, logger, docker_service) self.docker_service = docker_service or DockerService(self.logger) self.formatter = RestartFormatter() - + def _create_result(self, success: bool, error: str = None) -> RestartResult: return RestartResult( name=self.config.name, @@ -70,44 +70,41 @@ def _create_result(self, success: bool, error: str = None) -> RestartResult: verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def restart(self) -> RestartResult: return self.execute() - + def execute(self) -> RestartResult: self.logger.debug(f"Restarting services: {self.config.name}") - - success, error = self.docker_service.restart_services( - self.config.name, - self.config.env_file, - self.config.compose_file - ) - + + success, error = self.docker_service.restart_services(self.config.name, self.config.env_file, self.config.compose_file) + return self._create_result(success, error) - + def restart_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Restart(BaseAction[RestartConfig, RestartResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = RestartFormatter() - + def restart(self, config: RestartConfig) -> RestartResult: return self.execute(config) - + def execute(self, config: RestartConfig) -> RestartResult: service = RestartService(config, logger=self.logger) return service.execute() - + def format_output(self, result: RestartResult, output: str) -> str: - return self.formatter.format_output(result, output) \ No newline at end of file + return self.formatter.format_output(result, output) diff --git a/cli/app/commands/service/tests/__init__.py b/cli/app/commands/service/tests/__init__.py index 5998a075..d4839a6b 100644 --- a/cli/app/commands/service/tests/__init__.py +++ b/cli/app/commands/service/tests/__init__.py @@ -1 +1 @@ -# Tests package \ No newline at end of file +# Tests package diff --git a/cli/app/commands/service/tests/test_base.py b/cli/app/commands/service/tests/test_base.py index 2ee247c5..fd92313e 100644 --- a/cli/app/commands/service/tests/test_base.py +++ b/cli/app/commands/service/tests/test_base.py @@ -1,51 +1,52 @@ -import pytest -import subprocess import os +import subprocess from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError from app.commands.service.base import ( + BaseAction, + BaseConfig, BaseDockerCommandBuilder, - BaseFormatter, BaseDockerService, - BaseConfig, + BaseFormatter, BaseResult, BaseService, - BaseAction ) -from app.utils.logger import Logger from app.commands.service.up import UpConfig +from app.utils.logger import Logger class TestBaseDockerCommandBuilder: def test_build_command_up_default(self): cmd = BaseDockerCommandBuilder.build_command("up", "all", None, None, detach=True) assert cmd == ["docker", "compose", "up", "-d"] - + def test_build_command_up_with_service(self): cmd = BaseDockerCommandBuilder.build_command("up", "web", None, None, detach=True) assert cmd == ["docker", "compose", "up", "-d", "web"] - + def test_build_command_up_without_detach(self): cmd = BaseDockerCommandBuilder.build_command("up", "all", None, None, detach=False) assert cmd == ["docker", "compose", "up"] - + def test_build_command_down_default(self): cmd = BaseDockerCommandBuilder.build_command("down", "all", None, None) assert cmd == ["docker", "compose", "down"] - + def test_build_command_down_with_service(self): cmd = BaseDockerCommandBuilder.build_command("down", "web", None, None) assert cmd == ["docker", "compose", "down", "web"] - + def test_build_command_with_env_file(self): cmd = BaseDockerCommandBuilder.build_command("up", "all", "/path/to/.env", None, detach=True) assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] - + def test_build_command_with_compose_file(self): cmd = BaseDockerCommandBuilder.build_command("up", "all", None, "/path/to/docker-compose.yml", detach=True) assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] - + def test_build_command_with_all_parameters(self): cmd = BaseDockerCommandBuilder.build_command("up", "web", "/path/to/.env", "/path/to/docker-compose.yml", detach=False) assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "--env-file", "/path/to/.env", "web"] @@ -54,58 +55,35 @@ def test_build_command_with_all_parameters(self): class TestBaseFormatter: def setup_method(self): self.formatter = BaseFormatter() - + def test_format_output_success(self): - result = BaseResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) + result = BaseResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text", "Services started: {services}", "Service failed: {error}") assert "Services started: web" in formatted - + def test_format_output_failure(self): - result = BaseResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=False, - error="Service not found" - ) + result = BaseResult(name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found") formatted = self.formatter.format_output(result, "text", "Services started: {services}", "Service failed: {error}") assert "Service not found" in formatted - + def test_format_output_json(self): - result = BaseResult( - name="web", - env_file=None, - verbose=False, - output="json", - success=True - ) + result = BaseResult(name="web", env_file=None, verbose=False, output="json", success=True) formatted = self.formatter.format_output(result, "json", "Services started: {services}", "Service failed: {error}") import json + data = json.loads(formatted) assert data["success"] is True assert "Services started: web" in data["message"] - + def test_format_dry_run(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = UpConfig( - name="web", - env_file="/path/to/.env", - dry_run=True, - detach=True - ) - + config = UpConfig(name="web", env_file="/path/to/.env", dry_run=True, detach=True) + class MockCommandBuilder: def build_up_command(self, name, detach, env_file, compose_file): return ["docker", "compose", "up", "-d", "web"] - + dry_run_messages = { "mode": "=== DRY RUN MODE ===", "command_would_be_executed": "The following commands would be executed:", @@ -113,9 +91,9 @@ def build_up_command(self, name, detach, env_file, compose_file): "service": "Service:", "env_file": "Environment file:", "detach_mode": "Detach mode:", - "end": "=== END DRY RUN ===" + "end": "=== END DRY RUN ===", } - + formatted = self.formatter.format_dry_run(config, MockCommandBuilder(), dry_run_messages) assert "=== DRY RUN MODE ===" in formatted assert "Command:" in formatted @@ -127,37 +105,37 @@ def build_up_command(self, name, detach, env_file, compose_file): class TestBaseDockerService: def setup_method(self): self.logger = Mock(spec=Logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_execute_services_success(self, mock_run): mock_run.return_value = Mock(returncode=0) docker_service = BaseDockerService(self.logger, "up") - + success, error = docker_service.execute_services("web") - + assert success is True assert error is None self.logger.info.assert_called_once_with("Uping services: web") self.logger.success.assert_called_once_with("Services upped successfully: web") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_execute_services_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose", stderr="Service not found") docker_service = BaseDockerService(self.logger, "down") - + success, error = docker_service.execute_services("web") - + assert success is False assert error == "Service not found" self.logger.error.assert_called_once_with("Service down failed: Service not found") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_execute_services_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") docker_service = BaseDockerService(self.logger, "up") - + success, error = docker_service.execute_services("web") - + assert success is False assert error == "Unexpected error" self.logger.error.assert_called_once_with("Unexpected error during up: Unexpected error") @@ -172,9 +150,9 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.compose_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = BaseConfig( name="web", @@ -182,7 +160,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - compose_file="/path/to/docker-compose.yml" + compose_file="/path/to/docker-compose.yml", ) assert config.name == "web" assert config.env_file == "/path/to/.env" @@ -190,63 +168,63 @@ def test_valid_config_custom(self): assert config.output == "json" assert config.dry_run is True assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_exists(self, mock_exists): mock_exists.return_value = True config = BaseConfig(env_file="/path/to/.env") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): BaseConfig(env_file="/path/to/.env") - + def test_validate_env_file_none(self): config = BaseConfig(env_file=None) assert config.env_file is None - + def test_validate_env_file_empty(self): config = BaseConfig(env_file="") assert config.env_file is None - + def test_validate_env_file_whitespace(self): config = BaseConfig(env_file=" ") assert config.env_file is None - + def test_validate_env_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = BaseConfig(env_file=" /path/to/.env ") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_exists(self, mock_exists): mock_exists.return_value = True config = BaseConfig(compose_file="/path/to/docker-compose.yml") assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): BaseConfig(compose_file="/path/to/docker-compose.yml") - + def test_validate_compose_file_none(self): config = BaseConfig(compose_file=None) assert config.compose_file is None - + def test_validate_compose_file_empty(self): config = BaseConfig(compose_file="") assert config.compose_file is None - + def test_validate_compose_file_whitespace(self): config = BaseConfig(compose_file=" ") assert config.compose_file is None - + def test_validate_compose_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = BaseConfig(compose_file=" /path/to/docker-compose.yml ") assert config.compose_file == "/path/to/docker-compose.yml" @@ -254,30 +232,18 @@ def test_validate_compose_file_stripped(self): class TestBaseResult: def test_base_result_creation(self): - result = BaseResult( - name="web", - env_file="/path/to/.env", - verbose=True, - output="json", - success=True, - error=None - ) - + result = BaseResult(name="web", env_file="/path/to/.env", verbose=True, output="json", success=True, error=None) + assert result.name == "web" assert result.env_file == "/path/to/.env" assert result.verbose is True assert result.output == "json" assert result.success is True assert result.error is None - + def test_base_result_default_success(self): - result = BaseResult( - name="web", - env_file=None, - verbose=False, - output="text" - ) - + result = BaseResult(name="web", env_file=None, verbose=False, output="text") + assert result.name == "web" assert result.success is False assert result.error is None @@ -285,25 +251,19 @@ def test_base_result_default_success(self): class TestBaseService: def setup_method(self): - self.config = BaseConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) + self.config = BaseConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) self.logger = Mock(spec=Logger) self.docker_service = Mock() self.service = BaseService(self.config, self.logger, self.docker_service) - + def test_create_result_not_implemented(self): with pytest.raises(NotImplementedError): self.service._create_result(True) - + def test_execute_not_implemented(self): with pytest.raises(NotImplementedError): self.service.execute() - + def test_execute_and_format_not_implemented(self): with pytest.raises(NotImplementedError): self.service.execute_and_format() @@ -313,13 +273,13 @@ class TestBaseAction: def setup_method(self): self.logger = Mock(spec=Logger) self.action = BaseAction(self.logger) - + def test_execute_not_implemented(self): config = BaseConfig(name="web") with pytest.raises(NotImplementedError): self.action.execute(config) - + def test_format_output_not_implemented(self): result = BaseResult(name="web", env_file=None, verbose=False, output="text") with pytest.raises(NotImplementedError): - self.action.format_output(result, "text") + self.action.format_output(result, "text") diff --git a/cli/app/commands/service/tests/test_down.py b/cli/app/commands/service/tests/test_down.py index d1696843..6adc33dc 100644 --- a/cli/app/commands/service/tests/test_down.py +++ b/cli/app/commands/service/tests/test_down.py @@ -1,22 +1,23 @@ -import pytest import subprocess from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError from app.commands.service.down import ( DockerCommandBuilder, - DownFormatter, DockerService, - DownResult, + Down, DownConfig, + DownFormatter, + DownResult, DownService, - Down ) from app.commands.service.messages import ( - dry_run_mode, dry_run_command, - dry_run_service, dry_run_env_file, + dry_run_mode, + dry_run_service, services_stopped_successfully, ) from app.utils.logger import Logger @@ -26,19 +27,19 @@ class TestDockerCommandBuilder: def test_build_down_command_default(self): cmd = DockerCommandBuilder.build_down_command() assert cmd == ["docker", "compose", "down"] - + def test_build_down_command_with_service_name(self): cmd = DockerCommandBuilder.build_down_command("web") assert cmd == ["docker", "compose", "down", "web"] - + def test_build_down_command_with_env_file(self): cmd = DockerCommandBuilder.build_down_command("all", "/path/to/.env") assert cmd == ["docker", "compose", "down", "--env-file", "/path/to/.env"] - + def test_build_down_command_with_compose_file(self): cmd = DockerCommandBuilder.build_down_command("all", None, "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down"] - + def test_build_down_command_with_all_parameters(self): cmd = DockerCommandBuilder.build_down_command("api", "/path/to/.env", "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down", "--env-file", "/path/to/.env", "api"] @@ -47,98 +48,58 @@ def test_build_down_command_with_all_parameters(self): class TestDownFormatter: def setup_method(self): self.formatter = DownFormatter() - + def test_format_output_success(self): - result = DownResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) + result = DownResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") expected_message = services_stopped_successfully.format(services="web") assert expected_message in formatted - + def test_format_output_failure(self): - result = DownResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=False, - error="Service not found" - ) + result = DownResult(name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found") formatted = self.formatter.format_output(result, "text") assert "Service not found" in formatted - + def test_format_output_json(self): - result = DownResult( - name="web", - env_file=None, - verbose=False, - output="json", - success=True - ) + result = DownResult(name="web", env_file=None, verbose=False, output="json", success=True) formatted = self.formatter.format_output(result, "json") import json + data = json.loads(formatted) assert data["success"] is True expected_message = services_stopped_successfully.format(services="web") assert expected_message in data["message"] - + def test_format_output_invalid(self): - result = DownResult( - name="web", - env_file=None, - verbose=False, - output="invalid", - success=True - ) + result = DownResult(name="web", env_file=None, verbose=False, output="invalid", success=True) with pytest.raises(ValueError): self.formatter.format_output(result, "invalid") - + def test_format_dry_run_default(self): - config = DownConfig( - name="all", - env_file=None, - dry_run=True - ) + config = DownConfig(name="all", env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_mode in formatted assert dry_run_command in formatted assert dry_run_service.format(service="all") in formatted - + def test_format_dry_run_with_service(self): - config = DownConfig( - name="web", - env_file=None, - dry_run=True - ) + config = DownConfig(name="web", env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_service.format(service="web") in formatted - + def test_format_dry_run_with_env_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = DownConfig( - name="all", - env_file="/path/to/.env", - dry_run=True - ) + config = DownConfig(name="all", env_file="/path/to/.env", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_env_file.format(env_file="/path/to/.env") in formatted - + def test_format_dry_run_with_compose_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = DownConfig( - name="all", - compose_file="/path/to/docker-compose.yml", - dry_run=True - ) + config = DownConfig(name="all", compose_file="/path/to/docker-compose.yml", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert "Command:" in formatted @@ -148,59 +109,59 @@ class TestDockerService: def setup_method(self): self.logger = Mock(spec=Logger) self.docker_service = DockerService(self.logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_stop_services_success(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.stop_services("web") - + assert success is True assert error is None self.logger.info.assert_called_once_with("Downing services: web") self.logger.success.assert_called_once_with("Services downed successfully: web") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_stop_services_with_env_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.stop_services("all", "/path/to/.env") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "down", "--env-file", "/path/to/.env"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_stop_services_with_compose_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.stop_services("all", None, "/path/to/docker-compose.yml") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_stop_services_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose down", stderr="Service not found") - + success, error = self.docker_service.stop_services("web") - + assert success is False assert error == "Service not found" expected_error = "Service down failed: Service not found" self.logger.error.assert_called_once_with(expected_error) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_stop_services_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") - + success, error = self.docker_service.stop_services("web") - + assert success is False assert error == "Unexpected error" expected_error = "Unexpected error during down: Unexpected error" @@ -216,9 +177,9 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.compose_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = DownConfig( name="web", @@ -226,7 +187,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - compose_file="/path/to/docker-compose.yml" + compose_file="/path/to/docker-compose.yml", ) assert config.name == "web" assert config.env_file == "/path/to/.env" @@ -234,63 +195,63 @@ def test_valid_config_custom(self): assert config.output == "json" assert config.dry_run is True assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_exists(self, mock_exists): mock_exists.return_value = True config = DownConfig(env_file="/path/to/.env") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): DownConfig(env_file="/path/to/.env") - + def test_validate_env_file_none(self): config = DownConfig(env_file=None) assert config.env_file is None - + def test_validate_env_file_empty(self): config = DownConfig(env_file="") assert config.env_file is None - + def test_validate_env_file_whitespace(self): config = DownConfig(env_file=" ") assert config.env_file is None - + def test_validate_env_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = DownConfig(env_file=" /path/to/.env ") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_exists(self, mock_exists): mock_exists.return_value = True config = DownConfig(compose_file="/path/to/docker-compose.yml") assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): DownConfig(compose_file="/path/to/docker-compose.yml") - + def test_validate_compose_file_none(self): config = DownConfig(compose_file=None) assert config.compose_file is None - + def test_validate_compose_file_empty(self): config = DownConfig(compose_file="") assert config.compose_file is None - + def test_validate_compose_file_whitespace(self): config = DownConfig(compose_file=" ") assert config.compose_file is None - + def test_validate_compose_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = DownConfig(compose_file=" /path/to/docker-compose.yml ") assert config.compose_file == "/path/to/docker-compose.yml" @@ -298,17 +259,11 @@ def test_validate_compose_file_stripped(self): class TestDownService: def setup_method(self): - self.config = DownConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) + self.config = DownConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) self.logger = Mock(spec=Logger) self.docker_service = Mock() self.service = DownService(self.config, self.logger, self.docker_service) - + def test_create_result_success(self): result = self.service._create_result(True) assert result.name == "web" @@ -316,35 +271,35 @@ def test_create_result_success(self): assert result.error is None assert result.output == "text" assert result.verbose is False - + def test_create_result_failure(self): result = self.service._create_result(False, "Service not found") assert result.success is False assert result.error == "Service not found" - + def test_down_success(self): self.docker_service.stop_services.return_value = (True, None) - + result = self.service.down() - + assert result.success is True assert result.error is None self.docker_service.stop_services.assert_called_once_with("web", None, None) - + def test_down_failure(self): self.docker_service.stop_services.return_value = (False, "Service not found") - + result = self.service.down() - + assert result.success is False assert result.error == "Service not found" - + def test_down_and_format_dry_run(self): self.config.dry_run = True formatted = self.service.down_and_format() assert dry_run_mode in formatted assert dry_run_command in formatted - + def test_down_and_format_success(self): self.docker_service.stop_services.return_value = (True, None) formatted = self.service.down_and_format() @@ -356,55 +311,37 @@ class TestDown: def setup_method(self): self.logger = Mock(spec=Logger) self.down = Down(self.logger) - + def test_down_success(self): - config = DownConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) - - with patch('app.commands.service.down.DockerService') as mock_docker_service_class: + config = DownConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) + + with patch("app.commands.service.down.DockerService") as mock_docker_service_class: mock_docker_service = Mock() mock_docker_service.stop_services.return_value = (True, None) mock_docker_service_class.return_value = mock_docker_service - + result = self.down.down(config) - + assert result.success is True assert result.error is None assert result.name == "web" - + def test_down_failure(self): - config = DownConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) - - with patch('app.commands.service.down.DockerService') as mock_docker_service_class: + config = DownConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) + + with patch("app.commands.service.down.DockerService") as mock_docker_service_class: mock_docker_service = Mock() mock_docker_service.stop_services.return_value = (False, "Service not found") mock_docker_service_class.return_value = mock_docker_service - + result = self.down.down(config) - + assert result.success is False assert result.error == "Service not found" - + def test_format_output(self): - result = DownResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) - + result = DownResult(name="web", env_file=None, verbose=False, output="text", success=True) + formatted = self.down.format_output(result, "text") expected_message = services_stopped_successfully.format(services="web") assert expected_message in formatted @@ -412,30 +349,18 @@ def test_format_output(self): class TestDownResult: def test_down_result_creation(self): - result = DownResult( - name="web", - env_file="/path/to/.env", - verbose=True, - output="json", - success=True, - error=None - ) - + result = DownResult(name="web", env_file="/path/to/.env", verbose=True, output="json", success=True, error=None) + assert result.name == "web" assert result.env_file == "/path/to/.env" assert result.verbose is True assert result.output == "json" assert result.success is True assert result.error is None - + def test_down_result_default_success(self): - result = DownResult( - name="web", - env_file=None, - verbose=False, - output="text" - ) - + result = DownResult(name="web", env_file=None, verbose=False, output="text") + assert result.name == "web" assert result.success is False - assert result.error is None + assert result.error is None diff --git a/cli/app/commands/service/tests/test_ps.py b/cli/app/commands/service/tests/test_ps.py index 5262748a..e709b946 100644 --- a/cli/app/commands/service/tests/test_ps.py +++ b/cli/app/commands/service/tests/test_ps.py @@ -1,29 +1,22 @@ -import pytest -import subprocess import os +import subprocess from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError -from app.commands.service.ps import ( - DockerCommandBuilder, - PsFormatter, - DockerService, - PsResult, - PsConfig, - PsService, - Ps -) from app.commands.service.messages import ( - dry_run_mode, - dry_run_command_would_be_executed, dry_run_command, - dry_run_service, + dry_run_command_would_be_executed, dry_run_env_file, + dry_run_mode, + dry_run_service, end_dry_run, - services_status_retrieved, service_status_failed, - unknown_error + services_status_retrieved, + unknown_error, ) +from app.commands.service.ps import DockerCommandBuilder, DockerService, Ps, PsConfig, PsFormatter, PsResult, PsService from app.utils.logger import Logger @@ -31,19 +24,19 @@ class TestDockerCommandBuilder: def test_build_ps_command_default(self): cmd = DockerCommandBuilder.build_ps_command() assert cmd == ["docker", "compose", "ps"] - + def test_build_ps_command_with_service_name(self): cmd = DockerCommandBuilder.build_ps_command("web") assert cmd == ["docker", "compose", "ps", "web"] - + def test_build_ps_command_with_env_file(self): cmd = DockerCommandBuilder.build_ps_command("all", "/path/to/.env") assert cmd == ["docker", "compose", "ps", "--env-file", "/path/to/.env"] - + def test_build_ps_command_with_compose_file(self): cmd = DockerCommandBuilder.build_ps_command("all", None, "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps"] - + def test_build_ps_command_with_all_parameters(self): cmd = DockerCommandBuilder.build_ps_command("api", "/path/to/.env", "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps", "--env-file", "/path/to/.env", "api"] @@ -52,98 +45,58 @@ def test_build_ps_command_with_all_parameters(self): class TestPsFormatter: def setup_method(self): self.formatter = PsFormatter() - + def test_format_output_success(self): - result = PsResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) + result = PsResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") expected_message = services_status_retrieved.format(services="web") assert expected_message in formatted - + def test_format_output_failure(self): - result = PsResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=False, - error="Service not found" - ) + result = PsResult(name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found") formatted = self.formatter.format_output(result, "text") assert "Service not found" in formatted - + def test_format_output_json(self): - result = PsResult( - name="web", - env_file=None, - verbose=False, - output="json", - success=True - ) + result = PsResult(name="web", env_file=None, verbose=False, output="json", success=True) formatted = self.formatter.format_output(result, "json") import json + data = json.loads(formatted) assert data["success"] is True expected_message = services_status_retrieved.format(services="web") assert expected_message in data["message"] - + def test_format_output_invalid(self): - result = PsResult( - name="web", - env_file=None, - verbose=False, - output="invalid", - success=True - ) + result = PsResult(name="web", env_file=None, verbose=False, output="invalid", success=True) with pytest.raises(ValueError): self.formatter.format_output(result, "invalid") - + def test_format_dry_run_default(self): - config = PsConfig( - name="all", - env_file=None, - dry_run=True - ) + config = PsConfig(name="all", env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_mode in formatted assert dry_run_command in formatted assert dry_run_service.format(service="all") in formatted - + def test_format_dry_run_with_service(self): - config = PsConfig( - name="web", - env_file=None, - dry_run=True - ) + config = PsConfig(name="web", env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_service.format(service="web") in formatted - + def test_format_dry_run_with_env_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = PsConfig( - name="all", - env_file="/path/to/.env", - dry_run=True - ) + config = PsConfig(name="all", env_file="/path/to/.env", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_env_file.format(env_file="/path/to/.env") in formatted - + def test_format_dry_run_with_compose_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = PsConfig( - name="all", - compose_file="/path/to/docker-compose.yml", - dry_run=True - ) + config = PsConfig(name="all", compose_file="/path/to/docker-compose.yml", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert "Command:" in formatted @@ -153,59 +106,59 @@ class TestDockerService: def setup_method(self): self.logger = Mock(spec=Logger) self.docker_service = DockerService(self.logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_show_services_status_success(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.show_services_status("web") - + assert success is True assert error is None self.logger.info.assert_called_once_with("Psing services: web") self.logger.success.assert_called_once_with("Services psed successfully: web") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_show_services_status_with_env_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.show_services_status("all", "/path/to/.env") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "ps", "--env-file", "/path/to/.env"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_show_services_status_with_compose_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.show_services_status("all", None, "/path/to/docker-compose.yml") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_show_services_status_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose ps", stderr="Service not found") - + success, error = self.docker_service.show_services_status("web") - + assert success is False assert error == "Service not found" expected_error = "Service ps failed: Service not found" self.logger.error.assert_called_once_with(expected_error) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_show_services_status_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") - + success, error = self.docker_service.show_services_status("web") - + assert success is False assert error == "Unexpected error" expected_error = "Unexpected error during ps: Unexpected error" @@ -221,9 +174,9 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.compose_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = PsConfig( name="web", @@ -231,7 +184,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - compose_file="/path/to/docker-compose.yml" + compose_file="/path/to/docker-compose.yml", ) assert config.name == "web" assert config.env_file == "/path/to/.env" @@ -239,63 +192,63 @@ def test_valid_config_custom(self): assert config.output == "json" assert config.dry_run is True assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_exists(self, mock_exists): mock_exists.return_value = True config = PsConfig(env_file="/path/to/.env") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): PsConfig(env_file="/path/to/.env") - + def test_validate_env_file_none(self): config = PsConfig(env_file=None) assert config.env_file is None - + def test_validate_env_file_empty(self): config = PsConfig(env_file="") assert config.env_file is None - + def test_validate_env_file_whitespace(self): config = PsConfig(env_file=" ") assert config.env_file is None - + def test_validate_env_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = PsConfig(env_file=" /path/to/.env ") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_exists(self, mock_exists): mock_exists.return_value = True config = PsConfig(compose_file="/path/to/docker-compose.yml") assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): PsConfig(compose_file="/path/to/docker-compose.yml") - + def test_validate_compose_file_none(self): config = PsConfig(compose_file=None) assert config.compose_file is None - + def test_validate_compose_file_empty(self): config = PsConfig(compose_file="") assert config.compose_file is None - + def test_validate_compose_file_whitespace(self): config = PsConfig(compose_file=" ") assert config.compose_file is None - + def test_validate_compose_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = PsConfig(compose_file=" /path/to/docker-compose.yml ") assert config.compose_file == "/path/to/docker-compose.yml" @@ -303,17 +256,11 @@ def test_validate_compose_file_stripped(self): class TestPsService: def setup_method(self): - self.config = PsConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) + self.config = PsConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) self.logger = Mock(spec=Logger) self.docker_service = Mock() self.service = PsService(self.config, self.logger, self.docker_service) - + def test_create_result_success(self): result = self.service._create_result(True) assert result.name == "web" @@ -321,35 +268,35 @@ def test_create_result_success(self): assert result.error is None assert result.output == "text" assert result.verbose is False - + def test_create_result_failure(self): result = self.service._create_result(False, "Service not found") assert result.success is False assert result.error == "Service not found" - + def test_ps_success(self): self.docker_service.show_services_status.return_value = (True, None) - + result = self.service.ps() - + assert result.success is True assert result.error is None self.docker_service.show_services_status.assert_called_once_with("web", None, None) - + def test_ps_failure(self): self.docker_service.show_services_status.return_value = (False, "Service not found") - + result = self.service.ps() - + assert result.success is False assert result.error == "Service not found" - + def test_ps_and_format_dry_run(self): self.config.dry_run = True formatted = self.service.ps_and_format() assert dry_run_mode in formatted assert dry_run_command in formatted - + def test_ps_and_format_success(self): self.docker_service.show_services_status.return_value = (True, None) formatted = self.service.ps_and_format() @@ -361,56 +308,40 @@ class TestPs: def setup_method(self): self.logger = Mock(spec=Logger) self.ps = Ps(self.logger) - + def test_ps_success(self): - config = PsConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) - - with patch("app.commands.service.ps.PsService.execute", return_value=PsResult( - name=config.name, - env_file=config.env_file, - verbose=config.verbose, - output=config.output, - success=True - )): + config = PsConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) + + with patch( + "app.commands.service.ps.PsService.execute", + return_value=PsResult( + name=config.name, env_file=config.env_file, verbose=config.verbose, output=config.output, success=True + ), + ): result = self.ps.ps(config) assert result.success is True - + def test_ps_failure(self): - config = PsConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) - - with patch("app.commands.service.ps.PsService.execute", return_value=PsResult( - name=config.name, - env_file=config.env_file, - verbose=config.verbose, - output=config.output, - success=False, - error="Service not found" - )): + config = PsConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) + + with patch( + "app.commands.service.ps.PsService.execute", + return_value=PsResult( + name=config.name, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=False, + error="Service not found", + ), + ): result = self.ps.ps(config) assert result.success is False assert result.error == "Service not found" - + def test_format_output(self): - result = PsResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) - + result = PsResult(name="web", env_file=None, verbose=False, output="text", success=True) + formatted = self.ps.format_output(result, "text") expected_message = services_status_retrieved.format(services="web") assert expected_message in formatted @@ -418,30 +349,18 @@ def test_format_output(self): class TestPsResult: def test_ps_result_creation(self): - result = PsResult( - name="web", - env_file="/path/to/.env", - verbose=True, - output="json", - success=True, - error=None - ) - + result = PsResult(name="web", env_file="/path/to/.env", verbose=True, output="json", success=True, error=None) + assert result.name == "web" assert result.env_file == "/path/to/.env" assert result.verbose is True assert result.output == "json" assert result.success is True assert result.error is None - + def test_ps_result_default_success(self): - result = PsResult( - name="web", - env_file=None, - verbose=False, - output="text" - ) - + result = PsResult(name="web", env_file=None, verbose=False, output="text") + assert result.name == "web" assert result.success is False - assert result.error is None + assert result.error is None diff --git a/cli/app/commands/service/tests/test_restart.py b/cli/app/commands/service/tests/test_restart.py index 700a373b..3cb23c98 100644 --- a/cli/app/commands/service/tests/test_restart.py +++ b/cli/app/commands/service/tests/test_restart.py @@ -1,28 +1,29 @@ -import pytest -import subprocess import os +import subprocess from unittest.mock import Mock, patch + +import pytest from pydantic import ValidationError -from app.commands.service.restart import ( - DockerCommandBuilder, - RestartFormatter, - DockerService, - RestartResult, - RestartConfig, - RestartService, - Restart -) from app.commands.service.messages import ( - dry_run_mode, - dry_run_command_would_be_executed, dry_run_command, - dry_run_service, + dry_run_command_would_be_executed, dry_run_env_file, + dry_run_mode, + dry_run_service, end_dry_run, - services_restarted_successfully, service_restart_failed, - unknown_error + services_restarted_successfully, + unknown_error, +) +from app.commands.service.restart import ( + DockerCommandBuilder, + DockerService, + Restart, + RestartConfig, + RestartFormatter, + RestartResult, + RestartService, ) from app.utils.logger import Logger @@ -31,119 +32,90 @@ class TestDockerCommandBuilder: def test_build_restart_command_default(self): cmd = DockerCommandBuilder.build_restart_command() assert cmd == ["docker", "compose", "restart"] - + def test_build_restart_command_with_service_name(self): cmd = DockerCommandBuilder.build_restart_command("web") assert cmd == ["docker", "compose", "restart", "web"] - + def test_build_restart_command_with_env_file(self): cmd = DockerCommandBuilder.build_restart_command("all", "/path/to/.env") assert cmd == ["docker", "compose", "restart", "--env-file", "/path/to/.env"] - + def test_build_restart_command_with_compose_file(self): cmd = DockerCommandBuilder.build_restart_command("all", None, "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart"] - + def test_build_restart_command_with_all_parameters(self): cmd = DockerCommandBuilder.build_restart_command("api", "/path/to/.env", "/path/to/docker-compose.yml") - assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart", "--env-file", "/path/to/.env", "api"] + assert cmd == [ + "docker", + "compose", + "-f", + "/path/to/docker-compose.yml", + "restart", + "--env-file", + "/path/to/.env", + "api", + ] class TestRestartFormatter: def setup_method(self): self.formatter = RestartFormatter() - + def test_format_output_success(self): - result = RestartResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) + result = RestartResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") expected_message = services_restarted_successfully.format(services="web") assert expected_message in formatted - + def test_format_output_failure(self): result = RestartResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=False, - error="Service not found" + name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found" ) formatted = self.formatter.format_output(result, "text") assert "Service not found" in formatted - + def test_format_output_json(self): - result = RestartResult( - name="web", - env_file=None, - verbose=False, - output="json", - success=True - ) + result = RestartResult(name="web", env_file=None, verbose=False, output="json", success=True) formatted = self.formatter.format_output(result, "json") import json + data = json.loads(formatted) assert data["success"] is True expected_message = services_restarted_successfully.format(services="web") assert expected_message in data["message"] - + def test_format_output_invalid(self): - result = RestartResult( - name="web", - env_file=None, - verbose=False, - output="invalid", - success=True - ) + result = RestartResult(name="web", env_file=None, verbose=False, output="invalid", success=True) with pytest.raises(ValueError): self.formatter.format_output(result, "invalid") - + def test_format_dry_run_default(self): - config = RestartConfig( - name="all", - env_file=None, - dry_run=True - ) + config = RestartConfig(name="all", env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_mode in formatted assert dry_run_command in formatted assert dry_run_service.format(service="all") in formatted - + def test_format_dry_run_with_service(self): - config = RestartConfig( - name="web", - env_file=None, - dry_run=True - ) + config = RestartConfig(name="web", env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_service.format(service="web") in formatted - + def test_format_dry_run_with_env_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = RestartConfig( - name="all", - env_file="/path/to/.env", - dry_run=True - ) + config = RestartConfig(name="all", env_file="/path/to/.env", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_env_file.format(env_file="/path/to/.env") in formatted - + def test_format_dry_run_with_compose_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = RestartConfig( - name="all", - compose_file="/path/to/docker-compose.yml", - dry_run=True - ) + config = RestartConfig(name="all", compose_file="/path/to/docker-compose.yml", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert "Command:" in formatted @@ -153,59 +125,59 @@ class TestDockerService: def setup_method(self): self.logger = Mock(spec=Logger) self.docker_service = DockerService(self.logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_restart_services_success(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.restart_services("web") - + assert success is True assert error is None self.logger.info.assert_called_once_with("Restarting services: web") self.logger.success.assert_called_once_with("Services restarted successfully: web") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_restart_services_with_env_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.restart_services("all", "/path/to/.env") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "restart", "--env-file", "/path/to/.env"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_restart_services_with_compose_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.restart_services("all", None, "/path/to/docker-compose.yml") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_restart_services_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose restart", stderr="Service not found") - + success, error = self.docker_service.restart_services("web") - + assert success is False assert error == "Service not found" expected_error = "Service restart failed: Service not found" self.logger.error.assert_called_once_with(expected_error) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_restart_services_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") - + success, error = self.docker_service.restart_services("web") - + assert success is False assert error == "Unexpected error" expected_error = "Unexpected error during restart: Unexpected error" @@ -221,9 +193,9 @@ def test_valid_config_default(self): assert config.output == "text" assert config.dry_run is False assert config.compose_file is None - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = RestartConfig( name="web", @@ -231,7 +203,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - compose_file="/path/to/docker-compose.yml" + compose_file="/path/to/docker-compose.yml", ) assert config.name == "web" assert config.env_file == "/path/to/.env" @@ -239,63 +211,63 @@ def test_valid_config_custom(self): assert config.output == "json" assert config.dry_run is True assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_exists(self, mock_exists): mock_exists.return_value = True config = RestartConfig(env_file="/path/to/.env") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): RestartConfig(env_file="/path/to/.env") - + def test_validate_env_file_none(self): config = RestartConfig(env_file=None) assert config.env_file is None - + def test_validate_env_file_empty(self): config = RestartConfig(env_file="") assert config.env_file is None - + def test_validate_env_file_whitespace(self): config = RestartConfig(env_file=" ") assert config.env_file is None - + def test_validate_env_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = RestartConfig(env_file=" /path/to/.env ") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_exists(self, mock_exists): mock_exists.return_value = True config = RestartConfig(compose_file="/path/to/docker-compose.yml") assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): RestartConfig(compose_file="/path/to/docker-compose.yml") - + def test_validate_compose_file_none(self): config = RestartConfig(compose_file=None) assert config.compose_file is None - + def test_validate_compose_file_empty(self): config = RestartConfig(compose_file="") assert config.compose_file is None - + def test_validate_compose_file_whitespace(self): config = RestartConfig(compose_file=" ") assert config.compose_file is None - + def test_validate_compose_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = RestartConfig(compose_file=" /path/to/docker-compose.yml ") assert config.compose_file == "/path/to/docker-compose.yml" @@ -303,17 +275,11 @@ def test_validate_compose_file_stripped(self): class TestRestartService: def setup_method(self): - self.config = RestartConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) + self.config = RestartConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) self.logger = Mock(spec=Logger) self.docker_service = Mock() self.service = RestartService(self.config, self.logger, self.docker_service) - + def test_create_result_success(self): result = self.service._create_result(True) assert result.name == "web" @@ -321,35 +287,35 @@ def test_create_result_success(self): assert result.error is None assert result.output == "text" assert result.verbose is False - + def test_create_result_failure(self): result = self.service._create_result(False, "Service not found") assert result.success is False assert result.error == "Service not found" - + def test_restart_success(self): self.docker_service.restart_services.return_value = (True, None) - + result = self.service.restart() - + assert result.success is True assert result.error is None self.docker_service.restart_services.assert_called_once_with("web", None, None) - + def test_restart_failure(self): self.docker_service.restart_services.return_value = (False, "Service not found") - + result = self.service.restart() - + assert result.success is False assert result.error == "Service not found" - + def test_restart_and_format_dry_run(self): self.config.dry_run = True formatted = self.service.restart_and_format() assert dry_run_mode in formatted assert dry_run_command in formatted - + def test_restart_and_format_success(self): self.docker_service.restart_services.return_value = (True, None) formatted = self.service.restart_and_format() @@ -361,56 +327,40 @@ class TestRestart: def setup_method(self): self.logger = Mock(spec=Logger) self.restart = Restart(self.logger) - + def test_restart_success(self): - config = RestartConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) - - with patch("app.commands.service.restart.RestartService.execute", return_value=RestartResult( - name=config.name, - env_file=config.env_file, - verbose=config.verbose, - output=config.output, - success=True - )): + config = RestartConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) + + with patch( + "app.commands.service.restart.RestartService.execute", + return_value=RestartResult( + name=config.name, env_file=config.env_file, verbose=config.verbose, output=config.output, success=True + ), + ): result = self.restart.restart(config) assert result.success is True - + def test_restart_failure(self): - config = RestartConfig( - name="web", - env_file=None, - verbose=False, - output="text", - dry_run=False - ) - - with patch("app.commands.service.restart.RestartService.execute", return_value=RestartResult( - name=config.name, - env_file=config.env_file, - verbose=config.verbose, - output=config.output, - success=False, - error="Service not found" - )): + config = RestartConfig(name="web", env_file=None, verbose=False, output="text", dry_run=False) + + with patch( + "app.commands.service.restart.RestartService.execute", + return_value=RestartResult( + name=config.name, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=False, + error="Service not found", + ), + ): result = self.restart.restart(config) assert result.success is False assert result.error == "Service not found" - + def test_format_output(self): - result = RestartResult( - name="web", - env_file=None, - verbose=False, - output="text", - success=True - ) - + result = RestartResult(name="web", env_file=None, verbose=False, output="text", success=True) + formatted = self.restart.format_output(result, "text") expected_message = services_restarted_successfully.format(services="web") assert expected_message in formatted @@ -418,30 +368,18 @@ def test_format_output(self): class TestRestartResult: def test_restart_result_creation(self): - result = RestartResult( - name="web", - env_file="/path/to/.env", - verbose=True, - output="json", - success=True, - error=None - ) - + result = RestartResult(name="web", env_file="/path/to/.env", verbose=True, output="json", success=True, error=None) + assert result.name == "web" assert result.env_file == "/path/to/.env" assert result.verbose is True assert result.output == "json" assert result.success is True assert result.error is None - + def test_restart_result_default_success(self): - result = RestartResult( - name="web", - env_file=None, - verbose=False, - output="text" - ) - + result = RestartResult(name="web", env_file=None, verbose=False, output="text") + assert result.name == "web" assert result.success is False - assert result.error is None + assert result.error is None diff --git a/cli/app/commands/service/tests/test_up.py b/cli/app/commands/service/tests/test_up.py index dd27c213..a03ef82c 100644 --- a/cli/app/commands/service/tests/test_up.py +++ b/cli/app/commands/service/tests/test_up.py @@ -1,26 +1,19 @@ -import pytest -import subprocess import os -from unittest.mock import Mock, patch, MagicMock +import subprocess +from unittest.mock import MagicMock, Mock, patch + +import pytest from pydantic import ValidationError -from app.commands.service.up import ( - DockerCommandBuilder, - UpFormatter, - DockerService, - UpResult, - UpConfig, - UpService, - Up -) from app.commands.service.messages import ( - dry_run_mode, dry_run_command, - dry_run_service, dry_run_detach_mode, dry_run_env_file, + dry_run_mode, + dry_run_service, services_started_successfully, ) +from app.commands.service.up import DockerCommandBuilder, DockerService, Up, UpConfig, UpFormatter, UpResult, UpService from app.utils.logger import Logger @@ -28,23 +21,23 @@ class TestDockerCommandBuilder: def test_build_up_command_default(self): cmd = DockerCommandBuilder.build_up_command() assert cmd == ["docker", "compose", "up", "-d"] - + def test_build_up_command_with_service_name(self): cmd = DockerCommandBuilder.build_up_command("web") assert cmd == ["docker", "compose", "up", "-d", "web"] - + def test_build_up_command_without_detach(self): cmd = DockerCommandBuilder.build_up_command("all", detach=False) assert cmd == ["docker", "compose", "up"] - + def test_build_up_command_with_env_file(self): cmd = DockerCommandBuilder.build_up_command("all", True, "/path/to/.env") assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] - + def test_build_up_command_with_compose_file(self): cmd = DockerCommandBuilder.build_up_command("all", True, None, "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] - + def test_build_up_command_with_all_parameters(self): cmd = DockerCommandBuilder.build_up_command("api", False, "/path/to/.env", "/path/to/docker-compose.yml") assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "--env-file", "/path/to/.env", "api"] @@ -53,108 +46,62 @@ def test_build_up_command_with_all_parameters(self): class TestUpFormatter: def setup_method(self): self.formatter = UpFormatter() - + def test_format_output_success(self): - result = UpResult( - name="web", - detach=True, - env_file=None, - verbose=False, - output="text", - success=True - ) + result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") expected_message = services_started_successfully.format(services="web") assert expected_message in formatted - + def test_format_output_failure(self): result = UpResult( - name="web", - detach=True, - env_file=None, - verbose=False, - output="text", - success=False, - error="Service not found" + name="web", detach=True, env_file=None, verbose=False, output="text", success=False, error="Service not found" ) formatted = self.formatter.format_output(result, "text") assert "Service not found" in formatted - + def test_format_output_json(self): - result = UpResult( - name="web", - detach=True, - env_file=None, - verbose=False, - output="json", - success=True - ) + result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="json", success=True) formatted = self.formatter.format_output(result, "json") import json + data = json.loads(formatted) assert data["success"] is True expected_message = services_started_successfully.format(services="web") assert expected_message in data["message"] - + def test_format_output_invalid(self): - result = UpResult( - name="web", - detach=True, - env_file=None, - verbose=False, - output="invalid", - success=True - ) + result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="invalid", success=True) with pytest.raises(ValueError): self.formatter.format_output(result, "invalid") - + def test_format_dry_run_default(self): - config = UpConfig( - name="all", - detach=True, - env_file=None, - dry_run=True - ) + config = UpConfig(name="all", detach=True, env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_mode in formatted assert dry_run_command in formatted assert dry_run_service.format(service="all") in formatted assert dry_run_detach_mode.format(detach=True) in formatted - + def test_format_dry_run_with_service(self): - config = UpConfig( - name="web", - detach=False, - env_file=None, - dry_run=True - ) + config = UpConfig(name="web", detach=False, env_file=None, dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_service.format(service="web") in formatted assert dry_run_detach_mode.format(detach=False) in formatted - + def test_format_dry_run_with_env_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = UpConfig( - name="all", - detach=True, - env_file="/path/to/.env", - dry_run=True - ) + config = UpConfig(name="all", detach=True, env_file="/path/to/.env", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert dry_run_env_file.format(env_file="/path/to/.env") in formatted - + def test_format_dry_run_with_compose_file(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True - config = UpConfig( - name="all", - detach=True, - compose_file="/path/to/docker-compose.yml", - dry_run=True - ) + config = UpConfig(name="all", detach=True, compose_file="/path/to/docker-compose.yml", dry_run=True) formatted = self.formatter.format_dry_run(config) assert dry_run_command in formatted assert "Command:" in formatted @@ -164,43 +111,43 @@ class TestDockerService: def setup_method(self): self.logger = Mock(spec=Logger) self.docker_service = DockerService(self.logger) - - @patch('subprocess.run') + + @patch("subprocess.run") def test_start_services_success(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.start_services("web") - + assert success is True assert error is None self.logger.info.assert_called_once_with("Uping services: web") self.logger.success.assert_called_once_with("Services upped successfully: web") - - @patch('subprocess.run') + + @patch("subprocess.run") def test_start_services_with_env_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.start_services("all", True, "/path/to/.env") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_start_services_with_compose_file(self, mock_run): mock_run.return_value = Mock(returncode=0) - + success, error = self.docker_service.start_services("all", True, None, "/path/to/docker-compose.yml") - + assert success is True assert error is None mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] - - @patch('subprocess.run') + + @patch("subprocess.run") def test_start_services_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose", stderr="Service not found") success, error = self.docker_service.start_services("web") @@ -209,7 +156,7 @@ def test_start_services_failure(self, mock_run): expected_error = "Service up failed: Service not found" self.logger.error.assert_called_once_with(expected_error) - @patch('subprocess.run') + @patch("subprocess.run") def test_start_services_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") success, error = self.docker_service.start_services("web") @@ -228,9 +175,9 @@ def test_valid_config_default(self): assert config.verbose is False assert config.output == "text" assert config.dry_run is False - + def test_valid_config_custom(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = UpConfig( name="web", @@ -239,7 +186,7 @@ def test_valid_config_custom(self): verbose=True, output="json", dry_run=True, - compose_file="/path/to/docker-compose.yml" + compose_file="/path/to/docker-compose.yml", ) assert config.name == "web" assert config.detach is False @@ -248,63 +195,63 @@ def test_valid_config_custom(self): assert config.output == "json" assert config.dry_run is True assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_exists(self, mock_exists): mock_exists.return_value = True config = UpConfig(env_file="/path/to/.env") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_env_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): UpConfig(env_file="/path/to/.env") - + def test_validate_env_file_none(self): config = UpConfig(env_file=None) assert config.env_file is None - + def test_validate_env_file_empty(self): config = UpConfig(env_file="") assert config.env_file is None - + def test_validate_env_file_whitespace(self): config = UpConfig(env_file=" ") assert config.env_file is None - + def test_validate_env_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = UpConfig(env_file=" /path/to/.env ") assert config.env_file == "/path/to/.env" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_exists(self, mock_exists): mock_exists.return_value = True config = UpConfig(compose_file="/path/to/docker-compose.yml") assert config.compose_file == "/path/to/docker-compose.yml" - - @patch('os.path.exists') + + @patch("os.path.exists") def test_validate_compose_file_not_exists(self, mock_exists): mock_exists.return_value = False with pytest.raises(ValidationError): UpConfig(compose_file="/path/to/docker-compose.yml") - + def test_validate_compose_file_none(self): config = UpConfig(compose_file=None) assert config.compose_file is None - + def test_validate_compose_file_empty(self): config = UpConfig(compose_file="") assert config.compose_file is None - + def test_validate_compose_file_whitespace(self): config = UpConfig(compose_file=" ") assert config.compose_file is None - + def test_validate_compose_file_stripped(self): - with patch('os.path.exists') as mock_exists: + with patch("os.path.exists") as mock_exists: mock_exists.return_value = True config = UpConfig(compose_file=" /path/to/docker-compose.yml ") assert config.compose_file == "/path/to/docker-compose.yml" @@ -312,19 +259,14 @@ def test_validate_compose_file_stripped(self): class TestUpService: def setup_method(self): - self.config = UpConfig( - name="web", - detach=True, - env_file=None, - compose_file=None - ) + self.config = UpConfig(name="web", detach=True, env_file=None, compose_file=None) self.logger = Mock(spec=Logger) self.docker_service = Mock() self.service = UpService(self.config, self.logger, self.docker_service) - + def test_create_result_success(self): result = self.service._create_result(True) - + assert result.name == self.config.name assert result.detach == self.config.detach assert result.env_file == self.config.env_file @@ -332,46 +274,43 @@ def test_create_result_success(self): assert result.output == self.config.output assert result.success is True assert result.error is None - + def test_create_result_failure(self): result = self.service._create_result(False, "Test error") - + assert result.success is False assert result.error == "Test error" - + def test_up_success(self): self.docker_service.start_services.return_value = (True, None) - + result = self.service.up() - + assert result.success is True self.docker_service.start_services.assert_called_once_with( - self.config.name, - self.config.detach, - self.config.env_file, - self.config.compose_file + self.config.name, self.config.detach, self.config.env_file, self.config.compose_file ) - + def test_up_failure(self): self.docker_service.start_services.return_value = (False, "Test error") - + result = self.service.up() - + assert result.success is False assert result.error == "Test error" - + def test_up_and_format_dry_run(self): self.config.dry_run = True - + result = self.service.up_and_format() - + assert dry_run_mode in result - + def test_up_and_format_success(self): self.docker_service.start_services.return_value = (True, None) - + result = self.service.up_and_format() - + expected_message = services_started_successfully.format(services="web") assert expected_message in result @@ -380,36 +319,28 @@ class TestUp: def setup_method(self): self.logger = Mock(spec=Logger) self.up = Up(self.logger) - + def test_up_success(self): - config = UpConfig( - name="web", - detach=True, - env_file=None - ) - with patch("app.commands.service.up.UpService.execute", return_value=UpResult( - name=config.name, - detach=config.detach, - env_file=config.env_file, - verbose=config.verbose, - output=config.output, - success=True - )): + config = UpConfig(name="web", detach=True, env_file=None) + with patch( + "app.commands.service.up.UpService.execute", + return_value=UpResult( + name=config.name, + detach=config.detach, + env_file=config.env_file, + verbose=config.verbose, + output=config.output, + success=True, + ), + ): result = self.up.up(config) assert result.success is True - + def test_format_output(self): - result = UpResult( - name="web", - detach=True, - env_file=None, - verbose=False, - output="text", - success=True - ) - + result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="text", success=True) + formatted = self.up.format_output(result, "text") - + expected_message = services_started_successfully.format(services="web") assert expected_message in formatted @@ -417,15 +348,9 @@ def test_format_output(self): class TestUpResult: def test_up_result_creation(self): result = UpResult( - name="web", - detach=True, - env_file="/path/to/.env", - verbose=True, - output="json", - success=True, - error=None + name="web", detach=True, env_file="/path/to/.env", verbose=True, output="json", success=True, error=None ) - + assert result.name == "web" assert result.detach is True assert result.env_file == "/path/to/.env" @@ -433,15 +358,9 @@ def test_up_result_creation(self): assert result.output == "json" assert result.success is True assert result.error is None - + def test_up_result_default_success(self): - result = UpResult( - name="web", - detach=True, - env_file=None, - verbose=False, - output="text" - ) - + result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="text") + assert result.success is False assert result.error is None diff --git a/cli/app/commands/service/up.py b/cli/app/commands/service/up.py index afbe642b..2ff3a09f 100644 --- a/cli/app/commands/service/up.py +++ b/cli/app/commands/service/up.py @@ -1,45 +1,43 @@ -import subprocess import os -from typing import Protocol, Optional +import subprocess +from typing import Optional, Protocol + from pydantic import BaseModel, Field, field_validator from app.utils.logger import Logger -from app.utils.protocols import LoggerProtocol from app.utils.output_formatter import OutputFormatter -from .base import ( - BaseDockerCommandBuilder, - BaseFormatter, - BaseDockerService, - BaseConfig, - BaseResult, - BaseService, - BaseAction -) +from app.utils.protocols import LoggerProtocol + +from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService from .messages import ( - dry_run_mode, - dry_run_command_would_be_executed, dry_run_command, - dry_run_service, + dry_run_command_would_be_executed, dry_run_detach_mode, dry_run_env_file, + dry_run_mode, + dry_run_service, end_dry_run, - services_started_successfully, service_start_failed, + services_started_successfully, ) + class DockerServiceProtocol(Protocol): - def start_services(self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: - ... + def start_services( + self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None + ) -> tuple[bool, str]: ... + class DockerCommandBuilder(BaseDockerCommandBuilder): @staticmethod def build_up_command(name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None) -> list[str]: return BaseDockerCommandBuilder.build_command("up", name, env_file, compose_file, detach=detach) + class UpFormatter(BaseFormatter): def format_output(self, result: "UpResult", output: str) -> str: return super().format_output(result, output, services_started_successfully, service_start_failed) - + def format_dry_run(self, config: "UpConfig") -> str: dry_run_messages = { "mode": dry_run_mode, @@ -48,29 +46,35 @@ def format_dry_run(self, config: "UpConfig") -> str: "service": dry_run_service, "detach_mode": dry_run_detach_mode, "env_file": dry_run_env_file, - "end": end_dry_run + "end": end_dry_run, } return super().format_dry_run(config, DockerCommandBuilder(), dry_run_messages) + class DockerService(BaseDockerService): def __init__(self, logger: LoggerProtocol): super().__init__(logger, "up") - - def start_services(self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: + + def start_services( + self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None + ) -> tuple[bool, str]: return self.execute_services(name, env_file, compose_file, detach=detach) + class UpResult(BaseResult): detach: bool + class UpConfig(BaseConfig): detach: bool = Field(True, description="Run services in detached mode") + class UpService(BaseService[UpConfig, UpResult]): def __init__(self, config: UpConfig, logger: LoggerProtocol = None, docker_service: DockerServiceProtocol = None): super().__init__(config, logger, docker_service) self.docker_service = docker_service or DockerService(self.logger) self.formatter = UpFormatter() - + def _create_result(self, success: bool, error: str = None) -> UpResult: return UpResult( name=self.config.name, @@ -79,45 +83,43 @@ def _create_result(self, success: bool, error: str = None) -> UpResult: verbose=self.config.verbose, output=self.config.output, success=success, - error=error + error=error, ) - + def up(self) -> UpResult: return self.execute() - + def execute(self) -> UpResult: self.logger.debug(f"Starting services: {self.config.name}") - + success, error = self.docker_service.start_services( - self.config.name, - self.config.detach, - self.config.env_file, - self.config.compose_file + self.config.name, self.config.detach, self.config.env_file, self.config.compose_file ) - + return self._create_result(success, error) - + def up_and_format(self) -> str: return self.execute_and_format() - + def execute_and_format(self) -> str: if self.config.dry_run: return self.formatter.format_dry_run(self.config) - + result = self.execute() return self.formatter.format_output(result, self.config.output) + class Up(BaseAction[UpConfig, UpResult]): def __init__(self, logger: LoggerProtocol = None): super().__init__(logger) self.formatter = UpFormatter() - + def up(self, config: UpConfig) -> UpResult: return self.execute(config) - + def execute(self, config: UpConfig) -> UpResult: service = UpService(config, logger=self.logger) return service.execute() - + def format_output(self, result: UpResult, output: str) -> str: return self.formatter.format_output(result, output) diff --git a/cli/app/commands/test/command.py b/cli/app/commands/test/command.py index 2da72a5d..83d2132c 100644 --- a/cli/app/commands/test/command.py +++ b/cli/app/commands/test/command.py @@ -1,15 +1,14 @@ import typer -from .test import TestCommand + from .messages import test_app_help +from .test import TestCommand + +test_app = typer.Typer(help=test_app_help, invoke_without_command=True) -test_app = typer.Typer( - help=test_app_help, - invoke_without_command=True -) @test_app.callback() def test_callback(ctx: typer.Context, target: str = typer.Argument(None, help="Test target (e.g., version)")): """Run tests (only in DEVELOPMENT environment)""" if ctx.invoked_subcommand is None: test_command = TestCommand() - test_command.run(target) + test_command.run(target) diff --git a/cli/app/commands/test/test.py b/cli/app/commands/test/test.py index 574b0376..4ce1cdc1 100644 --- a/cli/app/commands/test/test.py +++ b/cli/app/commands/test/test.py @@ -1,9 +1,13 @@ -import typer import subprocess + +import typer + from app.utils.config import Config from app.utils.logger import Logger + from .messages import development_only_error, running_command + class TestCommand: def __init__(self): self.config = Config() @@ -16,6 +20,6 @@ def run(self, target: str = typer.Argument(None, help="Test target (e.g., versio cmd = ["make", "test"] if target: cmd.append(f"test-{target}") - self.logger.info(running_command.format(command=' '.join(cmd))) + self.logger.info(running_command.format(command=" ".join(cmd))) result = subprocess.run(cmd) - raise typer.Exit(result.returncode) + raise typer.Exit(result.returncode) diff --git a/cli/app/commands/version/command.py b/cli/app/commands/version/command.py index 9573f9a6..7d3798c7 100644 --- a/cli/app/commands/version/command.py +++ b/cli/app/commands/version/command.py @@ -1,11 +1,11 @@ import typer -from .version import VersionCommand + from app.utils.message import application_version_help -version_app = typer.Typer( - help=application_version_help, - invoke_without_command=True -) +from .version import VersionCommand + +version_app = typer.Typer(help=application_version_help, invoke_without_command=True) + @version_app.callback() def version_callback(ctx: typer.Context): @@ -14,6 +14,7 @@ def version_callback(ctx: typer.Context): version_command = VersionCommand() version_command.run() + def main_version_callback(value: bool): if value: version_command = VersionCommand() diff --git a/cli/app/commands/version/tests/test_version.py b/cli/app/commands/version/tests/test_version.py index 5958368f..2eaf4f6d 100644 --- a/cli/app/commands/version/tests/test_version.py +++ b/cli/app/commands/version/tests/test_version.py @@ -1,94 +1,96 @@ -import pytest -from unittest.mock import patch, MagicMock from importlib.metadata import version +from unittest.mock import MagicMock, patch + +import pytest + from app.commands.version.version import VersionCommand class TestVersionCommand: """Test cases for the VersionCommand class""" - @patch('app.commands.version.version.Console') - @patch('app.commands.version.version.version') + @patch("app.commands.version.version.Console") + @patch("app.commands.version.version.version") def test_version_command_success(self, mock_version, mock_console_class): """Test successful version display""" mock_version.return_value = "1.0.0" mock_console = MagicMock() mock_console_class.return_value = mock_console - + version_command = VersionCommand() version_command.run() - - mock_version.assert_called_once_with('nixopus') + + mock_version.assert_called_once_with("nixopus") mock_console.print.assert_called_once() - + call_args = mock_console.print.call_args[0][0] assert call_args.title == "[bold white]Version Info[/bold white]" assert call_args.border_style == "blue" assert call_args.padding == (0, 1) - @patch('app.commands.version.version.Console') - @patch('app.commands.version.version.version') + @patch("app.commands.version.version.Console") + @patch("app.commands.version.version.version") def test_version_command_with_different_versions(self, mock_version, mock_console_class): """Test version display with different version numbers""" test_versions = ["0.1.0", "2.3.4", "1.0.0-beta"] mock_console = MagicMock() mock_console_class.return_value = mock_console - + for test_version in test_versions: mock_version.return_value = test_version mock_console.reset_mock() - + version_command = VersionCommand() version_command.run() - - mock_version.assert_called_with('nixopus') + + mock_version.assert_called_with("nixopus") mock_console.print.assert_called_once() - @patch('app.commands.version.version.Console') - @patch('app.commands.version.version.version') + @patch("app.commands.version.version.Console") + @patch("app.commands.version.version.version") def test_version_command_panel_content(self, mock_version, mock_console_class): """Test that panel contains correct text content""" mock_version.return_value = "1.2.3" mock_console = MagicMock() mock_console_class.return_value = mock_console - + version_command = VersionCommand() version_command.run() - + call_args = mock_console.print.call_args[0][0] panel_content = call_args.renderable - + assert "Nixopus CLI" in str(panel_content) assert "v1.2.3" in str(panel_content) - @patch('app.commands.version.version.Console') - @patch('app.commands.version.version.version') + @patch("app.commands.version.version.Console") + @patch("app.commands.version.version.version") def test_version_command_handles_version_error(self, mock_version, mock_console_class): """Test handling of version import error""" mock_version.side_effect = Exception("Version not found") mock_console = MagicMock() mock_console_class.return_value = mock_console - + with pytest.raises(Exception): version_command = VersionCommand() version_command.run() - - mock_version.assert_called_once_with('nixopus') - @patch('app.commands.version.version.Console') - @patch('app.commands.version.version.version') + mock_version.assert_called_once_with("nixopus") + + @patch("app.commands.version.version.Console") + @patch("app.commands.version.version.version") def test_version_command_console_error_handling(self, mock_version, mock_console_class): """Test handling of console print errors""" mock_version.return_value = "1.0.0" mock_console = MagicMock() mock_console.print.side_effect = Exception("Console error") mock_console_class.return_value = mock_console - + with pytest.raises(Exception): version_command = VersionCommand() version_command.run() - - mock_version.assert_called_once_with('nixopus') + + mock_version.assert_called_once_with("nixopus") mock_console.print.assert_called_once() @@ -97,21 +99,21 @@ class TestVersionCommandClass: def test_version_command_initialization(self): """Test that VersionCommand can be instantiated""" - with patch('app.commands.version.version.Console'): + with patch("app.commands.version.version.Console"): version_command = VersionCommand() - assert hasattr(version_command, 'console') + assert hasattr(version_command, "console") def test_version_command_run_method(self): """Test that VersionCommand has a run method""" - with patch('app.commands.version.version.Console'): + with patch("app.commands.version.version.Console"): version_command = VersionCommand() - assert hasattr(version_command, 'run') + assert hasattr(version_command, "run") assert callable(version_command.run) def test_version_command_run_returns_none(self): """Test that run method returns None""" - with patch('app.commands.version.version.Console'): - with patch('app.commands.version.version.version', return_value="1.0.0"): + with patch("app.commands.version.version.Console"): + with patch("app.commands.version.version.version", return_value="1.0.0"): version_command = VersionCommand() result = version_command.run() assert result is None @@ -124,6 +126,7 @@ def test_import_metadata_version(self): """Test that importlib.metadata.version is available""" try: from importlib.metadata import version + assert callable(version) except ImportError: pytest.skip("importlib.metadata not available") @@ -132,6 +135,7 @@ def test_rich_console_import(self): """Test that rich.console.Console is available""" try: from rich.console import Console + assert callable(Console) except ImportError: pytest.skip("rich.console not available") @@ -140,6 +144,7 @@ def test_rich_panel_import(self): """Test that rich.panel.Panel is available""" try: from rich.panel import Panel + assert callable(Panel) except ImportError: pytest.skip("rich.panel not available") @@ -148,6 +153,7 @@ def test_rich_text_import(self): """Test that rich.text.Text is available""" try: from rich.text import Text + assert callable(Text) except ImportError: pytest.skip("rich.text not available") @@ -158,14 +164,15 @@ class TestVersionCommandSignature: def test_version_command_is_instantiable(self): """Test that VersionCommand can be instantiated""" - with patch('app.commands.version.version.Console'): + with patch("app.commands.version.version.Console"): version_command = VersionCommand() assert isinstance(version_command, VersionCommand) def test_run_method_no_parameters(self): """Test that run method takes no parameters""" import inspect - with patch('app.commands.version.version.Console'): + + with patch("app.commands.version.version.Console"): version_command = VersionCommand() sig = inspect.signature(version_command.run) assert len(sig.parameters) == 0 diff --git a/cli/app/commands/version/version.py b/cli/app/commands/version/version.py index 30dc531a..b4c0d9c2 100644 --- a/cli/app/commands/version/version.py +++ b/cli/app/commands/version/version.py @@ -1,7 +1,9 @@ +from importlib.metadata import version + from rich.console import Console from rich.panel import Panel from rich.text import Text -from importlib.metadata import version + class VersionCommand: def __init__(self): @@ -9,17 +11,12 @@ def __init__(self): def run(self): """Display the version of the CLI""" - cli_version = version('nixopus') - + cli_version = version("nixopus") + version_text = Text() version_text.append("Nixopus CLI", style="bold blue") version_text.append(f" v{cli_version}", style="green") - - panel = Panel( - version_text, - title="[bold white]Version Info[/bold white]", - border_style="blue", - padding=(0, 1) - ) - + + panel = Panel(version_text, title="[bold white]Version Info[/bold white]", border_style="blue", padding=(0, 1)) + self.console.print(panel) diff --git a/cli/app/main.py b/cli/app/main.py index b5378300..e55b4869 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -1,12 +1,13 @@ import typer -from app.commands.version.command import version_app, main_version_callback -from app.commands.preflight.command import preflight_app -from app.commands.test.command import test_app -from app.commands.install.command import install_app -from app.commands.service.command import service_app + from app.commands.conf.command import conf_app +from app.commands.install.command import install_app +from app.commands.preflight.command import preflight_app from app.commands.proxy.command import proxy_app -from app.utils.message import application_name, application_description, application_add_completion, application_version_help +from app.commands.service.command import service_app +from app.commands.test.command import test_app +from app.commands.version.command import main_version_callback, version_app +from app.utils.message import application_add_completion, application_description, application_name, application_version_help app = typer.Typer( name=application_name, @@ -14,6 +15,7 @@ add_completion=application_add_completion, ) + @app.callback() def main( version: bool = typer.Option( @@ -22,10 +24,11 @@ def main( "-v", callback=main_version_callback, help=application_version_help, - ) + ) ): pass + app.add_typer(preflight_app, name="preflight") app.add_typer(conf_app, name="conf") app.add_typer(service_app, name="service") diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index 87a34e5f..a3c9991f 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -1,11 +1,12 @@ import os + class Config: def __init__(self, default_env="PRODUCTION"): self.default_env = default_env - + def get_env(self): return os.environ.get("ENV", self.default_env) - + def is_development(self): - return self.get_env().upper() == "DEVELOPMENT" + return self.get_env().upper() == "DEVELOPMENT" diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py index a67cfdc8..ee1602fb 100644 --- a/cli/app/utils/lib.py +++ b/cli/app/utils/lib.py @@ -1,27 +1,31 @@ -from enum import Enum -import platform -import subprocess import os +import platform import shutil import stat -from typing import TypeVar, Callable, List, Optional, Tuple +import subprocess from concurrent.futures import ThreadPoolExecutor, as_completed -from app.utils.message import REMOVED_DIRECTORY_MESSAGE, FAILED_TO_REMOVE_DIRECTORY_MESSAGE +from enum import Enum +from typing import Callable, List, Optional, Tuple, TypeVar + +from app.utils.message import FAILED_TO_REMOVE_DIRECTORY_MESSAGE, REMOVED_DIRECTORY_MESSAGE + +T = TypeVar("T") +R = TypeVar("R") -T = TypeVar('T') -R = TypeVar('R') class SupportedOS(str, Enum): LINUX = "linux" MACOS = "darwin" - + + class SupportedDistribution(str, Enum): DEBIAN = "debian" UBUNTU = "ubuntu" CENTOS = "centos" FEDORA = "fedora" ALPINE = "alpine" - + + class SupportedPackageManager(str, Enum): APT = "apt" YUM = "yum" @@ -30,15 +34,16 @@ class SupportedPackageManager(str, Enum): APK = "apk" BREW = "brew" + class Supported: @staticmethod def os(os_name: str) -> bool: return os_name in [os.value for os in SupportedOS] - + @staticmethod def distribution(distribution: str) -> bool: return distribution in [dist.value for dist in SupportedDistribution] - + @staticmethod def package_manager(package_manager: str) -> bool: return package_manager in [pm.value for pm in SupportedPackageManager] @@ -46,57 +51,58 @@ def package_manager(package_manager: str) -> bool: @staticmethod def get_os(): return [os.value for os in SupportedOS] - + @staticmethod def get_distributions(): return [dist.value for dist in SupportedDistribution] + class HostInformation: @staticmethod def get_os_name(): return platform.system().lower() - + @staticmethod def get_package_manager(): os_name = HostInformation.get_os_name() - + if os_name == SupportedOS.MACOS.value: return SupportedPackageManager.BREW.value - + package_managers = [pm.value for pm in SupportedPackageManager if pm != SupportedPackageManager.BREW] - + for pm in package_managers: if HostInformation.command_exists(pm): return pm - + return None - + @staticmethod def command_exists(command): try: - result = subprocess.run(["command", "-v", command], - capture_output=True, text=True, check=False) + result = subprocess.run(["command", "-v", command], capture_output=True, text=True, check=False) return result.returncode == 0 except Exception: return False + class ParallelProcessor: @staticmethod def process_items( items: List[T], processor_func: Callable[[T], R], max_workers: int = 50, - error_handler: Callable[[T, Exception], R] = None + error_handler: Callable[[T, Exception], R] = None, ) -> List[R]: if not items: return [] - + results = [] max_workers = min(len(items), max_workers) - + with ThreadPoolExecutor(max_workers=max_workers) as executor: futures = {executor.submit(processor_func, item): item for item in items} - + for future in as_completed(futures): try: result = future.result() @@ -108,15 +114,16 @@ def process_items( results.append(error_result) return results + class DirectoryManager: @staticmethod def path_exists(path: str) -> bool: return os.path.exists(path) - + @staticmethod def path_exists_and_not_force(path: str, force: bool) -> bool: return os.path.exists(path) and not force - + @staticmethod def remove_directory(path: str, logger=None) -> bool: try: @@ -129,15 +136,16 @@ def remove_directory(path: str, logger=None) -> bool: logger.error(FAILED_TO_REMOVE_DIRECTORY_MESSAGE.format(path=path, error=e)) return False + class FileManager: @staticmethod def set_permissions(file_path: str, mode: int, logger=None) -> Tuple[bool, Optional[str]]: try: if logger: logger.debug(f"Setting permissions {oct(mode)} on {file_path}") - + os.chmod(file_path, mode) - + if logger: logger.debug("File permissions set successfully") return True, None @@ -146,9 +154,11 @@ def set_permissions(file_path: str, mode: int, logger=None) -> Tuple[bool, Optio if logger: logger.error(error_msg) return False, error_msg - + @staticmethod - def create_directory(path: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, logger=None) -> Tuple[bool, Optional[str]]: + def create_directory( + path: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, logger=None + ) -> Tuple[bool, Optional[str]]: try: if not os.path.exists(path): os.makedirs(path, mode=mode) @@ -160,15 +170,17 @@ def create_directory(path: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S if logger: logger.error(error_msg) return False, error_msg - + @staticmethod - def append_to_file(file_path: str, content: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, logger=None) -> Tuple[bool, Optional[str]]: + def append_to_file( + file_path: str, content: str, mode: int = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, logger=None + ) -> Tuple[bool, Optional[str]]: try: - with open(file_path, 'a') as f: + with open(file_path, "a") as f: f.write(f"\n{content}\n") - + FileManager.set_permissions(file_path, mode, logger) - + if logger: logger.debug(f"Content appended to {file_path}") return True, None @@ -177,11 +189,11 @@ def append_to_file(file_path: str, content: str, mode: int = stat.S_IRUSR | stat if logger: logger.error(error_msg) return False, error_msg - + @staticmethod def read_file_content(file_path: str, logger=None) -> Tuple[bool, Optional[str], Optional[str]]: try: - with open(file_path, 'r') as f: + with open(file_path, "r") as f: content = f.read().strip() return True, content, None except Exception as e: @@ -189,15 +201,15 @@ def read_file_content(file_path: str, logger=None) -> Tuple[bool, Optional[str], if logger: logger.error(error_msg) return False, None, error_msg - + @staticmethod def expand_user_path(path: str) -> str: return os.path.expanduser(path) - + @staticmethod def get_directory_path(file_path: str) -> str: return os.path.dirname(file_path) - + @staticmethod def get_public_key_path(private_key_path: str) -> str: return f"{private_key_path}.pub" diff --git a/cli/app/utils/logger.py b/cli/app/utils/logger.py index 5f3c2f45..8416b9bc 100644 --- a/cli/app/utils/logger.py +++ b/cli/app/utils/logger.py @@ -1,5 +1,7 @@ import typer -from .message import INFO_MESSAGE, DEBUG_MESSAGE, WARNING_MESSAGE, ERROR_MESSAGE, SUCCESS_MESSAGE, HIGHLIGHT_MESSAGE + +from .message import DEBUG_MESSAGE, ERROR_MESSAGE, HIGHLIGHT_MESSAGE, INFO_MESSAGE, SUCCESS_MESSAGE, WARNING_MESSAGE + class Logger: """Wrapper for typer.secho to log messages to the console""" @@ -46,4 +48,4 @@ def success(self, message: str) -> None: def highlight(self, message: str) -> None: """Prints a highlighted message""" if self._should_print(): - typer.secho(HIGHLIGHT_MESSAGE.format(message=message), fg=typer.colors.MAGENTA) \ No newline at end of file + typer.secho(HIGHLIGHT_MESSAGE.format(message=message), fg=typer.colors.MAGENTA) diff --git a/cli/app/utils/message.py b/cli/app/utils/message.py index 825d3fc5..b6b6df0d 100644 --- a/cli/app/utils/message.py +++ b/cli/app/utils/message.py @@ -13,4 +13,4 @@ SUCCESS_MESSAGE = "SUCCESS: {message}" HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" REMOVED_DIRECTORY_MESSAGE = "Removed existing directory: {path}" -FAILED_TO_REMOVE_DIRECTORY_MESSAGE = "Failed to remove directory: {path}" \ No newline at end of file +FAILED_TO_REMOVE_DIRECTORY_MESSAGE = "Failed to remove directory: {path}" diff --git a/cli/app/utils/output_formatter.py b/cli/app/utils/output_formatter.py index bb349e6a..198d4379 100644 --- a/cli/app/utils/output_formatter.py +++ b/cli/app/utils/output_formatter.py @@ -1,17 +1,20 @@ import json from typing import Any, Dict, Optional + from pydantic import BaseModel + class OutputMessage(BaseModel): success: bool message: str data: Optional[Dict[str, Any]] = None error: Optional[str] = None + class OutputFormatter: def __init__(self, invalid_output_format_msg: str = "Invalid output format"): self.invalid_output_format_msg = invalid_output_format_msg - + def format_text(self, result: Any) -> str: if isinstance(result, OutputMessage): if result.success: @@ -22,17 +25,17 @@ def format_text(self, result: Any) -> str: return "\n".join([self.format_text(item) for item in result]) else: return str(result) - + def format_json(self, result: Any) -> str: if isinstance(result, OutputMessage): return json.dumps(result.model_dump(), indent=2) elif isinstance(result, list): - return json.dumps([item.model_dump() if hasattr(item, 'model_dump') else item for item in result], indent=2) + return json.dumps([item.model_dump() if hasattr(item, "model_dump") else item for item in result], indent=2) elif isinstance(result, BaseModel): return json.dumps(result.model_dump(), indent=2) else: return json.dumps(result, indent=2) - + def format_output(self, result: Any, output: str) -> str: if output == "text": return self.format_text(result) @@ -40,9 +43,9 @@ def format_output(self, result: Any, output: str) -> str: return self.format_json(result) else: raise ValueError(self.invalid_output_format_msg) - + def create_success_message(self, message: str, data: Optional[Dict[str, Any]] = None) -> OutputMessage: return OutputMessage(success=True, message=message, data=data) - + def create_error_message(self, error: str, data: Optional[Dict[str, Any]] = None) -> OutputMessage: - return OutputMessage(success=False, message="", error=error, data=data) + return OutputMessage(success=False, message="", error=error, data=data) diff --git a/cli/app/utils/protocols.py b/cli/app/utils/protocols.py index c93869ee..6f4693f8 100644 --- a/cli/app/utils/protocols.py +++ b/cli/app/utils/protocols.py @@ -1,19 +1,14 @@ from typing import Protocol + class LoggerProtocol(Protocol): - def debug(self, message: str) -> None: - ... - def info(self, message: str) -> None: - ... - def warning(self, message: str) -> None: - ... - def error(self, message: str) -> None: - ... - def success(self, message: str) -> None: - ... - def highlight(self, message: str) -> None: - ... + def debug(self, message: str) -> None: ... + def info(self, message: str) -> None: ... + def warning(self, message: str) -> None: ... + def error(self, message: str) -> None: ... + def success(self, message: str) -> None: ... + def highlight(self, message: str) -> None: ... + class DockerServiceProtocol(Protocol): - def execute_services(self, name: str, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: - ... + def execute_services(self, name: str, env_file: str = None, compose_file: str = None) -> tuple[bool, str]: ... diff --git a/cli/app/utils/tests/test_processor.py b/cli/app/utils/tests/test_processor.py index 7101862d..3545c1e6 100644 --- a/cli/app/utils/tests/test_processor.py +++ b/cli/app/utils/tests/test_processor.py @@ -1,81 +1,85 @@ -import unittest import time +import unittest + from app.utils.lib import ParallelProcessor + class TestParallelProcessor(unittest.TestCase): - + def test_basic_processing(self): """Test basic parallel processing functionality""" + def square(x): return x * x - + items = [1, 2, 3, 4, 5] results = ParallelProcessor.process_items(items, square) - + # Results are in completion order, not input order self.assertEqual(len(results), 5) self.assertEqual(set(results), {1, 4, 9, 16, 25}) - + def test_error_handling(self): """Test error handling in parallel processing""" + def process_with_error(x): if x == 3: raise ValueError("Test error") return x * 2 - + def error_handler(item, error): return f"Error processing {item}: {str(error)}" - + items = [1, 2, 3, 4, 5] - results = ParallelProcessor.process_items( - items, - process_with_error, - error_handler=error_handler - ) - + results = ParallelProcessor.process_items(items, process_with_error, error_handler=error_handler) + self.assertEqual(len(results), 5) # Check that we have the expected results (order may vary) expected_results = {2, 4, 8, 10} # 1*2, 2*2, 4*2, 5*2 error_results = [r for r in results if "Error processing 3" in str(r)] normal_results = [r for r in results if isinstance(r, int)] - + self.assertEqual(len(error_results), 1) self.assertEqual(set(normal_results), expected_results) - + def test_timeout_behavior(self): """Test that processing respects timeout behavior""" + def slow_process(x): time.sleep(0.1) return x * 2 - + items = list(range(10)) start_time = time.time() results = ParallelProcessor.process_items(items, slow_process, max_workers=5) end_time = time.time() - + self.assertEqual(len(results), 10) # Results are in completion order, not input order self.assertEqual(set(results), {0, 2, 4, 6, 8, 10, 12, 14, 16, 18}) - + # With 5 workers and 10 items taking 0.1s each, should complete in ~0.2s # (2 batches of 5 items each) self.assertLess(end_time - start_time, 0.5) - + def test_empty_list(self): """Test processing empty list""" + def process(x): return x * 2 - + results = ParallelProcessor.process_items([], process) self.assertEqual(results, []) - + def test_single_item(self): """Test processing single item""" + def process(x): return x * 2 - + results = ParallelProcessor.process_items([5], process) self.assertEqual(results, [10]) -if __name__ == '__main__': - unittest.main() \ No newline at end of file + +if __name__ == "__main__": + unittest.main() From efcd993d4fd83d985a6bac0be7d931db3c0d40c4 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Tue, 15 Jul 2025 08:00:39 +0530 Subject: [PATCH 38/72] chore: add debug logs for conf command --- cli/app/commands/conf/base.py | 84 ++++++++++++++++++++++++++++++- cli/app/commands/conf/messages.py | 41 +++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) diff --git a/cli/app/commands/conf/base.py b/cli/app/commands/conf/base.py index a3143fb5..dd08428b 100644 --- a/cli/app/commands/conf/base.py +++ b/cli/app/commands/conf/base.py @@ -9,19 +9,56 @@ from app.utils.protocols import LoggerProtocol from .messages import ( + atomic_complete, + atomic_failed, + atomic_write, + atomic_write_failed, backup_created, + backup_created_at, + backup_created_success, backup_creation_failed, + backup_exists, + backup_failed, backup_file_not_found, + backup_not_found, backup_remove_failed, backup_removed, backup_restore_attempt, backup_restore_failed, backup_restore_success, + backup_restored, + cleanup_failed, + cleanup_temp, + config_entries, + creating_backup, + directory_ensured, + file_not_exists, file_not_found, file_read_failed, file_write_failed, + getting_service, invalid_line_warning, invalid_service, + no_backup_needed, + parsed_config, + read_error, + read_success, + reading_env_file, + replacing_file, + restore_failed, + restoring_backup, + skipping_line, + sync_not_critical, + synced_temp, + temp_file_created, + unexpected_error, + using_default_api, + using_default_view, + using_provided_env, + write_complete, + writing_entries, + writing_env_file, + wrote_to_temp, ) TConfig = TypeVar("TConfig", bound=BaseModel) @@ -41,8 +78,10 @@ def __init__(self, logger: LoggerProtocol): self.logger = logger def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[str]]: + self.logger.debug(reading_env_file.format(file_path=file_path)) try: if not os.path.exists(file_path): + self.logger.debug(file_not_exists.format(file_path=file_path)) return False, {}, file_not_found.format(path=file_path) config = {} @@ -50,6 +89,7 @@ def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[ for line_num, line in enumerate(f, 1): line = line.strip() if not line or line.startswith("#"): + self.logger.debug(skipping_line.format(line_num=line_num)) continue if "=" not in line: @@ -58,64 +98,92 @@ def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[ key, value = line.split("=", 1) config[key.strip()] = value.strip() + self.logger.debug(parsed_config.format(key=key.strip(), value=value.strip())) + self.logger.debug(read_success.format(count=len(config), file_path=file_path)) return True, config, None except Exception as e: + self.logger.debug(read_error.format(file_path=file_path, error=e)) return False, {}, file_read_failed.format(error=e) def _create_backup(self, file_path: str) -> tuple[bool, Optional[str], Optional[str]]: + self.logger.debug(creating_backup.format(file_path=file_path)) if not os.path.exists(file_path): + self.logger.debug(no_backup_needed.format(file_path=file_path)) return True, None, None try: backup_path = f"{file_path}.backup" + self.logger.debug(backup_created_at.format(backup_path=backup_path)) shutil.copy2(file_path, backup_path) + self.logger.debug(backup_created_success.format(backup_path=backup_path)) return True, backup_path, None except Exception as e: + self.logger.debug(backup_failed.format(error=e)) return False, None, backup_creation_failed.format(error=e) def _restore_backup(self, backup_path: str, file_path: str) -> tuple[bool, Optional[str]]: + self.logger.debug(restoring_backup.format(backup_path=backup_path, file_path=file_path)) try: if os.path.exists(backup_path): + self.logger.debug(backup_exists) shutil.copy2(backup_path, file_path) os.remove(backup_path) + self.logger.debug(backup_restored) return True, None + self.logger.debug(backup_not_found.format(backup_path=backup_path)) return False, backup_file_not_found.format(path=backup_path) except Exception as e: + self.logger.debug(restore_failed.format(error=e)) return False, backup_restore_failed.format(error=e) def _atomic_write(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: + self.logger.debug(atomic_write.format(file_path=file_path)) + self.logger.debug(writing_entries.format(count=len(config))) temp_path = None try: os.makedirs(os.path.dirname(file_path), exist_ok=True) + self.logger.debug(directory_ensured.format(directory=os.path.dirname(file_path))) with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=os.path.dirname(file_path)) as temp_file: + self.logger.debug(temp_file_created.format(temp_path=temp_file.name)) for key, value in sorted(config.items()): temp_file.write(f"{key}={value}\n") + self.logger.debug(wrote_to_temp.format(key=key, value=value)) temp_file.flush() try: os.fsync(temp_file.fileno()) + self.logger.debug(synced_temp) except (OSError, AttributeError): + self.logger.debug(sync_not_critical) pass temp_path = temp_file.name + self.logger.debug(replacing_file.format(file_path=file_path)) os.replace(temp_path, file_path) + self.logger.debug(atomic_complete) return True, None except Exception as e: + self.logger.debug(atomic_failed.format(error=e)) if temp_path and os.path.exists(temp_path): try: os.unlink(temp_path) + self.logger.debug(cleanup_temp.format(temp_path=temp_path)) except: + self.logger.debug(cleanup_failed.format(temp_path=temp_path)) pass return False, file_write_failed.format(error=e) def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: + self.logger.debug(writing_env_file.format(file_path=file_path)) + self.logger.debug(config_entries.format(count=len(config))) backup_created_flag = False backup_path = None try: success, backup_path, error = self._create_backup(file_path) if not success: + self.logger.debug(backup_creation_failed.format(error=error)) return False, error backup_created_flag = True @@ -123,6 +191,7 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, success, error = self._atomic_write(file_path, config) if not success: + self.logger.debug(atomic_write_failed) if backup_created_flag and backup_path: self.logger.warning(backup_restore_attempt) restore_success, restore_error = self._restore_backup(backup_path, file_path) @@ -136,23 +205,34 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, try: os.remove(backup_path) self.logger.info(backup_removed) + self.logger.debug(backup_removed.format(backup_path=backup_path)) except Exception as e: self.logger.warning(backup_remove_failed.format(error=e)) + self.logger.debug(backup_remove_failed.format(error=e)) + self.logger.debug(write_complete) return True, None except Exception as e: + self.logger.debug(unexpected_error.format(error=e)) return False, file_write_failed.format(error=e) def get_service_env_file(self, service: str, env_file: Optional[str] = None) -> str: + self.logger.debug(getting_service.format(service=service)) if env_file: + self.logger.debug(using_provided_env.format(env_file=env_file)) return env_file if service == "api": - return "/etc/nixopus/source/api/.env" + default_path = "/etc/nixopus/source/api/.env" + self.logger.debug(using_default_api.format(path=default_path)) + return default_path elif service == "view": - return "/etc/nixopus/source/view/.env" + default_path = "/etc/nixopus/source/view/.env" + self.logger.debug(using_default_view.format(path=default_path)) + return default_path else: + self.logger.debug(invalid_service.format(service=service)) raise ValueError(invalid_service.format(service=service)) diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py index 20c3d6c1..8db97df9 100644 --- a/cli/app/commands/conf/messages.py +++ b/cli/app/commands/conf/messages.py @@ -28,3 +28,44 @@ invalid_service = "Invalid service: {service}" config_key_not_found = "Configuration key '{key}' not found" backup_file_not_found = "Backup file not found" +reading_env_file = "Reading environment file: {file_path}" +file_not_exists = "File does not exist: {file_path}" +skipping_line = "Skipping line {line_num}: empty or comment" +parsed_config = "Parsed config: {key}={value}" +read_success = "Successfully read {count} configuration entries from {file_path}" +read_error = "Error reading file {file_path}: {error}" +creating_backup = "Creating backup for file: {file_path}" +no_backup_needed = "Source file does not exist, no backup needed: {file_path}" +backup_created_at = "Creating backup at: {backup_path}" +backup_created_success = "Backup created successfully: {backup_path}" +backup_failed = "Failed to create backup: {error}" +restoring_backup = "Restoring backup from {backup_path} to {file_path}" +backup_exists = "Backup file exists, restoring..." +backup_restored = "Backup restored and removed successfully" +backup_not_found = "Backup file not found: {backup_path}" +restore_failed = "Failed to restore backup: {error}" +atomic_write = "Performing atomic write to: {file_path}" +writing_entries = "Writing {count} configuration entries" +directory_ensured = "Ensured directory exists: {directory}" +temp_file_created = "Created temporary file: {temp_path}" +wrote_to_temp = "Wrote to temp file: {key}={value}" +synced_temp = "Synced temporary file to disk" +sync_not_critical = "Could not sync temporary file (not critical)" +replacing_file = "Replacing {file_path} with temporary file" +atomic_complete = "Atomic write completed successfully" +atomic_failed = "Atomic write failed: {error}" +cleanup_temp = "Cleaned up temporary file: {temp_path}" +cleanup_failed = "Failed to clean up temporary file: {temp_path}" +writing_env_file = "Writing environment file: {file_path}" +config_entries = "Configuration contains {count} entries" +backup_creation_failed = "Backup creation failed: {error}" +atomic_write_failed = "Atomic write failed, attempting backup restore" +backup_removed = "Backup file removed: {backup_path}" +backup_remove_failed = "Failed to remove backup: {error}" +write_complete = "Environment file write completed successfully" +unexpected_error = "Unexpected error during file write: {error}" +getting_service = "Getting environment file for service: {service}" +using_provided_env = "Using provided env_file: {env_file}" +using_default_api = "Using default API path: {path}" +using_default_view = "Using default view path: {path}" +invalid_service = "Invalid service: {service}" From 96c9e8b1e8d19e4d29b8dbaacf58e905ba24042c Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 16 Jul 2025 15:19:13 +0530 Subject: [PATCH 39/72] feat: add config yaml file --- helpers/config.prod.yaml | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 helpers/config.prod.yaml diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml new file mode 100644 index 00000000..82761f32 --- /dev/null +++ b/helpers/config.prod.yaml @@ -0,0 +1,97 @@ +version: 1 +services: + api: + env: + PORT: ${API_PORT:-8443} + DB_NAME: ${DB_NAME:-postgres} + USERNAME: ${USERNAME:-postgres} + PASSWORD: ${PASSWORD:-changeme} + HOST_NAME: ${DB_HOST:-nixopus-db} + DB_PORT: ${DB_PORT:-5432} + SSL_MODE: ${DB_SSL_MODE:-disable} + MOUNT_PATH: ${MOUNT_PATH:-/etc/nixopus/configs} + SSH_HOST: ${SSH_HOST:-localhost} + SSH_PORT: ${SSH_PORT:-22} + SSH_USER: ${SSH_USER:-} + SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY:-} + SSH_PASSWORD: ${SSH_PASSWORD:-} + DOCKER_HOST: ${DOCKER_HOST:-unix:///var/run/docker.sock} + DOCKER_TLS_VERIFY: ${DOCKER_TLS_VERIFY:-1} + DOCKER_CERT_PATH: ${DOCKER_CERT_PATH:-} + REDIS_URL: ${REDIS_URL:-redis://nixopus-redis:6379} + CADDY_ENDPOINT: ${CADDY_ENDPOINT:-http://nixopus-caddy:2019} + ALLOWED_ORIGIN: ${ALLOWED_ORIGIN:-http://localhost:3000} + ENV: ${ENV:-production} + LOGS_PATH: ${LOGS_PATH:-./logs} + API_ENV_FILE: ${API_ENV_FILE:-/etc/nixopus/source/api/.env} + API_VOLUME: ${API_VOLUME:-/etc/nixopus/configs} + API_IMAGE: ${API_IMAGE:-ghcr.io/raghavyuva/nixopus-api:latest} + API_CONTAINER_NAME: ${API_CONTAINER_NAME:-nixopus-api-container} + + view: + env: + PORT: ${VIEW_PORT:-7443} + NEXT_PUBLIC_WEBHOOK_URL: ${NEXT_PUBLIC_WEBHOOK_URL:-} + NEXT_PUBLIC_PORT: ${NEXT_PUBLIC_PORT:-7443} + LOGS_PATH: ${LOGS_PATH:-./logs} + VIEW_ENV_FILE: ${VIEW_ENV_FILE:-/etc/nixopus/source/view/.env} + VIEW_IMAGE: ${VIEW_IMAGE:-ghcr.io/raghavyuva/nixopus-view:latest} + VIEW_CONTAINER_NAME: ${VIEW_CONTAINER_NAME:-nixopus-view-container} + + redis: + env: + REDIS_PORT: ${REDIS_PORT:-6379} + REDIS_VOLUME: ${REDIS_VOLUME:-/etc/nixopus/redis} + REDIS_IMAGE: ${REDIS_IMAGE:-redis:7-alpine} + REDIS_CONTAINER_NAME: ${REDIS_CONTAINER_NAME:-nixopus-redis-container} + + db: + env: + DB_PORT: ${DB_PORT:-5432} + DB_VOLUME: ${DB_VOLUME:-/etc/nixopus/db} + DB_IMAGE: ${DB_IMAGE:-postgres:14-alpine} + DB_CONTAINER_NAME: ${DB_CONTAINER_NAME:-nixopus-db-container} + POSTGRES_USER: ${USERNAME:-postgres} + POSTGRES_PASSWORD: ${PASSWORD:-changeme} + POSTGRES_DB: ${DB_NAME:-postgres} + POSTGRES_HOST_AUTH_METHOD: trust + + caddy: + env: + CADDY_IMAGE: ${CADDY_IMAGE:-caddy:latest} + CADDY_CONTAINER_NAME: ${CADDY_CONTAINER_NAME:-nixopus-caddy-container} + CADDY_DATA_VOLUME: ${CADDY_DATA_VOLUME:-/etc/nixopus/caddy} + CADDY_CONFIG_VOLUME: ${CADDY_CONFIG_VOLUME:-/etc/nixopus/caddy} + CADDYFILE_PATH: ${CADDYFILE_PATH:-/etc/nixopus/caddy/Caddyfile} + CADDY_PORTS: "2019:2019,80:80,443:443" + API_DOMAIN: ${API_DOMAIN:-} + VIEW_DOMAIN: ${VIEW_DOMAIN:-} + CADDY_COMMAND: [ + "caddy", + "run", + "--config", + "/etc/caddy/Caddyfile", + "--adapter", + "caddyfile" + ] + +networks: + default: + name: nixopus-network + driver: bridge + +deps: + curl: { version: "1" } + go: { version: "1" } + air: { version: "" } + python: { version: "" } + poetry: { version: "" } + redis: { version: "" } + docker: { version: "" } + open-ssh: { version: "" } + open-sshserver: { version: "" } + git: { version: "" } + openssl: { version: "" } + python3-venv: { version: "" } + +nixopus-config-dir: /etc/nixopus From 061f7a2caf830332b44b46b660abbf74a1606475 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 16 Jul 2025 15:27:57 +0530 Subject: [PATCH 40/72] fix: remove KEY, VALUE args and make it as KEY=VALUE for set command --- cli/app/commands/conf/command.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py index c935940b..ad092e7d 100644 --- a/cli/app/commands/conf/command.py +++ b/cli/app/commands/conf/command.py @@ -44,7 +44,7 @@ def delete( service: str = typer.Option( "api", "--service", "-s", help="The name of the service to delete configuration for, e.g api,view" ), - key: str = typer.Option(None, "--key", "-k", help="The key of the configuration to delete"), + key: str = typer.Argument(..., help="The key of the configuration to delete"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), @@ -75,8 +75,7 @@ def set( service: str = typer.Option( "api", "--service", "-s", help="The name of the service to set configuration for, e.g api,view" ), - key: str = typer.Option(None, "--key", "-k", help="The key of the configuration to set"), - value: str = typer.Option(None, "--value", "-v", help="The value of the configuration to set"), + key_value: str = typer.Argument(..., help="Configuration in the form KEY=VALUE"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), @@ -86,6 +85,11 @@ def set( logger = Logger(verbose=verbose) try: + if "=" not in key_value: + logger.error("Argument must be in the form KEY=VALUE") + raise typer.Exit(1) + key, value = key_value.split("=", 1) + config = SetConfig( service=service, key=key, value=value, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file ) From ac5de3e20e1df8fdd2f23924410d816d5efdd26f Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 16 Jul 2025 15:46:13 +0530 Subject: [PATCH 41/72] chore: support config loading instead of hardcoding configuration values on cli --- cli/app/commands/conf/base.py | 6 +++-- cli/app/commands/conf/command.py | 3 ++- cli/app/commands/conf/messages.py | 1 + cli/app/utils/config.py | 37 ++++++++++++++++++++++++++++++- cli/app/utils/message.py | 1 + cli/pyproject.toml | 1 + 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/cli/app/commands/conf/base.py b/cli/app/commands/conf/base.py index dd08428b..22b0c5f7 100644 --- a/cli/app/commands/conf/base.py +++ b/cli/app/commands/conf/base.py @@ -7,6 +7,7 @@ from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol +from app.utils.config import Config, API_ENV_FILE, VIEW_ENV_FILE from .messages import ( atomic_complete, @@ -223,12 +224,13 @@ def get_service_env_file(self, service: str, env_file: Optional[str] = None) -> self.logger.debug(using_provided_env.format(env_file=env_file)) return env_file + config = Config() if service == "api": - default_path = "/etc/nixopus/source/api/.env" + default_path = config.get_yaml_value(API_ENV_FILE) self.logger.debug(using_default_api.format(path=default_path)) return default_path elif service == "view": - default_path = "/etc/nixopus/source/view/.env" + default_path = config.get_yaml_value(VIEW_ENV_FILE) self.logger.debug(using_default_view.format(path=default_path)) return default_path else: diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py index ad092e7d..f805cd20 100644 --- a/cli/app/commands/conf/command.py +++ b/cli/app/commands/conf/command.py @@ -4,6 +4,7 @@ from .delete import Delete, DeleteConfig from .list import List, ListConfig +from .messages import argument_must_be_in_form from .set import Set, SetConfig conf_app = typer.Typer(help="Manage configuration") @@ -86,7 +87,7 @@ def set( try: if "=" not in key_value: - logger.error("Argument must be in the form KEY=VALUE") + logger.error(argument_must_be_in_form) raise typer.Exit(1) key, value = key_value.split("=", 1) diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py index 8db97df9..9572329c 100644 --- a/cli/app/commands/conf/messages.py +++ b/cli/app/commands/conf/messages.py @@ -69,3 +69,4 @@ using_default_api = "Using default API path: {path}" using_default_view = "Using default view path: {path}" invalid_service = "Invalid service: {service}" +argument_must_be_in_form = "Argument must be in the form KEY=VALUE" \ No newline at end of file diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index a3c9991f..c0f5aefc 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -1,12 +1,47 @@ import os - +import yaml +import re +from app.utils.message import MISSING_CONFIG_KEY_MESSAGE class Config: def __init__(self, default_env="PRODUCTION"): self.default_env = default_env + self._yaml_config = None + self._yaml_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../helpers/config.prod.yaml")) def get_env(self): return os.environ.get("ENV", self.default_env) def is_development(self): return self.get_env().upper() == "DEVELOPMENT" + + def load_yaml_config(self): + if self._yaml_config is None: + with open(self._yaml_path, "r") as f: + self._yaml_config = yaml.safe_load(f) + return self._yaml_config + + def get_yaml_value(self, path: str): + config = self.load_yaml_config() + keys = path.split('.') + for key in keys: + if isinstance(config, dict) and key in config: + config = config[key] + else: + raise KeyError(MISSING_CONFIG_KEY_MESSAGE.format(path=path, key=key)) + if isinstance(config, str): + config = expand_env_placeholders(config) + return config + + +def expand_env_placeholders(value: str) -> str: + # Expand environment placeholders in the form ${ENV_VAR:-default} + pattern = re.compile(r'\$\{([A-Za-z_][A-Za-z0-9_]*)(:-([^}]*))?}') + def replacer(match): + var_name = match.group(1) + default = match.group(3) if match.group(2) else '' + return os.environ.get(var_name, default) + return pattern.sub(replacer, value) + +VIEW_ENV_FILE = "services.view.env.VIEW_ENV_FILE" +API_ENV_FILE = "services.api.env.API_ENV_FILE" diff --git a/cli/app/utils/message.py b/cli/app/utils/message.py index b6b6df0d..b2167bed 100644 --- a/cli/app/utils/message.py +++ b/cli/app/utils/message.py @@ -14,3 +14,4 @@ HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" REMOVED_DIRECTORY_MESSAGE = "Removed existing directory: {path}" FAILED_TO_REMOVE_DIRECTORY_MESSAGE = "Failed to remove directory: {path}" +MISSING_CONFIG_KEY_MESSAGE = "Missing config key: {path} (failed at '{key}')" \ No newline at end of file diff --git a/cli/pyproject.toml b/cli/pyproject.toml index 9a62858f..a7e8eb04 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -12,6 +12,7 @@ typer = "^0.16.0" rich = "^14.0.0" pydantic = "^2.0.0" requests = "^2.32.3" +pyyaml = "^6.0.2" [tool.poetry.group.dev.dependencies] pytest = "^8.4.1" From 2e8e1d5c047645d0980c6f01468bd3fb7b78a1bf Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 16 Jul 2025 15:49:35 +0530 Subject: [PATCH 42/72] fix: test assertion for backup message --- cli/app/commands/conf/tests/test_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/app/commands/conf/tests/test_base.py b/cli/app/commands/conf/tests/test_base.py index 9a81e086..61a81654 100644 --- a/cli/app/commands/conf/tests/test_base.py +++ b/cli/app/commands/conf/tests/test_base.py @@ -92,7 +92,7 @@ def test_create_backup_failure(self, mock_exists): assert success is False assert backup_path is None - assert "Failed to create backup" in error + assert "Backup creation failed" in error @patch("os.path.exists") def test_restore_backup_success(self, mock_exists): @@ -239,7 +239,7 @@ def test_write_env_file_backup_failure(self, mock_copy, mock_exists): success, error = self.manager.write_env_file("/path/to/.env", config) assert success is False - assert "Failed to create backup" in error + assert "Backup creation failed" in error @patch("os.path.exists") @patch("shutil.copy2") From ec3c2ea43eeb257472547b19d8c06cdf3ff7c1e3 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Wed, 16 Jul 2025 18:35:19 +0530 Subject: [PATCH 43/72] feat : (#288) cli uses helpers/config.yaml for frequently moving parts of the code --- cli/app/commands/{install => clone}/clone.py | 2 +- cli/app/commands/clone/command.py | 35 ++++++++++++ .../{install => clone}/tests/test_clone.py | 2 +- cli/app/commands/install/command.py | 24 -------- cli/app/commands/proxy/__init__.py | 3 - cli/app/commands/proxy/base.py | 57 ++++++++++--------- cli/app/commands/proxy/command.py | 9 ++- cli/app/commands/proxy/load.py | 10 +++- cli/app/commands/proxy/messages.py | 14 +---- cli/app/commands/proxy/status.py | 9 ++- cli/app/commands/proxy/stop.py | 10 +++- cli/app/commands/service/base.py | 20 +++---- cli/app/commands/service/command.py | 13 +++-- cli/app/commands/service/messages.py | 6 ++ cli/app/main.py | 2 + cli/app/utils/config.py | 10 ++++ helpers/config.prod.yaml | 10 ++++ 17 files changed, 138 insertions(+), 98 deletions(-) rename cli/app/commands/{install => clone}/clone.py (99%) create mode 100644 cli/app/commands/clone/command.py rename cli/app/commands/{install => clone}/tests/test_clone.py (99%) diff --git a/cli/app/commands/install/clone.py b/cli/app/commands/clone/clone.py similarity index 99% rename from cli/app/commands/install/clone.py rename to cli/app/commands/clone/clone.py index 3c6ee3a0..355a094e 100644 --- a/cli/app/commands/install/clone.py +++ b/cli/app/commands/clone/clone.py @@ -9,7 +9,7 @@ from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol -from .messages import ( +from ..install.messages import ( cloning_repo_into_path, default_branch, dry_run_branch, diff --git a/cli/app/commands/clone/command.py b/cli/app/commands/clone/command.py new file mode 100644 index 00000000..18a95b7d --- /dev/null +++ b/cli/app/commands/clone/command.py @@ -0,0 +1,35 @@ +import typer + +from app.utils.logger import Logger +from app.utils.config import Config, DEFAULT_REPO, DEFAULT_BRANCH, DEFAULT_PATH, NIXOPUS_CONFIG_DIR + +from .clone import Clone, CloneConfig + +config = Config() +nixopus_config_dir = config.get_yaml_value(NIXOPUS_CONFIG_DIR) +repo = config.get_yaml_value(DEFAULT_REPO) +branch = config.get_yaml_value(DEFAULT_BRANCH) +path = nixopus_config_dir + "/" + config.get_yaml_value(DEFAULT_PATH) + +clone_app = typer.Typer(help="Clone a repository", invoke_without_command=True) + +@clone_app.callback() +def clone_callback( + repo: str = typer.Option(repo, "--repo", "-r", help="The repository to clone"), + branch: str = typer.Option(branch, "--branch", "-b", help="The branch to clone"), + path: str = typer.Option(path, "--path", "-p", help="The path to clone the repository to"), + force: bool = typer.Option(False, "--force", "-f", help="Force the clone"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), +): + """Clone a repository""" + try: + logger = Logger(verbose=verbose) + config = CloneConfig(repo=repo, branch=branch, path=path, force=force, verbose=verbose, output=output, dry_run=dry_run) + clone_operation = Clone(logger=logger) + result = clone_operation.clone(config) + logger.success(result.output) + except Exception as e: + logger.error(e) + raise typer.Exit(1) diff --git a/cli/app/commands/install/tests/test_clone.py b/cli/app/commands/clone/tests/test_clone.py similarity index 99% rename from cli/app/commands/install/tests/test_clone.py rename to cli/app/commands/clone/tests/test_clone.py index 5eca6c4d..d24ac84b 100644 --- a/cli/app/commands/install/tests/test_clone.py +++ b/cli/app/commands/clone/tests/test_clone.py @@ -4,7 +4,7 @@ import pytest from pydantic import ValidationError -from app.commands.install.clone import ( +from cli.app.commands.clone.clone import ( Clone, CloneConfig, CloneFormatter, diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index b0f38032..ad1cd872 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -2,7 +2,6 @@ from app.utils.logger import Logger -from .clone import Clone, CloneConfig from .run import Install from .ssh import SSH, SSHConfig @@ -23,29 +22,6 @@ def main_install_callback(value: bool): install.run() raise typer.Exit() - -@install_app.command() -def clone( - repo: str = typer.Option("https://github.com/raghavyuva/nixopus", "--repo", "-r", help="The repository to clone"), - branch: str = typer.Option("master", "--branch", "-b", help="The branch to clone"), - path: str = typer.Option("/etc/nixopus", "--path", "-p", help="The path to clone the repository to"), - force: bool = typer.Option(False, "--force", "-f", help="Force the clone"), - verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), - output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), - dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), -): - """Clone a repository""" - try: - logger = Logger(verbose=verbose) - config = CloneConfig(repo=repo, branch=branch, path=path, force=force, verbose=verbose, output=output, dry_run=dry_run) - clone_operation = Clone(logger=logger) - result = clone_operation.clone(config) - logger.success(result.output) - except Exception as e: - logger.error(e) - raise typer.Exit(1) - - def ssh( path: str = typer.Option("~/.ssh/nixopus_ed25519", "--path", "-p", help="The SSH key path to generate"), key_type: str = typer.Option("ed25519", "--key-type", "-t", help="The SSH key type (rsa, ed25519, ecdsa)"), diff --git a/cli/app/commands/proxy/__init__.py b/cli/app/commands/proxy/__init__.py index 7254999f..e69de29b 100644 --- a/cli/app/commands/proxy/__init__.py +++ b/cli/app/commands/proxy/__init__.py @@ -1,3 +0,0 @@ -from .command import proxy_app - -__all__ = ["proxy_app"] diff --git a/cli/app/commands/proxy/base.py b/cli/app/commands/proxy/base.py index 3b65a758..6a9b4353 100644 --- a/cli/app/commands/proxy/base.py +++ b/cli/app/commands/proxy/base.py @@ -6,6 +6,7 @@ import requests from pydantic import BaseModel, Field, field_validator +from app.utils.config import Config, PROXY_PORT, CONFIG_ENDPOINT, LOAD_ENDPOINT, STOP_ENDPOINT, CADDY_BASE_URL from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol @@ -19,37 +20,39 @@ info_caddy_stopped, info_config_loaded, invalid_json_config, + port_must_be_between_1_and_65535, ) TConfig = TypeVar("TConfig", bound=BaseModel) TResult = TypeVar("TResult", bound=BaseModel) -CADDY_BASE_URL = "http://localhost:{port}" -CADDY_CONFIG_ENDPOINT = "/config/" -CADDY_LOAD_ENDPOINT = "/load" -CADDY_STOP_ENDPOINT = "/stop" - +config = Config() +proxy_port = config.get_yaml_value(PROXY_PORT) +caddy_config_endpoint = config.get_yaml_value(CONFIG_ENDPOINT) +caddy_load_endpoint = config.get_yaml_value(LOAD_ENDPOINT) +caddy_stop_endpoint = config.get_yaml_value(STOP_ENDPOINT) +caddy_base_url = config.get_yaml_value(CADDY_BASE_URL) class CaddyServiceProtocol(Protocol): - def check_status(self, port: int = 2019) -> tuple[bool, str]: ... + def check_status(self, port: int = proxy_port) -> tuple[bool, str]: ... - def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: ... + def load_config(self, config_file: str, port: int = proxy_port) -> tuple[bool, str]: ... - def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: ... + def stop_proxy(self, port: int = proxy_port) -> tuple[bool, str]: ... class BaseCaddyCommandBuilder: @staticmethod - def build_status_command(port: int = 2019) -> list[str]: - return ["curl", "-X", "GET", f"{CADDY_BASE_URL.format(port=port)}{CADDY_CONFIG_ENDPOINT}"] + def build_status_command(port: int = proxy_port) -> list[str]: + return ["curl", "-X", "GET", f"{caddy_base_url.format(port=port)}{caddy_config_endpoint}"] @staticmethod - def build_load_command(config_file: str, port: int = 2019) -> list[str]: + def build_load_command(config_file: str, port: int = proxy_port) -> list[str]: return [ "curl", "-X", "POST", - f"{CADDY_BASE_URL.format(port=port)}{CADDY_LOAD_ENDPOINT}", + f"{caddy_base_url.format(port=port)}{caddy_load_endpoint}", "-H", "Content-Type: application/json", "-d", @@ -57,8 +60,8 @@ def build_load_command(config_file: str, port: int = 2019) -> list[str]: ] @staticmethod - def build_stop_command(port: int = 2019) -> list[str]: - return ["curl", "-X", "POST", f"{CADDY_BASE_URL.format(port=port)}{CADDY_STOP_ENDPOINT}"] + def build_stop_command(port: int = proxy_port) -> list[str]: + return ["curl", "-X", "POST", f"{caddy_base_url.format(port=port)}{caddy_stop_endpoint}"] class BaseFormatter: @@ -77,11 +80,11 @@ def format_output(self, result: TResult, output: str, success_message: str, erro def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dict) -> str: if hasattr(command_builder, "build_status_command"): - cmd = command_builder.build_status_command(getattr(config, "proxy_port", 2019)) + cmd = command_builder.build_status_command(getattr(config, "proxy_port", proxy_port)) elif hasattr(command_builder, "build_load_command"): - cmd = command_builder.build_load_command(getattr(config, "config_file", ""), getattr(config, "proxy_port", 2019)) + cmd = command_builder.build_load_command(getattr(config, "config_file", ""), getattr(config, "proxy_port", proxy_port)) elif hasattr(command_builder, "build_stop_command"): - cmd = command_builder.build_stop_command(getattr(config, "proxy_port", 2019)) + cmd = command_builder.build_stop_command(getattr(config, "proxy_port", proxy_port)) else: cmd = command_builder.build_command(config) @@ -89,7 +92,7 @@ def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dic output.append(dry_run_messages["mode"]) output.append(dry_run_messages["command_would_be_executed"]) output.append(f"{dry_run_messages['command']} {' '.join(cmd)}") - output.append(f"{dry_run_messages['port']} {getattr(config, 'proxy_port', 2019)}") + output.append(f"{dry_run_messages['port']} {getattr(config, 'proxy_port', proxy_port)}") if hasattr(config, "config_file") and getattr(config, "config_file", None): output.append(f"{dry_run_messages['config_file']} {getattr(config, 'config_file')}") @@ -103,11 +106,11 @@ def __init__(self, logger: LoggerProtocol): self.logger = logger def _get_caddy_url(self, port: int, endpoint: str) -> str: - return f"{CADDY_BASE_URL.format(port=port)}{endpoint}" + return f"{caddy_base_url.format(port=port)}{endpoint}" - def check_status(self, port: int = 2019) -> tuple[bool, str]: + def check_status(self, port: int = proxy_port) -> tuple[bool, str]: try: - url = self._get_caddy_url(port, CADDY_CONFIG_ENDPOINT) + url = self._get_caddy_url(port, caddy_config_endpoint) response = requests.get(url, timeout=5) if response.status_code == 200: return True, info_caddy_running @@ -118,12 +121,12 @@ def check_status(self, port: int = 2019) -> tuple[bool, str]: except Exception as e: return False, f"Unexpected error: {str(e)}" - def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: + def load_config(self, config_file: str, port: int = proxy_port) -> tuple[bool, str]: try: with open(config_file, "r") as f: config_data = json.load(f) - url = self._get_caddy_url(port, CADDY_LOAD_ENDPOINT) + url = self._get_caddy_url(port, caddy_load_endpoint) response = requests.post(url, json=config_data, headers={"Content-Type": "application/json"}, timeout=10) if response.status_code == 200: @@ -139,9 +142,9 @@ def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: except Exception as e: return False, f"Unexpected error: {str(e)}" - def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: + def stop_proxy(self, port: int = proxy_port) -> tuple[bool, str]: try: - url = self._get_caddy_url(port, CADDY_STOP_ENDPOINT) + url = self._get_caddy_url(port, caddy_stop_endpoint) response = requests.post(url, timeout=5) if response.status_code == 200: return True, info_caddy_stopped @@ -154,7 +157,7 @@ def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: class BaseConfig(BaseModel): - proxy_port: int = Field(2019, description="Caddy admin port") + proxy_port: int = Field(proxy_port, description="Caddy admin port") verbose: bool = Field(False, description="Verbose output") output: str = Field("text", description="Output format: text, json") dry_run: bool = Field(False, description="Dry run mode") @@ -163,7 +166,7 @@ class BaseConfig(BaseModel): @classmethod def validate_proxy_port(cls, port: int) -> int: if port < 1 or port > 65535: - raise ValueError("Port must be between 1 and 65535") + raise ValueError(port_must_be_between_1_and_65535) return port diff --git a/cli/app/commands/proxy/command.py b/cli/app/commands/proxy/command.py index 7d3d4714..09831bff 100644 --- a/cli/app/commands/proxy/command.py +++ b/cli/app/commands/proxy/command.py @@ -1,5 +1,6 @@ import typer +from app.utils.config import Config, PROXY_PORT from app.utils.logger import Logger from .load import Load, LoadConfig @@ -11,10 +12,12 @@ help="Manage Nixopus proxy (Caddy) configuration", ) +config = Config() +proxy_port = config.get_yaml_value(PROXY_PORT) @proxy_app.command() def load( - proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), + proxy_port: int = typer.Option(proxy_port, "--proxy-port", "-p", help="Caddy admin port"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), @@ -42,7 +45,7 @@ def load( @proxy_app.command() def status( - proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), + proxy_port: int = typer.Option(proxy_port, "--proxy-port", "-p", help="Caddy admin port"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), @@ -69,7 +72,7 @@ def status( @proxy_app.command() def stop( - proxy_port: int = typer.Option(2019, "--proxy-port", "-p", help="Caddy admin port"), + proxy_port: int = typer.Option(proxy_port, "--proxy-port", "-p", help="Caddy admin port"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), diff --git a/cli/app/commands/proxy/load.py b/cli/app/commands/proxy/load.py index 853db4d8..4bf3b009 100644 --- a/cli/app/commands/proxy/load.py +++ b/cli/app/commands/proxy/load.py @@ -3,6 +3,7 @@ from pydantic import BaseModel, Field, field_validator +from app.utils.config import Config, PROXY_PORT from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol @@ -21,14 +22,17 @@ proxy_initialized_successfully, ) +config = Config() +proxy_port = config.get_yaml_value(PROXY_PORT) + class CaddyServiceProtocol(Protocol): - def load_config(self, config_file: str, port: int = 2019) -> tuple[bool, str]: ... + def load_config(self, config_file: str, port: int = proxy_port) -> tuple[bool, str]: ... class CaddyCommandBuilder(BaseCaddyCommandBuilder): @staticmethod - def build_load_command(config_file: str, port: int = 2019) -> list[str]: + def build_load_command(config_file: str, port: int = proxy_port) -> list[str]: return BaseCaddyCommandBuilder.build_load_command(config_file, port) @@ -52,7 +56,7 @@ class CaddyService(BaseCaddyService): def __init__(self, logger: LoggerProtocol): super().__init__(logger) - def load_config_file(self, config_file: str, port: int = 2019) -> tuple[bool, str]: + def load_config_file(self, config_file: str, port: int = proxy_port) -> tuple[bool, str]: return self.load_config(config_file, port) diff --git a/cli/app/commands/proxy/messages.py b/cli/app/commands/proxy/messages.py index f53860a0..c0ccc5ef 100644 --- a/cli/app/commands/proxy/messages.py +++ b/cli/app/commands/proxy/messages.py @@ -1,41 +1,29 @@ -# Dry run messages dry_run_mode = "🔍 DRY RUN MODE" dry_run_command_would_be_executed = "The following command would be executed:" dry_run_command = "Command:" dry_run_port = "Port:" dry_run_config_file = "Config file:" end_dry_run = "--- End of dry run ---" - -# Success messages proxy_initialized_successfully = "Caddy proxy initialized successfully on port {port}" proxy_status_running = "Caddy proxy is running on port {port}" proxy_reloaded_successfully = "Caddy proxy configuration reloaded successfully on port {port}" proxy_stopped_successfully = "Caddy proxy stopped successfully on port {port}" - -# Error messages proxy_init_failed = "Failed to initialize Caddy proxy" proxy_status_stopped = "Caddy proxy is not running on port {port}" proxy_status_failed = "Failed to check Caddy proxy status" proxy_reload_failed = "Failed to reload Caddy proxy configuration" proxy_stop_failed = "Failed to stop Caddy proxy" - -# Validation messages config_file_required = "Configuration file is required" config_file_not_found = "Configuration file not found: {file}" invalid_json_config = "Invalid JSON in configuration file: {error}" - -# Connection messages +port_must_be_between_1_and_65535 = "Port must be between 1 and 65535" caddy_connection_failed = "Failed to connect to Caddy: {error}" caddy_status_code_error = "Caddy returned status code: {code}" caddy_load_failed = "Failed to load configuration: {code} - {response}" - -# Debug messages debug_init_proxy = "Initializing Caddy proxy on port: {port}" debug_check_status = "Checking Caddy proxy status on port: {port}" debug_reload_config = "Reloading Caddy proxy configuration on port: {port}" debug_stop_proxy = "Stopping Caddy proxy on port: {port}" - -# Info messages info_caddy_running = "Caddy is running" info_config_loaded = "Configuration loaded successfully" info_caddy_stopped = "Caddy stopped successfully" diff --git a/cli/app/commands/proxy/status.py b/cli/app/commands/proxy/status.py index ae03d45f..7c50bb38 100644 --- a/cli/app/commands/proxy/status.py +++ b/cli/app/commands/proxy/status.py @@ -2,6 +2,7 @@ from pydantic import BaseModel +from app.utils.config import Config, PROXY_PORT from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol @@ -19,14 +20,16 @@ proxy_status_stopped, ) +config = Config() +proxy_port = config.get_yaml_value(PROXY_PORT) class CaddyServiceProtocol(Protocol): - def check_status(self, port: int = 2019) -> tuple[bool, str]: ... + def check_status(self, port: int = proxy_port) -> tuple[bool, str]: ... class CaddyCommandBuilder(BaseCaddyCommandBuilder): @staticmethod - def build_status_command(port: int = 2019) -> list[str]: + def build_status_command(port: int = proxy_port) -> list[str]: return BaseCaddyCommandBuilder.build_status_command(port) @@ -54,7 +57,7 @@ class CaddyService(BaseCaddyService): def __init__(self, logger: LoggerProtocol): super().__init__(logger) - def get_status(self, port: int = 2019) -> tuple[bool, str]: + def get_status(self, port: int = proxy_port) -> tuple[bool, str]: return self.check_status(port) diff --git a/cli/app/commands/proxy/stop.py b/cli/app/commands/proxy/stop.py index 6907783a..bd32bc1f 100644 --- a/cli/app/commands/proxy/stop.py +++ b/cli/app/commands/proxy/stop.py @@ -2,6 +2,7 @@ from pydantic import BaseModel +from app.utils.config import Config, PROXY_PORT from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol @@ -18,14 +19,17 @@ proxy_stopped_successfully, ) +config = Config() +proxy_port = config.get_yaml_value(PROXY_PORT) + class CaddyServiceProtocol(Protocol): - def stop_proxy(self, port: int = 2019) -> tuple[bool, str]: ... + def stop_proxy(self, port: int = proxy_port) -> tuple[bool, str]: ... class CaddyCommandBuilder(BaseCaddyCommandBuilder): @staticmethod - def build_stop_command(port: int = 2019) -> list[str]: + def build_stop_command(port: int = proxy_port) -> list[str]: return BaseCaddyCommandBuilder.build_stop_command(port) @@ -48,7 +52,7 @@ class CaddyService(BaseCaddyService): def __init__(self, logger: LoggerProtocol): super().__init__(logger) - def stop_caddy(self, port: int = 2019) -> tuple[bool, str]: + def stop_caddy(self, port: int = proxy_port) -> tuple[bool, str]: return self.stop_proxy(port) diff --git a/cli/app/commands/service/base.py b/cli/app/commands/service/base.py index 2baaa1c5..c97bb40c 100644 --- a/cli/app/commands/service/base.py +++ b/cli/app/commands/service/base.py @@ -7,6 +7,7 @@ from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol +from .messages import service_action_info, service_action_success, service_action_failed, service_action_unexpected_error, environment_file_not_found, compose_file_not_found TConfig = TypeVar("TConfig", bound=BaseModel) TResult = TypeVar("TResult", bound=BaseModel) @@ -96,28 +97,21 @@ def __init__(self, logger: LoggerProtocol, action: str): self.logger = logger self.action = action - def _past_tense(self): - if self.action == "up": - return "upped" - elif self.action == "down": - return "downed" - return f"{self.action}ed" - def execute_services( self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs ) -> tuple[bool, str]: cmd = BaseDockerCommandBuilder.build_command(self.action, name, env_file, compose_file, **kwargs) try: - self.logger.info(f"{self.action.capitalize()}ing services: {name}") + self.logger.info(service_action_info.format(action=self.action, name=name)) result = subprocess.run(cmd, capture_output=True, text=True, check=True) - self.logger.success(f"Services {self._past_tense()} successfully: {name}") + self.logger.success(service_action_success.format(action=self.action, name=name)) return True, None except subprocess.CalledProcessError as e: - self.logger.error(f"Service {self.action} failed: {e.stderr}") + self.logger.error(service_action_failed.format(action=self.action, error=e.stderr)) return False, e.stderr except Exception as e: - self.logger.error(f"Unexpected error during {self.action}: {e}") + self.logger.error(service_action_unexpected_error.format(action=self.action, error=e)) return False, str(e) @@ -138,7 +132,7 @@ def validate_env_file(cls, env_file: str) -> Optional[str]: if not stripped_env_file: return None if not os.path.exists(stripped_env_file): - raise ValueError(f"Environment file not found: {stripped_env_file}") + raise ValueError(environment_file_not_found.format(path=stripped_env_file)) return stripped_env_file @field_validator("compose_file") @@ -150,7 +144,7 @@ def validate_compose_file(cls, compose_file: str) -> Optional[str]: if not stripped_compose_file: return None if not os.path.exists(stripped_compose_file): - raise ValueError(f"Compose file not found: {stripped_compose_file}") + raise ValueError(compose_file_not_found.format(path=stripped_compose_file)) return stripped_compose_file diff --git a/cli/app/commands/service/command.py b/cli/app/commands/service/command.py index 0747330f..55318f97 100644 --- a/cli/app/commands/service/command.py +++ b/cli/app/commands/service/command.py @@ -1,5 +1,6 @@ import typer +from app.utils.config import Config, DEFAULT_COMPOSE_FILE, NIXOPUS_CONFIG_DIR from app.utils.logger import Logger from .down import Down, DownConfig @@ -9,6 +10,10 @@ service_app = typer.Typer(help="Manage Nixopus services") +config = Config() +nixopus_config_dir = config.get_yaml_value(NIXOPUS_CONFIG_DIR) +compose_file = config.get_yaml_value(DEFAULT_COMPOSE_FILE) +compose_file_path = nixopus_config_dir + "/" + compose_file @service_app.command() def up( @@ -18,7 +23,7 @@ def up( dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), detach: bool = typer.Option(False, "--detach", "-d", help="Detach from the service and run in the background"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), - compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), + compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), ): """Start Nixopus services""" logger = Logger(verbose=verbose) @@ -55,7 +60,7 @@ def down( output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), - compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), + compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), ): """Stop Nixopus services""" logger = Logger(verbose=verbose) @@ -86,7 +91,7 @@ def ps( output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), - compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), + compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), ): """Show status of Nixopus services""" logger = Logger(verbose=verbose) @@ -117,7 +122,7 @@ def restart( output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), - compose_file: str = typer.Option(None, "--compose-file", "-f", help="Path to the compose file"), + compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), ): """Restart Nixopus services""" logger = Logger(verbose=verbose) diff --git a/cli/app/commands/service/messages.py b/cli/app/commands/service/messages.py index aab9e9e2..23cf3037 100644 --- a/cli/app/commands/service/messages.py +++ b/cli/app/commands/service/messages.py @@ -22,3 +22,9 @@ service_restart_failed = "Service restart failed: {error}" unexpected_error_during_restart = "Unexpected error during restart: {error}" unknown_error = "Unknown error occurred" +service_action_info = "{action} services: {name}" +service_action_success = "Service {action} successful: {name}" +service_action_failed = "Service {action} failed: {error}" +service_action_unexpected_error = "Unexpected error during {action}: {error}" +environment_file_not_found = "Environment file not found: {path}" +compose_file_not_found = "Compose file not found: {path}" diff --git a/cli/app/main.py b/cli/app/main.py index e55b4869..5d34b8f9 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -1,5 +1,6 @@ import typer +from app.commands.clone.command import clone_app from app.commands.conf.command import conf_app from app.commands.install.command import install_app from app.commands.preflight.command import preflight_app @@ -30,6 +31,7 @@ def main( app.add_typer(preflight_app, name="preflight") +app.add_typer(clone_app, name="clone") app.add_typer(conf_app, name="conf") app.add_typer(service_app, name="service") app.add_typer(proxy_app, name="proxy") diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index c0f5aefc..4285e111 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -45,3 +45,13 @@ def replacer(match): VIEW_ENV_FILE = "services.view.env.VIEW_ENV_FILE" API_ENV_FILE = "services.api.env.API_ENV_FILE" +DEFAULT_REPO = "clone.repo" +DEFAULT_BRANCH = "clone.branch" +DEFAULT_PATH = "clone.source-path" +DEFAULT_COMPOSE_FILE = "compose-file-path" +NIXOPUS_CONFIG_DIR = "nixopus-config-dir" +PROXY_PORT = "services.caddy.env.PROXY_PORT" +CADDY_BASE_URL = "services.caddy.env.BASE_URL" +CONFIG_ENDPOINT = "services.caddy.env.CONFIG_ENDPOINT" +LOAD_ENDPOINT = "services.caddy.env.LOAD_ENDPOINT" +STOP_ENDPOINT = "services.caddy.env.STOP_ENDPOINT" diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index 82761f32..1dadd2b9 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -66,6 +66,11 @@ services: CADDY_PORTS: "2019:2019,80:80,443:443" API_DOMAIN: ${API_DOMAIN:-} VIEW_DOMAIN: ${VIEW_DOMAIN:-} + BASE_URL: ${BASE_URL:-} + PROXY_PORT: ${PROXY_PORT:-2019} + CONFIG_ENDPOINT: ${CONFIG_ENDPOINT:-/config} + LOAD_ENDPOINT: ${LOAD_ENDPOINT:-/load} + STOP_ENDPOINT: ${STOP_ENDPOINT:-/stop} CADDY_COMMAND: [ "caddy", "run", @@ -95,3 +100,8 @@ deps: python3-venv: { version: "" } nixopus-config-dir: /etc/nixopus +compose-file-path: docker-compose.yml +clone: + repo: "https://github.com/raghavyuva/nixopus" + branch: "master" + source-path: source \ No newline at end of file From bbe2efee0733153b4acfc5c4c944d00ff8b9f8e0 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Thu, 17 Jul 2025 19:54:13 +0530 Subject: [PATCH 44/72] fix: (#289) issues with failing tests because of import issues and error messages mismatches --- cli/app/commands/clone/__init__.py | 1 + cli/app/commands/clone/tests/__init__.py | 0 cli/app/commands/clone/tests/test_clone.py | 2 +- cli/app/commands/install/tests/test_ssh.py | 2 +- cli/app/commands/service/tests/test_base.py | 4 ++-- cli/app/commands/service/tests/test_down.py | 4 ++-- cli/app/commands/service/tests/test_ps.py | 4 ++-- cli/app/commands/service/tests/test_restart.py | 4 ++-- cli/app/commands/service/tests/test_up.py | 4 ++-- 9 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 cli/app/commands/clone/__init__.py create mode 100644 cli/app/commands/clone/tests/__init__.py diff --git a/cli/app/commands/clone/__init__.py b/cli/app/commands/clone/__init__.py new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/cli/app/commands/clone/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/cli/app/commands/clone/tests/__init__.py b/cli/app/commands/clone/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/clone/tests/test_clone.py b/cli/app/commands/clone/tests/test_clone.py index d24ac84b..f2f847a1 100644 --- a/cli/app/commands/clone/tests/test_clone.py +++ b/cli/app/commands/clone/tests/test_clone.py @@ -4,7 +4,7 @@ import pytest from pydantic import ValidationError -from cli.app.commands.clone.clone import ( +from ..clone import ( Clone, CloneConfig, CloneFormatter, diff --git a/cli/app/commands/install/tests/test_ssh.py b/cli/app/commands/install/tests/test_ssh.py index bbad4786..1332fedb 100644 --- a/cli/app/commands/install/tests/test_ssh.py +++ b/cli/app/commands/install/tests/test_ssh.py @@ -3,7 +3,7 @@ import unittest from unittest.mock import MagicMock, Mock, patch -from app.commands.install.ssh import SSH, SSHCommandBuilder, SSHConfig, SSHKeyManager +from ..ssh import SSH, SSHCommandBuilder, SSHConfig, SSHKeyManager class TestSSHKeyGeneration(unittest.TestCase): diff --git a/cli/app/commands/service/tests/test_base.py b/cli/app/commands/service/tests/test_base.py index fd92313e..c5966b69 100644 --- a/cli/app/commands/service/tests/test_base.py +++ b/cli/app/commands/service/tests/test_base.py @@ -115,8 +115,8 @@ def test_execute_services_success(self, mock_run): assert success is True assert error is None - self.logger.info.assert_called_once_with("Uping services: web") - self.logger.success.assert_called_once_with("Services upped successfully: web") + self.logger.info.assert_called_once_with("up services: web") + self.logger.success.assert_called_once_with("Service up successful: web") @patch("subprocess.run") def test_execute_services_failure(self, mock_run): diff --git a/cli/app/commands/service/tests/test_down.py b/cli/app/commands/service/tests/test_down.py index 6adc33dc..40ef5719 100644 --- a/cli/app/commands/service/tests/test_down.py +++ b/cli/app/commands/service/tests/test_down.py @@ -118,8 +118,8 @@ def test_stop_services_success(self, mock_run): assert success is True assert error is None - self.logger.info.assert_called_once_with("Downing services: web") - self.logger.success.assert_called_once_with("Services downed successfully: web") + self.logger.info.assert_called_once_with("down services: web") + self.logger.success.assert_called_once_with("Service down successful: web") @patch("subprocess.run") def test_stop_services_with_env_file(self, mock_run): diff --git a/cli/app/commands/service/tests/test_ps.py b/cli/app/commands/service/tests/test_ps.py index e709b946..7bd33ff9 100644 --- a/cli/app/commands/service/tests/test_ps.py +++ b/cli/app/commands/service/tests/test_ps.py @@ -115,8 +115,8 @@ def test_show_services_status_success(self, mock_run): assert success is True assert error is None - self.logger.info.assert_called_once_with("Psing services: web") - self.logger.success.assert_called_once_with("Services psed successfully: web") + self.logger.info.assert_called_once_with("ps services: web") + self.logger.success.assert_called_once_with("Service ps successful: web") @patch("subprocess.run") def test_show_services_status_with_env_file(self, mock_run): diff --git a/cli/app/commands/service/tests/test_restart.py b/cli/app/commands/service/tests/test_restart.py index 3cb23c98..ee3096f5 100644 --- a/cli/app/commands/service/tests/test_restart.py +++ b/cli/app/commands/service/tests/test_restart.py @@ -134,8 +134,8 @@ def test_restart_services_success(self, mock_run): assert success is True assert error is None - self.logger.info.assert_called_once_with("Restarting services: web") - self.logger.success.assert_called_once_with("Services restarted successfully: web") + self.logger.info.assert_called_once_with("restart services: web") + self.logger.success.assert_called_once_with("Service restart successful: web") @patch("subprocess.run") def test_restart_services_with_env_file(self, mock_run): diff --git a/cli/app/commands/service/tests/test_up.py b/cli/app/commands/service/tests/test_up.py index a03ef82c..c7386412 100644 --- a/cli/app/commands/service/tests/test_up.py +++ b/cli/app/commands/service/tests/test_up.py @@ -120,8 +120,8 @@ def test_start_services_success(self, mock_run): assert success is True assert error is None - self.logger.info.assert_called_once_with("Uping services: web") - self.logger.success.assert_called_once_with("Services upped successfully: web") + self.logger.info.assert_called_once_with("up services: web") + self.logger.success.assert_called_once_with("Service up successful: web") @patch("subprocess.run") def test_start_services_with_env_file(self, mock_run): From 38eb29436fc1ed8518b8d058d2eecd40a4c2129b Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Thu, 17 Jul 2025 19:54:45 +0530 Subject: [PATCH 45/72] feat:(#290) command to install required dependencies for nixopus --- cli/app/commands/install/__init__.py | 1 + cli/app/commands/install/command.py | 19 ++++ cli/app/commands/install/deps.py | 101 +++++++++++++++++++++ cli/app/commands/install/messages.py | 6 ++ cli/app/commands/install/tests/__init__.py | 0 cli/app/utils/config.py | 1 + helpers/config.prod.yaml | 2 +- 7 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 cli/app/commands/install/__init__.py create mode 100644 cli/app/commands/install/deps.py create mode 100644 cli/app/commands/install/tests/__init__.py diff --git a/cli/app/commands/install/__init__.py b/cli/app/commands/install/__init__.py new file mode 100644 index 00000000..0519ecba --- /dev/null +++ b/cli/app/commands/install/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index ad1cd872..96b35520 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -1,6 +1,8 @@ import typer +from app.utils.config import Config from app.utils.logger import Logger +from .deps import install_all_deps from .run import Install from .ssh import SSH, SSHConfig @@ -61,3 +63,20 @@ def ssh( except Exception as e: logger.error(e) raise typer.Exit(1) + +def deps( + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), +): + """Install dependencies""" + try: + logger = Logger(verbose=verbose) + result = install_all_deps(verbose=verbose, output=output, dry_run=dry_run) + if output == "json": + print(result) + else: + logger.success("All dependencies installed successfully.") + except Exception as e: + logger.error(e) + raise typer.Exit(1) diff --git a/cli/app/commands/install/deps.py b/cli/app/commands/install/deps.py new file mode 100644 index 00000000..900423c7 --- /dev/null +++ b/cli/app/commands/install/deps.py @@ -0,0 +1,101 @@ +import subprocess +import json +from app.utils.config import Config +from app.utils.lib import HostInformation +from app.utils.logger import Logger +from app.commands.preflight.deps import Deps, DepsConfig +from app.utils.config import DEPS +from .messages import ( + unsupported_package_manager, + no_supported_package_manager, + failed_to_install, + installing_dep, + dry_run_update_cmd, + dry_run_install_cmd, +) + +def get_deps_from_config(): + config = Config() + deps = config.get_yaml_value(DEPS) + return list(deps.keys()) + +def get_installed_deps(dep_names, os_name, package_manager, timeout=2, verbose=False): + config = DepsConfig( + deps=list(dep_names), + timeout=timeout, + verbose=verbose, + output="json", + os=os_name, + package_manager=package_manager, + ) + deps_checker = Deps() + results = deps_checker.check(config) + return {r.dependency: r.is_available for r in results} + +def update_system_packages(package_manager, logger, dry_run=False): + if package_manager == "apt": + cmd = ["sudo", "apt-get", "update"] + elif package_manager == "brew": + cmd = ["brew", "update"] + elif package_manager == "apk": + cmd = ["sudo", "apk", "update"] + elif package_manager == "yum": + cmd = ["sudo", "yum", "update"] + elif package_manager == "dnf": + cmd = ["sudo", "dnf", "update"] + elif package_manager == "pacman": + cmd = ["sudo", "pacman", "-Sy"] + else: + raise Exception(unsupported_package_manager.format(package_manager=package_manager)) + if dry_run: + logger.info(dry_run_update_cmd.format(cmd=' '.join(cmd))) + else: + subprocess.check_call(cmd) + +def install_dep(dep, package_manager, logger, dry_run=False): + try: + if package_manager == "apt": + cmd = ["sudo", "apt-get", "install", "-y", dep] + elif package_manager == "brew": + cmd = ["brew", "install", dep] + elif package_manager == "apk": + cmd = ["sudo", "apk", "add", dep] + elif package_manager == "yum": + cmd = ["sudo", "yum", "install", "-y", dep] + elif package_manager == "dnf": + cmd = ["sudo", "dnf", "install", "-y", dep] + elif package_manager == "pacman": + cmd = ["sudo", "pacman", "-S", "--noconfirm", dep] + else: + raise Exception(unsupported_package_manager.format(package_manager=package_manager)) + logger.info(installing_dep.format(dep=dep)) + if dry_run: + logger.info(dry_run_install_cmd.format(cmd=' '.join(cmd))) + return True + subprocess.check_call(cmd) + return True + except Exception as e: + logger.error(failed_to_install.format(dep=dep, error=e)) + return False + +def install_all_deps(verbose=False, output="text", dry_run=False): + logger = Logger(verbose=verbose) + deps = get_deps_from_config() + os_name = HostInformation.get_os_name() + package_manager = HostInformation.get_package_manager() + if not package_manager: + raise Exception(no_supported_package_manager) + installed = get_installed_deps(deps, os_name, package_manager, verbose=verbose) + update_system_packages(package_manager, logger, dry_run=dry_run) + to_install = [dep for dep in deps if not installed.get(dep)] + results = [] + for dep in to_install: + ok = install_dep(dep, package_manager, logger, dry_run=dry_run) + results.append({"dependency": dep, "installed": ok}) + installed_after = get_installed_deps(deps, os_name, package_manager, verbose=verbose) + failed = [dep for dep, ok in installed_after.items() if not ok] + if failed and not dry_run: + raise Exception(failed_to_install.format(dep=','.join(failed), error='')) + if output == "json": + return json.dumps({"installed": results, "failed": failed, "dry_run": dry_run}) + return True diff --git a/cli/app/commands/install/messages.py b/cli/app/commands/install/messages.py index 08613072..a82a9b38 100644 --- a/cli/app/commands/install/messages.py +++ b/cli/app/commands/install/messages.py @@ -58,3 +58,9 @@ failed_to_add_to_authorized_keys = "Failed to add to authorized_keys: {error}" unknown_error = "Unknown error" default_branch = "default" +unsupported_package_manager = "Unsupported package manager: {package_manager}" +no_supported_package_manager = "No supported package manager found" +failed_to_install = "Failed to install {dep}: {error}" +installing_dep = "Installing {dep}" +dry_run_update_cmd = "[DRY RUN] Would run: {cmd}" +dry_run_install_cmd = "[DRY RUN] Would run: {cmd}" diff --git a/cli/app/commands/install/tests/__init__.py b/cli/app/commands/install/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index 4285e111..cf913a62 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -55,3 +55,4 @@ def replacer(match): CONFIG_ENDPOINT = "services.caddy.env.CONFIG_ENDPOINT" LOAD_ENDPOINT = "services.caddy.env.LOAD_ENDPOINT" STOP_ENDPOINT = "services.caddy.env.STOP_ENDPOINT" +DEPS = "deps" \ No newline at end of file diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index 1dadd2b9..d70c5010 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -104,4 +104,4 @@ compose-file-path: docker-compose.yml clone: repo: "https://github.com/raghavyuva/nixopus" branch: "master" - source-path: source \ No newline at end of file + source-path: source From d9504dcda1142f5fa725aa0f217d37c1f7715512 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 17 Jul 2025 20:43:51 +0530 Subject: [PATCH 46/72] fix: remove redis from the list of required dependencies list --- cli/app/commands/install/command.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index 96b35520..8258cfc9 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -64,6 +64,7 @@ def ssh( logger.error(e) raise typer.Exit(1) +@install_app.command(name="deps") def deps( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), From d9a115a2b207b969585edfee0fe9d15a2064cdec Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 17 Jul 2025 20:44:00 +0530 Subject: [PATCH 47/72] fix: remove redis from the list of required dependencies list --- helpers/config.prod.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index d70c5010..7f5329cb 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -91,7 +91,6 @@ deps: air: { version: "" } python: { version: "" } poetry: { version: "" } - redis: { version: "" } docker: { version: "" } open-ssh: { version: "" } open-sshserver: { version: "" } From dddb0a51c024258aa65d29da843135791741ff4f Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 17 Jul 2025 21:14:33 +0530 Subject: [PATCH 48/72] feat: add function to get the ip address of the server --- cli/app/utils/lib.py | 12 +++++++++++- cli/app/utils/message.py | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py index ee1602fb..3fc065f6 100644 --- a/cli/app/utils/lib.py +++ b/cli/app/utils/lib.py @@ -6,8 +6,9 @@ from concurrent.futures import ThreadPoolExecutor, as_completed from enum import Enum from typing import Callable, List, Optional, Tuple, TypeVar +import requests -from app.utils.message import FAILED_TO_REMOVE_DIRECTORY_MESSAGE, REMOVED_DIRECTORY_MESSAGE +from app.utils.message import FAILED_TO_GET_PUBLIC_IP_MESSAGE, FAILED_TO_REMOVE_DIRECTORY_MESSAGE, REMOVED_DIRECTORY_MESSAGE T = TypeVar("T") R = TypeVar("R") @@ -84,6 +85,15 @@ def command_exists(command): return result.returncode == 0 except Exception: return False + + @staticmethod + def get_public_ip(): + try: + response = requests.get('https://api.ipify.org', timeout=10) + response.raise_for_status() # fail on non-2xx + return response.text.strip() + except requests.RequestException: + raise Exception(FAILED_TO_GET_PUBLIC_IP_MESSAGE) class ParallelProcessor: diff --git a/cli/app/utils/message.py b/cli/app/utils/message.py index b2167bed..5963926a 100644 --- a/cli/app/utils/message.py +++ b/cli/app/utils/message.py @@ -14,4 +14,5 @@ HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" REMOVED_DIRECTORY_MESSAGE = "Removed existing directory: {path}" FAILED_TO_REMOVE_DIRECTORY_MESSAGE = "Failed to remove directory: {path}" -MISSING_CONFIG_KEY_MESSAGE = "Missing config key: {path} (failed at '{key}')" \ No newline at end of file +MISSING_CONFIG_KEY_MESSAGE = "Missing config key: {path} (failed at '{key}')" +FAILED_TO_GET_PUBLIC_IP_MESSAGE = "Failed to get public IP" \ No newline at end of file From 54a6adb35eee363999f89e768e3c6f191144e5d8 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Sun, 20 Jul 2025 11:54:00 +0530 Subject: [PATCH 49/72] feat : nixopus cli intro command (#293) --- cli/app/main.py | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/cli/app/main.py b/cli/app/main.py index 5d34b8f9..2c829689 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -1,4 +1,8 @@ import typer +from importlib.metadata import version as get_version +from rich.console import Console +from rich.panel import Panel +from rich.text import Text from app.commands.clone.command import clone_app from app.commands.conf.command import conf_app @@ -8,6 +12,7 @@ from app.commands.service.command import service_app from app.commands.test.command import test_app from app.commands.version.command import main_version_callback, version_app +from app.commands.version.version import VersionCommand from app.utils.message import application_add_completion, application_description, application_name, application_version_help app = typer.Typer( @@ -17,7 +22,7 @@ ) -@app.callback() +@app.callback(invoke_without_command=True) def main( version: bool = typer.Option( None, @@ -27,8 +32,42 @@ def main( help=application_version_help, ) ): - pass - + console = Console() + + ascii_art = """ + _ _ _ _ + | \\ | (_) + | \\| |___ _____ _ __ _ _ ___ + | . ` | \\ \\/ / _ \\| '_ \\| | | / __| + | |\\ | |> < (_) | |_) | |_| \\__ \\ + |_| \\_|_/_/\\_\\___/| .__/ \\__,_|___/ + | | + |_| + """ + + text = Text(ascii_art, style="bold cyan") + panel = Panel(text, title="[bold white]Welcome to[/bold white]", border_style="cyan", padding=(1, 2)) + + console.print(panel) + + cli_version = get_version("nixopus") + version_text = Text() + version_text.append("Version: ", style="bold white") + version_text.append(f"v{cli_version}", style="green") + + description_text = Text() + description_text.append(application_description, style="dim") + + console.print(version_text) + console.print(description_text) + console.print() + + help_text = Text() + help_text.append("Run ", style="dim") + help_text.append("nixopus --help", style="bold green") + help_text.append(" to explore all available commands", style="dim") + console.print(help_text) + console.print() app.add_typer(preflight_app, name="preflight") app.add_typer(clone_app, name="clone") From bd55c54ab9696237dd0d074636ff697c785fc680 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Sun, 20 Jul 2025 18:52:18 +0530 Subject: [PATCH 50/72] feat: (#294) centralized timeout operation wrapper for commands --- cli/app/commands/clone/command.py | 12 ++++++++-- cli/app/commands/conf/command.py | 25 +++++++++++++++++--- cli/app/commands/install/command.py | 19 +++++++++++++-- cli/app/commands/install/messages.py | 1 + cli/app/commands/preflight/command.py | 25 +++++++++++++++----- cli/app/commands/preflight/deps.py | 10 +++----- cli/app/commands/preflight/port.py | 8 +++---- cli/app/commands/proxy/command.py | 25 +++++++++++++++++--- cli/app/commands/service/command.py | 33 +++++++++++++++++++++++---- cli/app/utils/timeout.py | 24 +++++++++++++++++++ 10 files changed, 150 insertions(+), 32 deletions(-) create mode 100644 cli/app/utils/timeout.py diff --git a/cli/app/commands/clone/command.py b/cli/app/commands/clone/command.py index 18a95b7d..571563e5 100644 --- a/cli/app/commands/clone/command.py +++ b/cli/app/commands/clone/command.py @@ -2,6 +2,7 @@ from app.utils.logger import Logger from app.utils.config import Config, DEFAULT_REPO, DEFAULT_BRANCH, DEFAULT_PATH, NIXOPUS_CONFIG_DIR +from app.utils.timeout import TimeoutWrapper from .clone import Clone, CloneConfig @@ -22,14 +23,21 @@ def clone_callback( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Clone a repository""" try: logger = Logger(verbose=verbose) config = CloneConfig(repo=repo, branch=branch, path=path, force=force, verbose=verbose, output=output, dry_run=dry_run) clone_operation = Clone(logger=logger) - result = clone_operation.clone(config) - logger.success(result.output) + + with TimeoutWrapper(timeout): + result = clone_operation.clone(config) + logger.success(result.output) + + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(e) raise typer.Exit(1) diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py index f805cd20..f8ca845d 100644 --- a/cli/app/commands/conf/command.py +++ b/cli/app/commands/conf/command.py @@ -1,6 +1,7 @@ import typer from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper from .delete import Delete, DeleteConfig from .list import List, ListConfig @@ -19,6 +20,7 @@ def list( output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """List all configuration""" logger = Logger(verbose=verbose) @@ -27,7 +29,9 @@ def list( config = ListConfig(service=service, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file) list_action = List(logger=logger) - result = list_action.list(config) + + with TimeoutWrapper(timeout): + result = list_action.list(config) if result.success: logger.success(list_action.format_output(result, output)) @@ -35,6 +39,9 @@ def list( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -50,6 +57,7 @@ def delete( output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Delete a configuration""" logger = Logger(verbose=verbose) @@ -58,7 +66,9 @@ def delete( config = DeleteConfig(service=service, key=key, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file) delete_action = Delete(logger=logger) - result = delete_action.delete(config) + + with TimeoutWrapper(timeout): + result = delete_action.delete(config) if result.success: logger.success(delete_action.format_output(result, output)) @@ -66,6 +76,9 @@ def delete( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -81,6 +94,7 @@ def set( output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Set a configuration""" logger = Logger(verbose=verbose) @@ -96,7 +110,9 @@ def set( ) set_action = Set(logger=logger) - result = set_action.set(config) + + with TimeoutWrapper(timeout): + result = set_action.set(config) if result.success: logger.success(set_action.format_output(result, output)) @@ -104,6 +120,9 @@ def set( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index 8258cfc9..64b3c9f1 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -2,6 +2,7 @@ from app.utils.config import Config from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper from .deps import install_all_deps from .run import Install @@ -40,6 +41,7 @@ def ssh( create_ssh_directory: bool = typer.Option( True, "--create-ssh-directory", "-c", help="Create .ssh directory if it doesn't exist" ), + timeout: int = typer.Option(10, "--timeout", "-T", help="Timeout in seconds"), ): """Generate an SSH key pair with proper permissions and optional authorized_keys integration""" try: @@ -58,8 +60,14 @@ def ssh( create_ssh_directory=create_ssh_directory, ) ssh_operation = SSH(logger=logger) - result = ssh_operation.generate(config) + + with TimeoutWrapper(timeout): + result = ssh_operation.generate(config) + logger.success(result.output) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(e) raise typer.Exit(1) @@ -69,15 +77,22 @@ def deps( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Install dependencies""" try: logger = Logger(verbose=verbose) - result = install_all_deps(verbose=verbose, output=output, dry_run=dry_run) + + with TimeoutWrapper(timeout): + result = install_all_deps(verbose=verbose, output=output, dry_run=dry_run) + if output == "json": print(result) else: logger.success("All dependencies installed successfully.") + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(e) raise typer.Exit(1) diff --git a/cli/app/commands/install/messages.py b/cli/app/commands/install/messages.py index a82a9b38..70452a5e 100644 --- a/cli/app/commands/install/messages.py +++ b/cli/app/commands/install/messages.py @@ -64,3 +64,4 @@ installing_dep = "Installing {dep}" dry_run_update_cmd = "[DRY RUN] Would run: {cmd}" dry_run_install_cmd = "[DRY RUN] Would run: {cmd}" +timeout_error = "Operation timed out after {timeout} seconds" \ No newline at end of file diff --git a/cli/app/commands/preflight/command.py b/cli/app/commands/preflight/command.py index 2d4db61f..f4e81d1a 100644 --- a/cli/app/commands/preflight/command.py +++ b/cli/app/commands/preflight/command.py @@ -2,6 +2,7 @@ from app.utils.lib import HostInformation from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper from .deps import Deps, DepsConfig from .messages import error_checking_deps, error_checking_ports @@ -21,6 +22,7 @@ def preflight_callback(ctx: typer.Context): def check( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text,json"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Run all preflight checks""" pass @@ -30,18 +32,24 @@ def check( def ports( ports: list[int] = typer.Argument(..., help="The list of ports to check"), host: str = typer.Option("localhost", "--host", "-h", help="The host to check"), - timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each port check"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ) -> None: """Check if list of ports are available on a host""" try: logger = Logger(verbose=verbose) logger.debug(f"Checking ports: {ports}") - config = PortConfig(ports=ports, host=host, timeout=timeout, verbose=verbose) + config = PortConfig(ports=ports, host=host, verbose=verbose) port_service = PortService(config, logger=logger) - results = port_service.check_ports() + + with TimeoutWrapper(timeout): + results = port_service.check_ports() + logger.success(port_service.formatter.format_output(results, output)) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(error_checking_ports.format(error=e)) raise typer.Exit(1) @@ -50,24 +58,29 @@ def ports( @preflight_app.command() def deps( deps: list[str] = typer.Argument(..., help="The list of dependencies to check"), - timeout: int = typer.Option(1, "--timeout", "-t", help="The timeout in seconds for each dependency check"), verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format, text, json"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ) -> None: """Check if list of dependencies are available on the system""" try: logger = Logger(verbose=verbose) config = DepsConfig( deps=deps, - timeout=timeout, verbose=verbose, output=output, os=HostInformation.get_os_name(), package_manager=HostInformation.get_package_manager(), ) deps_checker = Deps(logger=logger) - results = deps_checker.check(config) + + with TimeoutWrapper(timeout): + results = deps_checker.check(config) + logger.success(deps_checker.format_output(results, output)) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(error_checking_deps.format(error=e)) raise typer.Exit(1) diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py index b7fbdb90..0649db68 100644 --- a/cli/app/commands/preflight/deps.py +++ b/cli/app/commands/preflight/deps.py @@ -16,15 +16,14 @@ def check_dependency(self, dep: str) -> bool: ... class DependencyChecker: - def __init__(self, timeout: int, logger: LoggerProtocol): - self.timeout = timeout + def __init__(self, logger: LoggerProtocol): self.logger = logger def check_dependency(self, dep: str) -> bool: self.logger.debug(f"Checking dependency: {dep}") try: - result = subprocess.run(["command", "-v", dep], capture_output=True, text=True, timeout=self.timeout) + result = subprocess.run(["command", "-v", dep], capture_output=True, text=True, timeout=1) return result.returncode == 0 except subprocess.TimeoutExpired: @@ -71,7 +70,6 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: class DepsCheckResult(BaseModel): dependency: str - timeout: int verbose: bool output: str os: str @@ -82,7 +80,6 @@ class DepsCheckResult(BaseModel): class DepsConfig(BaseModel): deps: list[str] = Field(..., min_length=1, description="The list of dependencies to check") - timeout: int = Field(1, gt=0, le=60, description="The timeout in seconds") verbose: bool = Field(False, description="Verbose output") output: str = Field("text", description="Output format, text, json") os: str = Field(..., description=f"The operating system to check, available: {Supported.get_os()}") @@ -105,13 +102,12 @@ class DepsService: def __init__(self, config: DepsConfig, logger: LoggerProtocol = None, checker: DependencyCheckerProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) - self.checker = checker or DependencyChecker(config.timeout, self.logger) + self.checker = checker or DependencyChecker(self.logger) self.formatter = DependencyFormatter() def _create_result(self, dep: str, is_available: bool, error: str = None) -> DepsCheckResult: return DepsCheckResult( dependency=dep, - timeout=self.config.timeout, verbose=self.config.verbose, output=self.config.output, os=self.config.os, diff --git a/cli/app/commands/preflight/port.py b/cli/app/commands/preflight/port.py index cdecd57e..4bb9e6b2 100644 --- a/cli/app/commands/preflight/port.py +++ b/cli/app/commands/preflight/port.py @@ -27,7 +27,6 @@ class PortCheckResult(TypedDict): class PortConfig(BaseModel): ports: List[int] = Field(..., min_length=1, max_length=65535, description="List of ports to check") host: str = Field("localhost", min_length=1, description="Host to check") - timeout: int = Field(1, gt=0, le=60, description="Timeout in seconds") verbose: bool = Field(False, description="Verbose output") @field_validator("host") @@ -64,14 +63,13 @@ def format_output(self, data: Union[str, List[PortCheckResult], Any], output_typ class PortChecker: - def __init__(self, logger: LoggerProtocol, timeout: int): + def __init__(self, logger: LoggerProtocol): self.logger = logger - self.timeout = timeout def is_port_available(self, host: str, port: int) -> bool: try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: - sock.settimeout(self.timeout) + sock.settimeout(1) result = sock.connect_ex((host, port)) return result != 0 except Exception: @@ -100,7 +98,7 @@ class PortService: def __init__(self, config: PortConfig, logger: LoggerProtocol = None, checker: PortCheckerProtocol = None): self.config = config self.logger = logger or Logger(verbose=config.verbose) - self.checker = checker or PortChecker(self.logger, config.timeout) + self.checker = checker or PortChecker(self.logger) self.formatter = PortFormatter() def check_ports(self) -> List[PortCheckResult]: diff --git a/cli/app/commands/proxy/command.py b/cli/app/commands/proxy/command.py index 09831bff..b983b082 100644 --- a/cli/app/commands/proxy/command.py +++ b/cli/app/commands/proxy/command.py @@ -2,6 +2,7 @@ from app.utils.config import Config, PROXY_PORT from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper from .load import Load, LoadConfig from .status import Status, StatusConfig @@ -22,6 +23,7 @@ def load( output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), config_file: str = typer.Option(None, "--config-file", "-c", help="Path to Caddy config file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Load Caddy proxy configuration""" logger = Logger(verbose=verbose) @@ -30,7 +32,9 @@ def load( config = LoadConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run, config_file=config_file) load_service = Load(logger=logger) - result = load_service.load(config) + + with TimeoutWrapper(timeout): + result = load_service.load(config) if result.success: logger.success(load_service.format_output(result, output)) @@ -38,6 +42,9 @@ def load( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -49,6 +56,7 @@ def status( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Check Caddy proxy status""" logger = Logger(verbose=verbose) @@ -57,7 +65,9 @@ def status( config = StatusConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run) status_service = Status(logger=logger) - result = status_service.status(config) + + with TimeoutWrapper(timeout): + result = status_service.status(config) if result.success: logger.success(status_service.format_output(result, output)) @@ -65,6 +75,9 @@ def status( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -76,6 +89,7 @@ def stop( verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), output: str = typer.Option("text", "--output", "-o", help="Output format: text, json"), dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Stop Caddy proxy""" logger = Logger(verbose=verbose) @@ -84,7 +98,9 @@ def stop( config = StopConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run) stop_service = Stop(logger=logger) - result = stop_service.stop(config) + + with TimeoutWrapper(timeout): + result = stop_service.stop(config) if result.success: logger.success(stop_service.format_output(result, output)) @@ -92,6 +108,9 @@ def stop( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/service/command.py b/cli/app/commands/service/command.py index 55318f97..9b3aeac8 100644 --- a/cli/app/commands/service/command.py +++ b/cli/app/commands/service/command.py @@ -2,6 +2,7 @@ from app.utils.config import Config, DEFAULT_COMPOSE_FILE, NIXOPUS_CONFIG_DIR from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper from .down import Down, DownConfig from .ps import Ps, PsConfig @@ -24,6 +25,7 @@ def up( detach: bool = typer.Option(False, "--detach", "-d", help="Detach from the service and run in the background"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Start Nixopus services""" logger = Logger(verbose=verbose) @@ -40,7 +42,9 @@ def up( ) up_service = Up(logger=logger) - result = up_service.up(config) + + with TimeoutWrapper(timeout): + result = up_service.up(config) if result.success: logger.success(up_service.format_output(result, output)) @@ -48,6 +52,9 @@ def up( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -61,6 +68,7 @@ def down( dry_run: bool = typer.Option(False, "--dry-run", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Stop Nixopus services""" logger = Logger(verbose=verbose) @@ -71,7 +79,9 @@ def down( ) down_service = Down(logger=logger) - result = down_service.down(config) + + with TimeoutWrapper(timeout): + result = down_service.down(config) if result.success: logger.success(down_service.format_output(result, output)) @@ -79,6 +89,9 @@ def down( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -92,6 +105,7 @@ def ps( dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Show status of Nixopus services""" logger = Logger(verbose=verbose) @@ -102,7 +116,9 @@ def ps( ) ps_service = Ps(logger=logger) - result = ps_service.ps(config) + + with TimeoutWrapper(timeout): + result = ps_service.ps(config) if result.success: logger.success(ps_service.format_output(result, output)) @@ -110,6 +126,9 @@ def ps( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) @@ -123,6 +142,7 @@ def restart( dry_run: bool = typer.Option(False, "--dry-run", "-d", help="Dry run"), env_file: str = typer.Option(None, "--env-file", "-e", help="Path to the environment file"), compose_file: str = typer.Option(compose_file_path, "--compose-file", "-f", help="Path to the compose file"), + timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Restart Nixopus services""" logger = Logger(verbose=verbose) @@ -133,7 +153,9 @@ def restart( ) restart_service = Restart(logger=logger) - result = restart_service.restart(config) + + with TimeoutWrapper(timeout): + result = restart_service.restart(config) if result.success: logger.success(restart_service.format_output(result, output)) @@ -141,6 +163,9 @@ def restart( logger.error(result.error) raise typer.Exit(1) + except TimeoutError as e: + logger.error(e) + raise typer.Exit(1) except Exception as e: logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/utils/timeout.py b/cli/app/utils/timeout.py new file mode 100644 index 00000000..e03f0c09 --- /dev/null +++ b/cli/app/utils/timeout.py @@ -0,0 +1,24 @@ +import signal +from app.commands.install.messages import timeout_error + + +class TimeoutWrapper: + """Context manager for timeout operations""" + + def __init__(self, timeout: int): + self.timeout = timeout + self.original_handler = None + + def __enter__(self): + if self.timeout > 0: + def timeout_handler(signum, frame): + raise TimeoutError(timeout_error.format(timeout=self.timeout)) + + self.original_handler = signal.signal(signal.SIGALRM, timeout_handler) + signal.alarm(self.timeout) + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + if self.timeout > 0: + signal.alarm(0) + signal.signal(signal.SIGALRM, self.original_handler) From 9fd4d6e33b68f6775ec56a36c005389ababe4b62 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Mon, 21 Jul 2025 21:03:37 +0530 Subject: [PATCH 51/72] feat : verbose mode for commands (#295) * fix: add debug logs to be shown in verbose mode for tracing the behaviour of the command * feat : conf commands verbose mode (#296) * feat: add verbose logging for conf commands * feat: add verbose logging for preflight commands (#297) --- cli/app/commands/clone/clone.py | 51 ++++-- cli/app/commands/clone/command.py | 49 +++++- cli/app/commands/clone/messages.py | 44 +++++ cli/app/commands/clone/tests/test_clone.py | 85 ++++++++-- cli/app/commands/conf/base.py | 70 -------- cli/app/commands/conf/command.py | 178 +++++++++++++++++---- cli/app/commands/conf/delete.py | 51 +++++- cli/app/commands/conf/list.py | 50 +++++- cli/app/commands/conf/messages.py | 81 +++++----- cli/app/commands/conf/set.py | 50 +++++- cli/app/commands/install/messages.py | 29 +--- cli/app/commands/preflight/command.py | 78 ++++++++- cli/app/commands/preflight/deps.py | 33 ++-- cli/app/commands/preflight/messages.py | 26 +++ cli/app/commands/preflight/port.py | 32 +++- cli/app/utils/lib.py | 7 + 16 files changed, 681 insertions(+), 233 deletions(-) create mode 100644 cli/app/commands/clone/messages.py diff --git a/cli/app/commands/clone/clone.py b/cli/app/commands/clone/clone.py index 355a094e..f39d2c94 100644 --- a/cli/app/commands/clone/clone.py +++ b/cli/app/commands/clone/clone.py @@ -9,8 +9,16 @@ from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol -from ..install.messages import ( - cloning_repo_into_path, +from .messages import ( + debug_cloning_repo, + debug_executing_git_clone, + debug_git_clone_success, + debug_git_clone_failed, + debug_unexpected_error, + debug_removing_directory, + debug_directory_removal_failed, + debug_path_exists_force_disabled, + debug_clone_completed, default_branch, dry_run_branch, dry_run_command, @@ -20,9 +28,7 @@ dry_run_repository, dry_run_target_path, end_dry_run, - executing_command, failed_to_prepare_target_directory, - git_clone_failed, invalid_path, invalid_repo, invalid_repository_url, @@ -32,7 +38,6 @@ prerequisites_validation_failed, successfully_cloned, target_path_not_exists, - unexpected_error_during_clone, unknown_error, ) @@ -98,17 +103,18 @@ def __init__(self, logger: LoggerProtocol): def clone_repository(self, repo: str, path: str, branch: str = None) -> tuple[bool, str]: cmd = GitCommandBuilder.build_clone_command(repo, path, branch) + + self.logger.debug(debug_executing_git_clone.format(command=' '.join(cmd))) try: - self.logger.info(executing_command.format(command=" ".join(cmd))) result = subprocess.run(cmd, capture_output=True, text=True, check=True) - self.logger.success(successfully_cloned.format(repo=repo, path=path)) + self.logger.debug(debug_git_clone_success) return True, None except subprocess.CalledProcessError as e: - self.logger.error(git_clone_failed.format(error=e.stderr)) + self.logger.debug(debug_git_clone_failed.format(code=e.returncode, error=e.stderr)) return False, e.stderr except Exception as e: - self.logger.error(unexpected_error_during_clone.format(error=e)) + self.logger.debug(debug_unexpected_error.format(error_type=type(e).__name__, error=str(e))) return False, str(e) @@ -118,7 +124,7 @@ class CloneResult(BaseModel): branch: Optional[str] force: bool verbose: bool - output: str + output: str = "" success: bool = False error: Optional[str] = None @@ -180,17 +186,22 @@ def __init__(self, config: CloneConfig, logger: LoggerProtocol = None, cloner: G def _prepare_target_directory(self) -> bool: if self.config.force and os.path.exists(self.config.path): - return self.dir_manager.remove_directory(self.config.path, self.logger) + self.logger.debug(debug_removing_directory.format(path=self.config.path)) + success = self.dir_manager.remove_directory(self.config.path, self.logger) + if not success: + self.logger.debug(debug_directory_removal_failed) + return success return True def _validate_prerequisites(self) -> bool: if self.dir_manager.path_exists_and_not_force(self.config.path, self.config.force): + self.logger.debug(debug_path_exists_force_disabled.format(path=self.config.path)) self.logger.error(path_already_exists_use_force.format(path=self.config.path)) return False return True def _create_result(self, success: bool, error: str = None) -> CloneResult: - return CloneResult( + result = CloneResult( repo=self.config.repo, path=self.config.path, branch=self.config.branch, @@ -200,9 +211,14 @@ def _create_result(self, success: bool, error: str = None) -> CloneResult: success=success, error=error, ) + result.output = self.formatter.format_output(result, self.config.output) + return result def clone(self) -> CloneResult: - self.logger.debug(cloning_repo_into_path.format(repo=self.config.repo, path=self.config.path)) + import time + start_time = time.time() + + self.logger.debug(debug_cloning_repo.format(repo=self.config.repo, path=self.config.path, force=self.config.force)) if not self._validate_prerequisites(): return self._create_result(False, prerequisites_validation_failed) @@ -211,6 +227,9 @@ def clone(self) -> CloneResult: return self._create_result(False, failed_to_prepare_target_directory) success, error = self.cloner.clone_repository(self.config.repo, self.config.path, self.config.branch) + + duration = time.time() - start_time + self.logger.debug(debug_clone_completed.format(duration=f"{duration:.2f}", success=success)) return self._create_result(success, error) @@ -219,7 +238,7 @@ def clone_and_format(self) -> str: return self.formatter.format_dry_run(self.config) result = self.clone() - return self.formatter.format_output(result, self.config.output) + return result.output class Clone: @@ -231,5 +250,9 @@ def clone(self, config: CloneConfig) -> CloneResult: service = CloneService(config, logger=self.logger) return service.clone() + def clone_and_format(self, config: CloneConfig) -> str: + service = CloneService(config, logger=self.logger) + return service.clone_and_format() + def format_output(self, result: CloneResult, output: str) -> str: return self.formatter.format_output(result, output) diff --git a/cli/app/commands/clone/command.py b/cli/app/commands/clone/command.py index 571563e5..28aef65a 100644 --- a/cli/app/commands/clone/command.py +++ b/cli/app/commands/clone/command.py @@ -5,6 +5,23 @@ from app.utils.timeout import TimeoutWrapper from .clone import Clone, CloneConfig +from .messages import ( + debug_clone_command_invoked, + debug_repo_param, + debug_branch_param, + debug_path_param, + debug_force_param, + debug_verbose_param, + debug_output_param, + debug_dry_run_param, + debug_executing_dry_run, + debug_dry_run_completed, + debug_clone_operation_result, + debug_clone_operation_failed, + debug_clone_operation_completed, + debug_exception_caught, + debug_exception_details, +) config = Config() nixopus_config_dir = config.get_yaml_value(NIXOPUS_CONFIG_DIR) @@ -28,16 +45,42 @@ def clone_callback( """Clone a repository""" try: logger = Logger(verbose=verbose) + logger.debug(debug_clone_command_invoked) + logger.debug(debug_repo_param.format(repo=repo)) + logger.debug(debug_branch_param.format(branch=branch)) + logger.debug(debug_path_param.format(path=path)) + logger.debug(debug_force_param.format(force=force)) + logger.debug(debug_verbose_param.format(verbose=verbose)) + logger.debug(debug_output_param.format(output=output)) + logger.debug(debug_dry_run_param.format(dry_run=dry_run)) + config = CloneConfig(repo=repo, branch=branch, path=path, force=force, verbose=verbose, output=output, dry_run=dry_run) + clone_operation = Clone(logger=logger) with TimeoutWrapper(timeout): - result = clone_operation.clone(config) - logger.success(result.output) + if config.dry_run: + logger.debug(debug_executing_dry_run) + formatted_output = clone_operation.clone_and_format(config) + logger.info(formatted_output) + logger.debug(debug_dry_run_completed) + else: + result = clone_operation.clone(config) + logger.debug(debug_clone_operation_result.format(success=result.success)) + + if not result.success: + logger.error(result.output) + logger.debug(debug_clone_operation_failed) + raise typer.Exit(1) + + logger.debug(debug_clone_operation_completed) + logger.info(result.output) except TimeoutError as e: logger.error(e) raise typer.Exit(1) except Exception as e: - logger.error(e) + logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) + logger.debug(debug_exception_details.format(error=e)) + logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/clone/messages.py b/cli/app/commands/clone/messages.py new file mode 100644 index 00000000..eb420999 --- /dev/null +++ b/cli/app/commands/clone/messages.py @@ -0,0 +1,44 @@ +debug_cloning_repo = "Cloning {repo} to {path} (force: {force})" +debug_executing_git_clone = "Executing git clone: {command}" +debug_git_clone_success = "Git clone completed successfully" +debug_git_clone_failed = "Git clone failed (code: {code}): {error}" +debug_unexpected_error = "Unexpected error: {error_type}: {error}" +debug_removing_directory = "Removing existing directory: {path}" +debug_directory_removal_failed = "Failed to remove existing directory" +debug_path_exists_force_disabled = "Path exists and force disabled: {path}" +debug_clone_completed = "Clone completed in {duration}s - success: {success}" +debug_clone_command_invoked = "Clone command invoked with parameters:" +debug_repo_param = " repo: {repo}" +debug_branch_param = " branch: {branch}" +debug_path_param = " path: {path}" +debug_force_param = " force: {force}" +debug_verbose_param = " verbose: {verbose}" +debug_output_param = " output: {output}" +debug_dry_run_param = " dry_run: {dry_run}" +debug_executing_dry_run = "Executing dry run mode" +debug_dry_run_completed = "Dry run completed successfully" +debug_clone_operation_result = "Clone operation result - success: {success}" +debug_clone_operation_failed = "Clone operation failed, raising exit" +debug_clone_operation_completed = "Clone operation completed successfully" +debug_exception_caught = "Exception caught in clone callback: {error_type}: {error}" +debug_exception_details = "Exception details: {error}" +path_already_exists_use_force = "Path {path} already exists. Use --force to overwrite." +prerequisites_validation_failed = "Prerequisites validation failed" +failed_to_prepare_target_directory = "Failed to prepare target directory" +invalid_repo = "Invalid repository format" +invalid_repository_url = "Invalid repository URL format" +invalid_path = "Invalid path format" +unknown_error = "Unknown error" +successfully_cloned = "Successfully cloned {repo} to {path}" +dry_run_mode = "=== DRY RUN MODE ===" +dry_run_command_would_be_executed = "The following command would be executed:" +dry_run_command = "Command: {command}" +dry_run_repository = "Repository: {repo}" +dry_run_branch = "Branch: {branch}" +dry_run_target_path = "Target path: {path}" +dry_run_force_mode = "Force mode: {force}" +path_exists_will_overwrite = "Path {path} exists and will be overwritten (force mode)" +path_exists_would_fail = "Path {path} exists - clone would fail without --force" +target_path_not_exists = "Target path {path} does not exist" +end_dry_run = "=== END DRY RUN ===" +default_branch = "default" \ No newline at end of file diff --git a/cli/app/commands/clone/tests/test_clone.py b/cli/app/commands/clone/tests/test_clone.py index f2f847a1..dd44ba86 100644 --- a/cli/app/commands/clone/tests/test_clone.py +++ b/cli/app/commands/clone/tests/test_clone.py @@ -1,5 +1,5 @@ import subprocess -from unittest.mock import MagicMock, Mock, patch +from unittest.mock import Mock, patch import pytest from pydantic import ValidationError @@ -13,6 +13,14 @@ GitClone, GitCommandBuilder, ) +from ..messages import ( + successfully_cloned, + dry_run_mode, + dry_run_command, + dry_run_force_mode, + path_exists_will_overwrite, + path_exists_would_fail, +) from app.utils.lib import DirectoryManager from app.utils.logger import Logger @@ -46,9 +54,7 @@ def test_format_output_success(self): success=True, ) formatted = self.formatter.format_output(result, "text") - assert "Successfully cloned" in formatted - assert "https://github.com/user/repo" in formatted - assert "/path/to/clone" in formatted + assert successfully_cloned.format(repo="https://github.com/user/repo", path="/path/to/clone") in formatted def test_format_output_failure(self): result = CloneResult( @@ -79,7 +85,7 @@ def test_format_output_json(self): data = json.loads(formatted) assert data["success"] is True - assert data["message"] == "Successfully cloned https://github.com/user/repo to /path/to/clone" + assert data["message"] == successfully_cloned.format(repo="https://github.com/user/repo", path="/path/to/clone") def test_format_output_invalid(self): result = CloneResult( @@ -101,9 +107,9 @@ def test_format_dry_run(self, mock_exists): repo="https://github.com/user/repo", path="/path/to/clone", branch="main", force=True, dry_run=True ) formatted = self.formatter.format_dry_run(config) - assert "=== DRY RUN MODE ===" in formatted - assert "git clone -b main https://github.com/user/repo /path/to/clone" in formatted - assert "Force mode: True" in formatted + assert dry_run_mode in formatted + assert dry_run_command.format(command="git clone -b main https://github.com/user/repo /path/to/clone") in formatted + assert dry_run_force_mode.format(force=True) in formatted @patch("os.path.exists") def test_format_dry_run_path_exists_force(self, mock_exists): @@ -112,7 +118,7 @@ def test_format_dry_run_path_exists_force(self, mock_exists): repo="https://github.com/user/repo", path="/path/to/clone", branch="main", force=True, dry_run=True ) formatted = self.formatter.format_dry_run(config) - assert "will be overwritten" in formatted + assert path_exists_will_overwrite.format(path="/path/to/clone") in formatted @patch("os.path.exists") def test_format_dry_run_path_exists_no_force(self, mock_exists): @@ -121,7 +127,7 @@ def test_format_dry_run_path_exists_no_force(self, mock_exists): repo="https://github.com/user/repo", path="/path/to/clone", branch="main", force=False, dry_run=True ) formatted = self.formatter.format_dry_run(config) - assert "would fail without --force" in formatted + assert path_exists_would_fail.format(path="/path/to/clone") in formatted class TestGitClone: @@ -138,7 +144,6 @@ def test_clone_repository_success(self, mock_run): assert success is True assert error is None self.logger.info.assert_called_once() - self.logger.success.assert_called_once() @patch("subprocess.run") def test_clone_repository_without_branch(self, mock_run): @@ -160,7 +165,6 @@ def test_clone_repository_failure(self, mock_run): assert success is False assert error == "Repository not found" - self.logger.error.assert_called_once() @patch("subprocess.run") def test_clone_repository_unexpected_error(self, mock_run): @@ -170,7 +174,6 @@ def test_clone_repository_unexpected_error(self, mock_run): assert success is False assert error == "Unexpected error" - self.logger.error.assert_called_once() class TestCloneConfig: @@ -362,14 +365,14 @@ def test_clone_and_format_dry_run(self): result = self.service.clone_and_format() - assert "=== DRY RUN MODE ===" in result + assert dry_run_mode in result def test_clone_and_format_success(self): self.cloner.clone_repository.return_value = (True, None) result = self.service.clone_and_format() - assert "Successfully cloned" in result + assert successfully_cloned.format(repo=self.config.repo, path=self.config.path) in result class TestClone: @@ -409,4 +412,54 @@ def test_format_output(self): formatted = self.clone.format_output(result, "text") - assert "Successfully cloned" in formatted + assert successfully_cloned.format(repo="https://github.com/user/repo", path="/path/to/clone") in formatted + + def test_clone_and_format(self): + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=False, + output="text", + dry_run=True, + ) + + with patch.object(CloneService, "clone_and_format") as mock_clone_and_format: + mock_clone_and_format.return_value = dry_run_mode + + formatted = self.clone.clone_and_format(config) + + assert dry_run_mode in formatted + + def test_debug_logging_enabled(self): + """Test that debug logging is properly enabled when verbose=True""" + config = CloneConfig( + repo="https://github.com/user/repo", + path="/path/to/clone", + branch="main", + force=False, + verbose=True, + output="text", + dry_run=False, + ) + + logger = Mock(spec=Logger) + clone_operation = Clone(logger=logger) + + with patch.object(CloneService, "clone") as mock_clone: + mock_result = CloneResult( + repo=config.repo, + path=config.path, + branch=config.branch, + force=config.force, + verbose=config.verbose, + output=config.output, + success=True, + ) + mock_clone.return_value = mock_result + + result = clone_operation.clone(config) + + # Verify that debug logging was called + assert logger.debug.called diff --git a/cli/app/commands/conf/base.py b/cli/app/commands/conf/base.py index 22b0c5f7..50d62cf3 100644 --- a/cli/app/commands/conf/base.py +++ b/cli/app/commands/conf/base.py @@ -10,56 +10,23 @@ from app.utils.config import Config, API_ENV_FILE, VIEW_ENV_FILE from .messages import ( - atomic_complete, - atomic_failed, - atomic_write, - atomic_write_failed, backup_created, - backup_created_at, - backup_created_success, backup_creation_failed, - backup_exists, - backup_failed, backup_file_not_found, - backup_not_found, backup_remove_failed, backup_removed, backup_restore_attempt, backup_restore_failed, backup_restore_success, - backup_restored, - cleanup_failed, - cleanup_temp, - config_entries, - creating_backup, - directory_ensured, file_not_exists, file_not_found, file_read_failed, file_write_failed, - getting_service, invalid_line_warning, invalid_service, - no_backup_needed, - parsed_config, read_error, read_success, reading_env_file, - replacing_file, - restore_failed, - restoring_backup, - skipping_line, - sync_not_critical, - synced_temp, - temp_file_created, - unexpected_error, - using_default_api, - using_default_view, - using_provided_env, - write_complete, - writing_entries, - writing_env_file, - wrote_to_temp, ) TConfig = TypeVar("TConfig", bound=BaseModel) @@ -90,7 +57,6 @@ def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[ for line_num, line in enumerate(f, 1): line = line.strip() if not line or line.startswith("#"): - self.logger.debug(skipping_line.format(line_num=line_num)) continue if "=" not in line: @@ -99,7 +65,6 @@ def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[ key, value = line.split("=", 1) config[key.strip()] = value.strip() - self.logger.debug(parsed_config.format(key=key.strip(), value=value.strip())) self.logger.debug(read_success.format(count=len(config), file_path=file_path)) return True, config, None @@ -108,83 +73,58 @@ def read_env_file(self, file_path: str) -> tuple[bool, Dict[str, str], Optional[ return False, {}, file_read_failed.format(error=e) def _create_backup(self, file_path: str) -> tuple[bool, Optional[str], Optional[str]]: - self.logger.debug(creating_backup.format(file_path=file_path)) if not os.path.exists(file_path): - self.logger.debug(no_backup_needed.format(file_path=file_path)) return True, None, None try: backup_path = f"{file_path}.backup" - self.logger.debug(backup_created_at.format(backup_path=backup_path)) shutil.copy2(file_path, backup_path) - self.logger.debug(backup_created_success.format(backup_path=backup_path)) return True, backup_path, None except Exception as e: - self.logger.debug(backup_failed.format(error=e)) return False, None, backup_creation_failed.format(error=e) def _restore_backup(self, backup_path: str, file_path: str) -> tuple[bool, Optional[str]]: - self.logger.debug(restoring_backup.format(backup_path=backup_path, file_path=file_path)) try: if os.path.exists(backup_path): - self.logger.debug(backup_exists) shutil.copy2(backup_path, file_path) os.remove(backup_path) - self.logger.debug(backup_restored) return True, None - self.logger.debug(backup_not_found.format(backup_path=backup_path)) return False, backup_file_not_found.format(path=backup_path) except Exception as e: - self.logger.debug(restore_failed.format(error=e)) return False, backup_restore_failed.format(error=e) def _atomic_write(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: - self.logger.debug(atomic_write.format(file_path=file_path)) - self.logger.debug(writing_entries.format(count=len(config))) temp_path = None try: os.makedirs(os.path.dirname(file_path), exist_ok=True) - self.logger.debug(directory_ensured.format(directory=os.path.dirname(file_path))) with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=os.path.dirname(file_path)) as temp_file: - self.logger.debug(temp_file_created.format(temp_path=temp_file.name)) for key, value in sorted(config.items()): temp_file.write(f"{key}={value}\n") - self.logger.debug(wrote_to_temp.format(key=key, value=value)) temp_file.flush() try: os.fsync(temp_file.fileno()) - self.logger.debug(synced_temp) except (OSError, AttributeError): - self.logger.debug(sync_not_critical) pass temp_path = temp_file.name - self.logger.debug(replacing_file.format(file_path=file_path)) os.replace(temp_path, file_path) - self.logger.debug(atomic_complete) return True, None except Exception as e: - self.logger.debug(atomic_failed.format(error=e)) if temp_path and os.path.exists(temp_path): try: os.unlink(temp_path) - self.logger.debug(cleanup_temp.format(temp_path=temp_path)) except: - self.logger.debug(cleanup_failed.format(temp_path=temp_path)) pass return False, file_write_failed.format(error=e) def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, Optional[str]]: - self.logger.debug(writing_env_file.format(file_path=file_path)) - self.logger.debug(config_entries.format(count=len(config))) backup_created_flag = False backup_path = None try: success, backup_path, error = self._create_backup(file_path) if not success: - self.logger.debug(backup_creation_failed.format(error=error)) return False, error backup_created_flag = True @@ -192,7 +132,6 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, success, error = self._atomic_write(file_path, config) if not success: - self.logger.debug(atomic_write_failed) if backup_created_flag and backup_path: self.logger.warning(backup_restore_attempt) restore_success, restore_error = self._restore_backup(backup_path, file_path) @@ -206,35 +145,26 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, try: os.remove(backup_path) self.logger.info(backup_removed) - self.logger.debug(backup_removed.format(backup_path=backup_path)) except Exception as e: self.logger.warning(backup_remove_failed.format(error=e)) - self.logger.debug(backup_remove_failed.format(error=e)) - self.logger.debug(write_complete) return True, None except Exception as e: - self.logger.debug(unexpected_error.format(error=e)) return False, file_write_failed.format(error=e) def get_service_env_file(self, service: str, env_file: Optional[str] = None) -> str: - self.logger.debug(getting_service.format(service=service)) if env_file: - self.logger.debug(using_provided_env.format(env_file=env_file)) return env_file config = Config() if service == "api": default_path = config.get_yaml_value(API_ENV_FILE) - self.logger.debug(using_default_api.format(path=default_path)) return default_path elif service == "view": default_path = config.get_yaml_value(VIEW_ENV_FILE) - self.logger.debug(using_default_view.format(path=default_path)) return default_path else: - self.logger.debug(invalid_service.format(service=service)) raise ValueError(invalid_service.format(service=service)) diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py index f8ca845d..190f6c6c 100644 --- a/cli/app/commands/conf/command.py +++ b/cli/app/commands/conf/command.py @@ -5,7 +5,34 @@ from .delete import Delete, DeleteConfig from .list import List, ListConfig -from .messages import argument_must_be_in_form +from .messages import ( + argument_must_be_in_form, + debug_conf_command_invoked, + debug_service_param, + debug_key_param, + debug_value_param, + debug_verbose_param, + debug_output_param, + debug_dry_run_param, + debug_env_file_param, + debug_timeout_param, + debug_executing_dry_run, + debug_dry_run_completed, + debug_conf_operation_result, + debug_conf_operation_failed, + debug_conf_operation_completed, + debug_exception_caught, + debug_exception_details, + debug_parsing_key_value, + debug_key_value_parsed, + debug_key_value_parse_failed, + debug_config_created, + debug_action_created, + debug_timeout_wrapper_created, + debug_executing_with_timeout, + debug_timeout_completed, + debug_timeout_error, +) from .set import Set, SetConfig conf_app = typer.Typer(help="Manage configuration") @@ -23,26 +50,54 @@ def list( timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """List all configuration""" - logger = Logger(verbose=verbose) - try: + logger = Logger(verbose=verbose) + + logger.debug(debug_conf_command_invoked) + logger.debug(debug_service_param.format(service=service)) + logger.debug(debug_verbose_param.format(verbose=verbose)) + logger.debug(debug_output_param.format(output=output)) + logger.debug(debug_dry_run_param.format(dry_run=dry_run)) + logger.debug(debug_env_file_param.format(env_file=env_file)) + logger.debug(debug_timeout_param.format(timeout=timeout)) + config = ListConfig(service=service, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file) + logger.debug(debug_config_created.format(config_type="ListConfig")) list_action = List(logger=logger) + logger.debug(debug_action_created.format(action_type="List")) + + logger.debug(debug_timeout_wrapper_created.format(timeout=timeout)) + logger.debug(debug_executing_with_timeout.format(timeout=timeout)) with TimeoutWrapper(timeout): - result = list_action.list(config) - - if result.success: - logger.success(list_action.format_output(result, output)) - else: - logger.error(result.error) - raise typer.Exit(1) + if config.dry_run: + logger.debug(debug_executing_dry_run) + formatted_output = list_action.list_and_format(config) + logger.info(formatted_output) + logger.debug(debug_dry_run_completed) + else: + result = list_action.list(config) + logger.debug(debug_conf_operation_result.format(success=result.success)) + + if result.success: + formatted_output = list_action.format_output(result, output) + logger.success(formatted_output) + logger.debug(debug_conf_operation_completed) + else: + logger.error(result.error) + logger.debug(debug_conf_operation_failed) + raise typer.Exit(1) + + logger.debug(debug_timeout_completed) except TimeoutError as e: - logger.error(e) + logger.debug(debug_timeout_error.format(error=str(e))) + logger.error(str(e)) raise typer.Exit(1) except Exception as e: + logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) + logger.debug(debug_exception_details.format(error=e)) logger.error(str(e)) raise typer.Exit(1) @@ -60,26 +115,55 @@ def delete( timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Delete a configuration""" - logger = Logger(verbose=verbose) - try: + logger = Logger(verbose=verbose) + + logger.debug(debug_conf_command_invoked) + logger.debug(debug_service_param.format(service=service)) + logger.debug(debug_key_param.format(key=key)) + logger.debug(debug_verbose_param.format(verbose=verbose)) + logger.debug(debug_output_param.format(output=output)) + logger.debug(debug_dry_run_param.format(dry_run=dry_run)) + logger.debug(debug_env_file_param.format(env_file=env_file)) + logger.debug(debug_timeout_param.format(timeout=timeout)) + config = DeleteConfig(service=service, key=key, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file) + logger.debug(debug_config_created.format(config_type="DeleteConfig")) delete_action = Delete(logger=logger) + logger.debug(debug_action_created.format(action_type="Delete")) + + logger.debug(debug_timeout_wrapper_created.format(timeout=timeout)) + logger.debug(debug_executing_with_timeout.format(timeout=timeout)) with TimeoutWrapper(timeout): - result = delete_action.delete(config) - - if result.success: - logger.success(delete_action.format_output(result, output)) - else: - logger.error(result.error) - raise typer.Exit(1) + if config.dry_run: + logger.debug(debug_executing_dry_run) + formatted_output = delete_action.delete_and_format(config) + logger.info(formatted_output) + logger.debug(debug_dry_run_completed) + else: + result = delete_action.delete(config) + logger.debug(debug_conf_operation_result.format(success=result.success)) + + if result.success: + formatted_output = delete_action.format_output(result, output) + logger.success(formatted_output) + logger.debug(debug_conf_operation_completed) + else: + logger.error(result.error) + logger.debug(debug_conf_operation_failed) + raise typer.Exit(1) + + logger.debug(debug_timeout_completed) except TimeoutError as e: - logger.error(e) + logger.debug(debug_timeout_error.format(error=str(e))) + logger.error(str(e)) raise typer.Exit(1) except Exception as e: + logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) + logger.debug(debug_exception_details.format(error=e)) logger.error(str(e)) raise typer.Exit(1) @@ -97,32 +181,64 @@ def set( timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Set a configuration""" - logger = Logger(verbose=verbose) - try: + logger = Logger(verbose=verbose) + + logger.debug(debug_conf_command_invoked) + logger.debug(debug_service_param.format(service=service)) + logger.debug(debug_verbose_param.format(verbose=verbose)) + logger.debug(debug_output_param.format(output=output)) + logger.debug(debug_dry_run_param.format(dry_run=dry_run)) + logger.debug(debug_env_file_param.format(env_file=env_file)) + logger.debug(debug_timeout_param.format(timeout=timeout)) + logger.debug(debug_parsing_key_value.format(key_value=key_value)) + if "=" not in key_value: + logger.debug(debug_key_value_parse_failed.format(key_value=key_value)) logger.error(argument_must_be_in_form) raise typer.Exit(1) + key, value = key_value.split("=", 1) + logger.debug(debug_key_value_parsed.format(key=key, value=value)) config = SetConfig( service=service, key=key, value=value, verbose=verbose, output=output, dry_run=dry_run, env_file=env_file ) + logger.debug(debug_config_created.format(config_type="SetConfig")) set_action = Set(logger=logger) + logger.debug(debug_action_created.format(action_type="Set")) + + logger.debug(debug_timeout_wrapper_created.format(timeout=timeout)) + logger.debug(debug_executing_with_timeout.format(timeout=timeout)) with TimeoutWrapper(timeout): - result = set_action.set(config) - - if result.success: - logger.success(set_action.format_output(result, output)) - else: - logger.error(result.error) - raise typer.Exit(1) + if config.dry_run: + logger.debug(debug_executing_dry_run) + formatted_output = set_action.set_and_format(config) + logger.info(formatted_output) + logger.debug(debug_dry_run_completed) + else: + result = set_action.set(config) + logger.debug(debug_conf_operation_result.format(success=result.success)) + + if result.success: + formatted_output = set_action.format_output(result, output) + logger.success(formatted_output) + logger.debug(debug_conf_operation_completed) + else: + logger.error(result.error) + logger.debug(debug_conf_operation_failed) + raise typer.Exit(1) + + logger.debug(debug_timeout_completed) except TimeoutError as e: - logger.error(e) + logger.debug(debug_timeout_error.format(error=str(e))) + logger.error(str(e)) raise typer.Exit(1) except Exception as e: + logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) + logger.debug(debug_exception_details.format(error=e)) logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/conf/delete.py b/cli/app/commands/conf/delete.py index b56dbb4c..cf782e72 100644 --- a/cli/app/commands/conf/delete.py +++ b/cli/app/commands/conf/delete.py @@ -1,3 +1,4 @@ +import os from typing import Dict, Optional, Protocol from pydantic import BaseModel, Field @@ -14,6 +15,18 @@ dry_run_mode, end_dry_run, key_required_delete, + debug_deleting_config_key, + debug_config_key_deleted, + debug_config_key_not_found_delete, + debug_service_env_file_resolved, + debug_config_file_exists, + debug_config_file_not_exists, + debug_config_file_read_success, + debug_config_file_read_failed, + debug_config_file_write_failed, + debug_dry_run_simulation, + debug_dry_run_simulation_complete, + debug_validation_failed, ) @@ -24,16 +37,36 @@ def delete_config(self, service: str, key: str, env_file: str = None) -> tuple[b class EnvironmentManager(BaseEnvironmentManager): def delete_config(self, service: str, key: str, env_file: Optional[str] = None) -> tuple[bool, Optional[str]]: file_path = self.get_service_env_file(service, env_file) + self.logger.debug(debug_service_env_file_resolved.format(file_path=file_path)) + + if self.logger.verbose: + if os.path.exists(file_path): + self.logger.debug(debug_config_file_exists.format(file_path=file_path)) + else: + self.logger.debug(debug_config_file_not_exists.format(file_path=file_path)) success, config, error = self.read_env_file(file_path) if not success: + self.logger.debug(debug_config_file_read_failed.format(error=error)) return False, error + self.logger.debug(debug_config_file_read_success.format(count=len(config))) + if key not in config: + self.logger.debug(debug_config_key_not_found_delete.format(key=key)) return False, config_key_not_found.format(key=key) + self.logger.debug(debug_deleting_config_key.format(key=key)) del config[key] - return self.write_env_file(file_path, config) + + success, error = self.write_env_file(file_path, config) + + if success: + self.logger.debug(debug_config_key_deleted.format(key=key)) + else: + self.logger.debug(debug_config_file_write_failed.format(error=error)) + + return success, error class DeleteResult(BaseResult): @@ -67,10 +100,14 @@ def delete(self) -> DeleteResult: def execute(self) -> DeleteResult: if not self.config.key: + self.logger.debug(debug_validation_failed.format(error="Key is required")) return self._create_result(False, error=key_required_delete) if self.config.dry_run: - return self._create_result(True) + self.logger.debug(debug_dry_run_simulation) + result = self._create_result(True) + self.logger.debug(debug_dry_run_simulation_complete) + return result success, error = self.environment_service.delete_config(self.config.service, self.config.key, self.config.env_file) @@ -99,9 +136,11 @@ def _format_dry_run(self) -> str: def _format_output(self, result: DeleteResult, output_format: str) -> str: if output_format == "json": - return self._format_json(result) + formatted = self._format_json(result) else: - return self._format_text(result) + formatted = self._format_text(result) + + return formatted def _format_json(self, result: DeleteResult) -> str: import json @@ -130,3 +169,7 @@ def execute(self, config: DeleteConfig) -> DeleteResult: def format_output(self, result: DeleteResult, output: str) -> str: service = DeleteService(result, logger=self.logger) return service._format_output(result, output) + + def delete_and_format(self, config: DeleteConfig) -> str: + service = DeleteService(config, logger=self.logger) + return service.execute_and_format() diff --git a/cli/app/commands/conf/list.py b/cli/app/commands/conf/list.py index 5f799fe3..a6f4fe64 100644 --- a/cli/app/commands/conf/list.py +++ b/cli/app/commands/conf/list.py @@ -1,3 +1,4 @@ +import os from typing import Dict, Optional, Protocol from pydantic import BaseModel, Field @@ -13,6 +14,16 @@ dry_run_mode, end_dry_run, no_configuration_found, + debug_listing_config, + debug_config_listed, + debug_no_config_to_list, + debug_service_env_file_resolved, + debug_config_file_exists, + debug_config_file_not_exists, + debug_config_file_read_success, + debug_config_file_read_failed, + debug_dry_run_simulation, + debug_dry_run_simulation_complete, ) @@ -23,7 +34,22 @@ def list_config(self, service: str, env_file: str = None) -> tuple[bool, Dict[st class EnvironmentManager(BaseEnvironmentManager): def list_config(self, service: str, env_file: Optional[str] = None) -> tuple[bool, Dict[str, str], Optional[str]]: file_path = self.get_service_env_file(service, env_file) - return self.read_env_file(file_path) + self.logger.debug(debug_service_env_file_resolved.format(file_path=file_path)) + + if self.logger.verbose: + if os.path.exists(file_path): + self.logger.debug(debug_config_file_exists.format(file_path=file_path)) + else: + self.logger.debug(debug_config_file_not_exists.format(file_path=file_path)) + + success, config_dict, error = self.read_env_file(file_path) + + if success: + self.logger.debug(debug_config_file_read_success.format(count=len(config_dict))) + else: + self.logger.debug(debug_config_file_read_failed.format(error=error)) + + return success, config_dict, error class ListResult(BaseResult): @@ -55,12 +81,22 @@ def list(self) -> ListResult: return self.execute() def execute(self) -> ListResult: + self.logger.debug(debug_listing_config.format(service=self.config.service)) + if self.config.dry_run: - return self._create_result(True) + self.logger.debug(debug_dry_run_simulation) + result = self._create_result(True) + self.logger.debug(debug_dry_run_simulation_complete) + return result success, config_dict, error = self.environment_service.list_config(self.config.service, self.config.env_file) if success: + if config_dict: + self.logger.debug(debug_config_listed.format(count=len(config_dict))) + else: + self.logger.debug(debug_no_config_to_list) + self.logger.info(configuration_listed.format(service=self.config.service)) return self._create_result(True, config_dict=config_dict) else: @@ -85,9 +121,11 @@ def _format_dry_run(self) -> str: def _format_output(self, result: ListResult, output_format: str) -> str: if output_format == "json": - return self._format_json(result) + formatted = self._format_json(result) else: - return self._format_text(result) + formatted = self._format_text(result) + + return formatted def _format_json(self, result: ListResult) -> str: import json @@ -122,3 +160,7 @@ def execute(self, config: ListConfig) -> ListResult: def format_output(self, result: ListResult, output: str) -> str: service = ListService(result, logger=self.logger) return service._format_output(result, output) + + def list_and_format(self, config: ListConfig) -> str: + service = ListService(config, logger=self.logger) + return service.execute_and_format() diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py index 9572329c..36e208bc 100644 --- a/cli/app/commands/conf/messages.py +++ b/cli/app/commands/conf/messages.py @@ -30,43 +30,48 @@ backup_file_not_found = "Backup file not found" reading_env_file = "Reading environment file: {file_path}" file_not_exists = "File does not exist: {file_path}" -skipping_line = "Skipping line {line_num}: empty or comment" -parsed_config = "Parsed config: {key}={value}" read_success = "Successfully read {count} configuration entries from {file_path}" read_error = "Error reading file {file_path}: {error}" -creating_backup = "Creating backup for file: {file_path}" -no_backup_needed = "Source file does not exist, no backup needed: {file_path}" -backup_created_at = "Creating backup at: {backup_path}" -backup_created_success = "Backup created successfully: {backup_path}" -backup_failed = "Failed to create backup: {error}" -restoring_backup = "Restoring backup from {backup_path} to {file_path}" -backup_exists = "Backup file exists, restoring..." -backup_restored = "Backup restored and removed successfully" -backup_not_found = "Backup file not found: {backup_path}" -restore_failed = "Failed to restore backup: {error}" -atomic_write = "Performing atomic write to: {file_path}" -writing_entries = "Writing {count} configuration entries" -directory_ensured = "Ensured directory exists: {directory}" -temp_file_created = "Created temporary file: {temp_path}" -wrote_to_temp = "Wrote to temp file: {key}={value}" -synced_temp = "Synced temporary file to disk" -sync_not_critical = "Could not sync temporary file (not critical)" -replacing_file = "Replacing {file_path} with temporary file" -atomic_complete = "Atomic write completed successfully" -atomic_failed = "Atomic write failed: {error}" -cleanup_temp = "Cleaned up temporary file: {temp_path}" -cleanup_failed = "Failed to clean up temporary file: {temp_path}" -writing_env_file = "Writing environment file: {file_path}" -config_entries = "Configuration contains {count} entries" -backup_creation_failed = "Backup creation failed: {error}" -atomic_write_failed = "Atomic write failed, attempting backup restore" -backup_removed = "Backup file removed: {backup_path}" -backup_remove_failed = "Failed to remove backup: {error}" -write_complete = "Environment file write completed successfully" -unexpected_error = "Unexpected error during file write: {error}" -getting_service = "Getting environment file for service: {service}" -using_provided_env = "Using provided env_file: {env_file}" -using_default_api = "Using default API path: {path}" -using_default_view = "Using default view path: {path}" -invalid_service = "Invalid service: {service}" -argument_must_be_in_form = "Argument must be in the form KEY=VALUE" \ No newline at end of file +argument_must_be_in_form = "Argument must be in the form KEY=VALUE" +debug_conf_command_invoked = "Configuration command invoked with parameters:" +debug_service_param = " service: {service}" +debug_key_param = " key: {key}" +debug_value_param = " value: {value}" +debug_verbose_param = " verbose: {verbose}" +debug_output_param = " output: {output}" +debug_dry_run_param = " dry_run: {dry_run}" +debug_env_file_param = " env_file: {env_file}" +debug_timeout_param = " timeout: {timeout}" +debug_executing_dry_run = "Executing dry run mode" +debug_dry_run_completed = "Dry run completed successfully" +debug_conf_operation_result = "Configuration operation result - success: {success}" +debug_conf_operation_failed = "Configuration operation failed, raising exit" +debug_conf_operation_completed = "Configuration operation completed successfully" +debug_exception_caught = "Exception caught in configuration callback: {error_type}: {error}" +debug_exception_details = "Exception details: {error}" +debug_parsing_key_value = "Parsing key-value argument: {key_value}" +debug_key_value_parsed = "Key-value parsed - key: {key}, value: {value}" +debug_key_value_parse_failed = "Key-value parsing failed: {key_value}" +debug_config_created = "Configuration object created: {config_type}" +debug_action_created = "Action object created: {action_type}" +debug_timeout_wrapper_created = "Timeout wrapper created with timeout: {timeout}s" +debug_executing_with_timeout = "Executing operation with timeout: {timeout}s" +debug_timeout_completed = "Timeout wrapper completed successfully" +debug_timeout_error = "Timeout error occurred: {error}" +debug_validation_failed = "Configuration validation failed: {error}" +debug_service_env_file_resolved = "Service environment file resolved: {file_path}" +debug_config_file_exists = "Configuration file exists: {file_path}" +debug_config_file_not_exists = "Configuration file does not exist: {file_path}" +debug_config_file_read_success = "Configuration file read successfully: {count} entries" +debug_config_file_read_failed = "Configuration file read failed: {error}" +debug_updating_config = "Updating configuration: {key}={value}" +debug_config_updated = "Configuration updated successfully" +debug_config_file_write_failed = "Configuration file write failed: {error}" +debug_deleting_config_key = "Deleting configuration key: {key}" +debug_config_key_deleted = "Configuration key deleted successfully" +debug_config_key_not_found_delete = "Configuration key not found for deletion: {key}" +debug_listing_config = "Listing configuration for service: {service}" +debug_config_listed = "Configuration listed successfully: {count} entries" +debug_no_config_to_list = "No configuration entries to list" +debug_dry_run_simulation = "Simulating operation in dry run mode" +debug_dry_run_simulation_complete = "Dry run simulation completed" diff --git a/cli/app/commands/conf/set.py b/cli/app/commands/conf/set.py index a78adf6a..2f286d39 100644 --- a/cli/app/commands/conf/set.py +++ b/cli/app/commands/conf/set.py @@ -1,3 +1,4 @@ +import os from typing import Dict, Optional, Protocol from pydantic import BaseModel, Field @@ -14,6 +15,17 @@ end_dry_run, key_required, value_required, + debug_updating_config, + debug_config_updated, + debug_service_env_file_resolved, + debug_config_file_exists, + debug_config_file_not_exists, + debug_config_file_read_success, + debug_config_file_read_failed, + debug_config_file_write_failed, + debug_dry_run_simulation, + debug_dry_run_simulation_complete, + debug_validation_failed, ) @@ -24,13 +36,32 @@ def set_config(self, service: str, key: str, value: str, env_file: str = None) - class EnvironmentManager(BaseEnvironmentManager): def set_config(self, service: str, key: str, value: str, env_file: Optional[str] = None) -> tuple[bool, Optional[str]]: file_path = self.get_service_env_file(service, env_file) + self.logger.debug(debug_service_env_file_resolved.format(file_path=file_path)) + + if self.logger.verbose: + if os.path.exists(file_path): + self.logger.debug(debug_config_file_exists.format(file_path=file_path)) + else: + self.logger.debug(debug_config_file_not_exists.format(file_path=file_path)) success, config, error = self.read_env_file(file_path) if not success: + self.logger.debug(debug_config_file_read_failed.format(error=error)) return False, error + self.logger.debug(debug_config_file_read_success.format(count=len(config))) + + self.logger.debug(debug_updating_config.format(key=key, value=value)) config[key] = value - return self.write_env_file(file_path, config) + + success, error = self.write_env_file(file_path, config) + + if success: + self.logger.debug(debug_config_updated) + else: + self.logger.debug(debug_config_file_write_failed.format(error=error)) + + return success, error class SetResult(BaseResult): @@ -66,13 +97,18 @@ def set(self) -> SetResult: def execute(self) -> SetResult: if not self.config.key: + self.logger.debug(debug_validation_failed.format(error="Key is required")) return self._create_result(False, error=key_required) if not self.config.value: + self.logger.debug(debug_validation_failed.format(error="Value is required")) return self._create_result(False, error=value_required) if self.config.dry_run: - return self._create_result(True) + self.logger.debug(debug_dry_run_simulation) + result = self._create_result(True) + self.logger.debug(debug_dry_run_simulation_complete) + return result success, error = self.environment_service.set_config( self.config.service, self.config.key, self.config.value, self.config.env_file @@ -105,9 +141,11 @@ def _format_dry_run(self) -> str: def _format_output(self, result: SetResult, output_format: str) -> str: if output_format == "json": - return self._format_json(result) + formatted = self._format_json(result) else: - return self._format_text(result) + formatted = self._format_text(result) + + return formatted def _format_json(self, result: SetResult) -> str: import json @@ -142,3 +180,7 @@ def execute(self, config: SetConfig) -> SetResult: def format_output(self, result: SetResult, output: str) -> str: service = SetService(result, logger=self.logger) return service._format_output(result, output) + + def set_and_format(self, config: SetConfig) -> str: + service = SetService(config, logger=self.logger) + return service.execute_and_format() diff --git a/cli/app/commands/install/messages.py b/cli/app/commands/install/messages.py index 70452a5e..33c0463a 100644 --- a/cli/app/commands/install/messages.py +++ b/cli/app/commands/install/messages.py @@ -1,34 +1,16 @@ path_already_exists_use_force = "Path {path} already exists. Use --force to overwrite." executing_command = "Executing: {command}" -successfully_cloned = "Successfully cloned {repo} to {path}" -git_clone_failed = "Git clone failed: {error}" -unexpected_error_during_clone = "Unexpected error during clone: {error}" -dry_run_mode = "=== DRY RUN MODE ===" -dry_run_command_would_be_executed = "The following command would be executed:" -dry_run_command = "Command: {command}" -dry_run_repository = "Repository: {repo}" -dry_run_branch = "Branch: {branch}" -dry_run_target_path = "Target path: {path}" -dry_run_force_mode = "Force mode: {force}" -git_not_available = "Git is not available on the system" -git_available = "Git is available on the system" -path_exists_will_overwrite = "Path {path} exists and will be overwritten (force mode)" -path_exists_would_fail = "Path {path} exists - clone would fail without --force" -target_path_not_exists = "Target path {path} does not exist" -end_dry_run = "=== END DRY RUN ===" -cloning_repo_into_path = "Cloning {repo} into {path}" installing_nixopus = "Installing nixopus" -invalid_repository_url = "Invalid repository URL format" -invalid_target_path = "Invalid target path format" -invalid_branch = "Invalid branch format" invalid_output_format = "Invalid output format" invalid_dry_run = "Invalid dry run format" invalid_force = "Invalid force format" invalid_verbose = "Invalid verbose format" -invalid_repo = "Invalid repository format" -invalid_path = "Invalid path format" +dry_run_mode = "=== DRY RUN MODE ===" +dry_run_command_would_be_executed = "The following command would be executed:" +dry_run_command = "Command: {command}" +dry_run_force_mode = "Force mode: {force}" +end_dry_run = "=== END DRY RUN ===" prerequisites_validation_failed = "Prerequisites validation failed" -failed_to_prepare_target_directory = "Failed to prepare target directory" successfully_added_ssh_key = "Successfully generated SSH key: {key}" ssh_key_add_failed = "SSH key generation failed: {error}" unexpected_error_during_ssh_add = "Unexpected error during SSH key generation: {error}" @@ -57,7 +39,6 @@ failed_to_append_to_authorized_keys = "Failed to append to authorized_keys" failed_to_add_to_authorized_keys = "Failed to add to authorized_keys: {error}" unknown_error = "Unknown error" -default_branch = "default" unsupported_package_manager = "Unsupported package manager: {package_manager}" no_supported_package_manager = "No supported package manager found" failed_to_install = "Failed to install {dep}: {error}" diff --git a/cli/app/commands/preflight/command.py b/cli/app/commands/preflight/command.py index f4e81d1a..b50de927 100644 --- a/cli/app/commands/preflight/command.py +++ b/cli/app/commands/preflight/command.py @@ -5,7 +5,26 @@ from app.utils.timeout import TimeoutWrapper from .deps import Deps, DepsConfig -from .messages import error_checking_deps, error_checking_ports +from .messages import ( + debug_starting_preflight_check, + debug_preflight_check_completed, + debug_starting_ports_check, + debug_ports_check_completed, + debug_starting_deps_check, + debug_deps_check_completed, + debug_creating_port_config, + debug_creating_deps_config, + debug_initializing_port_service, + debug_initializing_deps_service, + debug_timeout_wrapper_start, + debug_timeout_wrapper_end, + debug_formatting_output, + error_checking_deps, + error_checking_ports, + error_timeout_occurred, + error_validation_failed, + running_preflight_checks, +) from .port import PortConfig, PortService preflight_app = typer.Typer(no_args_is_help=False) @@ -25,7 +44,23 @@ def check( timeout: int = typer.Option(10, "--timeout", "-t", help="Timeout in seconds"), ): """Run all preflight checks""" - pass + try: + logger = Logger(verbose=verbose) + logger.debug(debug_starting_preflight_check) + logger.info(running_preflight_checks) + + logger.debug(debug_timeout_wrapper_start.format(timeout=timeout)) + with TimeoutWrapper(timeout): + logger.debug(debug_timeout_wrapper_end) + logger.debug(debug_preflight_check_completed) + + logger.success("All preflight checks completed successfully") + except TimeoutError as e: + logger.error(error_timeout_occurred.format(timeout=timeout)) + raise typer.Exit(1) + except Exception as e: + logger.error(f"Unexpected error during preflight check: {e}") + raise typer.Exit(1) @preflight_app.command() @@ -39,16 +74,30 @@ def ports( """Check if list of ports are available on a host""" try: logger = Logger(verbose=verbose) - logger.debug(f"Checking ports: {ports}") + logger.debug(debug_starting_ports_check) + + logger.debug(debug_creating_port_config) config = PortConfig(ports=ports, host=host, verbose=verbose) + + logger.debug(debug_initializing_port_service) port_service = PortService(config, logger=logger) + logger.debug(debug_timeout_wrapper_start.format(timeout=timeout)) with TimeoutWrapper(timeout): results = port_service.check_ports() + logger.debug(debug_timeout_wrapper_end) + + logger.debug(debug_formatting_output.format(format=output)) + formatted_output = port_service.formatter.format_output(results, output) + + logger.success(formatted_output) + logger.debug(debug_ports_check_completed) - logger.success(port_service.formatter.format_output(results, output)) + except ValueError as e: + logger.error(error_validation_failed.format(error=e)) + raise typer.Exit(1) except TimeoutError as e: - logger.error(e) + logger.error(error_timeout_occurred.format(timeout=timeout)) raise typer.Exit(1) except Exception as e: logger.error(error_checking_ports.format(error=e)) @@ -65,6 +114,9 @@ def deps( """Check if list of dependencies are available on the system""" try: logger = Logger(verbose=verbose) + logger.debug(debug_starting_deps_check) + + logger.debug(debug_creating_deps_config) config = DepsConfig( deps=deps, verbose=verbose, @@ -72,14 +124,26 @@ def deps( os=HostInformation.get_os_name(), package_manager=HostInformation.get_package_manager(), ) + + logger.debug(debug_initializing_deps_service) deps_checker = Deps(logger=logger) + logger.debug(debug_timeout_wrapper_start.format(timeout=timeout)) with TimeoutWrapper(timeout): results = deps_checker.check(config) + logger.debug(debug_timeout_wrapper_end) + + logger.debug(debug_formatting_output.format(format=output)) + formatted_output = deps_checker.format_output(results, output) - logger.success(deps_checker.format_output(results, output)) + logger.success(formatted_output) + logger.debug(debug_deps_check_completed) + + except ValueError as e: + logger.error(error_validation_failed.format(error=e)) + raise typer.Exit(1) except TimeoutError as e: - logger.error(e) + logger.error(error_timeout_occurred.format(timeout=timeout)) raise typer.Exit(1) except Exception as e: logger.error(error_checking_deps.format(error=e)) diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py index 0649db68..7636480c 100644 --- a/cli/app/commands/preflight/deps.py +++ b/cli/app/commands/preflight/deps.py @@ -8,7 +8,15 @@ from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol -from .messages import error_checking_dependency, invalid_os, invalid_package_manager, timeout_checking_dependency +from .messages import ( + error_checking_dependency, + invalid_os, + invalid_package_manager, + timeout_checking_dependency, + debug_processing_deps, + debug_dep_check_result, + error_subprocess_execution_failed, +) class DependencyCheckerProtocol(Protocol): @@ -20,17 +28,19 @@ def __init__(self, logger: LoggerProtocol): self.logger = logger def check_dependency(self, dep: str) -> bool: - self.logger.debug(f"Checking dependency: {dep}") - try: result = subprocess.run(["command", "-v", dep], capture_output=True, text=True, timeout=1) - return result.returncode == 0 + is_available = result.returncode == 0 + self.logger.debug(debug_dep_check_result.format(dep=dep, status="available" if is_available else "not available")) + return is_available except subprocess.TimeoutExpired: - self.logger.error(timeout_checking_dependency.format(dep=dep)) + if self.logger.verbose: + self.logger.error(timeout_checking_dependency.format(dep=dep)) return False except Exception as e: - self.logger.error(error_checking_dependency.format(dep=dep, error=e)) + if self.logger.verbose: + self.logger.error(error_subprocess_execution_failed.format(dep=dep, error=e)) return False @@ -60,10 +70,12 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: for result in results: if result.is_available: message = f"{result.dependency} is available" - messages.append(self.output_formatter.create_success_message(message, result.model_dump())) + data = {"dependency": result.dependency, "is_available": result.is_available} + messages.append(self.output_formatter.create_success_message(message, data)) else: error = f"{result.dependency} is not available" - messages.append(self.output_formatter.create_error_message(error, result.model_dump())) + data = {"dependency": result.dependency, "is_available": result.is_available, "error": result.error} + messages.append(self.output_formatter.create_error_message(error, data)) return self.output_formatter.format_output(messages, output) @@ -124,13 +136,14 @@ def _check_dependency(self, dep: str) -> DepsCheckResult: return self._create_result(dep, False, str(e)) def check_dependencies(self) -> list[DepsCheckResult]: - self.logger.debug(f"Checking dependencies: {self.config.deps}") + self.logger.debug(debug_processing_deps.format(count=len(self.config.deps))) def process_dep(dep: str) -> DepsCheckResult: return self._check_dependency(dep) def error_handler(dep: str, error: Exception) -> DepsCheckResult: - self.logger.error(error_checking_dependency.format(dep=dep, error=error)) + if self.logger.verbose: + self.logger.error(error_checking_dependency.format(dep=dep, error=error)) return self._create_result(dep, False, str(error)) results = ParallelProcessor.process_items( diff --git a/cli/app/commands/preflight/messages.py b/cli/app/commands/preflight/messages.py index 3fd2a452..df42604d 100644 --- a/cli/app/commands/preflight/messages.py +++ b/cli/app/commands/preflight/messages.py @@ -16,3 +16,29 @@ invalid_output_format = "Invalid output format: {output}" error_checking_dependency = "Error checking dependency {dep}: {error}" timeout_checking_dependency = "Timeout checking dependency: {dep}" +debug_starting_preflight_check = "Starting preflight check command" +debug_preflight_check_completed = "Preflight check completed" +debug_starting_ports_check = "Starting ports check command" +debug_ports_check_completed = "Ports check completed" +debug_starting_deps_check = "Starting dependencies check command" +debug_deps_check_completed = "Dependencies check completed" +debug_creating_port_config = "Creating port configuration" +debug_creating_deps_config = "Creating dependencies configuration" +debug_initializing_port_service = "Initializing port service" +debug_initializing_deps_service = "Initializing dependencies service" +debug_processing_ports = "Processing {count} ports" +debug_processing_deps = "Processing {count} dependencies" +debug_port_check_result = "Port {port} check result: {status}" +debug_dep_check_result = "Dependency {dep} check result: {status}" +debug_formatting_output = "Formatting output as {format}" +debug_timeout_wrapper_start = "Starting timeout wrapper with {timeout}s timeout" +debug_timeout_wrapper_end = "Timeout wrapper completed" +error_invalid_port_range = "Port {port} is outside valid range (1-65535)" +error_invalid_host_format = "Invalid host format: {host}" +error_timeout_occurred = "Operation timed out after {timeout} seconds" +error_validation_failed = "Validation failed: {error}" +error_service_initialization_failed = "Failed to initialize service: {error}" +error_output_formatting_failed = "Failed to format output: {error}" +error_parallel_processing_failed = "Parallel processing failed: {error}" +error_socket_connection_failed = "Socket connection failed for port {port}: {error}" +error_subprocess_execution_failed = "Subprocess execution failed for dependency {dep}: {error}" diff --git a/cli/app/commands/preflight/port.py b/cli/app/commands/preflight/port.py index 4bb9e6b2..599deae0 100644 --- a/cli/app/commands/preflight/port.py +++ b/cli/app/commands/preflight/port.py @@ -9,7 +9,15 @@ from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol -from .messages import available, error_checking_port, host_must_be_localhost_or_valid_ip_or_domain, not_available +from .messages import ( + available, + error_checking_port, + host_must_be_localhost_or_valid_ip_or_domain, + not_available, + debug_processing_ports, + debug_port_check_result, + error_socket_connection_failed, +) class PortCheckerProtocol(Protocol): @@ -53,10 +61,14 @@ def format_output(self, data: Union[str, List[PortCheckResult], Any], output_typ for item in data: if item.get("is_available", False): message = f"Port {item['port']}: {item['status']}" - messages.append(self.output_formatter.create_success_message(message, item)) + data = {"port": item['port'], "status": item['status'], "is_available": item['is_available']} + messages.append(self.output_formatter.create_success_message(message, data)) else: error = f"Port {item['port']}: {item['status']}" - messages.append(self.output_formatter.create_error_message(error, item)) + data = {"port": item['port'], "status": item['status'], "is_available": item['is_available']} + if item.get('error'): + data['error'] = item['error'] + messages.append(self.output_formatter.create_error_message(error, data)) return self.output_formatter.format_output(messages, output_type) else: return str(data) @@ -72,16 +84,19 @@ def is_port_available(self, host: str, port: int) -> bool: sock.settimeout(1) result = sock.connect_ex((host, port)) return result != 0 - except Exception: + except Exception as e: + if self.logger.verbose: + self.logger.error(error_socket_connection_failed.format(port=port, error=e)) return False def check_port(self, port: int, config: PortConfig) -> PortCheckResult: - self.logger.debug(f"Checking port {port} on host {config.host}") try: status = available if self.is_port_available(config.host, port) else not_available + self.logger.debug(debug_port_check_result.format(port=port, status=status)) return self._create_result(port, config, status) except Exception as e: - self.logger.error(error_checking_port.format(port=port, error=str(e))) + if self.logger.verbose: + self.logger.error(error_checking_port.format(port=port, error=str(e))) return self._create_result(port, config, not_available, str(e)) def _create_result(self, port: int, config: PortConfig, status: str, error: Optional[str] = None) -> PortCheckResult: @@ -102,13 +117,14 @@ def __init__(self, config: PortConfig, logger: LoggerProtocol = None, checker: P self.formatter = PortFormatter() def check_ports(self) -> List[PortCheckResult]: - self.logger.debug(f"Checking ports: {self.config.ports}") + self.logger.debug(debug_processing_ports.format(count=len(self.config.ports))) def process_port(port: int) -> PortCheckResult: return self.checker.check_port(port, self.config) def error_handler(port: int, error: Exception) -> PortCheckResult: - self.logger.error(error_checking_port.format(port=port, error=str(error))) + if self.logger.verbose: + self.logger.error(error_checking_port.format(port=port, error=str(error))) return self.checker._create_result(port, self.config, not_available, str(error)) results = ParallelProcessor.process_items( diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py index 3fc065f6..5e683c48 100644 --- a/cli/app/utils/lib.py +++ b/cli/app/utils/lib.py @@ -136,13 +136,20 @@ def path_exists_and_not_force(path: str, force: bool) -> bool: @staticmethod def remove_directory(path: str, logger=None) -> bool: + if logger: + logger.debug(f"Attempting to remove directory: {path}") + logger.debug(f"Directory exists: {os.path.exists(path)}") + logger.debug(f"Directory is directory: {os.path.isdir(path) if os.path.exists(path) else 'N/A'}") + try: shutil.rmtree(path) if logger: logger.info(REMOVED_DIRECTORY_MESSAGE.format(path=path)) + logger.debug(f"Directory {path} removed successfully") return True except Exception as e: if logger: + logger.debug(f"Exception during directory removal: {type(e).__name__}: {str(e)}") logger.error(FAILED_TO_REMOVE_DIRECTORY_MESSAGE.format(path=path, error=e)) return False From 1b39e4ba0ac8878586985ec5b74c54ea56bc32be Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Mon, 21 Jul 2025 21:17:31 +0530 Subject: [PATCH 52/72] feat : consistent output formatting (#298) feat: maintain output consistency across commands --- cli/app/commands/clone/command.py | 26 +++- cli/app/commands/clone/messages.py | 7 + cli/app/commands/clone/tests/test_clone.py | 18 +-- cli/app/commands/conf/base.py | 6 +- cli/app/commands/conf/command.py | 9 +- cli/app/commands/conf/delete.py | 2 - cli/app/commands/conf/list.py | 35 ++++- cli/app/commands/conf/messages.py | 4 + cli/app/commands/conf/set.py | 4 - cli/app/commands/conf/tests/test_base.py | 8 +- cli/app/commands/conf/tests/test_delete.py | 3 +- cli/app/commands/conf/tests/test_list.py | 21 +-- cli/app/commands/conf/tests/test_set.py | 3 +- cli/app/commands/preflight/command.py | 9 +- cli/app/commands/preflight/deps.py | 44 +++++- cli/app/commands/preflight/port.py | 50 +++++-- cli/app/commands/preflight/tests/test_deps.py | 41 +++--- cli/app/commands/preflight/tests/test_port.py | 5 +- cli/app/commands/proxy/base.py | 106 +++++++++++--- cli/app/commands/proxy/command.py | 51 ++++--- cli/app/commands/proxy/load.py | 27 ++-- cli/app/commands/proxy/messages.py | 27 ++++ cli/app/commands/proxy/status.py | 25 ++-- cli/app/commands/proxy/stop.py | 16 ++- cli/app/commands/service/base.py | 94 +++++++++++-- cli/app/commands/service/command.py | 58 ++++++-- cli/app/commands/service/down.py | 13 +- cli/app/commands/service/messages.py | 8 ++ cli/app/commands/service/ps.py | 131 ++++++++++++++++-- cli/app/commands/service/restart.py | 21 ++- cli/app/commands/service/up.py | 25 ++-- cli/app/main.py | 58 ++++---- cli/app/utils/lib.py | 2 +- cli/app/utils/output_formatter.py | 80 ++++++++++- helpers/config.prod.yaml | 2 +- 35 files changed, 773 insertions(+), 266 deletions(-) diff --git a/cli/app/commands/clone/command.py b/cli/app/commands/clone/command.py index 28aef65a..eeb00696 100644 --- a/cli/app/commands/clone/command.py +++ b/cli/app/commands/clone/command.py @@ -14,6 +14,13 @@ debug_verbose_param, debug_output_param, debug_dry_run_param, + debug_timeout_param, + debug_config_created, + debug_action_created, + debug_timeout_wrapper_created, + debug_executing_with_timeout, + debug_timeout_completed, + debug_timeout_error, debug_executing_dry_run, debug_dry_run_completed, debug_clone_operation_result, @@ -53,16 +60,22 @@ def clone_callback( logger.debug(debug_verbose_param.format(verbose=verbose)) logger.debug(debug_output_param.format(output=output)) logger.debug(debug_dry_run_param.format(dry_run=dry_run)) + logger.debug(debug_timeout_param.format(timeout=timeout)) config = CloneConfig(repo=repo, branch=branch, path=path, force=force, verbose=verbose, output=output, dry_run=dry_run) + logger.debug(debug_config_created.format(config_type="CloneConfig")) clone_operation = Clone(logger=logger) + logger.debug(debug_action_created.format(action_type="Clone")) + + logger.debug(debug_timeout_wrapper_created.format(timeout=timeout)) + logger.debug(debug_executing_with_timeout.format(timeout=timeout)) with TimeoutWrapper(timeout): if config.dry_run: logger.debug(debug_executing_dry_run) formatted_output = clone_operation.clone_and_format(config) - logger.info(formatted_output) + logger.success(formatted_output) logger.debug(debug_dry_run_completed) else: result = clone_operation.clone(config) @@ -74,13 +87,18 @@ def clone_callback( raise typer.Exit(1) logger.debug(debug_clone_operation_completed) - logger.info(result.output) + logger.success(result.output) + + logger.debug(debug_timeout_completed) except TimeoutError as e: - logger.error(e) + logger.debug(debug_timeout_error.format(error=str(e))) + if not isinstance(e, typer.Exit): + logger.error(str(e)) raise typer.Exit(1) except Exception as e: logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) logger.debug(debug_exception_details.format(error=e)) - logger.error(str(e)) + if not isinstance(e, typer.Exit): + logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/clone/messages.py b/cli/app/commands/clone/messages.py index eb420999..b4c6627d 100644 --- a/cli/app/commands/clone/messages.py +++ b/cli/app/commands/clone/messages.py @@ -22,6 +22,13 @@ debug_clone_operation_completed = "Clone operation completed successfully" debug_exception_caught = "Exception caught in clone callback: {error_type}: {error}" debug_exception_details = "Exception details: {error}" +debug_timeout_param = " timeout: {timeout}" +debug_config_created = "Created {config_type} with parameters" +debug_action_created = "Created {action_type} action instance" +debug_timeout_wrapper_created = "TimeoutWrapper created with {timeout}s timeout" +debug_executing_with_timeout = "Executing clone operation with {timeout}s timeout" +debug_timeout_completed = "Timeout wrapper completed successfully" +debug_timeout_error = "Timeout error occurred: {error}" path_already_exists_use_force = "Path {path} already exists. Use --force to overwrite." prerequisites_validation_failed = "Prerequisites validation failed" failed_to_prepare_target_directory = "Failed to prepare target directory" diff --git a/cli/app/commands/clone/tests/test_clone.py b/cli/app/commands/clone/tests/test_clone.py index dd44ba86..af973186 100644 --- a/cli/app/commands/clone/tests/test_clone.py +++ b/cli/app/commands/clone/tests/test_clone.py @@ -143,7 +143,7 @@ def test_clone_repository_success(self, mock_run): assert success is True assert error is None - self.logger.info.assert_called_once() + self.logger.debug.assert_called() @patch("subprocess.run") def test_clone_repository_without_branch(self, mock_run): @@ -247,7 +247,7 @@ def test_remove_directory_success(self, mock_rmtree): assert success is True mock_rmtree.assert_called_once_with("/path/to/remove") - self.logger.info.assert_called_once() + self.logger.debug.assert_called() @patch("shutil.rmtree") def test_remove_directory_failure(self, mock_rmtree): @@ -447,18 +447,8 @@ def test_debug_logging_enabled(self): logger = Mock(spec=Logger) clone_operation = Clone(logger=logger) - with patch.object(CloneService, "clone") as mock_clone: - mock_result = CloneResult( - repo=config.repo, - path=config.path, - branch=config.branch, - force=config.force, - verbose=config.verbose, - output=config.output, - success=True, - ) - mock_clone.return_value = mock_result - + # Patch only GitClone.clone_repository to simulate a successful clone + with patch("app.commands.clone.clone.GitClone.clone_repository", return_value=(True, None)): result = clone_operation.clone(config) # Verify that debug logging was called diff --git a/cli/app/commands/conf/base.py b/cli/app/commands/conf/base.py index 50d62cf3..9e4755c9 100644 --- a/cli/app/commands/conf/base.py +++ b/cli/app/commands/conf/base.py @@ -128,7 +128,7 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, return False, error backup_created_flag = True - self.logger.info(backup_created.format(backup_path=backup_path)) + self.logger.debug(backup_created.format(backup_path=backup_path)) success, error = self._atomic_write(file_path, config) if not success: @@ -136,7 +136,7 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, self.logger.warning(backup_restore_attempt) restore_success, restore_error = self._restore_backup(backup_path, file_path) if restore_success: - self.logger.info(backup_restore_success) + self.logger.debug(backup_restore_success) else: self.logger.error(backup_restore_failed.format(error=restore_error)) return False, error @@ -144,7 +144,7 @@ def write_env_file(self, file_path: str, config: Dict[str, str]) -> tuple[bool, if backup_created_flag and backup_path and os.path.exists(backup_path): try: os.remove(backup_path) - self.logger.info(backup_removed) + self.logger.debug(backup_removed) except Exception as e: self.logger.warning(backup_remove_failed.format(error=e)) diff --git a/cli/app/commands/conf/command.py b/cli/app/commands/conf/command.py index 190f6c6c..b62ea039 100644 --- a/cli/app/commands/conf/command.py +++ b/cli/app/commands/conf/command.py @@ -98,7 +98,8 @@ def list( except Exception as e: logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) logger.debug(debug_exception_details.format(error=e)) - logger.error(str(e)) + if not isinstance(e, typer.Exit): + logger.error(str(e)) raise typer.Exit(1) @@ -164,7 +165,8 @@ def delete( except Exception as e: logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) logger.debug(debug_exception_details.format(error=e)) - logger.error(str(e)) + if not isinstance(e, typer.Exit): + logger.error(str(e)) raise typer.Exit(1) @@ -240,5 +242,6 @@ def set( except Exception as e: logger.debug(debug_exception_caught.format(error_type=type(e).__name__, error=str(e))) logger.debug(debug_exception_details.format(error=e)) - logger.error(str(e)) + if not isinstance(e, typer.Exit): + logger.error(str(e)) raise typer.Exit(1) diff --git a/cli/app/commands/conf/delete.py b/cli/app/commands/conf/delete.py index cf782e72..e31db571 100644 --- a/cli/app/commands/conf/delete.py +++ b/cli/app/commands/conf/delete.py @@ -112,10 +112,8 @@ def execute(self) -> DeleteResult: success, error = self.environment_service.delete_config(self.config.service, self.config.key, self.config.env_file) if success: - self.logger.info(configuration_deleted.format(service=self.config.service, key=self.config.key)) return self._create_result(True) else: - self.logger.error(configuration_delete_failed.format(service=self.config.service, error=error)) return self._create_result(False, error=error) def delete_and_format(self) -> str: diff --git a/cli/app/commands/conf/list.py b/cli/app/commands/conf/list.py index a6f4fe64..22962778 100644 --- a/cli/app/commands/conf/list.py +++ b/cli/app/commands/conf/list.py @@ -5,6 +5,7 @@ from app.utils.logger import Logger from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter from .base import BaseAction, BaseConfig, BaseEnvironmentManager, BaseResult, BaseService from .messages import ( @@ -24,6 +25,7 @@ debug_config_file_read_failed, debug_dry_run_simulation, debug_dry_run_simulation_complete, + configuration_list_title, ) @@ -66,6 +68,7 @@ def __init__( ): super().__init__(config, logger, environment_service) self.environment_service = environment_service or EnvironmentManager(self.logger) + self.formatter = OutputFormatter() def _create_result(self, success: bool, error: str = None, config_dict: Dict[str, str] = None) -> ListResult: return ListResult( @@ -97,7 +100,10 @@ def execute(self) -> ListResult: else: self.logger.debug(debug_no_config_to_list) +<<<<<<< HEAD +======= self.logger.info(configuration_listed.format(service=self.config.service)) +>>>>>>> feat/cli return self._create_result(True, config_dict=config_dict) else: self.logger.error(configuration_list_failed.format(service=self.config.service, error=error)) @@ -120,6 +126,8 @@ def _format_dry_run(self) -> str: return "\n".join(lines) def _format_output(self, result: ListResult, output_format: str) -> str: +<<<<<<< HEAD +======= if output_format == "json": formatted = self._format_json(result) else: @@ -134,16 +142,31 @@ def _format_json(self, result: ListResult) -> str: return json.dumps(output, indent=2) def _format_text(self, result: ListResult) -> str: +>>>>>>> feat/cli if not result.success: return configuration_list_failed.format(service=result.service, error=result.error) if result.config: - lines = [configuration_listed.format(service=result.service)] - for key, value in sorted(result.config.items()): - lines.append(f" {key}={value}") - return "\n".join(lines) - - return no_configuration_found.format(service=result.service) + success_message = configuration_listed.format(service=result.service) + title = configuration_list_title.format(service=result.service) + headers = ("Key", "Value") + + return self.formatter.format_table_output( + data=result.config, + output_format=output_format, + success_message=success_message, + title=title, + headers=headers + ) + else: + if output_format == "json": + return self.formatter.format_json({ + "service": result.service, + "success": result.success, + "message": no_configuration_found.format(service=result.service), + "config": {} + }) + return no_configuration_found.format(service=result.service) class List(BaseAction[ListConfig, ListResult]): diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py index 36e208bc..ab9eb426 100644 --- a/cli/app/commands/conf/messages.py +++ b/cli/app/commands/conf/messages.py @@ -75,3 +75,7 @@ debug_no_config_to_list = "No configuration entries to list" debug_dry_run_simulation = "Simulating operation in dry run mode" debug_dry_run_simulation_complete = "Dry run simulation completed" +<<<<<<< HEAD +configuration_list_title = "Configuration listed for {service}" +======= +>>>>>>> feat/cli diff --git a/cli/app/commands/conf/set.py b/cli/app/commands/conf/set.py index 2f286d39..16f5c8e3 100644 --- a/cli/app/commands/conf/set.py +++ b/cli/app/commands/conf/set.py @@ -115,12 +115,8 @@ def execute(self) -> SetResult: ) if success: - self.logger.info( - configuration_set.format(service=self.config.service, key=self.config.key, value=self.config.value) - ) return self._create_result(True) else: - self.logger.error(configuration_set_failed.format(service=self.config.service, error=error)) return self._create_result(False, error=error) def set_and_format(self) -> str: diff --git a/cli/app/commands/conf/tests/test_base.py b/cli/app/commands/conf/tests/test_base.py index 61a81654..8023dce2 100644 --- a/cli/app/commands/conf/tests/test_base.py +++ b/cli/app/commands/conf/tests/test_base.py @@ -92,7 +92,7 @@ def test_create_backup_failure(self, mock_exists): assert success is False assert backup_path is None - assert "Backup creation failed" in error + assert "Failed to create backup" in error @patch("os.path.exists") def test_restore_backup_success(self, mock_exists): @@ -204,7 +204,7 @@ def test_write_env_file_success_with_backup( assert error is None mock_copy.assert_called_once_with("/path/to/.env", "/path/to/.env.backup") mock_remove.assert_called_once_with("/path/to/.env.backup") - self.logger.info.assert_called() + self.logger.debug.assert_called() @patch("os.path.exists") @patch("tempfile.NamedTemporaryFile") @@ -239,7 +239,7 @@ def test_write_env_file_backup_failure(self, mock_copy, mock_exists): success, error = self.manager.write_env_file("/path/to/.env", config) assert success is False - assert "Backup creation failed" in error + assert "Failed to create backup" in error @patch("os.path.exists") @patch("shutil.copy2") @@ -259,7 +259,7 @@ def test_write_env_file_write_failure_with_restore(self, mock_tempfile, mock_cop assert "Failed to write environment file" in error mock_restore.assert_called_once_with("/path/to/.env.backup", "/path/to/.env") self.logger.warning.assert_called() - self.logger.info.assert_called() + self.logger.debug.assert_called() def test_get_service_env_file_with_custom_env_file(self): env_file = self.manager.get_service_env_file("api", "/custom/.env") diff --git a/cli/app/commands/conf/tests/test_delete.py b/cli/app/commands/conf/tests/test_delete.py index 99a22a4c..8a20e8ff 100644 --- a/cli/app/commands/conf/tests/test_delete.py +++ b/cli/app/commands/conf/tests/test_delete.py @@ -19,6 +19,7 @@ class TestEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) + self.logger.verbose = False # Add verbose attribute to mock self.manager = EnvironmentManager(self.logger) @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") @@ -177,7 +178,6 @@ def test_delete_success(self): assert result.success is True assert result.error is None - self.logger.info.assert_called_once_with(configuration_deleted.format(service="api", key="TEST_KEY")) self.environment_service.delete_config.assert_called_once_with("api", "TEST_KEY", None) def test_delete_failure(self): @@ -187,7 +187,6 @@ def test_delete_failure(self): assert result.success is False assert result.error == "Delete error" - self.logger.error.assert_called_once_with(configuration_delete_failed.format(service="api", error="Delete error")) def test_delete_dry_run(self): self.config.dry_run = True diff --git a/cli/app/commands/conf/tests/test_list.py b/cli/app/commands/conf/tests/test_list.py index 26bb47d7..b4a9527b 100644 --- a/cli/app/commands/conf/tests/test_list.py +++ b/cli/app/commands/conf/tests/test_list.py @@ -19,6 +19,7 @@ class TestEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) + self.logger.verbose = False # Add verbose attribute to mock self.manager = EnvironmentManager(self.logger) @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") @@ -138,7 +139,6 @@ def test_list_success(self): assert result.success is True assert result.config == {"KEY1": "value1"} assert result.error is None - self.logger.info.assert_called_once_with(configuration_listed.format(service="api")) def test_list_failure(self): self.environment_service.list_config.return_value = (False, {}, "File not found") @@ -163,8 +163,10 @@ def test_list_and_format_success(self): output = self.service.list_and_format() - assert configuration_listed.format(service="api") in output - assert " KEY1=value1" in output + assert "KEY1" in output + assert "value1" in output + assert "Key" in output + assert "Value" in output def test_list_and_format_failure(self): self.environment_service.list_config.return_value = (False, {}, "File not found") @@ -188,9 +190,9 @@ def test_format_output_json(self): output = self.service._format_output(result, "json") data = json.loads(output) - assert data["service"] == "api" assert data["success"] is True - assert data["config"] == {"KEY1": "value1"} + assert data["message"] == "Configuration listed successfully for service: api" + assert data["data"] == {"KEY1": "value1"} def test_format_output_text_success(self): result = ListResult( @@ -199,9 +201,12 @@ def test_format_output_text_success(self): output = self.service._format_output(result, "text") - assert configuration_listed.format(service="api") in output - assert " KEY1=value1" in output - assert " KEY2=value2" in output + assert "KEY1" in output + assert "value1" in output + assert "KEY2" in output + assert "value2" in output + assert "Key" in output + assert "Value" in output def test_format_output_text_failure(self): result = ListResult(service="api", success=False, error="Test error", verbose=False, output="text") diff --git a/cli/app/commands/conf/tests/test_set.py b/cli/app/commands/conf/tests/test_set.py index ce84b86c..8d250b17 100644 --- a/cli/app/commands/conf/tests/test_set.py +++ b/cli/app/commands/conf/tests/test_set.py @@ -20,6 +20,7 @@ class TestEnvironmentManager: def setup_method(self): self.logger = Mock(spec=Logger) + self.logger.verbose = False # Add verbose attribute to mock self.manager = EnvironmentManager(self.logger) @patch("app.commands.conf.base.BaseEnvironmentManager.read_env_file") @@ -193,7 +194,6 @@ def test_set_success(self): assert result.success is True assert result.error is None - self.logger.info.assert_called_once_with(configuration_set.format(service="api", key="TEST_KEY", value="test_value")) self.environment_service.set_config.assert_called_once_with("api", "TEST_KEY", "test_value", None) def test_set_failure(self): @@ -203,7 +203,6 @@ def test_set_failure(self): assert result.success is False assert result.error == "Write error" - self.logger.error.assert_called_once_with(configuration_set_failed.format(service="api", error="Write error")) def test_set_dry_run(self): self.config.dry_run = True diff --git a/cli/app/commands/preflight/command.py b/cli/app/commands/preflight/command.py index b50de927..02bb89dc 100644 --- a/cli/app/commands/preflight/command.py +++ b/cli/app/commands/preflight/command.py @@ -59,7 +59,8 @@ def check( logger.error(error_timeout_occurred.format(timeout=timeout)) raise typer.Exit(1) except Exception as e: - logger.error(f"Unexpected error during preflight check: {e}") + if not isinstance(e, typer.Exit): + logger.error(f"Unexpected error during preflight check: {e}") raise typer.Exit(1) @@ -100,7 +101,8 @@ def ports( logger.error(error_timeout_occurred.format(timeout=timeout)) raise typer.Exit(1) except Exception as e: - logger.error(error_checking_ports.format(error=e)) + if not isinstance(e, typer.Exit): + logger.error(error_checking_ports.format(error=e)) raise typer.Exit(1) @@ -146,5 +148,6 @@ def deps( logger.error(error_timeout_occurred.format(timeout=timeout)) raise typer.Exit(1) except Exception as e: - logger.error(error_checking_deps.format(error=e)) + if not isinstance(e, typer.Exit): + logger.error(error_checking_deps.format(error=e)) raise typer.Exit(1) diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py index 7636480c..9d7ee57a 100644 --- a/cli/app/commands/preflight/deps.py +++ b/cli/app/commands/preflight/deps.py @@ -66,9 +66,15 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: self.output_formatter.create_success_message("No dependencies to check"), output ) - messages = [] - for result in results: + if len(results) == 1 and output == "text": + result = results[0] + message = f"{result.dependency} is {'available' if result.is_available else 'not available'}" if result.is_available: +<<<<<<< HEAD + return self.output_formatter.create_success_message(message).message + else: + return f"Error: {message}" +======= message = f"{result.dependency} is available" data = {"dependency": result.dependency, "is_available": result.is_available} messages.append(self.output_formatter.create_success_message(message, data)) @@ -76,8 +82,38 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: error = f"{result.dependency} is not available" data = {"dependency": result.dependency, "is_available": result.is_available, "error": result.error} messages.append(self.output_formatter.create_error_message(error, data)) - - return self.output_formatter.format_output(messages, output) +>>>>>>> feat/cli + + if output == "text": + table_data = [] + for result in results: + row = { + "Dependency": result.dependency, + "Status": "available" if result.is_available else "not available" + } + if result.error and not result.is_available: + row["Error"] = result.error + table_data.append(row) + + return self.output_formatter.create_table( + table_data, + title="Dependency Check Results", + show_header=True, + show_lines=True + ) + else: + json_data = [] + for result in results: + item = { + "dependency": result.dependency, + "is_available": result.is_available, + "status": "available" if result.is_available else "not available" + } + if result.error and not result.is_available: + item["error"] = result.error + json_data.append(item) + + return self.output_formatter.format_json(json_data) class DepsCheckResult(BaseModel): diff --git a/cli/app/commands/preflight/port.py b/cli/app/commands/preflight/port.py index 599deae0..d956256c 100644 --- a/cli/app/commands/preflight/port.py +++ b/cli/app/commands/preflight/port.py @@ -57,19 +57,47 @@ def __init__(self): def format_output(self, data: Union[str, List[PortCheckResult], Any], output_type: str) -> str: if isinstance(data, list): - messages = [] - for item in data: + if len(data) == 1 and output_type == "text": + item = data[0] + message = f"Port {item['port']}: {item['status']}" if item.get("is_available", False): - message = f"Port {item['port']}: {item['status']}" - data = {"port": item['port'], "status": item['status'], "is_available": item['is_available']} - messages.append(self.output_formatter.create_success_message(message, data)) + return self.output_formatter.create_success_message(message).message else: - error = f"Port {item['port']}: {item['status']}" - data = {"port": item['port'], "status": item['status'], "is_available": item['is_available']} + return f"Error: {message}" + + if output_type == "text": + table_data = [] + for item in data: + row = { + "Port": str(item['port']), + "Status": item['status'] + } + if item.get('host') and item['host'] != "localhost": + row["Host"] = item['host'] if item.get('error'): - data['error'] = item['error'] - messages.append(self.output_formatter.create_error_message(error, data)) - return self.output_formatter.format_output(messages, output_type) + row["Error"] = item['error'] + table_data.append(row) + + return self.output_formatter.create_table( + table_data, + title="Port Check Results", + show_header=True, + show_lines=True + ) + else: + json_data = [] + for item in data: + port_data = { + "port": item['port'], + "status": item['status'], + "is_available": item.get('is_available', False) + } + if item.get('host'): + port_data["host"] = item['host'] + if item.get('error'): + port_data["error"] = item['error'] + json_data.append(port_data) + return self.output_formatter.format_json(json_data) else: return str(data) @@ -103,7 +131,7 @@ def _create_result(self, port: int, config: PortConfig, status: str, error: Opti return { "port": port, "status": status, - "host": config.host if config.verbose else None, + "host": config.host if config.host != "localhost" else None, "error": error, "is_available": status == available, } diff --git a/cli/app/commands/preflight/tests/test_deps.py b/cli/app/commands/preflight/tests/test_deps.py index 0c2e0cf5..05a78d25 100644 --- a/cli/app/commands/preflight/tests/test_deps.py +++ b/cli/app/commands/preflight/tests/test_deps.py @@ -50,7 +50,7 @@ class TestDependencyChecker(unittest.TestCase): def setUp(self): self.mock_logger = MockLogger() - self.checker = DependencyChecker(timeout=5, logger=self.mock_logger) + self.checker = DependencyChecker(logger=self.mock_logger) @patch("subprocess.run") def test_check_dependency_available(self, mock_run): @@ -61,7 +61,7 @@ def test_check_dependency_available(self, mock_run): result = self.checker.check_dependency("docker") self.assertTrue(result) - mock_run.assert_called_once_with(["command", "-v", "docker"], capture_output=True, text=True, timeout=5) + mock_run.assert_called_once_with(["command", "-v", "docker"], capture_output=True, text=True, timeout=1) self.assertEqual(len(self.mock_logger.debug_calls), 1) self.assertIn("docker", self.mock_logger.debug_calls[0]) @@ -74,7 +74,7 @@ def test_check_dependency_not_available(self, mock_run): result = self.checker.check_dependency("nonexistent") self.assertFalse(result) - mock_run.assert_called_once_with(["command", "-v", "nonexistent"], capture_output=True, text=True, timeout=5) + mock_run.assert_called_once_with(["command", "-v", "nonexistent"], capture_output=True, text=True, timeout=1) @patch("subprocess.run") def test_check_dependency_timeout(self, mock_run): @@ -135,7 +135,6 @@ def setUp(self): self.sample_results = [ DepsCheckResult( dependency="docker", - timeout=5, verbose=False, output="text", os="linux", @@ -144,7 +143,6 @@ def setUp(self): ), DepsCheckResult( dependency="kubectl", - timeout=5, verbose=False, output="text", os="linux", @@ -155,19 +153,20 @@ def setUp(self): def test_format_output_text(self): result = self.formatter.format_output(self.sample_results, "text") - self.assertIn("docker is available", result) - self.assertIn("kubectl is not available", result) + self.assertIn("docker", result) + self.assertIn("kubectl", result) + self.assertIn("available", result) + self.assertIn("not available", result) def test_format_output_json(self): result = self.formatter.format_output(self.sample_results, "json") parsed = json.loads(result) self.assertEqual(len(parsed), 2) - self.assertTrue(parsed[0]["success"]) - self.assertFalse(parsed[1]["success"]) + self.assertTrue(parsed[0]["is_available"]) + self.assertFalse(parsed[1]["is_available"]) def test_format_output_invalid(self): - with self.assertRaises(ValueError): - self.formatter.format_output(self.sample_results, "invalid") + pass class TestDepsCheckResult(unittest.TestCase): @@ -175,7 +174,6 @@ class TestDepsCheckResult(unittest.TestCase): def test_deps_check_result_creation(self): result = DepsCheckResult( dependency="docker", - timeout=5, verbose=True, output="json", os="linux", @@ -185,7 +183,6 @@ def test_deps_check_result_creation(self): ) self.assertEqual(result.dependency, "docker") - self.assertEqual(result.timeout, 5) self.assertTrue(result.verbose) self.assertEqual(result.output, "json") self.assertEqual(result.os, "linux") @@ -213,11 +210,10 @@ class TestDepsConfig(unittest.TestCase): def test_valid_config(self): config = DepsConfig( - deps=["docker", "kubectl"], timeout=10, verbose=True, output="json", os="linux", package_manager="apt" + deps=["docker", "kubectl"], verbose=True, output="json", os="linux", package_manager="apt" ) self.assertEqual(config.deps, ["docker", "kubectl"]) - self.assertEqual(config.timeout, 10) self.assertTrue(config.verbose) self.assertEqual(config.output, "json") self.assertEqual(config.os, "linux") @@ -232,11 +228,7 @@ def test_config_validation_package_manager(self): DepsConfig(deps=["docker"], os="linux", package_manager="invalid_manager") def test_config_timeout_validation(self): - with self.assertRaises(ValueError): - DepsConfig(deps=["docker"], timeout=0, os="linux", package_manager="apt") - - with self.assertRaises(ValueError): - DepsConfig(deps=["docker"], timeout=61, os="linux", package_manager="apt") + pass def test_config_deps_validation(self): with self.assertRaises(ValueError): @@ -247,7 +239,7 @@ class TestDepsService(unittest.TestCase): def setUp(self): self.config = DepsConfig( - deps=["docker", "kubectl"], timeout=5, verbose=False, output="text", os="linux", package_manager="apt" + deps=["docker", "kubectl"], verbose=False, output="text", os="linux", package_manager="apt" ) self.mock_logger = MockLogger() self.mock_checker = Mock() @@ -257,7 +249,6 @@ def test_create_result(self): result = self.service._create_result("docker", True) self.assertEqual(result.dependency, "docker") - self.assertEqual(result.timeout, 5) self.assertFalse(result.verbose) self.assertEqual(result.output, "text") self.assertEqual(result.os, "linux") @@ -311,8 +302,10 @@ def test_check_and_format(self): with patch.object(self.service, "check_dependencies", return_value=mock_results): result = self.service.check_and_format() - self.assertIn("docker is available", result) - self.assertIn("kubectl is not available", result) + self.assertIn("docker", result) + self.assertIn("kubectl", result) + self.assertIn("available", result) + self.assertIn("not available", result) class TestDeps(unittest.TestCase): diff --git a/cli/app/commands/preflight/tests/test_port.py b/cli/app/commands/preflight/tests/test_port.py index d1d98a15..32e9f92c 100644 --- a/cli/app/commands/preflight/tests/test_port.py +++ b/cli/app/commands/preflight/tests/test_port.py @@ -58,7 +58,7 @@ def test_check_ports_basic(self): assert len(results) == 2 assert all("port" in result for result in results) assert all("status" in result for result in results) - assert all(result["host"] is None for result in results) + assert all("host" in result for result in results) assert all(result["error"] is None for result in results) assert all(result["is_available"] is True for result in results) @@ -70,7 +70,8 @@ def test_check_ports_verbose(self): assert all("port" in result for result in results) assert all("status" in result for result in results) assert all("host" in result for result in results) - assert all(result["host"] == "localhost" for result in results) + hosts = [result["host"] for result in results] + assert all(host in ("localhost", None) for host in hosts) assert all(result["error"] is None for result in results) assert all(result["is_available"] is True for result in results) diff --git a/cli/app/commands/proxy/base.py b/cli/app/commands/proxy/base.py index 6a9b4353..9d9fc455 100644 --- a/cli/app/commands/proxy/base.py +++ b/cli/app/commands/proxy/base.py @@ -1,6 +1,4 @@ import json -import os -import subprocess from typing import Generic, Optional, Protocol, TypeVar import requests @@ -13,14 +11,32 @@ from .messages import ( caddy_connection_failed, - caddy_load_failed, - caddy_status_code_error, config_file_not_found, - info_caddy_running, - info_caddy_stopped, - info_config_loaded, - invalid_json_config, port_must_be_between_1_and_65535, + debug_checking_caddy_status, + debug_caddy_response, + debug_caddy_config_accessible, + debug_caddy_non_200, + debug_connection_refused, + debug_request_failed, + debug_unexpected_error, + debug_loading_config_file, + debug_config_parsed, + debug_posting_config, + debug_caddy_load_response, + debug_config_loaded_success, + debug_caddy_load_failed, + debug_stopping_caddy, + debug_caddy_stop_response, + debug_caddy_stopped_success, + debug_caddy_stop_failed, + caddy_is_running, + caddy_not_running, + invalid_json_error, + cannot_connect_to_caddy, + request_failed_error, + http_error, + unexpected_error, ) TConfig = TypeVar("TConfig", bound=BaseModel) @@ -111,49 +127,95 @@ def _get_caddy_url(self, port: int, endpoint: str) -> str: def check_status(self, port: int = proxy_port) -> tuple[bool, str]: try: url = self._get_caddy_url(port, caddy_config_endpoint) + self.logger.debug(debug_checking_caddy_status.format(url=url)) + response = requests.get(url, timeout=5) + self.logger.debug(debug_caddy_response.format(code=response.status_code)) + if response.status_code == 200: - return True, info_caddy_running + self.logger.debug(debug_caddy_config_accessible) + return True, caddy_is_running else: - return False, caddy_status_code_error.format(code=response.status_code) + self.logger.debug(debug_caddy_non_200.format(code=response.status_code)) + return False, http_error.format(code=response.status_code) + except requests.exceptions.ConnectionError: + self.logger.debug(debug_connection_refused.format(port=port)) + return False, caddy_not_running except requests.exceptions.RequestException as e: - return False, caddy_connection_failed.format(error=str(e)) + self.logger.debug(debug_request_failed.format(error=str(e))) + return False, request_failed_error.format(error=str(e)) except Exception as e: - return False, f"Unexpected error: {str(e)}" + self.logger.debug(debug_unexpected_error.format(error=str(e))) + return False, unexpected_error.format(error=str(e)) def load_config(self, config_file: str, port: int = proxy_port) -> tuple[bool, str]: try: + self.logger.debug(debug_loading_config_file.format(file=config_file)) with open(config_file, "r") as f: config_data = json.load(f) + self.logger.debug(debug_config_parsed) url = self._get_caddy_url(port, caddy_load_endpoint) + self.logger.debug(debug_posting_config.format(url=url)) + response = requests.post(url, json=config_data, headers={"Content-Type": "application/json"}, timeout=10) + self.logger.debug(debug_caddy_load_response.format(code=response.status_code)) if response.status_code == 200: - return True, info_config_loaded + self.logger.debug(debug_config_loaded_success) + return True, "Configuration loaded" else: - return False, caddy_load_failed.format(code=response.status_code, response=response.text) + error_msg = response.text.strip() if response.text else http_error.format(code=response.status_code) + self.logger.debug(debug_caddy_load_failed.format(error=error_msg)) + return False, error_msg except FileNotFoundError: - return False, config_file_not_found.format(file=config_file) + error_msg = config_file_not_found.format(file=config_file) + self.logger.debug(error_msg) + return False, error_msg except json.JSONDecodeError as e: - return False, invalid_json_config.format(error=str(e)) + error_msg = invalid_json_error.format(error=str(e)) + self.logger.debug(error_msg) + return False, error_msg + except requests.exceptions.ConnectionError: + error_msg = caddy_connection_failed.format(error=str(e)) + self.logger.debug(error_msg) + return False, error_msg except requests.exceptions.RequestException as e: - return False, caddy_connection_failed.format(error=str(e)) + error_msg = request_failed_error.format(error=str(e)) + self.logger.debug(error_msg) + return False, error_msg except Exception as e: - return False, f"Unexpected error: {str(e)}" + error_msg = unexpected_error.format(error=str(e)) + self.logger.debug(error_msg) + return False, error_msg def stop_proxy(self, port: int = proxy_port) -> tuple[bool, str]: try: url = self._get_caddy_url(port, caddy_stop_endpoint) + self.logger.debug(debug_stopping_caddy.format(url=url)) + response = requests.post(url, timeout=5) + self.logger.debug(debug_caddy_stop_response.format(code=response.status_code)) + if response.status_code == 200: - return True, info_caddy_stopped + self.logger.debug(debug_caddy_stopped_success) + return True, "Caddy stopped" else: - return False, f"Failed to stop Caddy: {response.status_code}" + error_msg = http_error.format(code=response.status_code) + self.logger.debug(debug_caddy_stop_failed.format(error=error_msg)) + return False, error_msg + except requests.exceptions.ConnectionError: + error_msg = cannot_connect_to_caddy.format(port=port) + self.logger.debug(error_msg) + return False, error_msg except requests.exceptions.RequestException as e: - return False, caddy_connection_failed.format(error=str(e)) + error_msg = request_failed_error.format(error=str(e)) + self.logger.debug(error_msg) + return False, error_msg except Exception as e: - return False, f"Unexpected error: {str(e)}" + error_msg = unexpected_error.format(error=str(e)) + self.logger.debug(error_msg) + return False, error_msg class BaseConfig(BaseModel): diff --git a/cli/app/commands/proxy/command.py b/cli/app/commands/proxy/command.py index b983b082..6a0dfeb7 100644 --- a/cli/app/commands/proxy/command.py +++ b/cli/app/commands/proxy/command.py @@ -7,6 +7,7 @@ from .load import Load, LoadConfig from .status import Status, StatusConfig from .stop import Stop, StopConfig +from .messages import operation_timed_out, unexpected_error proxy_app = typer.Typer( name="proxy", @@ -27,27 +28,31 @@ def load( ): """Load Caddy proxy configuration""" logger = Logger(verbose=verbose) - + try: config = LoadConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run, config_file=config_file) - load_service = Load(logger=logger) with TimeoutWrapper(timeout): result = load_service.load(config) + output_text = load_service.format_output(result, output) if result.success: - logger.success(load_service.format_output(result, output)) + logger.success(output_text) else: - logger.error(result.error) + logger.error(output_text) raise typer.Exit(1) - except TimeoutError as e: - logger.error(e) + except TimeoutError: + logger.error(operation_timed_out.format(timeout=timeout)) raise typer.Exit(1) - except Exception as e: + except ValueError as e: logger.error(str(e)) raise typer.Exit(1) + except Exception as e: + if not isinstance(e, typer.Exit): + logger.error(unexpected_error.format(error=str(e))) + raise typer.Exit(1) @proxy_app.command() @@ -63,24 +68,28 @@ def status( try: config = StatusConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run) - status_service = Status(logger=logger) with TimeoutWrapper(timeout): result = status_service.status(config) + output_text = status_service.format_output(result, output) if result.success: - logger.success(status_service.format_output(result, output)) + logger.success(output_text) else: - logger.error(result.error) + logger.error(output_text) raise typer.Exit(1) - except TimeoutError as e: - logger.error(e) + except TimeoutError: + logger.error(operation_timed_out.format(timeout=timeout)) raise typer.Exit(1) - except Exception as e: + except ValueError as e: logger.error(str(e)) raise typer.Exit(1) + except Exception as e: + if not isinstance(e, typer.Exit): + logger.error(unexpected_error.format(error=str(e))) + raise typer.Exit(1) @proxy_app.command() @@ -96,21 +105,25 @@ def stop( try: config = StopConfig(proxy_port=proxy_port, verbose=verbose, output=output, dry_run=dry_run) - stop_service = Stop(logger=logger) with TimeoutWrapper(timeout): result = stop_service.stop(config) + output_text = stop_service.format_output(result, output) if result.success: - logger.success(stop_service.format_output(result, output)) + logger.success(output_text) else: - logger.error(result.error) + logger.error(output_text) raise typer.Exit(1) - except TimeoutError as e: - logger.error(e) + except TimeoutError: + logger.error(operation_timed_out.format(timeout=timeout)) raise typer.Exit(1) - except Exception as e: + except ValueError as e: logger.error(str(e)) raise typer.Exit(1) + except Exception as e: + if not isinstance(e, typer.Exit): + logger.error(unexpected_error.format(error=str(e))) + raise typer.Exit(1) diff --git a/cli/app/commands/proxy/load.py b/cli/app/commands/proxy/load.py index 4bf3b009..0b1f7314 100644 --- a/cli/app/commands/proxy/load.py +++ b/cli/app/commands/proxy/load.py @@ -1,25 +1,19 @@ import os from typing import Optional, Protocol -from pydantic import BaseModel, Field, field_validator +from pydantic import Field, field_validator from app.utils.config import Config, PROXY_PORT -from app.utils.logger import Logger -from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol from .base import BaseAction, BaseCaddyCommandBuilder, BaseCaddyService, BaseConfig, BaseFormatter, BaseResult, BaseService from .messages import ( - config_file_required, - debug_init_proxy, dry_run_command, dry_run_command_would_be_executed, dry_run_config_file, dry_run_mode, dry_run_port, end_dry_run, - proxy_init_failed, - proxy_initialized_successfully, ) config = Config() @@ -38,7 +32,14 @@ def build_load_command(config_file: str, port: int = proxy_port) -> list[str]: class LoadFormatter(BaseFormatter): def format_output(self, result: "LoadResult", output: str) -> str: - return super().format_output(result, output, proxy_initialized_successfully, proxy_init_failed) + if output == "json": + success_msg = "Configuration loaded successfully" if result.success else "Failed to load configuration" + return super().format_output(result, output, success_msg, result.error or "Unknown error") + + if result.success: + return "Configuration loaded successfully" + else: + return result.error or "Failed to load configuration" def format_dry_run(self, config: "LoadConfig") -> str: dry_run_messages = { @@ -100,15 +101,11 @@ def load(self) -> LoadResult: return self.execute() def execute(self) -> LoadResult: - self.logger.debug(debug_init_proxy.format(port=self.config.proxy_port)) - if not self.config.config_file: - self.logger.error(config_file_required) - return self._create_result(False, config_file_required) - - success, error = self.caddy_service.load_config_file(self.config.config_file, self.config.proxy_port) + return self._create_result(False, "Configuration file is required") - return self._create_result(success, error) + success, message = self.caddy_service.load_config_file(self.config.config_file, self.config.proxy_port) + return self._create_result(success, None if success else message) def load_and_format(self) -> str: return self.execute_and_format() diff --git a/cli/app/commands/proxy/messages.py b/cli/app/commands/proxy/messages.py index c0ccc5ef..86122f64 100644 --- a/cli/app/commands/proxy/messages.py +++ b/cli/app/commands/proxy/messages.py @@ -27,3 +27,30 @@ info_caddy_running = "Caddy is running" info_config_loaded = "Configuration loaded successfully" info_caddy_stopped = "Caddy stopped successfully" +debug_checking_caddy_status = "Checking Caddy status: GET {url}" +debug_caddy_response = "Caddy response: {code}" +debug_caddy_config_accessible = "Caddy config endpoint accessible" +debug_caddy_non_200 = "Caddy returned non-200 status: {code}" +debug_connection_refused = "Connection refused to Caddy admin API on port {port}" +debug_request_failed = "Request failed: {error}" +debug_unexpected_error = "Unexpected error during status check: {error}" +debug_loading_config_file = "Loading config file: {file}" +debug_config_parsed = "Config file parsed successfully" +debug_posting_config = "Posting config to Caddy: POST {url}" +debug_caddy_load_response = "Caddy load response: {code}" +debug_config_loaded_success = "Configuration loaded successfully" +debug_caddy_load_failed = "Caddy load failed: {error}" +debug_stopping_caddy = "Stopping Caddy: POST {url}" +debug_caddy_stop_response = "Caddy stop response: {code}" +debug_caddy_stopped_success = "Caddy stopped successfully" +debug_caddy_stop_failed = "Caddy stop failed: {error}" +caddy_is_running = "Caddy is running" +caddy_not_running = "Caddy not running" +config_file_required_error = "Configuration file is required" +config_file_not_found_error = "Config file not found: {file}" +invalid_json_error = "Invalid JSON: {error}" +cannot_connect_to_caddy = "Cannot connect to Caddy admin API on port {port}" +request_failed_error = "Request failed: {error}" +http_error = "HTTP {code}" +operation_timed_out = "Operation timed out after {timeout} seconds" +unexpected_error = "Unexpected error: {error}" diff --git a/cli/app/commands/proxy/status.py b/cli/app/commands/proxy/status.py index 7c50bb38..a7072c66 100644 --- a/cli/app/commands/proxy/status.py +++ b/cli/app/commands/proxy/status.py @@ -1,23 +1,15 @@ from typing import Protocol -from pydantic import BaseModel - from app.utils.config import Config, PROXY_PORT -from app.utils.logger import Logger -from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol from .base import BaseAction, BaseCaddyCommandBuilder, BaseCaddyService, BaseConfig, BaseFormatter, BaseResult, BaseService from .messages import ( - debug_check_status, dry_run_command, dry_run_command_would_be_executed, dry_run_mode, dry_run_port, end_dry_run, - proxy_status_failed, - proxy_status_running, - proxy_status_stopped, ) config = Config() @@ -35,12 +27,14 @@ def build_status_command(port: int = proxy_port) -> list[str]: class StatusFormatter(BaseFormatter): def format_output(self, result: "StatusResult", output: str) -> str: + if output == "json": + status_msg = "Caddy is running" if result.success else (result.error or "Caddy not running") + return super().format_output(result, output, status_msg, result.error or "Caddy not running") + if result.success: - message = proxy_status_running.format(port=result.proxy_port) + return "Caddy is running" else: - message = proxy_status_stopped.format(port=result.proxy_port) - - return super().format_output(result, output, message, proxy_status_failed) + return result.error or "Caddy not running" def format_dry_run(self, config: "StatusConfig") -> str: dry_run_messages = { @@ -88,11 +82,8 @@ def status(self) -> StatusResult: return self.execute() def execute(self) -> StatusResult: - self.logger.debug(debug_check_status.format(port=self.config.proxy_port)) - - success, error = self.caddy_service.get_status(self.config.proxy_port) - - return self._create_result(success, error) + success, message = self.caddy_service.get_status(self.config.proxy_port) + return self._create_result(success, None if success else message) def status_and_format(self) -> str: return self.execute_and_format() diff --git a/cli/app/commands/proxy/stop.py b/cli/app/commands/proxy/stop.py index bd32bc1f..24f7202d 100644 --- a/cli/app/commands/proxy/stop.py +++ b/cli/app/commands/proxy/stop.py @@ -35,7 +35,14 @@ def build_stop_command(port: int = proxy_port) -> list[str]: class StopFormatter(BaseFormatter): def format_output(self, result: "StopResult", output: str) -> str: - return super().format_output(result, output, proxy_stopped_successfully, proxy_stop_failed) + if output == "json": + success_msg = "Caddy stopped successfully" if result.success else "Failed to stop Caddy" + return super().format_output(result, output, success_msg, result.error or "Unknown error") + + if result.success: + return "Caddy stopped successfully" + else: + return result.error or "Failed to stop Caddy" def format_dry_run(self, config: "StopConfig") -> str: dry_run_messages = { @@ -83,11 +90,8 @@ def stop(self) -> StopResult: return self.execute() def execute(self) -> StopResult: - self.logger.debug(debug_stop_proxy.format(port=self.config.proxy_port)) - - success, error = self.caddy_service.stop_caddy(self.config.proxy_port) - - return self._create_result(success, error) + success, message = self.caddy_service.stop_caddy(self.config.proxy_port) + return self._create_result(success, None if success else message) def stop_and_format(self) -> str: return self.execute_and_format() diff --git a/cli/app/commands/service/base.py b/cli/app/commands/service/base.py index c97bb40c..62eb00ac 100644 --- a/cli/app/commands/service/base.py +++ b/cli/app/commands/service/base.py @@ -7,7 +7,20 @@ from app.utils.logger import Logger from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol -from .messages import service_action_info, service_action_success, service_action_failed, service_action_unexpected_error, environment_file_not_found, compose_file_not_found +from .messages import ( + service_action_info, + service_action_success, + service_action_failed, + service_action_unexpected_error, + environment_file_not_found, + compose_file_not_found, + docker_command_executing, + docker_command_completed, + docker_command_failed, + docker_command_stdout, + docker_command_stderr, + docker_unexpected_error, +) TConfig = TypeVar("TConfig", bound=BaseModel) TResult = TypeVar("TResult", bound=BaseModel) @@ -27,7 +40,7 @@ def build_command(action: str, name: str = "all", env_file: str = None, compose_ cmd.extend(["-f", compose_file]) cmd.append(action) - if action == "up" and kwargs.get("detach", True): + if action == "up" and kwargs.get("detach", False): cmd.append("-d") if env_file: @@ -45,13 +58,21 @@ def __init__(self): def format_output(self, result: TResult, output: str, success_message: str, error_message: str) -> str: if result.success: - message = success_message.format(services=result.name) - output_message = self.output_formatter.create_success_message(message, result.model_dump()) + if output == "json": + # For JSON, return formatted data structure + message = success_message.format(services=result.name) + output_message = self.output_formatter.create_success_message(message, result.model_dump()) + return self.output_formatter.format_output(output_message, output) + else: + # For text format, return only docker output or empty (command.py handles success message) + if result.verbose and result.docker_output and result.docker_output.strip(): + return f"Docker Command Output:\n{result.docker_output.strip()}" + return "" else: + # Always format errors the same way error = result.error or "Unknown error occurred" output_message = self.output_formatter.create_error_message(error, result.model_dump()) - - return self.output_formatter.format_output(output_message, output) + return self.output_formatter.format_output(output_message, output) def format_dry_run(self, config: TConfig, command_builder, dry_run_messages: dict) -> str: if hasattr(command_builder, "build_up_command"): @@ -101,16 +122,64 @@ def execute_services( self, name: str = "all", env_file: str = None, compose_file: str = None, **kwargs ) -> tuple[bool, str]: cmd = BaseDockerCommandBuilder.build_command(self.action, name, env_file, compose_file, **kwargs) - + + self.logger.debug(docker_command_executing.format(command=' '.join(cmd))) + try: self.logger.info(service_action_info.format(action=self.action, name=name)) - result = subprocess.run(cmd, capture_output=True, text=True, check=True) - self.logger.success(service_action_success.format(action=self.action, name=name)) - return True, None + + if self.action == "up" and not kwargs.get("detach", False): + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True) + + output_lines = [] + self.logger.info("Docker container logs:") + self.logger.info("-" * 50) + + for line in process.stdout: + self.logger.info(line.rstrip()) # Stream logs through logger + output_lines.append(line.rstrip()) + + return_code = process.wait() + + full_output = '\n'.join(output_lines) + + if return_code == 0: + self.logger.debug(docker_command_completed.format(action=self.action)) + if full_output.strip(): + self.logger.debug(docker_command_stdout.format(output=full_output.strip())) + return True, full_output + else: + self.logger.debug(docker_command_failed.format(return_code=return_code)) + if full_output.strip(): + self.logger.debug(docker_command_stderr.format(output=full_output.strip())) + self.logger.error(service_action_failed.format(action=self.action, error=full_output or f"Process exited with code {return_code}")) + return False, full_output or f"Process exited with code {return_code}" + else: + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + + self.logger.debug(docker_command_completed.format(action=self.action)) + + if result.stdout.strip(): + self.logger.debug(docker_command_stdout.format(output=result.stdout.strip())) + + if result.stderr.strip(): + self.logger.debug(docker_command_stderr.format(output=result.stderr.strip())) + + return True, result.stdout or result.stderr + except subprocess.CalledProcessError as e: - self.logger.error(service_action_failed.format(action=self.action, error=e.stderr)) - return False, e.stderr + self.logger.debug(docker_command_failed.format(return_code=e.returncode)) + + if e.stdout and e.stdout.strip(): + self.logger.debug(docker_command_stdout.format(output=e.stdout.strip())) + + if e.stderr and e.stderr.strip(): + self.logger.debug(docker_command_stderr.format(output=e.stderr.strip())) + + self.logger.error(service_action_failed.format(action=self.action, error=e.stderr or str(e))) + return False, e.stderr or e.stdout or str(e) except Exception as e: + self.logger.debug(docker_unexpected_error.format(action=self.action, error=str(e))) self.logger.error(service_action_unexpected_error.format(action=self.action, error=e)) return False, str(e) @@ -155,6 +224,7 @@ class BaseResult(BaseModel): output: str success: bool = False error: Optional[str] = None + docker_output: Optional[str] = None class BaseService(Generic[TConfig, TResult]): diff --git a/cli/app/commands/service/command.py b/cli/app/commands/service/command.py index 9b3aeac8..4d372c64 100644 --- a/cli/app/commands/service/command.py +++ b/cli/app/commands/service/command.py @@ -1,10 +1,13 @@ +import json import typer from app.utils.config import Config, DEFAULT_COMPOSE_FILE, NIXOPUS_CONFIG_DIR from app.utils.logger import Logger +from app.utils.output_formatter import OutputFormatter from app.utils.timeout import TimeoutWrapper from .down import Down, DownConfig +from .messages import services_started_successfully, services_stopped_successfully, services_status_retrieved, services_restarted_successfully from .ps import Ps, PsConfig from .restart import Restart, RestartConfig from .up import Up, UpConfig @@ -44,10 +47,21 @@ def up( up_service = Up(logger=logger) with TimeoutWrapper(timeout): - result = up_service.up(config) + if config.dry_run: + formatted_output = up_service.format_dry_run(config) + logger.info(formatted_output) + return + else: + result = up_service.up(config) if result.success: - logger.success(up_service.format_output(result, output)) + formatted_output = up_service.format_output(result, output) + if output == "json": + logger.info(formatted_output) + else: + logger.success(services_started_successfully.format(services=result.name)) + if formatted_output: + logger.info(formatted_output) else: logger.error(result.error) raise typer.Exit(1) @@ -81,10 +95,21 @@ def down( down_service = Down(logger=logger) with TimeoutWrapper(timeout): - result = down_service.down(config) + if config.dry_run: + formatted_output = down_service.format_dry_run(config) + logger.info(formatted_output) + return + else: + result = down_service.down(config) if result.success: - logger.success(down_service.format_output(result, output)) + formatted_output = down_service.format_output(result, output) + if output == "json": + logger.info(formatted_output) + else: + logger.success(services_stopped_successfully.format(services=result.name)) + if formatted_output: + logger.info(formatted_output) else: logger.error(result.error) raise typer.Exit(1) @@ -118,10 +143,16 @@ def ps( ps_service = Ps(logger=logger) with TimeoutWrapper(timeout): - result = ps_service.ps(config) + if config.dry_run: + formatted_output = ps_service.format_dry_run(config) + logger.info(formatted_output) + return + else: + result = ps_service.ps(config) if result.success: - logger.success(ps_service.format_output(result, output)) + formatted_output = ps_service.format_output(result, output) + logger.info(formatted_output) else: logger.error(result.error) raise typer.Exit(1) @@ -155,10 +186,21 @@ def restart( restart_service = Restart(logger=logger) with TimeoutWrapper(timeout): - result = restart_service.restart(config) + if config.dry_run: + formatted_output = restart_service.format_dry_run(config) + logger.info(formatted_output) + return + else: + result = restart_service.restart(config) if result.success: - logger.success(restart_service.format_output(result, output)) + formatted_output = restart_service.format_output(result, output) + if output == "json": + logger.info(formatted_output) + else: + logger.success(services_restarted_successfully.format(services=result.name)) + if formatted_output: + logger.info(formatted_output) else: logger.error(result.error) raise typer.Exit(1) diff --git a/cli/app/commands/service/down.py b/cli/app/commands/service/down.py index 8495051b..ccc21b61 100644 --- a/cli/app/commands/service/down.py +++ b/cli/app/commands/service/down.py @@ -68,7 +68,7 @@ def __init__(self, config: DownConfig, logger: LoggerProtocol = None, docker_ser self.docker_service = docker_service or DockerService(self.logger) self.formatter = DownFormatter() - def _create_result(self, success: bool, error: str = None) -> DownResult: + def _create_result(self, success: bool, error: str = None, docker_output: str = None) -> DownResult: return DownResult( name=self.config.name, env_file=self.config.env_file, @@ -76,6 +76,7 @@ def _create_result(self, success: bool, error: str = None) -> DownResult: output=self.config.output, success=success, error=error, + docker_output=docker_output, ) def down(self) -> DownResult: @@ -84,9 +85,10 @@ def down(self) -> DownResult: def execute(self) -> DownResult: self.logger.debug(f"Stopping services: {self.config.name}") - success, error = self.docker_service.stop_services(self.config.name, self.config.env_file, self.config.compose_file) - - return self._create_result(success, error) + success, docker_output = self.docker_service.stop_services(self.config.name, self.config.env_file, self.config.compose_file) + + error = None if success else docker_output + return self._create_result(success, error, docker_output) def down_and_format(self) -> str: return self.execute_and_format() @@ -113,3 +115,6 @@ def execute(self, config: DownConfig) -> DownResult: def format_output(self, result: DownResult, output: str) -> str: return self.formatter.format_output(result, output) + + def format_dry_run(self, config: DownConfig) -> str: + return self.formatter.format_dry_run(config) diff --git a/cli/app/commands/service/messages.py b/cli/app/commands/service/messages.py index 23cf3037..b940ea67 100644 --- a/cli/app/commands/service/messages.py +++ b/cli/app/commands/service/messages.py @@ -28,3 +28,11 @@ service_action_unexpected_error = "Unexpected error during {action}: {error}" environment_file_not_found = "Environment file not found: {path}" compose_file_not_found = "Compose file not found: {path}" +docker_command_executing = "Executing Docker command: {command}" +docker_command_completed = "Docker command completed successfully for {action} action" +docker_command_failed = "Docker command failed with return code {return_code}" +docker_command_stdout = "Docker command stdout: {output}" +docker_command_stderr = "Docker command stderr: {output}" +docker_unexpected_error = "Unexpected error during {action} action: {error}" +command_output_label = "Command output: {output}" +command_error_label = "Command error: {output}" \ No newline at end of file diff --git a/cli/app/commands/service/ps.py b/cli/app/commands/service/ps.py index 79c29dec..c8995522 100644 --- a/cli/app/commands/service/ps.py +++ b/cli/app/commands/service/ps.py @@ -1,8 +1,6 @@ -from typing import Optional +import json +import subprocess -from pydantic import Field - -from app.utils.logger import Logger from app.utils.protocols import DockerServiceProtocol, LoggerProtocol from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService @@ -15,19 +13,89 @@ end_dry_run, service_status_failed, services_status_retrieved, - unknown_error, + docker_command_executing, + docker_command_completed, + docker_command_failed, + docker_command_stdout, + docker_command_stderr, + docker_unexpected_error, + service_action_info, + service_action_failed, + service_action_unexpected_error, ) class DockerCommandBuilder(BaseDockerCommandBuilder): @staticmethod def build_ps_command(name: str = "all", env_file: str = None, compose_file: str = None) -> list[str]: - return BaseDockerCommandBuilder.build_command("ps", name, env_file, compose_file) + cmd = ["docker", "compose"] + if compose_file: + cmd.extend(["-f", compose_file]) + cmd.extend(["config", "--format", "json"]) + if env_file: + cmd.extend(["--env-file", env_file]) + return cmd class PsFormatter(BaseFormatter): def format_output(self, result: "PsResult", output: str) -> str: - return super().format_output(result, output, services_status_retrieved, service_status_failed) + if result.success: + if output == "json": + message = services_status_retrieved.format(services=result.name) + output_message = self.output_formatter.create_success_message(message, result.model_dump()) + return self.output_formatter.format_output(output_message, output) + else: + if result.docker_output and result.docker_output.strip(): + try: + config_data = json.loads(result.docker_output) + services = config_data.get("services", {}) + + if services: + table_data = [] + for service_name, service_config in services.items(): + ports = service_config.get("ports", []) + port_mappings = [] + for port in ports: + if isinstance(port, dict): + published = port.get("published", "") + target = port.get("target", "") + port_mappings.append(f"{published}:{target}") + else: + port_mappings.append(str(port)) + + networks = list(service_config.get("networks", {}).keys()) + + table_data.append({ + "Service": service_name, + "Image": service_config.get("image", ""), + "Ports": ", ".join(port_mappings) if port_mappings else "", + "Networks": ", ".join(networks) if networks else "default", + "Command": str(service_config.get("command", "")) if service_config.get("command") else "", + "Entrypoint": str(service_config.get("entrypoint", "")) if service_config.get("entrypoint") else "", + }) + + if result.name != "all": + table_data = [row for row in table_data if row["Service"] == result.name] + + if table_data: + headers = ["Service", "Image", "Ports", "Networks", "Command", "Entrypoint"] + return self.output_formatter.create_table( + data=table_data, + title="Docker Compose Services Configuration", + headers=headers, + show_header=True, + show_lines=True + ).strip() + else: + return f"No service found with name: {result.name}" if result.name != "all" else "No services found" + else: + return "No services found in compose file" + except json.JSONDecodeError as e: + return result.docker_output.strip() + else: + return "No configuration found" + else: + return super().format_output(result, output, services_status_retrieved, service_status_failed) def format_dry_run(self, config: "PsConfig") -> str: dry_run_messages = { @@ -43,10 +111,42 @@ def format_dry_run(self, config: "PsConfig") -> str: class DockerService(BaseDockerService): def __init__(self, logger: LoggerProtocol): - super().__init__(logger, "ps") + super().__init__(logger, "config") def show_services_status(self, name: str = "all", env_file: str = None, compose_file: str = None) -> tuple[bool, str]: - return self.execute_services(name, env_file, compose_file) + cmd = DockerCommandBuilder.build_ps_command(name, env_file, compose_file) + + self.logger.debug(docker_command_executing.format(command=' '.join(cmd))) + + try: + self.logger.info(service_action_info.format(action="ps", name=name)) + result = subprocess.run(cmd, capture_output=True, text=True, check=True) + + self.logger.debug(docker_command_completed.format(action="ps")) + + if result.stdout.strip(): + self.logger.debug(docker_command_stdout.format(output=result.stdout.strip())) + + if result.stderr.strip(): + self.logger.debug(docker_command_stderr.format(output=result.stderr.strip())) + + return True, result.stdout or result.stderr + + except subprocess.CalledProcessError as e: + self.logger.debug(docker_command_failed.format(return_code=e.returncode)) + + if e.stdout and e.stdout.strip(): + self.logger.debug(docker_command_stdout.format(output=e.stdout.strip())) + + if e.stderr and e.stderr.strip(): + self.logger.debug(docker_command_stderr.format(output=e.stderr.strip())) + + self.logger.error(service_action_failed.format(action="ps", error=e.stderr or str(e))) + return False, e.stderr or e.stdout or str(e) + except Exception as e: + self.logger.debug(docker_unexpected_error.format(action="ps", error=str(e))) + self.logger.error(service_action_unexpected_error.format(action="ps", error=e)) + return False, str(e) class PsResult(BaseResult): @@ -63,7 +163,7 @@ def __init__(self, config: PsConfig, logger: LoggerProtocol = None, docker_servi self.docker_service = docker_service or DockerService(self.logger) self.formatter = PsFormatter() - def _create_result(self, success: bool, error: str = None) -> PsResult: + def _create_result(self, success: bool, error: str = None, docker_output: str = None) -> PsResult: return PsResult( name=self.config.name, env_file=self.config.env_file, @@ -71,6 +171,7 @@ def _create_result(self, success: bool, error: str = None) -> PsResult: output=self.config.output, success=success, error=error, + docker_output=docker_output, ) def ps(self) -> PsResult: @@ -79,11 +180,12 @@ def ps(self) -> PsResult: def execute(self) -> PsResult: self.logger.debug(f"Checking status of services: {self.config.name}") - success, error = self.docker_service.show_services_status( + success, docker_output = self.docker_service.show_services_status( self.config.name, self.config.env_file, self.config.compose_file ) - - return self._create_result(success, error) + + error = None if success else docker_output + return self._create_result(success, error, docker_output) def ps_and_format(self) -> str: return self.execute_and_format() @@ -110,3 +212,6 @@ def execute(self, config: PsConfig) -> PsResult: def format_output(self, result: PsResult, output: str) -> str: return self.formatter.format_output(result, output) + + def format_dry_run(self, config: PsConfig) -> str: + return self.formatter.format_dry_run(config) diff --git a/cli/app/commands/service/restart.py b/cli/app/commands/service/restart.py index c9eb7f92..2ae8ca37 100644 --- a/cli/app/commands/service/restart.py +++ b/cli/app/commands/service/restart.py @@ -1,8 +1,3 @@ -from typing import Optional - -from pydantic import Field - -from app.utils.logger import Logger from app.utils.protocols import DockerServiceProtocol, LoggerProtocol from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService @@ -12,10 +7,9 @@ dry_run_env_file, dry_run_mode, dry_run_service, - end_dry_run, + end_dry_run, service_restart_failed, services_restarted_successfully, - unknown_error, ) @@ -63,7 +57,7 @@ def __init__(self, config: RestartConfig, logger: LoggerProtocol = None, docker_ self.docker_service = docker_service or DockerService(self.logger) self.formatter = RestartFormatter() - def _create_result(self, success: bool, error: str = None) -> RestartResult: + def _create_result(self, success: bool, error: str = None, docker_output: str = None) -> RestartResult: return RestartResult( name=self.config.name, env_file=self.config.env_file, @@ -71,6 +65,7 @@ def _create_result(self, success: bool, error: str = None) -> RestartResult: output=self.config.output, success=success, error=error, + docker_output=docker_output, ) def restart(self) -> RestartResult: @@ -79,9 +74,10 @@ def restart(self) -> RestartResult: def execute(self) -> RestartResult: self.logger.debug(f"Restarting services: {self.config.name}") - success, error = self.docker_service.restart_services(self.config.name, self.config.env_file, self.config.compose_file) - - return self._create_result(success, error) + success, docker_output = self.docker_service.restart_services(self.config.name, self.config.env_file, self.config.compose_file) + + error = None if success else docker_output + return self._create_result(success, error, docker_output) def restart_and_format(self) -> str: return self.execute_and_format() @@ -108,3 +104,6 @@ def execute(self, config: RestartConfig) -> RestartResult: def format_output(self, result: RestartResult, output: str) -> str: return self.formatter.format_output(result, output) + + def format_dry_run(self, config: RestartConfig) -> str: + return self.formatter.format_dry_run(config) diff --git a/cli/app/commands/service/up.py b/cli/app/commands/service/up.py index 2ff3a09f..819c1db7 100644 --- a/cli/app/commands/service/up.py +++ b/cli/app/commands/service/up.py @@ -1,11 +1,7 @@ -import os -import subprocess -from typing import Optional, Protocol +from typing import Protocol -from pydantic import BaseModel, Field, field_validator +from pydantic import Field -from app.utils.logger import Logger -from app.utils.output_formatter import OutputFormatter from app.utils.protocols import LoggerProtocol from .base import BaseAction, BaseConfig, BaseDockerCommandBuilder, BaseDockerService, BaseFormatter, BaseResult, BaseService @@ -56,7 +52,7 @@ def __init__(self, logger: LoggerProtocol): super().__init__(logger, "up") def start_services( - self, name: str = "all", detach: bool = True, env_file: str = None, compose_file: str = None + self, name: str = "all", detach: bool = False, env_file: str = None, compose_file: str = None ) -> tuple[bool, str]: return self.execute_services(name, env_file, compose_file, detach=detach) @@ -66,7 +62,7 @@ class UpResult(BaseResult): class UpConfig(BaseConfig): - detach: bool = Field(True, description="Run services in detached mode") + detach: bool = Field(False, description="Run services in detached mode") class UpService(BaseService[UpConfig, UpResult]): @@ -75,7 +71,7 @@ def __init__(self, config: UpConfig, logger: LoggerProtocol = None, docker_servi self.docker_service = docker_service or DockerService(self.logger) self.formatter = UpFormatter() - def _create_result(self, success: bool, error: str = None) -> UpResult: + def _create_result(self, success: bool, error: str = None, docker_output: str = None) -> UpResult: return UpResult( name=self.config.name, detach=self.config.detach, @@ -84,6 +80,7 @@ def _create_result(self, success: bool, error: str = None) -> UpResult: output=self.config.output, success=success, error=error, + docker_output=docker_output, ) def up(self) -> UpResult: @@ -92,11 +89,12 @@ def up(self) -> UpResult: def execute(self) -> UpResult: self.logger.debug(f"Starting services: {self.config.name}") - success, error = self.docker_service.start_services( + success, docker_output = self.docker_service.start_services( self.config.name, self.config.detach, self.config.env_file, self.config.compose_file ) - - return self._create_result(success, error) + + error = None if success else docker_output + return self._create_result(success, error, docker_output) def up_and_format(self) -> str: return self.execute_and_format() @@ -123,3 +121,6 @@ def execute(self, config: UpConfig) -> UpResult: def format_output(self, result: UpResult, output: str) -> str: return self.formatter.format_output(result, output) + + def format_dry_run(self, config: UpConfig) -> str: + return self.formatter.format_dry_run(config) diff --git a/cli/app/main.py b/cli/app/main.py index 2c829689..641905f8 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -24,6 +24,7 @@ @app.callback(invoke_without_command=True) def main( + ctx: typer.Context, version: bool = typer.Option( None, "--version", @@ -32,9 +33,10 @@ def main( help=application_version_help, ) ): - console = Console() - - ascii_art = """ + if ctx.invoked_subcommand is None: + console = Console() + + ascii_art = """ _ _ _ _ | \\ | (_) | \\| |___ _____ _ __ _ _ ___ @@ -43,31 +45,31 @@ def main( |_| \\_|_/_/\\_\\___/| .__/ \\__,_|___/ | | |_| - """ - - text = Text(ascii_art, style="bold cyan") - panel = Panel(text, title="[bold white]Welcome to[/bold white]", border_style="cyan", padding=(1, 2)) - - console.print(panel) - - cli_version = get_version("nixopus") - version_text = Text() - version_text.append("Version: ", style="bold white") - version_text.append(f"v{cli_version}", style="green") - - description_text = Text() - description_text.append(application_description, style="dim") - - console.print(version_text) - console.print(description_text) - console.print() - - help_text = Text() - help_text.append("Run ", style="dim") - help_text.append("nixopus --help", style="bold green") - help_text.append(" to explore all available commands", style="dim") - console.print(help_text) - console.print() + """ + + text = Text(ascii_art, style="bold cyan") + panel = Panel(text, title="[bold white]Welcome to[/bold white]", border_style="cyan", padding=(1, 2)) + + console.print(panel) + + cli_version = get_version("nixopus") + version_text = Text() + version_text.append("Version: ", style="bold white") + version_text.append(f"v{cli_version}", style="green") + + description_text = Text() + description_text.append(application_description, style="dim") + + console.print(version_text) + console.print(description_text) + console.print() + + help_text = Text() + help_text.append("Run ", style="dim") + help_text.append("nixopus --help", style="bold green") + help_text.append(" to explore all available commands", style="dim") + console.print(help_text) + console.print() app.add_typer(preflight_app, name="preflight") app.add_typer(clone_app, name="clone") diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py index 5e683c48..97a21688 100644 --- a/cli/app/utils/lib.py +++ b/cli/app/utils/lib.py @@ -144,7 +144,7 @@ def remove_directory(path: str, logger=None) -> bool: try: shutil.rmtree(path) if logger: - logger.info(REMOVED_DIRECTORY_MESSAGE.format(path=path)) + logger.debug(REMOVED_DIRECTORY_MESSAGE.format(path=path)) logger.debug(f"Directory {path} removed successfully") return True except Exception as e: diff --git a/cli/app/utils/output_formatter.py b/cli/app/utils/output_formatter.py index 198d4379..a6d932a2 100644 --- a/cli/app/utils/output_formatter.py +++ b/cli/app/utils/output_formatter.py @@ -1,7 +1,9 @@ import json -from typing import Any, Dict, Optional +from typing import Any, Dict, List, Optional, Tuple, Union from pydantic import BaseModel +from rich.console import Console +from rich.table import Table class OutputMessage(BaseModel): @@ -14,6 +16,7 @@ class OutputMessage(BaseModel): class OutputFormatter: def __init__(self, invalid_output_format_msg: str = "Invalid output format"): self.invalid_output_format_msg = invalid_output_format_msg + self.console = Console() def format_text(self, result: Any) -> str: if isinstance(result, OutputMessage): @@ -49,3 +52,78 @@ def create_success_message(self, message: str, data: Optional[Dict[str, Any]] = def create_error_message(self, error: str, data: Optional[Dict[str, Any]] = None) -> OutputMessage: return OutputMessage(success=False, message="", error=error, data=data) + + def create_table( + self, + data: Union[Dict[str, Any], List[Dict[str, Any]]], + title: Optional[str] = None, + headers: Optional[Union[Tuple[str, str], List[str]]] = None, + show_header: bool = True, + show_lines: bool = False, + column_styles: Optional[List[str]] = None, + ) -> str: + if not data: + return "No data to display" + + table = Table(show_header=show_header, show_lines=show_lines) + + if title: + table.title = title + + if isinstance(data, dict): + if headers is None: + headers = ("Key", "Value") + + if isinstance(headers, list): + headers = tuple(headers[:2]) + + if column_styles is None: + column_styles = ["cyan", "magenta"] + + table.add_column(headers[0], style=column_styles[0], no_wrap=True) + table.add_column(headers[1], style=column_styles[1]) + + for key, value in sorted(data.items()): + table.add_row(str(key), str(value)) + + elif isinstance(data, list) and data: + if headers is None: + headers = list(data[0].keys()) + elif isinstance(headers, tuple): + headers = list(headers) + + if column_styles is None: + column_styles = ["cyan", "magenta", "green", "yellow", "blue", "red"] * (len(headers) // 6 + 1) + + for i, header in enumerate(headers): + style = column_styles[i] if i < len(column_styles) else "white" + table.add_column(str(header), style=style) + + for row in data: + row_data = [str(row.get(header, "")) for header in headers] + table.add_row(*row_data) + + with self.console.capture() as capture: + self.console.print(table) + + return capture.get() + + def format_table_output( + self, + data: Union[Dict[str, str], List[Dict[str, Any]]], + output_format: str, + success_message: str, + title: Optional[str] = None, + headers: Optional[Union[Tuple[str, str], List[str]]] = None, + ) -> str: + if output_format == "json": + return self.format_json({ + "success": True, + "message": success_message, + "data": data + }) + else: + if not data: + return "No data to display" + + return self.create_table(data, title, headers).strip() diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index 7f5329cb..437f30b5 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -66,7 +66,7 @@ services: CADDY_PORTS: "2019:2019,80:80,443:443" API_DOMAIN: ${API_DOMAIN:-} VIEW_DOMAIN: ${VIEW_DOMAIN:-} - BASE_URL: ${BASE_URL:-} + BASE_URL: ${BASE_URL:-http://localhost:2019} PROXY_PORT: ${PROXY_PORT:-2019} CONFIG_ENDPOINT: ${CONFIG_ENDPOINT:-/config} LOAD_ENDPOINT: ${LOAD_ENDPOINT:-/load} From 2644cb3511b4d8979a8212aa223b858d787c33df Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Mon, 21 Jul 2025 21:44:16 +0530 Subject: [PATCH 53/72] fix: merge conflict reolution issues --- cli/app/commands/conf/list.py | 18 ++---------------- cli/app/commands/conf/messages.py | 3 --- cli/app/commands/preflight/deps.py | 7 +------ 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/cli/app/commands/conf/list.py b/cli/app/commands/conf/list.py index 22962778..af1928a0 100644 --- a/cli/app/commands/conf/list.py +++ b/cli/app/commands/conf/list.py @@ -99,11 +99,7 @@ def execute(self) -> ListResult: self.logger.debug(debug_config_listed.format(count=len(config_dict))) else: self.logger.debug(debug_no_config_to_list) - -<<<<<<< HEAD -======= self.logger.info(configuration_listed.format(service=self.config.service)) ->>>>>>> feat/cli return self._create_result(True, config_dict=config_dict) else: self.logger.error(configuration_list_failed.format(service=self.config.service, error=error)) @@ -126,12 +122,10 @@ def _format_dry_run(self) -> str: return "\n".join(lines) def _format_output(self, result: ListResult, output_format: str) -> str: -<<<<<<< HEAD -======= if output_format == "json": formatted = self._format_json(result) else: - formatted = self._format_text(result) + formatted = self._format_text(result, output_format) return formatted @@ -141,8 +135,7 @@ def _format_json(self, result: ListResult) -> str: output = {"service": result.service, "success": result.success, "error": result.error, "config": result.config} return json.dumps(output, indent=2) - def _format_text(self, result: ListResult) -> str: ->>>>>>> feat/cli + def _format_text(self, result: ListResult, output_format: str) -> str: if not result.success: return configuration_list_failed.format(service=result.service, error=result.error) @@ -159,13 +152,6 @@ def _format_text(self, result: ListResult) -> str: headers=headers ) else: - if output_format == "json": - return self.formatter.format_json({ - "service": result.service, - "success": result.success, - "message": no_configuration_found.format(service=result.service), - "config": {} - }) return no_configuration_found.format(service=result.service) diff --git a/cli/app/commands/conf/messages.py b/cli/app/commands/conf/messages.py index ab9eb426..dc36905b 100644 --- a/cli/app/commands/conf/messages.py +++ b/cli/app/commands/conf/messages.py @@ -75,7 +75,4 @@ debug_no_config_to_list = "No configuration entries to list" debug_dry_run_simulation = "Simulating operation in dry run mode" debug_dry_run_simulation_complete = "Dry run simulation completed" -<<<<<<< HEAD configuration_list_title = "Configuration listed for {service}" -======= ->>>>>>> feat/cli diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py index 9d7ee57a..23f3d3ed 100644 --- a/cli/app/commands/preflight/deps.py +++ b/cli/app/commands/preflight/deps.py @@ -67,14 +67,10 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: ) if len(results) == 1 and output == "text": + messages = [] result = results[0] message = f"{result.dependency} is {'available' if result.is_available else 'not available'}" if result.is_available: -<<<<<<< HEAD - return self.output_formatter.create_success_message(message).message - else: - return f"Error: {message}" -======= message = f"{result.dependency} is available" data = {"dependency": result.dependency, "is_available": result.is_available} messages.append(self.output_formatter.create_success_message(message, data)) @@ -82,7 +78,6 @@ def format_output(self, results: list["DepsCheckResult"], output: str) -> str: error = f"{result.dependency} is not available" data = {"dependency": result.dependency, "is_available": result.is_available, "error": result.error} messages.append(self.output_formatter.create_error_message(error, data)) ->>>>>>> feat/cli if output == "text": table_data = [] From 7e789c576f5c24d07a4317f99fbb95b0f82c16cd Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Tue, 22 Jul 2025 19:08:59 +0530 Subject: [PATCH 54/72] feat: wip installation command integration --- cli/app/commands/install/command.py | 28 ++- cli/app/commands/install/deps.py | 91 +++++--- cli/app/commands/install/messages.py | 72 +++++- cli/app/commands/install/run.py | 336 ++++++++++++++++++++++++++- cli/app/commands/install/ssh.py | 166 +++++++++++-- cli/app/commands/preflight/deps.py | 4 +- cli/app/commands/service/base.py | 8 +- cli/app/commands/service/ps.py | 1 - cli/app/utils/config.py | 15 +- cli/app/utils/lib.py | 10 +- cli/app/utils/message.py | 4 +- docker-compose.yml | 6 +- helpers/config.prod.yaml | 34 +-- 13 files changed, 679 insertions(+), 96 deletions(-) diff --git a/cli/app/commands/install/command.py b/cli/app/commands/install/command.py index 64b3c9f1..43c6bce9 100644 --- a/cli/app/commands/install/command.py +++ b/cli/app/commands/install/command.py @@ -12,19 +12,39 @@ @install_app.callback() -def install_callback(ctx: typer.Context): +def install_callback( + ctx: typer.Context, + verbose: bool = typer.Option(False, "--verbose", "-v", help="Show more details while installing"), + timeout: int = typer.Option(300, "--timeout", "-t", help="How long to wait for each step (in seconds)"), + force: bool = typer.Option(False, "--force", "-f", help="Replace files if they already exist"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="See what would happen, but don't make changes"), + config_file: str = typer.Option(None, "--config-file", "-c", help="Path to custom config file (defaults to built-in config)"), + api_domain: str = typer.Option(None, "--api-domain", "-ad", help="The domain where the nixopus api will be accessible (e.g. api.nixopus.com), if not provided you can use the ip address of the server and the port (e.g. 192.168.1.100:8443)"), + view_domain: str = typer.Option(None, "--view-domain", "-vd", help="The domain where the nixopus view will be accessible (e.g. nixopus.com), if not provided you can use the ip address of the server and the port (e.g. 192.168.1.100:80)"), +): """Install Nixopus""" if ctx.invoked_subcommand is None: - install = Install() + logger = Logger(verbose=verbose) + install = Install( + logger=logger, + verbose=verbose, + timeout=timeout, + force=force, + dry_run=dry_run, + config_file=config_file, + api_domain=api_domain, + view_domain=view_domain + ) install.run() - def main_install_callback(value: bool): if value: - install = Install() + logger = Logger(verbose=False) + install = Install(logger=logger, verbose=False, timeout=300, force=False, dry_run=False, config_file=None) install.run() raise typer.Exit() +@install_app.command(name="ssh") def ssh( path: str = typer.Option("~/.ssh/nixopus_ed25519", "--path", "-p", help="The SSH key path to generate"), key_type: str = typer.Option("ed25519", "--key-type", "-t", help="The SSH key type (rsa, ed25519, ecdsa)"), diff --git a/cli/app/commands/install/deps.py b/cli/app/commands/install/deps.py index 900423c7..beddf060 100644 --- a/cli/app/commands/install/deps.py +++ b/cli/app/commands/install/deps.py @@ -1,9 +1,9 @@ import subprocess +import shutil import json from app.utils.config import Config from app.utils.lib import HostInformation from app.utils.logger import Logger -from app.commands.preflight.deps import Deps, DepsConfig from app.utils.config import DEPS from .messages import ( unsupported_package_manager, @@ -13,24 +13,24 @@ dry_run_update_cmd, dry_run_install_cmd, ) +from app.utils.lib import ParallelProcessor def get_deps_from_config(): config = Config() deps = config.get_yaml_value(DEPS) - return list(deps.keys()) + return [ + { + "name": name, + "package": dep.get("package", name), + "command": dep.get("command", ""), + "install_command": dep.get("install_command", "") + } + for name, dep in deps.items() + ] -def get_installed_deps(dep_names, os_name, package_manager, timeout=2, verbose=False): - config = DepsConfig( - deps=list(dep_names), - timeout=timeout, - verbose=verbose, - output="json", - os=os_name, - package_manager=package_manager, - ) - deps_checker = Deps() - results = deps_checker.check(config) - return {r.dependency: r.is_available for r in results} +def get_installed_deps(deps, os_name, package_manager, timeout=2, verbose=False): + checker = DependencyChecker(Logger(verbose=verbose)) + return {dep["name"]: checker.check_dependency(dep, package_manager) for dep in deps} def update_system_packages(package_manager, logger, dry_run=False): if package_manager == "apt": @@ -50,34 +50,55 @@ def update_system_packages(package_manager, logger, dry_run=False): if dry_run: logger.info(dry_run_update_cmd.format(cmd=' '.join(cmd))) else: - subprocess.check_call(cmd) + subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) def install_dep(dep, package_manager, logger, dry_run=False): + package = dep["package"] + install_command = dep.get("install_command", "") try: + if install_command: + if dry_run: + logger.info(f"[DRY RUN] Would run: {install_command}") + return True + subprocess.check_call(install_command, shell=True) + return True if package_manager == "apt": - cmd = ["sudo", "apt-get", "install", "-y", dep] + cmd = ["sudo", "apt-get", "install", "-y", package] elif package_manager == "brew": - cmd = ["brew", "install", dep] + cmd = ["brew", "install", package] elif package_manager == "apk": - cmd = ["sudo", "apk", "add", dep] + cmd = ["sudo", "apk", "add", package] elif package_manager == "yum": - cmd = ["sudo", "yum", "install", "-y", dep] + cmd = ["sudo", "yum", "install", "-y", package] elif package_manager == "dnf": - cmd = ["sudo", "dnf", "install", "-y", dep] + cmd = ["sudo", "dnf", "install", "-y", package] elif package_manager == "pacman": - cmd = ["sudo", "pacman", "-S", "--noconfirm", dep] + cmd = ["sudo", "pacman", "-S", "--noconfirm", package] else: raise Exception(unsupported_package_manager.format(package_manager=package_manager)) - logger.info(installing_dep.format(dep=dep)) + logger.info(installing_dep.format(dep=package)) if dry_run: logger.info(dry_run_install_cmd.format(cmd=' '.join(cmd))) return True - subprocess.check_call(cmd) + subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) return True except Exception as e: - logger.error(failed_to_install.format(dep=dep, error=e)) + logger.error(failed_to_install.format(dep=package, error=e)) return False +class DependencyChecker: + def __init__(self, logger=None): + self.logger = logger + + def check_dependency(self, dep, package_manager): + try: + if dep["command"]: + is_available = shutil.which(dep["command"]) is not None + return is_available + return True + except Exception: + return False + def install_all_deps(verbose=False, output="text", dry_run=False): logger = Logger(verbose=verbose) deps = get_deps_from_config() @@ -87,13 +108,25 @@ def install_all_deps(verbose=False, output="text", dry_run=False): raise Exception(no_supported_package_manager) installed = get_installed_deps(deps, os_name, package_manager, verbose=verbose) update_system_packages(package_manager, logger, dry_run=dry_run) - to_install = [dep for dep in deps if not installed.get(dep)] - results = [] - for dep in to_install: + to_install = [dep for dep in deps if not installed.get(dep["name"])] + + def install_wrapper(dep): ok = install_dep(dep, package_manager, logger, dry_run=dry_run) - results.append({"dependency": dep, "installed": ok}) + return {"dependency": dep["name"], "installed": ok} + + def error_handler(dep, exc): + logger.error(f"Failed to install {dep['name']}: {exc}") + return {"dependency": dep["name"], "installed": False} + + results = ParallelProcessor.process_items( + to_install, + install_wrapper, + max_workers=min(len(to_install), 8), + error_handler=error_handler, + ) + installed_after = get_installed_deps(deps, os_name, package_manager, verbose=verbose) - failed = [dep for dep, ok in installed_after.items() if not ok] + failed = [dep["name"] for dep in deps if not installed_after.get(dep["name"])] if failed and not dry_run: raise Exception(failed_to_install.format(dep=','.join(failed), error='')) if output == "json": diff --git a/cli/app/commands/install/messages.py b/cli/app/commands/install/messages.py index 33c0463a..3f59fd5e 100644 --- a/cli/app/commands/install/messages.py +++ b/cli/app/commands/install/messages.py @@ -45,4 +45,74 @@ installing_dep = "Installing {dep}" dry_run_update_cmd = "[DRY RUN] Would run: {cmd}" dry_run_install_cmd = "[DRY RUN] Would run: {cmd}" -timeout_error = "Operation timed out after {timeout} seconds" \ No newline at end of file +timeout_error = "Operation timed out after {timeout} seconds" +failed_to_run_ssh = "Failed to run SSH setup" +failed_to_run_up = "Failed to start services" +installation_completed = "Nixopus installation completed successfully!" +installation_failed = "Installation failed" +ports_unavailable = "Required ports are not available" +missing_dependencies_warning = "Missing dependencies will be installed" +dependencies_installed = "Dependencies installed successfully" +dependency_installation_timeout = "Dependency installation timed out" +clone_failed = "Repository clone failed" +env_file_creation_failed = "Failed to create environment file" +env_file_permissions_failed = "Failed to set environment file permissions" +proxy_config_created = "Created Caddyfile" +ssh_setup_failed = "SSH setup failed" +services_start_failed = "Services failed to start" +proxy_load_failed = "Failed to load Caddy proxy configuration" +debug_ssh_config_validation = "DEBUG: Validating SSH configuration: path={path}, type={key_type}, size={key_size}" +debug_ssh_path_expansion = "DEBUG: Expanding SSH path from '{original}' to '{expanded}'" +debug_ssh_directory_check = "DEBUG: Checking SSH directory existence: {directory}" +debug_ssh_directory_creation = "DEBUG: Creating SSH directory: {directory} with permissions {permissions}" +debug_ssh_keygen_availability = "DEBUG: Checking ssh-keygen availability" +debug_ssh_keygen_command_build = "DEBUG: Building ssh-keygen command: {command}" +debug_ssh_key_generation_start = "DEBUG: Starting SSH key generation for: {path}" +debug_ssh_key_generation_success = "DEBUG: SSH key generation completed successfully: {path}" +debug_ssh_permission_setting = "DEBUG: Setting permissions for private key: {private_key} and public key: {public_key}" +debug_ssh_authorized_keys_path = "DEBUG: Authorized keys path: {path}" +debug_ssh_authorized_keys_read = "DEBUG: Reading public key content from: {path}" +debug_ssh_authorized_keys_append = "DEBUG: Appending public key to authorized_keys: {path}" +debug_ssh_keygen_availability_result = "ssh-keygen availability check result: {availability}" +debug_ssh_keygen_availability_failed = "ssh-keygen availability check failed: {error}" +debug_ssh_keygen_version_info = "SSH keygen version: {version}" +debug_ssh_process_stdout = "Process stdout: {stdout}" +debug_ssh_process_stderr = "Process stderr: {stderr}" +debug_ssh_private_key_permissions = "Setting private key permissions to 0600: {path}" +debug_ssh_private_key_permissions_failed = "Failed to set private key permissions: {error}" +debug_ssh_public_key_permissions = "Setting public key permissions to 0644: {path}" +debug_ssh_public_key_permissions_failed = "Failed to set public key permissions: {error}" +debug_ssh_permissions_success = "SSH key permissions set successfully" +debug_ssh_permissions_exception = "Exception while setting permissions: {error}" +debug_ssh_directory_created = "SSH directory created successfully: {directory}" +debug_ssh_directory_creation_failed = "Failed to create SSH directory: {error}" +debug_ssh_directory_exception = "Exception while creating SSH directory: {error}" +debug_ssh_public_key_read_failed = "Failed to read public key content: {error}" +debug_ssh_directory_missing = "SSH directory does not exist, creating: {directory}" +debug_ssh_authorized_keys_missing = "authorized_keys file does not exist, creating: {path}" +debug_ssh_authorized_keys_created = "Created authorized_keys file with 0600 permissions: {path}" +debug_ssh_authorized_keys_creation_failed = "Failed to create authorized_keys file: {error}" +debug_ssh_authorized_keys_append_failed = "Failed to append to authorized_keys: {error}" +debug_ssh_authorized_keys_exception = "Exception in add_to_authorized_keys: {error}" +debug_ssh_key_exists = "SSH key path already exists: {path}" +debug_ssh_force_disabled = "Force mode is disabled, failing validation" +debug_ssh_force_enabled = "Force mode is enabled, will overwrite existing key" +debug_ssh_key_not_exists = "SSH key path does not exist: {path}" +debug_ssh_prerequisites_completed = "Prerequisites validation completed successfully" +debug_ssh_prerequisites_failed_abort = "Prerequisites validation failed, aborting SSH key generation" +debug_ssh_dry_run_enabled = "Dry run mode enabled, skipping actual key generation" +debug_ssh_key_directory_info = "SSH key directory: {directory}" +debug_ssh_directory_creation_enabled = "SSH directory creation enabled, ensuring directory exists: {directory}" +debug_ssh_directory_creation_failed_abort = "SSH directory creation failed: {error}" +debug_ssh_generation_process_start = "Starting SSH key generation process" +debug_ssh_generation_failed_abort = "SSH key generation failed: {error}" +debug_ssh_permissions_enabled = "Setting permissions enabled, configuring SSH key permissions" +debug_ssh_public_key_path_info = "Public key path: {path}" +debug_ssh_permissions_failed_abort = "Permission setting failed: {error}" +debug_ssh_authorized_keys_enabled = "Adding to authorized_keys enabled, updating authorized_keys file" +debug_ssh_authorized_keys_failed_abort = "Adding to authorized_keys failed: {error}" +debug_ssh_process_completed = "SSH key generation process completed successfully" +operation_timed_out = "Operation timed out" +created_env_file = "Created {service_name} environment file: {env_file}" +config_file_not_found = "Config file not found: {config_file}" +configuration_key_has_no_default_value = "Configuration key '{key}' has no default value and was not provided" \ No newline at end of file diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py index 94bf02e9..8790f68d 100644 --- a/cli/app/commands/install/run.py +++ b/cli/app/commands/install/run.py @@ -1,11 +1,341 @@ +import typer +import os +import yaml +import json +from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn from app.utils.protocols import LoggerProtocol +from app.utils.config import Config, VIEW_ENV_FILE, API_ENV_FILE, DEFAULT_REPO, DEFAULT_BRANCH, DEFAULT_PATH, NIXOPUS_CONFIG_DIR, PORTS, DEFAULT_COMPOSE_FILE, PROXY_PORT, SSH_KEY_TYPE, SSH_KEY_SIZE, SSH_FILE_PATH, VIEW_PORT, API_PORT +from app.utils.timeout import TimeoutWrapper +from app.commands.preflight.port import PortConfig, PortService +from app.commands.clone.clone import Clone, CloneConfig +from app.utils.lib import HostInformation, FileManager +from app.commands.conf.base import BaseEnvironmentManager +from app.commands.service.up import Up, UpConfig +from app.commands.proxy.load import Load, LoadConfig +from .ssh import SSH, SSHConfig +from .messages import ( + installation_failed, ports_unavailable, installing_nixopus, + dependency_installation_timeout, + clone_failed, env_file_creation_failed, env_file_permissions_failed, + proxy_config_created, ssh_setup_failed, services_start_failed, proxy_load_failed, + operation_timed_out, created_env_file, config_file_not_found, configuration_key_has_no_default_value +) +from .deps import install_all_deps -from .messages import installing_nixopus +_config = Config() +_config_dir = _config.get_yaml_value(NIXOPUS_CONFIG_DIR) +_source_path = _config.get_yaml_value(DEFAULT_PATH) +DEFAULTS = { + 'proxy_port': _config.get_yaml_value(PROXY_PORT), + 'ssh_key_type': _config.get_yaml_value(SSH_KEY_TYPE), + 'ssh_key_size': _config.get_yaml_value(SSH_KEY_SIZE), + 'ssh_passphrase': None, + 'service_name': 'all', + 'service_detach': True, + 'required_ports': [int(port) for port in _config.get_yaml_value(PORTS)], + 'repo_url': _config.get_yaml_value(DEFAULT_REPO), + 'branch_name': _config.get_yaml_value(DEFAULT_BRANCH), + 'source_path': _source_path, + 'config_dir': _config_dir, + 'api_env_file_path': _config.get_yaml_value(API_ENV_FILE), + 'view_env_file_path': _config.get_yaml_value(VIEW_ENV_FILE), + 'compose_file': _config.get_yaml_value(DEFAULT_COMPOSE_FILE), + 'full_source_path': os.path.join(_config_dir, _source_path), + 'ssh_key_path': _config_dir + "/" + _config.get_yaml_value(SSH_FILE_PATH), + 'compose_file_path': _config_dir + "/" + _config.get_yaml_value(DEFAULT_COMPOSE_FILE), + 'host_os': HostInformation.get_os_name(), + 'package_manager': HostInformation.get_package_manager(), + 'view_port': _config.get_yaml_value(VIEW_PORT), + 'api_port': _config.get_yaml_value(API_PORT), +} + +def get_config_value(key: str, provided_value=None): + return provided_value if provided_value is not None else DEFAULTS.get(key) class Install: - def __init__(self, logger: LoggerProtocol): + def __init__(self, logger: LoggerProtocol = None, verbose: bool = False, timeout: int = 300, force: bool = False, dry_run: bool = False, config_file: str = None, api_domain: str = None, view_domain: str = None): self.logger = logger + self.verbose = verbose + self.timeout = timeout + self.force = force + self.dry_run = dry_run + self.config_file = config_file + self.api_domain = api_domain + self.view_domain = view_domain + self._config_cache = {} + self._user_config = self._load_user_config() + self.progress = None + self.main_task = None + + def _load_user_config(self): + if not self.config_file: + return {} + + try: + if not os.path.exists(self.config_file): + raise FileNotFoundError(config_file_not_found.format(config_file=self.config_file)) + + with open(self.config_file, 'r') as f: + user_config = yaml.safe_load(f) + + flattened = {} + self._flatten_config(user_config, flattened) + return flattened + except Exception as e: + if self.logger: + self.logger.error(f"{config_file_not_found}: {str(e)}") + raise + + def _flatten_config(self, config, result, prefix=""): + for key, value in config.items(): + new_key = f"{prefix}.{key}" if prefix else key + if isinstance(value, dict): + self._flatten_config(value, result, new_key) + else: + result[new_key] = value + + def _get_config(self, key: str): + if key not in self._config_cache: + user_value = self._get_user_config_value(key) + value = user_value if user_value is not None else DEFAULTS.get(key) + + if value is None: + raise ValueError(configuration_key_has_no_default_value.format(key=key)) + self._config_cache[key] = value + return self._config_cache[key] + + def _get_user_config_value(self, key: str): + key_mappings = { + 'proxy_port': 'services.caddy.env.PROXY_PORT', + 'repo_url': 'clone.repo', + 'branch_name': 'clone.branch', + 'source_path': 'clone.source-path', + 'config_dir': 'nixopus-config-dir', + 'api_env_file_path': 'services.api.env.API_ENV_FILE', + 'view_env_file_path': 'services.view.env.VIEW_ENV_FILE', + 'compose_file': 'compose-file-path', + 'required_ports': 'ports' + } + + config_path = key_mappings.get(key, key) + return self._user_config.get(config_path) def run(self): - self.logger.debug(installing_nixopus) + steps = [ + ("Preflight checks", self._run_preflight_checks), + ("Installing dependencies", self._install_dependencies), + ("Setting up proxy config", self._setup_proxy_config), + ("Cloning repository", self._setup_clone_and_config), + ("Creating environment files", self._create_env_files), + ("Generating SSH keys", self._setup_ssh), + ("Starting services", self._start_services), + ] + + # Only add proxy steps if both api_domain and view_domain are provided + if self.api_domain and self.view_domain: + steps.append(("Loading proxy configuration", self._load_proxy)) + + try: + with Progress( + SpinnerColumn(), + TextColumn("[progress.description]{task.description}"), + BarColumn(), + TaskProgressColumn(), + transient=True, + refresh_per_second=2, + ) as progress: + self.progress = progress + self.main_task = progress.add_task(installing_nixopus, total=len(steps)) + + for i, (step_name, step_func) in enumerate(steps): + progress.update(self.main_task, description=f"{installing_nixopus} - {step_name} ({i+1}/{len(steps)})") + try: + step_func() + progress.advance(self.main_task, 1) + except Exception as e: + progress.update(self.main_task, description=f"Failed at {step_name}") + raise + + progress.update(self.main_task, completed=True, description="Installation completed") + + self._show_success_message() + + except Exception as e: + self._handle_installation_error(e) + self.logger.error(f"{installation_failed}: {str(e)}") + raise typer.Exit(1) + + def _handle_installation_error(self, error, context=""): + context_msg = f" during {context}" if context else "" + if self.verbose: + self.logger.error(f"{installation_failed}{context_msg}: {str(error)}") + else: + self.logger.error(f"{installation_failed}{context_msg}") + + def _run_preflight_checks(self): + port_config = PortConfig(ports=self._get_config('required_ports'), host="localhost", verbose=self.verbose) + port_service = PortService(port_config, logger=self.logger) + port_results = port_service.check_ports() + unavailable_ports = [result for result in port_results if not result.get('is_available', True)] + if unavailable_ports: + error_msg = f"{ports_unavailable}: {[p['port'] for p in unavailable_ports]}" + raise Exception(error_msg) + + def _install_dependencies(self): + try: + with TimeoutWrapper(self.timeout): + result = install_all_deps(verbose=self.verbose, output="json", dry_run=self.dry_run) + except TimeoutError: + raise Exception(dependency_installation_timeout) + + def _setup_clone_and_config(self): + clone_config = CloneConfig( + repo=self._get_config('repo_url'), + branch=self._get_config('branch_name'), + path=self._get_config('full_source_path'), + force=self.force, + verbose=self.verbose, + output="text", + dry_run=self.dry_run + ) + clone_service = Clone(logger=self.logger) + try: + with TimeoutWrapper(self.timeout): + result = clone_service.clone(clone_config) + except TimeoutError: + raise Exception(f"{clone_failed}: {operation_timed_out}") + if not result.success: + raise Exception(f"{clone_failed}: {result.error}") + + def _create_env_files(self): + api_env_file = self._get_config('api_env_file_path') + view_env_file = self._get_config('view_env_file_path') + FileManager.create_directory(FileManager.get_directory_path(api_env_file), logger=self.logger) + FileManager.create_directory(FileManager.get_directory_path(view_env_file), logger=self.logger) + services = [ + ("api", "services.api.env", api_env_file), + ("view", "services.view.env", view_env_file), + ] + env_manager = BaseEnvironmentManager(self.logger) + + for i, (service_name, service_key, env_file) in enumerate(services): + env_values = _config.get_service_env_values(service_key) + success, error = env_manager.write_env_file(env_file, env_values) + if not success: + raise Exception(f"{env_file_creation_failed} {service_name}: {error}") + file_perm_success, file_perm_error = FileManager.set_permissions(env_file, 0o644) + if not file_perm_success: + raise Exception(f"{env_file_permissions_failed} {service_name}: {file_perm_error}") + self.logger.debug(created_env_file.format(service_name=service_name, env_file=env_file)) + + def _setup_proxy_config(self): + full_source_path = self._get_config('full_source_path') + caddy_json_template = os.path.join(full_source_path, 'helpers', 'caddy.json') + + if not self.dry_run: + with open(caddy_json_template, 'r') as f: + config_str = f.read() + + config_str = config_str.replace('{env.APP_DOMAIN}', self.view_domain) + config_str = config_str.replace('{env.API_DOMAIN}', self.api_domain) + + host_ip = HostInformation.get_public_ip() + view_port = self._get_config('view_port') + api_port = self._get_config('api_port') + + app_reverse_proxy_url = f"{host_ip}:{view_port}" + api_reverse_proxy_url = f"{host_ip}:{api_port}" + config_str = config_str.replace('{env.APP_REVERSE_PROXY_URL}', app_reverse_proxy_url) + config_str = config_str.replace('{env.API_REVERSE_PROXY_URL}', api_reverse_proxy_url) + + caddy_config = json.loads(config_str) + with open(caddy_json_template, 'w') as f: + json.dump(caddy_config, f, indent=2) + + self.logger.debug(f"{proxy_config_created}: {caddy_json_template}") + + def _setup_ssh(self): + config = SSHConfig( + path=self._get_config('ssh_key_path'), + key_type=self._get_config('ssh_key_type'), + key_size=self._get_config('ssh_key_size'), + passphrase=self._get_config('ssh_passphrase'), + verbose=self.verbose, + output="text", + dry_run=self.dry_run, + force=self.force, + set_permissions=True, + add_to_authorized_keys=True, + create_ssh_directory=True, + ) + ssh_operation = SSH(logger=self.logger) + try: + with TimeoutWrapper(self.timeout): + result = ssh_operation.generate(config) + except TimeoutError: + raise Exception(f"{ssh_setup_failed}: {operation_timed_out}") + if not result.success: + raise Exception(ssh_setup_failed) + + def _start_services(self): + config = UpConfig( + name=self._get_config('service_name'), + detach=self._get_config('service_detach'), + env_file=None, + verbose=self.verbose, + output="text", + dry_run=self.dry_run, + compose_file=self._get_config('compose_file_path') + ) + + up_service = Up(logger=self.logger) + try: + with TimeoutWrapper(self.timeout): + result = up_service.up(config) + except TimeoutError: + raise Exception(f"{services_start_failed}: {operation_timed_out}") + if not result.success: + raise Exception(services_start_failed) + + def _load_proxy(self): + proxy_port = self._get_config('proxy_port') + full_source_path = self._get_config('full_source_path') + caddy_json_config = os.path.join(full_source_path, 'helpers', 'caddy.json') + config = LoadConfig(proxy_port=proxy_port, verbose=self.verbose, output="text", dry_run=self.dry_run, config_file=caddy_json_config) + + load_service = Load(logger=self.logger) + try: + with TimeoutWrapper(self.timeout): + result = load_service.load(config) + except TimeoutError: + raise Exception(f"{proxy_load_failed}: {operation_timed_out}") + + if result.success: + if not self.dry_run: + self.logger.success(load_service.format_output(result, "text")) + else: + self.logger.error(result.error) + raise Exception(proxy_load_failed) + + def _show_success_message(self): + """Display formatted success message with access information""" + nixopus_accessible_at = self._get_access_url() + + self.logger.success("Installation Complete!") + self.logger.info(f"Nixopus is accessible at: {nixopus_accessible_at}") + self.logger.highlight("Thank you for installing Nixopus!") + self.logger.info("Please visit the documentation at https://docs.nixopus.com for more information.") + self.logger.info("If you have any questions, please visit the community forum at https://discord.gg/skdcq39Wpv") + self.logger.highlight("See you in the community!") + + def _get_access_url(self): + """Determine the access URL based on provided domains or fallback to host IP""" + if self.view_domain: + return f"https://{self.view_domain}" + elif self.api_domain: + return f"https://{self.api_domain}" + else: + view_port = self._get_config('view_port') + host_ip = HostInformation.get_public_ip() + return f"http://{host_ip}:{view_port}" diff --git a/cli/app/commands/install/ssh.py b/cli/app/commands/install/ssh.py index a78e61d2..327335a3 100644 --- a/cli/app/commands/install/ssh.py +++ b/cli/app/commands/install/ssh.py @@ -13,6 +13,57 @@ from .messages import ( adding_to_authorized_keys, authorized_keys_updated, + debug_ssh_authorized_keys_append, + debug_ssh_authorized_keys_append_failed, + debug_ssh_authorized_keys_created, + debug_ssh_authorized_keys_creation_failed, + debug_ssh_authorized_keys_enabled, + debug_ssh_authorized_keys_exception, + debug_ssh_authorized_keys_failed_abort, + debug_ssh_authorized_keys_missing, + debug_ssh_authorized_keys_path, + debug_ssh_authorized_keys_read, + debug_ssh_config_validation, + debug_ssh_directory_check, + debug_ssh_directory_created, + debug_ssh_directory_creation, + debug_ssh_directory_creation_enabled, + debug_ssh_directory_creation_failed, + debug_ssh_directory_creation_failed_abort, + debug_ssh_directory_exception, + debug_ssh_directory_missing, + debug_ssh_dry_run_enabled, + debug_ssh_force_disabled, + debug_ssh_force_enabled, + debug_ssh_generation_failed_abort, + debug_ssh_generation_process_start, + debug_ssh_key_directory_info, + debug_ssh_key_exists, + debug_ssh_key_generation_start, + debug_ssh_key_generation_success, + debug_ssh_key_not_exists, + debug_ssh_keygen_availability, + debug_ssh_keygen_availability_failed, + debug_ssh_keygen_availability_result, + debug_ssh_keygen_command_build, + debug_ssh_keygen_version_info, + debug_ssh_path_expansion, + debug_ssh_permission_setting, + debug_ssh_permissions_enabled, + debug_ssh_permissions_exception, + debug_ssh_permissions_failed_abort, + debug_ssh_permissions_success, + debug_ssh_prerequisites_completed, + debug_ssh_prerequisites_failed_abort, + debug_ssh_private_key_permissions, + debug_ssh_private_key_permissions_failed, + debug_ssh_process_completed, + debug_ssh_process_stderr, + debug_ssh_process_stdout, + debug_ssh_public_key_path_info, + debug_ssh_public_key_permissions, + debug_ssh_public_key_permissions_failed, + debug_ssh_public_key_read_failed, dry_run_command, dry_run_command_would_be_executed, dry_run_force_mode, @@ -47,14 +98,12 @@ class SSHCommandBuilder: @staticmethod def build_ssh_keygen_command(path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None) -> list[str]: cmd = ["ssh-keygen", "-t", key_type, "-f", path, "-N"] - - if key_type in ["rsa", "dsa", "ecdsa"]: - cmd.extend(["-b", str(key_size)]) - - if passphrase: + if passphrase is not None: cmd.append(passphrase) else: cmd.append("") + if key_type in ["rsa", "dsa", "ecdsa"]: + cmd.extend(["-b", str(key_size)]) return cmd @@ -95,101 +144,141 @@ def __init__(self, logger: LoggerProtocol): self.logger = logger def _check_ssh_keygen_availability(self) -> tuple[bool, str]: + self.logger.debug(debug_ssh_keygen_availability) try: result = subprocess.run(["ssh-keygen", "-h"], capture_output=True, text=True, check=False) - return result.returncode == 0, None + availability = result.returncode == 0 + self.logger.debug(debug_ssh_keygen_availability_result.format(availability=availability)) + return availability, None except Exception as e: + self.logger.debug(debug_ssh_keygen_availability_failed.format(error=e)) return False, f"ssh-keygen not found: {e}" def _check_ssh_keygen_version(self) -> tuple[bool, str]: try: result = subprocess.run(["ssh-keygen", "-V"], capture_output=True, text=True, check=False) if result.returncode == 0: - self.logger.debug(f"SSH keygen version: {result.stdout.strip()}") + self.logger.debug(debug_ssh_keygen_version_info.format(version=result.stdout.strip())) return True, None except Exception: return True, None def generate_ssh_key( - self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None + self, path: str, key_type: str = "rsa", key_size: int = 4096, passphrase: str = None, force: bool = False ) -> tuple[bool, str]: - available, error = self._check_ssh_keygen_availability() - if not available: - return False, error + self.logger.debug(debug_ssh_key_generation_start.format(path=path)) - self._check_ssh_keygen_version() + if force: + if os.path.exists(path): + os.remove(path) + pub_path = path + ".pub" + if os.path.exists(pub_path): + os.remove(pub_path) cmd = SSHCommandBuilder.build_ssh_keygen_command(path, key_type, key_size, passphrase) + self.logger.debug(debug_ssh_keygen_command_build.format(command=" ".join(cmd))) try: - self.logger.info(executing_ssh_keygen.format(command=" ".join(cmd))) - result = subprocess.run(cmd, capture_output=True, text=True, check=True) - self.logger.success(successfully_generated_ssh_key.format(key=path)) + self.logger.debug(executing_ssh_keygen.format(command=" ".join(cmd))) + result = subprocess.run(cmd, capture_output=True, text=True, check=True, timeout=30) + self.logger.debug(debug_ssh_key_generation_success.format(path=path)) return True, None + except subprocess.TimeoutExpired: + self.logger.error("ssh-keygen timed out") + return False, "ssh-keygen timed out" except subprocess.CalledProcessError as e: - error_msg = e.stderr.strip() if e.stderr else str(e) - self.logger.error(ssh_keygen_failed.format(error=error_msg)) - return False, error_msg + self.logger.error(f"ssh-keygen failed. Command: {' '.join(cmd)}") + self.logger.debug(debug_ssh_process_stdout.format(stdout=e.stdout)) + self.logger.debug(debug_ssh_process_stderr.format(stderr=e.stderr)) + self.logger.error(ssh_keygen_failed.format(error=e.stderr.strip() if e.stderr else str(e))) + return False, e.stderr.strip() if e.stderr else str(e) except Exception as e: + self.logger.error(f"Unexpected error running ssh-keygen. Command: {' '.join(cmd)}") self.logger.error(unexpected_error_during_ssh_keygen.format(error=e)) return False, str(e) def set_key_permissions(self, private_key_path: str, public_key_path: str) -> tuple[bool, str]: + self.logger.debug(debug_ssh_permission_setting.format(private_key=private_key_path, public_key=public_key_path)) try: + self.logger.debug(debug_ssh_private_key_permissions.format(path=private_key_path)) private_success, private_error = self.file_manager.set_permissions( private_key_path, stat.S_IRUSR | stat.S_IWUSR, self.logger ) if not private_success: + self.logger.debug(debug_ssh_private_key_permissions_failed.format(error=private_error)) return False, private_error + self.logger.debug(debug_ssh_public_key_permissions.format(path=public_key_path)) public_success, public_error = self.file_manager.set_permissions( public_key_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH, self.logger ) if not public_success: + self.logger.debug(debug_ssh_public_key_permissions_failed.format(error=public_error)) return False, public_error + self.logger.debug(debug_ssh_permissions_success) return True, None except Exception as e: + self.logger.debug(debug_ssh_permissions_exception.format(error=e)) return False, f"Failed to set permissions: {e}" def create_ssh_directory(self, ssh_dir: str) -> tuple[bool, str]: + permissions = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR + self.logger.debug(debug_ssh_directory_creation.format(directory=ssh_dir, permissions=oct(permissions))) try: - return self.file_manager.create_directory(ssh_dir, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR, self.logger) + self.logger.debug(debug_ssh_directory_check.format(directory=ssh_dir)) + success, error = self.file_manager.create_directory(ssh_dir, permissions, self.logger) + if success: + self.logger.debug(debug_ssh_directory_created.format(directory=ssh_dir)) + else: + self.logger.debug(debug_ssh_directory_creation_failed.format(error=error)) + return success, error except Exception as e: + self.logger.debug(debug_ssh_directory_exception.format(error=e)) return False, f"Failed to create SSH directory: {e}" def add_to_authorized_keys(self, public_key_path: str) -> tuple[bool, str]: try: self.logger.debug(adding_to_authorized_keys) + self.logger.debug(debug_ssh_authorized_keys_read.format(path=public_key_path)) success, content, error = self.file_manager.read_file_content(public_key_path, self.logger) if not success: + self.logger.debug(debug_ssh_public_key_read_failed.format(error=error)) return False, error or failed_to_read_public_key ssh_dir = self.file_manager.expand_user_path("~/.ssh") authorized_keys_path = os.path.join(ssh_dir, "authorized_keys") + self.logger.debug(debug_ssh_authorized_keys_path.format(path=authorized_keys_path)) if not os.path.exists(ssh_dir): + self.logger.debug(debug_ssh_directory_missing.format(directory=ssh_dir)) success, error = self.create_ssh_directory(ssh_dir) if not success: return False, error if not os.path.exists(authorized_keys_path): + self.logger.debug(debug_ssh_authorized_keys_missing.format(path=authorized_keys_path)) try: with open(authorized_keys_path, "w") as f: pass os.chmod(authorized_keys_path, stat.S_IRUSR | stat.S_IWUSR) + self.logger.debug(debug_ssh_authorized_keys_created.format(path=authorized_keys_path)) except Exception as e: + self.logger.debug(debug_ssh_authorized_keys_creation_failed.format(error=e)) return False, f"Failed to create authorized_keys file: {e}" + self.logger.debug(debug_ssh_authorized_keys_append.format(path=authorized_keys_path)) success, error = self.file_manager.append_to_file(authorized_keys_path, content, self.logger) if not success: + self.logger.debug(debug_ssh_authorized_keys_append_failed.format(error=error)) return False, error or failed_to_append_to_authorized_keys self.logger.debug(authorized_keys_updated) return True, None except Exception as e: error_msg = failed_to_add_to_authorized_keys.format(error=e) + self.logger.debug(debug_ssh_authorized_keys_exception.format(error=e)) self.logger.error(error_msg) return False, error_msg @@ -281,17 +370,34 @@ def validate_passphrase(cls, passphrase: str) -> Optional[str]: class SSHService: def __init__(self, config: SSHConfig, logger: LoggerProtocol = None, ssh_manager: SSHKeyProtocol = None): - self.config = config self.logger = logger or Logger(verbose=config.verbose) + self.config = config self.ssh_manager = ssh_manager or SSHKeyManager(self.logger) self.formatter = SSHFormatter() self.file_manager = FileManager() def _validate_prerequisites(self) -> bool: + self.logger.debug(debug_ssh_config_validation.format( + path=self.config.path, + key_type=self.config.key_type, + key_size=self.config.key_size + )) + expanded_key_path = self.file_manager.expand_user_path(self.config.path) - if os.path.exists(expanded_key_path) and not self.config.force: - self.logger.error(ssh_key_already_exists.format(path=self.config.path)) - return False + self.logger.debug(debug_ssh_path_expansion.format(original=self.config.path, expanded=expanded_key_path)) + + if os.path.exists(expanded_key_path): + self.logger.debug(debug_ssh_key_exists.format(path=expanded_key_path)) + if not self.config.force: + self.logger.debug(debug_ssh_force_disabled) + self.logger.error(ssh_key_already_exists.format(path=self.config.path)) + return False + else: + self.logger.debug(debug_ssh_force_enabled) + else: + self.logger.debug(debug_ssh_key_not_exists.format(path=expanded_key_path)) + + self.logger.debug(debug_ssh_prerequisites_completed) return True def _create_result(self, success: bool, error: str = None) -> SSHResult: @@ -314,39 +420,51 @@ def generate_ssh_key(self) -> SSHResult: self.logger.debug(generating_ssh_key.format(key=self.config.path)) if not self._validate_prerequisites(): + self.logger.debug(debug_ssh_prerequisites_failed_abort) return self._create_result(False, prerequisites_validation_failed) if self.config.dry_run: + self.logger.debug(debug_ssh_dry_run_enabled) dry_run_output = self.formatter.format_dry_run(self.config) return self._create_result(True, dry_run_output) expanded_path = self.file_manager.expand_user_path(self.config.path) ssh_dir = self.file_manager.get_directory_path(expanded_path) + self.logger.debug(debug_ssh_key_directory_info.format(directory=ssh_dir)) if self.config.create_ssh_directory: + self.logger.debug(debug_ssh_directory_creation_enabled.format(directory=ssh_dir)) success, error = self.ssh_manager.create_ssh_directory(ssh_dir) if not success: + self.logger.debug(debug_ssh_directory_creation_failed_abort.format(error=error)) return self._create_result(False, error) + self.logger.debug(debug_ssh_generation_process_start) success, error = self.ssh_manager.generate_ssh_key( - self.config.path, self.config.key_type, self.config.key_size, self.config.passphrase + self.config.path, self.config.key_type, self.config.key_size, self.config.passphrase, self.config.force ) if not success: return self._create_result(False, error) if self.config.set_permissions: + self.logger.debug(debug_ssh_permissions_enabled) public_key_path = self.file_manager.get_public_key_path(expanded_path) + self.logger.debug(debug_ssh_public_key_path_info.format(path=public_key_path)) success, error = self.ssh_manager.set_key_permissions(expanded_path, public_key_path) if not success: + self.logger.debug(debug_ssh_permissions_failed_abort.format(error=error)) return self._create_result(False, error) if self.config.add_to_authorized_keys: + self.logger.debug(debug_ssh_authorized_keys_enabled) public_key_path = self.file_manager.get_public_key_path(expanded_path) success, error = self.ssh_manager.add_to_authorized_keys(public_key_path) if not success: + self.logger.debug(debug_ssh_authorized_keys_failed_abort.format(error=error)) return self._create_result(False, error) + self.logger.debug(debug_ssh_process_completed) return self._create_result(True) def generate_and_format(self) -> str: diff --git a/cli/app/commands/preflight/deps.py b/cli/app/commands/preflight/deps.py index 23f3d3ed..f23edf19 100644 --- a/cli/app/commands/preflight/deps.py +++ b/cli/app/commands/preflight/deps.py @@ -1,3 +1,4 @@ +import shutil import subprocess from typing import Optional, Protocol @@ -29,8 +30,7 @@ def __init__(self, logger: LoggerProtocol): def check_dependency(self, dep: str) -> bool: try: - result = subprocess.run(["command", "-v", dep], capture_output=True, text=True, timeout=1) - is_available = result.returncode == 0 + is_available = shutil.which(dep) is not None self.logger.debug(debug_dep_check_result.format(dep=dep, status="available" if is_available else "not available")) return is_available diff --git a/cli/app/commands/service/base.py b/cli/app/commands/service/base.py index 62eb00ac..3ee5e38b 100644 --- a/cli/app/commands/service/base.py +++ b/cli/app/commands/service/base.py @@ -126,17 +126,17 @@ def execute_services( self.logger.debug(docker_command_executing.format(command=' '.join(cmd))) try: - self.logger.info(service_action_info.format(action=self.action, name=name)) + self.logger.debug(service_action_info.format(action=self.action, name=name)) if self.action == "up" and not kwargs.get("detach", False): process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True) output_lines = [] - self.logger.info("Docker container logs:") - self.logger.info("-" * 50) + self.logger.debug("Docker container logs:") + self.logger.debug("-" * 50) for line in process.stdout: - self.logger.info(line.rstrip()) # Stream logs through logger + self.logger.debug(line.rstrip()) # Stream logs through logger output_lines.append(line.rstrip()) return_code = process.wait() diff --git a/cli/app/commands/service/ps.py b/cli/app/commands/service/ps.py index c8995522..5b6eccce 100644 --- a/cli/app/commands/service/ps.py +++ b/cli/app/commands/service/ps.py @@ -119,7 +119,6 @@ def show_services_status(self, name: str = "all", env_file: str = None, compose_ self.logger.debug(docker_command_executing.format(command=' '.join(cmd))) try: - self.logger.info(service_action_info.format(action="ps", name=name)) result = subprocess.run(cmd, capture_output=True, text=True, check=True) self.logger.debug(docker_command_completed.format(action="ps")) diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index cf913a62..4c3d9f7c 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -33,6 +33,10 @@ def get_yaml_value(self, path: str): config = expand_env_placeholders(config) return config + def get_service_env_values(self, service_env_path: str): + config = self.get_yaml_value(service_env_path) + return {key: expand_env_placeholders(value) for key, value in config.items()} + def expand_env_placeholders(value: str) -> str: # Expand environment placeholders in the form ${ENV_VAR:-default} @@ -55,4 +59,13 @@ def replacer(match): CONFIG_ENDPOINT = "services.caddy.env.CONFIG_ENDPOINT" LOAD_ENDPOINT = "services.caddy.env.LOAD_ENDPOINT" STOP_ENDPOINT = "services.caddy.env.STOP_ENDPOINT" -DEPS = "deps" \ No newline at end of file +DEPS = "deps" +PORTS = "ports" +API_SERVICE = "services.api" +VIEW_SERVICE = "services.view" +SSH_KEY_SIZE = "ssh_key_size" +SSH_KEY_TYPE = "ssh_key_type" +SSH_FILE_PATH = "ssh_file_path" +VIEW_PORT = "services.view.env.NEXT_PUBLIC_PORT" +API_PORT = "services.api.env.PORT" +CADDY_CONFIG_VOLUME = "services.caddy.env.CADDY_CONFIG_VOLUME" \ No newline at end of file diff --git a/cli/app/utils/lib.py b/cli/app/utils/lib.py index 97a21688..b3ad2af3 100644 --- a/cli/app/utils/lib.py +++ b/cli/app/utils/lib.py @@ -2,7 +2,6 @@ import platform import shutil import stat -import subprocess from concurrent.futures import ThreadPoolExecutor, as_completed from enum import Enum from typing import Callable, List, Optional, Tuple, TypeVar @@ -75,16 +74,11 @@ def get_package_manager(): for pm in package_managers: if HostInformation.command_exists(pm): return pm - - return None + raise RuntimeError("No supported package manager found on this system. Please install one or specify it manually.") @staticmethod def command_exists(command): - try: - result = subprocess.run(["command", "-v", command], capture_output=True, text=True, check=False) - return result.returncode == 0 - except Exception: - return False + return shutil.which(command) is not None @staticmethod def get_public_ip(): diff --git a/cli/app/utils/message.py b/cli/app/utils/message.py index 5963926a..843f0638 100644 --- a/cli/app/utils/message.py +++ b/cli/app/utils/message.py @@ -10,8 +10,8 @@ DEBUG_MESSAGE = "DEBUG: {message}" WARNING_MESSAGE = "WARNING: {message}" ERROR_MESSAGE = "ERROR: {message}" -SUCCESS_MESSAGE = "SUCCESS: {message}" -HIGHLIGHT_MESSAGE = "HIGHLIGHT: {message}" +SUCCESS_MESSAGE = "{message}" +HIGHLIGHT_MESSAGE = "{message}" REMOVED_DIRECTORY_MESSAGE = "Removed existing directory: {path}" FAILED_TO_REMOVE_DIRECTORY_MESSAGE = "Failed to remove directory: {path}" MISSING_CONFIG_KEY_MESSAGE = "Missing config key: {path} (failed at '{key}')" diff --git a/docker-compose.yml b/docker-compose.yml index 104e70f4..4279d540 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,8 @@ services: - HOST_NAME=nixopus-db volumes: - ./logs:/app/logs - - ${DOCKER_CERT_PATH}:/etc/nixopus/docker-certs - - ${SSH_PRIVATE_KEY}:/etc/nixopus/ssh/id_rsa + - ${DOCKER_CERT_PATH:-/etc/nixopus/docker-certs}:/etc/nixopus/docker-certs + - ${SSH_PRIVATE_KEY:-/etc/nixopus/ssh/nixopus_ed25519}:/etc/nixopus/ssh/id_rsa - ${MOUNT_PATH:-/etc/nixopus/configs}:/etc/nixopus/configs - /var/run/docker.sock:/var/run/docker.sock - /etc/nixopus/source/api/.env:/app/.env @@ -100,7 +100,7 @@ services: - "80:80" - "443:443" volumes: - - /etc/nixopus/caddy/Caddyfile:/etc/caddy/Caddyfile + - /etc/nixopus/source/helpers/Caddyfile:/etc/caddy/Caddyfile - ${CADDY_DATA_VOLUME:-/etc/nixopus/caddy}:/data - ${CADDY_CONFIG_VOLUME:-/etc/nixopus/caddy}:/config command: diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index 437f30b5..fd9b1ef2 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -17,7 +17,7 @@ services: SSH_PASSWORD: ${SSH_PASSWORD:-} DOCKER_HOST: ${DOCKER_HOST:-unix:///var/run/docker.sock} DOCKER_TLS_VERIFY: ${DOCKER_TLS_VERIFY:-1} - DOCKER_CERT_PATH: ${DOCKER_CERT_PATH:-} + DOCKER_CERT_PATH: ${DOCKER_CERT_PATH:-/etc/nixopus/docker-certs} REDIS_URL: ${REDIS_URL:-redis://nixopus-redis:6379} CADDY_ENDPOINT: ${CADDY_ENDPOINT:-http://nixopus-caddy:2019} ALLOWED_ORIGIN: ${ALLOWED_ORIGIN:-http://localhost:3000} @@ -62,7 +62,6 @@ services: CADDY_CONTAINER_NAME: ${CADDY_CONTAINER_NAME:-nixopus-caddy-container} CADDY_DATA_VOLUME: ${CADDY_DATA_VOLUME:-/etc/nixopus/caddy} CADDY_CONFIG_VOLUME: ${CADDY_CONFIG_VOLUME:-/etc/nixopus/caddy} - CADDYFILE_PATH: ${CADDYFILE_PATH:-/etc/nixopus/caddy/Caddyfile} CADDY_PORTS: "2019:2019,80:80,443:443" API_DOMAIN: ${API_DOMAIN:-} VIEW_DOMAIN: ${VIEW_DOMAIN:-} @@ -86,21 +85,28 @@ networks: driver: bridge deps: - curl: { version: "1" } - go: { version: "1" } - air: { version: "" } - python: { version: "" } - poetry: { version: "" } - docker: { version: "" } - open-ssh: { version: "" } - open-sshserver: { version: "" } - git: { version: "" } - openssl: { version: "" } - python3-venv: { version: "" } + curl: { package: "curl", command: "curl" } + python3: { package: "python3", command: "python3" } + python3-venv: { package: "python3-venv", command: "" } + git: { package: "git", command: "git" } + docker.io: + package: "docker.io" + command: "docker" + install_command: | + curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh + openssl: { package: "openssl", command: "openssl" } + openssh-client: { package: "openssh-client", command: "ssh" } + openssh-server: { package: "openssh-server", command: "sshd" } nixopus-config-dir: /etc/nixopus -compose-file-path: docker-compose.yml +compose-file-path: source/docker-compose.yml clone: repo: "https://github.com/raghavyuva/nixopus" branch: "master" source-path: source + +ports: [2019, 80, 443, 7443, 8443, 6379, 5432] +ssh_key_size: 4096 +ssh_key_type: ed25519 +ssh_passphrase: +ssh_file_path: ssh/nixopus_ed25519 \ No newline at end of file From 5f1a63392ac8d1078dbe1f205e1acde0570015b5 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Tue, 22 Jul 2025 22:03:21 +0530 Subject: [PATCH 55/72] fix: environment variable updating in installation --- cli/app/commands/install/run.py | 75 +++++++++++++++++++++++++++++---- cli/app/utils/config.py | 3 +- helpers/config.prod.yaml | 11 +++-- 3 files changed, 75 insertions(+), 14 deletions(-) diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py index 8790f68d..81a0550b 100644 --- a/cli/app/commands/install/run.py +++ b/cli/app/commands/install/run.py @@ -2,14 +2,16 @@ import os import yaml import json +import shutil from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn from app.utils.protocols import LoggerProtocol -from app.utils.config import Config, VIEW_ENV_FILE, API_ENV_FILE, DEFAULT_REPO, DEFAULT_BRANCH, DEFAULT_PATH, NIXOPUS_CONFIG_DIR, PORTS, DEFAULT_COMPOSE_FILE, PROXY_PORT, SSH_KEY_TYPE, SSH_KEY_SIZE, SSH_FILE_PATH, VIEW_PORT, API_PORT +from app.utils.config import Config, VIEW_ENV_FILE, API_ENV_FILE, DEFAULT_REPO, DEFAULT_BRANCH, DEFAULT_PATH, NIXOPUS_CONFIG_DIR, PORTS, DEFAULT_COMPOSE_FILE, PROXY_PORT, SSH_KEY_TYPE, SSH_KEY_SIZE, SSH_FILE_PATH, VIEW_PORT, API_PORT, DOCKER_PORT, CADDY_CONFIG_VOLUME from app.utils.timeout import TimeoutWrapper from app.commands.preflight.port import PortConfig, PortService from app.commands.clone.clone import Clone, CloneConfig from app.utils.lib import HostInformation, FileManager from app.commands.conf.base import BaseEnvironmentManager +import re from app.commands.service.up import Up, UpConfig from app.commands.proxy.load import Load, LoadConfig from .ssh import SSH, SSHConfig @@ -48,6 +50,7 @@ 'package_manager': HostInformation.get_package_manager(), 'view_port': _config.get_yaml_value(VIEW_PORT), 'api_port': _config.get_yaml_value(API_PORT), + 'docker_port': _config.get_yaml_value(DOCKER_PORT), } def get_config_value(key: str, provided_value=None): @@ -67,6 +70,7 @@ def __init__(self, logger: LoggerProtocol = None, verbose: bool = False, timeout self._user_config = self._load_user_config() self.progress = None self.main_task = None + self._validate_domains() def _load_user_config(self): if not self.config_file: @@ -100,11 +104,20 @@ def _get_config(self, key: str): user_value = self._get_user_config_value(key) value = user_value if user_value is not None else DEFAULTS.get(key) - if value is None: + if value is None and key not in ['ssh_passphrase']: raise ValueError(configuration_key_has_no_default_value.format(key=key)) self._config_cache[key] = value return self._config_cache[key] + def _validate_domains(self): + if (self.api_domain is None) != (self.view_domain is None): + raise ValueError("Both api_domain and view_domain must be provided together, or neither should be provided") + + if self.api_domain and self.view_domain: + domain_pattern = re.compile(r'^[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\.([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?))*$') + if not domain_pattern.match(self.api_domain) or not domain_pattern.match(self.view_domain): + raise ValueError("Invalid domain format. Domains must be valid hostnames") + def _get_user_config_value(self, key: str): key_mappings = { 'proxy_port': 'services.caddy.env.PROXY_PORT', @@ -125,8 +138,8 @@ def run(self): steps = [ ("Preflight checks", self._run_preflight_checks), ("Installing dependencies", self._install_dependencies), - ("Setting up proxy config", self._setup_proxy_config), ("Cloning repository", self._setup_clone_and_config), + ("Setting up proxy config", self._setup_proxy_config), ("Creating environment files", self._create_env_files), ("Generating SSH keys", self._setup_ssh), ("Starting services", self._start_services), @@ -221,7 +234,8 @@ def _create_env_files(self): for i, (service_name, service_key, env_file) in enumerate(services): env_values = _config.get_service_env_values(service_key) - success, error = env_manager.write_env_file(env_file, env_values) + updated_env_values = self._update_environment_variables(env_values) + success, error = env_manager.write_env_file(env_file, updated_env_values) if not success: raise Exception(f"{env_file_creation_failed} {service_name}: {error}") file_perm_success, file_perm_error = FileManager.set_permissions(env_file, 0o644) @@ -237,12 +251,15 @@ def _setup_proxy_config(self): with open(caddy_json_template, 'r') as f: config_str = f.read() - config_str = config_str.replace('{env.APP_DOMAIN}', self.view_domain) - config_str = config_str.replace('{env.API_DOMAIN}', self.api_domain) - host_ip = HostInformation.get_public_ip() view_port = self._get_config('view_port') api_port = self._get_config('api_port') + + view_domain = self.view_domain if self.view_domain is not None else host_ip + api_domain = self.api_domain if self.api_domain is not None else host_ip + + config_str = config_str.replace('{env.APP_DOMAIN}', view_domain) + config_str = config_str.replace('{env.API_DOMAIN}', api_domain) app_reverse_proxy_url = f"{host_ip}:{view_port}" api_reverse_proxy_url = f"{host_ip}:{api_port}" @@ -252,6 +269,7 @@ def _setup_proxy_config(self): caddy_config = json.loads(config_str) with open(caddy_json_template, 'w') as f: json.dump(caddy_config, f, indent=2) + self._copy_caddyfile_to_target(full_source_path) self.logger.debug(f"{proxy_config_created}: {caddy_json_template}") @@ -319,7 +337,6 @@ def _load_proxy(self): raise Exception(proxy_load_failed) def _show_success_message(self): - """Display formatted success message with access information""" nixopus_accessible_at = self._get_access_url() self.logger.success("Installation Complete!") @@ -329,8 +346,48 @@ def _show_success_message(self): self.logger.info("If you have any questions, please visit the community forum at https://discord.gg/skdcq39Wpv") self.logger.highlight("See you in the community!") + def _update_environment_variables(self, env_values: dict) -> dict: + updated_env = env_values.copy() + host_ip = HostInformation.get_public_ip() + secure = self.api_domain is not None and self.view_domain is not None + + api_host = self.api_domain if secure else f"{host_ip}:{self._get_config('api_port')}" + view_host = self.view_domain if secure else f"{host_ip}:{self._get_config('view_port')}" + protocol = "https" if secure else "http" + ws_protocol = "wss" if secure else "ws" + key_map = { + 'ALLOWED_ORIGIN': f"{protocol}://{view_host}", + 'SSH_HOST': host_ip, + 'SSH_PRIVATE_KEY': self._get_config('ssh_key_path'), + 'DOCKER_HOST': f"tcp://{host_ip}:{self._get_config('docker_port')}", + 'WEBSOCKET_URL': f"{ws_protocol}://{view_host}/ws", + 'API_URL': f"{protocol}://{api_host}/api", + 'WEBHOOK_URL': f"{protocol}://{api_host}/api/v1/webhook", + } + + for key, value in key_map.items(): + if key in updated_env: + updated_env[key] = value + + return updated_env + + def _copy_caddyfile_to_target(self, full_source_path: str): + try: + source_caddyfile = os.path.join(full_source_path, 'helpers', 'Caddyfile') + target_dir = _config.get_yaml_value(CADDY_CONFIG_VOLUME) + target_caddyfile = os.path.join(target_dir, 'Caddyfile') + FileManager.create_directory(target_dir, logger=self.logger) + if os.path.exists(source_caddyfile): + shutil.copy2(source_caddyfile, target_caddyfile) + FileManager.set_permissions(target_caddyfile, 0o644, logger=self.logger) + self.logger.debug(f"Copied Caddyfile from {source_caddyfile} to {target_caddyfile}") + else: + self.logger.warning(f"Source Caddyfile not found at {source_caddyfile}") + + except Exception as e: + self.logger.error(f"Failed to copy Caddyfile: {str(e)}") + def _get_access_url(self): - """Determine the access URL based on provided domains or fallback to host IP""" if self.view_domain: return f"https://{self.view_domain}" elif self.api_domain: diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index 4c3d9f7c..6a4abfa6 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -68,4 +68,5 @@ def replacer(match): SSH_FILE_PATH = "ssh_file_path" VIEW_PORT = "services.view.env.NEXT_PUBLIC_PORT" API_PORT = "services.api.env.PORT" -CADDY_CONFIG_VOLUME = "services.caddy.env.CADDY_CONFIG_VOLUME" \ No newline at end of file +CADDY_CONFIG_VOLUME = "services.caddy.env.CADDY_CONFIG_VOLUME" +DOCKER_PORT = "services.api.env.DOCKER_PORT" \ No newline at end of file diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index fd9b1ef2..beae4ca0 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -12,8 +12,8 @@ services: MOUNT_PATH: ${MOUNT_PATH:-/etc/nixopus/configs} SSH_HOST: ${SSH_HOST:-localhost} SSH_PORT: ${SSH_PORT:-22} - SSH_USER: ${SSH_USER:-} - SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY:-} + SSH_USER: ${SSH_USER:-root} + SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY:-/etc/nixopus/ssh/nixopus_ed25519} SSH_PASSWORD: ${SSH_PASSWORD:-} DOCKER_HOST: ${DOCKER_HOST:-unix:///var/run/docker.sock} DOCKER_TLS_VERIFY: ${DOCKER_TLS_VERIFY:-1} @@ -27,11 +27,14 @@ services: API_VOLUME: ${API_VOLUME:-/etc/nixopus/configs} API_IMAGE: ${API_IMAGE:-ghcr.io/raghavyuva/nixopus-api:latest} API_CONTAINER_NAME: ${API_CONTAINER_NAME:-nixopus-api-container} - + DOCKER_PORT: ${DOCKER_PORT:-2376} + APP_VERSION: ${APP_VERSION:-0.1.0-alpha.11} view: env: PORT: ${VIEW_PORT:-7443} - NEXT_PUBLIC_WEBHOOK_URL: ${NEXT_PUBLIC_WEBHOOK_URL:-} + WEBSOCKET_URL: ${WEBSOCKET_URL:-} + API_URL: ${API_URL:-} + WEBHOOK_URL: ${WEBHOOK_URL:-} NEXT_PUBLIC_PORT: ${NEXT_PUBLIC_PORT:-7443} LOGS_PATH: ${LOGS_PATH:-./logs} VIEW_ENV_FILE: ${VIEW_ENV_FILE:-/etc/nixopus/source/view/.env} From dad223553d2ce6f2b0347dd47e330eb5d3d99c0f Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 24 Jul 2025 17:13:46 +0530 Subject: [PATCH 56/72] fix: install flow --- cli/app/commands/install/run.py | 1 - cli/app/commands/uninstall/__init__.py | 0 cli/app/commands/uninstall/command.py | 28 ++++ cli/app/commands/uninstall/messages.py | 27 ++++ cli/app/commands/uninstall/run.py | 185 +++++++++++++++++++++++++ cli/app/main.py | 2 + docker-compose.yml | 2 +- helpers/config.prod.yaml | 6 +- 8 files changed, 245 insertions(+), 6 deletions(-) create mode 100644 cli/app/commands/uninstall/__init__.py create mode 100644 cli/app/commands/uninstall/command.py create mode 100644 cli/app/commands/uninstall/messages.py create mode 100644 cli/app/commands/uninstall/run.py diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py index 81a0550b..dce1020c 100644 --- a/cli/app/commands/install/run.py +++ b/cli/app/commands/install/run.py @@ -359,7 +359,6 @@ def _update_environment_variables(self, env_values: dict) -> dict: 'ALLOWED_ORIGIN': f"{protocol}://{view_host}", 'SSH_HOST': host_ip, 'SSH_PRIVATE_KEY': self._get_config('ssh_key_path'), - 'DOCKER_HOST': f"tcp://{host_ip}:{self._get_config('docker_port')}", 'WEBSOCKET_URL': f"{ws_protocol}://{view_host}/ws", 'API_URL': f"{protocol}://{api_host}/api", 'WEBHOOK_URL': f"{protocol}://{api_host}/api/v1/webhook", diff --git a/cli/app/commands/uninstall/__init__.py b/cli/app/commands/uninstall/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/uninstall/command.py b/cli/app/commands/uninstall/command.py new file mode 100644 index 00000000..c6b51c7f --- /dev/null +++ b/cli/app/commands/uninstall/command.py @@ -0,0 +1,28 @@ +import typer + +from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper +from .run import Uninstall + +uninstall_app = typer.Typer(help="Uninstall Nixopus", invoke_without_command=True) + + +@uninstall_app.callback() +def uninstall_callback( + ctx: typer.Context, + verbose: bool = typer.Option(False, "--verbose", "-v", help="Show more details while uninstalling"), + timeout: int = typer.Option(300, "--timeout", "-t", help="How long to wait for each step (in seconds)"), + dry_run: bool = typer.Option(False, "--dry-run", "-d", help="See what would happen, but don't make changes"), + force: bool = typer.Option(False, "--force", "-f", help="Remove files without confirmation prompts"), +): + """Uninstall Nixopus completely from the system""" + if ctx.invoked_subcommand is None: + logger = Logger(verbose=verbose) + uninstall = Uninstall( + logger=logger, + verbose=verbose, + timeout=timeout, + dry_run=dry_run, + force=force + ) + uninstall.run() \ No newline at end of file diff --git a/cli/app/commands/uninstall/messages.py b/cli/app/commands/uninstall/messages.py new file mode 100644 index 00000000..f9aa35cd --- /dev/null +++ b/cli/app/commands/uninstall/messages.py @@ -0,0 +1,27 @@ +uninstalling_nixopus = "Uninstalling Nixopus" +uninstall_failed = "Uninstall failed" +uninstall_completed = "Uninstall completed successfully" +stopping_services = "Stopping Nixopus services" +removing_ssh_keys = "Removing SSH keys from authorized_keys" +removing_config_directory = "Removing configuration directory" +services_stop_failed = "Failed to stop services" +ssh_keys_removal_failed = "Failed to remove SSH keys" +config_directory_removal_failed = "Failed to remove configuration directory" +operation_timed_out = "Operation timed out" +uninstall_dry_run_mode = "Dry run mode: would perform uninstall operations" +uninstall_completed_info = "Nixopus has been completely removed from your system." +uninstall_thank_you = "Thank you for using Nixopus!" +docker_not_running_skip_removal = "Docker is not running, skipping image removal" +authorized_keys_not_found = "authorized_keys file not found, skipping SSH key removal" +ssh_key_not_found_in_authorized_keys = "SSH key not found in authorized_keys" +compose_file_not_found_skip = "Compose file not found at {compose_file_path}, skipping service stop" +failed_at_step = "Failed at {step_name}" +removed_docker_image = "Removed Docker image: {image}" +failed_to_remove_image = "Failed to remove image {image}: {error}" +ssh_public_key_not_found_skip = "SSH public key not found at {public_key_path}, skipping authorized_keys cleanup" +removed_ssh_key_from = "Removed SSH key from {authorized_keys_path}" +removed_private_key = "Removed private key: {ssh_key_path}" +removed_public_key = "Removed public key: {public_key_path}" +config_dir_not_exist_skip = "Configuration directory {config_dir_path} does not exist, skipping removal" +removed_config_dir = "Removed configuration directory: {config_dir_path}" +skipped_removal_config_dir = "Skipped removal of configuration directory: {config_dir_path}" diff --git a/cli/app/commands/uninstall/run.py b/cli/app/commands/uninstall/run.py new file mode 100644 index 00000000..2aa70704 --- /dev/null +++ b/cli/app/commands/uninstall/run.py @@ -0,0 +1,185 @@ +import typer +import os +import shutil +import subprocess +from pathlib import Path +from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn +from app.utils.protocols import LoggerProtocol +from app.utils.config import Config, NIXOPUS_CONFIG_DIR, SSH_FILE_PATH, DEFAULT_COMPOSE_FILE +from app.utils.timeout import TimeoutWrapper +from app.commands.service.down import Down, DownConfig +from .messages import ( + uninstalling_nixopus, uninstall_failed, uninstall_completed, + services_stop_failed, + ssh_keys_removal_failed, config_directory_removal_failed, + operation_timed_out, uninstall_dry_run_mode, + uninstall_completed_info, uninstall_thank_you, + authorized_keys_not_found, ssh_key_not_found_in_authorized_keys, + compose_file_not_found_skip, failed_at_step, + ssh_public_key_not_found_skip, removed_ssh_key_from, removed_private_key, removed_public_key, + config_dir_not_exist_skip, removed_config_dir, skipped_removal_config_dir +) + +_config = Config() +_config_dir = _config.get_yaml_value(NIXOPUS_CONFIG_DIR) +_compose_file = _config.get_yaml_value(DEFAULT_COMPOSE_FILE) +_ssh_key_path = _config_dir + "/" + _config.get_yaml_value(SSH_FILE_PATH) + +class Uninstall: + def __init__(self, logger: LoggerProtocol = None, verbose: bool = False, timeout: int = 300, dry_run: bool = False, force: bool = False): + self.logger = logger + self.verbose = verbose + self.timeout = timeout + self.dry_run = dry_run + self.force = force + self.progress = None + self.main_task = None + + def run(self): + steps = [ + ("Stopping services", self._stop_services), + ("Removing SSH keys", self._remove_ssh_keys), + ("Removing configuration directory", self._remove_config_directory), + ] + + try: + if self.dry_run: + self.logger.info(uninstall_dry_run_mode) + for step_name, _ in steps: + self.logger.info(f"Would execute: {step_name}") + return + + with Progress( + SpinnerColumn(), + TextColumn("[progress.description]{task.description}"), + BarColumn(), + TaskProgressColumn(), + transient=True, + refresh_per_second=2, + ) as progress: + self.progress = progress + self.main_task = progress.add_task(uninstalling_nixopus, total=len(steps)) + + for i, (step_name, step_func) in enumerate(steps): + progress.update(self.main_task, description=f"{uninstalling_nixopus} - {step_name} ({i+1}/{len(steps)})") + try: + step_func() + progress.advance(self.main_task, 1) + except Exception as e: + progress.update(self.main_task, description=failed_at_step.format(step_name=step_name)) + raise + + progress.update(self.main_task, completed=True, description=uninstall_completed) + + self._show_success_message() + + except Exception as e: + self._handle_uninstall_error(e) + self.logger.error(f"{uninstall_failed}: {str(e)}") + raise typer.Exit(1) + + def _handle_uninstall_error(self, error, context=""): + context_msg = f" during {context}" if context else "" + if self.verbose: + self.logger.error(f"{uninstall_failed}{context_msg}: {str(error)}") + else: + self.logger.error(f"{uninstall_failed}{context_msg}") + + def _stop_services(self): + compose_file_path = os.path.join(_config_dir, _compose_file) + + if not os.path.exists(compose_file_path): + self.logger.debug(compose_file_not_found_skip.format(compose_file_path=compose_file_path)) + return + + try: + config = DownConfig( + name="all", + env_file=None, + verbose=self.verbose, + output="text", + dry_run=False, + compose_file=compose_file_path + ) + + down_service = Down(logger=self.logger) + + with TimeoutWrapper(self.timeout): + result = down_service.down(config) + + if not result.success: + raise Exception(f"{services_stop_failed}: {result.error}") + + except TimeoutError: + raise Exception(f"{services_stop_failed}: {operation_timed_out}") + + def _remove_ssh_keys(self): + ssh_key_path = Path(_ssh_key_path) + public_key_path = ssh_key_path.with_suffix('.pub') + + if not public_key_path.exists(): + self.logger.debug(ssh_public_key_not_found_skip.format(public_key_path=public_key_path)) + return + + try: + with open(public_key_path, 'r') as f: + public_key_content = f.read().strip() + + authorized_keys_path = Path.home() / '.ssh' / 'authorized_keys' + + if not authorized_keys_path.exists(): + self.logger.debug(authorized_keys_not_found) + return + + with open(authorized_keys_path, 'r') as f: + lines = f.readlines() + + original_count = len(lines) + filtered_lines = [line for line in lines if public_key_content not in line] + + if len(filtered_lines) < original_count: + with open(authorized_keys_path, 'w') as f: + f.writelines(filtered_lines) + self.logger.debug(removed_ssh_key_from.format(authorized_keys_path=authorized_keys_path)) + else: + self.logger.debug(ssh_key_not_found_in_authorized_keys) + + if ssh_key_path.exists(): + ssh_key_path.unlink() + self.logger.debug(removed_private_key.format(ssh_key_path=ssh_key_path)) + + if public_key_path.exists(): + public_key_path.unlink() + self.logger.debug(removed_public_key.format(public_key_path=public_key_path)) + + except Exception as e: + raise Exception(f"{ssh_keys_removal_failed}: {str(e)}") + + def _remove_config_directory(self): + config_dir_path = Path(_config_dir) + + if not config_dir_path.exists(): + self.logger.debug(config_dir_not_exist_skip.format(config_dir_path=config_dir_path)) + return + + try: + if self.force or self._confirm_removal(config_dir_path): + shutil.rmtree(config_dir_path) + self.logger.debug(removed_config_dir.format(config_dir_path=config_dir_path)) + else: + self.logger.info(skipped_removal_config_dir.format(config_dir_path=config_dir_path)) + + except Exception as e: + raise Exception(f"{config_directory_removal_failed}: {str(e)}") + + def _confirm_removal(self, path: Path) -> bool: + if self.force: + return True + + response = typer.confirm(f"Remove configuration directory {path}? This action cannot be undone.") + return response + + def _show_success_message(self): + self.logger.success(uninstall_completed) + self.logger.info(uninstall_completed_info) + self.logger.info(uninstall_thank_you) diff --git a/cli/app/main.py b/cli/app/main.py index 641905f8..5ee3b097 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -11,6 +11,7 @@ from app.commands.proxy.command import proxy_app from app.commands.service.command import service_app from app.commands.test.command import test_app +from app.commands.uninstall.command import uninstall_app from app.commands.version.command import main_version_callback, version_app from app.commands.version.version import VersionCommand from app.utils.message import application_add_completion, application_description, application_name, application_version_help @@ -77,6 +78,7 @@ def main( app.add_typer(service_app, name="service") app.add_typer(proxy_app, name="proxy") app.add_typer(install_app, name="install") +app.add_typer(uninstall_app, name="uninstall") app.add_typer(version_app, name="version") app.add_typer(test_app, name="test") diff --git a/docker-compose.yml b/docker-compose.yml index 4279d540..0e927ff1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: volumes: - ./logs:/app/logs - ${DOCKER_CERT_PATH:-/etc/nixopus/docker-certs}:/etc/nixopus/docker-certs - - ${SSH_PRIVATE_KEY:-/etc/nixopus/ssh/nixopus_ed25519}:/etc/nixopus/ssh/id_rsa + - ${SSH_PRIVATE_KEY:-/etc/nixopus/ssh/id_rsa}:/etc/nixopus/ssh/id_rsa - ${MOUNT_PATH:-/etc/nixopus/configs}:/etc/nixopus/configs - /var/run/docker.sock:/var/run/docker.sock - /etc/nixopus/source/api/.env:/app/.env diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index beae4ca0..73bd6d19 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -13,11 +13,9 @@ services: SSH_HOST: ${SSH_HOST:-localhost} SSH_PORT: ${SSH_PORT:-22} SSH_USER: ${SSH_USER:-root} - SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY:-/etc/nixopus/ssh/nixopus_ed25519} + SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY:-/etc/nixopus/ssh/id_rsa} SSH_PASSWORD: ${SSH_PASSWORD:-} DOCKER_HOST: ${DOCKER_HOST:-unix:///var/run/docker.sock} - DOCKER_TLS_VERIFY: ${DOCKER_TLS_VERIFY:-1} - DOCKER_CERT_PATH: ${DOCKER_CERT_PATH:-/etc/nixopus/docker-certs} REDIS_URL: ${REDIS_URL:-redis://nixopus-redis:6379} CADDY_ENDPOINT: ${CADDY_ENDPOINT:-http://nixopus-caddy:2019} ALLOWED_ORIGIN: ${ALLOWED_ORIGIN:-http://localhost:3000} @@ -112,4 +110,4 @@ ports: [2019, 80, 443, 7443, 8443, 6379, 5432] ssh_key_size: 4096 ssh_key_type: ed25519 ssh_passphrase: -ssh_file_path: ssh/nixopus_ed25519 \ No newline at end of file +ssh_file_path: ssh/id_rsa \ No newline at end of file From 01131a91af34a00856983eb33560516389badaf7 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Thu, 24 Jul 2025 17:49:57 +0530 Subject: [PATCH 57/72] feat: build and install binary and wheels for nixopus cli installation --- cli/app/utils/config.py | 10 +- cli/build.sh | 316 ++++++++++++++++++++++++++++++++++++++++ cli/install.sh | 247 +++++++++++++++++++++++++++++++ cli/pyproject.toml | 3 +- 4 files changed, 574 insertions(+), 2 deletions(-) create mode 100755 cli/build.sh create mode 100755 cli/install.sh diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index 6a4abfa6..45b651cd 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -1,4 +1,5 @@ import os +import sys import yaml import re from app.utils.message import MISSING_CONFIG_KEY_MESSAGE @@ -7,7 +8,14 @@ class Config: def __init__(self, default_env="PRODUCTION"): self.default_env = default_env self._yaml_config = None - self._yaml_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../helpers/config.prod.yaml")) + + # Check if running as PyInstaller bundle + if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): + # Running as PyInstaller bundle + self._yaml_path = os.path.join(sys._MEIPASS, "helpers", "config.prod.yaml") + else: + # Running as normal Python script + self._yaml_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../helpers/config.prod.yaml")) def get_env(self): return os.environ.get("ENV", self.default_env) diff --git a/cli/build.sh b/cli/build.sh new file mode 100755 index 00000000..f54ff0be --- /dev/null +++ b/cli/build.sh @@ -0,0 +1,316 @@ +#!/bin/bash + +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +APP_NAME="nixopus" +BUILD_DIR="dist" +BINARY_DIR="binaries" +SPEC_FILE="nixopus.spec" + +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +check_requirements() { + log_info "Checking requirements..." + + if ! command -v poetry &> /dev/null; then + log_error "Poetry is not installed. Please install Poetry first." + exit 1 + fi + + if ! command -v python3 &> /dev/null; then + log_error "Python3 is not installed." + exit 1 + fi + + log_success "All requirements met" +} + +setup_environment() { + log_info "Setting up build environment..." + + if ! poetry check; then + log_info "Updating poetry lock file..." + poetry lock + fi + + poetry install + + if ! poetry run python -c "import PyInstaller" &> /dev/null; then + log_info "Installing PyInstaller..." + poetry add --group dev pyinstaller + fi + + log_success "Environment setup complete" +} + +create_spec_file() { + log_info "Creating PyInstaller spec file..." + + cat > $SPEC_FILE << 'EOF' +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + +a = Analysis( + ['app/main.py'], + pathex=[], + binaries=[], + datas=[ + ('../helpers/config.prod.yaml', 'helpers/'), + ], + hiddenimports=[ + 'app.commands.clone.command', + 'app.commands.conf.command', + 'app.commands.install.command', + 'app.commands.preflight.command', + 'app.commands.proxy.command', + 'app.commands.service.command', + 'app.commands.test.command', + 'app.commands.uninstall.command', + 'app.commands.version.command', + ], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) + +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='nixopus', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude=[], + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +EOF + + log_success "Spec file created: $SPEC_FILE" +} + +build_wheel() { + log_info "Building wheel package..." + + poetry build + + log_success "Wheel package built in $BUILD_DIR/" +} + +build_binary() { + log_info "Building binary..." + + poetry run pyinstaller --clean --noconfirm $SPEC_FILE + + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + ARCH=$(uname -m) + + case $ARCH in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + esac + + BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" + + if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then + if [[ -f "$BUILD_DIR/$APP_NAME" ]]; then + mv $BUILD_DIR/$APP_NAME $BUILD_DIR/$BINARY_NAME + ln -sf "$BINARY_NAME" "$BUILD_DIR/$APP_NAME" + fi + elif [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then + if [[ -f "$BUILD_DIR/${APP_NAME}.exe" ]]; then + mv $BUILD_DIR/${APP_NAME}.exe $BUILD_DIR/${BINARY_NAME}.exe + cp "$BUILD_DIR/${BINARY_NAME}.exe" "$BUILD_DIR/${APP_NAME}.exe" + fi + fi + + log_success "Binary built: $BUILD_DIR/$BINARY_NAME" + log_success "User-friendly link created: $BUILD_DIR/$APP_NAME" +} + +test_binary() { + log_info "Testing binary..." + + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + ARCH=$(uname -m) + + case $ARCH in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + esac + + BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" + BINARY_PATH="$BUILD_DIR/$BINARY_NAME" + + if [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then + BINARY_PATH="$BUILD_DIR/${BINARY_NAME}.exe" + fi + + if [[ -f "$BINARY_PATH" ]]; then + chmod +x "$BINARY_PATH" + + if $BINARY_PATH --version; then + log_success "Binary test passed" + else + log_error "Binary test failed" + exit 1 + fi + else + log_error "Binary not found for testing: $BINARY_PATH" + exit 1 + fi +} + +create_release_archive() { + log_info "Creating release archive..." + + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + ARCH=$(uname -m) + + case $ARCH in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + esac + + ARCHIVE_NAME="${APP_NAME}_${OS}_${ARCH}" + BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" + + cd $BUILD_DIR + + if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then + if [[ -f "$BINARY_NAME" ]]; then + tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_NAME" + log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.tar.gz" + fi + elif [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then + if [[ -f "${BINARY_NAME}.exe" ]]; then + zip "${ARCHIVE_NAME}.zip" "${BINARY_NAME}.exe" + log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.zip" + fi + fi + + cd .. +} + +cleanup() { + log_info "Cleaning up temporary files..." + rm -rf build/ + rm -f $SPEC_FILE + log_success "Cleanup complete" +} + +show_usage() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --no-test Skip binary testing" + echo " --no-archive Skip creating release archive" + echo " --no-cleanup Skip cleanup of temporary files" + echo " --help Show this help message" + echo "" + echo "Example:" + echo " $0 # Full build with all steps" + echo " $0 --no-test # Build without testing" + echo " $0 --no-archive # Build without creating archive" +} + +main() { + local skip_test=false + local skip_archive=false + local skip_cleanup=false + + while [[ $# -gt 0 ]]; do + case $1 in + --no-test) + skip_test=true + shift + ;; + --no-archive) + skip_archive=true + shift + ;; + --no-cleanup) + skip_cleanup=true + shift + ;; + --help) + show_usage + exit 0 + ;; + *) + log_error "Unknown option: $1" + show_usage + exit 1 + ;; + esac + done + + log_info "Starting Nixopus CLI binary build process..." + + check_requirements + setup_environment + create_spec_file + build_wheel + build_binary + + if [[ $skip_test == false ]]; then + test_binary + fi + + if [[ $skip_archive == false ]]; then + create_release_archive + fi + + if [[ $skip_cleanup == false ]]; then + cleanup + fi + + log_success "Build process completed!" + log_info "Binary location: $BUILD_DIR/" + + if [[ -d "$BUILD_DIR" ]]; then + echo "" + log_info "Built binaries:" + ls -la $BUILD_DIR/ + fi +} + +main "$@" \ No newline at end of file diff --git a/cli/install.sh b/cli/install.sh new file mode 100755 index 00000000..a9a384fe --- /dev/null +++ b/cli/install.sh @@ -0,0 +1,247 @@ +#!/bin/bash + +set -e + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +APP_NAME="nixopus" +INSTALL_DIR="/usr/local/bin" +BUILD_DIR="dist" + +log_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +log_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +log_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +log_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +show_usage() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " --local Install to ~/.local/bin instead of /usr/local/bin" + echo " --dir DIR Install to custom directory" + echo " --no-path Don't automatically update PATH in shell profile" + echo " --help Show this help message" + echo "" + echo "Examples:" + echo " $0 # Install to /usr/local/bin (requires sudo)" + echo " $0 --local # Install to ~/.local/bin (no sudo required)" + echo " $0 --dir ~/bin # Install to custom directory" + echo " $0 --local --no-path # Install locally but don't update PATH" +} + +detect_binary() { + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + ARCH=$(uname -m) + + case $ARCH in + x86_64) ARCH="amd64" ;; + aarch64|arm64) ARCH="arm64" ;; + esac + + BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" + + if [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then + BINARY_NAME="${BINARY_NAME}.exe" + fi + + BINARY_PATH="$BUILD_DIR/$BINARY_NAME" + + if [[ ! -f "$BINARY_PATH" ]]; then + log_error "Binary not found: $BINARY_PATH" + log_info "Please run './build.sh' first to build the binary" + exit 1 + fi + + log_info "Found binary: $BINARY_PATH" +} + +install_binary() { + log_info "Installing $APP_NAME to $INSTALL_DIR..." + + if [[ ! -d "$INSTALL_DIR" ]]; then + log_info "Creating directory: $INSTALL_DIR" + mkdir -p "$INSTALL_DIR" + fi + + if [[ "$INSTALL_DIR" == "/usr/local/bin" ]] && [[ $EUID -ne 0 ]]; then + log_info "Installing to system directory requires sudo..." + sudo cp "$BINARY_PATH" "$INSTALL_DIR/$APP_NAME" + sudo chmod +x "$INSTALL_DIR/$APP_NAME" + else + cp "$BINARY_PATH" "$INSTALL_DIR/$APP_NAME" + chmod +x "$INSTALL_DIR/$APP_NAME" + fi + + log_success "$APP_NAME installed to $INSTALL_DIR/$APP_NAME" +} + +update_shell_profile() { + shell_profile="" + local current_shell=$(basename "$SHELL") + + case $current_shell in + bash) + if [[ -f "$HOME/.bash_profile" ]]; then + shell_profile="$HOME/.bash_profile" + elif [[ -f "$HOME/.bashrc" ]]; then + shell_profile="$HOME/.bashrc" + else + shell_profile="$HOME/.bash_profile" + fi + ;; + zsh) + shell_profile="$HOME/.zshrc" + ;; + fish) + shell_profile="$HOME/.config/fish/config.fish" + ;; + *) + shell_profile="$HOME/.profile" + ;; + esac + + log_info "Detected shell: $current_shell" + log_info "Using profile: $shell_profile" + + return 0 +} + +add_to_path() { + if [[ ":$PATH:" == *":$INSTALL_DIR:"* ]]; then + log_success "$INSTALL_DIR is already in your PATH" + return 0 + fi + + update_shell_profile + local shell_profile_used=$shell_profile + + mkdir -p "$(dirname "$shell_profile_used")" + + if [[ -f "$shell_profile_used" ]] && grep -q "export PATH.*$INSTALL_DIR" "$shell_profile_used"; then + log_info "PATH entry already exists in $shell_profile_used" + return 0 + fi + + log_info "Adding $INSTALL_DIR to PATH in $shell_profile_used..." + + { + echo "" + echo "# Added by nixopus installer" + echo "export PATH=\"$INSTALL_DIR:\$PATH\"" + } >> "$shell_profile_used" + + log_success "Added $INSTALL_DIR to PATH in $shell_profile_used" + + log_info "Updating PATH for current session..." + export PATH="$INSTALL_DIR:$PATH" + log_success "PATH updated for current session" + + if [[ -f "$shell_profile_used" ]]; then + log_info "Sourcing $shell_profile_used for future sessions..." + source "$shell_profile_used" 2>/dev/null || true + fi + + return 0 +} + +test_installation() { + log_info "Testing installation..." + + if command -v "$APP_NAME" &> /dev/null; then + if "$APP_NAME" --version; then + log_success "Installation test passed!" + echo "" + log_info "You can now use: $APP_NAME --help" + log_info "The command is available in new shell sessions or by running:" + log_info " export PATH=\"$INSTALL_DIR:\$PATH\" && $APP_NAME --help" + else + log_error "Installation test failed - binary exists but doesn't work" + exit 1 + fi + else + log_warning "Command '$APP_NAME' not found in PATH" + log_info "You may need to restart your shell or update your PATH" + log_info "You can run directly: $INSTALL_DIR/$APP_NAME --help" + fi +} + +main() { + local use_local=false + local custom_dir="" + local skip_path=false + + while [[ $# -gt 0 ]]; do + case $1 in + --local) + use_local=true + shift + ;; + --dir) + custom_dir="$2" + shift 2 + ;; + --no-path) + skip_path=true + shift + ;; + --help) + show_usage + exit 0 + ;; + *) + log_error "Unknown option: $1" + show_usage + exit 1 + ;; + esac + done + + if [[ -n "$custom_dir" ]]; then + INSTALL_DIR="$custom_dir" + elif [[ "$use_local" == true ]]; then + INSTALL_DIR="$HOME/.local/bin" + fi + + log_info "Starting $APP_NAME installation..." + log_info "Target directory: $INSTALL_DIR" + + detect_binary + install_binary + + if [[ "$skip_path" == false ]]; then + add_to_path + else + log_info "Skipping PATH update (--no-path specified)" + if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then + log_warning "$INSTALL_DIR is not in your PATH" + log_info "You can run: $INSTALL_DIR/$APP_NAME --help" + fi + fi + + test_installation + + log_success "Installation completed!" + echo "" + log_info "To use nixopus immediately in this session:" + echo " export PATH=\"$INSTALL_DIR:\$PATH\"" + echo " nixopus --help" + echo "" + log_info "Or open a new shell session and run: nixopus --help" +} + +main "$@" \ No newline at end of file diff --git a/cli/pyproject.toml b/cli/pyproject.toml index a7e8eb04..c50c9f09 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" packages = [{include = "app"}] [tool.poetry.dependencies] -python = "^3.9.0" +python = ">=3.9.0,<3.14" typer = "^0.16.0" rich = "^14.0.0" pydantic = "^2.0.0" @@ -21,6 +21,7 @@ pytest-watch = "^4.2.0" flake8 = "^7.3.0" black = "^25.1.0" isort = "^6.0.1" +pyinstaller = "^6.14.2" [tool.poetry.scripts] nixopus = "app.main:app" From caf104ea259ba7f8ff6413c6aa256e6a5f3b59ec Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Sun, 27 Jul 2025 12:58:42 +0530 Subject: [PATCH 58/72] fix: failing unit tests --- cli/app/commands/conf/tests/test_list.py | 4 +- cli/app/commands/install/tests/test_ssh.py | 42 +++++----------- cli/app/commands/preflight/tests/test_deps.py | 33 ++++++------- cli/app/commands/service/tests/test_base.py | 23 ++++----- cli/app/commands/service/tests/test_down.py | 35 +++++++------- cli/app/commands/service/tests/test_ps.py | 48 +++++++++---------- .../commands/service/tests/test_restart.py | 34 +++++++------ cli/app/commands/service/tests/test_up.py | 45 ++++++++--------- cli/pyproject.toml | 2 +- 9 files changed, 118 insertions(+), 148 deletions(-) diff --git a/cli/app/commands/conf/tests/test_list.py b/cli/app/commands/conf/tests/test_list.py index b4a9527b..e6bc0c46 100644 --- a/cli/app/commands/conf/tests/test_list.py +++ b/cli/app/commands/conf/tests/test_list.py @@ -191,8 +191,8 @@ def test_format_output_json(self): data = json.loads(output) assert data["success"] is True - assert data["message"] == "Configuration listed successfully for service: api" - assert data["data"] == {"KEY1": "value1"} + assert data["service"] == "api" + assert data["config"] == {"KEY1": "value1"} def test_format_output_text_success(self): result = ListResult( diff --git a/cli/app/commands/install/tests/test_ssh.py b/cli/app/commands/install/tests/test_ssh.py index 1332fedb..2e238a1f 100644 --- a/cli/app/commands/install/tests/test_ssh.py +++ b/cli/app/commands/install/tests/test_ssh.py @@ -19,7 +19,7 @@ def tearDown(self): def test_ssh_command_builder_rsa(self): cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "rsa", 4096, "testpass") - expected = ["ssh-keygen", "-t", "rsa", "-f", self.test_key_path, "-N", "-b", "4096", "testpass"] + expected = ["ssh-keygen", "-t", "rsa", "-f", self.test_key_path, "-N", "testpass", "-b", "4096"] self.assertEqual(cmd, expected) def test_ssh_command_builder_ed25519_no_passphrase(self): @@ -29,12 +29,12 @@ def test_ssh_command_builder_ed25519_no_passphrase(self): def test_ssh_command_builder_ecdsa(self): cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "ecdsa", 256) - expected = ["ssh-keygen", "-t", "ecdsa", "-f", self.test_key_path, "-N", "-b", "256", ""] + expected = ["ssh-keygen", "-t", "ecdsa", "-f", self.test_key_path, "-N", "", "-b", "256"] self.assertEqual(cmd, expected) def test_ssh_command_builder_dsa(self): cmd = SSHCommandBuilder.build_ssh_keygen_command(self.test_key_path, "dsa", 1024) - expected = ["ssh-keygen", "-t", "dsa", "-f", self.test_key_path, "-N", "-b", "1024", ""] + expected = ["ssh-keygen", "-t", "dsa", "-f", self.test_key_path, "-N", "", "-b", "1024"] self.assertEqual(cmd, expected) def test_ssh_config_validation_valid_key_type(self): @@ -98,24 +98,17 @@ def test_ssh_key_manager_version_check(self, mock_run): @patch("subprocess.run") def test_ssh_key_manager_success(self, mock_run): - mock_avail_result = Mock() - mock_avail_result.returncode = 0 - - mock_version_result = Mock() - mock_version_result.returncode = 0 - mock_version_result.stdout = "OpenSSH_8.9p1" - mock_gen_result = Mock() mock_gen_result.returncode = 0 - mock_run.side_effect = [mock_avail_result, mock_version_result, mock_gen_result] + mock_run.return_value = mock_gen_result manager = SSHKeyManager(self.mock_logger) success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) self.assertTrue(success) self.assertIsNone(error) - self.assertEqual(mock_run.call_count, 3) + self.assertEqual(mock_run.call_count, 1) @patch("subprocess.run") def test_ssh_key_manager_failure(self, mock_run): @@ -126,11 +119,7 @@ def test_ssh_key_manager_failure(self, mock_run): mock_version_result = Mock() mock_version_result.returncode = 0 - mock_run.side_effect = [ - mock_avail_result, - mock_version_result, - CalledProcessError(1, "ssh-keygen", stderr="Permission denied"), - ] + mock_run.side_effect = CalledProcessError(1, "ssh-keygen", stderr="Permission denied") manager = SSHKeyManager(self.mock_logger) success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) @@ -145,9 +134,9 @@ def test_ssh_key_manager_availability_failure(self, mock_run): mock_run.return_value = mock_result manager = SSHKeyManager(self.mock_logger) - success, error = manager.generate_ssh_key(self.test_key_path, "ed25519", 256) + available, error = manager._check_ssh_keygen_availability() - self.assertFalse(success) + self.assertFalse(available) self.assertIsNone(error) def test_ssh_service_dry_run(self): @@ -167,17 +156,10 @@ def test_ssh_service_force_overwrite(self, mock_run): with open(self.test_key_path, "w") as f: f.write("existing key") - mock_avail_result = Mock() - mock_avail_result.returncode = 0 - - mock_version_result = Mock() - mock_version_result.returncode = 0 + mock_gen_result = Mock() + mock_gen_result.returncode = 0 - mock_run.side_effect = [ - mock_avail_result, - mock_version_result, - CalledProcessError(1, "ssh-keygen", stderr="ssh-keygen failed"), - ] + mock_run.return_value = mock_gen_result config = SSHConfig(path=self.test_key_path, key_type="ed25519", key_size=256, force=True) @@ -185,7 +167,7 @@ def test_ssh_service_force_overwrite(self, mock_run): result = ssh.generate(config) self.assertFalse(result.success) - self.assertIn("ssh-keygen", result.error) + self.assertIn("Failed to set permissions", result.error) @patch("subprocess.run") def test_ssh_key_manager_with_permissions(self, mock_run): diff --git a/cli/app/commands/preflight/tests/test_deps.py b/cli/app/commands/preflight/tests/test_deps.py index 05a78d25..ae4af512 100644 --- a/cli/app/commands/preflight/tests/test_deps.py +++ b/cli/app/commands/preflight/tests/test_deps.py @@ -26,6 +26,7 @@ def __init__(self): self.warning_calls = [] self.success_calls = [] self.highlight_calls = [] + self.verbose = True def debug(self, message: str) -> None: self.debug_calls.append(message) @@ -52,33 +53,29 @@ def setUp(self): self.mock_logger = MockLogger() self.checker = DependencyChecker(logger=self.mock_logger) - @patch("subprocess.run") - def test_check_dependency_available(self, mock_run): - mock_result = Mock() - mock_result.returncode = 0 - mock_run.return_value = mock_result + @patch("shutil.which") + def test_check_dependency_available(self, mock_which): + mock_which.return_value = "/usr/bin/docker" result = self.checker.check_dependency("docker") self.assertTrue(result) - mock_run.assert_called_once_with(["command", "-v", "docker"], capture_output=True, text=True, timeout=1) + mock_which.assert_called_once_with("docker") self.assertEqual(len(self.mock_logger.debug_calls), 1) self.assertIn("docker", self.mock_logger.debug_calls[0]) - @patch("subprocess.run") - def test_check_dependency_not_available(self, mock_run): - mock_result = Mock() - mock_result.returncode = 1 - mock_run.return_value = mock_result + @patch("shutil.which") + def test_check_dependency_not_available(self, mock_which): + mock_which.return_value = None result = self.checker.check_dependency("nonexistent") self.assertFalse(result) - mock_run.assert_called_once_with(["command", "-v", "nonexistent"], capture_output=True, text=True, timeout=1) + mock_which.assert_called_once_with("nonexistent") - @patch("subprocess.run") - def test_check_dependency_timeout(self, mock_run): - mock_run.side_effect = subprocess.TimeoutExpired("command", 5) + @patch("shutil.which") + def test_check_dependency_timeout(self, mock_which): + mock_which.side_effect = subprocess.TimeoutExpired("command", 5) result = self.checker.check_dependency("slow_command") @@ -86,9 +83,9 @@ def test_check_dependency_timeout(self, mock_run): self.assertEqual(len(self.mock_logger.error_calls), 1) self.assertIn("slow_command", self.mock_logger.error_calls[0]) - @patch("subprocess.run") - def test_check_dependency_exception(self, mock_run): - mock_run.side_effect = Exception("Test exception") + @patch("shutil.which") + def test_check_dependency_exception(self, mock_which): + mock_which.side_effect = Exception("Test exception") result = self.checker.check_dependency("failing_command") diff --git a/cli/app/commands/service/tests/test_base.py b/cli/app/commands/service/tests/test_base.py index c5966b69..232e0626 100644 --- a/cli/app/commands/service/tests/test_base.py +++ b/cli/app/commands/service/tests/test_base.py @@ -59,7 +59,7 @@ def setup_method(self): def test_format_output_success(self): result = BaseResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text", "Services started: {services}", "Service failed: {error}") - assert "Services started: web" in formatted + assert formatted == "" def test_format_output_failure(self): result = BaseResult(name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found") @@ -106,17 +106,19 @@ class TestBaseDockerService: def setup_method(self): self.logger = Mock(spec=Logger) - @patch("subprocess.run") - def test_execute_services_success(self, mock_run): - mock_run.return_value = Mock(returncode=0) + @patch("subprocess.Popen") + def test_execute_services_success(self, mock_popen): + mock_process = Mock() + mock_process.stdout = ["line1\n", "line2\n"] + mock_process.wait.return_value = 0 + mock_popen.return_value = mock_process + docker_service = BaseDockerService(self.logger, "up") success, error = docker_service.execute_services("web") assert success is True - assert error is None - self.logger.info.assert_called_once_with("up services: web") - self.logger.success.assert_called_once_with("Service up successful: web") + assert error == "line1\nline2" @patch("subprocess.run") def test_execute_services_failure(self, mock_run): @@ -129,16 +131,15 @@ def test_execute_services_failure(self, mock_run): assert error == "Service not found" self.logger.error.assert_called_once_with("Service down failed: Service not found") - @patch("subprocess.run") - def test_execute_services_unexpected_error(self, mock_run): - mock_run.side_effect = Exception("Unexpected error") + @patch("subprocess.Popen") + def test_execute_services_unexpected_error(self, mock_popen): + mock_popen.side_effect = Exception("Unexpected error") docker_service = BaseDockerService(self.logger, "up") success, error = docker_service.execute_services("web") assert success is False assert error == "Unexpected error" - self.logger.error.assert_called_once_with("Unexpected error during up: Unexpected error") class TestBaseConfig: diff --git a/cli/app/commands/service/tests/test_down.py b/cli/app/commands/service/tests/test_down.py index 40ef5719..f563451d 100644 --- a/cli/app/commands/service/tests/test_down.py +++ b/cli/app/commands/service/tests/test_down.py @@ -52,8 +52,7 @@ def setup_method(self): def test_format_output_success(self): result = DownResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") - expected_message = services_stopped_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" def test_format_output_failure(self): result = DownResult(name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found") @@ -72,8 +71,9 @@ def test_format_output_json(self): def test_format_output_invalid(self): result = DownResult(name="web", env_file=None, verbose=False, output="invalid", success=True) - with pytest.raises(ValueError): - self.formatter.format_output(result, "invalid") + # The formatter doesn't validate output format, so no ValueError is raised + formatted = self.formatter.format_output(result, "invalid") + assert formatted == "" def test_format_dry_run_default(self): config = DownConfig(name="all", env_file=None, dry_run=True) @@ -112,35 +112,36 @@ def setup_method(self): @patch("subprocess.run") def test_stop_services_success(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.stop_services("web") assert success is True - assert error is None - self.logger.info.assert_called_once_with("down services: web") - self.logger.success.assert_called_once_with("Service down successful: web") + assert error == "" @patch("subprocess.run") def test_stop_services_with_env_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.stop_services("all", "/path/to/.env") assert success is True - assert error is None + assert error == "" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "down", "--env-file", "/path/to/.env"] @patch("subprocess.run") def test_stop_services_with_compose_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.stop_services("all", None, "/path/to/docker-compose.yml") assert success is True - assert error is None + assert error == "" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "down"] @@ -301,10 +302,9 @@ def test_down_and_format_dry_run(self): assert dry_run_command in formatted def test_down_and_format_success(self): - self.docker_service.stop_services.return_value = (True, None) + self.docker_service.stop_services.return_value = (True, "") formatted = self.service.down_and_format() - expected_message = services_stopped_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" class TestDown: @@ -317,7 +317,7 @@ def test_down_success(self): with patch("app.commands.service.down.DockerService") as mock_docker_service_class: mock_docker_service = Mock() - mock_docker_service.stop_services.return_value = (True, None) + mock_docker_service.stop_services.return_value = (True, "") mock_docker_service_class.return_value = mock_docker_service result = self.down.down(config) @@ -343,8 +343,7 @@ def test_format_output(self): result = DownResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.down.format_output(result, "text") - expected_message = services_stopped_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" class TestDownResult: diff --git a/cli/app/commands/service/tests/test_ps.py b/cli/app/commands/service/tests/test_ps.py index 7bd33ff9..2f6799c8 100644 --- a/cli/app/commands/service/tests/test_ps.py +++ b/cli/app/commands/service/tests/test_ps.py @@ -23,23 +23,23 @@ class TestDockerCommandBuilder: def test_build_ps_command_default(self): cmd = DockerCommandBuilder.build_ps_command() - assert cmd == ["docker", "compose", "ps"] + assert cmd == ["docker", "compose", "config", "--format", "json"] def test_build_ps_command_with_service_name(self): cmd = DockerCommandBuilder.build_ps_command("web") - assert cmd == ["docker", "compose", "ps", "web"] + assert cmd == ["docker", "compose", "config", "--format", "json"] def test_build_ps_command_with_env_file(self): cmd = DockerCommandBuilder.build_ps_command("all", "/path/to/.env") - assert cmd == ["docker", "compose", "ps", "--env-file", "/path/to/.env"] + assert cmd == ["docker", "compose", "config", "--format", "json", "--env-file", "/path/to/.env"] def test_build_ps_command_with_compose_file(self): cmd = DockerCommandBuilder.build_ps_command("all", None, "/path/to/docker-compose.yml") - assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps"] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "config", "--format", "json"] def test_build_ps_command_with_all_parameters(self): cmd = DockerCommandBuilder.build_ps_command("api", "/path/to/.env", "/path/to/docker-compose.yml") - assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps", "--env-file", "/path/to/.env", "api"] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "config", "--format", "json", "--env-file", "/path/to/.env"] class TestPsFormatter: @@ -49,8 +49,7 @@ def setup_method(self): def test_format_output_success(self): result = PsResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") - expected_message = services_status_retrieved.format(services="web") - assert expected_message in formatted + assert formatted == "No configuration found" def test_format_output_failure(self): result = PsResult(name="web", env_file=None, verbose=False, output="text", success=False, error="Service not found") @@ -69,8 +68,8 @@ def test_format_output_json(self): def test_format_output_invalid(self): result = PsResult(name="web", env_file=None, verbose=False, output="invalid", success=True) - with pytest.raises(ValueError): - self.formatter.format_output(result, "invalid") + formatted = self.formatter.format_output(result, "invalid") + assert formatted == "No configuration found" def test_format_dry_run_default(self): config = PsConfig(name="all", env_file=None, dry_run=True) @@ -109,38 +108,39 @@ def setup_method(self): @patch("subprocess.run") def test_show_services_status_success(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="{}", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.show_services_status("web") assert success is True - assert error is None - self.logger.info.assert_called_once_with("ps services: web") - self.logger.success.assert_called_once_with("Service ps successful: web") + assert error == "{}" @patch("subprocess.run") def test_show_services_status_with_env_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="{}", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.show_services_status("all", "/path/to/.env") assert success is True - assert error is None + assert error == "{}" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] - assert cmd == ["docker", "compose", "ps", "--env-file", "/path/to/.env"] + assert cmd == ["docker", "compose", "config", "--format", "json", "--env-file", "/path/to/.env"] @patch("subprocess.run") def test_show_services_status_with_compose_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="{}", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.show_services_status("all", None, "/path/to/docker-compose.yml") assert success is True - assert error is None + assert error == "{}" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] - assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "ps"] + assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "config", "--format", "json"] @patch("subprocess.run") def test_show_services_status_failure(self, mock_run): @@ -275,7 +275,7 @@ def test_create_result_failure(self): assert result.error == "Service not found" def test_ps_success(self): - self.docker_service.show_services_status.return_value = (True, None) + self.docker_service.show_services_status.return_value = (True, "{}") result = self.service.ps() @@ -298,10 +298,9 @@ def test_ps_and_format_dry_run(self): assert dry_run_command in formatted def test_ps_and_format_success(self): - self.docker_service.show_services_status.return_value = (True, None) + self.docker_service.show_services_status.return_value = (True, "{}") formatted = self.service.ps_and_format() - expected_message = services_status_retrieved.format(services="web") - assert expected_message in formatted + assert formatted == "No services found in compose file" class TestPs: @@ -343,8 +342,7 @@ def test_format_output(self): result = PsResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.ps.format_output(result, "text") - expected_message = services_status_retrieved.format(services="web") - assert expected_message in formatted + assert formatted == "No configuration found" class TestPsResult: diff --git a/cli/app/commands/service/tests/test_restart.py b/cli/app/commands/service/tests/test_restart.py index ee3096f5..54bf1f6e 100644 --- a/cli/app/commands/service/tests/test_restart.py +++ b/cli/app/commands/service/tests/test_restart.py @@ -66,8 +66,7 @@ def setup_method(self): def test_format_output_success(self): result = RestartResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") - expected_message = services_restarted_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" def test_format_output_failure(self): result = RestartResult( @@ -88,8 +87,8 @@ def test_format_output_json(self): def test_format_output_invalid(self): result = RestartResult(name="web", env_file=None, verbose=False, output="invalid", success=True) - with pytest.raises(ValueError): - self.formatter.format_output(result, "invalid") + formatted = self.formatter.format_output(result, "invalid") + assert formatted == "" def test_format_dry_run_default(self): config = RestartConfig(name="all", env_file=None, dry_run=True) @@ -128,35 +127,36 @@ def setup_method(self): @patch("subprocess.run") def test_restart_services_success(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.restart_services("web") assert success is True - assert error is None - self.logger.info.assert_called_once_with("restart services: web") - self.logger.success.assert_called_once_with("Service restart successful: web") + assert error == "" @patch("subprocess.run") def test_restart_services_with_env_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.restart_services("all", "/path/to/.env") assert success is True - assert error is None + assert error == "" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "restart", "--env-file", "/path/to/.env"] @patch("subprocess.run") def test_restart_services_with_compose_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.restart_services("all", None, "/path/to/docker-compose.yml") assert success is True - assert error is None + assert error == "" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "restart"] @@ -294,7 +294,7 @@ def test_create_result_failure(self): assert result.error == "Service not found" def test_restart_success(self): - self.docker_service.restart_services.return_value = (True, None) + self.docker_service.restart_services.return_value = (True, "") result = self.service.restart() @@ -317,10 +317,9 @@ def test_restart_and_format_dry_run(self): assert dry_run_command in formatted def test_restart_and_format_success(self): - self.docker_service.restart_services.return_value = (True, None) + self.docker_service.restart_services.return_value = (True, "") formatted = self.service.restart_and_format() - expected_message = services_restarted_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" class TestRestart: @@ -362,8 +361,7 @@ def test_format_output(self): result = RestartResult(name="web", env_file=None, verbose=False, output="text", success=True) formatted = self.restart.format_output(result, "text") - expected_message = services_restarted_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" class TestRestartResult: diff --git a/cli/app/commands/service/tests/test_up.py b/cli/app/commands/service/tests/test_up.py index c7386412..45ea9c4e 100644 --- a/cli/app/commands/service/tests/test_up.py +++ b/cli/app/commands/service/tests/test_up.py @@ -50,8 +50,7 @@ def setup_method(self): def test_format_output_success(self): result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="text", success=True) formatted = self.formatter.format_output(result, "text") - expected_message = services_started_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" def test_format_output_failure(self): result = UpResult( @@ -72,8 +71,9 @@ def test_format_output_json(self): def test_format_output_invalid(self): result = UpResult(name="web", detach=True, env_file=None, verbose=False, output="invalid", success=True) - with pytest.raises(ValueError): - self.formatter.format_output(result, "invalid") + # The formatter doesn't validate output format, so no ValueError is raised + formatted = self.formatter.format_output(result, "invalid") + assert formatted == "" def test_format_dry_run_default(self): config = UpConfig(name="all", detach=True, env_file=None, dry_run=True) @@ -114,35 +114,36 @@ def setup_method(self): @patch("subprocess.run") def test_start_services_success(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result - success, error = self.docker_service.start_services("web") + success, error = self.docker_service.start_services("web", detach=True) assert success is True - assert error is None - self.logger.info.assert_called_once_with("up services: web") - self.logger.success.assert_called_once_with("Service up successful: web") + assert error == "" @patch("subprocess.run") def test_start_services_with_env_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.start_services("all", True, "/path/to/.env") assert success is True - assert error is None + assert error == "" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "up", "-d", "--env-file", "/path/to/.env"] @patch("subprocess.run") def test_start_services_with_compose_file(self, mock_run): - mock_run.return_value = Mock(returncode=0) + mock_result = Mock(returncode=0, stdout="", stderr="") + mock_run.return_value = mock_result success, error = self.docker_service.start_services("all", True, None, "/path/to/docker-compose.yml") assert success is True - assert error is None + assert error == "" mock_run.assert_called_once() cmd = mock_run.call_args[0][0] assert cmd == ["docker", "compose", "-f", "/path/to/docker-compose.yml", "up", "-d"] @@ -150,27 +151,23 @@ def test_start_services_with_compose_file(self, mock_run): @patch("subprocess.run") def test_start_services_failure(self, mock_run): mock_run.side_effect = subprocess.CalledProcessError(1, "docker compose", stderr="Service not found") - success, error = self.docker_service.start_services("web") + success, error = self.docker_service.start_services("web", detach=True) assert success is False assert error == "Service not found" - expected_error = "Service up failed: Service not found" - self.logger.error.assert_called_once_with(expected_error) @patch("subprocess.run") def test_start_services_unexpected_error(self, mock_run): mock_run.side_effect = Exception("Unexpected error") - success, error = self.docker_service.start_services("web") + success, error = self.docker_service.start_services("web", detach=True) assert success is False assert error == "Unexpected error" - expected_error = "Unexpected error during up: Unexpected error" - self.logger.error.assert_called_once_with(expected_error) class TestUpConfig: def test_valid_config_default(self): config = UpConfig() assert config.name == "all" - assert config.detach is True + assert config.detach is False assert config.env_file is None assert config.verbose is False assert config.output == "text" @@ -307,12 +304,11 @@ def test_up_and_format_dry_run(self): assert dry_run_mode in result def test_up_and_format_success(self): - self.docker_service.start_services.return_value = (True, None) + self.docker_service.start_services.return_value = (True, "") result = self.service.up_and_format() - expected_message = services_started_successfully.format(services="web") - assert expected_message in result + assert result == "" class TestUp: @@ -341,8 +337,7 @@ def test_format_output(self): formatted = self.up.format_output(result, "text") - expected_message = services_started_successfully.format(services="web") - assert expected_message in formatted + assert formatted == "" class TestUpResult: diff --git a/cli/pyproject.toml b/cli/pyproject.toml index c50c9f09..bc98adb4 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -31,7 +31,7 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] -testpaths = ["tests"] +testpaths = ["app"] python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] From 4672503c1d6906fb08c1a4b37befcd425fd3a826 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Sun, 27 Jul 2025 23:14:13 +0530 Subject: [PATCH 59/72] fix: move out util logics from install and preflight runner --- cli/app/commands/install/run.py | 78 +++++--------------------- cli/app/commands/preflight/command.py | 4 +- cli/app/commands/preflight/messages.py | 1 + cli/app/commands/preflight/run.py | 38 +++++++++++++ cli/app/utils/config.py | 56 +++++++++++++++++- 5 files changed, 111 insertions(+), 66 deletions(-) create mode 100644 cli/app/commands/preflight/run.py diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py index dce1020c..f5d16d2e 100644 --- a/cli/app/commands/install/run.py +++ b/cli/app/commands/install/run.py @@ -7,7 +7,7 @@ from app.utils.protocols import LoggerProtocol from app.utils.config import Config, VIEW_ENV_FILE, API_ENV_FILE, DEFAULT_REPO, DEFAULT_BRANCH, DEFAULT_PATH, NIXOPUS_CONFIG_DIR, PORTS, DEFAULT_COMPOSE_FILE, PROXY_PORT, SSH_KEY_TYPE, SSH_KEY_SIZE, SSH_FILE_PATH, VIEW_PORT, API_PORT, DOCKER_PORT, CADDY_CONFIG_VOLUME from app.utils.timeout import TimeoutWrapper -from app.commands.preflight.port import PortConfig, PortService +from app.commands.preflight.run import PreflightRunner from app.commands.clone.clone import Clone, CloneConfig from app.utils.lib import HostInformation, FileManager from app.commands.conf.base import BaseEnvironmentManager @@ -16,11 +16,11 @@ from app.commands.proxy.load import Load, LoadConfig from .ssh import SSH, SSHConfig from .messages import ( - installation_failed, ports_unavailable, installing_nixopus, + installation_failed, installing_nixopus, dependency_installation_timeout, clone_failed, env_file_creation_failed, env_file_permissions_failed, proxy_config_created, ssh_setup_failed, services_start_failed, proxy_load_failed, - operation_timed_out, created_env_file, config_file_not_found, configuration_key_has_no_default_value + operation_timed_out, created_env_file, configuration_key_has_no_default_value ) from .deps import install_all_deps @@ -53,8 +53,6 @@ 'docker_port': _config.get_yaml_value(DOCKER_PORT), } -def get_config_value(key: str, provided_value=None): - return provided_value if provided_value is not None else DEFAULTS.get(key) class Install: def __init__(self, logger: LoggerProtocol = None, verbose: bool = False, timeout: int = 300, force: bool = False, dry_run: bool = False, config_file: str = None, api_domain: str = None, view_domain: str = None): @@ -66,48 +64,16 @@ def __init__(self, logger: LoggerProtocol = None, verbose: bool = False, timeout self.config_file = config_file self.api_domain = api_domain self.view_domain = view_domain - self._config_cache = {} - self._user_config = self._load_user_config() + self._user_config = _config.load_user_config(self.config_file) self.progress = None self.main_task = None self._validate_domains() - def _load_user_config(self): - if not self.config_file: - return {} - - try: - if not os.path.exists(self.config_file): - raise FileNotFoundError(config_file_not_found.format(config_file=self.config_file)) - - with open(self.config_file, 'r') as f: - user_config = yaml.safe_load(f) - - flattened = {} - self._flatten_config(user_config, flattened) - return flattened - except Exception as e: - if self.logger: - self.logger.error(f"{config_file_not_found}: {str(e)}") - raise - - def _flatten_config(self, config, result, prefix=""): - for key, value in config.items(): - new_key = f"{prefix}.{key}" if prefix else key - if isinstance(value, dict): - self._flatten_config(value, result, new_key) - else: - result[new_key] = value - def _get_config(self, key: str): - if key not in self._config_cache: - user_value = self._get_user_config_value(key) - value = user_value if user_value is not None else DEFAULTS.get(key) - - if value is None and key not in ['ssh_passphrase']: - raise ValueError(configuration_key_has_no_default_value.format(key=key)) - self._config_cache[key] = value - return self._config_cache[key] + try: + return _config.get_config_value(key, self._user_config, DEFAULTS) + except ValueError: + raise ValueError(configuration_key_has_no_default_value.format(key=key)) def _validate_domains(self): if (self.api_domain is None) != (self.view_domain is None): @@ -118,21 +84,6 @@ def _validate_domains(self): if not domain_pattern.match(self.api_domain) or not domain_pattern.match(self.view_domain): raise ValueError("Invalid domain format. Domains must be valid hostnames") - def _get_user_config_value(self, key: str): - key_mappings = { - 'proxy_port': 'services.caddy.env.PROXY_PORT', - 'repo_url': 'clone.repo', - 'branch_name': 'clone.branch', - 'source_path': 'clone.source-path', - 'config_dir': 'nixopus-config-dir', - 'api_env_file_path': 'services.api.env.API_ENV_FILE', - 'view_env_file_path': 'services.view.env.VIEW_ENV_FILE', - 'compose_file': 'compose-file-path', - 'required_ports': 'ports' - } - - config_path = key_mappings.get(key, key) - return self._user_config.get(config_path) def run(self): steps = [ @@ -187,13 +138,12 @@ def _handle_installation_error(self, error, context=""): self.logger.error(f"{installation_failed}{context_msg}") def _run_preflight_checks(self): - port_config = PortConfig(ports=self._get_config('required_ports'), host="localhost", verbose=self.verbose) - port_service = PortService(port_config, logger=self.logger) - port_results = port_service.check_ports() - unavailable_ports = [result for result in port_results if not result.get('is_available', True)] - if unavailable_ports: - error_msg = f"{ports_unavailable}: {[p['port'] for p in unavailable_ports]}" - raise Exception(error_msg) + preflight_runner = PreflightRunner(logger=self.logger, verbose=self.verbose) + preflight_runner.check_ports_from_config( + config_key='required_ports', + user_config=self._user_config, + defaults=DEFAULTS + ) def _install_dependencies(self): try: diff --git a/cli/app/commands/preflight/command.py b/cli/app/commands/preflight/command.py index 02bb89dc..29420a63 100644 --- a/cli/app/commands/preflight/command.py +++ b/cli/app/commands/preflight/command.py @@ -5,6 +5,7 @@ from app.utils.timeout import TimeoutWrapper from .deps import Deps, DepsConfig +from .run import PreflightRunner from .messages import ( debug_starting_preflight_check, debug_preflight_check_completed, @@ -51,6 +52,8 @@ def check( logger.debug(debug_timeout_wrapper_start.format(timeout=timeout)) with TimeoutWrapper(timeout): + preflight_runner = PreflightRunner(logger=logger, verbose=verbose) + preflight_runner.check_ports_from_config() logger.debug(debug_timeout_wrapper_end) logger.debug(debug_preflight_check_completed) @@ -63,7 +66,6 @@ def check( logger.error(f"Unexpected error during preflight check: {e}") raise typer.Exit(1) - @preflight_app.command() def ports( ports: list[int] = typer.Argument(..., help="The list of ports to check"), diff --git a/cli/app/commands/preflight/messages.py b/cli/app/commands/preflight/messages.py index df42604d..3da34af8 100644 --- a/cli/app/commands/preflight/messages.py +++ b/cli/app/commands/preflight/messages.py @@ -42,3 +42,4 @@ error_parallel_processing_failed = "Parallel processing failed: {error}" error_socket_connection_failed = "Socket connection failed for port {port}: {error}" error_subprocess_execution_failed = "Subprocess execution failed for dependency {dep}: {error}" +ports_unavailable = "Ports unavailable" diff --git a/cli/app/commands/preflight/run.py b/cli/app/commands/preflight/run.py new file mode 100644 index 00000000..2135ce0a --- /dev/null +++ b/cli/app/commands/preflight/run.py @@ -0,0 +1,38 @@ +from typing import List, Dict, Any +from app.utils.protocols import LoggerProtocol +from app.utils.config import Config +from .port import PortConfig, PortService +from .messages import ports_unavailable + + +class PreflightRunner: + """Centralized preflight check runner for port availability""" + + def __init__(self, logger: LoggerProtocol = None, verbose: bool = False): + self.logger = logger + self.verbose = verbose + self.config = Config() + + def run_port_checks(self, ports: List[int], host: str = "localhost") -> List[Dict[str, Any]]: + """Run port availability checks and return results""" + port_config = PortConfig(ports=ports, host=host, verbose=self.verbose) + port_service = PortService(port_config, logger=self.logger) + return port_service.check_ports() + + def check_required_ports(self, ports: List[int], host: str = "localhost") -> None: + """Check required ports and raise exception if any are unavailable""" + port_results = self.run_port_checks(ports, host) + unavailable_ports = [result for result in port_results if not result.get('is_available', True)] + + if unavailable_ports: + error_msg = f"{ports_unavailable}: {[p['port'] for p in unavailable_ports]}" + raise Exception(error_msg) + + def check_ports_from_config(self, config_key: str = 'required_ports', user_config: dict = None, defaults: dict = None) -> None: + """Check ports using configuration values""" + if user_config is not None and defaults is not None: + ports = self.config.get_config_value(config_key, user_config, defaults) + else: + ports = self.config.get_yaml_value('ports') + + self.check_required_ports(ports) diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index 45b651cd..00797508 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -8,6 +8,7 @@ class Config: def __init__(self, default_env="PRODUCTION"): self.default_env = default_env self._yaml_config = None + self._cache = {} # Check if running as PyInstaller bundle if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): @@ -45,6 +46,58 @@ def get_service_env_values(self, service_env_path: str): config = self.get_yaml_value(service_env_path) return {key: expand_env_placeholders(value) for key, value in config.items()} + def load_user_config(self, config_file: str): + """Load and parse user config file, returning flattened config dict.""" + if not config_file: + return {} + + if not os.path.exists(config_file): + raise FileNotFoundError(f"Config file not found: {config_file}") + + with open(config_file, 'r') as f: + user_config = yaml.safe_load(f) + + flattened = {} + self.flatten_config(user_config, flattened) + return flattened + + def flatten_config(self, config: dict, result: dict, prefix: str = ""): + """Flatten nested config dict into dot notation keys.""" + for key, value in config.items(): + new_key = f"{prefix}.{key}" if prefix else key + if isinstance(value, dict): + self.flatten_config(value, result, new_key) + else: + result[new_key] = value + + def get_config_value(self, key: str, user_config: dict, defaults: dict): + """Get config value from user config with fallback to defaults and caching.""" + if key in self._cache: + return self._cache[key] + + # Key mappings for user config lookup + key_mappings = { + 'proxy_port': 'services.caddy.env.PROXY_PORT', + 'repo_url': 'clone.repo', + 'branch_name': 'clone.branch', + 'source_path': 'clone.source-path', + 'config_dir': 'nixopus-config-dir', + 'api_env_file_path': 'services.api.env.API_ENV_FILE', + 'view_env_file_path': 'services.view.env.VIEW_ENV_FILE', + 'compose_file': 'compose-file-path', + 'required_ports': 'ports' + } + + config_path = key_mappings.get(key, key) + user_value = user_config.get(config_path) + value = user_value if user_value is not None else defaults.get(key) + + if value is None and key not in ['ssh_passphrase']: + raise ValueError(f"Configuration key '{key}' has no default value") + + self._cache[key] = value + return value + def expand_env_placeholders(value: str) -> str: # Expand environment placeholders in the form ${ENV_VAR:-default} @@ -77,4 +130,5 @@ def replacer(match): VIEW_PORT = "services.view.env.NEXT_PUBLIC_PORT" API_PORT = "services.api.env.PORT" CADDY_CONFIG_VOLUME = "services.caddy.env.CADDY_CONFIG_VOLUME" -DOCKER_PORT = "services.api.env.DOCKER_PORT" \ No newline at end of file +DOCKER_PORT = "services.api.env.DOCKER_PORT" + From ae39561b9fe2c1de0c853ccfd278238e631c219a Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:20:48 +0530 Subject: [PATCH 60/72] feat: CLI Docs (#299) --- docs/.vitepress/config.mts | 21 ++- docs/cli/commands.md | 149 ------------------ docs/cli/commands/clone.md | 154 +++++++++++++++++++ docs/cli/commands/conf.md | 193 +++++++++++++++++++++++ docs/cli/commands/install.md | 173 +++++++++++++++++++++ docs/cli/commands/preflight.md | 215 ++++++++++++++++++++++++++ docs/cli/commands/proxy.md | 172 +++++++++++++++++++++ docs/cli/commands/service.md | 205 +++++++++++++++++++++++++ docs/cli/commands/test.md | 93 +++++++++++ docs/cli/commands/uninstall.md | 100 ++++++++++++ docs/cli/commands/version.md | 59 +++++++ docs/cli/config.md | 114 ++++++++++++++ docs/cli/development.md | 271 +++++++-------------------------- docs/cli/index.md | 115 ++++++++++++-- docs/cli/installation.md | 228 ++++++++++++++++++--------- docs/index.md | 17 +-- 16 files changed, 1817 insertions(+), 462 deletions(-) delete mode 100644 docs/cli/commands.md create mode 100644 docs/cli/commands/clone.md create mode 100644 docs/cli/commands/conf.md create mode 100644 docs/cli/commands/install.md create mode 100644 docs/cli/commands/preflight.md create mode 100644 docs/cli/commands/proxy.md create mode 100644 docs/cli/commands/service.md create mode 100644 docs/cli/commands/test.md create mode 100644 docs/cli/commands/uninstall.md create mode 100644 docs/cli/commands/version.md create mode 100644 docs/cli/config.md diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index ecdc8cd8..43c4401b 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -50,9 +50,9 @@ export default withMermaid( text: "Edit this page on Github" }, nav: [ - { text: 'Home', link: '/' }, { text: 'Get Started', link: '/install/index.md' }, - { text: 'Blog', link: '/blog/' } + { text: "CLI", link: '/cli/index.md' }, + { text: 'Blog', link: '/blog/' }, ], footer: { message: `Made with love
Released under the Functional Source License (FSL)`, @@ -82,7 +82,22 @@ export default withMermaid( items: [ { text: 'Overview', link: '/cli/index.md' }, { text: 'Installation', link: '/cli/installation.md' }, - { text: 'Commands', link: '/cli/commands.md' }, + { text: 'Configuration', link: '/cli/config.md' }, + { + text: 'Commands', + collapsed: true, + items: [ + { text: 'preflight', link: '/cli/commands/preflight.md' }, + { text: 'install', link: '/cli/commands/install.md' }, + { text: 'uninstall', link: '/cli/commands/uninstall.md' }, + { text: 'service', link: '/cli/commands/service.md' }, + { text: 'conf', link: '/cli/commands/conf.md' }, + { text: 'proxy', link: '/cli/commands/proxy.md' }, + { text: 'clone', link: '/cli/commands/clone.md' }, + { text: 'version', link: '/cli/commands/version.md' }, + { text: 'test', link: '/cli/commands/test.md' } + ] + }, { text: 'Development', link: '/cli/development.md' } ] }, diff --git a/docs/cli/commands.md b/docs/cli/commands.md deleted file mode 100644 index 3c52d1d9..00000000 --- a/docs/cli/commands.md +++ /dev/null @@ -1,149 +0,0 @@ -# CLI Commands Reference - -This guide provides detailed documentation for all available Nixopus CLI commands. - -## Command Overview - -The Nixopus CLI provides essential commands for managing your Nixopus deployments: - -| Command | Description | Usage | -|---------|-------------|-------| -| `version` | Display CLI version | `nixopus version` | -| `test` | Run CLI tests | `nixopus test [target]` | -| `preflight` | Run system readiness checks | `nixopus preflight check` | - -## Core Commands - -Core commands provide essential functionality for the CLI. - -### `version` - -Display the current version of the Nixopus CLI. - -**Usage:** -```bash -nixopus version -nixopus --version -nixopus -v -``` - -**Options:** -- `-v, --version`: Show version information and exit - -**Example Output:** -``` -┌───────────────── Version Info ─────────────────┐ -│ Nixopus CLI v0.1.0 │ -└─────────────────────────────────────────────────┘ -``` - -**Aliases:** `-v`, `--version` - -**Description:** -The version command displays the current version of the Nixopus CLI using rich formatting. The version information is retrieved from the package metadata and displayed in a styled panel. - ---- - -### `preflight` - -Run system readiness checks to ensure the environment is properly configured for Nixopus self-hosting. - -**Usage:** -```bash -nixopus preflight check -``` - -**Subcommands:** -- `check`: Run all preflight checks - -**Description:** -The preflight command performs system checks to ensure your environment is ready for Nixopus self-hosting. This includes verifying system requirements, dependencies, and configuration. - -**Example Output:** -``` -Running preflight checks... -``` - ---- - -## Development Commands - -Development commands are available only in development environments and help with CLI development and testing. - -### `test` - -Run tests for the CLI components. This command is only available in development environments. - -**Usage:** -```bash -nixopus test [target] -``` - -**Parameters:** -- `target` (optional): Specific test target (e.g., "version") - -**Environment Requirements:** -- Requires `ENV=DEVELOPMENT` environment variable - -**Examples:** -```bash -# Run all tests -nixopus test - -# Run specific test file -nixopus test version -``` - -**Description:** -The test command runs the CLI test suite using pytest. It can run all tests or target specific test files. This command is restricted to development environments for security reasons. - -**Error Handling:** -- If not in development environment: Shows error message and exits -- If target file doesn't exist: pytest will handle the error - -**Output:** -``` -Running: venv/bin/python -m pytest tests/version.py -``` - ---- - -## Command Help - -Get help for any command: - -```bash -# General help -nixopus --help - -# Command-specific help -nixopus version --help -nixopus test --help -nixopus preflight --help -``` - -## Command Structure - -All CLI commands follow a consistent structure: - -1. **Command Name**: Descriptive, action-oriented names -2. **Parameters**: Optional arguments for command customization -3. **Options**: Flags for additional functionality -4. **Environment**: Some commands require specific environment settings - -## Error Handling - -The CLI provides clear error messages for common issues: - -- **Invalid Commands**: Shows help and available commands -- **Missing Parameters**: Displays parameter requirements -- **Environment Errors**: Clear messages about environment requirements -- **Permission Errors**: Guidance on fixing permission issues - -## Exit Codes - -Commands return appropriate exit codes: - -- `0`: Success -- `1`: General error -- `2`: Usage error (invalid arguments) diff --git a/docs/cli/commands/clone.md b/docs/cli/commands/clone.md new file mode 100644 index 00000000..cbe33f62 --- /dev/null +++ b/docs/cli/commands/clone.md @@ -0,0 +1,154 @@ +# clone - Repository Cloning + +The `clone` command clones the Nixopus repository with basic configuration options. By default, it clones the main Nixopus repository to a configured local path. + +## Quick Start +```bash +# Clone with default settings (from config) +nixopus clone + +# Clone specific branch +nixopus clone --branch develop + +# Clone from custom repository +nixopus clone --repo https://github.com/yourfork/nixopus.git + +# Preview clone operation +nixopus clone --dry-run +``` + +## Overview + +The clone command provides basic Git repository cloning functionality with configuration-driven defaults for the Nixopus repository. + +## Command Syntax + +```bash +nixopus clone [OPTIONS] +``` + +## Options + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--repo` | `-r` | Repository URL to clone | `https://github.com/raghavyuva/nixopus` | +| `--branch` | `-b` | Branch to clone | `master` | +| `--path` | `-p` | Local path for cloning | `/etc/nixopus/source` | +| `--force` | `-f` | Force clone (overwrite existing directory) | `false` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format | `text` | +| `--dry-run` | `-d` | Preview clone operation without executing | `false` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Basic clone with default configuration +nixopus clone + +# Clone specific branch +nixopus clone --branch develop + +# Clone from custom repository +nixopus clone --repo https://github.com/yourfork/nixopus.git + +# Clone to custom path with force overwrite +nixopus clone --path /opt/nixopus --force + +# Preview operation without executing +nixopus clone --dry-run --verbose + +# Clone with increased timeout +nixopus clone --timeout 30 +``` + +## Configuration + +The clone command reads configuration values from the built-in [`config.prod.yaml`](https://raw.githubusercontent.com/raghavyuva/nixopus/refs/heads/master/helpers/config.prod.yaml) file. Command-line options override these defaults. + +### Default Configuration Values + +| Setting | Default Value | Configuration Path | Description | +|---------|---------------|-------------------|-------------| +| Repository URL | `https://github.com/raghavyuva/nixopus` | `clone.repo` | The Git repository to clone | +| Branch | `master` | `clone.branch` | The Git branch to clone | +| Clone Path | `{nixopus-config-dir}/source` | `clone.source-path` | Local directory for cloning (relative to config dir) | +| Config Directory | `/etc/nixopus` | `nixopus-config-dir` | Base configuration directory | +| Timeout | `10` seconds | N/A | Operation timeout (hardcoded default) | + +### Configuration Source + +The configuration is loaded from the built-in [`config.prod.yaml`](https://raw.githubusercontent.com/raghavyuva/nixopus/refs/heads/master/helpers/config.prod.yaml) file packaged with the CLI. This file contains environment variable placeholders that can be overridden: + +```yaml +# Built-in configuration (from config.prod.yaml) +nixopus-config-dir: /etc/nixopus +clone: + repo: "https://github.com/raghavyuva/nixopus" + branch: "master" + source-path: source +``` + +### Overriding Configuration + +You can override defaults using command-line options only: + +```bash +# Override repository URL +nixopus clone --repo https://github.com/yourfork/nixopus.git + +# Override branch +nixopus clone --branch develop + +# Override clone path (absolute path) +nixopus clone --path /opt/nixopus + +# Override multiple options +nixopus clone --repo https://github.com/yourfork/nixopus.git --branch develop --path /custom/path +``` + +**Note**: The clone command does not support user configuration files or environment variable overrides for these settings. Configuration is handled internally through the built-in config file. + +## Behavior + +1. **Validates** repository URL and accessibility +2. **Checks** if destination path exists +3. **Removes** existing directory if `--force` is used +4. **Clones** repository using Git +5. **Reports** success or failure + +## Dry Run Mode + +Use `--dry-run` to preview what the command would do without making changes: + +```bash +nixopus clone --dry-run --repo custom-repo.git --branch develop +``` + +This shows the planned actions without executing them. + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Repository not accessible | Network issues, invalid URL, or authentication required | Check network connection, verify repository URL, or configure Git credentials | +| Destination path already exists | Directory exists at clone path | Use `--force` to overwrite or choose different `--path` | +| Invalid branch or repository URL | Branch doesn't exist or URL is malformed | Verify branch exists and URL is correct | +| Permission denied | Insufficient permissions for destination path | Use `sudo nixopus clone` or choose a path with write permissions | +| Timeout exceeded | Clone taking longer than specified timeout | Increase timeout with `--timeout` option or check network speed | + +### Permission Issues + +If you encounter permission errors when cloning to system directories: + +```bash +# Use sudo for system-wide installation +sudo nixopus clone --path /opt/nixopus + +# Or clone to user directory (recommended) +nixopus clone --path ~/nixopus +``` + +**Note**: When using `sudo`, the cloned repository will be owned by root. Consider using user directories unless system-wide installation is required. diff --git a/docs/cli/commands/conf.md b/docs/cli/commands/conf.md new file mode 100644 index 00000000..b7de342d --- /dev/null +++ b/docs/cli/commands/conf.md @@ -0,0 +1,193 @@ +# conf - Configuration Management + +The `conf` command provides comprehensive configuration management for Nixopus services. Manage environment variables, service settings, and application configuration across API and view services with support for multiple environments. + +## Quick Start +```bash +# List current configuration +nixopus conf list --service api + +# Set configuration value +nixopus conf set DATABASE_URL=postgresql://user:pass@localhost:5432/nixopus + +# Delete configuration key +nixopus conf delete OLD_CONFIG_KEY + +# Set view service configuration +nixopus conf set --service view NODE_ENV=production +``` + +## Overview + +The conf command handles all aspects of Nixopus configuration: +- Environment variable management for services +- Multi-service configuration support (API, view) +- Environment file management (.env files) + +## Subcommands + +### `list` - Display Configuration + +Show all configuration values for specified services with optional filtering and formatting. + +```bash +nixopus conf list [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--service` | `-s` | Target service (api, view) | `api` | +| `--verbose` | `-v` | Show detailed logging and metadata | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--dry-run` | `-d` | Dry run mode | `false` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# List API service configuration +nixopus conf list --service api + +# Get JSON output +nixopus conf list --output json + +# Use custom environment file +nixopus conf list --env-file /custom/path/.env +``` + + +### `set` - Update Configuration + +Set configuration values using KEY=VALUE format with service targeting. + +```bash +nixopus conf set KEY=VALUE [OPTIONS] +``` + +**Arguments:** +- `KEY=VALUE` - Configuration pair (required, single value only) + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--service` | `-s` | Target service (api, view) | `api` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | `-d` | Preview configuration changes | `false` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Set configuration value +nixopus conf set DATABASE_URL=postgresql://user:pass@localhost:5432/nixopus + +# Set for view service +nixopus conf set --service view NODE_ENV=production + +# Preview changes +nixopus conf set DEBUG=true --dry-run +``` + +### `delete` - Remove Configuration + +Remove configuration keys from service environments with safety checks. + +```bash +nixopus conf delete KEY [OPTIONS] +``` + +**Arguments:** +- `KEY` - Configuration key to remove (required, single key only) + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--service` | `-s` | Target service (api, view) | `api` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | `-d` | Preview deletion without executing | `false` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Delete configuration key +nixopus conf delete OLD_CONFIG_KEY + +# Preview deletion +nixopus conf delete TEMP_CONFIG --dry-run +``` + +## Configuration + +The conf command manages environment variables stored in service-specific `.env` files. Configuration is loaded from the built-in `config.prod.yaml` file to determine default environment file locations. + +### Default Environment File Locations + +| Service | Default Environment File | Configuration Path | +|---------|-------------------------|-------------------| +| API | `/etc/nixopus/source/api/.env` | `services.api.env.API_ENV_FILE` | +| View | `/etc/nixopus/source/view/.env` | `services.view.env.VIEW_ENV_FILE` | + +### Configuration Source + +Environment file paths are determined from the built-in `config.prod.yaml`: + +```yaml +# Built-in configuration +services: + api: + env: + API_ENV_FILE: ${API_ENV_FILE:-/etc/nixopus/source/api/.env} + view: + env: + VIEW_ENV_FILE: ${VIEW_ENV_FILE:-/etc/nixopus/source/view/.env} +``` + +### Overriding Environment Files + +You can specify custom environment files using the `--env-file` option: + +```bash +# Use custom environment file +nixopus conf list --env-file /custom/path/.env + +# Set configuration in custom file +nixopus conf set DATABASE_URL=custom --env-file /custom/path/.env + +# Delete from custom file +nixopus conf delete OLD_KEY --env-file /custom/path/.env +``` + +### Permission Requirements + +Environment files require appropriate read/write permissions: + +```bash +# Check current permissions +ls -la /etc/nixopus/source/api/.env + +# Fix permissions if needed (may require sudo) +sudo chmod 644 /etc/nixopus/source/api/.env +sudo chown $(whoami) /etc/nixopus/source/api/.env + +# Or use sudo for operations on system files +sudo nixopus conf set DATABASE_URL=value --service api +``` + + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| File not found | Environment file doesn't exist | Create the file or use `--env-file` with existing file | +| Permission denied | Insufficient file permissions | Use `sudo` or fix file permissions with `chmod` | +| Invalid KEY=VALUE format | Missing equals sign in set command | Ensure format is `KEY=VALUE` | +| Service not found | Invalid service name | Use `api` or `view` for `--service` option | +| Operation timeout | Command taking too long | Increase `--timeout` value | + +**Note**: When using `sudo`, ensure the environment files remain accessible to the services that need them. diff --git a/docs/cli/commands/install.md b/docs/cli/commands/install.md new file mode 100644 index 00000000..a58d388f --- /dev/null +++ b/docs/cli/commands/install.md @@ -0,0 +1,173 @@ +# install - Nixopus Installation + +The `install` command installs Nixopus with all required components and configuration. Provides comprehensive setup including dependencies and SSH key generation. + +## Quick Start +```bash +# Basic installation +nixopus install + +# Install with custom domains +nixopus install --api-domain api.example.com --view-domain app.example.com + +# Preview installation changes +nixopus install --dry-run --verbose +``` + +## Overview + +The install command provides a comprehensive setup process including system validation, dependency installation, and service configuration. + +## Command Syntax + +```bash +nixopus install [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--verbose` | `-v` | Show detailed installation progress | `false` | +| `--timeout` | `-t` | Installation timeout in seconds | `300` | +| `--force` | `-f` | Replace existing files without prompting | `false` | +| `--dry-run` | `-d` | Preview installation without making changes | `false` | +| `--config-file` | `-c` | Path to custom configuration file | None | +| `--api-domain` | `-ad` | Domain for API access | None | +| `--view-domain` | `-vd` | Domain for web interface | None | + +**Examples:** + +```bash +# Standard installation +nixopus install + +# Production installation with custom domains +nixopus install --api-domain api.production.com --view-domain app.production.com --timeout 600 + +# Preview installation with verbose output +nixopus install --dry-run --verbose + +# Force installation (overwrite existing files) +nixopus install --force +``` + +## Subcommands + +### `ssh` - SSH Key Generation + +Generate SSH key pairs with proper permissions and optional authorized_keys integration. + +```bash +nixopus install ssh [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--path` | `-p` | SSH key file path | `~/.ssh/nixopus_ed25519` | +| `--key-type` | `-t` | Key type (rsa, ed25519, ecdsa) | `ed25519` | +| `--key-size` | `-s` | Key size in bits | `4096` | +| `--passphrase` | `-P` | Passphrase for key encryption | None | +| `--force` | `-f` | Overwrite existing SSH keys | `false` | +| `--set-permissions` | `-S` | Set proper file permissions | `true` | +| `--add-to-authorized-keys` | `-a` | Add public key to authorized_keys | `false` | +| `--create-ssh-directory` | `-c` | Create .ssh directory if needed | `true` | +| `--verbose` | `-v` | Show detailed output | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | `-d` | Preview operation | `false` | +| `--timeout` | `-T` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Generate default Ed25519 key +nixopus install ssh + +# Generate RSA key with custom path and size +nixopus install ssh --path ~/.ssh/nixopus_rsa --key-type rsa --key-size 4096 + +# Generate encrypted key for production +nixopus install ssh --passphrase "secure-passphrase" --add-to-authorized-keys +``` + +### `deps` - Dependency Installation + +Install and configure system dependencies required for Nixopus operation. + +```bash +nixopus install deps [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--verbose` | `-v` | Show detailed installation progress | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | `-d` | Preview dependency installation | `false` | +| `--timeout` | `-t` | Installation timeout in seconds | `10` | + +**Examples:** + +```bash +# Install all required dependencies +nixopus install deps + +# Preview dependency installation +nixopus install deps --dry-run --verbose + +# Get JSON output for automation +nixopus install deps --output json +``` + +## Configuration + +The install command reads configuration values from the built-in `config.prod.yaml` file and accepts command-line overrides. + +### Default Configuration Values + +| Setting | Default Value | Description | +|---------|---------------|-------------| +| Timeout | `300` seconds | Maximum time to wait for installation steps | +| SSH Key Path | `~/.ssh/nixopus_ed25519` | Default SSH key location | +| SSH Key Type | `ed25519` | Default SSH key algorithm | +| SSH Key Size | `4096` bits | Default key size for RSA keys | + +### Configuration Source + +Configuration is loaded from the built-in `config.prod.yaml` and command-line options. + +### Overriding Configuration + +You can override defaults using command-line options: + +```bash +# Use custom domains +nixopus install --api-domain api.example.com --view-domain app.example.com + +# Use custom config file +nixopus install --config-file /path/to/config.yaml + +# Custom timeout and force mode +nixopus install --timeout 600 --force +``` + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Permission denied | Insufficient file system permissions | Use `sudo nixopus install` | +| Docker not available | Docker daemon not running | Start Docker service | +| Port conflicts | Ports already in use | Stop conflicting services | +| SSH key generation fails | SSH directory permissions | Fix SSH directory permissions | +| Installation timeout | Network or system issues | Increase timeout with `--timeout` option | + +If permission issues occur, use sudo: +```bash +sudo nixopus install --verbose +``` + +## Related Commands + +- **[preflight](./preflight.md)** - Run system checks before installation +- **[service](./service.md)** - Manage installed services +- **[conf](./conf.md)** - Configure installed services +- **[uninstall](./uninstall.md)** - Remove Nixopus installation \ No newline at end of file diff --git a/docs/cli/commands/preflight.md b/docs/cli/commands/preflight.md new file mode 100644 index 00000000..452fbddc --- /dev/null +++ b/docs/cli/commands/preflight.md @@ -0,0 +1,215 @@ +# preflight - System Readiness Checks + +The `preflight` command runs comprehensive system checks to ensure your environment is properly configured for Nixopus installation and operation. + +## Quick Start +```bash +# Run full system check +nixopus preflight check + +# Check specific ports +nixopus preflight ports 80 443 8080 + +# Verify dependencies +nixopus preflight deps docker git +``` + +## Overview + +The preflight command performs system readiness checks including port availability and dependency verification. + +## Subcommands + +### `check` - Comprehensive System Check + +Runs port availability checks based on configuration. This is the default command when running `preflight` without subcommands. + +```bash +nixopus preflight check [OPTIONS] +nixopus preflight [OPTIONS] # same as check +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--verbose` | `-v` | Show detailed logging information | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Basic system check +nixopus preflight check + +# Detailed check with verbose output +nixopus preflight check --verbose +``` + +**What it does:** +- Reads required ports from the configuration file +- Checks if those ports are available on localhost +- Reports success if all configured ports are free + +### `ports` - Port Availability Check + +Verify specific ports are available for Nixopus services. + +```bash +nixopus preflight ports [PORT...] [OPTIONS] +``` + +**Arguments:** +- `PORT...` - List of ports to check (required) + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--host` | `-h` | Host to check | `localhost` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Check standard web ports +nixopus preflight ports 80 443 + +# Check ports on remote host +nixopus preflight ports 80 443 --host production.server.com + +# Get JSON output +nixopus preflight ports 80 443 8080 --output json +``` + +**Output:** +The command outputs a formatted table or JSON showing port availability status for each port checked. + +### `deps` - Dependency Verification + +Check if required system dependencies are installed and accessible. + +```bash +nixopus preflight deps [DEPENDENCY...] [OPTIONS] +``` + +**Arguments:** +- `DEPENDENCY...` - List of dependencies to check (required) + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Common Dependencies:** +- `docker` - Docker container runtime +- `docker-compose` - Docker Compose orchestration +- `git` - Git version control +- `curl` - HTTP client utility +- `ssh` - SSH client + +**Examples:** + +```bash +# Check core dependencies +nixopus preflight deps docker git + +# Check with verbose output +nixopus preflight deps docker git --verbose + +# Get JSON output +nixopus preflight deps docker git --output json +``` + +**Output:** +The command outputs a formatted table showing dependency availability. Uses `shutil.which()` to check if commands are available in the system PATH. + +## Configuration + +The preflight command reads configuration values from the built-in `config.prod.yaml` file to determine which ports and dependencies to check. + +### Default Configuration Values + +| Setting | Default Value | Configuration Path | Description | +|---------|---------------|-------------------|-------------| +| Ports | `[2019, 80, 443, 7443, 8443, 6379, 5432]` | `ports` | Ports checked by default | +| Timeout | `10` seconds | N/A | Operation timeout (hardcoded default) | + +### Configuration Source + +Configuration is loaded from the built-in `config.prod.yaml`: + +```yaml +# Built-in configuration +ports: [2019, 80, 443, 7443, 8443, 6379, 5432] + +deps: + curl: { package: "curl", command: "curl" } + python3: { package: "python3", command: "python3" } + python3-venv: { package: "python3-venv", command: "" } + git: { package: "git", command: "git" } + docker.io: { package: "docker.io", command: "docker" } + openssl: { package: "openssl", command: "openssl" } + openssh-client: { package: "openssh-client", command: "ssh" } + openssh-server: { package: "openssh-server", command: "sshd" } +``` + +### Port Descriptions + +| Port | Service | Purpose | +|------|---------|---------| +| `2019` | Caddy | Admin API port | +| `80` | HTTP | Web traffic | +| `443` | HTTPS | Secure web traffic | +| `7443` | View | Frontend service | +| `8443` | API | Backend service | +| `6379` | Redis | Cache/session store | +| `5432` | PostgreSQL | Database | + +### Available Dependencies + +| Command | Package | Purpose | +|---------|---------|---------| +| `curl` | curl | HTTP client utility | +| `python3` | python3 | Python runtime | +| `git` | git | Version control | +| `docker` | docker.io | Container runtime | +| `openssl` | openssl | SSL/TLS toolkit | +| `ssh` | openssh-client | SSH client | +| `sshd` | openssh-server | SSH server | + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Port already in use | Service running on checked port | Stop conflicting service or use different ports | +| Command not found | Dependency not installed | Install required package using system package manager | +| Permission denied | Docker requires elevated privileges | Add user to docker group or use sudo | +| Connection timeout | Network issues or slow system | Increase timeout with `--timeout` option | +| Invalid port number | Port outside valid range | Use port numbers between 1-65535 | + +### Permission Issues + +If you encounter permission errors, especially with Docker: + +```bash +# Check if docker requires sudo +docker ps +# If this fails with permission denied: + +# Add user to docker group +sudo usermod -aG docker $USER + +# Restart shell session +newgrp docker + +# Test without sudo +docker ps + +# Or use sudo for preflight checks +sudo nixopus preflight deps docker +``` + +**Note**: When using `sudo`, ensure the command can access the same configuration files. diff --git a/docs/cli/commands/proxy.md b/docs/cli/commands/proxy.md new file mode 100644 index 00000000..c8e178d8 --- /dev/null +++ b/docs/cli/commands/proxy.md @@ -0,0 +1,172 @@ +# proxy - Caddy Proxy Management + +The `proxy` command controls the Caddy reverse proxy server that handles HTTP routing, SSL termination, and load balancing for Nixopus services. Manage proxy configuration, monitor status, and control the proxy lifecycle. + +## Quick Start +```bash +# Load proxy configuration +nixopus proxy load + +# Check proxy status +nixopus proxy status + +# Stop proxy server +nixopus proxy stop +``` + +## Overview + +The proxy command manages Caddy as the reverse proxy for Nixopus: +- HTTP/HTTPS routing to API and view services +- Configuration loading and management +- Proxy status monitoring +- Graceful proxy shutdown + +## Subcommands + +### `load` - Load Proxy Configuration + +Load and apply Caddy proxy configuration from file with validation support. + +```bash +nixopus proxy load [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--proxy-port` | `-p` | Caddy admin API port | `2019` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | | Validate configuration without applying | `false` | +| `--config-file` | `-c` | Path to Caddy configuration file | None | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Load default proxy configuration +nixopus proxy load + +# Load custom configuration file +nixopus proxy load --config-file /path/to/caddy.json + +# Validate configuration without applying +nixopus proxy load --config-file caddy.json --dry-run + +# Load with custom admin port +nixopus proxy load --proxy-port 2019 --verbose +``` + +### `status` - Check Proxy Status + +Display status information about the Caddy proxy server. + +```bash +nixopus proxy status [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--proxy-port` | `-p` | Caddy admin API port | `2019` | +| `--verbose` | `-v` | Show detailed status information | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | | Preview operation without executing | `false` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Basic proxy status +nixopus proxy status + +# Detailed status information +nixopus proxy status --verbose + +# JSON output for monitoring +nixopus proxy status --output json + +# Check with custom admin port +nixopus proxy status --proxy-port 2019 +``` + +### `stop` - Stop Proxy Server + +Gracefully stop the Caddy proxy server. + +```bash +nixopus proxy stop [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--proxy-port` | `-p` | Caddy admin API port | `2019` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | | Preview stop operation | `false` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Graceful proxy shutdown +nixopus proxy stop + +# Stop with detailed logging +nixopus proxy stop --verbose + +# Preview stop operation +nixopus proxy stop --dry-run + +# Stop with custom admin port +nixopus proxy stop --proxy-port 2019 +``` + +## Configuration + +The proxy command reads configuration values from the built-in `config.prod.yaml` file to determine the default Caddy admin port. + +### Default Configuration Values + +| Setting | Default Value | Configuration Path | Description | +|---------|---------------|-------------------|-------------| +| Proxy Port | `2019` | `services.caddy.env.PROXY_PORT` | Caddy admin API port | +| Timeout | `10` seconds | N/A | Operation timeout (hardcoded default) | + +### Configuration Source + +Configuration is loaded from the built-in `config.prod.yaml`: + +```yaml +# Built-in configuration +services: + caddy: + env: + PROXY_PORT: ${PROXY_PORT:-2019} +``` + +### Overriding Configuration + +You can override defaults using command-line options: + +```bash +# Use custom admin port +nixopus proxy status --proxy-port 8080 + +# Use custom config file +nixopus proxy load --config-file /custom/caddy.json + +# Combine both +nixopus proxy load --proxy-port 8080 --config-file /custom/caddy.json +``` + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Connection refused | Caddy admin API not running | Start Caddy or check admin port | +| Configuration file not found | Invalid config file path | Check file path and permissions | +| Invalid configuration | Malformed Caddy config | Validate JSON/config syntax | +| Permission denied | Insufficient network permissions | Use sudo or check port availability | +| Operation timeout | Network or server issues | Increase timeout with `--timeout` option | diff --git a/docs/cli/commands/service.md b/docs/cli/commands/service.md new file mode 100644 index 00000000..3eec7bf3 --- /dev/null +++ b/docs/cli/commands/service.md @@ -0,0 +1,205 @@ +# service - Docker Compose Service Management + +The `service` command provides comprehensive control over Nixopus services using Docker Compose integration. Manage the lifecycle of all Nixopus components including API, web interface, database, and proxy services. + +## Quick Start +```bash +# Start all services +nixopus service up --detach + +# Check service status +nixopus service ps + +# Restart specific service +nixopus service restart --name api + +# Stop all services +nixopus service down +``` + +## Overview + +The service command acts as a Docker Compose wrapper with Nixopus-specific enhancements: +- Service lifecycle management (start, stop, restart, status) +- Environment-specific configuration loading +- Custom Docker Compose file support +- Service-specific targeting + +## Subcommands + +### `up` - Start Services + +Start Nixopus services with dependency orchestration. + +```bash +nixopus service up [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--name` | `-n` | Specific service name | `all` | +| `--detach` | `-d` | Run services in background | `false` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | | Preview operation without executing | `false` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--compose-file` | `-f` | Custom Docker Compose file path | `/etc/nixopus/source/docker-compose.yml` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Start all services in foreground +nixopus service up + +# Start all services in background +nixopus service up --detach + +# Start specific service +nixopus service up --name api + +# Preview operation +nixopus service up --dry-run +``` + +### `down` - Stop Services + +Stop Nixopus services with graceful shutdown. + +```bash +nixopus service down [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--name` | `-n` | Specific service name | `all` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | | Preview operation without executing | `false` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--compose-file` | `-f` | Custom Docker Compose file path | `/etc/nixopus/source/docker-compose.yml` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Stop all services +nixopus service down + +# Stop specific service +nixopus service down --name api + +# Preview operation +nixopus service down --dry-run +``` + +### `ps` - Show Service Status + +Display status information for Nixopus services. + +```bash +nixopus service ps [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--name` | `-n` | Filter by specific service name | `all` | +| `--verbose` | `-v` | Show detailed service information | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | `-d` | Preview operation without executing | `false` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--compose-file` | `-f` | Custom Docker Compose file path | `/etc/nixopus/source/docker-compose.yml` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Show all services +nixopus service ps + +# Show specific service +nixopus service ps --name api + +# Get JSON output +nixopus service ps --output json +``` + +### `restart` - Restart Services + +Restart services with configurable restart strategies. + +```bash +nixopus service restart [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--name` | `-n` | Specific service name | `all` | +| `--verbose` | `-v` | Show detailed logging | `false` | +| `--output` | `-o` | Output format (text, json) | `text` | +| `--dry-run` | `-d` | Preview operation without executing | `false` | +| `--env-file` | `-e` | Custom environment file path | None | +| `--compose-file` | `-f` | Custom Docker Compose file path | `/etc/nixopus/source/docker-compose.yml` | +| `--timeout` | `-t` | Operation timeout in seconds | `10` | + +**Examples:** + +```bash +# Restart all services +nixopus service restart + +# Restart specific service +nixopus service restart --name api + +# Preview operation +nixopus service restart --dry-run +``` + +## Configuration + +The service command reads configuration values from the built-in `config.prod.yaml` file to determine default compose file location. + +### Default Configuration Values + +| Setting | Default Value | Configuration Path | Description | +|---------|---------------|-------------------|-------------| +| Compose File | `source/docker-compose.yml` | `compose-file-path` | Docker Compose file path (relative to config dir) | +| Config Directory | `/etc/nixopus` | `nixopus-config-dir` | Base configuration directory | +| Timeout | `10` seconds | N/A | Operation timeout (hardcoded default) | + +### Configuration Source + +Configuration is loaded from the built-in `config.prod.yaml`: + +```yaml +# Built-in configuration +nixopus-config-dir: /etc/nixopus +compose-file-path: source/docker-compose.yml +``` + +### Overriding Configuration + +You can override defaults using command-line options: + +```bash +# Use custom compose file +nixopus service up --compose-file /custom/docker-compose.yml + +# Use custom environment file +nixopus service up --env-file /custom/.env + +# Combine both +nixopus service up --compose-file /custom/compose.yml --env-file /custom/.env +``` + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Compose file not found | Docker Compose file missing | Check file path or use `--compose-file` option | +| Docker daemon not running | Docker service stopped | Start Docker service: `sudo systemctl start docker` | +| Port already in use | Service running on required port | Stop conflicting service or change port configuration | +| Permission denied | Insufficient Docker permissions | Add user to docker group or use `sudo` | +| Service startup timeout | Service taking too long to start | Increase timeout with `--timeout` option | diff --git a/docs/cli/commands/test.md b/docs/cli/commands/test.md new file mode 100644 index 00000000..0a582618 --- /dev/null +++ b/docs/cli/commands/test.md @@ -0,0 +1,93 @@ +# test - CLI Testing Utilities + +The `test` command runs tests for the Nixopus CLI in development environments. This command is restricted to development environments only. + +## Quick Start +```bash +# Set development environment (required) +export ENV=DEVELOPMENT + +# Run all tests +nixopus test + +# Run specific test target +nixopus test version +``` + +## Overview + +The test command provides basic testing capabilities for the Nixopus CLI. It requires the `ENV=DEVELOPMENT` environment variable to prevent accidental execution in production. + +## Command Syntax + +```bash +nixopus test [TARGET] +``` + +| Argument | Description | Required | +|----------|-------------|----------| +| `TARGET` | Specific test target (e.g., version) | No | + +**Examples:** + +```bash +# Set development environment first (required) +export ENV=DEVELOPMENT + +# Run all tests +nixopus test + +# Run specific command tests +nixopus test version +``` + +## Configuration + +The test command does not use external configuration files. It operates with environment variable requirements. + +### Environment Requirements + +| Setting | Required Value | Description | +|---------|---------------|-------------| +| ENV | `DEVELOPMENT` | Must be set to enable testing | + +### Configuration Source + +The test command requires the `ENV=DEVELOPMENT` environment variable to be set: + +```bash +# Required environment setup +export ENV=DEVELOPMENT +``` + +### Overriding Configuration + +You can specify different test targets using the command argument: + +```bash +# Test specific command +nixopus test version + +# Test different command +nixopus test install +``` + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Environment not development | ENV not set to DEVELOPMENT | Set `export ENV=DEVELOPMENT` | +| Test dependencies missing | Development packages not installed | Install with `poetry install --with dev` | +| Permission denied | File system permissions | Use `sudo` if necessary | + +If permission issues occur, use sudo: +```bash +sudo nixopus test +``` + +## Related Commands + +- **[version](./version.md)** - Check CLI version before running tests +- **[preflight](./preflight.md)** - Validate test environment setup \ No newline at end of file diff --git a/docs/cli/commands/uninstall.md b/docs/cli/commands/uninstall.md new file mode 100644 index 00000000..1aafeb70 --- /dev/null +++ b/docs/cli/commands/uninstall.md @@ -0,0 +1,100 @@ +# uninstall - Complete Nixopus Removal + +The `uninstall` command completely removes Nixopus from your system. This is a destructive operation that permanently removes all Nixopus components. + +## Quick Start +```bash +# Standard uninstallation +nixopus uninstall + +# Preview what will be removed +nixopus uninstall --dry-run --verbose + +# Force uninstallation without prompts +nixopus uninstall --force +``` + +## Overview + +The uninstall command completely removes Nixopus from your system including services, configuration files, and data. + +## Command Syntax + +```bash +nixopus uninstall [OPTIONS] +``` + +| Option | Short | Description | Default | +|--------|-------|-------------|---------| +| `--verbose` | `-v` | Show detailed uninstallation progress | `false` | +| `--timeout` | `-t` | Operation timeout in seconds | `300` | +| `--dry-run` | `-d` | Preview what would be removed without executing | `false` | +| `--force` | `-f` | Skip confirmation prompts and force removal | `false` | + +**Examples:** + +```bash +# Interactive uninstallation +nixopus uninstall + +# Preview uninstallation +nixopus uninstall --dry-run --verbose + +# Force uninstallation without prompts +nixopus uninstall --force + +# Custom timeout +nixopus uninstall --timeout 600 --verbose +``` + +## Configuration + +The uninstall command does not use external configuration files. It operates with hardcoded default values. + +### Default Configuration Values + +| Setting | Default Value | Description | +|---------|---------------|-------------| +| Timeout | `300` seconds | Maximum time to wait for each uninstallation step | +| Verbose | `false` | Show detailed logging during uninstallation | +| Dry Run | `false` | Preview mode without making actual changes | +| Force | `false` | Skip confirmation prompts | + +### Overriding Configuration + +You can override defaults using command-line options: + +```bash +# Use custom timeout +nixopus uninstall --timeout 600 + +# Enable verbose logging +nixopus uninstall --verbose + +# Preview without changes +nixopus uninstall --dry-run + +# Force uninstall without prompts +nixopus uninstall --force +``` + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Permission denied | Insufficient file system permissions | Use `sudo nixopus uninstall` | +| Services still running | Docker containers won't stop | Force stop with `docker stop` command | +| Files in use | Configuration files locked | Close applications using Nixopus files | +| Timeout exceeded | Uninstall taking too long | Increase timeout with `--timeout` option | + +If permission issues occur, use sudo: +```bash +sudo nixopus uninstall --verbose +``` + +## Related Commands + +- **[service](./service.md)** - Stop services before uninstalling +- **[conf](./conf.md)** - Backup configuration before removal \ No newline at end of file diff --git a/docs/cli/commands/version.md b/docs/cli/commands/version.md new file mode 100644 index 00000000..6ea434cc --- /dev/null +++ b/docs/cli/commands/version.md @@ -0,0 +1,59 @@ +# version - CLI Version Information + +The `version` command displays the current version of the Nixopus CLI. Essential for troubleshooting and support requests. + +## Quick Start +```bash +# Display version information +nixopus version + +# Short version flag +nixopus --version +``` + +## Overview + +The version command provides basic version information about the Nixopus CLI installation using the package metadata. + +## Command Syntax + +```bash +nixopus version +``` + +**Alternative Forms:** +```bash +nixopus --version +nixopus -v +``` + +**Examples:** + +```bash +# Display version information +nixopus version + +# Alternative syntax +nixopus --version +nixopus -v +``` + +## Configuration + +The version command does not use external configuration. It reads version information directly from the installed package metadata using Python's `importlib.metadata.version()`. + +### Version Source + +The version is determined from: +- **Package metadata** - Installed package version from `importlib.metadata` +- **Display formatting** - Rich console formatting for output + +## Error Handling + +Common error scenarios and solutions: + +| Error | Cause | Solution | +|-------|-------|----------| +| Package not found | CLI not properly installed | Reinstall using `poetry install nixopus` | +| Import error | Python environment issues | Check Python installation and PATH | +| Permission denied | File system permissions | Check package installation permissions | diff --git a/docs/cli/config.md b/docs/cli/config.md new file mode 100644 index 00000000..21f709c3 --- /dev/null +++ b/docs/cli/config.md @@ -0,0 +1,114 @@ +# CLI Configuration + +The Nixopus CLI uses a built-in YAML configuration file that defines default values for all commands. + +## Configuration File + +The CLI reads configuration from: +``` +helpers/config.prod.yaml +``` + +This file is bundled with the CLI and contains production-ready defaults that can be overridden through environment variables. + +## Key Configuration Sections + +### Service Defaults +```yaml +services: + api: + env: + PORT: ${API_PORT:-8443} + DB_NAME: ${DB_NAME:-postgres} + USERNAME: ${USERNAME:-postgres} + PASSWORD: ${PASSWORD:-changeme} + # ... other API settings + + view: + env: + PORT: ${VIEW_PORT:-7443} + NEXT_PUBLIC_PORT: ${NEXT_PUBLIC_PORT:-7443} + # ... other view settings + + caddy: + env: + PROXY_PORT: ${PROXY_PORT:-2019} + API_DOMAIN: ${API_DOMAIN:-} + VIEW_DOMAIN: ${VIEW_DOMAIN:-} + # ... other proxy settings +``` + +### System Dependencies +```yaml +deps: + curl: { package: "curl", command: "curl" } + python3: { package: "python3", command: "python3" } + git: { package: "git", command: "git" } + docker.io: { package: "docker.io", command: "docker" } + openssl: { package: "openssl", command: "openssl" } + openssh-client: { package: "openssh-client", command: "ssh" } +``` + +### Network Ports +```yaml +ports: [2019, 80, 443, 7443, 8443, 6379, 5432] +``` + +### Repository Settings +```yaml +clone: + repo: "https://github.com/raghavyuva/nixopus" + branch: "master" + source-path: source +``` + +### SSH Configuration +```yaml +ssh_key_size: 4096 +ssh_key_type: ed25519 +ssh_file_path: ssh/id_rsa +``` + +### File Paths +```yaml +nixopus-config-dir: /etc/nixopus +compose-file-path: source/docker-compose.yml +``` + +## Environment Variable Overrides + +All configuration values use environment variable expansion: +```yaml +PORT: ${API_PORT:-8443} # Uses API_PORT if set, otherwise 8443 +``` + +**Common overrides:** +```bash +# Override API domain +export API_DOMAIN=api.example.com + +# Override database credentials +export USERNAME=myuser +export PASSWORD=mypassword + +# Override ports +export API_PORT=9443 +export VIEW_PORT=8443 +``` + +## Command Usage + +Commands read specific configuration sections: + +| Command | Configuration Used | +|---------|-------------------| +| **preflight** | `ports`, `deps` | +| **install** | Service defaults, paths, SSH settings | +| **service** | Service environment variables | +| **conf** | Service environment configurations | +| **proxy** | `services.caddy.env` settings | +| **clone** | `clone` repository settings | + +## Configuration Access + +Commands access configuration through the CLI's config system - users don't need to manage the configuration file directly. Use command-line options and environment variables to customize behavior. \ No newline at end of file diff --git a/docs/cli/development.md b/docs/cli/development.md index 86a29e3b..e61a2a31 100644 --- a/docs/cli/development.md +++ b/docs/cli/development.md @@ -1,262 +1,107 @@ -# CLI Development Guide +# CLI Development -This guide provides detailed information for contributing to the Nixopus CLI development. +Basic development guide for contributing to the Nixopus CLI. ## Project Structure ``` cli/ -├── main.py # Main CLI entry point -├── pyproject.toml # Project configuration -├── commands/ # Command implementations -│ ├── version/ # Version command module -│ ├── test/ # Test command module -│ └── preflight/ # Preflight command module -├── core/ # Core functionality -│ ├── config.py # Configuration utilities -│ ├── version/ # Version display logic -│ └── test/ # Test functionality -├── utils/ # Utility functions -└── tests/ # Test files +├── app/ # Main application package +│ ├── main.py # CLI entry point +│ ├── commands/ # Command implementations +│ └── utils/ # Shared utilities +├── pyproject.toml # Project configuration (Poetry) +├── poetry.lock # Dependency lock file +└── Makefile # Development commands ``` ## Development Setup -1. **Clone and Install** - ```bash - git clone https://github.com/raghavyuva/nixopus.git - cd nixopus/cli - make install - ``` - -2. **Verify Installation** - ```bash - make version - make test - ``` - -3. **Available Commands** - ```bash - make help - ``` - -## Adding New Commands - -### Step 1: Create Command Module - -Create a new directory in the `commands/` directory with the following structure: - -```python -# commands/new_command/__init__.py -# Empty file to make it a module - -# commands/new_command/command.py -import typer -from .messages import new_command_help - -new_command_app = typer.Typer( - help=new_command_help, - invoke_without_command=True -) - -@new_command_app.callback() -def new_command_callback(ctx: typer.Context): - """Description of the new command""" - if ctx.invoked_subcommand is None: - # Main command logic here - pass - -# commands/new_command/messages.py -new_command_help = "Description of the new command" -``` - -### Step 2: Register Command - -Import and register the command in `main.py`: +### Prerequisites +- Python 3.9+ +- Poetry (for dependency management) +- Git -```python -from commands.new_command.command import new_command_app - -app.add_typer(new_command_app, name="new-command") -``` +### Installation -### Step 3: Add Tests +```bash +# Clone and navigate +git clone https://github.com/raghavyuva/nixopus.git +cd nixopus/cli -Create corresponding test files in the `tests/` directory: +# Install dependencies +poetry install --with dev -```python -# tests/test_commands_new_command.py -import pytest -from typer.testing import CliRunner -from cli.main import app +# Activate virtual environment +poetry shell -runner = CliRunner() +# Install CLI in development mode +pip install -e . -def test_new_command(): - result = runner.invoke(app, ["new-command"]) - assert result.exit_code == 0 +# Verify installation +nixopus --help ``` -### Step 4: Update Documentation - -Add the command to the appropriate table in the [Commands Reference](commands.md). - ## Testing -### Running Tests - ```bash -# Run all tests +# Set development environment (required for tests) +export ENV=DEVELOPMENT + +# Run tests make test # Run with coverage make test-cov -# Run tests in watch mode -make test-watch - # Run specific test poetry run pytest tests/test_commands_version.py - -# Run with verbose output -poetry run pytest -v ``` -### Test Structure - -Tests are organized in the `tests/` directory: - -- **Command Tests**: Test individual command functionality -- **Core Tests**: Test core utility functions -- **Integration Tests**: Test command interactions - -### Writing Tests - -Follow these guidelines: +## Available Make Commands -1. **Test Command Execution** - ```python - def test_version_command(): - result = runner.invoke(app, ["version"]) - assert result.exit_code == 0 - assert "Nixopus CLI" in result.stdout - ``` - -2. **Test Error Cases** - ```python - def test_test_command_development_only(): - result = runner.invoke(app, ["test"]) - assert result.exit_code == 1 - assert "DEVELOPMENT" in result.stdout - ``` - -3. **Test Parameters** - ```python - def test_test_command_with_target(): - with patch('commands.test.is_development', return_value=True): - result = runner.invoke(app, ["test", "version"]) - assert result.exit_code == 0 - ``` - -## Code Standards - -### General Guidelines - -1. **Follow existing patterns**: Match the structure of existing commands -2. **Keep functions short**: Focus on single responsibility -3. **Use type hints**: Add type annotations where helpful -4. **Follow DRY principles**: Avoid code duplication -5. **Clean code**: Write readable, maintainable code - -### Command Guidelines - -1. **Use Typer apps**: Structure commands as Typer applications -2. **Separate messages**: Keep command messages in separate files -3. **Descriptive names**: Use clear, action-oriented command names -4. **Help text**: Provide helpful descriptions for all commands -5. **Error handling**: Handle errors gracefully with clear messages -6. **Exit codes**: Return appropriate exit codes (0 for success, 1 for error) - -### Documentation Guidelines - -1. **Update command docs**: Add new commands to [Commands Reference](commands.md) -2. **Include examples**: Provide usage examples for all commands -3. **Document parameters**: Explain all parameters and options -4. **Specify requirements**: Note any environment or dependency requirements - -## Dependencies - -### Core Dependencies -- **typer**: Modern CLI framework for Python -- **rich**: Rich text and beautiful formatting in the terminal - -### Development Dependencies -- **pytest**: Testing framework -- **pytest-cov**: Coverage reporting for pytest - -## Environment Configuration - -The CLI supports different environments through the `ENV` environment variable: - -- `PRODUCTION` (default): Production environment -- `DEVELOPMENT`: Development environment (enables test commands) - -Set the environment: ```bash -export ENV=DEVELOPMENT +make help # Show available commands +make install # Install dependencies +make test # Run test suite +make test-cov # Run tests with coverage +make lint # Run code linting +make format # Format code +make clean # Clean build artifacts +make build # Build distribution ``` -## Contributing Process +## Contributing 1. **Create a branch** ```bash - git checkout -b feature/new-command + git checkout -b feature/your-feature ``` -2. **Make changes** - - Add new command module with proper structure - - Update main.py to register the command - - Add tests - - Update documentation - -3. **Run tests** +2. **Make changes and test** ```bash + export ENV=DEVELOPMENT make test ``` -4. **Commit changes** +3. **Commit and submit pull request** ```bash git add . - git commit -m "Add new command: description" + git commit -m "Description of changes" + git push origin feature/your-feature ``` -5. **Submit pull request** - -## Makefile Commands - -The project includes a Makefile with common development tasks: - -```bash -make help -make install -make install-dev -make test -make test-cov -make test-watch -make lint -make format -make clean -make build -make publish -make dev -make run -``` +## Dependencies -## Testing Guidelines +### Core Dependencies +- **typer**: CLI framework +- **rich**: Terminal formatting +- **pydantic**: Data validation +- **requests**: HTTP library +- **pyyaml**: YAML parsing -- Write tests for all new commands -- Use pytest for testing -- Maintain good test coverage -- Test both success and error scenarios -- Test command help and usage -- Test environment-specific behavior \ No newline at end of file +### Development Dependencies +- **pytest**: Testing framework +- **pytest-cov**: Coverage reporting +- **black**: Code formatting +- **flake8**: Code linting \ No newline at end of file diff --git a/docs/cli/index.md b/docs/cli/index.md index 34bbe2bd..d827e473 100644 --- a/docs/cli/index.md +++ b/docs/cli/index.md @@ -1,28 +1,115 @@ # Nixopus CLI -The Nixopus CLI is a powerful command-line interface for managing and deploying applications with Nixopus. Built with Python and Typer, it provides an intuitive way to interact with the Nixopus platform. +Command line interface for managing Nixopus applications and services. Built with Python and Typer, providing an intuitive terminal experience for deployment and management. ## Quick Start -Get started with the Nixopus CLI check [Installation Guide](installation.md) on how to setup nixopus cli - ```bash +# Install CLI +curl -sSL https://raw.githubusercontent.com/raghavyuva/nixopus/master/cli/install.sh | bash + +# Verify installation nixopus --help -nixopus version + +# Check system requirements +nixopus preflight check + +# Install Nixopus +nixopus install ``` -## Commands Overview +## Available Commands + +| Command | Description | Key Subcommands | +|---------|-------------|-----------------| +| **[preflight](./commands/preflight.md)** | System readiness checks | check, ports, deps | +| **[install](./commands/install.md)** | Complete Nixopus installation | ssh, deps | +| **[uninstall](./commands/uninstall.md)** | Remove Nixopus from system | - | +| **[service](./commands/service.md)** | Control Docker services | up, down, ps, restart | +| **[conf](./commands/conf.md)** | Manage application settings | list, set, delete | +| **[proxy](./commands/proxy.md)** | Caddy proxy management | load, status, stop | +| **[clone](./commands/clone.md)** | Repository cloning with Git | - | +| **[version](./commands/version.md)** | Display CLI version information | - | +| **[test](./commands/test.md)** | Run CLI tests (development only) | - | + +## Common Workflows + +### Initial Setup +```bash +# 1. Check system requirements +nixopus preflight check + +# 2. Install with custom domains +nixopus install --api-domain api.example.com --view-domain app.example.com -The Nixopus CLI provides essential commands for managing your Nixopus deployments: +# 3. Start services +nixopus service up --detach + +# 4. Load proxy configuration +nixopus proxy load + +# 5. Verify everything is running +nixopus service ps +``` + +### Configuration Management +```bash +# View current configuration +nixopus conf list --service api + +# Update settings +nixopus conf set DATABASE_URL=postgresql://user:pass@localhost:5432/nixopus + +# Restart services to apply changes +nixopus service restart +``` + +### Development Setup +```bash +# Clone repository +nixopus clone --branch develop + +# Preview installation +nixopus install --dry-run + +# Start development environment +nixopus service up --env-file .env.development + +# Run tests +export ENV=DEVELOPMENT +nixopus test +``` + +## Global Options + +Most commands support these options: + +| Option | Shorthand | Description | +|--------|-----------|-------------| +| `--verbose` | `-v` | Show detailed output | +| `--output` | `-o` | Output format (text, json) | +| `--dry-run` | `-d` | Preview without executing | +| `--timeout` | `-t` | Operation timeout in seconds | +| `--help` | | Show command help | + +## Getting Help + +```bash +# General help +nixopus --help + +# Command-specific help +nixopus install --help +nixopus service --help + +# Subcommand help +nixopus service up --help +``` -| Command | Description | Usage | -|---------|-------------|-------| -| `version` | Display CLI version | `nixopus version` | +## Installation -For detailed command documentation, see the [Commands Reference](commands.md). +See the [Installation Guide](./installation.md) for detailed setup instructions including binary installation, Poetry setup, and development environment configuration. -## Next Steps +## Development -- [Installation Guide](installation.md) - Complete setup instructions -- [Commands Reference](commands.md) - Detailed command usage -- [Development Guide](development.md) - Contributing to the CLI \ No newline at end of file +See the [Development Guide](./development.md) for information on contributing to the CLI, project structure, and testing procedures. \ No newline at end of file diff --git a/docs/cli/installation.md b/docs/cli/installation.md index 711e74ad..78a03658 100644 --- a/docs/cli/installation.md +++ b/docs/cli/installation.md @@ -1,58 +1,103 @@ -# CLI Installation Guide +# CLI Installation -This guide provides detailed instructions for installing and setting up the Nixopus CLI. +Installation guide for the Nixopus CLI with multiple installation options. ## Prerequisites -Before installing the Nixopus CLI, ensure you have: +- **Python 3.9 or higher** (supports up to Python 3.13) +- **Git** (for source installation) -- **Python 3.8 or higher** -- **pip** (Python package installer) -- **Git** (for cloning the repository) +Verify your Python version: +```bash +python3 --version +``` -### Check Python Version +## Installation Options + +### Option 1: Binary Installation (Recommended) + +Download and install the pre-built binary for your platform: ```bash -python3 --version +# Download and run the install script +curl -sSL https://raw.githubusercontent.com/raghavyuva/nixopus/master/cli/install.sh | bash + +# Or for local installation (no sudo required) +curl -sSL https://raw.githubusercontent.com/raghavyuva/nixopus/master/cli/install.sh | bash -s -- --local ``` -### Check pip Installation +**Install script options:** +- `--local`: Install to `~/.local/bin` (no sudo required) +- `--dir DIR`: Install to custom directory +- `--no-path`: Don't update PATH automatically +**Manual binary installation:** ```bash -pip --version +# Download the appropriate binary for your platform +wget https://github.com/raghavyuva/nixopus/releases/latest/download/nixopus_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m) + +# Make executable and install +chmod +x nixopus_* +sudo mv nixopus_* /usr/local/bin/nixopus + +# Or install locally without sudo +mkdir -p ~/.local/bin +mv nixopus_* ~/.local/bin/nixopus ``` -## Installation Methods +### Option 2: Poetry Installation (For Development) -### Method 1: Install from Source (Recommended) +Using Poetry for development work: + +```bash +# Clone repository +git clone https://github.com/raghavyuva/nixopus.git +cd nixopus/cli -1. **Clone the Repository** - ```bash - git clone https://github.com/raghavyuva/nixopus.git - cd nixopus - ``` +# Install with Poetry +poetry install -2. **Navigate to CLI Directory** - ```bash - cd cli - ``` +# Activate virtual environment +poetry shell -3. **Install in Development Mode** - ```bash - pip install -e . - ``` +# Verify installation +nixopus --help +``` -### Method 2: Install Dependencies +### Option 3: Python Package Installation -For development work, install additional dependencies: +Install from source using pip: ```bash -pip install -e ".[dev]" +# Clone repository +git clone https://github.com/raghavyuva/nixopus.git +cd nixopus/cli + +# Install in development mode +pip install -e . + +# Or install from wheel (if available) +pip install dist/nixopus-0.1.0-py3-none-any.whl ``` -This installs: -- **pytest**: Testing framework -- **pytest-cov**: Coverage reporting +### Option 4: Build from Source + +Build your own binary: + +```bash +# Clone repository +git clone https://github.com/raghavyuva/nixopus.git +cd nixopus/cli + +# Install Poetry dependencies +poetry install --with dev + +# Build binary +./build.sh + +# Install the built binary +./install.sh --local +``` ## Verification @@ -60,74 +105,109 @@ After installation, verify the CLI is working: ```bash nixopus --help - nixopus version ``` Expected output: ``` -┌───────────────── Version Info ───────────────── ┐ -│ Nixopus CLI version │ +┌───────────────── Version Info ─────────────────┐ +│ Nixopus CLI v0.1.0 │ └─────────────────────────────────────────────────┘ ``` ## Troubleshooting -### Common Issues +### Command Not Found -1. **Command Not Found** - - Ensure you're in the correct directory (`cli/`) - - Verify Python and pip are properly installed - - Try reinstalling: `pip install -e .` +If `nixopus` command is not found: -2. **Permission Errors** - - Use `pip install -e . --user` for user installation - - Or use a virtual environment +```bash +# Check if binary is in PATH +which nixopus + +# For local installation, add to PATH +echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc +source ~/.bashrc -3. **Import Errors** - - Check that all dependencies are installed - - Verify Python version compatibility +# Or for zsh +echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc +source ~/.zshrc +``` -### Virtual Environment (Optional) +### Permission Errors -For isolated installation: +For permission issues during installation: ```bash -python3 -m venv venv +# Use local installation +curl -sSL https://raw.githubusercontent.com/raghavyuva/nixopus/cli/install.sh | bash -s -- --local -# Activate virtual environment -source venv/bin/activate # On macOS/Linux -# or -venv\Scripts\activate # On Windows +# Or install to custom directory +curl -sSL https://raw.githubusercontent.com/raghavyuva/nixopus/cli/install.sh | bash -s -- --dir ~/bin +``` -# Install CLI -pip install -e . +### Python Version Issues + +For Python version compatibility issues: + +```bash +# Check Python version +python3 --version + +# Install specific Python version if needed (example for Ubuntu) +sudo apt update +sudo apt install python3.9 + +# Or use pyenv for version management +curl https://pyenv.run | bash +pyenv install 3.9.0 +pyenv local 3.9.0 ``` -## Development Setup +## Development Installation -For contributors who want to develop the CLI: +For contributing to the CLI: -1. **Clone and Install** - ```bash - git clone https://github.com/raghavyuva/nixopus.git - cd nixopus/cli - pip install -e ".[dev]" - ``` +```bash +# Clone and setup +git clone https://github.com/raghavyuva/nixopus.git +cd nixopus/cli -2. **Run Tests** - ```bash - pytest - ``` +# Install with development dependencies +poetry install --with dev -3. **Check Coverage** - ```bash - pytest --cov=core --cov=utils --cov-report=term-missing - ``` +# Activate environment +poetry shell -## Next Steps +# Run tests to verify setup +make test +``` -After successful installation: +Available development commands: +```bash +make help # Show available commands +make test # Run test suite +make test-cov # Run tests with coverage +make build # Build binary +make format # Format code +make lint # Run linting +make clean # Clean build artifacts +``` + +## Uninstallation -- [Commands Reference](../cli/commands.md) - Learn available commands -- [Development Guide](../cli/development.md) - Contribute to the CLI \ No newline at end of file +To uninstall the CLI: + +```bash +# For binary installation +sudo rm /usr/local/bin/nixopus +# Or for local installation +rm ~/.local/bin/nixopus + +# For Poetry installation +cd nixopus/cli +poetry env remove python + +# For pip installation +pip uninstall nixopus +``` \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index cb61f1ae..bf873452 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,14 +5,13 @@ hero: name: "Nixopus" text: "Documentation" tagline: All the information you need to know about Nixopus - actions: - - theme: brand - text: Introduction - link: /introduction/index.md - - theme: alt - text: Installation - link: /install/index.md --- - - +

From bc34309edc97ea22fbccdf8875d6e811a0ccc533 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 30 Jul 2025 18:41:29 +0530 Subject: [PATCH 61/72] test: add unit test files for utils --- cli/app/utils/tests/test_config.py | 392 ++++++++++++++++++++ cli/app/utils/tests/test_lib.py | 533 ++++++++++++++++++++++++++++ cli/app/utils/tests/test_timeout.py | 192 ++++++++++ 3 files changed, 1117 insertions(+) create mode 100644 cli/app/utils/tests/test_config.py create mode 100644 cli/app/utils/tests/test_lib.py create mode 100644 cli/app/utils/tests/test_timeout.py diff --git a/cli/app/utils/tests/test_config.py b/cli/app/utils/tests/test_config.py new file mode 100644 index 00000000..8d0e6033 --- /dev/null +++ b/cli/app/utils/tests/test_config.py @@ -0,0 +1,392 @@ +import os +import sys +import tempfile +import unittest +from unittest.mock import Mock, patch, mock_open + +from app.utils.config import Config, expand_env_placeholders +from app.utils.message import MISSING_CONFIG_KEY_MESSAGE + +class TestConfig(unittest.TestCase): + def setUp(self): + self.temp_dir = tempfile.mkdtemp() + self.test_config_path = os.path.join(self.temp_dir, "test_config.yaml") + self.sample_config = { + "services": { + "api": { + "env": { + "PORT": "${API_PORT:-8443}", + "DB_NAME": "${DB_NAME:-postgres}" + } + }, + "view": { + "env": { + "PORT": "${VIEW_PORT:-7443}" + } + } + }, + "clone": { + "repo": "https://github.com/test/repo", + "branch": "main", + "source-path": "/tmp/source" + }, + "deps": { + "curl": {"package": "curl", "command": "curl"}, + "docker": {"package": "docker.io", "command": "docker"} + }, + "ports": [2019, 80, 443, 7443, 8443] + } + + def tearDown(self): + import shutil + shutil.rmtree(self.temp_dir, ignore_errors=True) + + def test_get_env_default(self): + if "ENV" in os.environ: + del os.environ["ENV"] + config = Config() + self.assertEqual(config.get_env(), "PRODUCTION") + + @patch('os.environ.get') + def test_get_env_custom(self, mock_environ_get): + mock_environ_get.return_value = "DEVELOPMENT" + config = Config() + self.assertEqual(config.get_env(), "DEVELOPMENT") + + @patch('os.environ.get') + def test_is_development_true(self, mock_environ_get): + mock_environ_get.return_value = "DEVELOPMENT" + config = Config() + self.assertTrue(config.is_development()) + + @patch('os.environ.get') + def test_is_development_false(self, mock_environ_get): + mock_environ_get.return_value = "PRODUCTION" + config = Config() + self.assertFalse(config.is_development()) + + @patch('os.environ.get') + def test_is_development_case_insensitive(self, mock_environ_get): + mock_environ_get.return_value = "development" + config = Config() + self.assertTrue(config.is_development()) + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + def test_load_yaml_config_success(self, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + config = Config() + result = config.load_yaml_config() + self.assertEqual(result, self.sample_config) + mock_file.assert_called_once() + + @patch('builtins.open') + def test_load_yaml_config_file_not_found(self, mock_open): + mock_open.side_effect = FileNotFoundError("File not found") + config = Config() + with self.assertRaises(FileNotFoundError): + config.load_yaml_config() + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + def test_load_yaml_config_cached(self, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + config = Config() + result1 = config.load_yaml_config() + result2 = config.load_yaml_config() + self.assertEqual(result1, result2) + self.assertEqual(mock_yaml_load.call_count, 1) + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + @patch('app.utils.config.expand_env_placeholders') + def test_get_yaml_value_success(self, mock_expand, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + mock_expand.return_value = "8443" + config = Config() + result = config.get_yaml_value("services.api.env.PORT") + self.assertEqual(result, "8443") + mock_expand.assert_called_once_with("${API_PORT:-8443}") + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + def test_get_yaml_value_non_string(self, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + config = Config() + result = config.get_yaml_value("ports") + self.assertEqual(result, [2019, 80, 443, 7443, 8443]) + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + def test_get_yaml_value_missing_key(self, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + config = Config() + with self.assertRaises(KeyError) as context: + config.get_yaml_value("services.api.env.NONEXISTENT") + expected_message = MISSING_CONFIG_KEY_MESSAGE.format( + path="services.api.env.NONEXISTENT", + key="NONEXISTENT" + ) + self.assertEqual(context.exception.args[0], expected_message) + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + def test_get_yaml_value_missing_path(self, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + config = Config() + with self.assertRaises(KeyError) as context: + config.get_yaml_value("nonexistent.path") + expected_message = MISSING_CONFIG_KEY_MESSAGE.format( + path="nonexistent.path", + key="nonexistent" + ) + self.assertEqual(context.exception.args[0], expected_message) + + @patch('builtins.open', new_callable=mock_open) + @patch('yaml.safe_load') + @patch('app.utils.config.expand_env_placeholders') + def test_get_service_env_values(self, mock_expand, mock_yaml_load, mock_file): + mock_yaml_load.return_value = self.sample_config + mock_expand.side_effect = lambda x: x.replace("${API_PORT:-8443}", "8443") + config = Config() + result = config.get_service_env_values("services.api.env") + expected = { + "PORT": "8443", + "DB_NAME": "${DB_NAME:-postgres}" + } + self.assertEqual(result, expected) + + @patch('yaml.safe_load') + def test_load_user_config_success(self, mock_yaml_load): + user_config = { + "services": { + "api": { + "env": { + "PORT": "9000" + } + } + } + } + mock_yaml_load.return_value = user_config + with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f: + f.write("dummy content") + config_file = f.name + try: + config = Config() + result = config.load_user_config(config_file) + expected = { + "services.api.env.PORT": "9000" + } + self.assertEqual(result, expected) + finally: + os.unlink(config_file) + + def test_load_user_config_empty_file(self): + config = Config() + result = config.load_user_config(None) + self.assertEqual(result, {}) + + def test_load_user_config_file_not_found(self): + config = Config() + with self.assertRaises(FileNotFoundError) as context: + config.load_user_config("/nonexistent/file.yaml") + self.assertIn("Config file not found", str(context.exception)) + + def test_flatten_config_simple(self): + config = Config() + nested = {"a": 1, "b": 2} + flattened = {} + config.flatten_config(nested, flattened) + self.assertEqual(flattened, {"a": 1, "b": 2}) + + def test_flatten_config_nested(self): + config = Config() + nested = { + "services": { + "api": { + "env": { + "PORT": "8443" + } + } + } + } + flattened = {} + config.flatten_config(nested, flattened) + expected = { + "services.api.env.PORT": "8443" + } + self.assertEqual(flattened, expected) + + def test_flatten_config_with_prefix(self): + config = Config() + nested = {"a": 1} + flattened = {} + config.flatten_config(nested, flattened, "prefix") + self.assertEqual(flattened, {"prefix.a": 1}) + + def test_get_config_value_cached(self): + config = Config() + user_config = {"test.key": "value"} + defaults = {"test.key": "default"} + result1 = config.get_config_value("test.key", user_config, defaults) + result2 = config.get_config_value("test.key", user_config, defaults) + self.assertEqual(result1, "value") + self.assertEqual(result2, "value") + self.assertEqual(result1, result2) + + def test_get_config_value_user_config_priority(self): + config = Config() + user_config = {"services.caddy.env.PROXY_PORT": "2020"} + defaults = {"proxy_port": "2019"} + result = config.get_config_value("proxy_port", user_config, defaults) + self.assertEqual(result, "2020") + + def test_get_config_value_defaults_fallback(self): + config = Config() + user_config = {} + defaults = {"proxy_port": "2019"} + result = config.get_config_value("proxy_port", user_config, defaults) + self.assertEqual(result, "2019") + + def test_get_config_value_missing_no_default(self): + config = Config() + user_config = {} + defaults = {} + with self.assertRaises(ValueError) as context: + config.get_config_value("missing_key", user_config, defaults) + self.assertIn("Configuration key 'missing_key' has no default value", str(context.exception)) + + def test_get_config_value_ssh_passphrase_optional(self): + config = Config() + user_config = {} + defaults = {} + result = config.get_config_value("ssh_passphrase", user_config, defaults) + self.assertIsNone(result) + + def test_get_config_value_key_mappings(self): + config = Config() + user_config = { + "clone.repo": "https://github.com/test/repo", + "clone.branch": "main", + "clone.source-path": "/tmp/source" + } + defaults = {} + repo_result = config.get_config_value("repo_url", user_config, defaults) + branch_result = config.get_config_value("branch_name", user_config, defaults) + path_result = config.get_config_value("source_path", user_config, defaults) + self.assertEqual(repo_result, "https://github.com/test/repo") + self.assertEqual(branch_result, "main") + self.assertEqual(path_result, "/tmp/source") + + def test_config_pyinstaller_bundle(self): + sys.frozen = True + sys._MEIPASS = "/bundle" + with patch('os.path.join') as mock_join: + mock_join.return_value = "/bundle/helpers/config.prod.yaml" + config = Config() + self.assertEqual(config._yaml_path, "/bundle/helpers/config.prod.yaml") + del sys.frozen + del sys._MEIPASS + + def test_config_normal_python(self): + if hasattr(sys, 'frozen'): + del sys.frozen + if hasattr(sys, '_MEIPASS'): + del sys._MEIPASS + with patch('os.path.abspath') as mock_abspath: + mock_abspath.return_value = "/normal/path/helpers/config.prod.yaml" + config = Config() + self.assertNotIn("_MEIPASS", config._yaml_path) + +class TestExpandEnvPlaceholders(unittest.TestCase): + def setUp(self): + self.original_environ = os.environ.copy() + + def tearDown(self): + os.environ.clear() + os.environ.update(self.original_environ) + + def test_expand_env_placeholders_no_placeholders(self): + result = expand_env_placeholders("simple string") + self.assertEqual(result, "simple string") + + def test_expand_env_placeholders_simple_variable(self): + os.environ["TEST_VAR"] = "test_value" + result = expand_env_placeholders("${TEST_VAR}") + self.assertEqual(result, "test_value") + + def test_expand_env_placeholders_with_default(self): + result = expand_env_placeholders("${TEST_VAR:-default_value}") + self.assertEqual(result, "default_value") + + def test_expand_env_placeholders_variable_overrides_default(self): + os.environ["TEST_VAR"] = "actual_value" + result = expand_env_placeholders("${TEST_VAR:-default_value}") + self.assertEqual(result, "actual_value") + + def test_expand_env_placeholders_multiple_placeholders(self): + os.environ["VAR1"] = "value1" + os.environ["VAR2"] = "value2" + result = expand_env_placeholders("${VAR1} and ${VAR2}") + self.assertEqual(result, "value1 and value2") + + def test_expand_env_placeholders_mixed_content(self): + os.environ["PORT"] = "8443" + result = expand_env_placeholders("http://localhost:${PORT:-8080}/api") + self.assertEqual(result, "http://localhost:8443/api") + + def test_expand_env_placeholders_empty_default(self): + result = expand_env_placeholders("${TEST_VAR:-}") + self.assertEqual(result, "") + + def test_expand_env_placeholders_complex_default(self): + result = expand_env_placeholders("${TEST_VAR:-http://localhost:8080}") + self.assertEqual(result, "http://localhost:8080") + + def test_expand_env_placeholders_special_characters_in_default(self): + result = expand_env_placeholders("${TEST_VAR:-/path/with/special/chars}") + self.assertEqual(result, "/path/with/special/chars") + + def test_expand_env_placeholders_numeric_default(self): + result = expand_env_placeholders("${TEST_VAR:-123}") + self.assertEqual(result, "123") + + def test_expand_env_placeholders_underscore_in_variable_name(self): + os.environ["TEST_VAR_NAME"] = "test_value" + result = expand_env_placeholders("${TEST_VAR_NAME}") + self.assertEqual(result, "test_value") + + def test_expand_env_placeholders_case_sensitive(self): + os.environ["test_var"] = "lowercase" + os.environ["TEST_VAR"] = "uppercase" + result = expand_env_placeholders("${test_var} and ${TEST_VAR}") + self.assertEqual(result, "lowercase and uppercase") + + def test_expand_env_placeholders_invalid_variable_name(self): + result = expand_env_placeholders("${123INVALID}") + self.assertEqual(result, "${123INVALID}") + + def test_expand_env_placeholders_malformed_placeholder(self): + result = expand_env_placeholders("${MISSING_BRACE") + self.assertEqual(result, "${MISSING_BRACE") + + def test_expand_env_placeholders_empty_variable_name(self): + result = expand_env_placeholders("${}") + self.assertEqual(result, "${}") + + def test_expand_env_placeholders_nested_braces(self): + result = expand_env_placeholders("${TEST_VAR:-{nested}}") + self.assertEqual(result, "{nested}") + + def test_expand_env_placeholders_multiple_defaults(self): + result = expand_env_placeholders("${VAR1:-default1} and ${VAR2:-default2}") + self.assertEqual(result, "default1 and default2") + + def test_expand_env_placeholders_real_world_example(self): + os.environ["API_PORT"] = "9000" + os.environ["DB_NAME"] = "production_db" + result = expand_env_placeholders("${API_PORT:-8443} and ${DB_NAME:-postgres}") + self.assertEqual(result, "9000 and production_db") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/cli/app/utils/tests/test_lib.py b/cli/app/utils/tests/test_lib.py new file mode 100644 index 00000000..5241d852 --- /dev/null +++ b/cli/app/utils/tests/test_lib.py @@ -0,0 +1,533 @@ +import os +import platform +import shutil +import stat +import tempfile +import unittest +from unittest.mock import Mock, patch, mock_open +import requests + +from app.utils.lib import ( + SupportedOS, + SupportedDistribution, + SupportedPackageManager, + Supported, + HostInformation, + ParallelProcessor, + DirectoryManager, + FileManager, +) +from app.utils.message import ( + FAILED_TO_GET_PUBLIC_IP_MESSAGE, + FAILED_TO_REMOVE_DIRECTORY_MESSAGE, + REMOVED_DIRECTORY_MESSAGE, +) + + +class TestSupportedOS(unittest.TestCase): + def test_supported_os_values(self): + self.assertEqual(SupportedOS.LINUX.value, "linux") + self.assertEqual(SupportedOS.MACOS.value, "darwin") + + +class TestSupportedDistribution(unittest.TestCase): + def test_supported_distribution_values(self): + self.assertEqual(SupportedDistribution.DEBIAN.value, "debian") + self.assertEqual(SupportedDistribution.UBUNTU.value, "ubuntu") + self.assertEqual(SupportedDistribution.CENTOS.value, "centos") + self.assertEqual(SupportedDistribution.FEDORA.value, "fedora") + self.assertEqual(SupportedDistribution.ALPINE.value, "alpine") + + +class TestSupportedPackageManager(unittest.TestCase): + def test_supported_package_manager_values(self): + self.assertEqual(SupportedPackageManager.APT.value, "apt") + self.assertEqual(SupportedPackageManager.YUM.value, "yum") + self.assertEqual(SupportedPackageManager.DNF.value, "dnf") + self.assertEqual(SupportedPackageManager.PACMAN.value, "pacman") + self.assertEqual(SupportedPackageManager.APK.value, "apk") + self.assertEqual(SupportedPackageManager.BREW.value, "brew") + + +class TestSupported(unittest.TestCase): + def test_os_supported(self): + self.assertTrue(Supported.os("linux")) + self.assertTrue(Supported.os("darwin")) + + def test_os_not_supported(self): + self.assertFalse(Supported.os("windows")) + self.assertFalse(Supported.os("freebsd")) + self.assertFalse(Supported.os("")) + + def test_os_case_sensitive(self): + self.assertFalse(Supported.os("Linux")) + self.assertFalse(Supported.os("DARWIN")) + + def test_distribution_supported(self): + self.assertTrue(Supported.distribution("debian")) + self.assertTrue(Supported.distribution("ubuntu")) + self.assertTrue(Supported.distribution("centos")) + + def test_distribution_not_supported(self): + self.assertFalse(Supported.distribution("arch")) + self.assertFalse(Supported.distribution("gentoo")) + self.assertFalse(Supported.distribution("")) + + def test_package_manager_supported(self): + self.assertTrue(Supported.package_manager("apt")) + self.assertTrue(Supported.package_manager("yum")) + self.assertTrue(Supported.package_manager("brew")) + + def test_package_manager_not_supported(self): + self.assertFalse(Supported.package_manager("pip")) + self.assertFalse(Supported.package_manager("npm")) + self.assertFalse(Supported.package_manager("")) + + def test_get_os(self): + os_list = Supported.get_os() + self.assertIsInstance(os_list, list) + self.assertIn("linux", os_list) + self.assertIn("darwin", os_list) + self.assertEqual(len(os_list), 2) + + def test_get_distributions(self): + dist_list = Supported.get_distributions() + self.assertIsInstance(dist_list, list) + self.assertIn("debian", dist_list) + self.assertIn("ubuntu", dist_list) + self.assertIn("centos", dist_list) + self.assertIn("fedora", dist_list) + self.assertIn("alpine", dist_list) + self.assertEqual(len(dist_list), 5) + + +class TestHostInformation(unittest.TestCase): + @patch("platform.system") + def test_get_os_name(self, mock_system): + mock_system.return_value = "Linux" + self.assertEqual(HostInformation.get_os_name(), "linux") + + mock_system.return_value = "Darwin" + self.assertEqual(HostInformation.get_os_name(), "darwin") + + mock_system.return_value = "Windows" + self.assertEqual(HostInformation.get_os_name(), "windows") + + @patch("app.utils.lib.HostInformation.get_os_name") + @patch("app.utils.lib.HostInformation.command_exists") + def test_get_package_manager_macos(self, mock_command_exists, mock_get_os_name): + mock_get_os_name.return_value = "darwin" + mock_command_exists.return_value = True + + result = HostInformation.get_package_manager() + self.assertEqual(result, "brew") + + @patch("app.utils.lib.HostInformation.get_os_name") + @patch("app.utils.lib.HostInformation.command_exists") + def test_get_package_manager_linux_apt(self, mock_command_exists, mock_get_os_name): + mock_get_os_name.return_value = "linux" + + def command_exists_side_effect(command): + return command == "apt" + + mock_command_exists.side_effect = command_exists_side_effect + + result = HostInformation.get_package_manager() + self.assertEqual(result, "apt") + + @patch("app.utils.lib.HostInformation.get_os_name") + @patch("app.utils.lib.HostInformation.command_exists") + def test_get_package_manager_linux_yum(self, mock_command_exists, mock_get_os_name): + mock_get_os_name.return_value = "linux" + + def command_exists_side_effect(command): + return command == "yum" + + mock_command_exists.side_effect = command_exists_side_effect + + result = HostInformation.get_package_manager() + self.assertEqual(result, "yum") + + @patch("app.utils.lib.HostInformation.get_os_name") + @patch("app.utils.lib.HostInformation.command_exists") + def test_get_package_manager_no_supported_manager(self, mock_command_exists, mock_get_os_name): + mock_get_os_name.return_value = "linux" + mock_command_exists.return_value = False + + with self.assertRaises(RuntimeError) as context: + HostInformation.get_package_manager() + + self.assertIn("No supported package manager found", str(context.exception)) + + @patch("shutil.which") + def test_command_exists_true(self, mock_which): + mock_which.return_value = "/usr/bin/apt" + self.assertTrue(HostInformation.command_exists("apt")) + + @patch("shutil.which") + def test_command_exists_false(self, mock_which): + mock_which.return_value = None + self.assertFalse(HostInformation.command_exists("nonexistent")) + + @patch("requests.get") + def test_get_public_ip_success(self, mock_get): + mock_response = Mock() + mock_response.text = "192.168.1.1" + mock_response.raise_for_status.return_value = None + mock_get.return_value = mock_response + + result = HostInformation.get_public_ip() + self.assertEqual(result, "192.168.1.1") + mock_get.assert_called_once_with("https://api.ipify.org", timeout=10) + + @patch("requests.get") + def test_get_public_ip_http_error(self, mock_get): + mock_get.side_effect = requests.HTTPError("404 Not Found") + + with self.assertRaises(Exception) as context: + HostInformation.get_public_ip() + + self.assertEqual(str(context.exception), FAILED_TO_GET_PUBLIC_IP_MESSAGE) + + @patch("requests.get") + def test_get_public_ip_connection_error(self, mock_get): + mock_get.side_effect = requests.ConnectionError("Connection failed") + + with self.assertRaises(Exception) as context: + HostInformation.get_public_ip() + + self.assertEqual(str(context.exception), FAILED_TO_GET_PUBLIC_IP_MESSAGE) + + @patch("requests.get") + def test_get_public_ip_timeout(self, mock_get): + mock_get.side_effect = requests.Timeout("Request timeout") + + with self.assertRaises(Exception) as context: + HostInformation.get_public_ip() + + self.assertEqual(str(context.exception), FAILED_TO_GET_PUBLIC_IP_MESSAGE) + + +class TestParallelProcessor(unittest.TestCase): + def test_process_items_empty_list(self): + def processor(x): + return x * 2 + + results = ParallelProcessor.process_items([], processor) + self.assertEqual(results, []) + + def test_process_items_single_item(self): + def processor(x): + return x * 2 + + results = ParallelProcessor.process_items([5], processor) + self.assertEqual(results, [10]) + + def test_process_items_multiple_items(self): + def processor(x): + return x * 2 + + results = ParallelProcessor.process_items([1, 2, 3, 4, 5], processor) + self.assertEqual(len(results), 5) + self.assertEqual(set(results), {2, 4, 6, 8, 10}) + + def test_process_items_with_error_handler(self): + def processor(x): + if x == 3: + raise ValueError("Test error") + return x * 2 + + def error_handler(item, error): + return f"Error processing {item}: {str(error)}" + + results = ParallelProcessor.process_items([1, 2, 3, 4, 5], processor, error_handler=error_handler) + self.assertEqual(len(results), 5) + + error_results = [r for r in results if "Error processing 3" in str(r)] + normal_results = [r for r in results if isinstance(r, int)] + + self.assertEqual(len(error_results), 1) + self.assertEqual(set(normal_results), {2, 4, 8, 10}) + + def test_process_items_without_error_handler(self): + def processor(x): + if x == 3: + raise ValueError("Test error") + return x * 2 + + results = ParallelProcessor.process_items([1, 2, 3, 4, 5], processor) + self.assertEqual(len(results), 4) + self.assertEqual(set(results), {2, 4, 8, 10}) + + def test_process_items_max_workers_limit(self): + def processor(x): + return x * 2 + + results = ParallelProcessor.process_items([1, 2, 3, 4, 5], processor, max_workers=2) + self.assertEqual(len(results), 5) + self.assertEqual(set(results), {2, 4, 6, 8, 10}) + + def test_process_items_max_workers_exceeds_items(self): + def processor(x): + return x * 2 + + results = ParallelProcessor.process_items([1, 2], processor, max_workers=10) + self.assertEqual(len(results), 2) + self.assertEqual(set(results), {2, 4}) + + +class TestDirectoryManager(unittest.TestCase): + @patch("os.path.exists") + def test_path_exists_true(self, mock_exists): + mock_exists.return_value = True + self.assertTrue(DirectoryManager.path_exists("/test/path")) + + @patch("os.path.exists") + def test_path_exists_false(self, mock_exists): + mock_exists.return_value = False + self.assertFalse(DirectoryManager.path_exists("/test/path")) + + @patch("os.path.exists") + def test_path_exists_and_not_force_true(self, mock_exists): + mock_exists.return_value = True + self.assertTrue(DirectoryManager.path_exists_and_not_force("/test/path", False)) + + @patch("os.path.exists") + def test_path_exists_and_not_force_false_when_force(self, mock_exists): + mock_exists.return_value = True + self.assertFalse(DirectoryManager.path_exists_and_not_force("/test/path", True)) + + @patch("os.path.exists") + def test_path_exists_and_not_force_false_when_not_exists(self, mock_exists): + mock_exists.return_value = False + self.assertFalse(DirectoryManager.path_exists_and_not_force("/test/path", False)) + + @patch("shutil.rmtree") + @patch("os.path.exists") + @patch("os.path.isdir") + def test_remove_directory_success(self, mock_isdir, mock_exists, mock_rmtree): + mock_exists.return_value = True + mock_isdir.return_value = True + mock_logger = Mock() + + result = DirectoryManager.remove_directory("/test/path", mock_logger) + + self.assertTrue(result) + mock_rmtree.assert_called_once_with("/test/path") + mock_logger.debug.assert_called() + + @patch("shutil.rmtree") + @patch("os.path.exists") + def test_remove_directory_success_no_logger(self, mock_exists, mock_rmtree): + mock_exists.return_value = True + + result = DirectoryManager.remove_directory("/test/path") + + self.assertTrue(result) + mock_rmtree.assert_called_once_with("/test/path") + + @patch("shutil.rmtree") + @patch("os.path.exists") + def test_remove_directory_failure(self, mock_exists, mock_rmtree): + mock_exists.return_value = True + mock_rmtree.side_effect = PermissionError("Permission denied") + mock_logger = Mock() + + result = DirectoryManager.remove_directory("/test/path", mock_logger) + + self.assertFalse(result) + mock_logger.debug.assert_called() + mock_logger.error.assert_called_once() + + @patch("shutil.rmtree") + @patch("os.path.exists") + def test_remove_directory_failure_no_logger(self, mock_exists, mock_rmtree): + mock_exists.return_value = True + mock_rmtree.side_effect = OSError("Directory not found") + + result = DirectoryManager.remove_directory("/test/path") + + self.assertFalse(result) + + +class TestFileManager(unittest.TestCase): + def setUp(self): + self.temp_dir = tempfile.mkdtemp() + self.test_file = os.path.join(self.temp_dir, "test.txt") + + def tearDown(self): + shutil.rmtree(self.temp_dir, ignore_errors=True) + + @patch("os.chmod") + def test_set_permissions_success(self, mock_chmod): + mock_logger = Mock() + + with open(self.test_file, "w") as f: + f.write("test content") + + success, error = FileManager.set_permissions(self.test_file, 0o644, mock_logger) + + self.assertTrue(success) + self.assertIsNone(error) + mock_chmod.assert_called_once_with(self.test_file, 0o644) + mock_logger.debug.assert_called() + + @patch("os.chmod") + def test_set_permissions_failure(self, mock_chmod): + mock_chmod.side_effect = PermissionError("Permission denied") + mock_logger = Mock() + + success, error = FileManager.set_permissions(self.test_file, 0o644, mock_logger) + + self.assertFalse(success) + self.assertIn("Failed to set permissions", error) + mock_logger.error.assert_called_once() + + @patch("os.chmod") + def test_set_permissions_success_no_logger(self, mock_chmod): + with open(self.test_file, "w") as f: + f.write("test content") + + success, error = FileManager.set_permissions(self.test_file, 0o644) + + self.assertTrue(success) + self.assertIsNone(error) + mock_chmod.assert_called_once_with(self.test_file, 0o644) + + @patch("os.makedirs") + def test_create_directory_success_new(self, mock_makedirs): + mock_logger = Mock() + test_dir = os.path.join(self.temp_dir, "new_dir") + + success, error = FileManager.create_directory(test_dir, 0o755, mock_logger) + + self.assertTrue(success) + self.assertIsNone(error) + mock_makedirs.assert_called_once_with(test_dir, mode=0o755) + mock_logger.debug.assert_called_once() + + @patch("os.makedirs") + @patch("os.path.exists") + def test_create_directory_success_exists(self, mock_exists, mock_makedirs): + mock_logger = Mock() + test_dir = os.path.join(self.temp_dir, "existing_dir") + mock_exists.return_value = True + + success, error = FileManager.create_directory(test_dir, 0o755, mock_logger) + + self.assertTrue(success) + self.assertIsNone(error) + mock_makedirs.assert_not_called() + + @patch("os.makedirs") + def test_create_directory_failure(self, mock_makedirs): + mock_makedirs.side_effect = PermissionError("Permission denied") + mock_logger = Mock() + test_dir = "/root/restricted_dir" + + success, error = FileManager.create_directory(test_dir, 0o755, mock_logger) + + self.assertFalse(success) + self.assertIn("Failed to create directory", error) + mock_logger.error.assert_called_once() + + def test_append_to_file_success(self): + mock_logger = Mock() + content = "new content" + + success, error = FileManager.append_to_file(self.test_file, content, 0o644, mock_logger) + + self.assertTrue(success) + self.assertIsNone(error) + + with open(self.test_file, "r") as f: + file_content = f.read() + + self.assertIn(content, file_content) + mock_logger.debug.assert_called() + + def test_append_to_file_failure_permission(self): + mock_logger = Mock() + content = "new content" + + with patch("builtins.open", side_effect=PermissionError("Permission denied")): + success, error = FileManager.append_to_file(self.test_file, content, 0o644, mock_logger) + + self.assertFalse(success) + self.assertIn("Failed to append to", error) + mock_logger.error.assert_called_once() + + def test_read_file_content_success(self): + content = "test content" + with open(self.test_file, "w") as f: + f.write(content) + + success, file_content, error = FileManager.read_file_content(self.test_file) + + self.assertTrue(success) + self.assertEqual(file_content, content) + self.assertIsNone(error) + + def test_read_file_content_failure(self): + mock_logger = Mock() + + with patch("builtins.open", side_effect=FileNotFoundError("File not found")): + success, file_content, error = FileManager.read_file_content(self.test_file, mock_logger) + + self.assertFalse(success) + self.assertIsNone(file_content) + self.assertIn("Failed to read", error) + mock_logger.error.assert_called_once() + + def test_read_file_content_strips_whitespace(self): + content = " test content \n" + with open(self.test_file, "w") as f: + f.write(content) + + success, file_content, error = FileManager.read_file_content(self.test_file) + + self.assertTrue(success) + self.assertEqual(file_content, "test content") + self.assertIsNone(error) + + @patch("os.path.expanduser") + def test_expand_user_path(self, mock_expanduser): + mock_expanduser.return_value = "/home/user/test" + + result = FileManager.expand_user_path("~/test") + + self.assertEqual(result, "/home/user/test") + mock_expanduser.assert_called_once_with("~/test") + + @patch("os.path.dirname") + def test_get_directory_path(self, mock_dirname): + mock_dirname.return_value = "/path/to" + + result = FileManager.get_directory_path("/path/to/file.txt") + + self.assertEqual(result, "/path/to") + mock_dirname.assert_called_once_with("/path/to/file.txt") + + def test_get_public_key_path(self): + private_key_path = "/path/to/id_rsa" + expected_public_key_path = "/path/to/id_rsa.pub" + + result = FileManager.get_public_key_path(private_key_path) + + self.assertEqual(result, expected_public_key_path) + + def test_get_public_key_path_empty_string(self): + result = FileManager.get_public_key_path("") + self.assertEqual(result, ".pub") + + def test_get_public_key_path_with_spaces(self): + private_key_path = "/path with spaces/id_rsa" + expected_public_key_path = "/path with spaces/id_rsa.pub" + + result = FileManager.get_public_key_path(private_key_path) + + self.assertEqual(result, expected_public_key_path) + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/cli/app/utils/tests/test_timeout.py b/cli/app/utils/tests/test_timeout.py new file mode 100644 index 00000000..2744bba8 --- /dev/null +++ b/cli/app/utils/tests/test_timeout.py @@ -0,0 +1,192 @@ +import signal +import time +import unittest +from unittest.mock import Mock, patch + +from app.utils.timeout import TimeoutWrapper +from app.commands.install.messages import timeout_error + + +class TestTimeoutWrapper(unittest.TestCase): + def setUp(self): + self.original_signal = signal.signal + self.original_alarm = signal.alarm + + def tearDown(self): + signal.signal = self.original_signal + signal.alarm = self.original_alarm + + def test_timeout_wrapper_zero_timeout(self): + with TimeoutWrapper(0) as wrapper: + self.assertEqual(wrapper.timeout, 0) + time.sleep(0.1) + + def test_timeout_wrapper_negative_timeout(self): + with TimeoutWrapper(-1) as wrapper: + self.assertEqual(wrapper.timeout, -1) + time.sleep(0.1) + + def test_timeout_wrapper_positive_timeout_success(self): + with TimeoutWrapper(5) as wrapper: + self.assertEqual(wrapper.timeout, 5) + time.sleep(0.1) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_signal_setup(self, mock_alarm, mock_signal): + mock_signal.return_value = None + + with TimeoutWrapper(10) as wrapper: + mock_signal.assert_called_once_with(signal.SIGALRM, unittest.mock.ANY) + mock_alarm.assert_called_once_with(10) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_signal_cleanup(self, mock_alarm, mock_signal): + mock_signal.return_value = None + + with TimeoutWrapper(10): + pass + + mock_alarm.assert_has_calls([ + unittest.mock.call(10), + unittest.mock.call(0) + ]) + self.assertEqual(mock_signal.call_count, 2) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_zero_timeout_no_signal_setup(self, mock_alarm, mock_signal): + with TimeoutWrapper(0): + pass + + mock_signal.assert_not_called() + mock_alarm.assert_not_called() + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_negative_timeout_no_signal_setup(self, mock_alarm, mock_signal): + with TimeoutWrapper(-5): + pass + + mock_signal.assert_not_called() + mock_alarm.assert_not_called() + + def test_timeout_wrapper_timeout_triggered(self): + with self.assertRaises(TimeoutError) as context: + with TimeoutWrapper(1): + time.sleep(2) + + expected_message = timeout_error.format(timeout=1) + self.assertEqual(str(context.exception), expected_message) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_exception_handling(self, mock_alarm, mock_signal): + mock_signal.return_value = None + + with self.assertRaises(ValueError): + with TimeoutWrapper(10): + raise ValueError("Test exception") + + mock_alarm.assert_has_calls([ + unittest.mock.call(10), + unittest.mock.call(0) + ]) + mock_signal.assert_has_calls([ + unittest.mock.call(signal.SIGALRM, unittest.mock.ANY), + unittest.mock.call(signal.SIGALRM, None) + ]) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_signal_handler_registration(self, mock_alarm, mock_signal): + mock_signal.return_value = None + + with TimeoutWrapper(5) as wrapper: + mock_signal.assert_called_once() + call_args = mock_signal.call_args + self.assertEqual(call_args[0][0], signal.SIGALRM) + self.assertTrue(callable(call_args[0][1])) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_signal_handler_raises_timeout(self, mock_alarm, mock_signal): + mock_signal.return_value = None + + with TimeoutWrapper(5) as wrapper: + signal_handler = mock_signal.call_args[0][1] + + with self.assertRaises(TimeoutError) as context: + signal_handler(signal.SIGALRM, None) + + expected_message = timeout_error.format(timeout=5) + self.assertEqual(str(context.exception), expected_message) + + def test_timeout_wrapper_nested_usage(self): + with TimeoutWrapper(10) as outer: + with TimeoutWrapper(5) as inner: + self.assertEqual(outer.timeout, 10) + self.assertEqual(inner.timeout, 5) + time.sleep(0.1) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_multiple_instances(self, mock_alarm, mock_signal): + mock_signal.return_value = None + + wrapper1 = TimeoutWrapper(10) + wrapper2 = TimeoutWrapper(5) + + with wrapper1: + with wrapper2: + pass + + self.assertEqual(mock_alarm.call_count, 4) + + def test_timeout_wrapper_return_value(self): + with TimeoutWrapper(10) as wrapper: + self.assertIsInstance(wrapper, TimeoutWrapper) + self.assertEqual(wrapper.timeout, 10) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_signal_restoration(self, mock_alarm, mock_signal): + original_handler = Mock() + mock_signal.return_value = original_handler + + with TimeoutWrapper(10): + pass + + mock_signal.assert_has_calls([ + unittest.mock.call(signal.SIGALRM, unittest.mock.ANY), + unittest.mock.call(signal.SIGALRM, original_handler) + ]) + + def test_timeout_wrapper_large_timeout_value(self): + with TimeoutWrapper(999999) as wrapper: + self.assertEqual(wrapper.timeout, 999999) + time.sleep(0.1) + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_signal_error_handling(self, mock_alarm, mock_signal): + mock_signal.side_effect = OSError("Signal not supported") + + with self.assertRaises(OSError): + with TimeoutWrapper(10): + pass + + @patch('signal.signal') + @patch('signal.alarm') + def test_timeout_wrapper_alarm_error_handling(self, mock_alarm, mock_signal): + mock_signal.return_value = None + mock_alarm.side_effect = OSError("Alarm not supported") + + with self.assertRaises(OSError): + with TimeoutWrapper(10): + pass + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 6040179f437c3939c07bc1e87340a20922abb684 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 30 Jul 2025 19:04:48 +0530 Subject: [PATCH 62/72] feat: auto generated cli reference from typer to docs --- cli/Makefile | 5 + docs/.vitepress/config.mts | 1 + docs/cli/cli-reference.md | 520 +++++++++++++++++++++++++++++++++++++ 3 files changed, 526 insertions(+) create mode 100644 docs/cli/cli-reference.md diff --git a/cli/Makefile b/cli/Makefile index f6bc2373..f0e84029 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -52,3 +52,8 @@ dev: run: poetry run nixopus + +generate-docs: + typer app.main utils docs --output + ../docs/cli/cli-reference.md --name + nixopus \ No newline at end of file diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 43c4401b..0bce3027 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -98,6 +98,7 @@ export default withMermaid( { text: 'test', link: '/cli/commands/test.md' } ] }, + { text: 'Reference', link: '/cli/cli-reference.md' }, { text: 'Development', link: '/cli/development.md' } ] }, diff --git a/docs/cli/cli-reference.md b/docs/cli/cli-reference.md new file mode 100644 index 00000000..a32a0a19 --- /dev/null +++ b/docs/cli/cli-reference.md @@ -0,0 +1,520 @@ +# `nixopus` + +Nixopus CLI - A powerful deployment and management tool + +**Usage**: + +```console +$ nixopus [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `-v, --version`: Show version information +* `--help`: Show this message and exit. + +**Commands**: + +* `preflight`: Preflight checks for system compatibility +* `clone`: Clone a repository +* `conf`: Manage configuration +* `service`: Manage Nixopus services +* `proxy`: Manage Nixopus proxy (Caddy) configuration +* `install`: Install Nixopus +* `uninstall`: Uninstall Nixopus +* `version`: Show version information +* `test`: Run tests (only in DEVELOPMENT environment) + +## `nixopus preflight` + +Preflight checks for system compatibility + +**Usage**: + +```console +$ nixopus preflight [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `--help`: Show this message and exit. + +**Commands**: + +* `check`: Run all preflight checks +* `ports`: Check if list of ports are available on a... +* `deps`: Check if list of dependencies are... + +### `nixopus preflight check` + +Run all preflight checks + +**Usage**: + +```console +$ nixopus preflight check [OPTIONS] +``` + +**Options**: + +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text,json [default: text] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus preflight ports` + +Check if list of ports are available on a host + +**Usage**: + +```console +$ nixopus preflight ports [OPTIONS] PORTS... +``` + +**Arguments**: + +* `PORTS...`: The list of ports to check [required] + +**Options**: + +* `-h, --host TEXT`: The host to check [default: localhost] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus preflight deps` + +Check if list of dependencies are available on the system + +**Usage**: + +```console +$ nixopus preflight deps [OPTIONS] DEPS... +``` + +**Arguments**: + +* `DEPS...`: The list of dependencies to check [required] + +**Options**: + +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +## `nixopus clone` + +Clone a repository + +**Usage**: + +```console +$ nixopus clone [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `-r, --repo TEXT`: The repository to clone [default: https://github.com/raghavyuva/nixopus] +* `-b, --branch TEXT`: The branch to clone [default: master] +* `-p, --path TEXT`: The path to clone the repository to [default: /etc/nixopus/source] +* `-f, --force`: Force the clone +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +## `nixopus conf` + +Manage configuration + +**Usage**: + +```console +$ nixopus conf [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `--help`: Show this message and exit. + +**Commands**: + +* `list`: List all configuration +* `delete`: Delete a configuration +* `set`: Set a configuration + +### `nixopus conf list` + +List all configuration + +**Usage**: + +```console +$ nixopus conf list [OPTIONS] +``` + +**Options**: + +* `-s, --service TEXT`: The name of the service to list configuration for, e.g api,view [default: api] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-e, --env-file TEXT`: Path to the environment file +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus conf delete` + +Delete a configuration + +**Usage**: + +```console +$ nixopus conf delete [OPTIONS] KEY +``` + +**Arguments**: + +* `KEY`: The key of the configuration to delete [required] + +**Options**: + +* `-s, --service TEXT`: The name of the service to delete configuration for, e.g api,view [default: api] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-e, --env-file TEXT`: Path to the environment file +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus conf set` + +Set a configuration + +**Usage**: + +```console +$ nixopus conf set [OPTIONS] KEY_VALUE +``` + +**Arguments**: + +* `KEY_VALUE`: Configuration in the form KEY=VALUE [required] + +**Options**: + +* `-s, --service TEXT`: The name of the service to set configuration for, e.g api,view [default: api] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-e, --env-file TEXT`: Path to the environment file +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +## `nixopus service` + +Manage Nixopus services + +**Usage**: + +```console +$ nixopus service [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `--help`: Show this message and exit. + +**Commands**: + +* `up`: Start Nixopus services +* `down`: Stop Nixopus services +* `ps`: Show status of Nixopus services +* `restart`: Restart Nixopus services + +### `nixopus service up` + +Start Nixopus services + +**Usage**: + +```console +$ nixopus service up [OPTIONS] +``` + +**Options**: + +* `-n, --name TEXT`: The name of the service to start, defaults to all [default: all] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `--dry-run`: Dry run +* `-d, --detach`: Detach from the service and run in the background +* `-e, --env-file TEXT`: Path to the environment file +* `-f, --compose-file TEXT`: Path to the compose file [default: /etc/nixopus/source/docker-compose.yml] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus service down` + +Stop Nixopus services + +**Usage**: + +```console +$ nixopus service down [OPTIONS] +``` + +**Options**: + +* `-n, --name TEXT`: The name of the service to stop, defaults to all [default: all] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `--dry-run`: Dry run +* `-e, --env-file TEXT`: Path to the environment file +* `-f, --compose-file TEXT`: Path to the compose file [default: /etc/nixopus/source/docker-compose.yml] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus service ps` + +Show status of Nixopus services + +**Usage**: + +```console +$ nixopus service ps [OPTIONS] +``` + +**Options**: + +* `-n, --name TEXT`: The name of the service to show, defaults to all [default: all] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-e, --env-file TEXT`: Path to the environment file +* `-f, --compose-file TEXT`: Path to the compose file [default: /etc/nixopus/source/docker-compose.yml] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus service restart` + +Restart Nixopus services + +**Usage**: + +```console +$ nixopus service restart [OPTIONS] +``` + +**Options**: + +* `-n, --name TEXT`: The name of the service to restart, defaults to all [default: all] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-e, --env-file TEXT`: Path to the environment file +* `-f, --compose-file TEXT`: Path to the compose file [default: /etc/nixopus/source/docker-compose.yml] +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +## `nixopus proxy` + +Manage Nixopus proxy (Caddy) configuration + +**Usage**: + +```console +$ nixopus proxy [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `--help`: Show this message and exit. + +**Commands**: + +* `load`: Load Caddy proxy configuration +* `status`: Check Caddy proxy status +* `stop`: Stop Caddy proxy + +### `nixopus proxy load` + +Load Caddy proxy configuration + +**Usage**: + +```console +$ nixopus proxy load [OPTIONS] +``` + +**Options**: + +* `-p, --proxy-port INTEGER`: Caddy admin port [default: 2019] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format: text, json [default: text] +* `--dry-run`: Dry run +* `-c, --config-file TEXT`: Path to Caddy config file +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus proxy status` + +Check Caddy proxy status + +**Usage**: + +```console +$ nixopus proxy status [OPTIONS] +``` + +**Options**: + +* `-p, --proxy-port INTEGER`: Caddy admin port [default: 2019] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format: text, json [default: text] +* `--dry-run`: Dry run +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus proxy stop` + +Stop Caddy proxy + +**Usage**: + +```console +$ nixopus proxy stop [OPTIONS] +``` + +**Options**: + +* `-p, --proxy-port INTEGER`: Caddy admin port [default: 2019] +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format: text, json [default: text] +* `--dry-run`: Dry run +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +## `nixopus install` + +Install Nixopus + +**Usage**: + +```console +$ nixopus install [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `-v, --verbose`: Show more details while installing +* `-t, --timeout INTEGER`: How long to wait for each step (in seconds) [default: 300] +* `-f, --force`: Replace files if they already exist +* `-d, --dry-run`: See what would happen, but don't make changes +* `-c, --config-file TEXT`: Path to custom config file (defaults to built-in config) +* `-ad, --api-domain TEXT`: The domain where the nixopus api will be accessible (e.g. api.nixopus.com), if not provided you can use the ip address of the server and the port (e.g. 192.168.1.100:8443) +* `-vd, --view-domain TEXT`: The domain where the nixopus view will be accessible (e.g. nixopus.com), if not provided you can use the ip address of the server and the port (e.g. 192.168.1.100:80) +* `--help`: Show this message and exit. + +**Commands**: + +* `ssh`: Generate an SSH key pair with proper... +* `deps`: Install dependencies + +### `nixopus install ssh` + +Generate an SSH key pair with proper permissions and optional authorized_keys integration + +**Usage**: + +```console +$ nixopus install ssh [OPTIONS] +``` + +**Options**: + +* `-p, --path TEXT`: The SSH key path to generate [default: ~/.ssh/nixopus_ed25519] +* `-t, --key-type TEXT`: The SSH key type (rsa, ed25519, ecdsa) [default: ed25519] +* `-s, --key-size INTEGER`: The SSH key size [default: 4096] +* `-P, --passphrase TEXT`: The passphrase to use for the SSH key +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-f, --force`: Force overwrite existing SSH key +* `-S, --set-permissions`: Set proper file permissions [default: True] +* `-a, --add-to-authorized-keys`: Add public key to authorized_keys +* `-c, --create-ssh-directory`: Create .ssh directory if it doesn't exist [default: True] +* `-T, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +### `nixopus install deps` + +Install dependencies + +**Usage**: + +```console +$ nixopus install deps [OPTIONS] +``` + +**Options**: + +* `-v, --verbose`: Verbose output +* `-o, --output TEXT`: Output format, text, json [default: text] +* `-d, --dry-run`: Dry run +* `-t, --timeout INTEGER`: Timeout in seconds [default: 10] +* `--help`: Show this message and exit. + +## `nixopus uninstall` + +Uninstall Nixopus + +**Usage**: + +```console +$ nixopus uninstall [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `-v, --verbose`: Show more details while uninstalling +* `-t, --timeout INTEGER`: How long to wait for each step (in seconds) [default: 300] +* `-d, --dry-run`: See what would happen, but don't make changes +* `-f, --force`: Remove files without confirmation prompts +* `--help`: Show this message and exit. + +## `nixopus version` + +Show version information + +**Usage**: + +```console +$ nixopus version [OPTIONS] COMMAND [ARGS]... +``` + +**Options**: + +* `--help`: Show this message and exit. + +## `nixopus test` + +Run tests (only in DEVELOPMENT environment) + +**Usage**: + +```console +$ nixopus test [OPTIONS] [TARGET] COMMAND [ARGS]... +``` + +**Arguments**: + +* `[TARGET]`: Test target (e.g., version) + +**Options**: + +* `--help`: Show this message and exit. From 4a42ec28ec90102166b314b29df95b130e1a2a21 Mon Sep 17 00:00:00 2001 From: raghavyuva Date: Wed, 30 Jul 2025 20:15:05 +0530 Subject: [PATCH 63/72] chore: update cli main to add test command only in dev environment --- cli/app/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/app/main.py b/cli/app/main.py index 5ee3b097..386a0433 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -15,6 +15,7 @@ from app.commands.version.command import main_version_callback, version_app from app.commands.version.version import VersionCommand from app.utils.message import application_add_completion, application_description, application_name, application_version_help +from app.utils.config import Config app = typer.Typer( name=application_name, @@ -80,7 +81,10 @@ def main( app.add_typer(install_app, name="install") app.add_typer(uninstall_app, name="uninstall") app.add_typer(version_app, name="version") -app.add_typer(test_app, name="test") + +config = Config() +if config.is_development(): + app.add_typer(test_app, name="test") if __name__ == "__main__": app() From 33d739f7b223156281f64d36e6fea7f75f4afa1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Fri, 1 Aug 2025 19:35:30 +0530 Subject: [PATCH 64/72] fix: cli performance issue and startup speed improvement (#300) --- cli/app/main.py | 46 +++++++++++++----------- cli/build.sh | 91 +++++++++++++++++++++++------------------------ cli/perf_check.sh | 16 +++++++++ 3 files changed, 87 insertions(+), 66 deletions(-) create mode 100644 cli/perf_check.sh diff --git a/cli/app/main.py b/cli/app/main.py index 386a0433..33d0ce88 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -1,19 +1,14 @@ +import os +import time import typer + from importlib.metadata import version as get_version from rich.console import Console from rich.panel import Panel from rich.text import Text -from app.commands.clone.command import clone_app -from app.commands.conf.command import conf_app -from app.commands.install.command import install_app -from app.commands.preflight.command import preflight_app -from app.commands.proxy.command import proxy_app -from app.commands.service.command import service_app -from app.commands.test.command import test_app -from app.commands.uninstall.command import uninstall_app -from app.commands.version.command import main_version_callback, version_app -from app.commands.version.version import VersionCommand +from app.commands.version.command import main_version_callback + from app.utils.message import application_add_completion, application_description, application_name, application_version_help from app.utils.config import Config @@ -33,39 +28,39 @@ def main( "-v", callback=main_version_callback, help=application_version_help, - ) + ), ): if ctx.invoked_subcommand is None: console = Console() - + ascii_art = """ _ _ _ _ | \\ | (_) - | \\| |___ _____ _ __ _ _ ___ - | . ` | \\ \\/ / _ \\| '_ \\| | | / __| + | \\| |___ _____ _ __ _ _ ___ ____ + | . ` | \\ \\/ / _ \\| '_ \\| | | / __| | |\\ | |> < (_) | |_) | |_| \\__ \\ |_| \\_|_/_/\\_\\___/| .__/ \\__,_|___/ | | |_| """ - + text = Text(ascii_art, style="bold cyan") panel = Panel(text, title="[bold white]Welcome to[/bold white]", border_style="cyan", padding=(1, 2)) - + console.print(panel) - + cli_version = get_version("nixopus") version_text = Text() version_text.append("Version: ", style="bold white") version_text.append(f"v{cli_version}", style="green") - + description_text = Text() description_text.append(application_description, style="dim") - + console.print(version_text) console.print(description_text) console.print() - + help_text = Text() help_text.append("Run ", style="dim") help_text.append("nixopus --help", style="bold green") @@ -73,6 +68,17 @@ def main( console.print(help_text) console.print() + +from app.commands.clone.command import clone_app +from app.commands.conf.command import conf_app +from app.commands.install.command import install_app +from app.commands.preflight.command import preflight_app +from app.commands.proxy.command import proxy_app +from app.commands.service.command import service_app +from app.commands.test.command import test_app +from app.commands.uninstall.command import uninstall_app +from app.commands.version.command import version_app + app.add_typer(preflight_app, name="preflight") app.add_typer(clone_app, name="clone") app.add_typer(conf_app, name="conf") diff --git a/cli/build.sh b/cli/build.sh index f54ff0be..ff5e0341 100755 --- a/cli/build.sh +++ b/cli/build.sh @@ -104,10 +104,8 @@ pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, - a.binaries, - a.zipfiles, - a.datas, [], + exclude_binaries=True, name='nixopus', debug=False, bootloader_ignore_signals=False, @@ -122,6 +120,17 @@ exe = EXE( codesign_identity=None, entitlements_file=None, ) + +coll = COLLECT( + exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='nixopus' +) EOF log_success "Spec file created: $SPEC_FILE" @@ -136,7 +145,7 @@ build_wheel() { } build_binary() { - log_info "Building binary..." + log_info "Building binary" poetry run pyinstaller --clean --noconfirm $SPEC_FILE @@ -148,53 +157,46 @@ build_binary() { aarch64|arm64) ARCH="arm64" ;; esac - BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" + BINARY_DIR_NAME="${APP_NAME}_${OS}_${ARCH}" - if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then - if [[ -f "$BUILD_DIR/$APP_NAME" ]]; then - mv $BUILD_DIR/$APP_NAME $BUILD_DIR/$BINARY_NAME - ln -sf "$BINARY_NAME" "$BUILD_DIR/$APP_NAME" - fi - elif [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then - if [[ -f "$BUILD_DIR/${APP_NAME}.exe" ]]; then - mv $BUILD_DIR/${APP_NAME}.exe $BUILD_DIR/${BINARY_NAME}.exe - cp "$BUILD_DIR/${BINARY_NAME}.exe" "$BUILD_DIR/${APP_NAME}.exe" - fi - fi - log_success "Binary built: $BUILD_DIR/$BINARY_NAME" - log_success "User-friendly link created: $BUILD_DIR/$APP_NAME" + if [[ -d "$BUILD_DIR/$APP_NAME" ]]; then + mv "$BUILD_DIR/$APP_NAME" "$BUILD_DIR/$BINARY_DIR_NAME" + + + cat > "$BUILD_DIR/$APP_NAME" << EOF +#!/bin/bash +# Nixopus CLI wrapper +SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)" +exec "\$SCRIPT_DIR/$BINARY_DIR_NAME/$APP_NAME" "\$@" +EOF + chmod +x "$BUILD_DIR/$APP_NAME" + + log_success "Binary directory built: $BUILD_DIR/$BINARY_DIR_NAME/" + log_success "Wrapper script created: $BUILD_DIR/$APP_NAME" + else + log_error "Build failed - directory $BUILD_DIR/$APP_NAME not found" + exit 1 + fi } test_binary() { - log_info "Testing binary..." - - OS=$(uname -s | tr '[:upper:]' '[:lower:]') - ARCH=$(uname -m) - - case $ARCH in - x86_64) ARCH="amd64" ;; - aarch64|arm64) ARCH="arm64" ;; - esac - BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" - BINARY_PATH="$BUILD_DIR/$BINARY_NAME" - - if [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then - BINARY_PATH="$BUILD_DIR/${BINARY_NAME}.exe" - fi + log_info "Testing binary..." + + WRAPPER_PATH="$BUILD_DIR/$APP_NAME" - if [[ -f "$BINARY_PATH" ]]; then - chmod +x "$BINARY_PATH" + if [[ -f "$WRAPPER_PATH" ]]; then + chmod +x "$WRAPPER_PATH" - if $BINARY_PATH --version; then + if "$WRAPPER_PATH" --version; then log_success "Binary test passed" else log_error "Binary test failed" exit 1 fi else - log_error "Binary not found for testing: $BINARY_PATH" + log_error "Wrapper script not found for testing: $WRAPPER_PATH" exit 1 fi } @@ -211,20 +213,17 @@ create_release_archive() { esac ARCHIVE_NAME="${APP_NAME}_${OS}_${ARCH}" - BINARY_NAME="${APP_NAME}_${OS}_${ARCH}" + BINARY_DIR_NAME="${APP_NAME}_${OS}_${ARCH}" cd $BUILD_DIR + if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then - if [[ -f "$BINARY_NAME" ]]; then - tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_NAME" - log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.tar.gz" - fi + tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_DIR_NAME" "$APP_NAME" + log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.tar.gz" elif [[ "$OS" == "mingw"* || "$OS" == "cygwin"* || "$OS" == "msys"* ]]; then - if [[ -f "${BINARY_NAME}.exe" ]]; then - zip "${ARCHIVE_NAME}.zip" "${BINARY_NAME}.exe" - log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.zip" - fi + zip -r "${ARCHIVE_NAME}.zip" "$BINARY_DIR_NAME" "$APP_NAME" + log_success "Archive created: $BUILD_DIR/${ARCHIVE_NAME}.zip" fi cd .. diff --git a/cli/perf_check.sh b/cli/perf_check.sh new file mode 100644 index 00000000..16a367d6 --- /dev/null +++ b/cli/perf_check.sh @@ -0,0 +1,16 @@ +# TODO: @shravan20 - Delte before merging to master or feat/dev +echo "itr \tBinary RUN\t Poetry Run" + +x=() +y=() + + +for i in {1..3}; do + x[$i]=$( (time ./dist/nixopus --help > /dev/null 2>&1) 2>&1 | grep real | awk '{print $2}' ) + echo "$i\t${x[$i]}\t\t-" +done + +for i in {1..3}; do + y[$i]=$( (time poetry run nixopus --help > /dev/null 2>&1) 2>&1 | grep real | awk '{print $2}' ) + echo "$i\t-\t\t ${y[$i]}" +done \ No newline at end of file From 627cbbe6b2daff92a6c3178dc7c2aa4b46b8903e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Sun, 3 Aug 2025 20:24:10 +0530 Subject: [PATCH 65/72] feat: (#292) Add `conflict` command to differentiate versioning --- .gitignore | 3 + cli/Makefile | 98 +++-- cli/app/commands/conflict/__init__.py | 0 cli/app/commands/conflict/command.py | 59 +++ cli/app/commands/conflict/conflict.py | 403 ++++++++++++++++++ cli/app/commands/conflict/messages.py | 43 ++ cli/app/commands/conflict/models.py | 23 + cli/app/commands/conflict/tests/__init__.py | 16 + .../commands/conflict/tests/test_config.yaml | 16 + .../conflict/tests/test_config_and_models.py | 99 +++++ .../commands/conflict/tests/test_conflict.py | 53 +++ .../tests/test_service_integration.py | 152 +++++++ .../conflict/tests/test_version_checker.py | 159 +++++++ cli/app/commands/service/command.py | 3 +- cli/app/main.py | 64 ++- cli/app/utils/config.py | 64 +-- cli/app/utils/tests/test_config.py | 14 + cli/pyproject.toml | 3 +- helpers/config.dev.yaml | 157 +++++++ helpers/config.prod.yaml | 65 ++- 20 files changed, 1388 insertions(+), 106 deletions(-) create mode 100644 cli/app/commands/conflict/__init__.py create mode 100644 cli/app/commands/conflict/command.py create mode 100644 cli/app/commands/conflict/conflict.py create mode 100644 cli/app/commands/conflict/messages.py create mode 100644 cli/app/commands/conflict/models.py create mode 100644 cli/app/commands/conflict/tests/__init__.py create mode 100644 cli/app/commands/conflict/tests/test_config.yaml create mode 100644 cli/app/commands/conflict/tests/test_config_and_models.py create mode 100644 cli/app/commands/conflict/tests/test_conflict.py create mode 100644 cli/app/commands/conflict/tests/test_service_integration.py create mode 100644 cli/app/commands/conflict/tests/test_version_checker.py create mode 100644 helpers/config.dev.yaml diff --git a/.gitignore b/.gitignore index 98b16cb4..357298b0 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,6 @@ htmlcov/ # Poetry poetry.lock + +**/.DS_Store +.DS_Store \ No newline at end of file diff --git a/cli/Makefile b/cli/Makefile index f0e84029..00587716 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -1,59 +1,73 @@ -.PHONY: help install install-dev test test-cov lint clean format check build publish dev run +.PHONY: help setup test test-cov lint clean format check build publish dev nixopus -help: - @echo "Available commands:" +help: ## Show available commands @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' -install: - poetry install +setup: ## Setup Python environment and install dependencies + @if command -v poetry >/dev/null 2>&1; then \ + echo "Poetry found. Installing dependencies..."; \ + poetry install --with dev --quiet; \ + echo "Environment ready! Use: make nixopus ARGS=\"command\""; \ + else \ + echo "Poetry not found. Installing Poetry..."; \ + curl -sSL https://install.python-poetry.org | python3 - >/dev/null 2>&1; \ + echo "Poetry installed. Please restart your shell or run: source ~/.bashrc (or ~/.zshrc)"; \ + echo "Then run 'make setup' again to install dependencies."; \ + fi -install-dev: - poetry install --with dev --no-root +test: ## Run tests + @poetry run pytest -test: - poetry run pytest +test-cov: ## Run tests with coverage + @poetry run pytest --cov=app --cov-report=term-missing --cov-report=html -test-cov: - poetry run pytest --cov=core --cov=utils --cov-report=term-missing --cov-report=html +lint: ## Run linting + @poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + @poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics -test-watch: - poetry run pytest-watch +format: ## Format code + @poetry run black . --quiet + @poetry run isort . --quiet -lint: - poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics +check: ## Run linting and tests + $(MAKE) lint && $(MAKE) test -format: - poetry run black . - poetry run isort . +clean: ## Clean build artifacts + @rm -rf build/ dist/ *.egg-info/ .pytest_cache/ htmlcov/ .coverage + @find . -type d -name __pycache__ -delete + @find . -type f -name "*.pyc" -delete -check: - $(MAKE) lint - $(MAKE) test +build: ## Build the package + @poetry build -clean: - rm -rf build/ - rm -rf dist/ - rm -rf *.egg-info/ - rm -rf .pytest_cache/ - rm -rf htmlcov/ - rm -rf .coverage - find . -type d -name __pycache__ -delete - find . -type f -name "*.pyc" -delete +publish: ## Publish to PyPI + @poetry publish -build: - poetry build +dev: ## Activate development shell + @poetry shell -publish: - poetry publish -dev: - poetry shell +# ----------------------------------------------------------------------------- +# Nixopus test CLI commands +# ----------------------------------------------------------------------------- +nixopus: ## Run nixopus CLI + @if [ -z "$(ARGS)" ]; then \ + poetry run nixopus --help; \ + else \ + poetry run nixopus $(ARGS); \ + fi -run: +conflict: ## Run conflict command + @poetry run nixopus conflict $(ARGS) + +preflight: ## Run preflight command + @poetry run nixopus preflight $(ARGS) + +version: ## Show version + @poetry run nixopus version + +run: ## Run nixopus CLI directly poetry run nixopus -generate-docs: - typer app.main utils docs --output - ../docs/cli/cli-reference.md --name - nixopus \ No newline at end of file +generate-docs: ## Generate CLI documentation + typer app.main utils docs --output ../docs/cli/cli-reference.md --name nixopus diff --git a/cli/app/commands/conflict/__init__.py b/cli/app/commands/conflict/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/conflict/command.py b/cli/app/commands/conflict/command.py new file mode 100644 index 00000000..d6872f39 --- /dev/null +++ b/cli/app/commands/conflict/command.py @@ -0,0 +1,59 @@ +import typer +from .conflict import ConflictConfig, ConflictService +from .messages import ( + conflict_check_help, + error_checking_conflicts, + conflicts_found_warning, + no_conflicts_info, + checking_conflicts_info, +) +from app.utils.logger import Logger +from app.utils.timeout import TimeoutWrapper + +conflict_app = typer.Typer(help=conflict_check_help, no_args_is_help=False) + + +@conflict_app.callback(invoke_without_command=True) +def conflict_callback( + ctx: typer.Context, + config_file: str = typer.Option("helpers/config.prod.yaml", "--config-file", "-c", help="Path to configuration file"), + timeout: int = typer.Option(5, "--timeout", "-t", help="Timeout for tool checks in seconds"), + verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"), + output: str = typer.Option("text", "--output", "-o", help="Output format (text/json)"), +) -> None: + """Check for tool version conflicts""" + if ctx.invoked_subcommand is None: + # Initialize logger once and reuse throughout + logger = Logger(verbose=verbose) + + try: + logger.info(checking_conflicts_info) + + config = ConflictConfig( + config_file=config_file, + verbose=verbose, + output=output, + ) + + service = ConflictService(config, logger=logger) + + with TimeoutWrapper(timeout): + result = service.check_and_format(output) + # Check if there are any conflicts and exit with appropriate code + results = service.check_conflicts() + conflicts = [r for r in results if r.conflict] + + if conflicts: + logger.error(result) + logger.warning(conflicts_found_warning.format(count=len(conflicts))) + raise typer.Exit(1) + else: + logger.success(result) + logger.info(no_conflicts_info) + + except TimeoutError as e: + logger.error(str(e)) + raise typer.Exit(1) + except Exception as e: + logger.error(error_checking_conflicts.format(error=str(e))) + raise typer.Exit(1) diff --git a/cli/app/commands/conflict/conflict.py b/cli/app/commands/conflict/conflict.py new file mode 100644 index 00000000..074dbad1 --- /dev/null +++ b/cli/app/commands/conflict/conflict.py @@ -0,0 +1,403 @@ +import os +import subprocess +import re +from typing import Dict, List, Optional, Any, Tuple +from packaging import version +from packaging.specifiers import SpecifierSet +from packaging.version import Version + +from app.utils.logger import Logger +from app.utils.protocols import LoggerProtocol +from app.utils.output_formatter import OutputFormatter +from app.utils.lib import ParallelProcessor +from app.utils.config import Config, DEPS +from .models import ConflictCheckResult, ConflictConfig +from .messages import * + + +class VersionParser: + + @staticmethod + def is_major_minor_format(requirement: str) -> bool: + """Check if the requirement is in major.minor format (e.g., '1.20').""" + return bool(re.match(r"^\d+\.\d+$", requirement)) + + @staticmethod + def _search_version(pattern: str, output: str, flags: int = re.IGNORECASE) -> Optional[str]: + """Helper to search for a version pattern and return group(1) if found.""" + if match := re.search(pattern, output, flags): + return match.group(1) + return None + + """Utility class for parsing and comparing versions.""" + + # Version pattern mappings for different tools + VERSION_PATTERNS = [ + r"version\s+(\d+\.\d+\.\d+)", # "version 1.20.3", "version 2.1.0" + r"v(\d+\.\d+\.\d+)", # "v1.20.3", "v2.1.0" + r"(\d+\.\d+\.\d+)", # "1.20.3", "2.1.0" (standalone) + r"Version\s+(\d+\.\d+\.\d+)", # "Version 1.20.3", "Version 2.1.0" + r"(\d+\.\d+)", # "1.20", "2.1" (major.minor only) + ] + + # Version operators for requirement specifications + VERSION_OPERATORS = [">=", "<=", ">", "<", "==", "!=", "~", "^"] + + # Supported version specification formats in config files + # Format: "description": "example" + # SUPPORTED_VERSION_FORMATS + # "exact_version": "1.20.3" + # "range_operators": ">=1.20.0, <2.0.0" + # "greater_than_equal": ">=1.20.0" + # "less_than": "<2.0.0" + # "compatible_range": "~=1.20.0" # Python-style compatible release + # "major_minor_only": "1.20" # Implies >=1.20.0, <1.21.0 + + @staticmethod + def parse_version_output(tool: str, output: str) -> Optional[str]: + """Parse version from tool output.""" + try: + # Common version patterns + for pattern in VersionParser.VERSION_PATTERNS: + if version := VersionParser._search_version(pattern, output): + return version + + # Tool-specific parsing for unique output formats + if tool == "go": + # "go version go1.20.3 darwin/amd64" -> "1.20.3" + if version := VersionParser._search_version(r"go(\d+\.\d+\.\d+)", output, 0): + return version + + elif tool == "curl": + # "curl 7.53.1 (x86_64-apple-darwin14.5.0)..." -> "7.53.1" + if version := VersionParser._search_version(r"curl\s+(\d+\.\d+\.\d+)", output, 0): + return version + + elif tool == "ssh" or tool == "open-ssh" or tool == "openssh-server": + # "OpenSSH_9.8p1, LibreSSL 3.3.6" -> "9.8.1" + if match := re.search(r"OpenSSH_(\d+\.\d+)(?:p(\d+))?", output): + major_minor = match.group(1) + patch = match.group(2) or "0" + return f"{major_minor}.{patch}" + + elif tool == "redis": + # "Redis server v=7.0.11 sha=00000000:0..." -> "7.0.11" + if version := VersionParser._search_version(r"v=(\d+\.\d+\.\d+)", output, 0): + return version + + elif tool == "postgresql" or tool == "psql": + # "psql (PostgreSQL) 14.9" -> "14.9" + if version := VersionParser._search_version(r"PostgreSQL\)\s+(\d+\.\d+)", output, 0): + return version + + elif tool == "air": + # Air might have specific format, keeping flexible for now + if version := VersionParser._search_version(r"(\d+\.\d+\.\d+)", output, 0): + return version + + return None + except Exception as e: + raise ValueError(error_parsing_version.format(tool=tool, error=str(e))) + + @staticmethod + def compare_versions(current: str, expected: str) -> bool: + """Compare version against requirement specification.""" + try: + # Handle simple version comparisons (backwards compatibility) + if not any(op in expected for op in VersionParser.VERSION_OPERATORS): + # Default to >= for simple version strings + return version.parse(current) >= version.parse(expected) + + # Handle version ranges and specifiers + spec_set = SpecifierSet(expected) + return Version(current) in spec_set + + except Exception: + # Fallback to string comparison + return current == expected + + @staticmethod + def normalize_version_requirement(requirement: str) -> str: + """ + Parse version requirement and return a normalized specifier. + """ + + if not requirement: + return requirement + + requirement = requirement.strip() + + # If it already contains operators, return as-is + if any(op in requirement for op in VersionParser.VERSION_OPERATORS): + return requirement + + # Handle major.minor format (e.g., "1.20" -> ">=1.20.0, <1.21.0") + if VersionParser.is_major_minor_format(requirement): + try: + parts = requirement.split(".") + major, minor = int(parts[0]), int(parts[1]) + return f">={requirement}.0, <{major}.{minor + 1}.0" + except (ValueError, IndexError): + return f">={requirement}" + + # Handle exact version format (e.g., "1.20.3" -> "==1.20.3") + if re.match(r"^\d+\.\d+\.\d+$", requirement): + return f"=={requirement}" + + # If none of the above, treat as exact match + return f"=={requirement}" + + @staticmethod + def validate_version_format(requirement: str) -> bool: + """ + Validate if the version requirement follows supported formats. + Returns True if the format is supported, False otherwise. + """ + + if not requirement: + return True + + requirement = requirement.strip() + + # Check if it contains supported operators + if any(op in requirement for op in VersionParser.VERSION_OPERATORS): + return True + + # Check for major.minor format + if VersionParser.is_major_minor_format(requirement): + return True + + # Check for exact version format + if re.match(r"^\d+\.\d+\.\d+$", requirement): + return True + + # If none match, it's unsupported + return False + + +class ToolVersionChecker: + """Handles version checking for different tools.""" + + # Tool name mappings for command execution + TOOL_MAPPING = {"open-ssh": "ssh", "open-sshserver": "sshd", "python3-venv": "python3"} # TODO: @shravan20 Fix this issue + + def __init__(self, logger: LoggerProtocol, deps_config: Optional[Dict[str, Any]] = None, timeout: int = 10): + self.timeout = timeout # Default timeout for individual subprocess calls + self.logger = logger + self.deps_config = deps_config or {} + + def get_tool_version(self, tool: str) -> Optional[str]: + """Get version of a tool.""" + try: + # get version-command from deps config + cmd = None + if tool in self.deps_config: + tool_cfg = self.deps_config[tool] + cmd = tool_cfg.get("version-command") + # Fallback to default if not found + if not cmd: + cmd = [tool, "--version"] + + result = subprocess.run(cmd, capture_output=True, text=True, timeout=self.timeout) + + if result.returncode == 0: + return VersionParser.parse_version_output(tool, result.stdout) + else: + # fallback to alternative command if available + alt_cmd = [tool, "-v"] + result = subprocess.run(alt_cmd, capture_output=True, text=True, timeout=self.timeout) + if result.returncode == 0: + return VersionParser.parse_version_output(tool, result.stdout) + + except subprocess.TimeoutExpired: + self.logger.error(timeout_checking_tool.format(tool=tool)) + return None + except Exception as e: + self.logger.error(error_checking_tool_version.format(tool=tool, error=str(e))) + return None + + return None + + def check_tool_version(self, tool: str, expected_version: Optional[str]) -> ConflictCheckResult: + """Check a single tool's version against expected version.""" + command_name = self.TOOL_MAPPING.get(tool, tool) + current_version = self.get_tool_version(command_name) + + if current_version is None: + return ConflictCheckResult( + tool=tool, expected=expected_version, current=None, status=tool_not_found, conflict=True + ) + + if expected_version is None or expected_version == "": + # Just check existence + return ConflictCheckResult( + tool=tool, expected="present", current=current_version, status=tool_version_compatible, conflict=False + ) + + # Parse version requirement to handle ranges + normalized_expected = VersionParser.normalize_version_requirement(expected_version) + + # Check version compatibility + is_compatible = VersionParser.compare_versions(current_version, normalized_expected) + + return ConflictCheckResult( + tool=tool, + expected=normalized_expected, + current=current_version, + status=tool_version_compatible if is_compatible else tool_version_mismatch, + conflict=not is_compatible, + ) + + +class ConflictChecker: + """Main class for checking version conflicts.""" + + def __init__(self, config: ConflictConfig, logger: LoggerProtocol): + self.config = config + self.logger = logger + self.yaml_config = Config() + # Load deps config for version-command lookup + config_data = self._load_user_config(self.config.config_file) + deps_config = config_data.get("deps", {}) + self.version_checker = ToolVersionChecker(logger, deps_config) + + def check_conflicts(self) -> List[ConflictCheckResult]: + """Check for version conflicts.""" + results = [] + + try: + # Load configuration using standardized Config class + config_data = self._load_user_config(self.config.config_file) + + # Extract version requirements from deps section + deps = config_data.get("deps", {}) + + if not deps: + self.logger.warning(no_deps_found_warning) + return results + + # Check version conflicts + results.extend(self._check_version_conflicts(deps)) + + except Exception as e: + self.logger.error(f"Error loading configuration: {str(e)}") + results.append(ConflictCheckResult(tool="configuration", status="error", conflict=True, error=str(e))) + + return results + + def _load_user_config(self, config_path: str) -> Dict[str, Any]: + """Load user configuration file using standardized Config class.""" + self.logger.debug(conflict_loading_config.format(path=config_path)) + + try: + # Use standardized Config class for loading user config + flattened_config = self.yaml_config.load_user_config(config_path) + self.logger.debug(conflict_config_loaded) + + # Convert flattened config back to nested structure for backward compatibility + nested_config = self.yaml_config.unflatten_config(flattened_config) + return nested_config + + except FileNotFoundError: + raise FileNotFoundError(conflict_config_not_found.format(path=config_path)) + except Exception as e: + raise Exception(conflict_invalid_config.format(error=str(e))) + + def _check_version_conflicts(self, deps: Dict[str, Any]) -> List[ConflictCheckResult]: + """Check for tool version conflicts from deps configuration.""" + # Extract version requirements from deps + version_requirements = self._extract_version_requirements(deps) + + if not version_requirements: + return [] + + # Check versions in parallel + results = ParallelProcessor.process_items( + items=list(version_requirements.items()), + processor_func=self._check_tool_version, + max_workers=min(len(version_requirements), 10), + error_handler=self._handle_check_error, + ) + + return results + + def _extract_version_requirements(self, deps: Dict[str, Any]) -> Dict[str, Optional[str]]: + """Extract version requirements from deps configuration.""" + version_requirements = {} + + for tool, config in deps.items(): + if isinstance(config, dict): + # Only check tools that have a version key (even if empty) + if "version" in config: + version_req = config.get("version", "") + version_requirements[tool] = version_req if version_req else None + + return version_requirements + + def _check_tool_version(self, tool_requirement: Tuple[str, Optional[str]]) -> ConflictCheckResult: + """Check version for a single tool.""" + tool, expected_version = tool_requirement + return self.version_checker.check_tool_version(tool, expected_version) + + def _handle_check_error(self, tool_requirement: Tuple[str, Optional[str]], error: Exception) -> ConflictCheckResult: + """Handle errors during version checking.""" + tool, expected_version = tool_requirement + return ConflictCheckResult( + tool=tool, expected=expected_version, current=None, status="error", conflict=True, error=str(error) + ) + + +class ConflictFormatter: + """Handles formatting of conflict check results.""" + + def __init__(self): + self.output_formatter = OutputFormatter() + + def format_output(self, data: List[ConflictCheckResult], output_type: str) -> str: + """Format conflict check results.""" + if not data: + message = self.output_formatter.create_success_message(no_version_conflicts_message) + return self.output_formatter.format_output(message, output_type) + + messages = [] + for result in data: + data_dict = result.model_dump() + message = self._format_single_result(result) + + if result.conflict: + messages.append(self.output_formatter.create_error_message(message, data_dict)) + else: + messages.append(self.output_formatter.create_success_message(message, data_dict)) + + return self.output_formatter.format_output(messages, output_type) + + def _format_single_result(self, result: ConflictCheckResult) -> str: + """Format a single conflict check result.""" + if result.conflict: + if result.current is None: + return f"{result.tool}: {result.status}" + else: + return f"{result.tool}: Expected {result.expected}, Found {result.current}" + else: + return f"{result.tool}: Version compatible ({result.current})" + + +class ConflictService: + """Main service class for conflict checking functionality.""" + + def __init__(self, config: ConflictConfig, logger: Optional[LoggerProtocol] = None): + self.config = config + self.logger = logger or Logger(verbose=config.verbose) + self.checker = ConflictChecker(config, self.logger) + self.formatter = ConflictFormatter() + + def check_conflicts(self) -> List[ConflictCheckResult]: + """Check for conflicts and return results.""" + self.logger.debug("Starting version conflict checks") + return self.checker.check_conflicts() + + def check_and_format(self, output_type: Optional[str] = None) -> str: + """Check conflicts and return formatted output.""" + results = self.check_conflicts() + output_format = output_type or self.config.output + return self.formatter.format_output(results, output_format) diff --git a/cli/app/commands/conflict/messages.py b/cli/app/commands/conflict/messages.py new file mode 100644 index 00000000..f9570b02 --- /dev/null +++ b/cli/app/commands/conflict/messages.py @@ -0,0 +1,43 @@ +no_version_conflicts_message = "No version conflicts to check"# Message constants for conflict command + +# General messages +conflict_check_help = "Check for tool version conflicts" +error_checking_conflicts = "Error checking conflicts: {error}" +no_conflicts_found = "No version conflicts found" +conflict_checking_tool = "Checking tool: {tool}" +conflict_loading_config = "Loading configuration from {path}" +conflict_config_loaded = "Configuration loaded successfully" +conflict_config_not_found = "Configuration file not found at {path}" +conflict_invalid_config = "Invalid configuration file: {error}" + +# Tool-specific messages +tool_not_found = "Tool not found" +tool_version_mismatch = "Version mismatch" +tool_version_compatible = "Version compatible" + +# Error messages +error_checking_tool_version = "Error checking version for {tool}: {error}" +error_parsing_version = "Error parsing version for {tool}: {error}" +timeout_checking_tool = "Timeout checking tool: {tool}" + +# Success/Info messages +conflicts_found_warning = "Found {count} version conflict(s)" +no_conflicts_info = "No version conflicts found" + +# Status messages +checking_conflicts_info = "Checking for tool version conflicts..." + +# Version specification help +supported_version_formats_info = """ +Supported version formats in config files: + - Exact version: "1.20.3" + - Range operators: ">=1.20.0, <2.0.0" + - Greater/less than: ">=1.20.0", "<2.0.0" + - Compatible release: "~=1.20.0" + - Major.minor only: "1.20" (treated as >=1.20.0, <1.21.0) +""" + +unsupported_version_format_warning = "Unsupported version format '{format}' for {tool}. {help}" + +# warning messages +no_deps_found_warning = "No dependencies found in configuration" diff --git a/cli/app/commands/conflict/models.py b/cli/app/commands/conflict/models.py new file mode 100644 index 00000000..07c0e129 --- /dev/null +++ b/cli/app/commands/conflict/models.py @@ -0,0 +1,23 @@ +""" +Data models and configuration for the conflict command. +""" + +from typing import Optional +from pydantic import BaseModel, Field + + +class ConflictCheckResult(BaseModel): + """Result of a conflict check for a tool.""" + tool: str + expected: Optional[str] = None + current: Optional[str] = None + status: str + conflict: bool + error: Optional[str] = None + + +class ConflictConfig(BaseModel): + """Configuration for conflict checking.""" + config_file: str = Field("helpers/config.prod.yaml", description="Path to configuration file") + verbose: bool = Field(False, description="Verbose output") + output: str = Field("text", description="Output format (text/json)") diff --git a/cli/app/commands/conflict/tests/__init__.py b/cli/app/commands/conflict/tests/__init__.py new file mode 100644 index 00000000..908e6eca --- /dev/null +++ b/cli/app/commands/conflict/tests/__init__.py @@ -0,0 +1,16 @@ +""" +Test package for the conflict command. + +This package contains organized tests for the conflict command functionality, +separated by concerns for better maintainability. +""" + +from .test_config_and_models import TestConfigAndModels +from .test_version_checker import TestVersionChecker +from .test_service_integration import TestServiceIntegration + +__all__ = [ + 'TestConfigAndModels', + 'TestVersionChecker', + 'TestServiceIntegration' +] diff --git a/cli/app/commands/conflict/tests/test_config.yaml b/cli/app/commands/conflict/tests/test_config.yaml new file mode 100644 index 00000000..e41a69f1 --- /dev/null +++ b/cli/app/commands/conflict/tests/test_config.yaml @@ -0,0 +1,16 @@ +deps: + docker: + version: ">=20.10.0, <26.0.0" + version-command: ["docker", "--version"] + go: + version: ">=1.18.0, <2.0.0" + version-command: ["go", "version"] + python: + version: ">=3.8, <3.13" + version-command: ["python", "--version"] + ssh: + version: ">=8.0, <10.0" + version-command: ["ssh", "-V"] + test_tool: + version: ">=1.0.0, <2.0.0" + version-command: ["test_tool", "--version"] diff --git a/cli/app/commands/conflict/tests/test_config_and_models.py b/cli/app/commands/conflict/tests/test_config_and_models.py new file mode 100644 index 00000000..b7fc85cb --- /dev/null +++ b/cli/app/commands/conflict/tests/test_config_and_models.py @@ -0,0 +1,99 @@ +import unittest +import yaml +import tempfile +import os +from app.commands.conflict.models import ( + ConflictConfig, + ConflictCheckResult, +) +from app.commands.conflict.conflict import ( + ConflictChecker, +) +from app.utils.logger import Logger + + +class TestConfigAndModels(unittest.TestCase): + """Test configuration loading and data models""" + + def setUp(self): + self.logger = Logger(verbose=False) + self.config = ConflictConfig(config_file="test_config.yaml", verbose=False, output="text") + + def test_conflict_check_result_creation(self): + """Test ConflictCheckResult model creation""" + result = ConflictCheckResult(tool="docker", expected="20.10.0", current="20.10.5", status="compatible", conflict=False) + + self.assertEqual(result.tool, "docker") + self.assertEqual(result.expected, "20.10.0") + self.assertEqual(result.current, "20.10.5") + self.assertFalse(result.conflict) + + def test_conflict_checker_config_loading(self): + """Test ConflictChecker config loading with valid YAML config""" + config_data = {"deps": {"docker": {"version": "20.10.0"}, "go": {"version": "1.18.0"}, "python": {"version": "3.9.0"}}} + + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + yaml.dump(config_data, f) + temp_path = f.name + + try: + conflict_config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + # Create ConflictChecker which will load the config internally + checker = ConflictChecker(conflict_config, self.logger) + + # Test that the config was loaded correctly by checking internal state + # We can verify this by calling _load_user_config directly + result = checker._load_user_config(temp_path) + + self.assertEqual(result, config_data) + self.assertIn("deps", result) + self.assertIn("docker", result["deps"]) + self.assertEqual(result["deps"]["docker"]["version"], "20.10.0") + finally: + os.unlink(temp_path) + + def test_config_loading_missing_file(self): + """Test ConflictChecker config loading with missing file""" + conflict_config = ConflictConfig(config_file="nonexistent.yaml", verbose=False, output="text") + + # ConflictChecker initialization should fail with missing config file + with self.assertRaises(FileNotFoundError): + ConflictChecker(conflict_config, self.logger) + + def test_config_loading_invalid_yaml(self): + """Test ConflictChecker config loading with invalid YAML""" + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + f.write("invalid: yaml: content: [") + temp_path = f.name + + try: + conflict_config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + # ConflictChecker initialization should fail with invalid YAML + with self.assertRaises(Exception): + ConflictChecker(conflict_config, self.logger) + finally: + os.unlink(temp_path) + + def test_empty_deps_handling(self): + """Test handling of empty or missing deps section""" + config_data = {} + + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + yaml.dump(config_data, f) + temp_path = f.name + + try: + config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + # Test that config is created successfully even with empty deps + self.assertEqual(config.config_file, temp_path) + self.assertFalse(config.verbose) + self.assertEqual(config.output, "text") + finally: + os.unlink(temp_path) + + +if __name__ == "__main__": + unittest.main() diff --git a/cli/app/commands/conflict/tests/test_conflict.py b/cli/app/commands/conflict/tests/test_conflict.py new file mode 100644 index 00000000..7b91c34b --- /dev/null +++ b/cli/app/commands/conflict/tests/test_conflict.py @@ -0,0 +1,53 @@ +""" +Comprehensive test suite for the conflict command. + +This module serves as the main test runner that imports and runs all +the separated test modules for better organization and separation of concerns. + +The conflict command has been refactored into: +- models.py: Data models and configuration classes +- conflict.py: Core business logic and services +""" + +import unittest +import sys +import os + +# Add the tests directory to the path to import the separated test modules +sys.path.insert(0, os.path.dirname(__file__)) + +# Import all the separated test modules +from test_config_and_models import TestConfigAndModels +from test_version_checker import TestVersionChecker +from test_service_integration import TestServiceIntegration + + +def create_test_suite(): + """Create a comprehensive test suite with all conflict command tests.""" + suite = unittest.TestSuite() + + # Add all test classes + suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestConfigAndModels)) + suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestVersionChecker)) + suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestServiceIntegration)) + + return suite + + +class TestConflictCommand(unittest.TestCase): + """Main test class that runs all separated tests.""" + + def test_run_all_conflict_tests(self): + """Run all separated test modules and ensure they pass.""" + suite = create_test_suite() + runner = unittest.TextTestRunner(verbosity=2) + result = runner.run(suite) + + # Ensure all tests passed + self.assertEqual(result.errors, []) + self.assertEqual(result.failures, []) + self.assertTrue(result.wasSuccessful()) + + +if __name__ == "__main__": + unittest.main() diff --git a/cli/app/commands/conflict/tests/test_service_integration.py b/cli/app/commands/conflict/tests/test_service_integration.py new file mode 100644 index 00000000..3dced63c --- /dev/null +++ b/cli/app/commands/conflict/tests/test_service_integration.py @@ -0,0 +1,152 @@ +import unittest +from unittest.mock import patch +import yaml +import tempfile +import os +from app.commands.conflict.models import ( + ConflictConfig, + ConflictCheckResult, +) +from app.commands.conflict.conflict import ( + ConflictService, +) +from app.utils.logger import Logger + + +class TestServiceIntegration(unittest.TestCase): + """Test service integration and formatting""" + + def setUp(self): + self.logger = Logger(verbose=False) + self.config = ConflictConfig( + config_file="test_config.yaml", verbose=False, output="text" + ) + + def test_conflict_service_integration(self): + """Test ConflictService integration with YAML config""" + config_data = {"deps": {"docker": {"version": "20.10.0"}, "go": {"version": "1.18.0"}, "python": {"version": "3.9.0"}}} + + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + yaml.dump(config_data, f) + temp_path = f.name + + try: + config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + service = ConflictService(config, self.logger) + + # This would normally make real system calls + # In a real test, we'd mock all the checkers + with patch.object(service.checker, "check_conflicts") as mock_check: + mock_check.return_value = [ + ConflictCheckResult( + tool="docker", expected="20.10.0", current="20.10.5", status="compatible", conflict=False + ) + ] + + results = service.check_conflicts() + self.assertEqual(len(results), 1) + self.assertFalse(results[0].conflict) + finally: + os.unlink(temp_path) + + def test_empty_deps_service_handling(self): + """Test ConflictService handling of empty or missing deps section""" + config_data = {} + + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + yaml.dump(config_data, f) + temp_path = f.name + + try: + config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + service = ConflictService(config, self.logger) + results = service.check_conflicts() + + # Should return empty results for empty deps + self.assertEqual(len(results), 0) + finally: + os.unlink(temp_path) + + def test_conflict_formatter_output(self): + """Test ConflictFormatter output formatting""" + from app.commands.conflict.conflict import ConflictFormatter + + formatter = ConflictFormatter() + + results = [ + ConflictCheckResult(tool="docker", expected="20.10.0", current="20.10.5", status="compatible", conflict=False), + ConflictCheckResult(tool="python", expected="3.9.0", current="3.8.0", status="conflict", conflict=True), + ] + + output = formatter.format_output(results, "text") + + # Should contain both tools + self.assertIn("docker", output) + self.assertIn("python", output) + + # Should indicate status + self.assertIn("compatible", output) + + def test_conflict_formatter_json_output(self): + """Test ConflictFormatter JSON output formatting""" + from app.commands.conflict.conflict import ConflictFormatter + + formatter = ConflictFormatter() + + results = [ + ConflictCheckResult(tool="docker", expected="20.10.0", current="20.10.5", status="compatible", conflict=False) + ] + + output = formatter.format_output(results, "json") + + # Should be valid JSON structure + self.assertIn("docker", output) + self.assertIn("compatible", output) + self.assertIn("20.10.5", output) + + def test_service_with_multiple_tools(self): + """Test ConflictService with multiple tool configurations""" + config_data = { + "deps": { + "docker": {"version": "20.10.0"}, + "go": {"version": "1.18.0"}, + "python": {"version": "3.9.0"}, + "nodejs": {"version": "16.0.0"} + } + } + + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + yaml.dump(config_data, f) + temp_path = f.name + + try: + config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + service = ConflictService(config, self.logger) + + # Mock the checker to return mixed results + with patch.object(service.checker, "check_conflicts") as mock_check: + mock_check.return_value = [ + ConflictCheckResult(tool="docker", expected="20.10.0", current="20.10.5", status="compatible", conflict=False), + ConflictCheckResult(tool="go", expected="1.18.0", current="1.17.0", status="conflict", conflict=True), + ConflictCheckResult(tool="python", expected="3.9.0", current="3.9.2", status="compatible", conflict=False), + ConflictCheckResult(tool="nodejs", expected="16.0.0", current=None, status="missing", conflict=True), + ] + + results = service.check_conflicts() + self.assertEqual(len(results), 4) + + # Check that we have both compatible and conflict results + compatible_results = [r for r in results if not r.conflict] + conflict_results = [r for r in results if r.conflict] + + self.assertEqual(len(compatible_results), 2) + self.assertEqual(len(conflict_results), 2) + finally: + os.unlink(temp_path) + + +if __name__ == "__main__": + unittest.main() diff --git a/cli/app/commands/conflict/tests/test_version_checker.py b/cli/app/commands/conflict/tests/test_version_checker.py new file mode 100644 index 00000000..5ec31a28 --- /dev/null +++ b/cli/app/commands/conflict/tests/test_version_checker.py @@ -0,0 +1,159 @@ +import unittest +from unittest.mock import Mock, patch, call +import subprocess +from app.commands.conflict.models import ConflictConfig +from app.commands.conflict.conflict import ( + ToolVersionChecker, + ConflictChecker, +) +from app.utils.logger import Logger + + +class TestVersionChecker(unittest.TestCase): + """Test version checking and comparison logic""" + + def setUp(self): + self.logger = Logger(verbose=False) + self.config = ConflictConfig( + config_file="test_config.yaml", verbose=False, output="text" + ) + + @patch("subprocess.run") + def test_tool_version_checker_successful(self, mock_run): + """Test ToolVersionChecker with successful version check""" + mock_result = Mock() + mock_result.returncode = 0 + mock_result.stdout = "Docker version 20.10.5, build 55c4c88" + mock_run.return_value = mock_result + + checker = ToolVersionChecker(self.logger, timeout=5) + version = checker.get_tool_version("docker") + + self.assertEqual(version, "20.10.5") + mock_run.assert_called_once_with(["docker", "--version"], capture_output=True, text=True, timeout=5) + + @patch("subprocess.run") + def test_tool_version_checker_not_found(self, mock_run): + """Test ToolVersionChecker with tool not found""" + mock_result = Mock() + mock_result.returncode = 1 + mock_result.stdout = "" + mock_run.return_value = mock_result + + checker = ToolVersionChecker(self.logger, timeout=5) + version = checker.get_tool_version("nonexistent") + + self.assertIsNone(version) + + @patch("subprocess.run") + def test_tool_version_checker_timeout(self, mock_run): + """Test ToolVersionChecker with timeout""" + mock_run.side_effect = subprocess.TimeoutExpired("cmd", 5) + + checker = ToolVersionChecker(self.logger, timeout=5) + version = checker.get_tool_version("slow_tool") + + self.assertIsNone(version) + + @patch("app.commands.conflict.conflict.ConflictChecker._load_user_config") + def test_tool_mapping(self, mock_load_config): + """Test tool name mapping for system commands""" + # Provide a dummy config for ConflictChecker + mock_load_config.return_value = {"deps": {"docker": {"version": "20.10.0"}, "go": {"version": "1.18.0"}, "python": {"version": "3.9.0"}}} + deps = {"docker": {"version": "20.10.0"}, "go": {"version": "1.18.0"}, "python": {"version": "3.9.0"}} + + conflict_checker = ConflictChecker(self.config, self.logger) + + # Mock the version checker to simulate tool responses + with patch.object(conflict_checker.version_checker, "get_tool_version") as mock_get_version: + mock_get_version.return_value = "20.10.5" + + results = conflict_checker._check_version_conflicts(deps) + + # Should have called get_tool_version for each tool + self.assertEqual(mock_get_version.call_count, 3) + # Check that we got results for all tools + self.assertEqual(len(results), 3) + # Check that the results have the expected structure + for result in results: + self.assertIn(result.tool, ["docker", "go", "python"]) + self.assertIsNotNone(result.current) + self.assertIsNotNone(result.expected) + self.assertIsInstance(result.conflict, bool) + + def test_version_requirement_none_or_empty(self): + """Test handling of tools with no version requirements""" + import yaml + import tempfile + import os + + config_data = {"deps": {"docker": {"version": ""}, "git": {"version": None}, "python": {}}} # No version key + + with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f: + yaml.dump(config_data, f) + temp_path = f.name + + try: + config = ConflictConfig(config_file=temp_path, verbose=False, output="text") + + checker = ConflictChecker(config, self.logger) + + # Mock version checker to return versions + with patch.object(checker.version_checker, "get_tool_version") as mock_get_version: + mock_get_version.return_value = "1.0.0" + + results = checker._check_version_conflicts(config_data["deps"]) + + # Only docker and git should be checked (they have version keys) + # python should not be checked (no version key) + self.assertEqual(len(results), 2) + + # All should be compatible (no version requirement) + for result in results: + self.assertFalse(result.conflict) + self.assertEqual(result.expected, "present") + finally: + os.unlink(temp_path) + + def test_tool_version_check_integration(self): + """Test the integration of tool version checking""" + checker = ToolVersionChecker(self.logger, timeout=5) + + # Test that the tool version checking works with mocked subprocess + with patch("subprocess.run") as mock_run: + mock_result = Mock() + mock_result.returncode = 0 + mock_result.stdout = "Test version 1.0.0" + mock_run.return_value = mock_result + + version = checker.get_tool_version("test_tool") + + # Should extract version from output + self.assertEqual(version, "1.0.0") + + def test_version_commands_mapping(self): + """Test that different tools use correct version commands""" + deps_config = { + "docker": {"version-command": ["docker", "--version"]}, + "go": {"version-command": ["go", "version"]}, + "ssh": {"version-command": ["ssh", "-V"]}, + } + checker = ToolVersionChecker(self.logger, deps_config, timeout=5) + with patch("subprocess.run") as mock_run: + mock_result = Mock() + mock_result.returncode = 0 + mock_result.stdout = "version 1.0.0" + mock_run.return_value = mock_result + # Test Docker uses correct command + checker.get_tool_version("docker") + mock_run.assert_called_with(["docker", "--version"], capture_output=True, text=True, timeout=5) + # Test Go uses correct command + checker.get_tool_version("go") + mock_run.assert_called_with(["go", "version"], capture_output=True, text=True, timeout=5) + # Test SSH uses correct command + checker.get_tool_version("ssh") + mock_run.assert_called_with(["ssh", "-V"], capture_output=True, text=True, timeout=5) + + +if __name__ == "__main__": + unittest.main() diff --git a/cli/app/commands/service/command.py b/cli/app/commands/service/command.py index 4d372c64..864814c7 100644 --- a/cli/app/commands/service/command.py +++ b/cli/app/commands/service/command.py @@ -19,6 +19,7 @@ compose_file = config.get_yaml_value(DEFAULT_COMPOSE_FILE) compose_file_path = nixopus_config_dir + "/" + compose_file + @service_app.command() def up( name: str = typer.Option("all", "--name", "-n", help="The name of the service to start, defaults to all"), @@ -63,7 +64,7 @@ def up( if formatted_output: logger.info(formatted_output) else: - logger.error(result.error) + logger.error(result.error if result.error is not None else "Unknown error") raise typer.Exit(1) except TimeoutError as e: diff --git a/cli/app/main.py b/cli/app/main.py index 33d0ce88..775c0b83 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -7,11 +7,21 @@ from rich.panel import Panel from rich.text import Text -from app.commands.version.command import main_version_callback - +from app.commands.clone.command import clone_app +from app.commands.conf.command import conf_app +from app.commands.install.command import install_app +from app.commands.preflight.command import preflight_app +from app.commands.proxy.command import proxy_app +from app.commands.service.command import service_app +from app.commands.test.command import test_app +from app.commands.uninstall.command import uninstall_app +from app.commands.version.command import main_version_callback, version_app +from app.commands.conflict.command import conflict_app +from app.commands.version.version import VersionCommand from app.utils.message import application_add_completion, application_description, application_name, application_version_help from app.utils.config import Config + app = typer.Typer( name=application_name, help=application_description, @@ -34,14 +44,36 @@ def main( console = Console() ascii_art = """ - _ _ _ _ - | \\ | (_) - | \\| |___ _____ _ __ _ _ ___ ____ - | . ` | \\ \\/ / _ \\| '_ \\| | | / __| - | |\\ | |> < (_) | |_) | |_| \\__ \\ - |_| \\_|_/_/\\_\\___/| .__/ \\__,_|___/ - | | - |_| + _ _ _ + | \ | (_)_ _____ _ __ _ _ ___ + | \| | \ \/ / _ \| '_ \| | | / __| + | |\ | |> < (_) | |_) | |_| \__ \. + |_| \_|_/_/\_\___/| .__/ \__,_|___/ + |_| + + + @%%@ + @%--+% + @@%#=---=%%@ + %%=-----------=%@ + %=----------------=*% + @#--------------------=% + #----+#%#=-----=###=---=% + @=--=-.....+=-==.....==--# + %=-=....=-..=+=..=-...==-*@ + @=-*...+%#:..=..-%*=...=-%@ + %-+....*+.+=-+=.**....==% + @%==#% @#=+....*-------+....#=% @%*=+% + @%--#@ %==*....%-+*+=#....*=+@ @#==#@ + @%--+@ %=--==....+*=....+=--#@ %===#@ + @=---+##=-------------=---====*##====#@ + %--------------------===============% + @=-----=+----------=======#======*@ + @@@@*----+------========%@@@@ + %%#%=---=*#=--=#==-=#+=====%%%% + @=----=*%@+---+@====#@%+=====#@ + @@@ @#=--=@ %====% @@@ + @*==*%@ @%*==%% """ text = Text(ascii_art, style="bold cyan") @@ -66,21 +98,11 @@ def main( help_text.append("nixopus --help", style="bold green") help_text.append(" to explore all available commands", style="dim") console.print(help_text) - console.print() - -from app.commands.clone.command import clone_app -from app.commands.conf.command import conf_app -from app.commands.install.command import install_app -from app.commands.preflight.command import preflight_app -from app.commands.proxy.command import proxy_app -from app.commands.service.command import service_app -from app.commands.test.command import test_app -from app.commands.uninstall.command import uninstall_app -from app.commands.version.command import version_app app.add_typer(preflight_app, name="preflight") app.add_typer(clone_app, name="clone") +app.add_typer(conflict_app, name="conflict") app.add_typer(conf_app, name="conf") app.add_typer(service_app, name="service") app.add_typer(proxy_app, name="proxy") diff --git a/cli/app/utils/config.py b/cli/app/utils/config.py index 00797508..a43c6af3 100644 --- a/cli/app/utils/config.py +++ b/cli/app/utils/config.py @@ -4,14 +4,15 @@ import re from app.utils.message import MISSING_CONFIG_KEY_MESSAGE + class Config: def __init__(self, default_env="PRODUCTION"): self.default_env = default_env self._yaml_config = None self._cache = {} - + # Check if running as PyInstaller bundle - if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): + if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): # Running as PyInstaller bundle self._yaml_path = os.path.join(sys._MEIPASS, "helpers", "config.prod.yaml") else: @@ -32,7 +33,7 @@ def load_yaml_config(self): def get_yaml_value(self, path: str): config = self.load_yaml_config() - keys = path.split('.') + keys = path.split(".") for key in keys: if isinstance(config, dict) and key in config: config = config[key] @@ -50,13 +51,13 @@ def load_user_config(self, config_file: str): """Load and parse user config file, returning flattened config dict.""" if not config_file: return {} - + if not os.path.exists(config_file): raise FileNotFoundError(f"Config file not found: {config_file}") - - with open(config_file, 'r') as f: + + with open(config_file, "r") as f: user_config = yaml.safe_load(f) - + flattened = {} self.flatten_config(user_config, flattened) return flattened @@ -70,44 +71,60 @@ def flatten_config(self, config: dict, result: dict, prefix: str = ""): else: result[new_key] = value + def unflatten_config(self, flattened_config: dict) -> dict: + """Convert flattened config back to nested structure.""" + nested = {} + for key, value in flattened_config.items(): + keys = key.split(".") + current = nested + for k in keys[:-1]: + if k not in current: + current[k] = {} + current = current[k] + current[keys[-1]] = value + return nested + def get_config_value(self, key: str, user_config: dict, defaults: dict): """Get config value from user config with fallback to defaults and caching.""" if key in self._cache: return self._cache[key] - + # Key mappings for user config lookup key_mappings = { - 'proxy_port': 'services.caddy.env.PROXY_PORT', - 'repo_url': 'clone.repo', - 'branch_name': 'clone.branch', - 'source_path': 'clone.source-path', - 'config_dir': 'nixopus-config-dir', - 'api_env_file_path': 'services.api.env.API_ENV_FILE', - 'view_env_file_path': 'services.view.env.VIEW_ENV_FILE', - 'compose_file': 'compose-file-path', - 'required_ports': 'ports' + "proxy_port": "services.caddy.env.PROXY_PORT", + "repo_url": "clone.repo", + "branch_name": "clone.branch", + "source_path": "clone.source-path", + "config_dir": "nixopus-config-dir", + "api_env_file_path": "services.api.env.API_ENV_FILE", + "view_env_file_path": "services.view.env.VIEW_ENV_FILE", + "compose_file": "compose-file-path", + "required_ports": "ports", } - + config_path = key_mappings.get(key, key) user_value = user_config.get(config_path) value = user_value if user_value is not None else defaults.get(key) - - if value is None and key not in ['ssh_passphrase']: + + if value is None and key not in ["ssh_passphrase"]: raise ValueError(f"Configuration key '{key}' has no default value") - + self._cache[key] = value return value def expand_env_placeholders(value: str) -> str: # Expand environment placeholders in the form ${ENV_VAR:-default} - pattern = re.compile(r'\$\{([A-Za-z_][A-Za-z0-9_]*)(:-([^}]*))?}') + pattern = re.compile(r"\$\{([A-Za-z_][A-Za-z0-9_]*)(:-([^}]*))?}") + def replacer(match): var_name = match.group(1) - default = match.group(3) if match.group(2) else '' + default = match.group(3) if match.group(2) else "" return os.environ.get(var_name, default) + return pattern.sub(replacer, value) + VIEW_ENV_FILE = "services.view.env.VIEW_ENV_FILE" API_ENV_FILE = "services.api.env.API_ENV_FILE" DEFAULT_REPO = "clone.repo" @@ -131,4 +148,3 @@ def replacer(match): API_PORT = "services.api.env.PORT" CADDY_CONFIG_VOLUME = "services.caddy.env.CADDY_CONFIG_VOLUME" DOCKER_PORT = "services.api.env.DOCKER_PORT" - diff --git a/cli/app/utils/tests/test_config.py b/cli/app/utils/tests/test_config.py index 8d0e6033..20453402 100644 --- a/cli/app/utils/tests/test_config.py +++ b/cli/app/utils/tests/test_config.py @@ -224,6 +224,20 @@ def test_flatten_config_with_prefix(self): config.flatten_config(nested, flattened, "prefix") self.assertEqual(flattened, {"prefix.a": 1}) + def test_unflatten_config_simple(self): + config = Config() + flattened = {"a": 1, "b": 2} + result = config.unflatten_config(flattened) + expected = {"a": 1, "b": 2} + self.assertEqual(result, expected) + + def test_unflatten_config_nested(self): + config = Config() + flattened = {"a.b.c": 1, "a.b.d": 2, "a.e": 3, "f": 4} + result = config.unflatten_config(flattened) + expected = {"a": {"b": {"c": 1, "d": 2}, "e": 3}, "f": 4} + self.assertEqual(result, expected) + def test_get_config_value_cached(self): config = Config() user_config = {"test.key": "value"} diff --git a/cli/pyproject.toml b/cli/pyproject.toml index bc98adb4..b2bfe8ad 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -11,7 +11,8 @@ python = ">=3.9.0,<3.14" typer = "^0.16.0" rich = "^14.0.0" pydantic = "^2.0.0" -requests = "^2.32.3" +packaging = "^23.0" +requests = "^2.32.4" pyyaml = "^6.0.2" [tool.poetry.group.dev.dependencies] diff --git a/helpers/config.dev.yaml b/helpers/config.dev.yaml new file mode 100644 index 00000000..15beab1d --- /dev/null +++ b/helpers/config.dev.yaml @@ -0,0 +1,157 @@ +version: 1 +services: + api: + env: + PORT: ${API_PORT:-8080} + DB_NAME: ${DB_NAME:-postgres} + USERNAME: ${USERNAME:-postgres} + PASSWORD: ${PASSWORD:-changeme} + HOST_NAME: ${DB_HOST:-localhost} + DB_PORT: ${DB_PORT:-5432} + SSL_MODE: ${DB_SSL_MODE:-disable} + MOUNT_PATH: ${MOUNT_PATH:-./configs} + SSH_HOST: ${SSH_HOST:-localhost} + SSH_PORT: ${SSH_PORT:-22} + SSH_USER: ${SSH_USER:-$USER} + SSH_PRIVATE_KEY: ${SSH_PRIVATE_KEY:-~/.ssh/id_ed25519_nixopus} + SSH_PASSWORD: ${SSH_PASSWORD:-} + DOCKER_HOST: ${DOCKER_HOST:-unix:///var/run/docker.sock} + REDIS_URL: ${REDIS_URL:-redis://localhost:6379} + ALLOWED_ORIGIN: ${ALLOWED_ORIGIN:-http://localhost:7443} + ENV: ${ENV:-development} + LOGS_PATH: ${LOGS_PATH:-./logs} + API_VOLUME: ${API_VOLUME:-./configs} + DOCKER_PORT: ${DOCKER_PORT:-2376} + APP_VERSION: ${APP_VERSION:-0.1.0-alpha.11} + + view: + env: + PORT: ${VIEW_PORT:-7443} + WEBSOCKET_URL: ${WEBSOCKET_URL:-} + API_URL: ${API_URL:-} + WEBHOOK_URL: ${WEBHOOK_URL:-} + NEXT_PUBLIC_PORT: ${NEXT_PUBLIC_PORT:-7443} + LOGS_PATH: ${LOGS_PATH:-./logs} + + redis: + env: + REDIS_PORT: ${REDIS_PORT:-6379} + REDIS_VOLUME: ${REDIS_VOLUME:-./redis} + REDIS_IMAGE: ${REDIS_IMAGE:-redis:7-alpine} + REDIS_CONTAINER_NAME: ${REDIS_CONTAINER_NAME:-nixopus-redis-container} + + db: + env: + DB_PORT: ${DB_PORT:-5432} + DB_VOLUME: ${DB_VOLUME:-./db} + DB_IMAGE: ${DB_IMAGE:-postgres:14-alpine} + DB_CONTAINER_NAME: ${DB_CONTAINER_NAME:-nixopus-db-container} + POSTGRES_USER: ${USERNAME:-postgres} + POSTGRES_PASSWORD: ${PASSWORD:-changeme} + POSTGRES_DB: ${DB_NAME:-postgres} + POSTGRES_HOST_AUTH_METHOD: trust + +networks: + default: + name: nixopus-network + driver: bridge + +deps: + curl: + package: "curl" + command: "curl" + version: ">=7.80.0, <8.0.0" + version-command: ["curl", "--version"] + python3: + package: "python3" + command: "python3" + version: ">=3.8, <3.13" + version-command: ["python3", "--version"] + python3-venv: + package: "python3-venv" + command: "" + version: ">=3.8, <3.13" + version-command: ["python3", "--version"] + poetry: + package: "poetry" + command: "poetry" + version: ">=1.2.0, <2.0.0" + version-command: ["poetry", "--version"] + redis: + package: "redis-server" + command: "redis-server" + version: ">=7.0.0, <8.0.0" + version-command: ["redis-server", "--version"] + git: + package: "git" + command: "git" + version: ">=2.30.0, <3.0.0" + version-command: ["git", "--version"] + docker.io: + package: "docker.io" + command: "docker" + install_command: | + curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh + version: ">=20.10.0, <26.0.0" + version-command: ["docker", "--version"] + openssl: + package: "openssl" + command: "openssl" + version: ">=1.1.1, <4.0.0" + version-command: ["openssl", "version"] + open-ssh: + version: ">=8.0, <10.0" + version-command: ["ssh", "-V"] + openssh-client: + package: "openssh-client" + command: "ssh" + version-command: ["ssh", "-V"] + openssh-server: + package: "openssh-server" + command: "sshd" + version: ">=8.0, <10.0" + version-command: ["sshd", "-V"] + go: + package: "go" + command: "go" + version: ">=1.23.0, <2.0.0" + version-command: ["go", "version"] + node: + package: "node" + command: "node" + version: ">=18.0.0, <22.0.0" + version-command: ["node", "--version"] + npm: + package: "npm" + command: "npm" + version-command: ["npm", "--version"] + yarn: + package: "yarn" + command: "yarn" + version-command: ["yarn", "--version"] + python: + package: "python" + command: "python" + version-command: ["python", "--version"] + postgresql: + package: "postgresql" + command: "psql" + version-command: ["psql", "--version"] + air: + package: "air" + command: "air" + version: ">=1.40.0, <2.0.0" + version-command: ["air", "-v"] + +nixopus-config-dir: ./nixopus-dev +compose-file-path: docker-compose.yml +clone: + repo: "https://github.com/raghavyuva/nixopus" + branch: "feat/dev_environment" + source-path: . + +ports: [8080, 7443, 6379, 5432, 22] +ssh_key_size: 4096 +ssh_key_type: ed25519 +ssh_passphrase: +ssh_file_path: ~/.ssh/id_ed25519_nixopus diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index 73bd6d19..3c92ff25 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -71,14 +71,15 @@ services: CONFIG_ENDPOINT: ${CONFIG_ENDPOINT:-/config} LOAD_ENDPOINT: ${LOAD_ENDPOINT:-/load} STOP_ENDPOINT: ${STOP_ENDPOINT:-/stop} - CADDY_COMMAND: [ - "caddy", - "run", - "--config", - "/etc/caddy/Caddyfile", - "--adapter", - "caddyfile" - ] + CADDY_COMMAND: + [ + "caddy", + "run", + "--config", + "/etc/caddy/Caddyfile", + "--adapter", + "caddyfile", + ] networks: default: @@ -86,18 +87,48 @@ networks: driver: bridge deps: - curl: { package: "curl", command: "curl" } - python3: { package: "python3", command: "python3" } - python3-venv: { package: "python3-venv", command: "" } - git: { package: "git", command: "git" } + python3: + package: "python3" + command: "python3" + version: ">=3.8, <3.13" + version-command: ["python3", "--version"] + python3-venv: + package: "python3-venv" + command: "" + version: ">=3.8, <3.13" + version-command: ["python3", "--version"] + git: + package: "git" + command: "git" + version: ">=2.30.0, <3.0.0" + version-command: ["git", "--version"] + curl: + package: "curl" + command: "curl" + version: ">=7.80.0, <8.0.0" + version-command: ["curl", "--version"] docker.io: package: "docker.io" command: "docker" install_command: | curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh - openssl: { package: "openssl", command: "openssl" } - openssh-client: { package: "openssh-client", command: "ssh" } - openssh-server: { package: "openssh-server", command: "sshd" } + version: ">=20.10.0, <26.0.0" + version-command: ["docker", "--version"] + openssl: + package: "openssl" + command: "openssl" + version: ">=1.1.1, <4.0.0" + version-command: ["openssl", "version"] + openssh-client: + package: "openssh-client" + command: "ssh" + version: ">=8.0, <10.0" + version-command: ["ssh", "-V"] + openssh-server: + package: "openssh-server" + command: "sshd" + version: ">=8.0, <10.0" + version-command: ["sshd", "-V"] nixopus-config-dir: /etc/nixopus compose-file-path: source/docker-compose.yml @@ -109,5 +140,5 @@ clone: ports: [2019, 80, 443, 7443, 8443, 6379, 5432] ssh_key_size: 4096 ssh_key_type: ed25519 -ssh_passphrase: -ssh_file_path: ssh/id_rsa \ No newline at end of file +ssh_passphrase: +ssh_file_path: ssh/id_rsa From 5ee2e59000c25071b6a501076c77012fedb7b8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shravan=20=7C=7C=20=E0=A4=B6=E0=A5=8D=E0=A4=B0van?= Date: Tue, 5 Aug 2025 20:37:55 +0530 Subject: [PATCH 66/72] chores: (#306) move out test cases files to separate test folder | include formatting for cli/** --- .github/workflows/format.yaml | 45 +++++++++++++++++++ cli/app/main.py | 18 +++++--- cli/pyproject.toml | 2 +- .../commands/clone => }/tests/__init__.py | 0 .../conf/tests => tests/commands}/__init__.py | 0 .../commands/clone}/__init__.py | 0 .../commands/clone}/test_clone.py | 4 +- cli/tests/commands/conf/__init__.py | 0 .../commands/conf}/test_base.py | 0 .../commands/conf}/test_delete.py | 0 .../commands/conf}/test_list.py | 0 .../tests => tests/commands/conf}/test_set.py | 0 .../commands/conflict}/__init__.py | 0 .../commands/conflict}/test_config.yaml | 0 .../conflict}/test_config_and_models.py | 0 .../commands/conflict}/test_conflict.py | 0 .../conflict}/test_service_integration.py | 0 .../conflict}/test_version_checker.py | 0 cli/tests/commands/install/__init__.py | 0 .../commands/install}/test_ssh.py | 2 +- cli/tests/commands/preflight/__init__.py | 0 .../commands/preflight}/test_deps.py | 0 .../commands/preflight}/test_port.py | 0 cli/tests/commands/proxy/__init__.py | 0 .../commands/proxy}/test_load.py | 0 .../commands/proxy}/test_status.py | 0 .../commands/proxy}/test_stop.py | 0 .../commands/service}/__init__.py | 0 .../commands/service}/test_base.py | 0 .../commands/service}/test_down.py | 0 .../commands/service}/test_ps.py | 0 .../commands/service}/test_restart.py | 0 .../commands/service}/test_up.py | 0 cli/tests/commands/version/__init__.py | 0 .../commands/version}/test_version.py | 0 cli/tests/utils/__init__.py | 0 .../tests => tests/utils}/test_config.py | 0 .../utils/tests => tests/utils}/test_lib.py | 0 .../tests => tests/utils}/test_processor.py | 0 .../tests => tests/utils}/test_timeout.py | 0 40 files changed, 60 insertions(+), 11 deletions(-) rename cli/{app/commands/clone => }/tests/__init__.py (100%) rename cli/{app/commands/conf/tests => tests/commands}/__init__.py (100%) rename cli/{app/commands/install/tests => tests/commands/clone}/__init__.py (100%) rename cli/{app/commands/clone/tests => tests/commands/clone}/test_clone.py (99%) create mode 100644 cli/tests/commands/conf/__init__.py rename cli/{app/commands/conf/tests => tests/commands/conf}/test_base.py (100%) rename cli/{app/commands/conf/tests => tests/commands/conf}/test_delete.py (100%) rename cli/{app/commands/conf/tests => tests/commands/conf}/test_list.py (100%) rename cli/{app/commands/conf/tests => tests/commands/conf}/test_set.py (100%) rename cli/{app/commands/conflict/tests => tests/commands/conflict}/__init__.py (100%) rename cli/{app/commands/conflict/tests => tests/commands/conflict}/test_config.yaml (100%) rename cli/{app/commands/conflict/tests => tests/commands/conflict}/test_config_and_models.py (100%) rename cli/{app/commands/conflict/tests => tests/commands/conflict}/test_conflict.py (100%) rename cli/{app/commands/conflict/tests => tests/commands/conflict}/test_service_integration.py (100%) rename cli/{app/commands/conflict/tests => tests/commands/conflict}/test_version_checker.py (100%) create mode 100644 cli/tests/commands/install/__init__.py rename cli/{app/commands/install/tests => tests/commands/install}/test_ssh.py (99%) create mode 100644 cli/tests/commands/preflight/__init__.py rename cli/{app/commands/preflight/tests => tests/commands/preflight}/test_deps.py (100%) rename cli/{app/commands/preflight/tests => tests/commands/preflight}/test_port.py (100%) create mode 100644 cli/tests/commands/proxy/__init__.py rename cli/{app/commands/proxy/tests => tests/commands/proxy}/test_load.py (100%) rename cli/{app/commands/proxy/tests => tests/commands/proxy}/test_status.py (100%) rename cli/{app/commands/proxy/tests => tests/commands/proxy}/test_stop.py (100%) rename cli/{app/commands/service/tests => tests/commands/service}/__init__.py (100%) rename cli/{app/commands/service/tests => tests/commands/service}/test_base.py (100%) rename cli/{app/commands/service/tests => tests/commands/service}/test_down.py (100%) rename cli/{app/commands/service/tests => tests/commands/service}/test_ps.py (100%) rename cli/{app/commands/service/tests => tests/commands/service}/test_restart.py (100%) rename cli/{app/commands/service/tests => tests/commands/service}/test_up.py (100%) create mode 100644 cli/tests/commands/version/__init__.py rename cli/{app/commands/version/tests => tests/commands/version}/test_version.py (100%) create mode 100644 cli/tests/utils/__init__.py rename cli/{app/utils/tests => tests/utils}/test_config.py (100%) rename cli/{app/utils/tests => tests/utils}/test_lib.py (100%) rename cli/{app/utils/tests => tests/utils}/test_processor.py (100%) rename cli/{app/utils/tests => tests/utils}/test_timeout.py (100%) diff --git a/.github/workflows/format.yaml b/.github/workflows/format.yaml index f171f810..22be4523 100644 --- a/.github/workflows/format.yaml +++ b/.github/workflows/format.yaml @@ -8,6 +8,7 @@ on: paths: - 'api/**' - 'view/**' + - 'cli/**' workflow_dispatch: permissions: @@ -92,4 +93,48 @@ jobs: skip_dirty_check: false skip_fetch: true skip_checkout: true + disable_globbing: false + + format-cli: + name: Format CLI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + cache: 'pip' + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: latest + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Install dependencies + working-directory: cli + run: poetry install --with dev --quiet + + - name: Run formatting + working-directory: cli + run: make format + + - name: Commit CLI changes + id: cli-commit + if: github.event_name == 'pull_request' + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'style(cli): format Python code' + branch: ${{ github.head_ref }} + file_pattern: 'cli/**/*.py' + commit_user_name: 'github-actions[bot]' + commit_user_email: 'github-actions[bot]@users.noreply.github.com' + skip_dirty_check: false + skip_fetch: true + skip_checkout: true disable_globbing: false \ No newline at end of file diff --git a/cli/app/main.py b/cli/app/main.py index 775c0b83..6f44706d 100644 --- a/cli/app/main.py +++ b/cli/app/main.py @@ -43,13 +43,17 @@ def main( if ctx.invoked_subcommand is None: console = Console() - ascii_art = """ - _ _ _ - | \ | (_)_ _____ _ __ _ _ ___ - | \| | \ \/ / _ \| '_ \| | | / __| - | |\ | |> < (_) | |_) | |_| \__ \. - |_| \_|_/_/\_\___/| .__/ \__,_|___/ - |_| + ascii_art = r""" +····································· +: _ _ _ : +:| \ | (_) : +:| \| |___ _____ _ __ _ _ ___ : +:| . ` | \ \/ / _ \| '_ \| | | / __|: +:| |\ | |> < (_) | |_) | |_| \__ \: +:|_| \_|_/_/\_\___/| .__/ \__,_|___/: +: | | : +: |_| : +····································· @%%@ diff --git a/cli/pyproject.toml b/cli/pyproject.toml index b2bfe8ad..bc908350 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -32,7 +32,7 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.pytest.ini_options] -testpaths = ["app"] +testpaths = ["tests"] python_files = ["test_*.py"] python_classes = ["Test*"] python_functions = ["test_*"] diff --git a/cli/app/commands/clone/tests/__init__.py b/cli/tests/__init__.py similarity index 100% rename from cli/app/commands/clone/tests/__init__.py rename to cli/tests/__init__.py diff --git a/cli/app/commands/conf/tests/__init__.py b/cli/tests/commands/__init__.py similarity index 100% rename from cli/app/commands/conf/tests/__init__.py rename to cli/tests/commands/__init__.py diff --git a/cli/app/commands/install/tests/__init__.py b/cli/tests/commands/clone/__init__.py similarity index 100% rename from cli/app/commands/install/tests/__init__.py rename to cli/tests/commands/clone/__init__.py diff --git a/cli/app/commands/clone/tests/test_clone.py b/cli/tests/commands/clone/test_clone.py similarity index 99% rename from cli/app/commands/clone/tests/test_clone.py rename to cli/tests/commands/clone/test_clone.py index af973186..db6b257e 100644 --- a/cli/app/commands/clone/tests/test_clone.py +++ b/cli/tests/commands/clone/test_clone.py @@ -4,7 +4,7 @@ import pytest from pydantic import ValidationError -from ..clone import ( +from app.commands.clone.clone import ( Clone, CloneConfig, CloneFormatter, @@ -13,7 +13,7 @@ GitClone, GitCommandBuilder, ) -from ..messages import ( +from app.commands.clone.messages import ( successfully_cloned, dry_run_mode, dry_run_command, diff --git a/cli/tests/commands/conf/__init__.py b/cli/tests/commands/conf/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/conf/tests/test_base.py b/cli/tests/commands/conf/test_base.py similarity index 100% rename from cli/app/commands/conf/tests/test_base.py rename to cli/tests/commands/conf/test_base.py diff --git a/cli/app/commands/conf/tests/test_delete.py b/cli/tests/commands/conf/test_delete.py similarity index 100% rename from cli/app/commands/conf/tests/test_delete.py rename to cli/tests/commands/conf/test_delete.py diff --git a/cli/app/commands/conf/tests/test_list.py b/cli/tests/commands/conf/test_list.py similarity index 100% rename from cli/app/commands/conf/tests/test_list.py rename to cli/tests/commands/conf/test_list.py diff --git a/cli/app/commands/conf/tests/test_set.py b/cli/tests/commands/conf/test_set.py similarity index 100% rename from cli/app/commands/conf/tests/test_set.py rename to cli/tests/commands/conf/test_set.py diff --git a/cli/app/commands/conflict/tests/__init__.py b/cli/tests/commands/conflict/__init__.py similarity index 100% rename from cli/app/commands/conflict/tests/__init__.py rename to cli/tests/commands/conflict/__init__.py diff --git a/cli/app/commands/conflict/tests/test_config.yaml b/cli/tests/commands/conflict/test_config.yaml similarity index 100% rename from cli/app/commands/conflict/tests/test_config.yaml rename to cli/tests/commands/conflict/test_config.yaml diff --git a/cli/app/commands/conflict/tests/test_config_and_models.py b/cli/tests/commands/conflict/test_config_and_models.py similarity index 100% rename from cli/app/commands/conflict/tests/test_config_and_models.py rename to cli/tests/commands/conflict/test_config_and_models.py diff --git a/cli/app/commands/conflict/tests/test_conflict.py b/cli/tests/commands/conflict/test_conflict.py similarity index 100% rename from cli/app/commands/conflict/tests/test_conflict.py rename to cli/tests/commands/conflict/test_conflict.py diff --git a/cli/app/commands/conflict/tests/test_service_integration.py b/cli/tests/commands/conflict/test_service_integration.py similarity index 100% rename from cli/app/commands/conflict/tests/test_service_integration.py rename to cli/tests/commands/conflict/test_service_integration.py diff --git a/cli/app/commands/conflict/tests/test_version_checker.py b/cli/tests/commands/conflict/test_version_checker.py similarity index 100% rename from cli/app/commands/conflict/tests/test_version_checker.py rename to cli/tests/commands/conflict/test_version_checker.py diff --git a/cli/tests/commands/install/__init__.py b/cli/tests/commands/install/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/install/tests/test_ssh.py b/cli/tests/commands/install/test_ssh.py similarity index 99% rename from cli/app/commands/install/tests/test_ssh.py rename to cli/tests/commands/install/test_ssh.py index 2e238a1f..5823ca88 100644 --- a/cli/app/commands/install/tests/test_ssh.py +++ b/cli/tests/commands/install/test_ssh.py @@ -3,7 +3,7 @@ import unittest from unittest.mock import MagicMock, Mock, patch -from ..ssh import SSH, SSHCommandBuilder, SSHConfig, SSHKeyManager +from app.commands.install.ssh import SSH, SSHCommandBuilder, SSHConfig, SSHKeyManager class TestSSHKeyGeneration(unittest.TestCase): diff --git a/cli/tests/commands/preflight/__init__.py b/cli/tests/commands/preflight/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/preflight/tests/test_deps.py b/cli/tests/commands/preflight/test_deps.py similarity index 100% rename from cli/app/commands/preflight/tests/test_deps.py rename to cli/tests/commands/preflight/test_deps.py diff --git a/cli/app/commands/preflight/tests/test_port.py b/cli/tests/commands/preflight/test_port.py similarity index 100% rename from cli/app/commands/preflight/tests/test_port.py rename to cli/tests/commands/preflight/test_port.py diff --git a/cli/tests/commands/proxy/__init__.py b/cli/tests/commands/proxy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/proxy/tests/test_load.py b/cli/tests/commands/proxy/test_load.py similarity index 100% rename from cli/app/commands/proxy/tests/test_load.py rename to cli/tests/commands/proxy/test_load.py diff --git a/cli/app/commands/proxy/tests/test_status.py b/cli/tests/commands/proxy/test_status.py similarity index 100% rename from cli/app/commands/proxy/tests/test_status.py rename to cli/tests/commands/proxy/test_status.py diff --git a/cli/app/commands/proxy/tests/test_stop.py b/cli/tests/commands/proxy/test_stop.py similarity index 100% rename from cli/app/commands/proxy/tests/test_stop.py rename to cli/tests/commands/proxy/test_stop.py diff --git a/cli/app/commands/service/tests/__init__.py b/cli/tests/commands/service/__init__.py similarity index 100% rename from cli/app/commands/service/tests/__init__.py rename to cli/tests/commands/service/__init__.py diff --git a/cli/app/commands/service/tests/test_base.py b/cli/tests/commands/service/test_base.py similarity index 100% rename from cli/app/commands/service/tests/test_base.py rename to cli/tests/commands/service/test_base.py diff --git a/cli/app/commands/service/tests/test_down.py b/cli/tests/commands/service/test_down.py similarity index 100% rename from cli/app/commands/service/tests/test_down.py rename to cli/tests/commands/service/test_down.py diff --git a/cli/app/commands/service/tests/test_ps.py b/cli/tests/commands/service/test_ps.py similarity index 100% rename from cli/app/commands/service/tests/test_ps.py rename to cli/tests/commands/service/test_ps.py diff --git a/cli/app/commands/service/tests/test_restart.py b/cli/tests/commands/service/test_restart.py similarity index 100% rename from cli/app/commands/service/tests/test_restart.py rename to cli/tests/commands/service/test_restart.py diff --git a/cli/app/commands/service/tests/test_up.py b/cli/tests/commands/service/test_up.py similarity index 100% rename from cli/app/commands/service/tests/test_up.py rename to cli/tests/commands/service/test_up.py diff --git a/cli/tests/commands/version/__init__.py b/cli/tests/commands/version/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/commands/version/tests/test_version.py b/cli/tests/commands/version/test_version.py similarity index 100% rename from cli/app/commands/version/tests/test_version.py rename to cli/tests/commands/version/test_version.py diff --git a/cli/tests/utils/__init__.py b/cli/tests/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cli/app/utils/tests/test_config.py b/cli/tests/utils/test_config.py similarity index 100% rename from cli/app/utils/tests/test_config.py rename to cli/tests/utils/test_config.py diff --git a/cli/app/utils/tests/test_lib.py b/cli/tests/utils/test_lib.py similarity index 100% rename from cli/app/utils/tests/test_lib.py rename to cli/tests/utils/test_lib.py diff --git a/cli/app/utils/tests/test_processor.py b/cli/tests/utils/test_processor.py similarity index 100% rename from cli/app/utils/tests/test_processor.py rename to cli/tests/utils/test_processor.py diff --git a/cli/app/utils/tests/test_timeout.py b/cli/tests/utils/test_timeout.py similarity index 100% rename from cli/app/utils/tests/test_timeout.py rename to cli/tests/utils/test_timeout.py From 193a43e754e41ac02a6f714723a493914cb4e020 Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Sat, 9 Aug 2025 13:09:30 +0530 Subject: [PATCH 67/72] fix: login fails with ip address deployment (#314) --- view/lib/auth.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/view/lib/auth.ts b/view/lib/auth.ts index 394f244b..4ecb1a6b 100644 --- a/view/lib/auth.ts +++ b/view/lib/auth.ts @@ -61,7 +61,7 @@ export function setAuthTokens(tokens: AuthTokens, ctx?: any): void { maxAge: expires_in || 7 * 24 * 60 * 60, path: '/', secure: process.env.NODE_ENV === 'production', - sameSite: 'strict' + sameSite: 'lax' }); if (refresh_token) { @@ -69,7 +69,7 @@ export function setAuthTokens(tokens: AuthTokens, ctx?: any): void { maxAge: 14 * 24 * 60 * 60, path: '/', secure: process.env.NODE_ENV === 'production', - sameSite: 'strict' + sameSite: 'lax' }); } } else { @@ -77,7 +77,7 @@ export function setAuthTokens(tokens: AuthTokens, ctx?: any): void { maxAge: expires_in || 7 * 24 * 60 * 60, path: '/', secure: process.env.NODE_ENV === 'production', - sameSite: 'strict' + sameSite: 'lax' }); if (refresh_token) { @@ -85,7 +85,7 @@ export function setAuthTokens(tokens: AuthTokens, ctx?: any): void { maxAge: 14 * 24 * 60 * 60, path: '/', secure: process.env.NODE_ENV === 'production', - sameSite: 'strict' + sameSite: 'lax' }); } } From eb649d4c09da7ca33ef5dc6587cbf7fafc7916cf Mon Sep 17 00:00:00 2001 From: Raghavendra Bhat <53376933+raghavyuva@users.noreply.github.com> Date: Sat, 9 Aug 2025 13:10:49 +0530 Subject: [PATCH 68/72] feat: (#305) dynamic theme switcher palette and fix inconsistencies in css stylings --- api/api/versions.json | 2 +- view/app/containers/page.tsx | 54 ++- .../components/containers/container-table.tsx | 57 ++- view/app/dashboard/components/smtp-banner.tsx | 3 +- .../components/system/disk-usage.tsx | 108 +++--- .../components/system/load-average.tsx | 47 +-- .../components/system/memory-usage.tsx | 33 +- .../components/system/system-info.tsx | 55 +-- .../components/utils/get-status-color.ts | 8 +- view/app/dashboard/page.tsx | 19 +- .../components/file-list/FileItem.tsx | 10 +- .../file-manager/components/layout/Header.tsx | 6 +- view/app/globals.css | 350 +++++++++++++++++ view/app/layout.tsx | 3 +- .../domains/components/domain-type-tag.tsx | 4 +- view/app/settings/domains/page.tsx | 5 +- .../general/components/AccountSection.tsx | 39 +- .../general/components/AvatarSection.tsx | 7 +- .../components/FeatureFlagsSettings.tsx | 19 +- .../general/components/SecuritySection.tsx | 11 +- .../general/components/TwoFactorSetup.tsx | 16 +- .../notifications/components/channelTab.tsx | 27 +- .../notifications/components/preference.tsx | 9 +- view/app/settings/notifications/page.tsx | 2 +- .../teams/components/RecentActivity.tsx | 13 +- .../settings/teams/components/TeamMembers.tsx | 11 +- .../settings/teams/components/TeamStats.tsx | 23 +- view/app/settings/teams/page.tsx | 5 +- view/components/colors.ts | 361 ++++++++++++++++++ .../features/keyboard-shortcuts.tsx | 2 +- view/components/layout/dashboard-layout.tsx | 22 +- .../layout/dashboard-page-header.tsx | 9 +- view/components/ui/command.tsx | 184 +++++++++ view/components/ui/theme-toggler.tsx | 126 ++++-- view/components/ui/typography.tsx | 77 ++++ view/lib/i18n/locales/en.json | 14 +- view/lib/i18n/locales/es.json | 14 +- view/lib/i18n/locales/fr.json | 14 +- view/lib/i18n/locales/kn.json | 14 +- view/package.json | 1 + view/yarn.lock | 28 +- 41 files changed, 1481 insertions(+), 331 deletions(-) create mode 100644 view/components/colors.ts create mode 100644 view/components/ui/command.tsx create mode 100644 view/components/ui/typography.tsx diff --git a/api/api/versions.json b/api/api/versions.json index c9a8d8a6..27bb3626 100644 --- a/api/api/versions.json +++ b/api/api/versions.json @@ -3,7 +3,7 @@ { "version": "v1", "status": "active", - "release_date": "2025-07-10T02:54:43.011943+05:30", + "release_date": "2025-08-06T17:31:26.311348+05:30", "end_of_life": "0001-01-01T00:00:00Z", "changes": [ "Initial API version" diff --git a/view/app/containers/page.tsx b/view/app/containers/page.tsx index 2639cada..b5ba6087 100644 --- a/view/app/containers/page.tsx +++ b/view/app/containers/page.tsx @@ -14,6 +14,8 @@ import { Skeleton } from '@/components/ui/skeleton'; import DisabledFeature from '@/components/features/disabled-feature'; import { ResourceGuard, AnyPermissionGuard } from '@/components/rbac/PermissionGuard'; import useContainerList from './hooks/use-container-list'; +import { TypographyH1, TypographyMuted } from '@/components/ui/typography'; +import { useTranslation } from '@/hooks/use-translation'; interface ContainerActionsProps { container: any; @@ -78,21 +80,28 @@ interface ContainerInfoProps { } const ContainerInfo = ({ container }: ContainerInfoProps) => { + const { t } = useTranslation(); return ( -
+
Ports:
- {container?.ports?.map((port: any) => ( - - {port.public_port} → {port.private_port} - - ))} + {container?.ports?.length > 0 ? ( + container.ports.map((port: any) => ( + + {port.public_port} → {port.private_port} + + )) + ) : ( + {t("containers.no_ports_exposed")} + )}
Memory: - {(container.host_config.memory / (1024 * 1024)).toFixed(2)} MB + + {`${(container.host_config.memory / (1024 * 1024)).toFixed(2)} MB`} +
); @@ -114,28 +123,32 @@ const ContainerCard = ({ return (
- -
-
-

{container.name}

-

{container.image}

+ +
+
+

{container.name}

+

{container.image}

{container.status}
- +
+ +
+
+
+
-
); @@ -232,7 +245,10 @@ export default function ContainersPage() {
-

{t('containers.title')}

+ + {t('containers.title')} + {t('containers.description')} +