Skip to content

Commit

Permalink
Merge pull request #47 from kubenav/improve-required-data-checks
Browse files Browse the repository at this point in the history
Improve required data checks
  • Loading branch information
ricoberger committed Mar 11, 2020
2 parents 291cccf + 7c953df commit 5cf1f26
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 23 deletions.
1 change: 0 additions & 1 deletion src/components/settings/ClustersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const ClustersPage: React.FunctionComponent = () => {
</IonButtons>
<IonTitle>Clusters</IonTitle>
{isPlatform('hybrid') ? <AddCluster /> : null}
<AddCluster />
</IonToolbar>
</IonHeader>
<IonContent>
Expand Down
22 changes: 15 additions & 7 deletions src/components/settings/clusters/aws/AWS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IonList,
IonSelect,
IonSelectOption,
IonToast,
} from '@ionic/react';
import React, { useState } from 'react';

Expand All @@ -20,6 +21,7 @@ const AWS: React.FunctionComponent = () => {
const [accessKeyID, setAccessKeyID] = useState<string>('');
const [region, setRegion] = useState<string>('');
const [secretKey, setSecretKey] = useState<string>('');
const [error, setError] = useState<string>('');

const handleAccessKeyID = (event) => {
setAccessKeyID(event.target.value);
Expand All @@ -34,16 +36,20 @@ const AWS: React.FunctionComponent = () => {
};

const importClusters = () => {
let tokens: IAWSTokens = readAWSTokens();
if (accessKeyID === '' || region === '' || secretKey === '') {
setError('Access Key ID, Secret Key and Region are required.');
} else {
let tokens: IAWSTokens = readAWSTokens();

tokens[region] = {
accessKeyID: accessKeyID,
secretKey: secretKey,
};
tokens[region] = {
accessKeyID: accessKeyID,
secretKey: secretKey,
};

saveAWSTokens(tokens);
saveAWSTokens(tokens);

window.location.replace(`/settings/clusters/aws/${region}`);
window.location.replace(`/settings/clusters/aws/${region}`);
}
};

return (
Expand Down Expand Up @@ -103,6 +109,8 @@ const AWS: React.FunctionComponent = () => {

<IonButton expand="block" onClick={() => importClusters()}>Import from AWS</IonButton>
</IonCardContent>

<IonToast isOpen={error !== ''} onDidDismiss={() => setError('')} message={error} duration={3000} />
</IonCard>
);
};
Expand Down
35 changes: 24 additions & 11 deletions src/components/settings/clusters/azure/Azure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IonInput,
IonItem,
IonLabel,
IonList, IonToggle,
IonList, IonToast, IonToggle,
} from '@ionic/react';
import React, { useState } from 'react';

Expand All @@ -20,6 +20,7 @@ const Azure: React.FunctionComponent = () => {
const [tenantID, setTenantID] = useState<string>('');
const [resourceGroupName, setResourceGroupName] = useState<string>('');
const [admin, setAdmin] = useState<boolean>(false);
const [error, setError] = useState<string>('');

const handleSubscriptionID = (event) => {
setSubscriptionID(event.target.value);
Expand All @@ -46,16 +47,26 @@ const Azure: React.FunctionComponent = () => {
};

const importClusters = () => {
saveAzureCredentials({
subscriptionID: subscriptionID,
clientID: clientID,
clientSecret: clientSecret,
tenantID: tenantID,
resourceGroupName: resourceGroupName,
admin: admin,
});

window.location.replace(`/settings/clusters/azure`);
if (
subscriptionID === ''
|| clientID === ''
|| clientSecret === ''
|| tenantID === ''
|| resourceGroupName === ''
) {
setError('Subscription ID, Client ID, Client Secret, Tenant ID and Resource Group Name are required.');
} else {
saveAzureCredentials({
subscriptionID: subscriptionID,
clientID: clientID,
clientSecret: clientSecret,
tenantID: tenantID,
resourceGroupName: resourceGroupName,
admin: admin,
});

window.location.replace(`/settings/clusters/azure`);
}
};

return (
Expand Down Expand Up @@ -104,6 +115,8 @@ const Azure: React.FunctionComponent = () => {

<IonButton expand="block" onClick={() => importClusters()}>Import from Azure</IonButton>
</IonCardContent>

<IonToast isOpen={error !== ''} onDidDismiss={() => setError('')} message={error} duration={3000} />
</IonCard>
);
};
Expand Down
14 changes: 13 additions & 1 deletion src/components/settings/clusters/google/Google.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IonItem,
IonLabel,
IonList,
IonToast,
} from '@ionic/react';
import React, { useState } from 'react';

Expand All @@ -16,12 +17,21 @@ import { saveGoogleClientID } from '../../../../utils/storage';

const Google: React.FunctionComponent = () => {
const [clientID, setClientID] = useState<string>('');
const [error, setError] = useState<string>('');

const handleClientID = (event) => {
setClientID(event.target.value);
saveGoogleClientID(event.target.value);
};

const handleSignIn = () => {
if (clientID === '') {
setError('Client ID is required.')
} else {
window.location.replace(`${GOOGLE_OAUTH2_ENDPOINT}?client_id=${clientID}&redirect_uri=${GOOGLE_REDIRECT_URI}&response_type=${GOOGLE_RESPONSE_TYPE}&scope=${GOOGLE_SCOPE}`);
}
};

return (
<IonCard>
<div className="card-header-image">
Expand All @@ -47,8 +57,10 @@ const Google: React.FunctionComponent = () => {
</IonItem>
</IonList>

<IonButton expand="block" href={`${GOOGLE_OAUTH2_ENDPOINT}?client_id=${clientID}&redirect_uri=${GOOGLE_REDIRECT_URI}&response_type=${GOOGLE_RESPONSE_TYPE}&scope=${GOOGLE_SCOPE}`} target="_blank" rel="noopener noreferrer">Sign In with Google</IonButton>
<IonButton expand="block" onClick={() => handleSignIn()}>Sign In with Google</IonButton>
</IonCardContent>

<IonToast isOpen={error !== ''} onDidDismiss={() => setError('')} message={error} duration={3000} />
</IonCard>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const KubeconfigPage: React.FunctionComponent<IKubeconfigPageProps> = ({ history
const cluster = getKubeconfigCluster(ctx.context.cluster, config.clusters);
const user = getKubeconfigUser(ctx.context.user, config.users);

if (ctx.name === '' || cluster === null || user === null || !cluster.server || !cluster['certificate-authority-data'] || !((user['client-certificate-data'] && user['client-key-data']) || user.token || !(user.username && user.password))) {
if (ctx.name === '' || cluster === null || user === null || !cluster.server || !((user['client-certificate-data'] && user['client-key-data']) || user.token || !(user.username && user.password))) {
throw new Error('Invalid kubeconfig');
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/settings/clusters/manual/ManualPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ const ManualPage: React.FunctionComponent<IManualPageProps> = ({ history }) => {
setError('Server is required')
} else if (!url.startsWith('https://')) {
setError('Invalid URL')
} else if (certificateAuthorityData === '') {
setError('Certificate Authority Data is required')
} else if (clientCertificateData === '' && clientKeyData === '' && token === '' && username === '' && password === '') {
setError('Client Certificate Data and Client Key Data or Token or Username and Password is required')
} else {
Expand Down

0 comments on commit 5cf1f26

Please sign in to comment.