feat: added functionality for remote create subcommand (#268)

* feat: implement remote create subcommand

* chore: generate mocks for testing remote command

* refactor: separated out test code, made small changes to remote create code

* chore: ran make fmt

* chore: removed excess print statements

* refactor: made changes suggested in code review

* refactor: added name and remote id to printed table
This commit is contained in:
mcfarlm3 2021-09-14 13:03:17 -07:00 committed by GitHub
parent 2d1f3ee3bc
commit dcf9f5bc9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 2327 additions and 6 deletions

View File

@ -28,7 +28,7 @@ var (
type BackupApi interface {
/*
* GetBackupKV Download snapshot of metadata stored in the server's embedded KV store. Should not be used in versions > 2.1.x, as it doesn't include metadata stored in embedded SQL.
* GetBackupKV Download snapshot of metadata stored in the server's embedded KV store. Should not be used in versions greater than 2.1.x, as it doesn't include metadata stored in embedded SQL.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return ApiGetBackupKVRequest
*/
@ -110,7 +110,7 @@ func (r ApiGetBackupKVRequest) Execute() (*_nethttp.Response, error) {
}
/*
* GetBackupKV Download snapshot of metadata stored in the server's embedded KV store. Should not be used in versions > 2.1.x, as it doesn't include metadata stored in embedded SQL.
* GetBackupKV Download snapshot of metadata stored in the server's embedded KV store. Should not be used in versions greater than 2.1.x, as it doesn't include metadata stored in embedded SQL.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @return ApiGetBackupKVRequest
*/

File diff suppressed because it is too large Load Diff

View File

@ -68,6 +68,8 @@ type APIClient struct {
QueryApi QueryApi
RemoteConnectionsApi RemoteConnectionsApi
RestoreApi RestoreApi
SecretsApi SecretsApi
@ -116,6 +118,7 @@ func NewAPIClient(cfg *Configuration) *APIClient {
c.LegacyAuthorizationsApi = (*LegacyAuthorizationsApiService)(&c.common)
c.OrganizationsApi = (*OrganizationsApiService)(&c.common)
c.QueryApi = (*QueryApiService)(&c.common)
c.RemoteConnectionsApi = (*RemoteConnectionsApiService)(&c.common)
c.RestoreApi = (*RestoreApiService)(&c.common)
c.SecretsApi = (*SecretsApiService)(&c.common)
c.SetupApi = (*SetupApiService)(&c.common)

View File

@ -107,6 +107,12 @@ paths:
$ref: "./openapi/src/common/paths/authorizations.yml"
/authorizations/{authID}:
$ref: "./openapi/src/common/paths/authorizations_authID.yml"
/remotes:
$ref: "./openapi/src/oss/paths/remotes.yml"
/remotes/{remoteID}:
$ref: "./openapi/src/oss/paths/remotes_remoteID.yml"
/remotes/{remoteID}/validate:
$ref: "./openapi/src/oss/paths/remotes_remoteID_validate.yml"
components:
parameters:
TraceSpan:
@ -417,3 +423,11 @@ components:
$ref: "./openapi/src/oss/schemas/LegacyAuthorizationPostRequest.yml"
AuthorizationPostRequest:
$ref: "./openapi/src/common/schemas/AuthorizationPostRequest.yml"
RemoteConnection:
$ref: "./openapi/src/oss/schemas/RemoteConnection.yml"
RemoteConnectionCreationRequest:
$ref: "./openapi/src/oss/schemas/RemoteConnectionCreationRequest.yml"
RemoteConnenctionUpdateRequest:
$ref: "./openapi/src/oss/schemas/RemoteConnectionUpdateRequest.yml"
RemoteConnections:
$ref: "./openapi/src/oss/schemas/RemoteConnections.yml"

@ -1 +1 @@
Subproject commit 20706d0876987520eb2c57cfc5364005ad4bcbed
Subproject commit 039f87e84d94f37cf286cedc66883e4a82a1805c

View File

@ -0,0 +1,289 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// RemoteConnection struct for RemoteConnection
type RemoteConnection struct {
Id string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
OrgID string `json:"orgID" yaml:"orgID"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
RemoteURL string `json:"remoteURL" yaml:"remoteURL"`
RemoteOrgID string `json:"remoteOrgID" yaml:"remoteOrgID"`
AllowInsecureTLS bool `json:"allowInsecureTLS" yaml:"allowInsecureTLS"`
}
// NewRemoteConnection instantiates a new RemoteConnection object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewRemoteConnection(id string, name string, orgID string, remoteURL string, remoteOrgID string, allowInsecureTLS bool) *RemoteConnection {
this := RemoteConnection{}
this.Id = id
this.Name = name
this.OrgID = orgID
this.RemoteURL = remoteURL
this.RemoteOrgID = remoteOrgID
this.AllowInsecureTLS = allowInsecureTLS
return &this
}
// NewRemoteConnectionWithDefaults instantiates a new RemoteConnection object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewRemoteConnectionWithDefaults() *RemoteConnection {
this := RemoteConnection{}
var allowInsecureTLS bool = false
this.AllowInsecureTLS = allowInsecureTLS
return &this
}
// GetId returns the Id field value
func (o *RemoteConnection) GetId() string {
if o == nil {
var ret string
return ret
}
return o.Id
}
// GetIdOk returns a tuple with the Id field value
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetIdOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Id, true
}
// SetId sets field value
func (o *RemoteConnection) SetId(v string) {
o.Id = v
}
// GetName returns the Name field value
func (o *RemoteConnection) GetName() string {
if o == nil {
var ret string
return ret
}
return o.Name
}
// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Name, true
}
// SetName sets field value
func (o *RemoteConnection) SetName(v string) {
o.Name = v
}
// GetOrgID returns the OrgID field value
func (o *RemoteConnection) GetOrgID() string {
if o == nil {
var ret string
return ret
}
return o.OrgID
}
// GetOrgIDOk returns a tuple with the OrgID field value
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetOrgIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OrgID, true
}
// SetOrgID sets field value
func (o *RemoteConnection) SetOrgID(v string) {
o.OrgID = v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *RemoteConnection) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *RemoteConnection) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *RemoteConnection) SetDescription(v string) {
o.Description = &v
}
// GetRemoteURL returns the RemoteURL field value
func (o *RemoteConnection) GetRemoteURL() string {
if o == nil {
var ret string
return ret
}
return o.RemoteURL
}
// GetRemoteURLOk returns a tuple with the RemoteURL field value
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetRemoteURLOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.RemoteURL, true
}
// SetRemoteURL sets field value
func (o *RemoteConnection) SetRemoteURL(v string) {
o.RemoteURL = v
}
// GetRemoteOrgID returns the RemoteOrgID field value
func (o *RemoteConnection) GetRemoteOrgID() string {
if o == nil {
var ret string
return ret
}
return o.RemoteOrgID
}
// GetRemoteOrgIDOk returns a tuple with the RemoteOrgID field value
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetRemoteOrgIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.RemoteOrgID, true
}
// SetRemoteOrgID sets field value
func (o *RemoteConnection) SetRemoteOrgID(v string) {
o.RemoteOrgID = v
}
// GetAllowInsecureTLS returns the AllowInsecureTLS field value
func (o *RemoteConnection) GetAllowInsecureTLS() bool {
if o == nil {
var ret bool
return ret
}
return o.AllowInsecureTLS
}
// GetAllowInsecureTLSOk returns a tuple with the AllowInsecureTLS field value
// and a boolean to check if the value has been set.
func (o *RemoteConnection) GetAllowInsecureTLSOk() (*bool, bool) {
if o == nil {
return nil, false
}
return &o.AllowInsecureTLS, true
}
// SetAllowInsecureTLS sets field value
func (o *RemoteConnection) SetAllowInsecureTLS(v bool) {
o.AllowInsecureTLS = v
}
func (o RemoteConnection) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["id"] = o.Id
}
if true {
toSerialize["name"] = o.Name
}
if true {
toSerialize["orgID"] = o.OrgID
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
if true {
toSerialize["remoteURL"] = o.RemoteURL
}
if true {
toSerialize["remoteOrgID"] = o.RemoteOrgID
}
if true {
toSerialize["allowInsecureTLS"] = o.AllowInsecureTLS
}
return json.Marshal(toSerialize)
}
type NullableRemoteConnection struct {
value *RemoteConnection
isSet bool
}
func (v NullableRemoteConnection) Get() *RemoteConnection {
return v.value
}
func (v *NullableRemoteConnection) Set(val *RemoteConnection) {
v.value = val
v.isSet = true
}
func (v NullableRemoteConnection) IsSet() bool {
return v.isSet
}
func (v *NullableRemoteConnection) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableRemoteConnection(val *RemoteConnection) *NullableRemoteConnection {
return &NullableRemoteConnection{value: val, isSet: true}
}
func (v NullableRemoteConnection) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableRemoteConnection) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,289 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// RemoteConnectionCreationRequest struct for RemoteConnectionCreationRequest
type RemoteConnectionCreationRequest struct {
Name string `json:"name" yaml:"name"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
OrgID string `json:"orgID" yaml:"orgID"`
RemoteURL string `json:"remoteURL" yaml:"remoteURL"`
RemoteAPIToken string `json:"remoteAPIToken" yaml:"remoteAPIToken"`
RemoteOrgID string `json:"remoteOrgID" yaml:"remoteOrgID"`
AllowInsecureTLS bool `json:"allowInsecureTLS" yaml:"allowInsecureTLS"`
}
// NewRemoteConnectionCreationRequest instantiates a new RemoteConnectionCreationRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewRemoteConnectionCreationRequest(name string, orgID string, remoteURL string, remoteAPIToken string, remoteOrgID string, allowInsecureTLS bool) *RemoteConnectionCreationRequest {
this := RemoteConnectionCreationRequest{}
this.Name = name
this.OrgID = orgID
this.RemoteURL = remoteURL
this.RemoteAPIToken = remoteAPIToken
this.RemoteOrgID = remoteOrgID
this.AllowInsecureTLS = allowInsecureTLS
return &this
}
// NewRemoteConnectionCreationRequestWithDefaults instantiates a new RemoteConnectionCreationRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewRemoteConnectionCreationRequestWithDefaults() *RemoteConnectionCreationRequest {
this := RemoteConnectionCreationRequest{}
var allowInsecureTLS bool = false
this.AllowInsecureTLS = allowInsecureTLS
return &this
}
// GetName returns the Name field value
func (o *RemoteConnectionCreationRequest) GetName() string {
if o == nil {
var ret string
return ret
}
return o.Name
}
// GetNameOk returns a tuple with the Name field value
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetNameOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.Name, true
}
// SetName sets field value
func (o *RemoteConnectionCreationRequest) SetName(v string) {
o.Name = v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *RemoteConnectionCreationRequest) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *RemoteConnectionCreationRequest) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *RemoteConnectionCreationRequest) SetDescription(v string) {
o.Description = &v
}
// GetOrgID returns the OrgID field value
func (o *RemoteConnectionCreationRequest) GetOrgID() string {
if o == nil {
var ret string
return ret
}
return o.OrgID
}
// GetOrgIDOk returns a tuple with the OrgID field value
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetOrgIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.OrgID, true
}
// SetOrgID sets field value
func (o *RemoteConnectionCreationRequest) SetOrgID(v string) {
o.OrgID = v
}
// GetRemoteURL returns the RemoteURL field value
func (o *RemoteConnectionCreationRequest) GetRemoteURL() string {
if o == nil {
var ret string
return ret
}
return o.RemoteURL
}
// GetRemoteURLOk returns a tuple with the RemoteURL field value
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetRemoteURLOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.RemoteURL, true
}
// SetRemoteURL sets field value
func (o *RemoteConnectionCreationRequest) SetRemoteURL(v string) {
o.RemoteURL = v
}
// GetRemoteAPIToken returns the RemoteAPIToken field value
func (o *RemoteConnectionCreationRequest) GetRemoteAPIToken() string {
if o == nil {
var ret string
return ret
}
return o.RemoteAPIToken
}
// GetRemoteAPITokenOk returns a tuple with the RemoteAPIToken field value
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetRemoteAPITokenOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.RemoteAPIToken, true
}
// SetRemoteAPIToken sets field value
func (o *RemoteConnectionCreationRequest) SetRemoteAPIToken(v string) {
o.RemoteAPIToken = v
}
// GetRemoteOrgID returns the RemoteOrgID field value
func (o *RemoteConnectionCreationRequest) GetRemoteOrgID() string {
if o == nil {
var ret string
return ret
}
return o.RemoteOrgID
}
// GetRemoteOrgIDOk returns a tuple with the RemoteOrgID field value
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetRemoteOrgIDOk() (*string, bool) {
if o == nil {
return nil, false
}
return &o.RemoteOrgID, true
}
// SetRemoteOrgID sets field value
func (o *RemoteConnectionCreationRequest) SetRemoteOrgID(v string) {
o.RemoteOrgID = v
}
// GetAllowInsecureTLS returns the AllowInsecureTLS field value
func (o *RemoteConnectionCreationRequest) GetAllowInsecureTLS() bool {
if o == nil {
var ret bool
return ret
}
return o.AllowInsecureTLS
}
// GetAllowInsecureTLSOk returns a tuple with the AllowInsecureTLS field value
// and a boolean to check if the value has been set.
func (o *RemoteConnectionCreationRequest) GetAllowInsecureTLSOk() (*bool, bool) {
if o == nil {
return nil, false
}
return &o.AllowInsecureTLS, true
}
// SetAllowInsecureTLS sets field value
func (o *RemoteConnectionCreationRequest) SetAllowInsecureTLS(v bool) {
o.AllowInsecureTLS = v
}
func (o RemoteConnectionCreationRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
toSerialize["name"] = o.Name
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
if true {
toSerialize["orgID"] = o.OrgID
}
if true {
toSerialize["remoteURL"] = o.RemoteURL
}
if true {
toSerialize["remoteAPIToken"] = o.RemoteAPIToken
}
if true {
toSerialize["remoteOrgID"] = o.RemoteOrgID
}
if true {
toSerialize["allowInsecureTLS"] = o.AllowInsecureTLS
}
return json.Marshal(toSerialize)
}
type NullableRemoteConnectionCreationRequest struct {
value *RemoteConnectionCreationRequest
isSet bool
}
func (v NullableRemoteConnectionCreationRequest) Get() *RemoteConnectionCreationRequest {
return v.value
}
func (v *NullableRemoteConnectionCreationRequest) Set(val *RemoteConnectionCreationRequest) {
v.value = val
v.isSet = true
}
func (v NullableRemoteConnectionCreationRequest) IsSet() bool {
return v.isSet
}
func (v *NullableRemoteConnectionCreationRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableRemoteConnectionCreationRequest(val *RemoteConnectionCreationRequest) *NullableRemoteConnectionCreationRequest {
return &NullableRemoteConnectionCreationRequest{value: val, isSet: true}
}
func (v NullableRemoteConnectionCreationRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableRemoteConnectionCreationRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,113 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// RemoteConnections struct for RemoteConnections
type RemoteConnections struct {
Remotes *[]RemoteConnection `json:"remotes,omitempty" yaml:"remotes,omitempty"`
}
// NewRemoteConnections instantiates a new RemoteConnections object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewRemoteConnections() *RemoteConnections {
this := RemoteConnections{}
return &this
}
// NewRemoteConnectionsWithDefaults instantiates a new RemoteConnections object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewRemoteConnectionsWithDefaults() *RemoteConnections {
this := RemoteConnections{}
return &this
}
// GetRemotes returns the Remotes field value if set, zero value otherwise.
func (o *RemoteConnections) GetRemotes() []RemoteConnection {
if o == nil || o.Remotes == nil {
var ret []RemoteConnection
return ret
}
return *o.Remotes
}
// GetRemotesOk returns a tuple with the Remotes field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnections) GetRemotesOk() (*[]RemoteConnection, bool) {
if o == nil || o.Remotes == nil {
return nil, false
}
return o.Remotes, true
}
// HasRemotes returns a boolean if a field has been set.
func (o *RemoteConnections) HasRemotes() bool {
if o != nil && o.Remotes != nil {
return true
}
return false
}
// SetRemotes gets a reference to the given []RemoteConnection and assigns it to the Remotes field.
func (o *RemoteConnections) SetRemotes(v []RemoteConnection) {
o.Remotes = &v
}
func (o RemoteConnections) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Remotes != nil {
toSerialize["remotes"] = o.Remotes
}
return json.Marshal(toSerialize)
}
type NullableRemoteConnections struct {
value *RemoteConnections
isSet bool
}
func (v NullableRemoteConnections) Get() *RemoteConnections {
return v.value
}
func (v *NullableRemoteConnections) Set(val *RemoteConnections) {
v.value = val
v.isSet = true
}
func (v NullableRemoteConnections) IsSet() bool {
return v.isSet
}
func (v *NullableRemoteConnections) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableRemoteConnections(val *RemoteConnections) *NullableRemoteConnections {
return &NullableRemoteConnections{value: val, isSet: true}
}
func (v NullableRemoteConnections) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableRemoteConnections) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

View File

@ -0,0 +1,297 @@
/*
* Subset of Influx API covered by Influx CLI
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 2.0.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package api
import (
"encoding/json"
)
// RemoteConnenctionUpdateRequest struct for RemoteConnenctionUpdateRequest
type RemoteConnenctionUpdateRequest struct {
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
RemoteURL *string `json:"remoteURL,omitempty" yaml:"remoteURL,omitempty"`
RemoteAPIToken *string `json:"remoteAPIToken,omitempty" yaml:"remoteAPIToken,omitempty"`
RemoteOrgID *string `json:"remoteOrgID,omitempty" yaml:"remoteOrgID,omitempty"`
AllowInsecureTLS *bool `json:"allowInsecureTLS,omitempty" yaml:"allowInsecureTLS,omitempty"`
}
// NewRemoteConnenctionUpdateRequest instantiates a new RemoteConnenctionUpdateRequest object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewRemoteConnenctionUpdateRequest() *RemoteConnenctionUpdateRequest {
this := RemoteConnenctionUpdateRequest{}
var allowInsecureTLS bool = false
this.AllowInsecureTLS = &allowInsecureTLS
return &this
}
// NewRemoteConnenctionUpdateRequestWithDefaults instantiates a new RemoteConnenctionUpdateRequest object
// This constructor will only assign default values to properties that have it defined,
// but it doesn't guarantee that properties required by API are set
func NewRemoteConnenctionUpdateRequestWithDefaults() *RemoteConnenctionUpdateRequest {
this := RemoteConnenctionUpdateRequest{}
var allowInsecureTLS bool = false
this.AllowInsecureTLS = &allowInsecureTLS
return &this
}
// GetName returns the Name field value if set, zero value otherwise.
func (o *RemoteConnenctionUpdateRequest) GetName() string {
if o == nil || o.Name == nil {
var ret string
return ret
}
return *o.Name
}
// GetNameOk returns a tuple with the Name field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnenctionUpdateRequest) GetNameOk() (*string, bool) {
if o == nil || o.Name == nil {
return nil, false
}
return o.Name, true
}
// HasName returns a boolean if a field has been set.
func (o *RemoteConnenctionUpdateRequest) HasName() bool {
if o != nil && o.Name != nil {
return true
}
return false
}
// SetName gets a reference to the given string and assigns it to the Name field.
func (o *RemoteConnenctionUpdateRequest) SetName(v string) {
o.Name = &v
}
// GetDescription returns the Description field value if set, zero value otherwise.
func (o *RemoteConnenctionUpdateRequest) GetDescription() string {
if o == nil || o.Description == nil {
var ret string
return ret
}
return *o.Description
}
// GetDescriptionOk returns a tuple with the Description field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnenctionUpdateRequest) GetDescriptionOk() (*string, bool) {
if o == nil || o.Description == nil {
return nil, false
}
return o.Description, true
}
// HasDescription returns a boolean if a field has been set.
func (o *RemoteConnenctionUpdateRequest) HasDescription() bool {
if o != nil && o.Description != nil {
return true
}
return false
}
// SetDescription gets a reference to the given string and assigns it to the Description field.
func (o *RemoteConnenctionUpdateRequest) SetDescription(v string) {
o.Description = &v
}
// GetRemoteURL returns the RemoteURL field value if set, zero value otherwise.
func (o *RemoteConnenctionUpdateRequest) GetRemoteURL() string {
if o == nil || o.RemoteURL == nil {
var ret string
return ret
}
return *o.RemoteURL
}
// GetRemoteURLOk returns a tuple with the RemoteURL field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnenctionUpdateRequest) GetRemoteURLOk() (*string, bool) {
if o == nil || o.RemoteURL == nil {
return nil, false
}
return o.RemoteURL, true
}
// HasRemoteURL returns a boolean if a field has been set.
func (o *RemoteConnenctionUpdateRequest) HasRemoteURL() bool {
if o != nil && o.RemoteURL != nil {
return true
}
return false
}
// SetRemoteURL gets a reference to the given string and assigns it to the RemoteURL field.
func (o *RemoteConnenctionUpdateRequest) SetRemoteURL(v string) {
o.RemoteURL = &v
}
// GetRemoteAPIToken returns the RemoteAPIToken field value if set, zero value otherwise.
func (o *RemoteConnenctionUpdateRequest) GetRemoteAPIToken() string {
if o == nil || o.RemoteAPIToken == nil {
var ret string
return ret
}
return *o.RemoteAPIToken
}
// GetRemoteAPITokenOk returns a tuple with the RemoteAPIToken field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnenctionUpdateRequest) GetRemoteAPITokenOk() (*string, bool) {
if o == nil || o.RemoteAPIToken == nil {
return nil, false
}
return o.RemoteAPIToken, true
}
// HasRemoteAPIToken returns a boolean if a field has been set.
func (o *RemoteConnenctionUpdateRequest) HasRemoteAPIToken() bool {
if o != nil && o.RemoteAPIToken != nil {
return true
}
return false
}
// SetRemoteAPIToken gets a reference to the given string and assigns it to the RemoteAPIToken field.
func (o *RemoteConnenctionUpdateRequest) SetRemoteAPIToken(v string) {
o.RemoteAPIToken = &v
}
// GetRemoteOrgID returns the RemoteOrgID field value if set, zero value otherwise.
func (o *RemoteConnenctionUpdateRequest) GetRemoteOrgID() string {
if o == nil || o.RemoteOrgID == nil {
var ret string
return ret
}
return *o.RemoteOrgID
}
// GetRemoteOrgIDOk returns a tuple with the RemoteOrgID field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnenctionUpdateRequest) GetRemoteOrgIDOk() (*string, bool) {
if o == nil || o.RemoteOrgID == nil {
return nil, false
}
return o.RemoteOrgID, true
}
// HasRemoteOrgID returns a boolean if a field has been set.
func (o *RemoteConnenctionUpdateRequest) HasRemoteOrgID() bool {
if o != nil && o.RemoteOrgID != nil {
return true
}
return false
}
// SetRemoteOrgID gets a reference to the given string and assigns it to the RemoteOrgID field.
func (o *RemoteConnenctionUpdateRequest) SetRemoteOrgID(v string) {
o.RemoteOrgID = &v
}
// GetAllowInsecureTLS returns the AllowInsecureTLS field value if set, zero value otherwise.
func (o *RemoteConnenctionUpdateRequest) GetAllowInsecureTLS() bool {
if o == nil || o.AllowInsecureTLS == nil {
var ret bool
return ret
}
return *o.AllowInsecureTLS
}
// GetAllowInsecureTLSOk returns a tuple with the AllowInsecureTLS field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *RemoteConnenctionUpdateRequest) GetAllowInsecureTLSOk() (*bool, bool) {
if o == nil || o.AllowInsecureTLS == nil {
return nil, false
}
return o.AllowInsecureTLS, true
}
// HasAllowInsecureTLS returns a boolean if a field has been set.
func (o *RemoteConnenctionUpdateRequest) HasAllowInsecureTLS() bool {
if o != nil && o.AllowInsecureTLS != nil {
return true
}
return false
}
// SetAllowInsecureTLS gets a reference to the given bool and assigns it to the AllowInsecureTLS field.
func (o *RemoteConnenctionUpdateRequest) SetAllowInsecureTLS(v bool) {
o.AllowInsecureTLS = &v
}
func (o RemoteConnenctionUpdateRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Name != nil {
toSerialize["name"] = o.Name
}
if o.Description != nil {
toSerialize["description"] = o.Description
}
if o.RemoteURL != nil {
toSerialize["remoteURL"] = o.RemoteURL
}
if o.RemoteAPIToken != nil {
toSerialize["remoteAPIToken"] = o.RemoteAPIToken
}
if o.RemoteOrgID != nil {
toSerialize["remoteOrgID"] = o.RemoteOrgID
}
if o.AllowInsecureTLS != nil {
toSerialize["allowInsecureTLS"] = o.AllowInsecureTLS
}
return json.Marshal(toSerialize)
}
type NullableRemoteConnenctionUpdateRequest struct {
value *RemoteConnenctionUpdateRequest
isSet bool
}
func (v NullableRemoteConnenctionUpdateRequest) Get() *RemoteConnenctionUpdateRequest {
return v.value
}
func (v *NullableRemoteConnenctionUpdateRequest) Set(val *RemoteConnenctionUpdateRequest) {
v.value = val
v.isSet = true
}
func (v NullableRemoteConnenctionUpdateRequest) IsSet() bool {
return v.isSet
}
func (v *NullableRemoteConnenctionUpdateRequest) Unset() {
v.value = nil
v.isSet = false
}
func NewNullableRemoteConnenctionUpdateRequest(val *RemoteConnenctionUpdateRequest) *NullableRemoteConnenctionUpdateRequest {
return &NullableRemoteConnenctionUpdateRequest{value: val, isSet: true}
}
func (v NullableRemoteConnenctionUpdateRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(v.value)
}
func (v *NullableRemoteConnenctionUpdateRequest) UnmarshalJSON(src []byte) error {
v.isSet = true
return json.Unmarshal(src, &v.value)
}

117
clients/remote/remote.go Normal file
View File

@ -0,0 +1,117 @@
package remote
import (
"context"
"fmt"
"github.com/influxdata/influx-cli/v2/api"
"github.com/influxdata/influx-cli/v2/clients"
)
type Client struct {
clients.CLI
api.RemoteConnectionsApi
api.OrganizationsApi
}
type CreateParams struct {
Name string
Description string
OrgID string
OrgName string
RemoteURL string
RemoteAPIToken string
RemoteOrgID string
AllowInsecureTLS bool
}
func (c Client) Create(ctx context.Context, params *CreateParams) error {
if params.OrgID == "" && params.OrgName == "" && c.ActiveConfig.Org == "" {
return clients.ErrMustSpecifyOrg
}
// get org id via org name
if params.OrgID == "" {
name := params.OrgName
if name == "" {
name = c.ActiveConfig.Org
}
res, err := c.GetOrgs(ctx).Org(name).Execute()
if err != nil {
return fmt.Errorf("failed to lookup ID of org %q: %w", name, err)
}
orgs := res.GetOrgs()
if len(orgs) == 0 {
return fmt.Errorf("no organization found with name %q", name)
}
params.OrgID = orgs[0].GetId()
}
// set up a struct with required params
body := api.RemoteConnectionCreationRequest{
Name: params.Name,
OrgID: params.OrgID,
RemoteURL: params.RemoteURL,
RemoteAPIToken: params.RemoteAPIToken,
RemoteOrgID: params.RemoteOrgID,
AllowInsecureTLS: params.AllowInsecureTLS,
}
if params.Description != "" {
body.Description = &params.Description
}
// send post request
res, err := c.PostRemoteConnection(ctx).RemoteConnectionCreationRequest(body).Execute()
if err != nil {
return fmt.Errorf("failed to create remote connection %q: %w", params.Name, err)
}
// print confirmation of new connection
return c.printRemote(printRemoteOpts{remote: &res})
}
type printRemoteOpts struct {
remote *api.RemoteConnection
remotes []api.RemoteConnection
deleted bool
}
func (c Client) printRemote(opts printRemoteOpts) error {
if c.PrintAsJSON {
var v interface{}
if opts.remote != nil {
v = opts.remote
} else {
v = opts.remotes
}
return c.PrintJSON(v)
}
headers := []string{"ID", "Name", "Org ID", "Remote URL", "Remote Org ID", "Allow Insecure TLS"}
if opts.deleted {
headers = append(headers, "Deleted")
}
if opts.remote != nil {
opts.remotes = append(opts.remotes, *opts.remote)
}
var rows []map[string]interface{}
for _, r := range opts.remotes {
row := map[string]interface{}{
"ID": r.GetId(),
"Name": r.GetName(),
"Org ID": r.OrgID,
"Remote URL": r.RemoteURL,
"Remote Org ID": r.RemoteOrgID,
"Allow Insecure TLS": r.AllowInsecureTLS,
}
if opts.deleted {
row["Deleted"] = true
}
rows = append(rows, row)
}
return c.PrintTable(headers, rows...)
}

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/influxdata/influx-cli/v2/clients/remote"
"github.com/influxdata/influx-cli/v2/pkg/cli/middleware"
"github.com/urfave/cli"
)
@ -22,13 +23,68 @@ func newRemoteCmd() cli.Command {
}
func newRemoteCreateCmd() cli.Command {
var params remote.CreateParams
return cli.Command{
Name: "create",
Usage: "Create a new remote connection",
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
Flags: commonFlags(),
Action: func(ctx *cli.Context) {
fmt.Println("remote create command was called")
Flags: append(
commonFlags(),
&cli.StringFlag{
Name: "name, n",
Usage: "Name for the new remote connection",
Required: true,
Destination: &params.Name,
},
&cli.StringFlag{
Name: "description, d",
Usage: "Description for the new remote connection",
Destination: &params.Description,
},
&cli.StringFlag{
Name: "org-id",
Usage: "The ID of the local organization",
EnvVar: "INFLUX_ORG_ID",
Destination: &params.OrgID,
},
&cli.StringFlag{
Name: "org, o",
Usage: "The name of the organization",
EnvVar: "INFLUX_ORG",
Destination: &params.OrgName,
},
&cli.StringFlag{
Name: "remote-url",
Usage: "The url for the remote database",
Required: true,
Destination: &params.RemoteURL,
},
&cli.StringFlag{
Name: "remote-api-token",
Usage: "The API token for the remote database",
Required: true,
Destination: &params.RemoteAPIToken,
},
&cli.StringFlag{
Name: "remote-org-id",
Usage: "The ID of the remote organization",
Required: true,
Destination: &params.RemoteOrgID,
},
&cli.BoolFlag{
Name: "allow-insecure-tls",
Usage: "Allows insecure TLS",
Destination: &params.AllowInsecureTLS,
},
),
Action: func(ctx *cli.Context) error {
client := remote.Client{
CLI: getCLI(ctx),
RemoteConnectionsApi: getAPI(ctx).RemoteConnectionsApi,
OrganizationsApi: getAPI(ctx).OrganizationsApi,
}
return client.Create(getContext(ctx), &params)
},
}
}