README
¶
DISCONTINUATION OF PROJECT.
This project will no longer be maintained by Intel.
This project has been identified as having known security escapes.
Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project.
Intel no longer accepts patches to this project.
snap-client-go
This repo contains Snap REST API V2 Go client generated by go-swagger.
You can browse Snap REST API V2 by running the command below against Snap REST API V2 Specification.
swagger serve swagger.json --host=127.0.0.1
Package client and models are generated by go-swagger. They require no modification at all.
Topics
- Generating New Client
- Creating Client
- Writing Operations
- Running tests
- Community Support
- Contributing
- Code of Conduct
- Security Disclosure
- License
- Thank You
Generating New Client
If you like to generate a new client when there are changes in Snap APIs, simply do following:
- Run command
make
Note that the command make DELETES both client and models packages and regenerate them to the Snap API version provided in the glide.yaml.
Creating Client
You may create a default client or a custom client like examples below. The code in tests package may use as examples as well.
Default Client
c := client.NewHTTPClient(nil)
Custom Client
c := client.NewHTTPClientWithConfig(nil, &client.TransportConfig{
Host: "http://example.com:80",
BasePath: "/v2",
Schemes: []string{"http"},
})
Writing Operations
You can provide basic authentication info for each API. The following examples assume that basic auth is nil. Let's consider c is the client created, and examples are:
Get Plugins
getPlugins, err := c.Plugins.GetPlugins(snap.NewGetPluginsParams())
Get A Plugin
params := plugins.NewGetPluginParams()
params.SetPtype("collector")
params.SetPname("mock")
params.SetPversion(int64(1))
getPlugin, err := c.Plugins.GetPlugin(params, nil)
Load A Plugin
params := plugins.NewLoadPluginParams()
params.SetPluginData(<*os.file>)
loadPlugin, err := c.Plugins.LoadPlugin(params, nil)
Unload A Plugin
params := plugins.NewUnloadPluginParams()
params.SetPtype("collector")
params.SetPname("mock")
params.SetPversion(int64(1))
unloadPlugin, err := c.Plugins.UnloadPlugin(params, nil)
Get A Plugin Config
params := plugins.NewGetPluginConfigItemParams()
params.SetPname("mock")
params.SetPtype("collector")
params.SetPversion(int64(1))
getPluginConfig, err := c.Plugins.GetPluginConfigItem(params, nil)
Update A Plugin Config
cfg := `{"user":"jean","someint":1234567,"somefloat":3.1418,"somebool":false}`
params := plugins.NewSetPluginConfigItemParams()
params.SetPname("mock")
params.SetPtype("collector")
params.SetPversion(int64(1))
params.SetConfig(&cfg)
setPluginConfig, err := c.Plugins.SetPluginConfigItem(params, nil)
Delete A Plugin Config
params := plugins.NewDeletePluginConfigItemParams()
params.SetPname("mock")
params.SetPtype("collector")
params.SetPversion(int64(1))
params.SetConfig([]string{"somefloat", "someint"})
deletePluginConfig, err := c.Plugins.DeletePluginConfigItem(params, nil)
Get Metrics
params := plugins.NewGetMetricsParams()
getMetrics, err := c.Plugins.GetMetrics(params, nil)
Get Metrics Giving A Namespace
ns := "/intel/mock/bar"
params := plugins.NewGetMetricsParams()
params.SetNs(&ns)
getMetrics, err := c.Plugins.GetMetrics(params, nil)
Get A Metric
ns := "/intel/mock/bar"
ver := int64(1)
params := plugins.NewGetMetricsParams()
params.SetNs(&ns)
params.SetVer(&ver)
getMetric, err := c.Plugins.GetMetrics(params, nil)
Get Tasks
params := tasks.NewGetTasksParams()
getTasks, err := c.Tasks.GetTasks(params)
Get A Task
params := tasks.NewGetTaskParams()
params.SetID(id)
getTask, err := c.Tasks.GetTask(params, nil)
Create A Task
params := tasks.NewAddTaskParams()
params.SetTask(<task manifest> || <workflow manifest>)
createTask, err := c.Tasks.AddTask(params, nil)
Start A Task
params := tasks.NewUpdateTaskStateParams()
params.SetID(<task id>)
params.SetAction("start")
startTask, err := c.Tasks.UpdateTaskState(params, nil)
Stop A Task
params := tasks.NewUpdateTaskStateParams()
params.SetID(<task id>)
params.SetAction("stop")
stopTask, err := c.Tasks.UpdateTaskState(params, nil)
Enable A Task
params := tasks.NewUpdateTaskStateParams()
params.SetID(<task id>)
params.SetAction("enable")
enableTask, err := c.Tasks.UpdateTaskState(params, nil)
Remove A Task
params := tasks.NewRemoveTaskParams()
params.SetID(<task id>)
removeTask, err := c.Tasks.RemoveTask(params, nil)
Running tests
The package test contains integration tests that verify the generated client library if it is working appropriately against the actual behavior of the Snap REST API V2. Tests will fail if any incompatible change in the API.
For your convenience, the Docker and docker-compose based medium test is available for you to try out. At the root package, you can run:
make test-medium
Community Support
This repository is one of many in the Snap framework and has maintainers supporting it. We love contributions from our community along the way. No improvement is too small.
Contributing
We encourage contributions from the community.
- Contributors: We always appreciate more eyes on the core framework and Snap CLIs
- Feedback: try it and tell us about it on our Slack team or through a blog posts
- Integrations: snap-cli uses snap-client-go
To contribute to the Snap framework, see our CONTRIBUTING.md file. To give back to a specific plugin, open an issue on its repository. Snap maintainers aim to address comments and questions as quickly as possible. To get some attention on an issue, reach out to us on Slack, or open an issue to get a conversation started.
Code of Conduct
All contributors to snap-cli are expected to be helpful and encouraging to all members of the community, treating everyone with a high level of professionalism and respect. See our code of conduct for more details.
Security Disclosure
The Snap team takes security very seriously. If you have any issue regarding security, please notify us by sending an email to snap-security@intel.com and not by creating a GitHub issue. We will follow up with you promptly with more information and a plan for remediation.
License
Snap Client Go is an Open Source software released under the Apache 2.0 License.
Thank You
And thank you! Your contribution, through code and participation, is incredibly important to us.