github.com/influxdata/influxdb/v2@v2.7.6/source.go (about) 1 package influxdb 2 3 import ( 4 "context" 5 6 "github.com/influxdata/influxdb/v2/kit/platform" 7 ) 8 9 const ( 10 // ErrSourceNotFound is an error message when a source does not exist. 11 ErrSourceNotFound = "source not found" 12 ) 13 14 // SourceType is a string for types of sources. 15 type SourceType string 16 17 const ( 18 // V2SourceType is an InfluxDBv2 type. 19 V2SourceType = "v2" 20 // V1SourceType is an InfluxDBv1 type. 21 V1SourceType = "v1" 22 // SelfSourceType is the source hosting the UI. 23 SelfSourceType = "self" 24 ) 25 26 // Source is an external Influx with time series data. 27 // TODO(desa): do we still need default? 28 // TODO(desa): do sources belong 29 type Source struct { 30 ID platform.ID `json:"id,omitempty"` // ID is the unique ID of the source 31 OrganizationID platform.ID `json:"orgID"` // OrganizationID is the organization ID that resource belongs to 32 Default bool `json:"default"` // Default specifies the default source for the application 33 Name string `json:"name"` // Name is the user-defined name for the source 34 Type SourceType `json:"type,omitempty"` // Type specifies which kinds of source (enterprise vs oss vs 2.0) 35 URL string `json:"url"` // URL are the connections to the source 36 InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"` // InsecureSkipVerify as true means any certificate presented by the source is accepted 37 Telegraf string `json:"telegraf"` // Telegraf is the db telegraf is written to. By default it is "telegraf" 38 SourceFields 39 V1SourceFields 40 } 41 42 // V1SourceFields are the fields for connecting to a 1.0 source (oss or enterprise) 43 type V1SourceFields struct { 44 Username string `json:"username,omitempty"` // Username is the username to connect to the source 45 Password string `json:"password,omitempty"` // Password is in CLEARTEXT 46 SharedSecret string `json:"sharedSecret,omitempty"` // ShareSecret is the optional signing secret for Influx JWT authorization 47 MetaURL string `json:"metaUrl,omitempty"` // MetaURL is the url for the meta node 48 DefaultRP string `json:"defaultRP"` // DefaultRP is the default retention policy used in database queries to this source 49 } 50 51 // SourceFields is used to authorize against an influx 2.0 source. 52 type SourceFields struct { 53 Token string `json:"token"` // Token is the 2.0 authorization token associated with a source 54 } 55 56 // ops for sources. 57 const ( 58 OpDefaultSource = "DefaultSource" 59 OpFindSourceByID = "FindSourceByID" 60 OpFindSources = "FindSources" 61 OpCreateSource = "CreateSource" 62 OpUpdateSource = "UpdateSource" 63 OpDeleteSource = "DeleteSource" 64 ) 65 66 // SourceService is a service for managing sources. 67 type SourceService interface { 68 // DefaultSource retrieves the default source. 69 DefaultSource(ctx context.Context) (*Source, error) 70 // FindSourceByID retrieves a source by its ID. 71 FindSourceByID(ctx context.Context, id platform.ID) (*Source, error) 72 // FindSources returns a list of all sources. 73 FindSources(ctx context.Context, opts FindOptions) ([]*Source, int, error) 74 // CreateSource sets the sources ID and stores it. 75 CreateSource(ctx context.Context, s *Source) error 76 // UpdateSource updates the source. 77 UpdateSource(ctx context.Context, id platform.ID, upd SourceUpdate) (*Source, error) 78 // DeleteSource removes the source. 79 DeleteSource(ctx context.Context, id platform.ID) error 80 } 81 82 // DefaultSourceFindOptions are the default find options for sources 83 var DefaultSourceFindOptions = FindOptions{} 84 85 // SourceUpdate represents updates to a source. 86 type SourceUpdate struct { 87 Name *string `json:"name"` 88 Type *SourceType `json:"type,omitempty"` 89 Token *string `json:"token"` 90 URL *string `json:"url"` 91 InsecureSkipVerify *bool `json:"insecureSkipVerify,omitempty"` 92 Telegraf *string `json:"telegraf"` 93 Username *string `json:"username,omitempty"` 94 Password *string `json:"password,omitempty"` 95 SharedSecret *string `json:"sharedSecret,omitempty"` 96 MetaURL *string `json:"metaURL,omitempty"` 97 Role *string `json:"role,omitempty"` 98 DefaultRP *string `json:"defaultRP"` 99 } 100 101 // Apply applies an update to a source. 102 func (u SourceUpdate) Apply(s *Source) error { 103 if u.Name != nil { 104 s.Name = *u.Name 105 } 106 if u.Type != nil { 107 s.Type = *u.Type 108 } 109 if u.Token != nil { 110 s.Token = *u.Token 111 } 112 if u.URL != nil { 113 s.URL = *u.URL 114 } 115 if u.InsecureSkipVerify != nil { 116 s.InsecureSkipVerify = *u.InsecureSkipVerify 117 } 118 if u.Telegraf != nil { 119 s.Telegraf = *u.Telegraf 120 } 121 if u.Username != nil { 122 s.Username = *u.Username 123 } 124 if u.Password != nil { 125 s.Password = *u.Password 126 } 127 if u.SharedSecret != nil { 128 s.SharedSecret = *u.SharedSecret 129 } 130 if u.MetaURL != nil { 131 s.MetaURL = *u.MetaURL 132 } 133 if u.DefaultRP != nil { 134 s.DefaultRP = *u.DefaultRP 135 } 136 137 return nil 138 }