Esempio n. 1
0
// NewHTTPClient creates a new task tracker HTTP client.
func NewHTTPClient(formats strfmt.Registry) *TaskTracker {
	if formats == nil {
		formats = strfmt.Default
	}
	transport := httptransport.New("localhost:8322", "/", []string{"https", "http"})
	return New(transport, formats)
}
Esempio n. 2
0
// NewHTTPClient creates a new bill forward HTTP client.
func NewHTTPClient(formats strfmt.Registry) *BillForward {
	if formats == nil {
		formats = strfmt.Default
	}
	transport := httptransport.New("localhost:8080", "/", []string{"https"})
	return New(transport, formats)
}
Esempio n. 3
0
// NewHTTPClient creates a new client HTTP client.
func NewHTTPClient(formats strfmt.Registry) *Client {
	if formats == nil {
		formats = strfmt.Default
	}
	transport := httptransport.New("quay.io", "/", []string{"https"})
	return New(transport, formats)
}
// NewHTTPClient creates a new workflow manager HTTP client.
func NewHTTPClient(formats strfmt.Registry) *WorkflowManager {
	if formats == nil {
		formats = strfmt.Default
	}
	transport := httptransport.New("localhost", "/", []string{"http"})
	return New(transport, formats)
}
Esempio n. 5
0
// NewHTTPClient creates a new todo list HTTP client.
func NewHTTPClient(formats strfmt.Registry) *TodoList {
	if formats == nil {
		formats = strfmt.Default
	}
	transport := httptransport.New("localhost", "/", []string{"http", "https"})
	return New(transport, formats)
}
Esempio n. 6
0
// CreateImageStore creates an image store
func CreateImageStore(storename string) error {
	defer trace.End(trace.Begin(storename))

	transport := httptransport.New(options.host, "/", []string{"http"})
	client := apiclient.New(transport, nil)

	log.Debugf("Creating a store from input %s", storename)

	body := &models.ImageStore{Name: storename}

	_, err := client.Storage.CreateImageStore(
		storage.NewCreateImageStoreParamsWithContext(ctx).WithBody(body),
	)
	if _, ok := err.(*storage.CreateImageStoreConflict); ok {
		log.Debugf("Store already exists")
		return nil
	}
	if err != nil {
		log.Debugf("Creating a store failed: %s", err)

		return err
	}
	log.Debugf("Created a store %#v", body)

	return nil
}
// NewHTTPClient creates a new a to do list application HTTP client.
func NewHTTPClient(formats strfmt.Registry) *AToDoListApplication {
	if formats == nil {
		formats = strfmt.Default
	}
	transport := httptransport.New("localhost", "/", []string{"http"})
	return New(transport, formats)
}
Esempio n. 8
0
func main() {
	transport := httpclient.New("api-sandbox.billforward.net:443", "/v1", []string{"https"})
	transport.DefaultAuthentication = httpclient.BearerToken(os.Getenv("BILLFORWARD_API_KEY"))
	// Only necessary for the PDF response, but here in case someone needs it
	transport.Consumers["application/pdf"] = httpkit.ConsumerFunc(func(r io.Reader, data interface{}) error {
		f := data.(*httpkit.File)
		b, err := ioutil.ReadAll(r)
		if err != nil {
			return err
		}
		f.Data = &ReadWrapper{bytes.NewReader(b)}
		return nil
	})
	bfClient := client.New(transport, nil)

	acctsResp, err := bfClient.Accounts.GetAllAccounts(accounts.NewGetAllAccountsParams())
	if err != nil {
		log.Fatal(err)
	}
	for i, acct := range acctsResp.Payload.Results {
		log.Printf("account %d: %+v\n", i, acct)
		log.Printf("profile %d: %+v\n", i, acct.Profile)
	}

}
Esempio n. 9
0
func SetupConfig() {
	var conf goStashRestClientConfig
	ParseJsonFileStripComments("./config.json", &conf)
	validateRequiredField("host", &conf.Host)
	validateRequiredField("username", &conf.Username)
	if &conf.Password == nil || len(conf.Password) == 0 {
		fmt.Printf("Enter your password for %s: ", conf.Username)
		bytePassword, err := terminal.ReadPassword(0)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		fmt.Println()
		conf.Password = string(bytePassword)
	}
	validateRequiredField("password", &conf.Password)

	doc, err := spec.New(apiclient.SwaggerJSON, "")
	if err != nil {
		panic(err)
	}

	transport := httptransport.New(doc)
	transport.Host = conf.Host
	fmt.Println("using host", conf.Host)

	// Helpful to debug
	//	transport.Debug = true

	// Assumes basic auth. TODO enable the config.json to take different mechanisms, OR integrate with swagger spec file what it says is supported.
	transport.DefaultAuthentication = httptransport.BasicAuth(conf.Username, conf.Password)
	apiclient.Default.SetTransport(transport)
}
Esempio n. 10
0
// ListImages lists the images from given image store
func ListImages(host, storename string, images []*ImageWithMeta) (map[string]*models.Image, error) {
	defer trace.End(trace.Begin(storename))

	transport := httptransport.New(host, "/", []string{"http"})
	client := apiclient.New(transport, nil)

	ids := make([]string, len(images))

	for i := range images {
		ids = append(ids, images[i].ID)
	}

	imageList, err := client.Storage.ListImages(
		storage.NewListImagesParamsWithContext(ctx).WithStoreName(storename).WithIds(ids),
	)
	if err != nil {
		return nil, err
	}

	existingImages := make(map[string]*models.Image)
	for i := range imageList.Payload {
		v := imageList.Payload[i]
		existingImages[v.ID] = v
	}
	return existingImages, nil
}
// NewHTTPClient creates a new simple to do list HTTP client.
func NewHTTPClient(formats strfmt.Registry) *SimpleToDoList {
	swaggerSpec, err := spec.New(SwaggerJSON, "")
	if err != nil {
		// the swagger spec is valid because it was used to generated this code.
		panic(err)
	}
	if formats == nil {
		formats = strfmt.Default
	}
	return New(httptransport.New(swaggerSpec), formats)
}
Esempio n. 12
0
func GetSwaggerClient(apiURL string) (*apiclient.WorkflowManager, error) {
	urlDet, err := url.Parse(apiURL)
	if err != nil {
		return nil, err
	}
	// create the transport
	transport := httptransport.New(urlDet.Host, "", []string{urlDet.Scheme})
	apiClient := apiclient.Default
	apiClient.SetTransport(transport)
	return apiClient, nil
}
Esempio n. 13
0
// PingPortLayer calls the _ping endpoint of the portlayer
func PingPortLayer(host string) (bool, error) {
	defer trace.End(trace.Begin(host))

	transport := httptransport.New(host, "/", []string{"http"})
	client := apiclient.New(transport, nil)

	ok, err := client.Misc.Ping(misc.NewPingParamsWithContext(ctx))
	if err != nil {
		return false, err
	}
	return ok.Payload == "OK", nil
}
Esempio n. 14
0
func Init(portLayerAddr, product string, config *config.VirtualContainerHostConfigSpec, insecureRegs []url.URL) error {
	_, _, err := net.SplitHostPort(portLayerAddr)
	if err != nil {
		return err
	}

	vchConfig = config
	productName = product

	if config != nil {
		if config.Version != nil {
			productVersion = config.Version.ShortVersion()
		}
		if productVersion == "" {
			portLayerName = product + " Backend Engine"
		} else {
			portLayerName = product + " " + productVersion + " Backend Engine"
		}
	} else {
		portLayerName = product + " Backend Engine"
	}

	t := httptransport.New(portLayerAddr, "/", []string{"http"})
	portLayerClient = client.New(t, nil)
	portLayerServerAddr = portLayerAddr

	// block indefinitely while waiting on the portlayer to respond to pings
	// the vic-machine installer timeout will intervene if this blocks for too long
	pingPortLayer()

	if err := hydrateCaches(); err != nil {
		return err
	}

	log.Info("Creating image store")
	if err := createImageStore(); err != nil {
		log.Errorf("Failed to create image store")
		return err
	}

	serviceOptions := registry.ServiceOptions{}
	for _, r := range insecureRegs {
		insecureRegistries = append(insecureRegistries, r.Path)
	}
	if len(insecureRegistries) > 0 {
		serviceOptions.InsecureRegistries = insecureRegistries
	}
	log.Debugf("New registry service with options %#v", serviceOptions)
	RegistryService = registry.NewService(serviceOptions)

	return nil
}
Esempio n. 15
0
func (c *ContainerProxy) createNewAttachClientWithTimeouts(connectTimeout, responseTimeout, responseHeaderTimeout time.Duration) (*client.PortLayer, *httpclient.Transport) {
	runtime := httptransport.New(c.portlayerAddr, "/", []string{"http"})
	transport := &httpclient.Transport{
		ConnectTimeout:        connectTimeout,
		ResponseHeaderTimeout: responseHeaderTimeout,
		RequestTimeout:        responseTimeout,
	}
	runtime.Transport = transport

	plClient := client.New(runtime, nil)
	runtime.Consumers["application/octet-stream"] = httpkit.ByteStreamConsumer()
	runtime.Producers["application/octet-stream"] = httpkit.ByteStreamProducer()

	return plClient, transport
}
Esempio n. 16
0
func Init(portLayerAddr, product string, config *metadata.VirtualContainerHostConfigSpec) error {
	_, _, err := net.SplitHostPort(portLayerAddr)
	if err != nil {
		return err
	}

	vchConfig = config
	productName = product

	if config != nil {
		productVersion = config.Version
		if productVersion == "" {
			portLayerName = product + " Backend Engine"
		} else {
			portLayerName = product + " " + productVersion + " Backend Engine"
		}
	} else {
		portLayerName = product + " Backend Engine"
	}

	t := httptransport.New(portLayerAddr, "/", []string{"http"})
	portLayerClient = client.New(t, nil)
	portLayerServerAddr = portLayerAddr

	imageCache = cache.NewImageCache()

	// attempt to update the image cache at startup
	log.Info("Refreshing image cache...")
	go func() {
		for i := 0; i < Retries; i++ {

			// initial pause to wait for the portlayer to come up
			time.Sleep(RetryTimeSeconds * time.Second)

			if err := imageCache.Update(portLayerClient); err == nil {
				log.Info("Image cache updated successfully")
				return
			}
			log.Info("Failed to refresh image cache, retrying...")
		}
		log.Warn("Failed to refresh image cache. Is the portlayer server down?")
	}()

	return nil
}
Esempio n. 17
0
func TestNodeGetOperation(t *testing.T) {

	// create the transport
	transport := httptransport.New("localhost:9090", "/api/1.1", []string{"http"})

	// configure the host. include port with environment variable. For instance the vagrant image would be localhost:9090
	if os.Getenv("GORACKHD_ENDPOINT") != "" {
		transport.Host = os.Getenv("GORACKHD_ENDPOINT")
	}

	// create the API client, with the transport
	client := apiclient.New(transport, strfmt.Default)

	//use any function to do REST operations
	resp, err := client.Nodes.GetNodes(nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%#v\n", resp.Payload)
}
Esempio n. 18
0
func TestNodeDeleteOperation(t *testing.T) {

	// create the transport
	transport := httptransport.New("localhost:9090", "/api/1.1", []string{"http"})

	// configure the host. include port with environment variable. For instance the vagrant image would be localhost:9090
	if os.Getenv("GORACKHD_ENDPOINT") != "" {
		transport.Host = os.Getenv("GORACKHD_ENDPOINT")
	}

	// create the API client, with the transport
	client := apiclient.New(transport, strfmt.Default)

	//use any function to do REST operations
	resp, err := client.Nodes.DeleteNodesIdentifier(&nodes.DeleteNodesIdentifierParams{Identifier: "1234abcd1234abcd1234abcd"})
	//resp, err := client.Skus.GetSkusIdentifier(&skus.GetSkusIdentifierParams{Identifier: "568e8b76c3354ff04bab27e0"})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%#v\n", resp)
}
Esempio n. 19
0
func TestNodePostOperation(t *testing.T) {

	// create the transport
	transport := httptransport.New("localhost:9090", "/api/1.1", []string{"http"})

	// configure the host
	if os.Getenv("GORACKHD_ENDPOINT") != "" {
		transport.Host = os.Getenv("GORACKHD_ENDPOINT")
	}
	//fmt.Println(fmt.Sprintf("%+v", transport))

	// create the API client, with the transport
	client := apiclient.New(transport, strfmt.Default)

	c := &Node{
		ID:   "1234abcd1234abcd1234abcd",
		Name: "somename",
		Type: "compute",
		ObmSettings: []*ObmSettings{&ObmSettings{
			Service: "ipmi-obm-service",
			Config: &ObmConfig{
				Host:     "1.2.3.4",
				User:     "******",
				Password: "******",
			},
		}},
	}

	b, err := json.Marshal(c)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(b))

	resp, err := client.Nodes.PostNodes(&nodes.PostNodesParams{Identifiers: c})
	if err != nil {
		log.Fatal(err)
	}
	t.Logf("%+v", resp.Payload)
}
Esempio n. 20
0
// WriteImage writes the image to given image store
func WriteImage(host string, image *ImageWithMeta, data io.ReadCloser) error {
	defer trace.End(trace.Begin(image.ID))

	transport := httptransport.New(host, "/", []string{"http"})
	client := apiclient.New(transport, nil)

	transport.Consumers["application/json"] = httpkit.JSONConsumer()
	transport.Producers["application/json"] = httpkit.JSONProducer()
	transport.Consumers["application/octet-stream"] = httpkit.ByteStreamConsumer()
	transport.Producers["application/octet-stream"] = httpkit.ByteStreamProducer()

	key := new(string)
	blob := new(string)

	*key = metadata.MetaDataKey
	*blob = image.Meta

	r, err := client.Storage.WriteImage(
		storage.NewWriteImageParamsWithContext(ctx).
			WithImageID(image.ID).
			WithParentID(*image.Parent).
			WithStoreName(image.Store).
			WithMetadatakey(key).
			WithMetadataval(blob).
			WithImageFile(data).
			WithSum(image.Layer.BlobSum),
	)
	if err != nil {
		log.Debugf("Creating an image failed: %s", err)
		return err
	}
	log.Printf("Created an image %#v", r.Payload)

	return nil

}