Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement more features for the swagger client API #134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions apiserver/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ func (a *APIController) MetricsTokenHandler(w http.ResponseWriter, r *http.Reque
}
}

// swagger:route POST /auth/login login Login
//
// Logs in a user and returns a JWT token.
//
// Parameters:
// + name: Body
// description: Login information.
// type: PasswordLoginParams
// in: body
// required: true
//
// Responses:
// 200: JWTResponse
// 400: APIErrorResponse
//
// LoginHandler returns a jwt token
func (a *APIController) LoginHandler(w http.ResponseWriter, r *http.Request) {
var loginInfo runnerParams.PasswordLoginParams
Expand Down Expand Up @@ -253,6 +268,20 @@ func (a *APIController) LoginHandler(w http.ResponseWriter, r *http.Request) {
}
}

// swagger:route POST /first-run first-run FirstRun
//
// Initialize the first run of the controller.
//
// Parameters:
// + name: Body
// description: Create a new user.
// type: NewUserParams
// in: body
// required: true
//
// Responses:
// 200: User
// 400: APIErrorResponse
func (a *APIController) FirstRunHandler(w http.ResponseWriter, r *http.Request) {
if a.auth.IsInitialized() {
err := gErrors.NewConflictError("already initialized")
Expand All @@ -279,6 +308,13 @@ func (a *APIController) FirstRunHandler(w http.ResponseWriter, r *http.Request)
}
}

// swagger:route GET /credentials credentials ListCredentials
//
// List all credentials.
//
// Responses:
// 200: Credentials
// 400: APIErrorResponse
func (a *APIController) ListCredentials(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
creds, err := a.r.ListCredentials(ctx)
Expand All @@ -293,6 +329,13 @@ func (a *APIController) ListCredentials(w http.ResponseWriter, r *http.Request)
}
}

// swagger:route GET /providers providers ListProviders
//
// List all providers.
//
// Responses:
// 200: Providers
// 400: APIErrorResponse
func (a *APIController) ListProviders(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
providers, err := a.r.ListProviders(ctx)
Expand Down
28 changes: 28 additions & 0 deletions apiserver/controllers/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ import (
"github.com/gorilla/mux"
)

// swagger:route GET /pools/{poolID}/instances instances ListPoolInstances
//
// List runner instances in a pool.
//
// Parameters:
// + name: poolID
// description: Runner pool ID.
// type: string
// in: path
// required: true
//
// Responses:
// 200: Instances
// default: APIErrorResponse
func (a *APIController) ListPoolInstancesHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
Expand Down Expand Up @@ -176,6 +190,20 @@ func (a *APIController) ListRepoInstancesHandler(w http.ResponseWriter, r *http.
}
}

// swagger:route GET /organizations/{orgID}/instances organizations instances ListOrgInstances
//
// List organization instances.
//
// Parameters:
// + name: orgID
// description: Organization ID.
// type: string
// in: path
// required: true
//
// Responses:
// 200: Instances
// default: APIErrorResponse
func (a *APIController) ListOrgInstancesHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
Expand Down
167 changes: 167 additions & 0 deletions apiserver/controllers/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ import (
"github.com/gorilla/mux"
)

// swagger:route POST /organizations organizations CreateOrg
//
// Create organization with the parameters given.
//
// Parameters:
// + name: Body
// description: Parameters used when creating the organization.
// type: CreateOrgParams
// in: body
// required: true
//
// Responses:
// 200: Organization
// default: APIErrorResponse
func (a *APIController) CreateOrgHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand All @@ -48,6 +62,13 @@ func (a *APIController) CreateOrgHandler(w http.ResponseWriter, r *http.Request)
}
}

// swagger:route GET /organizations organizations ListOrgs
//
// List organizations.
//
// Responses:
// 200: Organizations
// default: APIErrorResponse
func (a *APIController) ListOrgsHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand All @@ -64,6 +85,20 @@ func (a *APIController) ListOrgsHandler(w http.ResponseWriter, r *http.Request)
}
}

// swagger:route GET /organizations/{orgID} organizations GetOrg
//
// Get organization by ID.
//
// Parameters:
// + name: orgID
// description: ID of the organization to fetch.
// type: string
// in: path
// required: true
//
// Responses:
// 200: Organization
// default: APIErrorResponse
func (a *APIController) GetOrgByIDHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -93,6 +128,19 @@ func (a *APIController) GetOrgByIDHandler(w http.ResponseWriter, r *http.Request
}
}

// swagger:route DELETE /organizations/{orgID} organizations DeleteOrg
//
// Delete organization by ID.
//
// Parameters:
// + name: orgID
// description: ID of the organization to delete.
// type: string
// in: path
// required: true
//
// Responses:
// default: APIErrorResponse
func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -120,6 +168,26 @@ func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request)

}

// swagger:route PUT /organizations/{orgID} organizations UpdateOrg
//
// Update organization with the parameters given.
//
// Parameters:
// + name: orgID
// description: ID of the organization to update.
// type: string
// in: path
// required: true
//
// + name: Body
// description: Parameters used when updating the organization.
// type: UpdateEntityParams
// in: body
// required: true
//
// Responses:
// 200: Organization
// default: APIErrorResponse
func (a *APIController) UpdateOrgHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -155,6 +223,26 @@ func (a *APIController) UpdateOrgHandler(w http.ResponseWriter, r *http.Request)
}
}

// swagger:route POST /organizations/{orgID}/pools organizations pools CreateOrgPool
//
// Create organization pool with the parameters given.
//
// Parameters:
// + name: orgID
// description: Organization ID.
// type: string
// in: path
// required: true
//
// + name: Body
// description: Parameters used when creating the organization pool.
// type: CreatePoolParams
// in: body
// required: true
//
// Responses:
// 200: Pool
// default: APIErrorResponse
func (a *APIController) CreateOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -191,6 +279,20 @@ func (a *APIController) CreateOrgPoolHandler(w http.ResponseWriter, r *http.Requ
}
}

// swagger:route GET /organizations/{orgID}/pools organizations pools ListOrgPools
//
// List organization pools.
//
// Parameters:
// + name: orgID
// description: Organization ID.
// type: string
// in: path
// required: true
//
// Responses:
// 200: Pools
// default: APIErrorResponse
func (a *APIController) ListOrgPoolsHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
Expand Down Expand Up @@ -219,6 +321,26 @@ func (a *APIController) ListOrgPoolsHandler(w http.ResponseWriter, r *http.Reque
}
}

// swagger:route GET /organizations/{orgID}/pools/{poolID} organizations pools GetOrgPool
//
// Get organization pool by ID.
//
// Parameters:
// + name: orgID
// description: Organization ID.
// type: string
// in: path
// required: true
//
// + name: poolID
// description: Pool ID.
// type: string
// in: path
// required: true
//
// Responses:
// 200: Pool
// default: APIErrorResponse
func (a *APIController) GetOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
Expand Down Expand Up @@ -248,6 +370,25 @@ func (a *APIController) GetOrgPoolHandler(w http.ResponseWriter, r *http.Request
}
}

// swagger:route DELETE /organizations/{orgID}/pools/{poolID} organizations pools DeleteOrgPool
//
// Delete organization pool by ID.
//
// Parameters:
// + name: orgID
// description: Organization ID.
// type: string
// in: path
// required: true
//
// + name: poolID
// description: ID of the organization pool to delete.
// type: string
// in: path
// required: true
//
// Responses:
// default: APIErrorResponse
func (a *APIController) DeleteOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down Expand Up @@ -276,6 +417,32 @@ func (a *APIController) DeleteOrgPoolHandler(w http.ResponseWriter, r *http.Requ

}

// swagger:route PUT /organizations/{orgID}/pools/{poolID} organizations pools UpdateOrgPool
//
// Update organization pool with the parameters given.
//
// Parameters:
// + name: orgID
// description: Organization ID.
// type: string
// in: path
// required: true
//
// + name: poolID
// description: ID of the organization pool to update.
// type: string
// in: path
// required: true
//
// + name: Body
// description: Parameters used when updating the organization pool.
// type: UpdatePoolParams
// in: body
// required: true
//
// Responses:
// 200: Pool
// default: APIErrorResponse
func (a *APIController) UpdateOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

Expand Down
Loading