<commit_before>// Copyright (c) 2016 Intel Corporation
//
// 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 api

import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"

	"github.com/ciao-project/ciao/ciao-controller/types"
	"github.com/ciao-project/ciao/service"
	"github.com/ciao-project/ciao/ssntp/uuid"
	"github.com/gorilla/mux"
)

// Port is the default port number for the ciao API.
const Port = 8889

const (
	// PoolsV1 is the content-type string for v1 of our pools resource
	PoolsV1 = "x.ciao.pools.v1"

	// ExternalIPsV1 is the content-type string for v1 of our external-ips resource
	ExternalIPsV1 = "x.ciao.external-ips.v1"

	// WorkloadsV1 is the content-type string for v1 of our workloads resource
	WorkloadsV1 = "x.ciao.workloads.v1"

	// TenantsV1 is the content-type string for v1 of our tenants resource
	TenantsV1 = "x.ciao.tenants.v1"

	// NodeV1 is the content-type string for v1 of our node resource
	NodeV1 = "x.ciao.node.v1"

	// ImagesV1 is the content-type string for v1 of our images resource
	ImagesV1 = "x.ciao.images.v1"
)

// ErrorImage defines all possible image handling errors
type ErrorImage error

var (
	// ErrNoImage is returned when an image is not found.
	ErrNoImage = errors.New("Image not found")

	// ErrImageSaving is returned when an image is being uploaded.
	ErrImageSaving = errors.New("Image being uploaded")

	// ErrBadUUID is returned when an invalid UUID is specified
	ErrBadUUID = errors.New("Bad UUID")

	// ErrAlreadyExists is returned when an attempt is made to add
	// an image with a UUID that already exists.
	ErrAlreadyExists = errors.New("Already Exists")

	// ErrDecodeImage is returned when there was an error on image decoding
	ErrDecodeImage = errors.New("Error on Image decode")

	// ErrForbiddenAccess is returned for only-privileged image operations
	ErrForbiddenAccess = errors.New("Forbidden Access")

	// ErrQuota is returned when the tenant exceeds its quota
	ErrQuota = errors.New("Tenant over quota")
)

// CreateImageRequest contains information for a create image request.
type CreateImageRequest struct {
	Name       string           `json:"name,omitempty"`
	ID         string           `json:"id,omitempty"`
	Visibility types.Visibility `json:"visibility,omitempty"`
}

// HTTPErrorData represents the HTTP response body for<commit_msg>ciao-controller: Remove unused error constants from image service<commit_after>// Copyright (c) 2016 Intel Corporation
//
// 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 api

import (
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"

	"github.com/ciao-project/ciao/ciao-controller/types"
	"github.com/ciao-project/ciao/service"
	"github.com/ciao-project/ciao/ssntp/uuid"
	"github.com/gorilla/mux"
)

// Port is the default port number for the ciao API.
const Port = 8889

const (
	// PoolsV1 is the content-type string for v1 of our pools resource
	PoolsV1 = "x.ciao.pools.v1"

	// ExternalIPsV1 is the content-type string for v1 of our external-ips resource
	ExternalIPsV1 = "x.ciao.external-ips.v1"

	// WorkloadsV1 is the content-type string for v1 of our workloads resource
	WorkloadsV1 = "x.ciao.workloads.v1"

	// TenantsV1 is the content-type string for v1 of our tenants resource
	TenantsV1 = "x.ciao.tenants.v1"

	// NodeV1 is the content-type string for v1 of our node resource
	NodeV1 = "x.ciao.node.v1"

	// ImagesV1 is the content-type string for v1 of our images resource
	ImagesV1 = "x.ciao.images.v1"
)

// ErrorImage defines all possible image handling errors
type ErrorImage error

var (
	// ErrNoImage is returned when an image is not found.
	ErrNoImage = errors.New("Image not found")

	// ErrImageSaving is returned when an image is being uploaded.
	ErrImageSaving = errors.New("Image being uploaded")

	// ErrBadUUID is returned when an invalid UUID is specified
	ErrBadUUID = errors.New("Bad UUID")

	// ErrAlreadyExists is returned when an attempt is made to add
	// an image with a UUID that already exists.
	ErrAlreadyExists = errors.New("Already Exists")

	// ErrQuota is returned when the tenant exceeds its quota
	ErrQuota = errors.New("Tenant over quota")
)

// CreateImageRequest contains information for a create image request.
type CreateImageRequest struct {
	Name       string           `json:"name,omitempty"`
	ID         string           `json:"id,omitempty"`
	Visibility types.Visibility `json:"visibility,omitempty"`
}

// HTTPErrorData represents the HTTP response body for
{'fraction_non_alphanumeric': 0.09009828904259191, 'fraction_numerical': 0.013105205678922462, 'mean_word_length': 3.6098993288590604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1044310', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1659, 'n_words': 630}