-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
748 changed files
with
304,389 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/debug | ||
.vscode/ | ||
*.test | ||
/ukfast.exe | ||
/ukfast | ||
cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM golang:1.11.5-alpine3.9 AS builder | ||
COPY . /build/ | ||
WORKDIR /build | ||
ENV GO111MODULE on | ||
ENV CGO_ENABLED 0 | ||
RUN go build -mod=vendor -o ukfast | ||
|
||
FROM alpine:3.9 | ||
RUN apk --no-cache add ca-certificates | ||
COPY --from=builder /build/ukfast /bin/ukfast | ||
CMD ["/bin/sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.PHONY: build build_windows build_mac test | ||
|
||
build: | ||
go build -mod=vendor -o ukfast -ldflags "-s -X 'main.VERSION=$$(git describe --tags)' -X 'main.BUILDDATE=$$(date +'%Y-%m-%dT%H:%M:%S')'" | ||
|
||
build_windows: | ||
GOOS=windows go build -mod=vendor -o ukfast.exe -ldflags "-s -X 'main.VERSION=$$(git describe --tags)' -X 'main.BUILDDATE=$$(date +'%Y-%m-%dT%H:%M:%S')'" | ||
|
||
build_mac: | ||
GOOS=darwin go build -mod=vendor -o ukfast -ldflags "-s -X 'main.VERSION=$$(git describe --tags)' -X 'main.BUILDDATE=$$(date +'%Y-%m-%dT%H:%M:%S')'" | ||
|
||
test: | ||
go test -mod=vendor -v -cover ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
# UKFast CLI | ||
|
||
[](https://github.com/ukfast/cli/commits/master) [](https://github.com/ukfast/cli/commits/master) | ||
|
||
This is the official UKFast command-line client, allowing for querying and controlling | ||
supported UKFast services. | ||
|
||
The client utilises UKFast APIs to provide access to most service features. You should refer to the | ||
[Getting Started](https://developers.ukfast.io/getting-started) section of the API documentation before | ||
proceeding below | ||
|
||
## Installation | ||
|
||
The CLI is distributed as a single binary, and is available for Windows, Linux and Mac. This binary | ||
should be downloaded and placed into a directory included in your `PATH`. This would typically | ||
be `/usr/local/bin` on most Linux distributions | ||
|
||
## Getting started | ||
|
||
To get started, we will define a single environment variable to store our API key: | ||
|
||
Bash: | ||
> UKF_API_KEY="iqmxgom0kairfnxzcopte5hx" | ||
PowerShell: | ||
> $env:UKF_API_KEY="iqmxgom0kairfnxzcopte5hx" | ||
And away we go! | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 | ||
+---------+--------------------+------+---------+---------------------------+----------+-----+ | ||
| ID | NAME | TYPE | CONTENT | UPDATED AT | PRIORITY | TTL | | ||
+---------+--------------------+------+---------+---------------------------+----------+-----+ | ||
| 3337874 | test.example.co.uk | A | 1.2.3.4 | 2019-03-19T16:33:55+00:00 | 0 | 0 | | ||
+---------+--------------------+------+---------+---------------------------+----------+-----+ | ||
``` | ||
|
||
## Configuration | ||
|
||
There are two available methods for configuring the CLI; Environment variables and configuration file. | ||
Both of these methods are explained below. | ||
|
||
### Environment variables | ||
|
||
Environment variables can be used to configure/manipulate the CLI | ||
|
||
#### Required | ||
|
||
* `UKF_API_KEY`: API key for interacting with UKFast APIs | ||
|
||
#### Debug | ||
|
||
* `UKF_API_TIMEOUT_SECONDS`: (int) HTTP timeout for API requests. Default: `90` | ||
* `UKF_API_URL`: (string) API URL. Default: `api.ukfast.io` | ||
* `UKF_API_INSECURE`: (bool) Specifies to ignore API certificate validation checks | ||
* `UKF_API_DEBUG`: (bool) Specifies for debug messages to be output to stderr | ||
* `UKF_API_PAGINATION_PERPAGE` (int) Specifies the per-page for paginated requests | ||
|
||
### Configuration File | ||
|
||
An alternative to environment variables is using a configuration file, which is read from | ||
`$HOME/.ukfast.yaml` by default. This path can be overridden with the `--config` flag. | ||
Values defined in the configuration file take precedence over environment variables. | ||
|
||
#### Required | ||
|
||
* `api_key`: API key for interacting with UKFast APIs | ||
|
||
#### Debug | ||
|
||
* `api_timeout_seconds`: (int) HTTP timeout for API requests. Default: `90` | ||
* `api_url`: (string) API URL. Default: `api.ukfast.io` | ||
* `api_insecure`: (bool) Specifies to ignore API certificate validation checks | ||
* `api_debug`: (bool) Specifies for debug messages to be output to stderr | ||
* `api_pagination_perpage` (int) Specifies the per-page for paginated requests | ||
|
||
|
||
## Output Formatting | ||
|
||
The output of all commands is determined by a single global flag `--format` / `-f`. | ||
In additional to format, there are several format modifier flags which are explained below. | ||
|
||
### Table (Default) | ||
|
||
The default output format for the CLI is `Table`, which will be used when the `--format` flag | ||
is `table` or unspecified: | ||
|
||
``` | ||
> ukfast safedns zone record list example.co.uk | ||
+---------+--------------------+------+-----------------------------------------------------------------------+---------------------------+----------+-------+ | ||
| ID | NAME | TYPE | CONTENT | UPDATED AT | PRIORITY | TTL | | ||
+---------+--------------------+------+-----------------------------------------------------------------------+---------------------------+----------+-------+ | ||
| 3337865 | ns0.ukfast.net | NS | 185.226.220.128 | 2019-03-19T16:31:48+00:00 | 0 | 0 | | ||
| 3337868 | ns1.ukfast.net | NS | 185.226.221.128 | 2019-03-19T16:31:48+00:00 | 0 | 0 | | ||
| 3337871 | example.co.uk | SOA | ns0.ukfast.net support.ukfast.co.uk 2019031901 7200 3600 604800 86400 | 2019-03-19T16:31:48+00:00 | 0 | 86400 | | ||
| 3337874 | test.example.co.uk | A | 1.2.3.4 | 2019-03-19T16:33:55+00:00 | 0 | 0 | | ||
+---------+--------------------+------+-----------------------------------------------------------------------+---------------------------+----------+-------+ | ||
``` | ||
|
||
The [Property Modifier](#property) is available for this format | ||
|
||
### JSON | ||
|
||
Results can be output in JSON using the `json` format: | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 --format json | ||
[{"id":3337874,"template_id":0,"name":"test.example.co.uk","type":"A","content":"1.2.3.4","updated_at":"2019-03-19T16:33:55+00:00","ttl":0,"priority":0}] | ||
``` | ||
|
||
### Value | ||
|
||
Results can be output with a value or set of values using the `value` format: | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 --format value | ||
3337874 test.example.co.uk A 1.2.3.4 2019-03-19T16:33:55+00:00 0 0 | ||
``` | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 --format value --property id | ||
3337874 | ||
``` | ||
|
||
The [Property Modifier](#property) is available for this format | ||
|
||
### CSV | ||
|
||
Results can be output as CSV using the `csv` format: | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 --format csv | ||
id,name,type,content,updatedat,priority | ||
3337874,test.example.co.uk,A,1.2.3.4,2019-03-19T16:33:55+00:00,0,0 | ||
``` | ||
|
||
The [Property Modifier](#property) is available for this format | ||
|
||
### Template | ||
|
||
Results can be output using a supplied Golang template string using the `template` format | ||
in conjunction with the `--outputtemplate` modifier flag: | ||
|
||
``` | ||
> ukfast safedns zone record list example.co.uk --format template --outputtemplate "Record name: {{ .Name }}, Type: {{ .Type }}" | ||
Record name: ns0.ukfast.net, Type: NS | ||
Record name: ns1.ukfast.net, Type: NS | ||
Record name: example.co.uk, Type: SOA | ||
Record name: test.example.co.uk, Type: A | ||
``` | ||
|
||
|
||
## Output modifiers | ||
|
||
### Property | ||
|
||
Some output formats support the `--property` output modifier. | ||
|
||
Required properties can be specified with the `--property` format modifer flag: | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 --format value --property name | ||
test.example.co.uk | ||
``` | ||
|
||
The property modifier accepts a comma-delimited list of property names, and is also repeatable: | ||
|
||
``` | ||
> ukfast safedns zone record show example.co.uk 3337874 --format value --property id,name --property content | ||
3337874 test.example.co.uk 1.2.3.4 | ||
``` | ||
|
||
The property modifier also accepts a single wildcard/glob `*`, which denotes all properties | ||
should be returned | ||
|
||
|
||
## Filtering | ||
|
||
When using `list` commands, filtering is available via the `--filter` flag. Additionally, optional operators are available. | ||
|
||
### Examples | ||
|
||
``` | ||
--filter id=123 | ||
--filter id:lt=10 | ||
``` | ||
|
||
Additionally, the `lk` filter is inferred when a glob `*` is included in the filter value (when operator is omitted) | ||
|
||
|
||
## Sorting | ||
|
||
When using `list` commands, sorting is available via the `--sort` flag. | ||
|
||
### Examples | ||
|
||
``` | ||
--sort id | ||
--sort id:desc | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Param | ||
( | ||
$OS=$null | ||
) | ||
|
||
switch ($OS) | ||
{ | ||
"windows" | ||
{ | ||
$env:GOOS = "windows" | ||
} | ||
"linux" | ||
{ | ||
$env:GOOS = "linux" | ||
} | ||
"mac" | ||
{ | ||
$env:GOOS = "darwin" | ||
} | ||
} | ||
|
||
$output = "ukfast" | ||
if ($env:GOOS -eq "windows" -or ([string]::IsNullOrEmpty($env:GOOS) -and $Env:OS -eq "Windows_NT")) | ||
{ | ||
$output = $output+".exe" | ||
} | ||
|
||
$version = $(git describe --tags) | ||
$builddate = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ss") | ||
$env:GO111MODULE="on" | ||
|
||
Write-Host -ForegroundColor Yellow -Object "Building $output with version $version and build date $builddate" | ||
go build -mod=vendor -o $output -ldflags "-s -X 'main.VERSION=$version' -X 'main.BUILDDATE=$builddate'" | ||
$ec = $LASTEXITCODE | ||
|
||
if (Test-Path -Path Env:\GOOS) | ||
{ | ||
Remove-Item -Path Env:\GOOS | ||
} | ||
|
||
exit $ec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/ukfast/cli/internal/pkg/output" | ||
"github.com/ukfast/sdk-go/pkg/service/account" | ||
) | ||
|
||
func accountRootCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "account", | ||
Short: "Commands relating to Account service", | ||
} | ||
|
||
// Child root commands | ||
cmd.AddCommand(accountContactRootCmd()) | ||
|
||
return cmd | ||
} | ||
|
||
// OutputAccountContacts implements OutputDataProvider for outputting an array of Contacts | ||
type OutputAccountContacts struct { | ||
Contacts []account.Contact | ||
} | ||
|
||
func outputAccountContacts(contacts []account.Contact) { | ||
err := Output(&OutputAccountContacts{Contacts: contacts}) | ||
if err != nil { | ||
output.Fatalf("Failed to output contacts: %s", err) | ||
} | ||
} | ||
|
||
func (o *OutputAccountContacts) GetData() interface{} { | ||
return o.Contacts | ||
} | ||
|
||
func (o *OutputAccountContacts) GetFieldData() ([]*output.OrderedFields, error) { | ||
var data []*output.OrderedFields | ||
for _, contact := range o.Contacts { | ||
fields := o.getOrderedFields(contact) | ||
data = append(data, fields) | ||
} | ||
|
||
return data, nil | ||
} | ||
|
||
func (o *OutputAccountContacts) getOrderedFields(contact account.Contact) *output.OrderedFields { | ||
fields := output.NewOrderedFields() | ||
fields.Set("id", output.NewFieldValue(strconv.Itoa(contact.ID), true)) | ||
fields.Set("type", output.NewFieldValue(contact.Type.String(), true)) | ||
fields.Set("first_name", output.NewFieldValue(contact.FirstName, true)) | ||
fields.Set("last_name", output.NewFieldValue(contact.LastName, true)) | ||
|
||
return fields | ||
} |
Oops, something went wrong.