zedcloudapi

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 13 Imported by: 1

README

github.com/zededa/zedcloud-api

zedcloud-api provides the open source API for zedcontrol (zedcloud). Currently, it provides a Go-Lang API. Support for API for Python and other languages can be added as needed.

API Swagger files are downloaded from zedcontrol. Go-Lang API is then generated using quay.io/goswagger/swagger generate client command. make in the root directory downloads the swagger files and generates the corresponding GO API - swagger_models and swagger_client.

  1. swagger_models
    • This directory has the generated Go structures for all API structs.
  2. swagger_client
    • This directory the corresponding generated Client wrapper.
  3. client.go
    • This file provides a wrapper Client object to interact with zedcloud. The Client has CSREF support.
  4. zedcloud_client
    • This has a sample Go-lang CLI client utility that uses the zedcloud-api. This is a tool mainly intended to serve as an example for using the API. Also used to manually test any changes to the API.
    • Do make client from zedcloud-api directory to build zedcloud_client
    • zedcloud_client/zedcloud_client -h for more info on using zedcloud_client.

Documentation

Overview

Copyright (c) 2018-2021 Zededa, Inc. SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsObjectNotFound added in v1.0.1

func IsObjectNotFound(resp *http.Response) bool

func UrlForNameOrId

func UrlForNameOrId(name, id string) (string, error)

UrlForNameOrId

ID is prefferred if specified. If not, use name.

func UrlForObjectRequest

func UrlForObjectRequest(urlExtension, name, id, reqType string) string

UrlForObjectRequest

Types

type Client

type Client struct {
	Bearer     runtime.ClientAuthInfoWriter
	HttpClient *http.Client
	// If bearerToken is not empty, it is used for Auth. This is the token
	// obtained from zedcontrol UI ( user profile page ).
	// Else, Login is done using username and password. bearerToken is set from
	// response of Login.
	BearerToken      string
	BaseUrl          string
	XRequestIdPrefix string

	// Set this flag for debugging information to be printed
	Debug bool
}

func NewClient

func NewClient(zedcloudUrl string, token, username, password string) (*Client, error)

func (*Client) CreateObj

func (client *Client) CreateObj(typeUrl string, reqBody interface{}) (
	*http.Response, *swagger_models.ZsrvResponse, error)

CreateObj

typeUrl - Ex: "devices", "apps", "instances" etc
id - ID of the object to delete

func (*Client) DeleteObj

func (client *Client) DeleteObj(typeUrl, id string) (
	*http.Response, *swagger_models.ZsrvResponse, error)

DeleteObj

typeUrl - Ex: "devices", "apps", "instances" etc
id - ID of the object to delete

func (*Client) GetObj

func (client *Client) GetObj(typeUrl, name, id string,
	status bool,
	rspBody interface{}) (*http.Response, error)

GetObj

typeUrl - Ex: "devices", "apps", "instances" etc

rspBody -> pointer to the expected response body. Response body would be unmarshalled into this.

Ex:
    rspData := &swagger_models.DeviceConfig{}
    client.GetObj("devices", "testDevice", "", false, rspData)

func (*Client) SendReq

func (client *Client) SendReq(method, urlExtension string,
	data interface{},
	rspData interface{}) (*http.Response, error)

SendReq

Return Values:
 Returns the http.Response received and any errors encountered in the
 process.
 If Response is Successful ( isHttpStatusCodeSuccess(resp.StatusCode)), returns nil as error.
 Caller can use err == nil to check for a successful response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL