github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/types/jamf.go (about) 1 // Copyright 2023 Gravitational, Inc 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package types 16 17 import ( 18 "net/url" 19 "slices" 20 "strings" 21 22 "github.com/gravitational/trace" 23 ) 24 25 const ( 26 // JamfOnMissingNOOP is the textual representation for the NOOP on_missing 27 // action. 28 JamfOnMissingNoop = "NOOP" 29 // JamfOnMissingDelete is the textual representation for the DELETE on_missing 30 // action. 31 JamfOnMissingDelete = "DELETE" 32 ) 33 34 // JamfOnMissingActions is a slice of all textual on_missing representations, 35 // excluding the empty string. 36 var JamfOnMissingActions = []string{ 37 JamfOnMissingNoop, 38 JamfOnMissingDelete, 39 } 40 41 // ValidateJamfSpecV1 validates a [JamfSpecV1] instance. 42 func ValidateJamfSpecV1(s *JamfSpecV1) error { 43 switch { 44 case s == nil: 45 return trace.BadParameter("spec required") 46 case s.Username == "": 47 return trace.BadParameter("username required") 48 case s.Password == "": 49 return trace.BadParameter("password required") 50 } 51 52 switch u, err := url.Parse(s.ApiEndpoint); { 53 case err != nil: 54 return trace.BadParameter("invalid API endpoint: %v", err) 55 case u.Host == "": 56 return trace.BadParameter("invalid API endpoint: missing hostname") 57 } 58 59 for i, e := range s.Inventory { 60 switch { 61 case e == nil: 62 return trace.BadParameter("inventory entry #%v is nil", i) 63 case e.OnMissing != "" && !slices.Contains(JamfOnMissingActions, e.OnMissing): 64 return trace.BadParameter( 65 "inventory[%v]: invalid on_missing action %q (expect empty or one of [%v])", 66 i, e.OnMissing, strings.Join(JamfOnMissingActions, ",")) 67 } 68 69 syncPartial := e.SyncPeriodPartial 70 syncFull := e.SyncPeriodFull 71 if syncFull > 0 && syncPartial >= syncFull { 72 return trace.BadParameter("inventory[%v]: sync_period_partial is greater or equal to sync_period_full, partial syncs will never happen", i) 73 } 74 } 75 76 return nil 77 }