github.com/blixtra/rkt@v0.8.1-0.20160204105720-ab0d1add1a43/rkt/flag/secflags.go (about)

     1  // Copyright 2015 The rkt Authors
     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 flag
    16  
    17  const (
    18  	insecureNone  = 0
    19  	insecureImage = 1 << (iota - 1)
    20  	insecureTLS
    21  	insecureOnDisk
    22  	insecureHTTP
    23  
    24  	insecureAll = (insecureImage | insecureTLS | insecureOnDisk | insecureHTTP)
    25  )
    26  
    27  var (
    28  	insecureOptions = []string{"none", "image", "tls", "ondisk", "http", "all"}
    29  
    30  	insecureOptionsMap = map[string]int{
    31  		insecureOptions[0]: insecureNone,
    32  		insecureOptions[1]: insecureImage,
    33  		insecureOptions[2]: insecureTLS,
    34  		insecureOptions[3]: insecureOnDisk,
    35  		insecureOptions[4]: insecureHTTP,
    36  		insecureOptions[5]: insecureAll,
    37  	}
    38  )
    39  
    40  type SecFlags struct {
    41  	*bitFlags
    42  }
    43  
    44  func NewSecFlags(defOpts string) (*SecFlags, error) {
    45  	bf, err := newBitFlags(insecureOptions, defOpts, insecureOptionsMap)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  
    50  	sf := &SecFlags{
    51  		bitFlags: bf,
    52  	}
    53  	return sf, nil
    54  }
    55  
    56  func (sf *SecFlags) SkipImageCheck() bool {
    57  	return sf.hasFlag(insecureImage)
    58  }
    59  
    60  func (sf *SecFlags) SkipTLSCheck() bool {
    61  	return sf.hasFlag(insecureTLS)
    62  }
    63  
    64  func (sf *SecFlags) SkipOnDiskCheck() bool {
    65  	return sf.hasFlag(insecureOnDisk)
    66  }
    67  
    68  func (sf *SecFlags) AllowHTTP() bool {
    69  	return sf.hasFlag(insecureHTTP)
    70  }
    71  
    72  func (sf *SecFlags) SkipAllSecurityChecks() bool {
    73  	return sf.hasFlag(insecureAll)
    74  }
    75  
    76  func (sf *SecFlags) SkipAnySecurityChecks() bool {
    77  	return sf.flags != 0
    78  }