2015-02-19 20:46:06 +00:00
|
|
|
// Copyright 2015 CoreOS, Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package url
|
|
|
|
|
|
|
|
import (
|
2017-02-22 23:55:32 +00:00
|
|
|
"github.com/rancher/os/config/cloudinit/datasource"
|
|
|
|
"github.com/rancher/os/config/cloudinit/pkg"
|
2015-02-19 20:46:06 +00:00
|
|
|
)
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
type RemoteFile struct {
|
2015-02-19 20:46:06 +00:00
|
|
|
url string
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func NewDatasource(url string) *RemoteFile {
|
|
|
|
return &RemoteFile{url}
|
2015-02-19 20:46:06 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func (f *RemoteFile) IsAvailable() bool {
|
|
|
|
client := pkg.NewHTTPClient()
|
2015-02-19 20:46:06 +00:00
|
|
|
_, err := client.Get(f.url)
|
|
|
|
return (err == nil)
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func (f *RemoteFile) AvailabilityChanges() bool {
|
2015-02-19 20:46:06 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func (f *RemoteFile) ConfigRoot() string {
|
2015-02-19 20:46:06 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func (f *RemoteFile) FetchMetadata() (datasource.Metadata, error) {
|
2015-02-19 20:46:06 +00:00
|
|
|
return datasource.Metadata{}, nil
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func (f *RemoteFile) FetchUserdata() ([]byte, error) {
|
|
|
|
client := pkg.NewHTTPClient()
|
2015-02-19 20:46:06 +00:00
|
|
|
return client.GetRetry(f.url)
|
|
|
|
}
|
|
|
|
|
2017-02-23 01:29:01 +00:00
|
|
|
func (f *RemoteFile) Type() string {
|
2015-02-19 20:46:06 +00:00
|
|
|
return "url"
|
|
|
|
}
|