Skip to content

Commit

Permalink
Remove unused git token and use access token instead (#300)
Browse files Browse the repository at this point in the history
* Fetch access token from api for initialize guide

* Do not pass user token to repo any more, get it through api instead

* Bug fix

* Bug fix: missing ref

* Bug fix
  • Loading branch information
hiveer authored Jul 15, 2024
1 parent 7978c79 commit abd23b9
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
:can-write="canWrite"
repo-type="space"
:user-name="userName"
:user-token="userToken"
:commitId="commitId"
@toggleSpaceLogsDrawer="toggleSpaceLogsDrawer"
/>
Expand Down Expand Up @@ -121,7 +120,6 @@
ownerUrl: String,
canWrite: Boolean,
userName: String,
userToken: String,
commitId: String
})
Expand Down
41 changes: 36 additions & 5 deletions app/javascript/components/application_spaces/InitializeGuide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,57 @@
:http-clone-url="httpCloneUrl"
:ssh-clone-url="sshCloneUrl"
:user-name="userName"
:user-token="userToken"
:user-token="accessToken"
:sdk="sdk" />

<StreamlitInitializeGuide v-show="sdk == 'streamlit'"
:http-clone-url="httpCloneUrl"
:ssh-clone-url="sshCloneUrl"
:user-name="userName"
:user-token="userToken"
:sdk="sdk" />
:user-token="accessToken"
:sdk="sdk" />
</template>

<script setup>
import GradioInitializeGuide from './GradioInitializeGuide.vue'
import StreamlitInitializeGuide from './StreamlitInitializeGuide.vue'
import jwtFetch from '../../packs/jwtFetch'
import { useCookies } from 'vue3-cookies'
import { ref, onMounted, inject } from 'vue'
const props = defineProps({
httpCloneUrl: String,
sshCloneUrl: String,
sdk: String,
userName: String,
userToken: String,
userName: String
})
const { cookies } = useCookies()
const csghubServer = inject('csghubServer')
const currentUser = ref(cookies.get('current_user'))
const accessToken = ref('')
const fetchUserToken = async () => {
const res = await jwtFetch(
`${csghubServer}/api/v1/user/${currentUser}/tokens?app=git`
)
if (!res.ok) {
res.json().then((error) => {
ElMessage({ message: error.msg, type: 'warning' })
})
} else {
res.json().then((body) => {
if (body.data) {
accessToken.value = body.data[0].token
}
})
}
}
onMounted(() => {
if (currentUser.value) {
fetchUserToken()
}
})
</script>
2 changes: 0 additions & 2 deletions app/javascript/components/codes/CodeDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
:settingsVisibility="settingsVisibility"
:can-write="canWrite"
:userName="userName"
:userToken="userToken"
repo-type="code"
:commitId="commitId"
/>
Expand Down Expand Up @@ -60,7 +59,6 @@
ownerUrl: String,
canWrite: Boolean,
userName: String,
userToken: String,
commitId: String
})
const repoDetailStore = useRepoDetailStore()
Expand Down
2 changes: 0 additions & 2 deletions app/javascript/components/datasets/DatasetDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
:tags="tags"
:tag-list="tagList"
:userName="userName"
:userToken="userToken"
repo-type="dataset"
:commitId="commitId"
/>
Expand Down Expand Up @@ -64,7 +63,6 @@
ownerUrl: String,
canWrite: Boolean,
userName: String,
userToken: String,
commitId: String
})
const repoDetailStore = useRepoDetailStore()
Expand Down
2 changes: 0 additions & 2 deletions app/javascript/components/models/ModelDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
:tags="tags"
:tag-list="tagList"
:userName="userName"
:userToken="userToken"
:commitId="commitId"
repo-type="model"
:admin="admin"
Expand Down Expand Up @@ -64,7 +63,6 @@
ownerUrl: String,
canWrite: Boolean,
userName: String,
userToken: String,
commitId: String,
admin: Boolean
})
Expand Down
1 change: 0 additions & 1 deletion app/javascript/components/shared/RepoClone.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
sshCloneUrl: String,
repoType: String,
userName: String,
userToken: String,
namespacePath: String,
admin: Boolean,
repo: Object,
Expand Down
3 changes: 0 additions & 3 deletions app/javascript/components/shared/RepoTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
:httpCloneUrl="repoDetail.repository.http_clone_url"
:sshCloneUrl="repoDetail.repository.ssh_clone_url"
:userName="userName"
:userToken="userToken"
:namespacePath="repoDetail.path"
:admin="admin"
:repo="repoDetail"
Expand All @@ -31,7 +30,6 @@
:ssh-clone-url="repoDetail.repository.ssh_clone_url"
:sdk="sdk"
:user-name="userName"
:user-token="userToken"
/>
<ApplicationPage
v-else-if="repoType === 'space' && appStatus === 'Running'"
Expand Down Expand Up @@ -298,7 +296,6 @@
appEndpoint: String,
sdk: String,
userName: String,
userToken: String,
commitId: String,
hardware: String,
modelId: String,
Expand Down
1 change: 0 additions & 1 deletion app/views/application_spaces/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
avatar="<%= @avatar_url %>"
:can-write="<%= !!(@local_application_space && current_user&.can_write?(@local_application_space)) %>"
user-name="<%= current_user&.name %>"
user-token="<%= current_user&.git_token %>"
commit-id="<%= @commit_id %>"
>
</application-space-detail>
Expand Down
1 change: 0 additions & 1 deletion app/views/codes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
avatar="<%= @avatar_url %>"
:can-write="<%= !!(@local_code && current_user&.can_write?(@local_code)) %>"
user-name="<%= current_user&.name %>"
user-token="<%= current_user&.git_token %>"
commit-id="<%= @commit_id %>"
></code-detail>
</div>
1 change: 0 additions & 1 deletion app/views/datasets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
avatar="<%= @avatar_url %>"
:can-write="<%= !!(@local_dataset && current_user&.can_write?(@local_dataset)) %>"
user-name="<%= current_user&.name %>"
user-token="<%= current_user&.git_token %>"
commit-id="<%= @commit_id %>"
>
</dataset-detail>
Expand Down
1 change: 0 additions & 1 deletion app/views/models/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
avatar="<%= @avatar_url %>"
:can-write="<%= !!(@local_model && current_user&.can_write?(@local_model)) %>"
user-name="<%= current_user&.name %>"
user-token="<%= current_user&.git_token %>"
commit-id="<%= @commit_id %>"
:admin="<%= current_user&.admin? %>"
></model-detail>
Expand Down

0 comments on commit abd23b9

Please sign in to comment.