github.com/argoproj/argo-events@v1.9.1/sensors/artifacts/file.go (about) 1 /* 2 Copyright 2018 BlackRock, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package artifacts 18 19 import ( 20 "fmt" 21 "os" 22 23 "github.com/argoproj/argo-events/common/logging" 24 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" 25 ) 26 27 // FileReader implements the ArtifactReader interface for file artifacts 28 type FileReader struct { 29 fileArtifact *v1alpha1.FileArtifact 30 } 31 32 // NewFileReader creates a new ArtifactReader for inline 33 func NewFileReader(fileArtifact *v1alpha1.FileArtifact) (ArtifactReader, error) { 34 // This should never happen! 35 if fileArtifact == nil { 36 return nil, fmt.Errorf("FileArtifact cannot be empty") 37 } 38 return &FileReader{fileArtifact}, nil 39 } 40 41 func (reader *FileReader) Read() ([]byte, error) { 42 content, err := os.ReadFile(reader.fileArtifact.Path) 43 if err != nil { 44 return nil, err 45 } 46 log := logging.NewArgoEventsLogger() 47 log.Debugf("reading fileArtifact from %s", reader.fileArtifact.Path) 48 return content, nil 49 }