Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AI API endpoint security issues and add AI / LLM text changes #829

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export default function ApiCreateAIAPI(props) {
multiGateway={multiGateway}
api={apiInputs}
isAPIProduct={false}
hideEndpoint
/>
)}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import ServiceEndpoint from './ServiceEndpoint';
import CustomBackend from './CustomBackend';
import { API_SECURITY_KEY_TYPE_PRODUCTION } from '../Configuration/components/APISecurity/components/apiSecurityConstants';
import { API_SECURITY_KEY_TYPE_SANDBOX } from '../Configuration/components/APISecurity/components/apiSecurityConstants';
import API from 'AppData/api';
import AIEndpointAuth from './AIEndpointAuth';

const PREFIX = 'EndpointOverview';
Expand Down Expand Up @@ -194,6 +193,7 @@ function EndpointOverview(props) {
setIsValidSequenceBackend,
isCustomBackendSelected,
setIsCustomBackendSelected,
apiKeyParamConfig,
} = props;
const { endpointConfig } = api;
const [endpointType, setEndpointType] = useState(endpointTypes[0]);
Expand All @@ -219,23 +219,6 @@ function EndpointOverview(props) {
(api.serviceInfo) });
const [servicesList, setServicesList] = useState([]);

const [apiKeyParamConfig, setApiKeyParamConfig] = useState({
authHeader: null,
authQueryParameter: null
});

useEffect(() => {
if (api.subtypeConfiguration?.subtype === 'AIAPI') {
API.getLLMProviderEndpointConfiguration(JSON.parse(api.subtypeConfiguration.configuration).llmProviderId)
.then((response) => {
if (response.body) {
const config = response.body;
setApiKeyParamConfig(config);
}
});
}
}, []);

const handleToggleEndpointSecurity = () => {
const tmpSecurityInfo = !endpointSecurityInfo ? {
production: CONSTS.DEFAULT_ENDPOINT_SECURITY,
Expand Down Expand Up @@ -409,7 +392,7 @@ function EndpointOverview(props) {
const endpointProp = 'production_endpoints';
if (endpointCategory[category]) {
delete endpointConfigCopy[endpointProp];
if (endpointConfigCopy?.endpoint_security?.production !== null) {
if (endpointConfigCopy?.endpoint_security?.production) {
delete endpointConfigCopy.endpoint_security.production;
}
if (endpointConfigCopy.endpointType === 'failover') {
Expand All @@ -427,7 +410,7 @@ function EndpointOverview(props) {
const endpointProp = 'sandbox_endpoints';
if (endpointCategory[category]) {
delete endpointConfigCopy[endpointProp];
if (endpointConfigCopy?.endpoint_security?.sandbox !== null) {
if (endpointConfigCopy?.endpoint_security?.sandbox) {
delete endpointConfigCopy.endpoint_security.sandbox;
}
if (endpointConfigCopy.endpointType === 'failover') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { APIContext } from 'AppComponents/Apis/Details/components/ApiContext';
import cloneDeep from 'lodash.clonedeep';
import { isRestricted } from 'AppData/AuthManager';
import { Alert } from 'AppComponents/Shared';

import API from 'AppData/api';
import EndpointOverview from './EndpointOverview';
import { createEndpointConfig, getEndpointTemplateByType } from './endpointUtils';
import { API_SECURITY_KEY_TYPE_PRODUCTION,
Expand Down Expand Up @@ -107,6 +109,22 @@ function Endpoints(props) {
const [productionBackendList, setProductionBackendList] = useState([]);
const [isValidSequenceBackend, setIsValidSequenceBackend] = useState(false);
const [isCustomBackendSelected, setIsCustomBackendSelected] = useState(false);
const [apiKeyParamConfig, setApiKeyParamConfig] = useState({
authHeader: null,
authQueryParameter: null
});

useEffect(() => {
if (api.subtypeConfiguration?.subtype === 'AIAPI') {
API.getLLMProviderEndpointConfiguration(JSON.parse(api.subtypeConfiguration.configuration).llmProviderId)
.then((response) => {
if (response.body) {
const config = response.body;
setApiKeyParamConfig(config);
}
});
}
}, []);

const apiReducer = (initState, configAction) => {
const tmpEndpointConfig = cloneDeep(initState.endpointConfig);
Expand Down Expand Up @@ -527,7 +545,8 @@ function Endpoints(props) {
}
}
} else if ((!endpointConfig || !endpointConfig.endpoint_security)
&& apiObject.subtypeConfiguration?.subtype === 'AIAPI' ) {
&& apiObject.subtypeConfiguration?.subtype === 'AIAPI'
&& (apiKeyParamConfig.authHeader || apiKeyParamConfig.authQueryParameter)) {
return {
isValid: false,
message: intl.formatMessage({
Expand Down Expand Up @@ -734,6 +753,7 @@ function Endpoints(props) {
setIsValidSequenceBackend={setIsValidSequenceBackend}
isCustomBackendSelected={isCustomBackendSelected}
setIsCustomBackendSelected={setIsCustomBackendSelected}
apiKeyParamConfig={apiKeyParamConfig}
/>
</Grid>
</Grid>
Expand Down
Loading