| // Copyright 2021 Google LLC |
| // |
| // 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 sysapi provides helper functions for performing various tasks on |
| // a system. All policy_manager code should use functions in this package instead of Go's |
| // built-in equivalents in order to allow testing on non-COS machines. |
| package sysapi |
| |
| import "os" |
| |
| // APIHandler interface defines the supported functions. |
| type APIHandler interface { |
| // ReadFile reads the named file and returns the content. |
| ReadFile(name string) (content []byte, err error) |
| |
| // WriteFile writes the given content to the named file with the |
| // supplied permission. |
| WriteFile(name string, content []byte, perm os.FileMode) error |
| |
| // AtomicWriteFile atomically writes a file. |
| AtomicWriteFile(name string, data []byte, perm os.FileMode) error |
| |
| // RunCommand returns the stdout and stderr produced by running the |
| // named program with the given arguments. |
| RunCommand(name string, arg ...string) (stdout, stderr []byte, err error) |
| |
| // MkdirAll creates a directory named path, along with any necessary |
| // parents, and returns nil, or else returns an error. The permission |
| // bits perm are used for all directories that MkdirAll creates. If path |
| // is already a directory, MkdirAll does nothing and returns nil. |
| MkdirAll(path string, perm os.FileMode) error |
| |
| // FileExists checks if the named file exists. |
| FileExists(path string) bool |
| |
| // GetUnixTimestamp returns the current UNIX timestamp. |
| GetUnixTimestamp() int64 |
| } |