jkawamoto/roadie

View on GitHub
cloud/azure/batch/models/certificate_reference.go

Summary

Maintainability
A
2 hrs
Test Coverage
package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
    "encoding/json"
    "strconv"

    strfmt "github.com/go-openapi/strfmt"
    "github.com/go-openapi/swag"

    "github.com/go-openapi/errors"
    "github.com/go-openapi/validate"
)

// CertificateReference A reference to a certificate to be installed on compute nodes in a pool.
// swagger:model CertificateReference
type CertificateReference struct {

    // The location of the certificate store on the compute node into which to install the certificate.
    //
    // The default value is CurrentUser. This property is applicable only for pools configured with Windows nodes (that is, created with cloudServiceConfiguration, or with virtualMachineConfiguration using a Windows image reference). For Linux compute nodes, the certificates are stored in a directory inside the task working directory and an environment variable AZ_BATCH_CERTIFICATES_DIR is supplied to the task to query for this location. For certificates with visibility of remoteuser, a certs directory is created in the user's home directory (e.g., /home/<user-name>/certs) where certificates are placed.
    StoreLocation string `json:"storeLocation,omitempty"`

    // The name of the certificate store on the compute node into which to install the certificate.
    //
    // The default value is My. This property is applicable only for pools configured with Windows nodes (that is, created with cloudServiceConfiguration, or with virtualMachineConfiguration using a Windows image reference).
    StoreName string `json:"storeName,omitempty"`

    // The thumbprint of the certificate.
    // Required: true
    Thumbprint *string `json:"thumbprint"`

    // The algorithm with which the thumbprint is associated. This must be sha1.
    // Required: true
    ThumbprintAlgorithm *string `json:"thumbprintAlgorithm"`

    // Which user accounts on the compute node should have access to the private data of the certificate.
    //
    // The default is all accounts.
    Visibility []string `json:"visibility"`
}

// Validate validates this certificate reference
func (m *CertificateReference) Validate(formats strfmt.Registry) error {
    var res []error

    if err := m.validateStoreLocation(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateThumbprint(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateThumbprintAlgorithm(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if err := m.validateVisibility(formats); err != nil {
        // prop
        res = append(res, err)
    }

    if len(res) > 0 {
        return errors.CompositeValidationError(res...)
    }
    return nil
}

var certificateReferenceTypeStoreLocationPropEnum []interface{}

func init() {
    var res []string
    if err := json.Unmarshal([]byte(`["currentuser","localmachine","unmapped"]`), &res); err != nil {
        panic(err)
    }
    for _, v := range res {
        certificateReferenceTypeStoreLocationPropEnum = append(certificateReferenceTypeStoreLocationPropEnum, v)
    }
}

const (
    // CertificateReferenceStoreLocationCurrentuser captures enum value "currentuser"
    CertificateReferenceStoreLocationCurrentuser string = "currentuser"
    // CertificateReferenceStoreLocationLocalmachine captures enum value "localmachine"
    CertificateReferenceStoreLocationLocalmachine string = "localmachine"
    // CertificateReferenceStoreLocationUnmapped captures enum value "unmapped"
    CertificateReferenceStoreLocationUnmapped string = "unmapped"
)

// prop value enum
func (m *CertificateReference) validateStoreLocationEnum(path, location string, value string) error {
    if err := validate.Enum(path, location, value, certificateReferenceTypeStoreLocationPropEnum); err != nil {
        return err
    }
    return nil
}

func (m *CertificateReference) validateStoreLocation(formats strfmt.Registry) error {

    if swag.IsZero(m.StoreLocation) { // not required
        return nil
    }

    // value enum
    if err := m.validateStoreLocationEnum("storeLocation", "body", m.StoreLocation); err != nil {
        return err
    }

    return nil
}

func (m *CertificateReference) validateThumbprint(formats strfmt.Registry) error {

    if err := validate.Required("thumbprint", "body", m.Thumbprint); err != nil {
        return err
    }

    return nil
}

func (m *CertificateReference) validateThumbprintAlgorithm(formats strfmt.Registry) error {

    if err := validate.Required("thumbprintAlgorithm", "body", m.ThumbprintAlgorithm); err != nil {
        return err
    }

    return nil
}

var certificateReferenceVisibilityItemsEnum []interface{}

func init() {
    var res []string
    if err := json.Unmarshal([]byte(`["starttask","task","remoteuser","unmapped"]`), &res); err != nil {
        panic(err)
    }
    for _, v := range res {
        certificateReferenceVisibilityItemsEnum = append(certificateReferenceVisibilityItemsEnum, v)
    }
}

func (m *CertificateReference) validateVisibilityItemsEnum(path, location string, value string) error {
    if err := validate.Enum(path, location, value, certificateReferenceVisibilityItemsEnum); err != nil {
        return err
    }
    return nil
}

func (m *CertificateReference) validateVisibility(formats strfmt.Registry) error {

    if swag.IsZero(m.Visibility) { // not required
        return nil
    }

    for i := 0; i < len(m.Visibility); i++ {

        // value enum
        if err := m.validateVisibilityItemsEnum("visibility"+"."+strconv.Itoa(i), "body", m.Visibility[i]); err != nil {
            return err
        }

    }

    return nil
}