client: Add /projects/ support
This commit is contained in:
parent
5ac3cb3f46
commit
271d27a41d
3 changed files with 95 additions and 1 deletions
|
|
@ -106,7 +106,8 @@ func GetRaw(socket *http.Client, method, path string) ([]byte, *APIResponse, err
|
|||
}
|
||||
|
||||
// Convert the API's JSON error response to an error type and return it
|
||||
if resp.StatusCode == 400 {
|
||||
// lorax-composer (wrongly) returns 404 for some of its json responses
|
||||
if resp.StatusCode == 400 || resp.StatusCode == 404 {
|
||||
apiResponse, err := apiError(resp)
|
||||
return nil, apiResponse, err
|
||||
}
|
||||
|
|
|
|||
70
internal/client/projects.go
Normal file
70
internal/client/projects.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
// Package client - projects contains functions for the projects API
|
||||
// Copyright (C) 2020 by Red Hat, Inc.
|
||||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
// "strings"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/weldr"
|
||||
)
|
||||
|
||||
// ListAllProjectsV0 returns a list of all the available project names
|
||||
func ListAllProjectsV0(socket *http.Client) ([]rpmmd.PackageInfo, *APIResponse, error) {
|
||||
body, resp, err := GetJSONAll(socket, "/api/v0/projects/list")
|
||||
if resp != nil || err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
var list weldr.ProjectsListV0
|
||||
err = json.Unmarshal(body, &list)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return list.Projects, nil, nil
|
||||
}
|
||||
|
||||
// ListSomeProjectsV0 returns a list of all the available project names
|
||||
func ListSomeProjectsV0(socket *http.Client, offset, limit int) ([]rpmmd.PackageInfo, *APIResponse, error) {
|
||||
path := fmt.Sprintf("/api/v0/projects/list?offset=%d&limit=%d", offset, limit)
|
||||
body, resp, err := GetRaw(socket, "GET", path)
|
||||
if resp != nil || err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
var list weldr.ProjectsListV0
|
||||
err = json.Unmarshal(body, &list)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return list.Projects, nil, nil
|
||||
}
|
||||
|
||||
// GetProjectsInfoV0 returns detailed project info on the named projects
|
||||
func GetProjectsInfoV0(socket *http.Client, projNames string) ([]rpmmd.PackageInfo, *APIResponse, error) {
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/v0/projects/info/"+projNames)
|
||||
if resp != nil || err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
var list weldr.ProjectsInfoV0
|
||||
err = json.Unmarshal(body, &list)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return list.Projects, nil, nil
|
||||
}
|
||||
|
||||
//DepsolveProjectsV0 returns the dependencies of the names projects
|
||||
func DepsolveProjectsV0(socket *http.Client, projNames string) ([]rpmmd.PackageSpec, *APIResponse, error) {
|
||||
body, resp, err := GetRaw(socket, "GET", "/api/v0/projects/depsolve/"+projNames)
|
||||
if resp != nil || err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
var deps weldr.ProjectsDependenciesV0
|
||||
err = json.Unmarshal(body, &deps)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return deps.Projects, nil, nil
|
||||
}
|
||||
|
|
@ -121,3 +121,26 @@ func (s *SourceConfigV0) SourceConfig() (ssc store.SourceConfig) {
|
|||
|
||||
return ssc
|
||||
}
|
||||
|
||||
// ProjectsListV0 is the response to /projects/list request
|
||||
type ProjectsListV0 struct {
|
||||
Total uint `json:"total"`
|
||||
Offset uint `json:"offset"`
|
||||
Limit uint `json:"limit"`
|
||||
Projects []rpmmd.PackageInfo `json:"projects"`
|
||||
}
|
||||
|
||||
// ProjectsInfoV0 is the response to /projects/info request
|
||||
type ProjectsInfoV0 struct {
|
||||
Projects []rpmmd.PackageInfo `json:"projects"`
|
||||
}
|
||||
|
||||
// ProjectsDependenciesV0 is the response to /projects/depsolve request
|
||||
type ProjectsDependenciesV0 struct {
|
||||
Projects []rpmmd.PackageSpec `json:"projects"`
|
||||
}
|
||||
|
||||
// ModulesInfoV0 is the response to /modules/info request
|
||||
type ModulesInfoV0 struct {
|
||||
Modules []rpmmd.PackageInfo `json:"modules"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue