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

feat(api): support x-greptime-auth HTTP header #483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@

if (import.meta.env.MODE === 'development' || import.meta.env.MODE === 'production') {
// Assuming local greptimeDB is up and running
const { username, password, database, host }: any = useStorage('config', {}).value
const { username, password, database, host, authHeader }: any = useStorage('config', {}).value
updateSettings({
username,
password,
database,
host,
authHeader,
})
}
</script>
8 changes: 6 additions & 2 deletions src/api/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios'
import JSONbigint from 'json-bigint'

import type { AxiosRequestConfig, AxiosResponse } from 'axios'
import { Message, Modal } from '@arco-design/web-vue'
import { Message } from '@arco-design/web-vue'
import { RecordsType } from '@/store/modules/code-run/types'

export interface OutputType {
Expand Down Expand Up @@ -47,7 +47,11 @@ axios.interceptors.request.use(

if (appStore.username || appStore.password) {
const basicAuth = `Basic ${btoa(`${appStore.username}:${appStore.password}`)}`
config.headers.authorization = basicAuth
if (!appStore.authHeader || appStore.authHeader === 'Authorization') {
config.headers.authorization = basicAuth
} else {
config.headers[appStore.authHeader] = basicAuth
}
}

if (isV1) {
Expand Down
2 changes: 1 addition & 1 deletion src/assets/style/select.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
padding-right: 8px;
padding-left: 8px;
background: var(--grey-bg-color);
// border-radius: 4px;
border-radius: 4px;
}

.arco-select-view-single:hover {
Expand Down
16 changes: 15 additions & 1 deletion src/components/global-setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ a-drawer.settings-drawer(
a-input(v-model="settingsForm.username")
a-form-item(:label="$t('settings.password')")
a-input-password(v-model="settingsForm.password" autocomplete="off")
a-form-item(v-if="settingsForm.username || settingsForm.password")
template(#label)
a-space(:size="4")
span {{ $t('settings.authHeader') }}
a-tooltip(mini position="tl" :content="$t('settings.authHeaderTip')")
svg.icon-12
use(href="#question")
a-select(v-model="settingsForm.authHeader")
a-option(value="Authorization") Authorization(default)
a-option(value="x-greptime-auth") x-greptime-auth
a-form-item
template(#label)
a-space(:size="4")
Expand Down Expand Up @@ -70,7 +80,9 @@ a-drawer.settings-drawer(
const { checkTables, getScriptsTable } = useDataBaseStore()

const { role } = storeToRefs(useUserStore())
const { globalSettings, host, database, username, password, databaseList, userTimezone } = storeToRefs(useAppStore())
const { globalSettings, host, database, username, password, databaseList, userTimezone, authHeader } = storeToRefs(
useAppStore()
)

const loginStatus = ref('')
const loginLoading = ref(false)
Expand All @@ -82,6 +94,7 @@ a-drawer.settings-drawer(
databaseList,
database: database.value,
userTimezone: userTimezone.value,
authHeader: authHeader.value,
})

const save = async () => {
Expand Down Expand Up @@ -118,6 +131,7 @@ a-drawer.settings-drawer(
databaseList: databaseList.value,
database: database.value,
userTimezone: userTimezone.value,
authHeader: authHeader.value || 'Authorization',
}
loginStatus.value = ''
}
Expand Down
1 change: 0 additions & 1 deletion src/components/refresh-playground-modal/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ a-modal.guide-modal(

<script lang="ts" setup name="RefreshPlaygroundModal">
import { createPlayground } from '@/api/playground'
import { useStorage } from '@vueuse/core'

const appStore = useAppStore()
const props = defineProps({
Expand Down
3 changes: 2 additions & 1 deletion src/config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"lifetime": "long",
"menuSelectedKey": "tables",
"userTimezone": "",
"isFullScreen": false
"isFullScreen": false,
"authHeader": "Authorization"
}
2 changes: 2 additions & 0 deletions src/locale/en-US/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export default {
'settings.timezone': 'Timezone',
'settings.saveTip': 'Authentication failed. Please check your settings.',
'settings.saveSuccess': 'Success!',
'settings.authHeader': 'Authentication Header Name',
'settings.authHeaderTip': 'The name of the HTTP header that is used for authentication.',
}
2 changes: 2 additions & 0 deletions src/locale/zh-CN/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export default {
'settings.timezone': '时区',
'settings.saveTip': '认证失败,请检查您的设置。',
'settings.saveSuccess': '保存成功!',
'settings.authHeader': '认证头名称',
'settings.authHeaderTip': '用于认证的HTTP头的名称。',
}
2 changes: 1 addition & 1 deletion src/router/guard/userLoginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function setupUserLoginInfoGuard(router: Router) {
appStore.updateSettings(useStorage('config', {}).value)
const { role } = storeToRefs(useUserStore())

const { username, password, database, guideModalVisible } = storeToRefs(useAppStore())
const { guideModalVisible } = storeToRefs(useAppStore())
if (role.value === 'cloud') {
guideModalVisible.value = true
}
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const useAppStore = defineStore('app', {
database: this.database,
username: this.username,
password: this.password,
authHeader: this.authHeader,
}
}
useStorage('config', config, localStorage, {
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export interface AppState {
menuSelectedKey: string
userTimezone: string
isFullScreen: boolean
authHeader: string
[key: string]: unknown
}
Loading